From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D1373C4345F for ; Thu, 25 Apr 2024 15:49:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s01K0-0006Az-QP; Thu, 25 Apr 2024 11:47:41 -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 1s01JX-0005qo-93 for qemu-devel@nongnu.org; Thu, 25 Apr 2024 11:47:11 -0400 Received: from madrid.collaboradmins.com ([2a00:1098:ed:100::25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s01JV-0006HH-6A for qemu-devel@nongnu.org; Thu, 25 Apr 2024 11:47:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1714060028; bh=PzB8kLY/IxYA9iFXDOGPHSW8XVoA1+1PGfg2eVAMIJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V077C/NrtaI4ErTtmay6TAbiXWkTx/DwCO3p07rYEtEgJrC4+U5iumrCGvnvfC6Es ytEctvGff7Q463E1rUOBVkpGGoLtp7jLr7moC+8bPA9jSQDvb06UQkvgipwpNPAeNT AP+OnjuyydsL2I7aniewigFjfVo/1mNMCbjEQl6rk3n+Zg3ysnGB7x27oxJH7UgcYx +xLTss/R6QlX8E/FsTtYess+DeMMx+KkdoZ/J0jTVLy7hYp5c4Vpj+sGU9+YlVtljN cwI/f99WdSPcT488M66jr1En1x0yUVVrjW8KdaqqVUeotfVtjtObyDUcUj5KvClX/5 41hWaaLkjefQQ== Received: from workpc.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 1CEF9378215D; Thu, 25 Apr 2024 15:47:06 +0000 (UTC) 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 , Anthony PERARD , 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 v9 08/11] virtio-gpu: Resource UUID Date: Thu, 25 Apr 2024 18:45:36 +0300 Message-ID: <20240425154539.2680550-9-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240425154539.2680550-1-dmitry.osipenko@collabora.com> References: <20240425154539.2680550-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1098:ed:100::25; envelope-from=dmitry.osipenko@collabora.com; helo=madrid.collaboradmins.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, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Antonio Caggiano Enable resource UUID feature and implement command resource assign UUID. UUID feature availability is mandatory for Vulkan Venus context. UUID is intended for sharing dmabufs between virtio devices on host. Qemu doesn't have second virtio device for sharing, thus a simple stub UUID implementation is enough. More complete implementation using global UUID resource table might become interesting for a multi-gpu cases. Signed-off-by: Antonio Caggiano Signed-off-by: Huang Rui Signed-off-by: Dmitry Osipenko --- hw/display/trace-events | 1 + hw/display/virtio-gpu-base.c | 3 +++ hw/display/virtio-gpu-virgl.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/hw/display/trace-events b/hw/display/trace-events index 2336a0ca1570..54d6894c59f4 100644 --- a/hw/display/trace-events +++ b/hw/display/trace-events @@ -41,6 +41,7 @@ virtio_gpu_cmd_res_create_blob(uint32_t res, uint64_t size) "res 0x%x, size %" P 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" +virtio_gpu_cmd_res_assign_uuid(uint32_t res) "res 0x%x" virtio_gpu_cmd_res_xfer_toh_2d(uint32_t res) "res 0x%x" virtio_gpu_cmd_res_xfer_toh_3d(uint32_t res) "res 0x%x" virtio_gpu_cmd_res_xfer_fromh_3d(uint32_t res) "res 0x%x" diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c index 4fc7ef8896c1..13014b9a73eb 100644 --- a/hw/display/virtio-gpu-base.c +++ b/hw/display/virtio-gpu-base.c @@ -226,6 +226,9 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features, virtio_gpu_rutabaga_enabled(g->conf)) { features |= (1 << VIRTIO_GPU_F_VIRGL); } + if (virtio_gpu_virgl_enabled(g->conf)) { + features |= (1 << VIRTIO_GPU_F_RESOURCE_UUID); + } if (virtio_gpu_edid_enabled(g->conf)) { features |= (1 << VIRTIO_GPU_F_EDID); } diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 73d4acbf1777..de788df155bf 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -14,6 +14,7 @@ #include "qemu/osdep.h" #include "qemu/error-report.h" #include "qemu/iov.h" +#include "qemu/uuid.h" #include "trace.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" @@ -28,6 +29,7 @@ struct virtio_gpu_virgl_resource { struct virtio_gpu_simple_resource base; bool async_unmap_in_progress; MemoryRegion *mr; + QemuUUID uuid; }; static struct virtio_gpu_virgl_resource * @@ -197,6 +199,7 @@ static void virgl_cmd_create_resource_2d(VirtIOGPU *g, res->base.format = c2d.format; res->base.resource_id = c2d.resource_id; res->base.dmabuf_fd = -1; + qemu_uuid_generate(&res->uuid); QTAILQ_INSERT_HEAD(&g->reslist, &res->base, next); args.handle = c2d.resource_id; @@ -245,6 +248,7 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g, res->base.format = c3d.format; res->base.resource_id = c3d.resource_id; res->base.dmabuf_fd = -1; + qemu_uuid_generate(&res->uuid); QTAILQ_INSERT_HEAD(&g->reslist, &res->base, next); args.handle = c3d.resource_id; @@ -672,6 +676,7 @@ static void virgl_cmd_resource_create_blob(VirtIOGPU *g, res->base.resource_id = cblob.resource_id; res->base.blob_size = cblob.size; res->base.dmabuf_fd = -1; + qemu_uuid_generate(&res->uuid); if (cblob.blob_mem != VIRTIO_GPU_BLOB_MEM_HOST3D) { ret = virtio_gpu_create_mapping_iov(g, cblob.nr_entries, sizeof(cblob), @@ -870,6 +875,31 @@ static void virgl_cmd_set_scanout_blob(VirtIOGPU *g, } #endif /* HAVE_VIRGL_RESOURCE_BLOB */ +static void virgl_cmd_assign_uuid(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + struct virtio_gpu_resource_assign_uuid assign; + struct virtio_gpu_resp_resource_uuid resp; + struct virtio_gpu_virgl_resource *res; + + VIRTIO_GPU_FILL_CMD(assign); + virtio_gpu_bswap_32(&assign, sizeof(assign)); + trace_virtio_gpu_cmd_res_assign_uuid(assign.resource_id); + + res = virtio_gpu_virgl_find_resource(g, assign.resource_id); + if (!res) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: resource does not exist %d\n", + __func__, assign.resource_id); + cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; + return; + } + + memset(&resp, 0, sizeof(resp)); + resp.hdr.type = VIRTIO_GPU_RESP_OK_RESOURCE_UUID; + memcpy(resp.uuid, res->uuid.data, sizeof(resp.uuid)); + virtio_gpu_ctrl_response(g, cmd, &resp.hdr, sizeof(resp)); +} + void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) { @@ -924,6 +954,9 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, /* TODO add security */ virgl_cmd_ctx_detach_resource(g, cmd); break; + case VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID: + virgl_cmd_assign_uuid(g, cmd); + break; case VIRTIO_GPU_CMD_GET_CAPSET_INFO: virgl_cmd_get_capset_info(g, cmd); break; -- 2.44.0