From nobody Sat Nov 23 20:50:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1730203892; cv=none; d=zohomail.com; s=zohoarc; b=VwYIy34ONYTOyzQLJMPc9vFqybVo+aTJFz7cbOsVEqv31l/qdz5gTD6kLKA1rRJG6sbyExrbjUsm2dvn1h1X1h7gQ+WKTJF1ZJP5tg6bN4+aFYIC6r1ij5y3txnR+Ca2ERoFJ8pg33u77cLajKKhgsCEPPy6atjq6MJ+KCHjoCg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730203892; h=Content-Type: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=ncfRO59zfqeBy20d7wY0nXZGIrmnZICFoanN5hMrK1U=; b=kfkvr1t4+klGfyajj5U//eWLZNy6oG4IQvoSSyGqjIFithjfHgmHNdWnf3m2mJg6CGLqSK6kYPAAp7hXDvIwZne/IoSjnrSlcr+a/TAQKO6wuu4YOGo/5yDGHqRiny75XDQ+We4V9GEmp49mIk35DdhRiAkmgv5l3cqUIhWlsU0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; 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 1730203892826846.7543643719937; Tue, 29 Oct 2024 05:11:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t5l3f-0004cp-1X; Tue, 29 Oct 2024 08:10:47 -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 1t5l3Y-0004aV-F8 for qemu-devel@nongnu.org; Tue, 29 Oct 2024 08:10:40 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t5l3W-0007St-OT for qemu-devel@nongnu.org; Tue, 29 Oct 2024 08:10:40 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-431548bd1b4so51195055e9.3 for ; Tue, 29 Oct 2024 05:10:38 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b1c8a9sm12375250f8f.12.2024.10.29.05.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 05:10:34 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 51F735FB43; Tue, 29 Oct 2024 12:10:31 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730203837; x=1730808637; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ncfRO59zfqeBy20d7wY0nXZGIrmnZICFoanN5hMrK1U=; b=TUEaODpZd+jrpnGNyYckJRERmp1SBeQRmC/Z1PKx3ZkkQxxkjFSIK1SAozp4fj+lqq n+BejvGWsjamC+dtMB8lTEt4txmNvLQr/VcTFtWETvC7qMgMoBy2z/0qY7yzVRmH1r/7 gycRPvJLPSXjpnAOF9MIur367Kxh8FD8eySjSZY+4vUHjiNDCyb9jBjTdC8w55rVxwIa 2MloUceFOzZTDOJN1KjTv5sRYVEE2IPryolAuCv7XIKEtxJPrTD7w0J5fMa+h/6/tSR0 thILGQfwUR3FOOA3FdPOJrebu3dRucyLqQ771NI8uq9qW7Bz0iljyJ8hthWPuF0WsZBX 15vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730203837; x=1730808637; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ncfRO59zfqeBy20d7wY0nXZGIrmnZICFoanN5hMrK1U=; b=QkqtY3A76fenlNF3wmDc+nhsMkZvuB1jcogdkV5giuRcNAzrOSUNinwXzBbNxJQ+Es /hbyAnK7k3DoGqVOMMCnVuDT1v0mPa19rlHaCQmPCkU2A0B1LIxSU9cEcfoo617R4v5k 8c9jHeujzulUHCsJg3EBB3AjW6DzRyOfRA0Pu9Z0vV0xXWyvF8a5FiHe88MVaRJbOZ9K QNKfbi5D7y050TU3sSzY+Ts+gCYmIw6W9ZVDCKk+fo+VCzVbCCkL375JmgpXwXfQxJfQ XXBdPrvQgc43HxHAgQlXTLKJYDxxs/49iIkiOGzY76AWqP5i/YWThfzU1XWWPNzLQGZ7 Uu+w== X-Gm-Message-State: AOJu0YxcZ+1rU3QACgbJ1Jp7QWp9SjRN0xnTzUsP7bKjcuznxzmlbVAj 2uVh9BkJWvmKsp0O4AgwHR6Km+8+YK98mJxF0B7nWDSr7d0IveIkGztGvqDE0HA= X-Google-Smtp-Source: AGHT+IGmerNsSwfqpa4mx7pMR4zempNAIqS+TkjkY2HYAQ9VCMwokpFvNFqj44cCVx+ys76Ro9axlA== X-Received: by 2002:a05:600c:35d3:b0:42c:c401:6d8b with SMTP id 5b1f17b1804b1-4319ac7832dmr102306955e9.7.1730203837128; Tue, 29 Oct 2024 05:10:37 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Huang Rui , Antonio Caggiano , Dmitry Osipenko , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S. Tsirkin" Subject: [PULL 09/13] virtio-gpu: Add virgl resource management Date: Tue, 29 Oct 2024 12:10:26 +0000 Message-Id: <20241029121030.4007014-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241029121030.4007014-1-alex.bennee@linaro.org> References: <20241029121030.4007014-1-alex.bennee@linaro.org> MIME-Version: 1.0 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x330.google.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, 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 @linaro.org) X-ZM-MESSAGEID: 1730203893172116600 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 Message-Id: <20241024210311.118220-10-dmitry.osipenko@collabora.com> Signed-off-by: Alex Benn=C3=A9e diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index b3aa444bcf..3ffea478e7 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.39.5