From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622125784; cv=none; d=zohomail.com; s=zohoarc; b=C58/4aeol4dM9I0ZsvyT9G4/RzQdfFYrPi3emYLhAq/WPdq74nX3wau8O1ovZQvm44oDFLe7hdDOsvoxAvn9RiUmdlXIgTTWFdac8os1s+nwDDEnBhWUlqdo//G1Go/G9Fz73CuOSEVoo784vG0hof6IM29bM6yNEJHL7W8h/rQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622125784; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uz52FNqICXdsKFhvti3vZUWX1HFRmjM04w09imUqWJQ=; b=YBqQ4mAi0nGVt8sYw0/WMMrwQArut0Xf+5CMvZX8/NPBzr+nRmKJhCBv2WPmSSWs/WNzaknWOYYCL8ZUY8XehsS0iYh/3qVG9tIKjVCDltbJvqFr5R7/oqUMzS/AlMcoTifwceDpYT6eHzeg/pWKhfmAuP8Fx75nMj6PtIwuF4g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622125784904433.07650863585593; Thu, 27 May 2021 07:29:44 -0700 (PDT) Received: from localhost ([::1]:45644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmH16-0008Ey-5w for importer2@patchew.org; Thu, 27 May 2021 10:29:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGvZ-0004yt-D0 for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22782) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGvW-00045O-16 for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:00 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-368-fTdPu56WOpytgKsYSHIJFg-1; Thu, 27 May 2021 10:23:54 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 44C15180FD69; Thu, 27 May 2021 14:23:53 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 77EBB5D6D3; Thu, 27 May 2021 14:23:42 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 00D2A1800393; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125436; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uz52FNqICXdsKFhvti3vZUWX1HFRmjM04w09imUqWJQ=; b=EJFHUthVdKZF3VyJcTw4TsS/zJtq/jHNiX8OESMFVmeHnuHsH2zNgAuWFl8D7G/PcIw2qY bwseaoIQyYP6s9dUqT1p2MVOQdaRG8Ga9D05cImTBxArkrQoKjxtxZzk/KTQrVkZWtDN4z gorQafSRDz/KuXh3ukkZikKdM+nk/bA= X-MC-Unique: fTdPu56WOpytgKsYSHIJFg-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 01/23] vhost-user-gpu: fix memory disclosure in virgl_cmd_get_capset_info (CVE-2021-3545) Date: Thu, 27 May 2021 16:23:18 +0200 Message-Id: <20210527142340.1352791-2-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Li Qiang , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Li Qiang Otherwise some of the 'resp' will be leaked to guest. Fixes: CVE-2021-3545 Reported-by: Li Qiang virtio-gpu fix: 42a8dadc74 ("virtio-gpu: fix information leak in getting capset info dispatch") Signed-off-by: Li Qiang Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20210516030403.107723-2-liq3ea@163.com> Signed-off-by: Gerd Hoffmann --- contrib/vhost-user-gpu/virgl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c index 9e6660c7ab87..6a332d601f80 100644 --- a/contrib/vhost-user-gpu/virgl.c +++ b/contrib/vhost-user-gpu/virgl.c @@ -128,6 +128,7 @@ virgl_cmd_get_capset_info(VuGpu *g, =20 VUGPU_FILL_CMD(info); =20 + memset(&resp, 0, sizeof(resp)); if (info.capset_index =3D=3D 0) { resp.capset_id =3D VIRTIO_GPU_CAPSET_VIRGL; virgl_renderer_get_cap_set(resp.capset_id, --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622125672; cv=none; d=zohomail.com; s=zohoarc; b=byw4SPgisU15VrwbMbbPlDqVboIpPN1osA8VLwUQd1OfrrckFrqM5HZzrn8e92dnLzJN9X0aSikpVNMSIdm0IuirduQ+UwPwbSPOfrE0JC5R/xLAKf5uBLkljQUXsOCU1qzc8ZAF1OLiVFf7K4D6/xVxQt9uO/GkXXfrW6FrZbw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622125672; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BZGrIz//c6HzXMND+tL9twY5A7Ll/vS79v1T9EAp1qw=; b=VcQdL8965Rsc9200pLMuxs/2bjyAy1KY/TRGyXUiZv7TeuzPaQbIPVo9+npLioZeuargUPa2n79OE/UFlAKGckDyeh4Wq4zPv+c3W20ChJVzHES909Gu4GRPeslQUXOYoSp56KNmRtTFjC8WeCevtt+dwEW/zB5DYsjxmGvYx1U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622125672225919.414237230774; Thu, 27 May 2021 07:27:52 -0700 (PDT) Received: from localhost ([::1]:38854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmGzH-0003hE-6m for importer2@patchew.org; Thu, 27 May 2021 10:27:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGvb-00054g-UG for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29163) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGva-00049t-8a for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:03 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-195-RtVMHw0kOhOQyLnK_79i2g-1; Thu, 27 May 2021 10:23:58 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 92F51501E1; Thu, 27 May 2021 14:23:57 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C9C405D9CC; Thu, 27 May 2021 14:23:54 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 10ED2180039F; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125441; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BZGrIz//c6HzXMND+tL9twY5A7Ll/vS79v1T9EAp1qw=; b=DqQPA/PlCyxL6C2MUjO90MGxXsgM3J5RzzxyupSJBUFZAlRX+09zunTiZfEDoyY1FZ4OHV xeH8gLJ7mJS6nzfZbbKsBLU3BZvjo8z+Ooz5Ic2r8iYzoGuj/pbPMdgUcckwzlfB8bAvkx PkipwsNdEnWxhvU0gWBDnaY7v4uE0zk= X-MC-Unique: RtVMHw0kOhOQyLnK_79i2g-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 02/23] vhost-user-gpu: fix resource leak in 'vg_resource_create_2d' (CVE-2021-3544) Date: Thu, 27 May 2021 16:23:19 +0200 Message-Id: <20210527142340.1352791-3-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Prasad J Pandit , "Michael S. Tsirkin" , Cornelia Huck , Li Qiang , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Li Qiang Call 'vugbm_buffer_destroy' in error path to avoid resource leak. Fixes: CVE-2021-3544 Reported-by: Li Qiang Reviewed-by: Prasad J Pandit Signed-off-by: Li Qiang Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20210516030403.107723-3-liq3ea@163.com> Signed-off-by: Gerd Hoffmann --- contrib/vhost-user-gpu/vhost-user-gpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-g= pu/vhost-user-gpu.c index f73f292c9f72..b5e153d0d648 100644 --- a/contrib/vhost-user-gpu/vhost-user-gpu.c +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c @@ -349,6 +349,7 @@ vg_resource_create_2d(VuGpu *g, g_critical("%s: resource creation failed %d %d %d", __func__, c2d.resource_id, c2d.width, c2d.height); g_free(res); + vugbm_buffer_destroy(&res->buffer); cmd->error =3D VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY; return; } --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622125567; cv=none; d=zohomail.com; s=zohoarc; b=bVP2y8Ru4kVzxe/YzEybiP+bAm8zXsgUeBuUSbrNVexBNTIwJRAgYYA+sKwK4V/ctojINrkKju+8Y1AJqqw/i1zCIOa1yLFzBqNr3MKhLAGYyizmQJrhV/niOabiWNgKV1PV1+w1vzUtU+UoU1aftl6ug/xyd3RAXwJbwlOj/Hg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622125567; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rjFsvmFZAUjqSCcfgViayGZRUEq161ht6r3odwR+pk4=; b=bcZ6/bPbUT3f8fQvIbgYZAhkdtH1P91HuDS+XGvdV02PVJBUEzVk9VLC74iGYRyceNIwoswuaFpX6qMpi6xV9EMmfXlpnfIP1fQrRRuEGHtWPf1QdfokHLUmHb67wfe8fgvPDGYDK7YCnX0i0hVnUhTOaz6d4rrrByAtTaMcnYc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622125567716621.2963044245021; Thu, 27 May 2021 07:26:07 -0700 (PDT) Received: from localhost ([::1]:32914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmGxa-0007zk-L6 for importer2@patchew.org; Thu, 27 May 2021 10:26:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGvp-0005ac-9V for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46632) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGvn-0004Jd-MJ for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-455-8T3PtDKmNMeqz0jBDYTbzQ-1; Thu, 27 May 2021 10:24:11 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B32848A026E; Thu, 27 May 2021 14:24:10 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 35EA1183AB; Thu, 27 May 2021 14:23:56 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 1CC28180063A; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125454; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rjFsvmFZAUjqSCcfgViayGZRUEq161ht6r3odwR+pk4=; b=QXCiuttDckFf3DHfTT/2SBVgp9c0A1CudGAFJpL+tzzLM66U4ZAwZwJNPAaHADkDru5MIG +DF7nK8ghCrZQIBHLCzqJfFjbTI897kmswAsdUiyHtYD5NtrdQrPYPDfXr6hEzIVeoT4rc YBTzVw9WxWfMzBeIoDo5WyJEf2XqIKM= X-MC-Unique: 8T3PtDKmNMeqz0jBDYTbzQ-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 03/23] vhost-user-gpu: fix memory leak in vg_resource_attach_backing (CVE-2021-3544) Date: Thu, 27 May 2021 16:23:20 +0200 Message-Id: <20210527142340.1352791-4-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Li Qiang , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Li Qiang Check whether the 'res' has already been attach_backing to avoid memory leak. Fixes: CVE-2021-3544 Reported-by: Li Qiang virtio-gpu fix: 204f01b309 ("virtio-gpu: fix memory leak in resource attach backing") Signed-off-by: Li Qiang Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20210516030403.107723-4-liq3ea@163.com> Signed-off-by: Gerd Hoffmann --- contrib/vhost-user-gpu/vhost-user-gpu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-g= pu/vhost-user-gpu.c index b5e153d0d648..0437e52b6460 100644 --- a/contrib/vhost-user-gpu/vhost-user-gpu.c +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c @@ -489,6 +489,11 @@ vg_resource_attach_backing(VuGpu *g, return; } =20 + if (res->iov) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + return; + } + ret =3D vg_create_mapping_iov(g, &ab, cmd, &res->iov); if (ret !=3D 0) { cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622125579; cv=none; d=zohomail.com; s=zohoarc; b=bmGJa1T0hqkPitFcMp5SbC/19xwBXxZ76ozm+uU7c6FMyntcsPgtaBIDYeaIAM8NtuhIGi/pYd4jwngBOQ4POSVKQVjo89qYfZhZRCP4p2WPzdO4HnpMzRSnaFLDeUkUV4TnFtgVqIejW3ECVdsxwBJxOjo0Y1zz3MZRyjoxcMc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622125579; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7lJvPJqZFShUMq3+67WegbHN1+FUnt0YX8aeZ9iiJD0=; b=e/QPb6CJah0uS2TLO4X2eWKDXJ/8Sy3U1/ITuD2OdBXR5ySpIx1gKBNhPKG1mdnQD6Ste/7cK7N2w3UMvvTXOS4Hi+wJWineunBbPrx3Zt3+mcns6gpYJA+9sIvIcUPTu7qL+oHy6xo729h+I3Ul8E33tDEZJDVsTjjYfWsJRsM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622125579376183.7570055482097; Thu, 27 May 2021 07:26:19 -0700 (PDT) Received: from localhost ([::1]:33190 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmGxm-0008BD-KD for importer2@patchew.org; Thu, 27 May 2021 10:26:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGvs-0005io-Fl for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46822) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGvq-0004Lq-RQ for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:20 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-495-uHaBSDeCMg6NLevR7hTh7Q-1; Thu, 27 May 2021 10:24:10 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2FE08501ED; Thu, 27 May 2021 14:24:09 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EE46F1349A; Thu, 27 May 2021 14:23:58 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 2851A180079B; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7lJvPJqZFShUMq3+67WegbHN1+FUnt0YX8aeZ9iiJD0=; b=dh4EQj+EyeeJG1LUcBJnmLPcuqb99ChCH7Gxu2qpsDhricm9jmXwoC5JBcjmVvoOKtuWNg 3ENO98dbJQ2mYAzOwDdrjE29kt5obNeldx6YdOS1S0v+y3Z0qzwOLiuYxD/8MRd0EO1i50 ZpDpSlBJXVP58FUoe/W9esQCw77cVrg= X-MC-Unique: uHaBSDeCMg6NLevR7hTh7Q-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 04/23] vhost-user-gpu: fix memory leak while calling 'vg_resource_unref' (CVE-2021-3544) Date: Thu, 27 May 2021 16:23:21 +0200 Message-Id: <20210527142340.1352791-5-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Prasad J Pandit , "Michael S. Tsirkin" , Cornelia Huck , Li Qiang , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Li Qiang If the guest trigger following sequences, the attach_backing will be leaked: vg_resource_create_2d vg_resource_attach_backing vg_resource_unref This patch fix this by freeing 'res->iov' in vg_resource_destroy. Fixes: CVE-2021-3544 Reported-by: Li Qiang virtio-gpu fix: 5e8e3c4c75 ("virtio-gpu: fix resource leak in virgl_cmd_resource_unref") Reviewed-by: Prasad J Pandit Signed-off-by: Li Qiang Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20210516030403.107723-5-liq3ea@163.com> Signed-off-by: Gerd Hoffmann --- contrib/vhost-user-gpu/vhost-user-gpu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-g= pu/vhost-user-gpu.c index 0437e52b6460..770dfad52989 100644 --- a/contrib/vhost-user-gpu/vhost-user-gpu.c +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c @@ -400,6 +400,7 @@ vg_resource_destroy(VuGpu *g, } =20 vugbm_buffer_destroy(&res->buffer); + g_free(res->iov); pixman_image_unref(res->image); QTAILQ_REMOVE(&g->reslist, res, next); g_free(res); --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622125853; cv=none; d=zohomail.com; s=zohoarc; b=EBBcQ6yxbdM41Pj+rTnId/tid4uavEcrlw1GUHy14OZ3c8pzQCrQN0mDWxJ0bs3snP5/sH3SBkA579xXeS8xikb2KUBQycMx9gnOsUo7gSiOeZT6GYnscc/drFx/1dbWW32khxOkp9/4vvVIT/tV0Pd0VOzP9oQZtzhA2VvJzGE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622125853; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IsWfZcqreEfNufHHb2WG+S/8FlWuJ5zpWayfFlvq9R0=; b=Nkw94HpM10C3MRj2bjv5x4n2ne3t4+EzWyP92/H4uU9yGjscJ3guZySUoYfNS547183Qo0hFsKedau8EeTATd7IZaw9JK8zFxx+AZPuOLlbs+e093bElG4SVYKS91+jKITNQp8P/6LXhaYDE8zUZA7+OZ3VMx1ulszDgxylmoek= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622125853194356.28337772712416; Thu, 27 May 2021 07:30:53 -0700 (PDT) Received: from localhost ([::1]:48972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmH2C-00021B-El for importer2@patchew.org; Thu, 27 May 2021 10:30:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGw1-0006G9-At for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40624) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGvz-0004TA-Oi for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:29 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-310-gVh06qyXOSScOdTAigLxsw-1; Thu, 27 May 2021 10:24:22 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 72370100945E; Thu, 27 May 2021 14:24:21 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B463E5B686; Thu, 27 May 2021 14:24:10 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 33A0518007B7; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125467; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IsWfZcqreEfNufHHb2WG+S/8FlWuJ5zpWayfFlvq9R0=; b=e5Bel6Tewu5YIfcmMCz/NkdAMrs3w+cgQ++sP3A+3umRFVKPj95HaRI87H1JG9Xj+M1BVj cSQOX8yWJY+8DRwWQzuKKKMFLyVM/C6ic0jXG11qhJ7nnkwEt2i9Kg/vboHY4vmvwNdPiT O3qxWUz9fLcGJOAIs8o1uI1COVrvPH0= X-MC-Unique: gVh06qyXOSScOdTAigLxsw-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 05/23] vhost-user-gpu: fix memory leak in 'virgl_cmd_resource_unref' (CVE-2021-3544) Date: Thu, 27 May 2021 16:23:22 +0200 Message-Id: <20210527142340.1352791-6-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Li Qiang , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Li Qiang The 'res->iov' will be leaked if the guest trigger following sequences: virgl_cmd_create_resource_2d virgl_resource_attach_backing virgl_cmd_resource_unref This patch fixes this. Fixes: CVE-2021-3544 Reported-by: Li Qiang virtio-gpu fix: 5e8e3c4c75 ("virtio-gpu: fix resource leak in virgl_cmd_resource_unref" Signed-off-by: Li Qiang Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20210516030403.107723-6-liq3ea@163.com> Signed-off-by: Gerd Hoffmann --- contrib/vhost-user-gpu/virgl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c index 6a332d601f80..c669d73a1dbe 100644 --- a/contrib/vhost-user-gpu/virgl.c +++ b/contrib/vhost-user-gpu/virgl.c @@ -108,9 +108,16 @@ virgl_cmd_resource_unref(VuGpu *g, struct virtio_gpu_ctrl_command *cmd) { struct virtio_gpu_resource_unref unref; + struct iovec *res_iovs =3D NULL; + int num_iovs =3D 0; =20 VUGPU_FILL_CMD(unref); =20 + virgl_renderer_resource_detach_iov(unref.resource_id, + &res_iovs, + &num_iovs); + g_free(res_iovs); + virgl_renderer_resource_unref(unref.resource_id); } =20 --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622125722; cv=none; d=zohomail.com; s=zohoarc; b=S3R6gyay4UjatWKQ6hiMLMMLKnwH+1Drlutz1uBs34Wrd6w/RIcrbnZnXY9/xrMHuGk7h1aSrGIuOWaujF0xcFn+C7NpdJZ6nIdsm2fJ9KPJgTrjh8u+2J9flBtJXuUAuUoZzmug7YUu5WNbtQx53O5ik2/ltkrIdy1u/FKwztY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622125722; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OcMbFP6i22pWWfS2BVh/DWIrIIwPfDVmDXnWR554kjg=; b=ADhlBzWHl2WIFNunlv3XDtTpk0rV7kv/iZ5cJqpwGgolVmJIaVl/neV5tu2nf1ZYvi0BIiqbNLxfuYnwxIxhE3bas776qi0IIRTB8l9lj/IvJpXKmIh0rGF8HmSsDWETUwiZdmsh0HaKXZW1QqO7SoBY5NmzBmU10qtz7kUq/lQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162212572224953.63349486334698; Thu, 27 May 2021 07:28:42 -0700 (PDT) Received: from localhost ([::1]:40554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmH05-0004oc-Gg for importer2@patchew.org; Thu, 27 May 2021 10:28:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGvz-00068D-EV for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56841) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGvx-0004Rv-Jn for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:27 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-378-X0m2B3OmP7CTlF55qWlZ2Q-1; Thu, 27 May 2021 10:24:22 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 084791009446; Thu, 27 May 2021 14:24:22 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1D6C81007606; Thu, 27 May 2021 14:24:12 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 3F20818007BF; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125464; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OcMbFP6i22pWWfS2BVh/DWIrIIwPfDVmDXnWR554kjg=; b=Ylp3ONpaMPiwewSgwu7u0VgBasmETY9UHWIp2qLZrbHtPdtfjKwCQvqi7jM09GpCCsgK8t QOWYoB5Cgc/pm/Wsg/mWEbssKlhvOPKLVykx81fjeDcqW4JiFffjpjrODEIhzrvnT6pkBy x7lDb1jvuGhNuRxheLWrWt6DJeWwgZ8= X-MC-Unique: X0m2B3OmP7CTlF55qWlZ2Q-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 06/23] vhost-user-gpu: fix memory leak in 'virgl_resource_attach_backing' (CVE-2021-3544) Date: Thu, 27 May 2021 16:23:23 +0200 Message-Id: <20210527142340.1352791-7-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Li Qiang , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Li Qiang If 'virgl_renderer_resource_attach_iov' failed, the 'res_iovs' will be leaked. Fixes: CVE-2021-3544 Reported-by: Li Qiang virtio-gpu fix: 33243031da ("virtio-gpu-3d: fix memory leak in resource attach backing") Signed-off-by: Li Qiang Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20210516030403.107723-7-liq3ea@163.com> Signed-off-by: Gerd Hoffmann --- contrib/vhost-user-gpu/virgl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c index c669d73a1dbe..a16a311d80df 100644 --- a/contrib/vhost-user-gpu/virgl.c +++ b/contrib/vhost-user-gpu/virgl.c @@ -287,8 +287,11 @@ virgl_resource_attach_backing(VuGpu *g, return; } =20 - virgl_renderer_resource_attach_iov(att_rb.resource_id, + ret =3D virgl_renderer_resource_attach_iov(att_rb.resource_id, res_iovs, att_rb.nr_entries); + if (ret !=3D 0) { + g_free(res_iovs); + } } =20 static void --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622125963; cv=none; d=zohomail.com; s=zohoarc; b=FpyEC1bg1Fpc461NV/mgUKm1XdODbvnpw5oEc+QNbGTLxaSavwXj6wtBqxuR9z779UL8U1/ug5KClAve2oRDAKg3HYoNTBrD5F2bpCW5DeCyx2O/xBzrbojHxaoZ/ZsCtE7aIRGnVFqcD5ZKx9IFSqthnyxgh67CQBVXkAvCU08= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622125963; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=c6C3i4cfX+dDn2nyg0DmidGarByqwbdaOjgX2j7L4Cw=; b=Z3O+Xb7oOZH6YE2fjvw7EzOleXrZvA7Q5fZ8BBD8w4j29Vhl85xPEs14cifOgUO0ZfRvWdOu5EnKqVOkln2qycnLnLHyjim5Vn6M+xhMuVR0IVwi97gUy9B+/9UCm9lTqzOMw3xovmIwKk8FT+udrIpzy+LGMTdQzDvTkUBiy/g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622125963232859.8343313264307; Thu, 27 May 2021 07:32:43 -0700 (PDT) Received: from localhost ([::1]:54144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmH3w-0005bA-8S for importer2@patchew.org; Thu, 27 May 2021 10:32:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34142) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwC-0006yD-Kn for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54693) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwA-0004bq-VH for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:40 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-95-vpDCh-HNMKiv9EnLzlSHeA-1; Thu, 27 May 2021 10:24:35 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 67480501E5; Thu, 27 May 2021 14:24:34 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 013825D9DC; Thu, 27 May 2021 14:24:23 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 4A8F21800843; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125478; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c6C3i4cfX+dDn2nyg0DmidGarByqwbdaOjgX2j7L4Cw=; b=FwKqzpBzGvNCpqklpT/IL96JAob8dLnqrZtSiAXauBXljvDdyMkhm0cQUZdCiCbdFolccB cd2wOif7TGem7/lrG7Oba+XYV+OjPlmIoGTH8jk17MgtS6/ZvCVphcy7TxHmPG8GJIAZ4b p+ikYEoBcdWNK430xe388Cztg7zg8c8= X-MC-Unique: vpDCh-HNMKiv9EnLzlSHeA-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 07/23] vhost-user-gpu: fix OOB write in 'virgl_cmd_get_capset' (CVE-2021-3546) Date: Thu, 27 May 2021 16:23:24 +0200 Message-Id: <20210527142340.1352791-8-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Prasad J Pandit , "Michael S. Tsirkin" , Cornelia Huck , Li Qiang , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Li Qiang If 'virgl_cmd_get_capset' set 'max_size' to 0, the 'virgl_renderer_fill_caps' will write the data after the 'resp'. This patch avoid this by checking the returned 'max_size'. virtio-gpu fix: abd7f08b23 ("display: virtio-gpu-3d: check virgl capabilities max_size") Fixes: CVE-2021-3546 Reported-by: Li Qiang Reviewed-by: Prasad J Pandit Signed-off-by: Li Qiang Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20210516030403.107723-8-liq3ea@163.com> Signed-off-by: Gerd Hoffmann --- contrib/vhost-user-gpu/virgl.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c index a16a311d80df..7172104b19d7 100644 --- a/contrib/vhost-user-gpu/virgl.c +++ b/contrib/vhost-user-gpu/virgl.c @@ -177,6 +177,10 @@ virgl_cmd_get_capset(VuGpu *g, =20 virgl_renderer_get_cap_set(gc.capset_id, &max_ver, &max_size); + if (!max_size) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; + return; + } resp =3D g_malloc0(sizeof(*resp) + max_size); =20 resp->hdr.type =3D VIRTIO_GPU_RESP_OK_CAPSET; --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622126016; cv=none; d=zohomail.com; s=zohoarc; b=DPgmeLhkFGboNRYoJpYmQx/fU2sXoS3ZJ/6V0jej043t0rpmUlfP4ciof2vnKs3zsP/7FhfmNMX2rwrqWVA4SjV61NHb8rCzWf8wOAKRYRBcDy48R4FToSuJVAcNtFVIVojUEu9CBGbXntJQDsTMoGSqZ08RNzXfmcEB1xXy4eo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622126016; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SpLOsHH0UTxbPG+vlTr/yNyU013X8CCW8KPm4t7J9Uo=; b=fq6xDIQZRhKsZfAayI42ZpAZR2koXVbanOImOgicU+zDluiOQDikm2Zv26fqOL/cmVZeEeeVSkIjXn8Zk3eUx47SNuxTYUu53b/Uplw6l/2T9RLHpZ4/7xsmg9AVOhWdlVfBYjoIp/o25fv06FmL32eOS91zzD8pZbCM6+X+nY8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622126016441491.81484565347523; Thu, 27 May 2021 07:33:36 -0700 (PDT) Received: from localhost ([::1]:57556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmH4p-0007sD-Ia for importer2@patchew.org; Thu, 27 May 2021 10:33:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34132) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwB-0006tR-Fd for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46184) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGw8-0004ap-Sn for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:39 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-208-DSO2L9O7Pb6jSGzuH-sIOQ-1; Thu, 27 May 2021 10:24:34 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 514BC8049C5; Thu, 27 May 2021 14:24:33 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6439F59479; Thu, 27 May 2021 14:24:23 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 5A0DE1800844; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125476; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SpLOsHH0UTxbPG+vlTr/yNyU013X8CCW8KPm4t7J9Uo=; b=HZxnrLxwq7vcjFMvAFQrJXsaBlbgnIj8XN4J3ijmpt5f2AiEyJBQR83kxRCTy19YbqOIzT b+2YpE+tQGF7KajRyMbS64bYqSrLjeHSc2TfTmuQw5HebV6MkAU/fiAWW0l6X/qqW05zEQ z7+zK/sZXmhHEvSMAQy3fLd+FdiOedY= X-MC-Unique: DSO2L9O7Pb6jSGzuH-sIOQ-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 08/23] vhost-user-gpu: abstract vg_cleanup_mapping_iov Date: Thu, 27 May 2021 16:23:25 +0200 Message-Id: <20210527142340.1352791-9-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Li Qiang , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Li Qiang Currently in vhost-user-gpu, we free resource directly in the cleanup case of resource. If we change the cleanup logic we need to change several places, also abstruct a 'vg_create_mapping_iov' can be symmetry with the 'vg_create_mapping_iov'. This is like what virtio-gpu does, no function changed. Signed-off-by: Li Qiang Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20210516030403.107723-9-liq3ea@163.com> Signed-off-by: Gerd Hoffmann --- contrib/vhost-user-gpu/vugpu.h | 2 +- contrib/vhost-user-gpu/vhost-user-gpu.c | 24 ++++++++++++++++++++---- contrib/vhost-user-gpu/virgl.c | 9 +++++---- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/contrib/vhost-user-gpu/vugpu.h b/contrib/vhost-user-gpu/vugpu.h index 04d56158123d..e2864bba68e0 100644 --- a/contrib/vhost-user-gpu/vugpu.h +++ b/contrib/vhost-user-gpu/vugpu.h @@ -169,7 +169,7 @@ int vg_create_mapping_iov(VuGpu *g, struct virtio_gpu_resource_attach_backing *a= b, struct virtio_gpu_ctrl_command *cmd, struct iovec **iov); - +void vg_cleanup_mapping_iov(VuGpu *g, struct iovec *iov, uint32_t count= ); void vg_get_display_info(VuGpu *vg, struct virtio_gpu_ctrl_command *cmd= ); =20 void vg_wait_ok(VuGpu *g); diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-g= pu/vhost-user-gpu.c index 770dfad52989..6dc6a44f4e26 100644 --- a/contrib/vhost-user-gpu/vhost-user-gpu.c +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c @@ -49,6 +49,8 @@ static char *opt_render_node; static gboolean opt_virgl; =20 static void vg_handle_ctrl(VuDev *dev, int qidx); +static void vg_cleanup_mapping(VuGpu *g, + struct virtio_gpu_simple_resource *res); =20 static const char * vg_cmd_to_string(int cmd) @@ -400,7 +402,7 @@ vg_resource_destroy(VuGpu *g, } =20 vugbm_buffer_destroy(&res->buffer); - g_free(res->iov); + vg_cleanup_mapping(g, res); pixman_image_unref(res->image); QTAILQ_REMOVE(&g->reslist, res, next); g_free(res); @@ -504,6 +506,22 @@ vg_resource_attach_backing(VuGpu *g, res->iov_cnt =3D ab.nr_entries; } =20 +/* Though currently only free iov, maybe later will do more work. */ +void vg_cleanup_mapping_iov(VuGpu *g, + struct iovec *iov, uint32_t count) +{ + g_free(iov); +} + +static void +vg_cleanup_mapping(VuGpu *g, + struct virtio_gpu_simple_resource *res) +{ + vg_cleanup_mapping_iov(g, res->iov, res->iov_cnt); + res->iov =3D NULL; + res->iov_cnt =3D 0; +} + static void vg_resource_detach_backing(VuGpu *g, struct virtio_gpu_ctrl_command *cmd) @@ -522,9 +540,7 @@ vg_resource_detach_backing(VuGpu *g, return; } =20 - g_free(res->iov); - res->iov =3D NULL; - res->iov_cnt =3D 0; + vg_cleanup_mapping(g, res); } =20 static void diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c index 7172104b19d7..3e45e1bd3360 100644 --- a/contrib/vhost-user-gpu/virgl.c +++ b/contrib/vhost-user-gpu/virgl.c @@ -116,8 +116,9 @@ virgl_cmd_resource_unref(VuGpu *g, virgl_renderer_resource_detach_iov(unref.resource_id, &res_iovs, &num_iovs); - g_free(res_iovs); - + if (res_iovs !=3D NULL && num_iovs !=3D 0) { + vg_cleanup_mapping_iov(g, res_iovs, num_iovs); + } virgl_renderer_resource_unref(unref.resource_id); } =20 @@ -294,7 +295,7 @@ virgl_resource_attach_backing(VuGpu *g, ret =3D virgl_renderer_resource_attach_iov(att_rb.resource_id, res_iovs, att_rb.nr_entries); if (ret !=3D 0) { - g_free(res_iovs); + vg_cleanup_mapping_iov(g, res_iovs, att_rb.nr_entries); } } =20 @@ -314,7 +315,7 @@ virgl_resource_detach_backing(VuGpu *g, if (res_iovs =3D=3D NULL || num_iovs =3D=3D 0) { return; } - g_free(res_iovs); + vg_cleanup_mapping_iov(g, res_iovs, num_iovs); } =20 static void --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622125813; cv=none; d=zohomail.com; s=zohoarc; b=QPqvzIk2EJqNxiiPkoYfLzrKqp0Lsjg63f4s/GKh0GZTh2Eh8wzKRcYN6+OB6Ptso1zXRfHrauYIefdNQLkbs50kODbGrjHbaportwXFanWE4mpYwSAuwRlcKrhJRuOPOpD0GXp5UehWjmlCXLXBgXAxuRhvd63mFu/p2FrphQ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622125813; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3Y0Ewjajw+kfrLoPlpe9S8MT/fRQyJvS61wf8vVT4xo=; b=AF9IJ5UP0kz88MJfy/QFcOFR/sYZrl8g92/zQBjnzzn9xO0cPA3aKwHEEZ5GT+7obnfPRpEseFfj18Z/y6k+eIKBBAWucmt6Fql/RDNcpxXLxz7FIFpl/VMJ38MO2TwcoBtWpM0Hel0VyiNxX+oZjWHfrN1Z0MuD6UlHB+rgQ3U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622125813809758.1003149106244; Thu, 27 May 2021 07:30:13 -0700 (PDT) Received: from localhost ([::1]:47036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmH1Y-0000j5-ID for importer2@patchew.org; Thu, 27 May 2021 10:30:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwT-000853-OT for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29313) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwS-0004pl-4T for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:57 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-417-6DeODLQ_OuqoIHtOhDhSgw-1; Thu, 27 May 2021 10:24:45 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AC395100960E; Thu, 27 May 2021 14:24:44 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8F2EA5C701; Thu, 27 May 2021 14:24:34 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 64AE61800845; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125495; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3Y0Ewjajw+kfrLoPlpe9S8MT/fRQyJvS61wf8vVT4xo=; b=QzkVLViTY2L3cUHKt0y4uaCZb0p1rNe2zVUJs6Ei588i9pX0EKMoDlowHmLEHP9HN/O5yh w3t8U1nb+6tngTVT/FsvIOOaKajc+GWSBNJmHQ6Qj/iN052AejSwxRrmO5Tmo99Cx5whgq QI5YA6K03LuEnj7mxmfyhbGs6QW8WCg= X-MC-Unique: 6DeODLQ_OuqoIHtOhDhSgw-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 09/23] hw/display/qxl: Set pci rom address aligned with page size Date: Thu, 27 May 2021 16:23:26 +0200 Message-Id: <20210527142340.1352791-10-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , maobibo , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: maobibo On some MIPS system, page size is 16K, and qxl vga device can be used for VM in kvm mode. Qxl pci rom size is set 8K fixed, smaller than 16K page size on host system, it fails to be added into memslots in kvm mode where memory_size and GPA are required to align with page size. This patch fixes this issue. Signed-off-by: Bibo Mao Message-Id: <1621340448-31617-1-git-send-email-maobibo@loongson.cn> Signed-off-by: Gerd Hoffmann --- hw/display/qxl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/display/qxl.c b/hw/display/qxl.c index 2ba75637ec30..6e1f8ff1b2a7 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -321,7 +321,7 @@ static ram_addr_t qxl_rom_size(void) #define QXL_ROM_SZ 8192 =20 QEMU_BUILD_BUG_ON(QXL_REQUIRED_SZ > QXL_ROM_SZ); - return QXL_ROM_SZ; + return QEMU_ALIGN_UP(QXL_REQUIRED_SZ, qemu_real_host_page_size); } =20 static void init_qxl_rom(PCIQXLDevice *d) --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622126225; cv=none; d=zohomail.com; s=zohoarc; b=mTxZpJtz/JXfFAmIp4bK26TmKjqoExcrdXj0tWY5AXS3AoWapMdUFrWfv/Jhit/RnC4gal9ybWJU6KA+9Hg1mu6j+/mZRjK2VK2cdRCaf9ho0Gk5NlIKDgpQx1IO14YW/cNXPlCGtOoKmJ6Y+itVhcTQ+Vx10IAbfG1RRoog/Wc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622126225; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uY50HrrozmNGZa3Sj60ePH/E9jzTJPx693fzbpd6jxU=; b=XmIJNj9nsYdpzzxeDO+DSfs3m0019TMlYZ//Dbtn+Jpq/T2WwE58yVVLJviYx0JPG5lil4D4vjL54X+BZR7W4dbSA5mJdGOuCJHDiV9IShQEak2E5eRZz8a0T/Q7XmuYza2hwNcqv+Lv4WF1fTJaunmdPyWj+a7g7cggTy0qZlw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162212622544745.24256921798826; Thu, 27 May 2021 07:37:05 -0700 (PDT) Received: from localhost ([::1]:37876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmH8C-00059N-Bx for importer2@patchew.org; Thu, 27 May 2021 10:37:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwH-0007JH-NQ for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59543) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwG-0004fg-3a for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:45 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-592-XtdC3fOgNX-peQ3M_GE4sw-1; Thu, 27 May 2021 10:24:41 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0D876180FD65; Thu, 27 May 2021 14:24:36 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C3F7B5D9CC; Thu, 27 May 2021 14:24:35 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 733991800846; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125483; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uY50HrrozmNGZa3Sj60ePH/E9jzTJPx693fzbpd6jxU=; b=huLpN17+e1IN5sj4NmFbN6UDeyRgV+DwDmHHQY4SLRQXPcmhp4/SMwXcoWYUCpJVXdaHpx 5+sheIk2Sn3/s0a7nMIf/j0yyjZB8uwJyPzEtcMRm4D4wlEPQEtTIP8Wy6ih2pEZ3RUfRQ An8VCHwVzwagrJuEODG5iM5/xno7Mls= X-MC-Unique: XtdC3fOgNX-peQ3M_GE4sw-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 10/23] ui: Get the fd associated with udmabuf driver Date: Thu, 27 May 2021 16:23:27 +0200 Message-Id: <20210527142340.1352791-11-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Vivek Kasireddy , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vivek Kasireddy Try to open the udmabuf dev node for the first time or return the fd if the device was previously opened. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy Message-Id: <20210526231429.1045476-2-vivek.kasireddy@intel.com> [ kraxel: fixup fcntl.h include ] Signed-off-by: Gerd Hoffmann --- include/ui/console.h | 3 +++ ui/udmabuf.c | 40 ++++++++++++++++++++++++++++++++++++++++ ui/meson.build | 1 + 3 files changed, 44 insertions(+) create mode 100644 ui/udmabuf.c diff --git a/include/ui/console.h b/include/ui/console.h index ca3c7af6a6c8..b30b63976a5a 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -471,4 +471,7 @@ bool vnc_display_reload_certs(const char *id, Error **= errp); /* input.c */ int index_from_key(const char *key, size_t key_length); =20 +/* udmabuf.c */ +int udmabuf_fd(void); + #endif diff --git a/ui/udmabuf.c b/ui/udmabuf.c new file mode 100644 index 000000000000..23abe1e7eb91 --- /dev/null +++ b/ui/udmabuf.c @@ -0,0 +1,40 @@ +/* + * udmabuf helper functions. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "ui/console.h" + +#ifdef CONFIG_LINUX + +#include +#include + +int udmabuf_fd(void) +{ + static bool first =3D true; + static int udmabuf; + + if (!first) { + return udmabuf; + } + first =3D false; + + udmabuf =3D open("/dev/udmabuf", O_RDWR); + if (udmabuf < 0) { + warn_report("open /dev/udmabuf: %s", strerror(errno)); + } + return udmabuf; +} + +#else + +int udmabuf_fd(void) +{ + return -1; +} + +#endif diff --git a/ui/meson.build b/ui/meson.build index b5aed14886cf..a3a187d633ab 100644 --- a/ui/meson.build +++ b/ui/meson.build @@ -12,6 +12,7 @@ softmmu_ss.add(files( 'kbd-state.c', 'keymaps.c', 'qemu-pixman.c', + 'udmabuf.c', )) softmmu_ss.add([spice_headers, files('spice-module.c')]) softmmu_ss.add(when: spice_protocol, if_true: files('vdagent.c')) --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622126105; cv=none; d=zohomail.com; s=zohoarc; b=YPxPidqJu4YeXipqQ1ypj7OacacLKbm+q5QVczTvwJuK/uXQ3nr47sYKU1gEhVz74sl1TTy15WEG5WVb3GGHotaxP2a8a/HYxeqmUGN3QFMObJz2/KmohETXFu5zpc3zQRV84zUSyXbjwuEuSEanRlRnIW2Bah/vAGDLxgi4BYA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622126105; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pOaFZ/OYeiyZ1qgfdSMKyv8V7Hnnlwig2DS1ADn0zY0=; b=J/BncOXZwI1LoRs/1WnTlnGVwko0l6qK0KuZXstEg9jgqHWPegnHhvcAt+mlmfO0JDU89CZ0z325hrqT+RMVBsEZBucoeLZGpUgkM2JU5hQy3lnCY8UVJO8Rjmn9ehoTCSfE7zoOdpfNouqKzUpCnbMwQFiTQDW+uyiBtb89GJc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622126105266825.8330205277545; Thu, 27 May 2021 07:35:05 -0700 (PDT) Received: from localhost ([::1]:34412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmH6F-0002nC-07 for importer2@patchew.org; Thu, 27 May 2021 10:35:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34164) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwG-0007DA-3M for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:36479) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwE-0004du-4f for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:43 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-216-a9UT1JKJOiqehDndjE-VIw-1; Thu, 27 May 2021 10:24:38 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A6B44180FD61; Thu, 27 May 2021 14:24:37 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6BA462BFE4; Thu, 27 May 2021 14:24:37 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 809041800847; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125481; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pOaFZ/OYeiyZ1qgfdSMKyv8V7Hnnlwig2DS1ADn0zY0=; b=ifb6db2yWvM/7UPilTo/guCvclXuCy7FThSjTadFRxL0PhA9nZMG5KlTaKAlF672JCFKDl PvakjM9CZvhV9Ybf87qxSgn09HS2rKxrAYRQMDow51hlbfCfCfseREPdk0CJiCtY1Pg/0W EW8mbyuI++b4p1iakA7ATT21VYdwlg8= X-MC-Unique: a9UT1JKJOiqehDndjE-VIw-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 11/23] headers: Add udmabuf.h Date: Thu, 27 May 2021 16:23:28 +0200 Message-Id: <20210527142340.1352791-12-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Vivek Kasireddy , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vivek Kasireddy This adds udmabuf header to standard headers so that the relevant udmabuf objects can be accessed in subsequent patches. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy Message-Id: <20210526231429.1045476-3-vivek.kasireddy@intel.com> Signed-off-by: Gerd Hoffmann --- include/standard-headers/linux/udmabuf.h | 32 ++++++++++++++++++++++++ scripts/update-linux-headers.sh | 3 +++ 2 files changed, 35 insertions(+) create mode 100644 include/standard-headers/linux/udmabuf.h diff --git a/include/standard-headers/linux/udmabuf.h b/include/standard-he= aders/linux/udmabuf.h new file mode 100644 index 000000000000..e19eb5b5ce75 --- /dev/null +++ b/include/standard-headers/linux/udmabuf.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _LINUX_UDMABUF_H +#define _LINUX_UDMABUF_H + +#include "standard-headers/linux/types.h" + +#define UDMABUF_FLAGS_CLOEXEC 0x01 + +struct udmabuf_create { + uint32_t memfd; + uint32_t flags; + uint64_t offset; + uint64_t size; +}; + +struct udmabuf_create_item { + uint32_t memfd; + uint32_t __pad; + uint64_t offset; + uint64_t size; +}; + +struct udmabuf_create_list { + uint32_t flags; + uint32_t count; + struct udmabuf_create_item list[]; +}; + +#define UDMABUF_CREATE _IOW('u', 0x42, struct udmabuf_create) +#define UDMABUF_CREATE_LIST _IOW('u', 0x43, struct udmabuf_create_list) + +#endif /* _LINUX_UDMABUF_H */ diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers= .sh index 1050e361694f..fea4d6eb655f 100755 --- a/scripts/update-linux-headers.sh +++ b/scripts/update-linux-headers.sh @@ -34,6 +34,7 @@ cp_portable() { if grep '#include' "$f" | grep -v -e 'linux/virtio' \ -e 'linux/types' \ + -e 'linux/ioctl' \ -e 'stdint' \ -e 'linux/if_ether' \ -e 'input-event-codes' \ @@ -66,6 +67,7 @@ cp_portable() { -e 's/__BITS_PER_LONG/HOST_LONG_BITS/' \ -e '/\"drm.h\"/d' \ -e '/sys\/ioctl.h/d' \ + -e '/linux\/ioctl.h/d' \ -e 's/SW_MAX/SW_MAX_/' \ -e 's/atomic_t/int/' \ -e 's/__kernel_long_t/long/' \ @@ -190,6 +192,7 @@ for i in "$tmpdir"/include/linux/*virtio*.h \ "$tmpdir/include/linux/fuse.h" \ "$tmpdir/include/linux/input.h" \ "$tmpdir/include/linux/input-event-codes.h" \ + "$tmpdir/include/linux/udmabuf.h" \ "$tmpdir/include/linux/pci_regs.h" \ "$tmpdir/include/linux/ethtool.h" \ "$tmpdir/include/linux/const.h" \ --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622126291; cv=none; d=zohomail.com; s=zohoarc; b=H4mMGCZMIsDGRCzgARwcAP+0PjhxEmZvKG7lbDrGSvPT8X35eVdkkLDgouCzSKYesfaFSZ0hmtIv/XjO45nKFSaKRnWPLQDxoBZE49nq5yOD0q/OFwd5vixq5u32z+BYzFBzU4My1ZoaJJk2N5Nid+bsvLydJiHAoOBl1rnRTLw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622126291; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=l6nxgyNxfNzPr/r4T7tvV9VeYIkZfn7E4pWpfAp8nI0=; b=Y9JlJi6VhM/NvldIIE7C46XqOEVTeOR545gR5XRa93TYI1VycxCNaBz3K7GVgNC9jOXYBoITka4fA0pVH+fD7xEJI0zOEp4T6diMwc/nqvVU26Le3UmUqkMC3c+KtfdxFzrVSR8xnqbDU7ubhBp7s4YCBktOmTm/g6oPFQeCVR8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622126291409356.7099491892584; Thu, 27 May 2021 07:38:11 -0700 (PDT) Received: from localhost ([::1]:42962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmH9G-0000Bi-95 for importer2@patchew.org; Thu, 27 May 2021 10:38:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwM-0007dD-Oy for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52417) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwI-0004gk-GU for qemu-devel@nongnu.org; Thu, 27 May 2021 10:24:50 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-381-maupDLBaMBCYhhc6kAk8yQ-1; Thu, 27 May 2021 10:24:42 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D0A06100960E; Thu, 27 May 2021 14:24:41 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0EA265D9D3; Thu, 27 May 2021 14:24:39 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 934BC1800849; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125486; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l6nxgyNxfNzPr/r4T7tvV9VeYIkZfn7E4pWpfAp8nI0=; b=F7tm+YXeifvZnu82QnVXLWnW5nuKVQCoaooc7W8QgQ3rfeKGDhV78lFp9Oq/XIdshwd/ni AbTsxnsikNKhG7+gG8s40MzD6sYCqS+D5UWpHU9IT5xsY+pEYBcz2BbTHrawbCZWKtdYwb 13FKa7OVqixqiw2K1cZlEnaOb4ikEqY= X-MC-Unique: maupDLBaMBCYhhc6kAk8yQ-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 12/23] virtio-gpu: Add udmabuf helpers Date: Thu, 27 May 2021 16:23:29 +0200 Message-Id: <20210527142340.1352791-13-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Vivek Kasireddy , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vivek Kasireddy Add helper functions to create a dmabuf for a resource and mmap it. Also, introduce the fields blob and blob_size so that these helpers can start to use them but the full picture will emerge only after adding create_blob API in patch 8 of this series. To be able to create a dmabuf using the udmabuf driver, Qemu needs to be lauched with the memfd memory backend like this: qemu-system-x86_64 -m 8192m -object memory-backend-memfd,id=3Dmem1,size=3D8= 192M -machine memory-backend=3Dmem1 Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy Message-Id: <20210526231429.1045476-4-vivek.kasireddy@intel.com> Signed-off-by: Gerd Hoffmann --- include/hw/virtio/virtio-gpu.h | 11 +++ hw/display/virtio-gpu-udmabuf.c | 158 ++++++++++++++++++++++++++++++++ hw/display/meson.build | 1 + 3 files changed, 170 insertions(+) create mode 100644 hw/display/virtio-gpu-udmabuf.c diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 8ca2c55d9abb..265b1c516cd1 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -50,6 +50,12 @@ struct virtio_gpu_simple_resource { uint32_t scanout_bitmask; pixman_image_t *image; uint64_t hostmem; + + uint64_t blob_size; + void *blob; + int dmabuf_fd; + uint8_t *remapped; + QTAILQ_ENTRY(virtio_gpu_simple_resource) next; }; =20 @@ -238,6 +244,11 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g, struct virtio_gpu_scanout *s, uint32_t resource_id); =20 +/* virtio-gpu-udmabuf.c */ +bool virtio_gpu_have_udmabuf(void); +void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res); +void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res); + /* virtio-gpu-3d.c */ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd); diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-udmabu= f.c new file mode 100644 index 000000000000..71c4672e327a --- /dev/null +++ b/hw/display/virtio-gpu-udmabuf.c @@ -0,0 +1,158 @@ +/* + * Virtio GPU Device + * + * Copyright Red Hat, Inc. 2013-2014 + * + * Authors: + * Dave Airlie + * Gerd Hoffmann + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "qemu-common.h" +#include "qemu/iov.h" +#include "ui/console.h" +#include "hw/virtio/virtio-gpu.h" +#include "hw/virtio/virtio-gpu-pixman.h" +#include "trace.h" +#include "exec/ramblock.h" +#include "sysemu/hostmem.h" +#include +#include +#include +#include "qemu/memfd.h" +#include "standard-headers/linux/udmabuf.h" + +static void virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *r= es) +{ + struct udmabuf_create_list *list; + RAMBlock *rb; + ram_addr_t offset; + int udmabuf, i; + + udmabuf =3D udmabuf_fd(); + if (udmabuf < 0) { + return; + } + + list =3D g_malloc0(sizeof(struct udmabuf_create_list) + + sizeof(struct udmabuf_create_item) * res->iov_cnt); + + for (i =3D 0; i < res->iov_cnt; i++) { + rcu_read_lock(); + rb =3D qemu_ram_block_from_host(res->iov[i].iov_base, false, &offs= et); + rcu_read_unlock(); + + if (!rb || rb->fd < 0) { + g_free(list); + return; + } + + list->list[i].memfd =3D rb->fd; + list->list[i].offset =3D offset; + list->list[i].size =3D res->iov[i].iov_len; + } + + list->count =3D res->iov_cnt; + list->flags =3D UDMABUF_FLAGS_CLOEXEC; + + res->dmabuf_fd =3D ioctl(udmabuf, UDMABUF_CREATE_LIST, list); + if (res->dmabuf_fd < 0) { + warn_report("%s: UDMABUF_CREATE_LIST: %s", __func__, + strerror(errno)); + } + g_free(list); +} + +static void virtio_gpu_remap_udmabuf(struct virtio_gpu_simple_resource *re= s) +{ + res->remapped =3D mmap(NULL, res->blob_size, PROT_READ, + MAP_SHARED, res->dmabuf_fd, 0); + if (res->remapped =3D=3D MAP_FAILED) { + warn_report("%s: dmabuf mmap failed: %s", __func__, + strerror(errno)); + res->remapped =3D NULL; + } +} + +static void virtio_gpu_destroy_udmabuf(struct virtio_gpu_simple_resource *= res) +{ + if (res->remapped) { + munmap(res->remapped, res->blob_size); + res->remapped =3D NULL; + } + if (res->dmabuf_fd >=3D 0) { + close(res->dmabuf_fd); + res->dmabuf_fd =3D -1; + } +} + +static int find_memory_backend_type(Object *obj, void *opaque) +{ + bool *memfd_backend =3D opaque; + int ret; + + if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) { + HostMemoryBackend *backend =3D MEMORY_BACKEND(obj); + RAMBlock *rb =3D backend->mr.ram_block; + + if (rb && rb->fd > 0) { + ret =3D fcntl(rb->fd, F_GET_SEALS); + if (ret > 0) { + *memfd_backend =3D true; + } + } + } + + return 0; +} + +bool virtio_gpu_have_udmabuf(void) +{ + Object *memdev_root; + int udmabuf; + bool memfd_backend =3D false; + + udmabuf =3D udmabuf_fd(); + if (udmabuf < 0) { + return false; + } + + memdev_root =3D object_resolve_path("/objects", NULL); + object_child_foreach(memdev_root, find_memory_backend_type, &memfd_bac= kend); + + return memfd_backend; +} + +void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res) +{ + void *pdata =3D NULL; + + res->dmabuf_fd =3D -1; + if (res->iov_cnt =3D=3D 1) { + pdata =3D res->iov[0].iov_base; + } else { + virtio_gpu_create_udmabuf(res); + if (res->dmabuf_fd < 0) { + return; + } + virtio_gpu_remap_udmabuf(res); + if (!res->remapped) { + return; + } + pdata =3D res->remapped; + } + + res->blob =3D pdata; +} + +void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res) +{ + if (res->remapped) { + virtio_gpu_destroy_udmabuf(res); + } +} diff --git a/hw/display/meson.build b/hw/display/meson.build index aaf797c5e9ee..e1f473c1dff5 100644 --- a/hw/display/meson.build +++ b/hw/display/meson.build @@ -56,6 +56,7 @@ if config_all_devices.has_key('CONFIG_VIRTIO_GPU') virtio_gpu_ss =3D ss.source_set() virtio_gpu_ss.add(when: 'CONFIG_VIRTIO_GPU', if_true: [files('virtio-gpu-base.c', 'virtio-gpu.c'), = pixman]) + virtio_gpu_ss.add(when: 'CONFIG_LINUX', if_true: files('virtio-gpu-udmab= uf.c')) virtio_gpu_ss.add(when: 'CONFIG_VHOST_USER_GPU', if_true: files('vhost-u= ser-gpu.c')) hw_display_modules +=3D {'virtio-gpu': virtio_gpu_ss} =20 --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622125767; cv=none; d=zohomail.com; s=zohoarc; b=SgjPwmmQSQaKnBRR7dVohCLaPHj7jGq4S6+TPld5B1SCc4Yk34ZXSjNx+k/yKYUvI3k2y6DR+ijFyP33DPA+/3xT/UOG6er98jkL0Hq3w1Mo9at/PvhRklMVbj+9hPRQJjkCgLlpn2+7fYcRyYQ68df/ftpM7aSnwKSW3GblmYc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622125767; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yryjHAhtoL78ycnVCb8yiifgJPX6deYLjQWuBxbxqpc=; b=Sio9PmI4KBYA+3r3jVOSnEAmuV+mZ4hZQ0bHyojJZgAmnTQllnyKjdYBDeBSDck9aqOzcp3jvgUoIIDhzU2qD3wUvZQtRyd5h9hB2u428/YP5lF1U7n6RmyLZ1RuJjmWmLguHyPnFUyWxEBlZrvl26f0ySDXJ/P5psPuolpep18= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622125767583787.8004395577215; Thu, 27 May 2021 07:29:27 -0700 (PDT) Received: from localhost ([::1]:43724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmH0o-0006vM-Ow for importer2@patchew.org; Thu, 27 May 2021 10:29:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34298) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwY-0008Iy-EW for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40751) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwW-0004rs-17 for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:02 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-532-S4B99iT2MdOaVgZ6JLas6A-1; Thu, 27 May 2021 10:24:57 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6ABD8180FD6A; Thu, 27 May 2021 14:24:56 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 42BBA5D9D3; Thu, 27 May 2021 14:24:43 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id A1DE1180084C; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125499; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yryjHAhtoL78ycnVCb8yiifgJPX6deYLjQWuBxbxqpc=; b=O/F/6IpldWnOiz6jvOB0cxf/L8PWCQEHCBzLSWplXft7gM5pJ06c9uFSSQOSaLEJPSOjTy aMrhfGp7Pl+OdaN8LQ1uYUj34oczjXvYITa4U1zWTixp91gjmEntRLJSJpiMyOP3vSUbYD W2Wo190f11GPopjvzB/sZOszpiBtcsg= X-MC-Unique: S4B99iT2MdOaVgZ6JLas6A-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 13/23] stubs: Add stubs for udmabuf helpers Date: Thu, 27 May 2021 16:23:30 +0200 Message-Id: <20210527142340.1352791-14-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Vivek Kasireddy , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vivek Kasireddy This is needed to ensure that virtio-gpu device works for non-linux builds. Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy Message-Id: <20210526231429.1045476-5-vivek.kasireddy@intel.com> [ kraxel: add virtio-gpu-udmabuf.c stubs only when building system emulation ] Signed-off-by: Gerd Hoffmann --- stubs/virtio-gpu-udmabuf.c | 18 ++++++++++++++++++ meson.build | 2 +- stubs/meson.build | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 stubs/virtio-gpu-udmabuf.c diff --git a/stubs/virtio-gpu-udmabuf.c b/stubs/virtio-gpu-udmabuf.c new file mode 100644 index 000000000000..e962e00d86d3 --- /dev/null +++ b/stubs/virtio-gpu-udmabuf.c @@ -0,0 +1,18 @@ +#include "qemu/osdep.h" +#include "hw/virtio/virtio-gpu.h" + +bool virtio_gpu_have_udmabuf(void) +{ + /* nothing (stub) */ + return false; +} + +void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res) +{ + /* nothing (stub) */ +} + +void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res) +{ + /* nothing (stub) */ +} diff --git a/meson.build b/meson.build index 632b380738d3..9b6d93b8bb44 100644 --- a/meson.build +++ b/meson.build @@ -1899,7 +1899,7 @@ util_ss.add_all(trace_ss) util_ss =3D util_ss.apply(config_all, strict: false) libqemuutil =3D static_library('qemuutil', sources: util_ss.sources() + stub_ss.sources(= ) + genh, - dependencies: [util_ss.dependencies(), m, gli= b, socket, malloc]) + dependencies: [util_ss.dependencies(), m, gli= b, socket, malloc, pixman]) qemuutil =3D declare_dependency(link_with: libqemuutil, sources: genh + version_res) =20 diff --git a/stubs/meson.build b/stubs/meson.build index 3faef16892be..c32d18258538 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -52,6 +52,7 @@ if have_system stub_ss.add(files('semihost.c')) stub_ss.add(files('usb-dev-stub.c')) stub_ss.add(files('xen-hw-stub.c')) + stub_ss.add(files('virtio-gpu-udmabuf.c')) else stub_ss.add(files('qdev.c')) endif --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622125993; cv=none; d=zohomail.com; s=zohoarc; b=QMkj652uvg/KL1diJb4BXBYyb5OfN0te1Eg3Jnz6ZxVk19ulZBjmUmyhXSE0Vx1yBIsuUcs40ap4kecgIWtOLprpdeFopOlVAYjzzmb1hwAb91F39XqRnQPZv82gA3sDki+ybB3TZa9/eh8+Svtym4RJEHZp0XIndh00l34L6qc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622125993; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QDKgwESQNukt/7NxGjyjtajbD8oiZ2DXHMu5o7DxSSw=; b=DtSpq/db1HIBDbJy6mfHBue8gf3lF4ifI0v+3j+WRXTlGhCzzS/qrRayOz/6BaEC34m19KRE84pd95ZiGYry3gKR6+ctxpq0pXx7IqcOyrvEbT/Yw+iv5Svn1L87nb3hWoM9OHfwYm5mfR/z2a/ZfNIrk+RspNyyae+wHcMgV2E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622125993233430.4028617471133; Thu, 27 May 2021 07:33:13 -0700 (PDT) Received: from localhost ([::1]:55696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmH4S-0006cL-Cm for importer2@patchew.org; Thu, 27 May 2021 10:33:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34320) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwc-00006s-R9 for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56590) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwb-0004uA-0e for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:06 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-152-jtFm1fzbPsWe8DrOv5BVNg-1; Thu, 27 May 2021 10:25:01 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8FF7E100A241; Thu, 27 May 2021 14:25:00 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 376D65B684; Thu, 27 May 2021 14:24:46 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id ADE48180084E; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125504; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QDKgwESQNukt/7NxGjyjtajbD8oiZ2DXHMu5o7DxSSw=; b=OYIviXdCoUb9qTEAIBznrHb3OTHXXPsuJK9yTiZ/6rytvMxX5Hh3+1l1P0gKXdX7KFJCR3 SYNdw9mRNIOqg2ZMzrIzR2x1klELrWC0nKEAuJy49K1vony0UzT9WcNPVufbRddBja+E3x 2Zi/+TvGkH2dnYF288LgEE1iQXoCzUs= X-MC-Unique: jtFm1fzbPsWe8DrOv5BVNg-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 14/23] virtio-gpu: Add virtio_gpu_find_check_resource Date: Thu, 27 May 2021 16:23:31 +0200 Message-Id: <20210527142340.1352791-15-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Vivek Kasireddy , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vivek Kasireddy Move finding the resource and validating its backing storage into one function. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy Message-Id: <20210526231429.1045476-6-vivek.kasireddy@intel.com> Signed-off-by: Gerd Hoffmann --- hw/display/virtio-gpu.c | 66 +++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index db56f0454a8a..7b5296f0d088 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -35,6 +35,10 @@ =20 static struct virtio_gpu_simple_resource* virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id); +static struct virtio_gpu_simple_resource * +virtio_gpu_find_check_resource(VirtIOGPU *g, uint32_t resource_id, + bool require_backing, + const char *caller, uint32_t *error); =20 static void virtio_gpu_cleanup_mapping(VirtIOGPU *g, struct virtio_gpu_simple_resource *= res); @@ -46,7 +50,8 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g, struct virtio_gpu_simple_resource *res; uint32_t pixels; =20 - res =3D virtio_gpu_find_resource(g, resource_id); + res =3D virtio_gpu_find_check_resource(g, resource_id, false, + __func__, NULL); if (!res) { return; } @@ -114,6 +119,37 @@ virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resour= ce_id) return NULL; } =20 +static struct virtio_gpu_simple_resource * +virtio_gpu_find_check_resource(VirtIOGPU *g, uint32_t resource_id, + bool require_backing, + const char *caller, uint32_t *error) +{ + struct virtio_gpu_simple_resource *res; + + res =3D virtio_gpu_find_resource(g, resource_id); + if (!res) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid resource specified %d\= n", + caller, resource_id); + if (error) { + *error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; + } + return NULL; + } + + if (require_backing) { + if (!res->iov || !res->image) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: no backing storage %d\n", + caller, resource_id); + if (error) { + *error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + } + return NULL; + } + } + + return res; +} + void virtio_gpu_ctrl_response(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd, struct virtio_gpu_ctrl_hdr *resp, @@ -352,11 +388,9 @@ static void virtio_gpu_transfer_to_host_2d(VirtIOGPU *= g, virtio_gpu_t2d_bswap(&t2d); trace_virtio_gpu_cmd_res_xfer_toh_2d(t2d.resource_id); =20 - res =3D virtio_gpu_find_resource(g, t2d.resource_id); - if (!res || !res->iov) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal resource specified %d\= n", - __func__, t2d.resource_id); - cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; + res =3D virtio_gpu_find_check_resource(g, t2d.resource_id, true, + __func__, &cmd->error); + if (!res) { return; } =20 @@ -410,11 +444,9 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g, trace_virtio_gpu_cmd_res_flush(rf.resource_id, rf.r.width, rf.r.height, rf.r.x, rf.r.y= ); =20 - res =3D virtio_gpu_find_resource(g, rf.resource_id); + res =3D virtio_gpu_find_check_resource(g, rf.resource_id, false, + __func__, &cmd->error); if (!res) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal resource specified %d\= n", - __func__, rf.resource_id); - cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; return; } =20 @@ -497,11 +529,9 @@ static void virtio_gpu_set_scanout(VirtIOGPU *g, } =20 /* create a surface for this scanout */ - res =3D virtio_gpu_find_resource(g, ss.resource_id); + res =3D virtio_gpu_find_check_resource(g, ss.resource_id, true, + __func__, &cmd->error); if (!res) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal resource specified %d\= n", - __func__, ss.resource_id); - cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; return; } =20 @@ -709,11 +739,9 @@ virtio_gpu_resource_detach_backing(VirtIOGPU *g, virtio_gpu_bswap_32(&detach, sizeof(detach)); trace_virtio_gpu_cmd_res_back_detach(detach.resource_id); =20 - res =3D virtio_gpu_find_resource(g, detach.resource_id); - if (!res || !res->iov) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal resource specified %d\= n", - __func__, detach.resource_id); - cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; + res =3D virtio_gpu_find_check_resource(g, detach.resource_id, true, + __func__, &cmd->error); + if (!res) { return; } virtio_gpu_cleanup_mapping(g, res); --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622126385; cv=none; d=zohomail.com; s=zohoarc; b=WmOCxe+Y7ELHgPNQXraUnMRnfORbq7CPlrZBAc3qpRU6hgp1a2OwYAC0KVdlxxgKLK69KlCqEJvdlFUA37BG2cHtOss5Gc27zFGR921urZYhD+FicXU0WGs2XhYjBD/N5TXO5xJ3Hr4ZTQPSYle9MxVF6vaSMmqqJwSzNy4acGA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622126385; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LlmpN+ezPbbvbh0veq5klpEiwrK/omsrUtmL1EkjQ68=; b=UsCGmV+TfnGPepHuDFdP93yrqhXiry3caEYkfByNfYUrrE72/k9yYQ++63PRy8mgySeZ9bDQR90IOkSNOSjes4eyxh3QDemlueFStU0zNTqz3MgWiWCq4WzvAvZlLy0iSPMxQWpEnJ5CCM34wsQxME73foUMckTkOlAsdeRme+Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622126385813168.12813326930723; Thu, 27 May 2021 07:39:45 -0700 (PDT) Received: from localhost ([::1]:49870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmHAm-0004qj-Ov for importer2@patchew.org; Thu, 27 May 2021 10:39:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34384) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwy-0000xO-Go for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43364) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwr-000546-P3 for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:25 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-295-ivz4k3hyNYypiPvrRjnL9w-1; Thu, 27 May 2021 10:25:18 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 468C4801817; Thu, 27 May 2021 14:25:17 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F12CD5945E; Thu, 27 May 2021 14:24:57 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id BC6801800853; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125520; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LlmpN+ezPbbvbh0veq5klpEiwrK/omsrUtmL1EkjQ68=; b=iZflPYH1DdpYuwfj8blcG926y8rwNf/5NKGrT9ucbN6KaJmhobW0QPE83cvlvOEKBQVaFz H84Flr/YOIrysYi7KVSeX6xx6xyhfAjwEeGraGXVfuT0jAhipvZjuu+I0i8M4JBhuT0hBl VaWXOXSRzz5Co+fPXWCoP8CNplPOqfE= X-MC-Unique: ivz4k3hyNYypiPvrRjnL9w-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 15/23] virtio-gpu: Refactor virtio_gpu_set_scanout Date: Thu, 27 May 2021 16:23:32 +0200 Message-Id: <20210527142340.1352791-16-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Vivek Kasireddy , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vivek Kasireddy Store the meta-data associated with a FB in a new object (struct virtio_gpu_framebuffer) and pass the object to set_scanout. Also move code in set_scanout into a do_set_scanout function. This will be helpful when adding set_scanout_blob API. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy Message-Id: <20210526231429.1045476-7-vivek.kasireddy@intel.com> Signed-off-by: Gerd Hoffmann --- include/hw/virtio/virtio-gpu.h | 8 ++ hw/display/virtio-gpu.c | 153 +++++++++++++++++++-------------- 2 files changed, 96 insertions(+), 65 deletions(-) diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 265b1c516cd1..b83a91a67f3a 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -59,6 +59,14 @@ struct virtio_gpu_simple_resource { QTAILQ_ENTRY(virtio_gpu_simple_resource) next; }; =20 +struct virtio_gpu_framebuffer { + pixman_format_code_t format; + uint32_t bytes_pp; + uint32_t width, height; + uint32_t stride; + uint32_t offset; +}; + struct virtio_gpu_scanout { QemuConsole *con; DisplaySurface *ds; diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 7b5296f0d088..fdcedfc61e54 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -500,95 +500,118 @@ static void virtio_unref_resource(pixman_image_t *im= age, void *data) pixman_image_unref(data); } =20 -static void virtio_gpu_set_scanout(VirtIOGPU *g, - struct virtio_gpu_ctrl_command *cmd) +static void virtio_gpu_do_set_scanout(VirtIOGPU *g, + uint32_t scanout_id, + struct virtio_gpu_framebuffer *fb, + struct virtio_gpu_simple_resource *r= es, + struct virtio_gpu_rect *r, + uint32_t *error) { - struct virtio_gpu_simple_resource *res, *ores; + struct virtio_gpu_simple_resource *ores; struct virtio_gpu_scanout *scanout; - pixman_format_code_t format; - uint32_t offset; - int bpp; - struct virtio_gpu_set_scanout ss; + uint8_t *data; =20 - VIRTIO_GPU_FILL_CMD(ss); - virtio_gpu_bswap_32(&ss, sizeof(ss)); - trace_virtio_gpu_cmd_set_scanout(ss.scanout_id, ss.resource_id, - ss.r.width, ss.r.height, ss.r.x, ss.r= .y); - - if (ss.scanout_id >=3D g->parent_obj.conf.max_outputs) { + if (scanout_id >=3D g->parent_obj.conf.max_outputs) { qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal scanout id specified %= d", - __func__, ss.scanout_id); - cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID; + __func__, scanout_id); + *error =3D VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID; + return; + } + scanout =3D &g->parent_obj.scanout[scanout_id]; + + if (r->x > fb->width || + r->y > fb->height || + r->width < 16 || + r->height < 16 || + r->width > fb->width || + r->height > fb->height || + r->x + r->width > fb->width || + r->y + r->height > fb->height) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal scanout %d bounds for" + " resource %d, rect (%d,%d)+%d,%d, fb %d %d\n", + __func__, scanout_id, res->resource_id, + r->x, r->y, r->width, r->height, + fb->width, fb->height); + *error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; return; } =20 g->parent_obj.enable =3D 1; - if (ss.resource_id =3D=3D 0) { - virtio_gpu_disable_scanout(g, ss.scanout_id); - return; - } + data =3D (uint8_t *)pixman_image_get_data(res->image); =20 /* create a surface for this scanout */ - res =3D virtio_gpu_find_check_resource(g, ss.resource_id, true, - __func__, &cmd->error); - if (!res) { - return; - } - - if (ss.r.x > res->width || - ss.r.y > res->height || - ss.r.width < 16 || - ss.r.height < 16 || - ss.r.width > res->width || - ss.r.height > res->height || - ss.r.x + ss.r.width > res->width || - ss.r.y + ss.r.height > res->height) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal scanout %d bounds for" - " resource %d, (%d,%d)+%d,%d vs %d %d\n", - __func__, ss.scanout_id, ss.resource_id, ss.r.x, ss.= r.y, - ss.r.width, ss.r.height, res->width, res->height); - cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; - return; - } - - scanout =3D &g->parent_obj.scanout[ss.scanout_id]; - - format =3D pixman_image_get_format(res->image); - bpp =3D DIV_ROUND_UP(PIXMAN_FORMAT_BPP(format), 8); - offset =3D (ss.r.x * bpp) + ss.r.y * pixman_image_get_stride(res->imag= e); - if (!scanout->ds || surface_data(scanout->ds) - !=3D ((uint8_t *)pixman_image_get_data(res->image) + offset) || - scanout->width !=3D ss.r.width || - scanout->height !=3D ss.r.height) { + if (!scanout->ds || + surface_data(scanout->ds) !=3D data + fb->offset || + scanout->width !=3D r->width || + scanout->height !=3D r->height) { pixman_image_t *rect; - void *ptr =3D (uint8_t *)pixman_image_get_data(res->image) + offse= t; - rect =3D pixman_image_create_bits(format, ss.r.width, ss.r.height,= ptr, - pixman_image_get_stride(res->image= )); - pixman_image_ref(res->image); - pixman_image_set_destroy_function(rect, virtio_unref_resource, - res->image); + void *ptr =3D data + fb->offset; + rect =3D pixman_image_create_bits(fb->format, r->width, r->height, + ptr, fb->stride); + + if (res->image) { + pixman_image_ref(res->image); + pixman_image_set_destroy_function(rect, virtio_unref_resource, + res->image); + } + /* realloc the surface ptr */ scanout->ds =3D qemu_create_displaysurface_pixman(rect); if (!scanout->ds) { - cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + *error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; return; } + pixman_image_unref(rect); - dpy_gfx_replace_surface(g->parent_obj.scanout[ss.scanout_id].con, + dpy_gfx_replace_surface(g->parent_obj.scanout[scanout_id].con, scanout->ds); } =20 ores =3D virtio_gpu_find_resource(g, scanout->resource_id); if (ores) { - ores->scanout_bitmask &=3D ~(1 << ss.scanout_id); + ores->scanout_bitmask &=3D ~(1 << scanout_id); } =20 - res->scanout_bitmask |=3D (1 << ss.scanout_id); - scanout->resource_id =3D ss.resource_id; - scanout->x =3D ss.r.x; - scanout->y =3D ss.r.y; - scanout->width =3D ss.r.width; - scanout->height =3D ss.r.height; + res->scanout_bitmask |=3D (1 << scanout_id); + scanout->resource_id =3D res->resource_id; + scanout->x =3D r->x; + scanout->y =3D r->y; + scanout->width =3D r->width; + scanout->height =3D r->height; +} + +static void virtio_gpu_set_scanout(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + struct virtio_gpu_simple_resource *res; + struct virtio_gpu_framebuffer fb =3D { 0 }; + struct virtio_gpu_set_scanout ss; + + VIRTIO_GPU_FILL_CMD(ss); + virtio_gpu_bswap_32(&ss, sizeof(ss)); + trace_virtio_gpu_cmd_set_scanout(ss.scanout_id, ss.resource_id, + ss.r.width, ss.r.height, ss.r.x, ss.r= .y); + + if (ss.resource_id =3D=3D 0) { + virtio_gpu_disable_scanout(g, ss.scanout_id); + return; + } + + res =3D virtio_gpu_find_check_resource(g, ss.resource_id, true, + __func__, &cmd->error); + if (!res) { + return; + } + + fb.format =3D pixman_image_get_format(res->image); + fb.bytes_pp =3D DIV_ROUND_UP(PIXMAN_FORMAT_BPP(fb.format), 8); + fb.width =3D pixman_image_get_width(res->image); + fb.height =3D pixman_image_get_height(res->image); + fb.stride =3D pixman_image_get_stride(res->image); + fb.offset =3D ss.r.x * fb.bytes_pp + ss.r.y * fb.stride; + + virtio_gpu_do_set_scanout(g, ss.scanout_id, + &fb, res, &ss.r, &cmd->error); } =20 int virtio_gpu_create_mapping_iov(VirtIOGPU *g, --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622126177; cv=none; d=zohomail.com; s=zohoarc; b=VuIxDrvN0shXv1hhm/xzRd32+K+vDFVWcd2wpaL7jy8VKkqZ7q+6d/N50hvyrwlqMa7zx/OvcChRiPTrbToXg3Fa9LsW67B6EUfnvj9BpkCiXb3Ij3e3pYCp+j/xG6gqOsGmXBkqb6JunEM1ahH8IR7ezsTfGl98myU7iPcd6K0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622126177; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ECytsFV/tTiY9uCkTge5/fNfz1TkXLsqSjG7TP9obEM=; b=LSB4VnptjWvcAZoOJ+c9FbBHEUnCBFozRCqj7DBk01fQwQ/YHK9NjVypkO0StQ6rT29IOj6AB19hAdRlt0AIbvbdgk8uPTk5HnglonA4Q7mSdvNhdOwBUukpV4CzgHLqZMDje+Xdj+P525LSqfobrtPIl0KXecuo9jFkIxp2dzo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16221261776651022.2158745257171; Thu, 27 May 2021 07:36:17 -0700 (PDT) Received: from localhost ([::1]:36038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmH7Q-0003tS-Es for importer2@patchew.org; Thu, 27 May 2021 10:36:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwu-0000vn-Ml for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30390) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGwq-000543-RR for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:24 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-338-zJ-rxU5INRi3UEATxSE2xw-1; Thu, 27 May 2021 10:25:17 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 94F11180FD65; Thu, 27 May 2021 14:25:16 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0E73F1007606; Thu, 27 May 2021 14:25:02 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id CBC881800854; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125520; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ECytsFV/tTiY9uCkTge5/fNfz1TkXLsqSjG7TP9obEM=; b=TNVcmLr5v0JqVzxSQIb8TEvUxyxYTQ/hAzJH2IxCYxjUIW3m+IcnAUKr1ofhMTbVsWR1/N gVMWVY5Rl5P1uyZBOBAX7hMhkOB0AxIC2tWLSqrloxwrlt9QZjAP2J7QxyKeidA3Njuzqy L2BGAdrlYTfwjhqFO/4ivdW73FSqamo= X-MC-Unique: zJ-rxU5INRi3UEATxSE2xw-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 16/23] virtio-gpu: Refactor virtio_gpu_create_mapping_iov Date: Thu, 27 May 2021 16:23:33 +0200 Message-Id: <20210527142340.1352791-17-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Vivek Kasireddy , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vivek Kasireddy Instead of passing the attach_backing object to extract nr_entries and offset, explicitly pass these as arguments to this function. This will be helpful when adding create_blob API. Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy Message-Id: <20210526231429.1045476-8-vivek.kasireddy@intel.com> Signed-off-by: Gerd Hoffmann --- include/hw/virtio/virtio-gpu.h | 2 +- hw/display/virtio-gpu-virgl.c | 3 ++- hw/display/virtio-gpu.c | 19 +++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index b83a91a67f3a..dad9a1d221f9 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -238,7 +238,7 @@ void virtio_gpu_get_display_info(VirtIOGPU *g, void virtio_gpu_get_edid(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd); int virtio_gpu_create_mapping_iov(VirtIOGPU *g, - struct virtio_gpu_resource_attach_backin= g *ab, + uint32_t nr_entries, uint32_t offset, struct virtio_gpu_ctrl_command *cmd, uint64_t **addr, struct iovec **iov, uint32_t *niov); diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 72c14d91324b..092c6dc380d9 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -289,7 +289,8 @@ static void virgl_resource_attach_backing(VirtIOGPU *g, VIRTIO_GPU_FILL_CMD(att_rb); trace_virtio_gpu_cmd_res_back_attach(att_rb.resource_id); =20 - ret =3D virtio_gpu_create_mapping_iov(g, &att_rb, cmd, NULL, &res_iovs= , &res_niov); + ret =3D virtio_gpu_create_mapping_iov(g, att_rb.nr_entries, sizeof(att= _rb), + cmd, NULL, &res_iovs, &res_niov); if (ret !=3D 0) { cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; return; diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index fdcedfc61e54..7a0db3a8602e 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -615,7 +615,7 @@ static void virtio_gpu_set_scanout(VirtIOGPU *g, } =20 int virtio_gpu_create_mapping_iov(VirtIOGPU *g, - struct virtio_gpu_resource_attach_backin= g *ab, + uint32_t nr_entries, uint32_t offset, struct virtio_gpu_ctrl_command *cmd, uint64_t **addr, struct iovec **iov, uint32_t *niov) @@ -624,17 +624,17 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g, size_t esize, s; int e, v; =20 - if (ab->nr_entries > 16384) { + if (nr_entries > 16384) { qemu_log_mask(LOG_GUEST_ERROR, "%s: nr_entries is too big (%d > 16384)\n", - __func__, ab->nr_entries); + __func__, nr_entries); return -1; } =20 - esize =3D sizeof(*ents) * ab->nr_entries; + esize =3D sizeof(*ents) * nr_entries; ents =3D g_malloc(esize); s =3D iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, - sizeof(*ab), ents, esize); + offset, ents, esize); if (s !=3D esize) { qemu_log_mask(LOG_GUEST_ERROR, "%s: command data size incorrect %zu vs %zu\n", @@ -647,7 +647,7 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g, if (addr) { *addr =3D NULL; } - for (e =3D 0, v =3D 0; e < ab->nr_entries; e++) { + for (e =3D 0, v =3D 0; e < nr_entries; e++) { uint64_t a =3D le64_to_cpu(ents[e].addr); uint32_t l =3D le32_to_cpu(ents[e].length); hwaddr len; @@ -659,8 +659,7 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g, a, &len, DMA_DIRECTION_TO_DEVICE); if (!map) { qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to map MMIO mem= ory for" - " resource %d element %d\n", - __func__, ab->resource_id, e); + " element %d\n", __func__, e); virtio_gpu_cleanup_mapping_iov(g, *iov, v); g_free(ents); *iov =3D NULL; @@ -743,8 +742,8 @@ virtio_gpu_resource_attach_backing(VirtIOGPU *g, return; } =20 - ret =3D virtio_gpu_create_mapping_iov(g, &ab, cmd, &res->addrs, - &res->iov, &res->iov_cnt); + ret =3D virtio_gpu_create_mapping_iov(g, ab.nr_entries, sizeof(ab), cm= d, + &res->addrs, &res->iov, &res->iov_= cnt); if (ret !=3D 0) { cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; return; --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622126313; cv=none; d=zohomail.com; s=zohoarc; b=MqSv7juB+waomBlGWt0/zAbhDu1D0mcfEpiwYoVlqyMl5fgKKs3YN6D0lfN+5q/GYWpMvXLTdTsrObeDWTSxydfisomsW8ClqWtRXtHuK95vPC3RcttYbvpGkfVhXrUDF/987QQ4P9hwKxLxZRwAoOq48dTGZY3qOTbJpPa8gTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622126313; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bSV69lT7H3OzP1ZcG8G8Fqv5wM/aSayOBaTmmMaOXdI=; b=EqkafXqfH0nU6voEiEardJIGu2+Ciji4x1O10etKAzWjN1VfBLn1KQ5hRv8ntPeh177f/NRNJnGdpN4YQlLxzvmHzmhPNjtaTclMCbP75u3qCsPBE20WVkB2FIqw58vql0yev3V5TEwf4SIaaZKSdXK0FvBumBRy4gp38VcIQpU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622126313432212.70972173025064; Thu, 27 May 2021 07:38:33 -0700 (PDT) Received: from localhost ([::1]:44536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmH9a-0001FW-LC for importer2@patchew.org; Thu, 27 May 2021 10:38:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGx9-0000yo-TT for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39969) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGx3-0005Bm-GG for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:37 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-24-VbXVwbzaNQGOYb7R6a56Yg-1; Thu, 27 May 2021 10:25:29 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 85367501E3; Thu, 27 May 2021 14:25:28 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A8445D6D3; Thu, 27 May 2021 14:25:18 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id DB1A81800867; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125531; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bSV69lT7H3OzP1ZcG8G8Fqv5wM/aSayOBaTmmMaOXdI=; b=UpR03s6K6fpWjVzLNFuWvRKWGVY5dYLZpcZDra/OEURK++wtNKz/DM9wllwtSFbJAaOfCU PYeIGeqA7kY78Oir3b+Mz4BkepJCzB7MbhJ4RXSuUO/lAl/lZ5lLkoc0RDG1PpdKpN8j5f PkuDllCX9Dnii6lNW6qzPSt+crTtwL4= X-MC-Unique: VbXVwbzaNQGOYb7R6a56Yg-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 17/23] virtio-gpu: Add initial definitions for blob resources Date: Thu, 27 May 2021 16:23:34 +0200 Message-Id: <20210527142340.1352791-18-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Vivek Kasireddy , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vivek Kasireddy Add the property bit, configuration flag and other relevant macros and definitions associated with this feature. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy Message-Id: <20210526231429.1045476-9-vivek.kasireddy@intel.com> Signed-off-by: Gerd Hoffmann --- include/hw/virtio/virtio-gpu.h | 3 +++ hw/display/virtio-gpu-base.c | 3 +++ hw/display/virtio-gpu.c | 14 ++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index dad9a1d221f9..66e7aaad0e98 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -89,6 +89,7 @@ enum virtio_gpu_base_conf_flags { VIRTIO_GPU_FLAG_STATS_ENABLED, VIRTIO_GPU_FLAG_EDID_ENABLED, VIRTIO_GPU_FLAG_DMABUF_ENABLED, + VIRTIO_GPU_FLAG_BLOB_ENABLED, }; =20 #define virtio_gpu_virgl_enabled(_cfg) \ @@ -99,6 +100,8 @@ enum virtio_gpu_base_conf_flags { (_cfg.flags & (1 << VIRTIO_GPU_FLAG_EDID_ENABLED)) #define virtio_gpu_dmabuf_enabled(_cfg) \ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED)) +#define virtio_gpu_blob_enabled(_cfg) \ + (_cfg.flags & (1 << VIRTIO_GPU_FLAG_BLOB_ENABLED)) =20 struct virtio_gpu_base_conf { uint32_t max_outputs; diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c index afb3ee7d9afc..dd294276cb38 100644 --- a/hw/display/virtio-gpu-base.c +++ b/hw/display/virtio-gpu-base.c @@ -208,6 +208,9 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64= _t features, if (virtio_gpu_edid_enabled(g->conf)) { features |=3D (1 << VIRTIO_GPU_F_EDID); } + if (virtio_gpu_blob_enabled(g->conf)) { + features |=3D (1 << VIRTIO_GPU_F_RESOURCE_BLOB); + } =20 return features; } diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 7a0db3a8602e..f77a7fc7dd21 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -1108,6 +1108,18 @@ void virtio_gpu_device_realize(DeviceState *qdev, Er= ror **errp) VirtIODevice *vdev =3D VIRTIO_DEVICE(qdev); VirtIOGPU *g =3D VIRTIO_GPU(qdev); =20 + if (virtio_gpu_blob_enabled(g->parent_obj.conf)) { + if (!virtio_gpu_have_udmabuf()) { + error_setg(errp, "cannot enable blob resources without udmabuf= "); + return; + } + + if (virtio_gpu_virgl_enabled(g->parent_obj.conf)) { + error_setg(errp, "blobs and virgl are not compatible (yet)"); + return; + } + } + if (!virtio_gpu_base_device_realize(qdev, virtio_gpu_handle_ctrl_cb, virtio_gpu_handle_cursor_cb, @@ -1201,6 +1213,8 @@ static Property virtio_gpu_properties[] =3D { VIRTIO_GPU_BASE_PROPERTIES(VirtIOGPU, parent_obj.conf), DEFINE_PROP_SIZE("max_hostmem", VirtIOGPU, conf_max_hostmem, 256 * MiB), + DEFINE_PROP_BIT("blob", VirtIOGPU, parent_obj.conf.flags, + VIRTIO_GPU_FLAG_BLOB_ENABLED, false), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622125937; cv=none; d=zohomail.com; s=zohoarc; b=AMU489CWxu9jCdZDMc2UvemFeVLIOdhXyVca5BgErzPNT+etyQpRUQAWEg9y67XnWf7kOCTr4zk1yyqFWRahSp/d2UcCWvQkYb5wuwtI8nMh2qE+gNr4M+j9NmDGEwYlMaanIUCBIu7vOkmC/3Vi8Me0Z2Mgh27Ctftf47JLXYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622125937; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iPysXiQ6CM4s11xzDO5i5g9kvmktjyps93pLiHWdoYk=; b=lixBdJCTmrd5dACu4lmKGTfdvOH9rWof8aYzILF7ZNyv0PQSnl0KRrNrkuTcaUPmkhlNUCRUhNiGZWRc48w6cd6GKbCDsSBP7lMa2oqVhlljt2JKLLYhjjaZ+JPZdxrMupA/Y4OipndTLHuQ2eiLxAQBiN29m6mbhXsusyzpYgQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622125937730278.37412396666264; Thu, 27 May 2021 07:32:17 -0700 (PDT) Received: from localhost ([::1]:52366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmH3Y-0004Mw-Uj for importer2@patchew.org; Thu, 27 May 2021 10:32:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGxB-0000zW-2Z for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58759) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGx5-0005ED-4r for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:39 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-36-x9L7xK7uNPGJTmDXhVLIfw-1; Thu, 27 May 2021 10:25:31 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7E91180D683; Thu, 27 May 2021 14:25:30 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC00260864; Thu, 27 May 2021 14:25:18 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id EAEE01800868; Thu, 27 May 2021 16:23:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125534; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iPysXiQ6CM4s11xzDO5i5g9kvmktjyps93pLiHWdoYk=; b=UfIO7c5VVc81KGPGycvtncvE3UN9iAH6gKmdmPF35BgfoOHnAQusygVCftJRTCutQeeQ3h YqpB/Ycau5Y5uXBsMsP7eEZSYrP2SaDckLQK9lZuuxtgYeg9KlbzyRStXJe9j7T4rwrCuZ Kn6jMikcaBWBHeVnqQ5j50aairQKwwE= X-MC-Unique: x9L7xK7uNPGJTmDXhVLIfw-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 18/23] virtio-gpu: Add virtio_gpu_resource_create_blob Date: Thu, 27 May 2021 16:23:35 +0200 Message-Id: <20210527142340.1352791-19-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Vivek Kasireddy , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vivek Kasireddy This API allows Qemu to register the blob allocated by the Guest as a new resource and map its backing storage. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy Message-Id: <20210526231429.1045476-10-vivek.kasireddy@intel.com> Signed-off-by: Gerd Hoffmann --- include/hw/virtio/virtio-gpu-bswap.h | 9 ++++ hw/display/virtio-gpu.c | 73 ++++++++++++++++++++++++++-- hw/display/trace-events | 1 + 3 files changed, 80 insertions(+), 3 deletions(-) diff --git a/include/hw/virtio/virtio-gpu-bswap.h b/include/hw/virtio/virti= o-gpu-bswap.h index 203f9e17189e..d23ac5cc4a06 100644 --- a/include/hw/virtio/virtio-gpu-bswap.h +++ b/include/hw/virtio/virtio-gpu-bswap.h @@ -59,4 +59,13 @@ virtio_gpu_t2d_bswap(struct virtio_gpu_transfer_to_host_= 2d *t2d) le32_to_cpus(&t2d->padding); } =20 +static inline void +virtio_gpu_create_blob_bswap(struct virtio_gpu_resource_create_blob *cblob) +{ + virtio_gpu_ctrl_hdr_bswap(&cblob->hdr); + le32_to_cpus(&cblob->resource_id); + le32_to_cpus(&cblob->blob_flags); + le64_to_cpus(&cblob->size); +} + #endif diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index f77a7fc7dd21..788b4540d5ea 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -137,7 +137,7 @@ virtio_gpu_find_check_resource(VirtIOGPU *g, uint32_t r= esource_id, } =20 if (require_backing) { - if (!res->iov || !res->image) { + if (!res->iov || (!res->image && !res->blob)) { qemu_log_mask(LOG_GUEST_ERROR, "%s: no backing storage %d\n", caller, resource_id); if (error) { @@ -313,6 +313,62 @@ static void virtio_gpu_resource_create_2d(VirtIOGPU *g, g->hostmem +=3D res->hostmem; } =20 +static void virtio_gpu_resource_create_blob(VirtIOGPU *g, + struct virtio_gpu_ctrl_command= *cmd) +{ + struct virtio_gpu_simple_resource *res; + struct virtio_gpu_resource_create_blob cblob; + int ret; + + VIRTIO_GPU_FILL_CMD(cblob); + virtio_gpu_create_blob_bswap(&cblob); + trace_virtio_gpu_cmd_res_create_blob(cblob.resource_id, cblob.size); + + if (cblob.resource_id =3D=3D 0) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: resource id 0 is not allowed\n= ", + __func__); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; + return; + } + + res =3D virtio_gpu_find_resource(g, cblob.resource_id); + if (res) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: resource already exists %d\n", + __func__, cblob.resource_id); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; + return; + } + + res =3D g_new0(struct virtio_gpu_simple_resource, 1); + res->resource_id =3D cblob.resource_id; + res->blob_size =3D cblob.size; + + if (cblob.blob_mem !=3D VIRTIO_GPU_BLOB_MEM_GUEST && + cblob.blob_flags !=3D VIRTIO_GPU_BLOB_FLAG_USE_SHAREABLE) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid memory type\n", + __func__); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; + g_free(res); + return; + } + + if (res->iov) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + return; + } + + ret =3D virtio_gpu_create_mapping_iov(g, cblob.nr_entries, sizeof(cblo= b), + cmd, &res->addrs, &res->iov, + &res->iov_cnt); + if (ret !=3D 0) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + return; + } + + virtio_gpu_init_udmabuf(res); + QTAILQ_INSERT_HEAD(&g->reslist, res, next); +} + static void virtio_gpu_disable_scanout(VirtIOGPU *g, int scanout_id) { struct virtio_gpu_scanout *scanout =3D &g->parent_obj.scanout[scanout_= id]; @@ -390,7 +446,7 @@ static void virtio_gpu_transfer_to_host_2d(VirtIOGPU *g, =20 res =3D virtio_gpu_find_check_resource(g, t2d.resource_id, true, __func__, &cmd->error); - if (!res) { + if (!res || res->blob) { return; } =20 @@ -446,7 +502,7 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g, =20 res =3D virtio_gpu_find_check_resource(g, rf.resource_id, false, __func__, &cmd->error); - if (!res) { + if (!res || res->blob) { return; } =20 @@ -715,6 +771,10 @@ static void virtio_gpu_cleanup_mapping(VirtIOGPU *g, res->iov_cnt =3D 0; g_free(res->addrs); res->addrs =3D NULL; + + if (res->blob) { + virtio_gpu_fini_udmabuf(res); + } } =20 static void @@ -785,6 +845,13 @@ void virtio_gpu_simple_process_cmd(VirtIOGPU *g, case VIRTIO_GPU_CMD_RESOURCE_CREATE_2D: virtio_gpu_resource_create_2d(g, cmd); break; + case VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB: + if (!virtio_gpu_blob_enabled(g->parent_obj.conf)) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; + break; + } + virtio_gpu_resource_create_blob(g, cmd); + break; case VIRTIO_GPU_CMD_RESOURCE_UNREF: virtio_gpu_resource_unref(g, cmd); break; diff --git a/hw/display/trace-events b/hw/display/trace-events index 9fccca18a1d7..f3f77b6984b7 100644 --- a/hw/display/trace-events +++ b/hw/display/trace-events @@ -32,6 +32,7 @@ virtio_gpu_cmd_get_edid(uint32_t scanout) "scanout %d" virtio_gpu_cmd_set_scanout(uint32_t id, uint32_t res, uint32_t w, uint32_t= h, uint32_t x, uint32_t y) "id %d, res 0x%x, w %d, h %d, x %d, y %d" virtio_gpu_cmd_res_create_2d(uint32_t res, uint32_t fmt, uint32_t w, uint3= 2_t h) "res 0x%x, fmt 0x%x, w %d, h %d" virtio_gpu_cmd_res_create_3d(uint32_t res, uint32_t fmt, uint32_t w, uint3= 2_t h, uint32_t d) "res 0x%x, fmt 0x%x, w %d, h %d, d %d" +virtio_gpu_cmd_res_create_blob(uint32_t res, uint64_t size) "res 0x%x, siz= e %" PRId64 virtio_gpu_cmd_res_unref(uint32_t res) "res 0x%x" virtio_gpu_cmd_res_back_attach(uint32_t res) "res 0x%x" virtio_gpu_cmd_res_back_detach(uint32_t res) "res 0x%x" --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622126506; cv=none; d=zohomail.com; s=zohoarc; b=DL3x2DztgTA5cNRVI6Sg/JiilTHmqhJPfEPUJQs856nGZUzfFMiQMSswqGDKbTr4Fctml/8qvQ1QicT9AtLPy4BOjvPF4tEUL3l3xUq299knNb6Buwx+JbkEZI/NHXFOe9ZCxtHYQjGACOgs9AUxgLy6/GYCcs9USQGx7QGrH8Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622126506; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/FFhgaacx72cceFwgMWC8Og/m0k2xFZHFSR7v+wDlDg=; b=E92T9Kxq41GJvsvRkhcgmQIDNAHv0x5albMHw+ViY/oDP2z+cpYWrffkg2fy+53iAIiNATQGukUK7tDG7QWEwpdXRP27FIm/5aq7aCZoeQtfOAcFNrlLXn199vmDHBcmUAvTmtVtLNFKL2BbxBvAyKcpFTazAkbG8I45mQ2KEWY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622126506570535.3592703478887; Thu, 27 May 2021 07:41:46 -0700 (PDT) Received: from localhost ([::1]:53134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmHCj-000779-Kg for importer2@patchew.org; Thu, 27 May 2021 10:41:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGxF-0001FX-Gx for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42782) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGxD-0005JU-MF for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:45 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-306--8I9FbQxPeuIbzR7mzKxNQ-1; Thu, 27 May 2021 10:25:41 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 20CF4101371E; Thu, 27 May 2021 14:25:40 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 100F5100E113; Thu, 27 May 2021 14:25:30 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 0398C1800869; Thu, 27 May 2021 16:23:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125543; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/FFhgaacx72cceFwgMWC8Og/m0k2xFZHFSR7v+wDlDg=; b=e+nvHaZPmuarQOqIgJoyV/F3gjkBgz538Gy0xtVT2Ow18YTgcJMgZtnYBfbcpamV9YtKD6 Q0A1kGzPtpzNYbmf4G0hvTBVxQ0T+cOR4V2QEJIR0pRxjgOYRihy3gFD849KzY5izuLRcn KADNwC+e/5GQTkcH8kNfzNCecXmrCR4= X-MC-Unique: -8I9FbQxPeuIbzR7mzKxNQ-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 19/23] ui/pixman: Add qemu_pixman_to_drm_format() Date: Thu, 27 May 2021 16:23:36 +0200 Message-Id: <20210527142340.1352791-20-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Vivek Kasireddy , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vivek Kasireddy This new function to get the drm_format associated with a pixman format will be useful while creating a dmabuf. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy Message-Id: <20210526231429.1045476-11-vivek.kasireddy@intel.com> Signed-off-by: Gerd Hoffmann --- include/ui/qemu-pixman.h | 1 + ui/qemu-pixman.c | 35 ++++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/include/ui/qemu-pixman.h b/include/ui/qemu-pixman.h index 87737a6f1629..806ddcd7cdab 100644 --- a/include/ui/qemu-pixman.h +++ b/include/ui/qemu-pixman.h @@ -62,6 +62,7 @@ typedef struct PixelFormat { PixelFormat qemu_pixelformat_from_pixman(pixman_format_code_t format); pixman_format_code_t qemu_default_pixman_format(int bpp, bool native_endia= n); pixman_format_code_t qemu_drm_format_to_pixman(uint32_t drm_format); +uint32_t qemu_pixman_to_drm_format(pixman_format_code_t pixman); int qemu_pixman_get_type(int rshift, int gshift, int bshift); pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf); bool qemu_pixman_check_format(DisplayChangeListener *dcl, diff --git a/ui/qemu-pixman.c b/ui/qemu-pixman.c index 85f2945e886f..3ab7e2e958a5 100644 --- a/ui/qemu-pixman.c +++ b/ui/qemu-pixman.c @@ -89,21 +89,34 @@ pixman_format_code_t qemu_default_pixman_format(int bpp= , bool native_endian) } =20 /* Note: drm is little endian, pixman is native endian */ +static const struct { + uint32_t drm_format; + pixman_format_code_t pixman_format; +} drm_format_pixman_map[] =3D { + { DRM_FORMAT_RGB888, PIXMAN_LE_r8g8b8 }, + { DRM_FORMAT_ARGB8888, PIXMAN_LE_a8r8g8b8 }, + { DRM_FORMAT_XRGB8888, PIXMAN_LE_x8r8g8b8 } +}; + pixman_format_code_t qemu_drm_format_to_pixman(uint32_t drm_format) { - static const struct { - uint32_t drm_format; - pixman_format_code_t pixman; - } map[] =3D { - { DRM_FORMAT_RGB888, PIXMAN_LE_r8g8b8 }, - { DRM_FORMAT_ARGB8888, PIXMAN_LE_a8r8g8b8 }, - { DRM_FORMAT_XRGB8888, PIXMAN_LE_x8r8g8b8 } - }; int i; =20 - for (i =3D 0; i < ARRAY_SIZE(map); i++) { - if (drm_format =3D=3D map[i].drm_format) { - return map[i].pixman; + for (i =3D 0; i < ARRAY_SIZE(drm_format_pixman_map); i++) { + if (drm_format =3D=3D drm_format_pixman_map[i].drm_format) { + return drm_format_pixman_map[i].pixman_format; + } + } + return 0; +} + +uint32_t qemu_pixman_to_drm_format(pixman_format_code_t pixman_format) +{ + int i; + + for (i =3D 0; i < ARRAY_SIZE(drm_format_pixman_map); i++) { + if (pixman_format =3D=3D drm_format_pixman_map[i].pixman_format) { + return drm_format_pixman_map[i].drm_format; } } return 0; --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622126073; cv=none; d=zohomail.com; s=zohoarc; b=VkyzhywjB7JoSLb7mtYANRhj0LuhLDJ3qsXhETOT58OD/zASKGnlWrf9/uWhi1Q3TjaeHdmMax9te0wkDgxIqNLO7QW43Ku/SCX2O50JfanwBEgJRmhwFsr3nC1gdd6Aftxidh0wGtj6w1ME1rjXlvAv8Hkje7YVJDPAzwGvVtA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622126073; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EFDwQ4UxlnwSROT5+1at07w+rc4xeGFWdv3s4uvQ+k4=; b=jvh3lYTjQiw6SZwHMdtyzdlpdltYch5WC4cgntRVDz51LOp3NRULOj7ljwC+Zp92klM3+vYZFODIqYaH5aSkZycmixfmuGcBQdya3uA0Mmqmt/lImsEgjlTksdtxzf+pqA9Qg8QEEiqY8H7MQtdFk/1R8OxInL3z6h7p4vJQU40= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622126073436998.2573252254635; Thu, 27 May 2021 07:34:33 -0700 (PDT) Received: from localhost ([::1]:60918 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmH5k-0001eL-Bi for importer2@patchew.org; Thu, 27 May 2021 10:34:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGxa-0001N2-4w for qemu-devel@nongnu.org; Thu, 27 May 2021 10:26:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:51777) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGxQ-0005OU-Da for qemu-devel@nongnu.org; Thu, 27 May 2021 10:26:05 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-138-qjy_MEa7P5CYVWDPGRXESQ-1; Thu, 27 May 2021 10:25:53 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 570091013720; Thu, 27 May 2021 14:25:52 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DE4C95D9CC; Thu, 27 May 2021 14:25:31 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 1331F180086E; Thu, 27 May 2021 16:23:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125555; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EFDwQ4UxlnwSROT5+1at07w+rc4xeGFWdv3s4uvQ+k4=; b=DzuDkCF5PWidqBYc2GIf6kcI8oq2j9EcUBpSeDURGHwQgEYWzeHgrIAEWeACwGaS8qoLn/ Fauv7OlHB6+W1AFsmswyhbmd3iIQJBiltS/1iJ95D1kU54vmSNUtV9Pb536P8KidkgzWvu wEfImSoCzNU7FRu9G+Okm70JsNTRW98= X-MC-Unique: qjy_MEa7P5CYVWDPGRXESQ-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 20/23] virtio-gpu: Add helpers to create and destroy dmabuf objects Date: Thu, 27 May 2021 16:23:37 +0200 Message-Id: <20210527142340.1352791-21-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Vivek Kasireddy , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vivek Kasireddy These helpers can be useful for creating dmabuf objects from blobs and submitting them to the UI. Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy Message-Id: <20210526231429.1045476-12-vivek.kasireddy@intel.com> Signed-off-by: Gerd Hoffmann --- include/hw/virtio/virtio-gpu.h | 15 ++++++++ hw/display/virtio-gpu-udmabuf.c | 65 +++++++++++++++++++++++++++++++++ stubs/virtio-gpu-udmabuf.c | 9 +++++ 3 files changed, 89 insertions(+) diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 66e7aaad0e98..bcf54d970f24 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -150,6 +150,12 @@ struct VirtIOGPUBaseClass { DEFINE_PROP_UINT32("xres", _state, _conf.xres, 1024), \ DEFINE_PROP_UINT32("yres", _state, _conf.yres, 768) =20 +typedef struct VGPUDMABuf { + QemuDmaBuf buf; + uint32_t scanout_id; + QTAILQ_ENTRY(VGPUDMABuf) next; +} VGPUDMABuf; + struct VirtIOGPU { VirtIOGPUBase parent_obj; =20 @@ -178,6 +184,11 @@ struct VirtIOGPU { uint32_t req_3d; uint32_t bytes_3d; } stats; + + struct { + QTAILQ_HEAD(, VGPUDMABuf) bufs; + VGPUDMABuf *primary; + } dmabuf; }; =20 struct VirtIOGPUClass { @@ -259,6 +270,10 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g, bool virtio_gpu_have_udmabuf(void); void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res); void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res); +int virtio_gpu_update_dmabuf(VirtIOGPU *g, + uint32_t scanout_id, + struct virtio_gpu_simple_resource *res, + struct virtio_gpu_framebuffer *fb); =20 /* virtio-gpu-3d.c */ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-udmabu= f.c index 71c4672e327a..3c01a415e71b 100644 --- a/hw/display/virtio-gpu-udmabuf.c +++ b/hw/display/virtio-gpu-udmabuf.c @@ -156,3 +156,68 @@ void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_= resource *res) virtio_gpu_destroy_udmabuf(res); } } + +static void virtio_gpu_free_dmabuf(VirtIOGPU *g, VGPUDMABuf *dmabuf) +{ + struct virtio_gpu_scanout *scanout; + + scanout =3D &g->parent_obj.scanout[dmabuf->scanout_id]; + dpy_gl_release_dmabuf(scanout->con, &dmabuf->buf); + QTAILQ_REMOVE(&g->dmabuf.bufs, dmabuf, next); + g_free(dmabuf); +} + +static VGPUDMABuf +*virtio_gpu_create_dmabuf(VirtIOGPU *g, + uint32_t scanout_id, + struct virtio_gpu_simple_resource *res, + struct virtio_gpu_framebuffer *fb) +{ + VGPUDMABuf *dmabuf; + + if (res->dmabuf_fd < 0) { + return NULL; + } + + dmabuf =3D g_new0(VGPUDMABuf, 1); + dmabuf->buf.width =3D fb->width; + dmabuf->buf.height =3D fb->height; + dmabuf->buf.stride =3D fb->stride; + dmabuf->buf.fourcc =3D qemu_pixman_to_drm_format(fb->format); + dmabuf->buf.fd =3D res->dmabuf_fd; + + dmabuf->scanout_id =3D scanout_id; + QTAILQ_INSERT_HEAD(&g->dmabuf.bufs, dmabuf, next); + + return dmabuf; +} + +int virtio_gpu_update_dmabuf(VirtIOGPU *g, + uint32_t scanout_id, + struct virtio_gpu_simple_resource *res, + struct virtio_gpu_framebuffer *fb) +{ + struct virtio_gpu_scanout *scanout =3D &g->parent_obj.scanout[scanout_= id]; + VGPUDMABuf *new_primary, *old_primary =3D NULL; + + new_primary =3D virtio_gpu_create_dmabuf(g, scanout_id, res, fb); + if (!new_primary) { + return -EINVAL; + } + + if (g->dmabuf.primary) { + old_primary =3D g->dmabuf.primary; + } + + g->dmabuf.primary =3D new_primary; + qemu_console_resize(scanout->con, + new_primary->buf.width, + new_primary->buf.height); + dpy_gl_scanout_dmabuf(scanout->con, &new_primary->buf); + + if (old_primary) { + virtio_gpu_free_dmabuf(g, old_primary); + } + + return 0; +} diff --git a/stubs/virtio-gpu-udmabuf.c b/stubs/virtio-gpu-udmabuf.c index e962e00d86d3..81f661441ab9 100644 --- a/stubs/virtio-gpu-udmabuf.c +++ b/stubs/virtio-gpu-udmabuf.c @@ -16,3 +16,12 @@ void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_re= source *res) { /* nothing (stub) */ } + +int virtio_gpu_update_dmabuf(VirtIOGPU *g, + uint32_t scanout_id, + struct virtio_gpu_simple_resource *res, + struct virtio_gpu_framebuffer *fb) +{ + /* nothing (stub) */ + return 0; +} --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622126337; cv=none; d=zohomail.com; s=zohoarc; b=UEzulQhLz3wnHDDdrCsXUPVdpKfvcvKb882JY5ZJIhBg4DrDjYJkuzBs8jf1ynSfEx8xGtcWalwmOVmawFdM1XsYQPltmJG6xAv8MeanKeO7JLTZft4MdwBw6lvBl38EytrmsxCgf/lOiYuv4L+jxvke+l1McLNiJomhKBTZHJg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622126337; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ro75jNMlpK4jgTIlUDKuFgrt7o+OFpGGsHJGBKp/VzM=; b=mLC84i99RIytvHjCHZP0rdwS+1WnIYp9Y6X/3TlogweDUcoF27B65Gf5Gy7jhYhVxDq9DYcB3oCN7F1RPowP5hnYTd2Xng4n8U0wtdTM/LXbxYy2AgfTYSKl5eVygvf4vgQjuJ8Nta/nLitreFjW3NhDQbwKkQYhrw3x3uGJ6T8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622126337415118.61891823536303; Thu, 27 May 2021 07:38:57 -0700 (PDT) Received: from localhost ([::1]:46538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmHA0-0002Z5-Cp for importer2@patchew.org; Thu, 27 May 2021 10:38:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGxK-0001IY-Hs for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29339) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGxF-0005K8-GY for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:50 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-381-l-5UEbeJMYGkQrkn0z79oQ-1; Thu, 27 May 2021 10:25:43 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F412080ED91; Thu, 27 May 2021 14:25:41 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A00E810016FF; Thu, 27 May 2021 14:25:41 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 1EE65180086F; Thu, 27 May 2021 16:23:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125545; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ro75jNMlpK4jgTIlUDKuFgrt7o+OFpGGsHJGBKp/VzM=; b=PxlmDo1xnd7hW6Qw0lfyWq3EWLnj1a5zKJWHFnx0X8YrA95Jq47unJN7ahNdIG/WIQTqL+ 23lnrJVLpm5zbmW6aAzQzkqw1Rw7ybSbQoiFwMlRq0RaqoGKNuDXt/2bNIyTf6WdLWEUn5 ajsdSHrauIsK5LiS4eLtDl43USQxiok= X-MC-Unique: l-5UEbeJMYGkQrkn0z79oQ-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 21/23] virtio-gpu: Factor out update scanout Date: Thu, 27 May 2021 16:23:38 +0200 Message-Id: <20210527142340.1352791-22-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Vivek Kasireddy , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vivek Kasireddy Creating a small helper function for updating the scanout will be useful in the next patch where this needs to be done early in do_set_scanout before returning. Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy Message-Id: <20210526231429.1045476-13-vivek.kasireddy@intel.com> Signed-off-by: Gerd Hoffmann --- hw/display/virtio-gpu.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 788b4540d5ea..0af08edde85b 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -556,6 +556,28 @@ static void virtio_unref_resource(pixman_image_t *imag= e, void *data) pixman_image_unref(data); } =20 +static void virtio_gpu_update_scanout(VirtIOGPU *g, + uint32_t scanout_id, + struct virtio_gpu_simple_resource *r= es, + struct virtio_gpu_rect *r) +{ + struct virtio_gpu_simple_resource *ores; + struct virtio_gpu_scanout *scanout; + + scanout =3D &g->parent_obj.scanout[scanout_id]; + ores =3D virtio_gpu_find_resource(g, scanout->resource_id); + if (ores) { + ores->scanout_bitmask &=3D ~(1 << scanout_id); + } + + res->scanout_bitmask |=3D (1 << scanout_id); + scanout->resource_id =3D res->resource_id; + scanout->x =3D r->x; + scanout->y =3D r->y; + scanout->width =3D r->width; + scanout->height =3D r->height; +} + static void virtio_gpu_do_set_scanout(VirtIOGPU *g, uint32_t scanout_id, struct virtio_gpu_framebuffer *fb, @@ -563,7 +585,6 @@ static void virtio_gpu_do_set_scanout(VirtIOGPU *g, struct virtio_gpu_rect *r, uint32_t *error) { - struct virtio_gpu_simple_resource *ores; struct virtio_gpu_scanout *scanout; uint8_t *data; =20 @@ -623,17 +644,7 @@ static void virtio_gpu_do_set_scanout(VirtIOGPU *g, scanout->ds); } =20 - ores =3D virtio_gpu_find_resource(g, scanout->resource_id); - if (ores) { - ores->scanout_bitmask &=3D ~(1 << scanout_id); - } - - res->scanout_bitmask |=3D (1 << scanout_id); - scanout->resource_id =3D res->resource_id; - scanout->x =3D r->x; - scanout->y =3D r->y; - scanout->width =3D r->width; - scanout->height =3D r->height; + virtio_gpu_update_scanout(g, scanout_id, res, r); } =20 static void virtio_gpu_set_scanout(VirtIOGPU *g, --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622126594; cv=none; d=zohomail.com; s=zohoarc; b=DKJdIwwLyd5xPyzQPOteDXCTDnX2sx56xDrO1A18cL1s01920x1fu69wfonae1fSIl8PcJx/TJ7rzl1H9Cpe+VK0RN8M6gAde2BRw3F8qTsmKactKvk1bPnStwbSDAWcLxC18pn+v+6f2+TOcYKtKqF+xg04w36JeTz3jkO+eH0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622126594; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qkQ4LCGwhTLlMAcdP2ATImTOe0wRl4+8uAbEV9AiNHQ=; b=A2u31y5j1666jAm9rdXXg/47ZyRbkWkWObH01dab7d5tH8n3YqPP9gsHzozNfla7DtWBPD1RGWtvQp+gAT36qWkq9I+f8bKSK4gqKW5mgzV3bEjwG1O3if4KGRzsPUJ4F1+q0KjuzpqVEk/M+R88NkcMYsDi4Sqm3D5dXxUVeYA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16221265941872.3389550231322573; Thu, 27 May 2021 07:43:14 -0700 (PDT) Received: from localhost ([::1]:56226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmHE9-0000sl-2F for importer2@patchew.org; Thu, 27 May 2021 10:43:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGxP-0001Jg-8Z for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58873) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGxI-0005M4-Bj for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:53 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-375-JrT8q2hMPoqetsQ8s63hYg-1; Thu, 27 May 2021 10:25:45 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CF64C180FD61; Thu, 27 May 2021 14:25:43 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5C3F7100EBB0; Thu, 27 May 2021 14:25:43 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 2F4C31800872; Thu, 27 May 2021 16:23:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125547; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qkQ4LCGwhTLlMAcdP2ATImTOe0wRl4+8uAbEV9AiNHQ=; b=dK7v7V8JjoGxrpUmdCqRVzWV2SeDs3Q5W6yMd238Gh+aC7M3amYpGM8THRlY9yi7MCBAQk e8wz3pxvn9GogiWrO9W1saLE6GWkYYT4E7Xxj2Kp3fDtY7xlFCjM+VA7Ofu7hCY8+dcjva xSLfTKzG3R9+3srct1XFEjZzuyOTu0M= X-MC-Unique: JrT8q2hMPoqetsQ8s63hYg-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 22/23] virtio-gpu: Add virtio_gpu_set_scanout_blob Date: Thu, 27 May 2021 16:23:39 +0200 Message-Id: <20210527142340.1352791-23-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Vivek Kasireddy , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vivek Kasireddy This API allows Qemu to set the blob allocated by the Guest as the scanout buffer. If Opengl support is available, then the scanout buffer would be submitted as a dmabuf to the UI; if not, a pixman image is created from the scanout buffer and is submitted to the UI via the display surface. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy Message-Id: <20210526231429.1045476-14-vivek.kasireddy@intel.com> Signed-off-by: Gerd Hoffmann --- include/hw/virtio/virtio-gpu-bswap.h | 7 ++ hw/display/virtio-gpu.c | 102 +++++++++++++++++++++++++-- hw/display/trace-events | 1 + 3 files changed, 103 insertions(+), 7 deletions(-) diff --git a/include/hw/virtio/virtio-gpu-bswap.h b/include/hw/virtio/virti= o-gpu-bswap.h index d23ac5cc4a06..e2bee8f59557 100644 --- a/include/hw/virtio/virtio-gpu-bswap.h +++ b/include/hw/virtio/virtio-gpu-bswap.h @@ -68,4 +68,11 @@ virtio_gpu_create_blob_bswap(struct virtio_gpu_resource_= create_blob *cblob) le64_to_cpus(&cblob->size); } =20 +static inline void +virtio_gpu_scanout_blob_bswap(struct virtio_gpu_set_scanout_blob *ssb) +{ + virtio_gpu_bswap_32(ssb, sizeof(*ssb) - sizeof(ssb->offsets[3])); + le32_to_cpus(&ssb->offsets[3]); +} + #endif diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 0af08edde85b..8cee6cb3e57d 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -403,7 +403,7 @@ static void virtio_gpu_resource_destroy(VirtIOGPU *g, } } =20 - pixman_image_unref(res->image); + qemu_pixman_image_unref(res->image); virtio_gpu_cleanup_mapping(g, res); QTAILQ_REMOVE(&g->reslist, res, next); g->hostmem -=3D res->hostmem; @@ -492,6 +492,7 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g, { struct virtio_gpu_simple_resource *res; struct virtio_gpu_resource_flush rf; + struct virtio_gpu_scanout *scanout; pixman_region16_t flush_region; int i; =20 @@ -502,16 +503,29 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g, =20 res =3D virtio_gpu_find_check_resource(g, rf.resource_id, false, __func__, &cmd->error); - if (!res || res->blob) { + if (!res) { return; } =20 - if (rf.r.x > res->width || + if (res->blob) { + for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { + scanout =3D &g->parent_obj.scanout[i]; + if (scanout->resource_id =3D=3D res->resource_id && + console_has_gl(scanout->con)) { + dpy_gl_update(scanout->con, 0, 0, scanout->width, + scanout->height); + return; + } + } + } + + if (!res->blob && + (rf.r.x > res->width || rf.r.y > res->height || rf.r.width > res->width || rf.r.height > res->height || rf.r.x + rf.r.width > res->width || - rf.r.y + rf.r.height > res->height) { + rf.r.y + rf.r.height > res->height)) { qemu_log_mask(LOG_GUEST_ERROR, "%s: flush bounds outside resource" " bounds for resource %d: %d %d %d %d vs %d %d\n", __func__, rf.resource_id, rf.r.x, rf.r.y, @@ -523,7 +537,6 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g, pixman_region_init_rect(&flush_region, rf.r.x, rf.r.y, rf.r.width, rf.r.height); for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { - struct virtio_gpu_scanout *scanout; pixman_region16_t region, finalregion; pixman_box16_t *extents; =20 @@ -614,10 +627,23 @@ static void virtio_gpu_do_set_scanout(VirtIOGPU *g, } =20 g->parent_obj.enable =3D 1; - data =3D (uint8_t *)pixman_image_get_data(res->image); + + if (res->blob) { + if (console_has_gl(scanout->con)) { + if (!virtio_gpu_update_dmabuf(g, scanout_id, res, fb)) { + virtio_gpu_update_scanout(g, scanout_id, res, r); + return; + } + } + + data =3D res->blob; + } else { + data =3D (uint8_t *)pixman_image_get_data(res->image); + } =20 /* create a surface for this scanout */ - if (!scanout->ds || + if ((res->blob && !console_has_gl(scanout->con)) || + !scanout->ds || surface_data(scanout->ds) !=3D data + fb->offset || scanout->width !=3D r->width || scanout->height !=3D r->height) { @@ -681,6 +707,61 @@ static void virtio_gpu_set_scanout(VirtIOGPU *g, &fb, res, &ss.r, &cmd->error); } =20 +static void virtio_gpu_set_scanout_blob(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cm= d) +{ + struct virtio_gpu_simple_resource *res; + struct virtio_gpu_framebuffer fb =3D { 0 }; + struct virtio_gpu_set_scanout_blob ss; + uint64_t fbend; + + VIRTIO_GPU_FILL_CMD(ss); + virtio_gpu_scanout_blob_bswap(&ss); + trace_virtio_gpu_cmd_set_scanout_blob(ss.scanout_id, ss.resource_id, + ss.r.width, ss.r.height, ss.r.x, + ss.r.y); + + if (ss.resource_id =3D=3D 0) { + virtio_gpu_disable_scanout(g, ss.scanout_id); + return; + } + + res =3D virtio_gpu_find_check_resource(g, ss.resource_id, true, + __func__, &cmd->error); + if (!res) { + return; + } + + fb.format =3D virtio_gpu_get_pixman_format(ss.format); + if (!fb.format) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: host couldn't handle guest format %d\n", + __func__, ss.format); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; + return; + } + + fb.bytes_pp =3D DIV_ROUND_UP(PIXMAN_FORMAT_BPP(fb.format), 8); + fb.width =3D ss.width; + fb.height =3D ss.height; + fb.stride =3D ss.strides[0]; + fb.offset =3D ss.offsets[0] + ss.r.x * fb.bytes_pp + ss.r.y * fb.strid= e; + + fbend =3D fb.offset; + fbend +=3D fb.stride * (ss.r.height - 1); + fbend +=3D fb.bytes_pp * ss.r.width; + if (fbend > res->blob_size) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: fb end out of range\n", + __func__); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; + return; + } + + virtio_gpu_do_set_scanout(g, ss.scanout_id, + &fb, res, &ss.r, &cmd->error); +} + int virtio_gpu_create_mapping_iov(VirtIOGPU *g, uint32_t nr_entries, uint32_t offset, struct virtio_gpu_ctrl_command *cmd, @@ -875,6 +956,13 @@ void virtio_gpu_simple_process_cmd(VirtIOGPU *g, case VIRTIO_GPU_CMD_SET_SCANOUT: virtio_gpu_set_scanout(g, cmd); break; + case VIRTIO_GPU_CMD_SET_SCANOUT_BLOB: + if (!virtio_gpu_blob_enabled(g->parent_obj.conf)) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; + break; + } + virtio_gpu_set_scanout_blob(g, cmd); + break; case VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING: virtio_gpu_resource_attach_backing(g, cmd); break; diff --git a/hw/display/trace-events b/hw/display/trace-events index f3f77b6984b7..e47264af5da1 100644 --- a/hw/display/trace-events +++ b/hw/display/trace-events @@ -30,6 +30,7 @@ virtio_gpu_features(bool virgl) "virgl %d" virtio_gpu_cmd_get_display_info(void) "" virtio_gpu_cmd_get_edid(uint32_t scanout) "scanout %d" virtio_gpu_cmd_set_scanout(uint32_t id, uint32_t res, uint32_t w, uint32_t= h, uint32_t x, uint32_t y) "id %d, res 0x%x, w %d, h %d, x %d, y %d" +virtio_gpu_cmd_set_scanout_blob(uint32_t id, uint32_t res, uint32_t w, uin= t32_t h, uint32_t x, uint32_t y) "id %d, res 0x%x, w %d, h %d, x %d, y %d" virtio_gpu_cmd_res_create_2d(uint32_t res, uint32_t fmt, uint32_t w, uint3= 2_t h) "res 0x%x, fmt 0x%x, w %d, h %d" virtio_gpu_cmd_res_create_3d(uint32_t res, uint32_t fmt, uint32_t w, uint3= 2_t h, uint32_t d) "res 0x%x, fmt 0x%x, w %d, h %d, d %d" virtio_gpu_cmd_res_create_blob(uint32_t res, uint64_t size) "res 0x%x, siz= e %" PRId64 --=20 2.31.1 From nobody Mon May 6 04:09:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622126697; cv=none; d=zohomail.com; s=zohoarc; b=QHqu6dU9VzAdaV8WQVvehylROL2dstEyFjcvs5jHZGRoVVVWEjY5xT1MRndnz9A1Otr34RuCGocYJeovPaOy2MUG51FEycdr+NLQYxr59e2YoW3rctYIlZZLk5QXbtVY5qhF0o2whT98LDOQzQ1OVg9/a3CdyAn9Bs10MyM4dso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622126697; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vpPk3tbDBPiT1k1fq7u1avz/zD1SGreypxWB9BKG3LE=; b=V3qHUuXrVy9KBs7gTfl5E0pIvOBGCmwp3MePuY89w+JC+f/XSpn5GWRZgrMG01r23x3Ydv4AFHnvEHGbJ2sEqgWFXXWh9WpLht69jQQR0LduoBWjQPWwzFFt3U2z8e/fsNNbnGanLSNjJtTap1TgeaCmG3QL1sN/uWwcY7/vasg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622126697050701.5139238960866; Thu, 27 May 2021 07:44:57 -0700 (PDT) Received: from localhost ([::1]:60320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmHFm-0003j4-0w for importer2@patchew.org; Thu, 27 May 2021 10:44:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34510) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGxP-0001Jm-RY for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20003) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmGxK-0005NC-96 for qemu-devel@nongnu.org; Thu, 27 May 2021 10:25:55 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-409-TjkzxCiNO56Qc8gbKXrwCA-1; Thu, 27 May 2021 10:25:46 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AFEB5818426; Thu, 27 May 2021 14:25:45 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-112-84.ams2.redhat.com [10.36.112.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 369D310190AA; Thu, 27 May 2021 14:25:45 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 3AFF81800875; Thu, 27 May 2021 16:23:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622125549; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vpPk3tbDBPiT1k1fq7u1avz/zD1SGreypxWB9BKG3LE=; b=Jg/F49+tQGDvbn9Spn1jw3iFQnilqKzNgni//jIP6rcsz1JV34u5C8sTM86DV6iyd+sveT QfTc8+9Ovwiy4Kb0XPrnc+Z9B9mT5O+YL+X4qZ18GXgoF37mxG/R1xt4eAqMd5/37n8R5G d0g4o1cgEHcLVwWvosd5NumIlc6Uiss= X-MC-Unique: TjkzxCiNO56Qc8gbKXrwCA-1 From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 23/23] virtio-gpu: Update cursor data using blob Date: Thu, 27 May 2021 16:23:40 +0200 Message-Id: <20210527142340.1352791-24-kraxel@redhat.com> In-Reply-To: <20210527142340.1352791-1-kraxel@redhat.com> References: <20210527142340.1352791-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Cornelia Huck , Vivek Kasireddy , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vivek Kasireddy If a blob is available for the cursor, copy the data from the blob. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy Message-Id: <20210526231429.1045476-15-vivek.kasireddy@intel.com> Signed-off-by: Gerd Hoffmann --- hw/display/virtio-gpu.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 8cee6cb3e57d..4d549377cbc1 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -49,6 +49,7 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g, { struct virtio_gpu_simple_resource *res; uint32_t pixels; + void *data; =20 res =3D virtio_gpu_find_check_resource(g, resource_id, false, __func__, NULL); @@ -56,14 +57,22 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g, return; } =20 - if (pixman_image_get_width(res->image) !=3D s->current_cursor->width = || - pixman_image_get_height(res->image) !=3D s->current_cursor->height= ) { - return; + if (res->blob_size) { + if (res->blob_size < (s->current_cursor->width * + s->current_cursor->height * 4)) { + return; + } + data =3D res->blob; + } else { + if (pixman_image_get_width(res->image) !=3D s->current_cursor->wi= dth || + pixman_image_get_height(res->image) !=3D s->current_cursor->he= ight) { + return; + } + data =3D pixman_image_get_data(res->image); } =20 pixels =3D s->current_cursor->width * s->current_cursor->height; - memcpy(s->current_cursor->data, - pixman_image_get_data(res->image), + memcpy(s->current_cursor->data, data, pixels * sizeof(uint32_t)); } =20 --=20 2.31.1