From nobody Fri Nov 1 07:17:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=dmitry.osipenko@collabora.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=collabora.com); dmarc=pass(p=none dis=none) header.from=collabora.com ARC-Seal: i=2; a=rsa-sha256; t=1729803985; cv=pass; d=zohomail.com; s=zohoarc; b=iB6cnvaPp+5H/BpOttT3DfOQ2roEioP6wl3CRfMaI1h9LsADKK0ItoLzMliroFZm4AwUzbs/i0yfAS4Gw0mesl26CzZxSp3OJyRZP/JEHAGy28Ya2ijx17PfzoPLbWBDVxU7LKIzRs+CNG+bHDSpzsdpmYbANS0/l2AFx67x/wo= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729803985; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Rrep0lHkSAfyWnfjt06Z02x3/hOZ0MUPUzJ5Ct6N5T8=; b=jS0/XktBB09FZpZbzg5aP8KNyVthmkC0XlU9bDViVcyMrQLtoUTIFMSUcq0KhlTphVrMgV9DKkAWaDQRKgjZuaxElakNYMA1BPYZ6mX+yxHIPdYJvzALIzkkerp0+DLtXtaTOs2z5xrUq+OHwTCd9sb0TRS0IcwyE3Gkk4g/9Bc= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass header.i=dmitry.osipenko@collabora.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=collabora.com); dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729803985373836.1488518930224; Thu, 24 Oct 2024 14:06:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t450j-0001Qt-5Z; Thu, 24 Oct 2024 17:04:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t450h-0001MN-Lg for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:04:47 -0400 Received: from sender4-pp-f112.zoho.com ([136.143.188.112]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t450f-0002EC-Mr for qemu-devel@nongnu.org; Thu, 24 Oct 2024 17:04:47 -0400 Received: by mx.zohomail.com with SMTPS id 1729803869683484.90670672233546; Thu, 24 Oct 2024 14:04:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729803870; cv=none; d=zohomail.com; s=zohoarc; b=hHFCgJcoe9Y5fOgFiQiUwzTInmTJfbv0n34tehUvTtxFbR4XU9m6aVgTrj4eDfMbxystISkdof4dns53F939ybizPCdA76vQtu6eQHlxVK5KYetUTgvKAhuLvLq6irsIFjScgEzgoSzYHehTLxJkicRg5pkCbrTUuN+ZKR1jcv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729803870; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=Rrep0lHkSAfyWnfjt06Z02x3/hOZ0MUPUzJ5Ct6N5T8=; b=C6QVNEuzwJGcqy6A9x4hH/WEnJjCSuAK23xksuBa+776C4VtXfifGHlsx0TAfYm75mL2780XdbswHLULfo4YD4x0jpI7eauVD2JhCc7EvdtyHXnZpuOYQg/pIcCfersTO9KEWkyMexn5h8ET4GROAthNDd1CX4o81qGl2hYZj/4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=dmitry.osipenko@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1729803870; s=zohomail; d=collabora.com; i=dmitry.osipenko@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=Rrep0lHkSAfyWnfjt06Z02x3/hOZ0MUPUzJ5Ct6N5T8=; b=ZVh395oW+DSu+FamiCjORH4/aZIL0sgfu8sK0+jN08T3IOOnD9YV1NhdG1pQko1N UPDlHA+FUVpV3SB78K91KO2eQt0k/ppUjkVA4H/ViWoXgzgoIdTLfZJmuZty7Ujc97Q jtr4YyRvZ0w6e9tgX5Niflo9y0e//nuNc0+EyCjA= From: Dmitry Osipenko To: Akihiko Odaki , Huang Rui , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , "Michael S . Tsirkin" , Stefano Stabellini , Antonio Caggiano , "Dr . David Alan Gilbert" , Robert Beckett , Gert Wollny , =?UTF-8?q?Alex=20Benn=C3=A9e?= Cc: qemu-devel@nongnu.org, Gurchetan Singh , ernunes@redhat.com, Alyssa Ross , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Alex Deucher , Stefano Stabellini , =?UTF-8?q?Christian=20K=C3=B6nig?= , Xenia Ragiadakou , Pierre-Eric Pelloux-Prayer , Honglei Huang , Julia Zhang , Chen Jiqian , Yiwei Zhang Subject: [PATCH v18 09/13] virtio-gpu: Add virgl resource management Date: Fri, 25 Oct 2024 00:03:07 +0300 Message-ID: <20241024210311.118220-10-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241024210311.118220-1-dmitry.osipenko@collabora.com> References: <20241024210311.118220-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=136.143.188.112; envelope-from=dmitry.osipenko@collabora.com; helo=sender4-pp-f112.zoho.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity dmitry.osipenko@collabora.com) X-ZM-MESSAGEID: 1729803987230116600 Content-Type: text/plain; charset="utf-8" From: Huang Rui In a preparation to adding host blobs support to virtio-gpu, add virgl resource management that allows to retrieve resource based on its ID and virgl resource wrapper on top of simple resource that will be contain fields specific to virgl. Signed-off-by: Huang Rui Reviewed-by: Antonio Caggiano Signed-off-by: Dmitry Osipenko --- hw/display/virtio-gpu-virgl.c | 76 +++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index b3aa444bcfa5..3ffea478e723 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -22,6 +22,23 @@ =20 #include =20 +struct virtio_gpu_virgl_resource { + struct virtio_gpu_simple_resource base; +}; + +static struct virtio_gpu_virgl_resource * +virtio_gpu_virgl_find_resource(VirtIOGPU *g, uint32_t resource_id) +{ + struct virtio_gpu_simple_resource *res; + + res =3D virtio_gpu_find_resource(g, resource_id); + if (!res) { + return NULL; + } + + return container_of(res, struct virtio_gpu_virgl_resource, base); +} + #if VIRGL_RENDERER_CALLBACKS_VERSION >=3D 4 static void * virgl_get_egl_display(G_GNUC_UNUSED void *cookie) @@ -35,11 +52,34 @@ static void virgl_cmd_create_resource_2d(VirtIOGPU *g, { struct virtio_gpu_resource_create_2d c2d; struct virgl_renderer_resource_create_args args; + struct virtio_gpu_virgl_resource *res; =20 VIRTIO_GPU_FILL_CMD(c2d); trace_virtio_gpu_cmd_res_create_2d(c2d.resource_id, c2d.format, c2d.width, c2d.height); =20 + if (c2d.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_virgl_find_resource(g, c2d.resource_id); + if (res) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: resource already exists %d\n", + __func__, c2d.resource_id); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; + return; + } + + res =3D g_new0(struct virtio_gpu_virgl_resource, 1); + res->base.width =3D c2d.width; + res->base.height =3D c2d.height; + res->base.format =3D c2d.format; + res->base.resource_id =3D c2d.resource_id; + QTAILQ_INSERT_HEAD(&g->reslist, &res->base, next); + args.handle =3D c2d.resource_id; args.target =3D 2; args.format =3D c2d.format; @@ -59,11 +99,34 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g, { struct virtio_gpu_resource_create_3d c3d; struct virgl_renderer_resource_create_args args; + struct virtio_gpu_virgl_resource *res; =20 VIRTIO_GPU_FILL_CMD(c3d); trace_virtio_gpu_cmd_res_create_3d(c3d.resource_id, c3d.format, c3d.width, c3d.height, c3d.depth); =20 + if (c3d.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_virgl_find_resource(g, c3d.resource_id); + if (res) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: resource already exists %d\n", + __func__, c3d.resource_id); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; + return; + } + + res =3D g_new0(struct virtio_gpu_virgl_resource, 1); + res->base.width =3D c3d.width; + res->base.height =3D c3d.height; + res->base.format =3D c3d.format; + res->base.resource_id =3D c3d.resource_id; + QTAILQ_INSERT_HEAD(&g->reslist, &res->base, next); + args.handle =3D c3d.resource_id; args.target =3D c3d.target; args.format =3D c3d.format; @@ -82,12 +145,21 @@ static void virgl_cmd_resource_unref(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) { struct virtio_gpu_resource_unref unref; + struct virtio_gpu_virgl_resource *res; struct iovec *res_iovs =3D NULL; int num_iovs =3D 0; =20 VIRTIO_GPU_FILL_CMD(unref); trace_virtio_gpu_cmd_res_unref(unref.resource_id); =20 + res =3D virtio_gpu_virgl_find_resource(g, unref.resource_id); + if (!res) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: resource does not exist %d\n", + __func__, unref.resource_id); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; + return; + } + virgl_renderer_resource_detach_iov(unref.resource_id, &res_iovs, &num_iovs); @@ -95,6 +167,10 @@ static void virgl_cmd_resource_unref(VirtIOGPU *g, virtio_gpu_cleanup_mapping_iov(g, res_iovs, num_iovs); } virgl_renderer_resource_unref(unref.resource_id); + + QTAILQ_REMOVE(&g->reslist, &res->base, next); + + g_free(res); } =20 static void virgl_cmd_context_create(VirtIOGPU *g, --=20 2.47.0