From nobody Sun Apr 12 00:57:45 2026 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=1772643115; cv=none; d=zohomail.com; s=zohoarc; b=D98tjBiTOuZu/NrShZFTbBZZ2usAu3goqNgsdk9+6C/m7CdcvnMcaml5rsQ3pTW62Ccdd7FrlyPfuOb0H8yGrFxlmTlPiHi7w0+X0L4g+aal43KMxR+rov0/tjAn93ZnFGRdqwVBSmOnnaP8g/0VX2udBW0tsb/S37T2rYPzGKg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772643115; 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=k7V5Ii6IobaiBeODB4/f9P2qABvi9G26OhS7yt+uN74=; b=JQbYjtPryBHLKT8Eqn3d4mzvjED14SlZ6+Bv7Lg2CHsAstyJgoOmQ7RGCsYie4T9DQtjC7WNAaB9iCjmSheJh2NVCf/79p5I7TavhnrSeqXamnwr48huAWuLPiR7iXRyZFlGCfX+u8GAWuA/tPlc9Tr7/T0QZiyHjsMMl5cXkTc= 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 1772643115100233.7252903733057; Wed, 4 Mar 2026 08:51:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxpR3-0003t1-Ey; Wed, 04 Mar 2026 11:50:57 -0500 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 1vxpR1-0003rt-Pi for qemu-devel@nongnu.org; Wed, 04 Mar 2026 11:50:55 -0500 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vxpQz-0002RA-SK for qemu-devel@nongnu.org; Wed, 04 Mar 2026 11:50:55 -0500 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-b8fbb24a9a9so1202538066b.0 for ; Wed, 04 Mar 2026 08:50:53 -0800 (PST) Received: from draig.lan ([185.124.0.126]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b935aec3ea3sm769311366b.57.2026.03.04.08.50.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2026 08:50:51 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id CF98162D79; Wed, 04 Mar 2026 16:50:44 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1772643052; x=1773247852; 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=k7V5Ii6IobaiBeODB4/f9P2qABvi9G26OhS7yt+uN74=; b=XeTdixb/ZtTWr3xZNszP2s02OheIgyv9LwL+G6TKwOagq+I7llLevKReA/SBlnMJ63 c8V+fqpNTp1XhciXt2inTElwiqvbAnsxkNtsIl0QfcjQ/rwsEOl5b3aEdyo7UZC6hZhL mrAKnuEPbFfQipXVHW3W9rH3eUOxi29HMTuCarOO7vLjLOE+B8s6PBJ/wvs3ZllIqnjr xJuzUuif5w91GJk9qq5CcQVh6G+G20C6GeU9fkdnqz9VNHUKi6TVFkJqRqBHT7c2CG4j pzYJWUqD3lzaVMMWDrd3SjEbywQvzZt4evpyxynJ+Z9i2jLZfjKFNfGYy1AwpXi48yO/ Wt1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772643052; x=1773247852; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=k7V5Ii6IobaiBeODB4/f9P2qABvi9G26OhS7yt+uN74=; b=XLzCQeDUoJxGTHHnQDr5hjhbDGdvM+NJXW+/yiNskgnw5dYzVEY6heEbMTDXjjLrlf G6+5daxQhmY9UX5qAWswgV1SwrXEYMm3MmeiHXAXKMOAoGesKGQnJvYw2kuNjRfJUbhH gCRXIM8OemfyJoJVuPonhsUXU6tJliUXNQb94OKS87eC0+17uLoKUXgjLn6FAUWaI1hr E4gNo+R1daTY0JQF4Kw1NjyhvxunXYWQoEtxsYQeN/s7ZutNfN9pnidbfMJL+9G478IS G+Y7hSb562t0sr8PYjw3bpLpUt9jw3sO4aDqx0FezZBR8/H/U5SVl8U+xcH36FX0yvOR 3YtQ== X-Gm-Message-State: AOJu0YxHW0iXI1Oqk93bhww/o8gtw3Dfmq4jToe2CHrPAw3xlO9FbeaZ NhBGwKIP7hxxS5Tmfjjlpt8pLbeFcdd8MDH0BFPbdNLN/ni42tDO+MpSBsnz0wuzIbQ= X-Gm-Gg: ATEYQzxHJHmk4mQ9H452wYN61FyOtxGGseME698XGXdn/Z0+BPS7pRD4DyfuPsTOhWy dzlEI4XfitEi5HSTFRFMh0k3amtbtwWZBSmf0FRJ56ogo2RIcmBWwG2e5V+KTlXNHG3HWFYazZu H8rnk8hXYsJsthWUvvnqHsIZ/Saw0l0/0svXSE2FybABZCFabIdqVrJAG+PY0hlOGUkwE0//Lv8 E8nETZU5SIOfmJlpGJSmM1JqDHUQnPlr0DP14wy7vrSZQq4DQ3aTW02YdKT3GYnIosafpayHGPc 24UiOU4SrChJfTqGUaKdOE5oxUj59SgzxmKscx92WYP+yaVIVzW9ImJYu2e5OH+ku3aW9Jmdob5 rdh7rPDoitSTAw+WHwt6evw30IwHQHRzmoYWz8Bp8itavD0lldVNcSO0h8EatDVFZKLIcYMf4jI aQ6nX2UCwho+fhz8L7enSJ4kk= X-Received: by 2002:a17:907:3e11:b0:b93:61c7:4f09 with SMTP id a640c23a62f3a-b93effa5a4fmr155969866b.20.1772643052183; Wed, 04 Mar 2026 08:50:52 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Peter Xu , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Markus Armbruster , Akihiko Odaki , Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Eric Blake , "Michael S. Tsirkin" , Dmitry Osipenko , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Akihiko Odaki , Pierre-Eric Pelloux-Prayer , Yiwei Zhang Subject: [PATCH 12/20] virtio-gpu: Support DRM native context Date: Wed, 4 Mar 2026 16:50:34 +0000 Message-ID: <20260304165043.1437519-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260304165043.1437519-1-alex.bennee@linaro.org> References: <20260304165043.1437519-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::62b; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62b.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: qemu development 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: 1772643115719158500 From: Dmitry Osipenko Add support for DRM native contexts to VirtIO-GPU. DRM context is enabled using a new virtio-gpu-gl device option "drm_native_context=3Don". Unlike Virgl and Venus contexts that operate on application API level, DRM native contexts work on a kernel UAPI level. This lower level results in a lightweight context implementations that yield better performance. Reviewed-by: Akihiko Odaki Acked-by: Michael S. Tsirkin Tested-by: Alex Benn=C3=A9e Acked-by: Pierre-Eric Pelloux-Prayer Reviewed-by: Yiwei Zhang Tested-by: Yiwei Zhang Signed-off-by: Dmitry Osipenko Message-ID: <20260303151422.977399-11-dmitry.osipenko@collabora.com> --- docs/system/devices/virtio/virtio-gpu.rst | 11 +++++++++ include/hw/virtio/virtio-gpu.h | 3 +++ hw/display/virtio-gpu-gl.c | 2 ++ hw/display/virtio-gpu-virgl.c | 28 +++++++++++++++++++++++ hw/display/virtio-gpu.c | 15 ++++++++++++ 5 files changed, 59 insertions(+) diff --git a/docs/system/devices/virtio/virtio-gpu.rst b/docs/system/device= s/virtio/virtio-gpu.rst index 0f4bb304a9b..086e2fcf27b 100644 --- a/docs/system/devices/virtio/virtio-gpu.rst +++ b/docs/system/devices/virtio/virtio-gpu.rst @@ -84,6 +84,17 @@ of virtio-gpu host memory window. This is typically betw= een 256M and 8G. =20 .. _venus: https://gitlab.freedesktop.org/virgl/venus-protocol/ =20 +DRM native context is supported since release of `virglrenderer`_ v1.0.0 +using `drm`_ protocol. ``DRM`` virtio-gpu capability set ("capset") requi= res +host blob support (``hostmem`` and ``blob`` fields) and should be enabled +using ``drm_native_context`` field. The ``hostmem`` field specifies the s= ize +of virtio-gpu host memory window. This is typically between 256M and 8G. + +.. parsed-literal:: + -device virtio-gpu-gl,hostmem=3D8G,blob=3Don,drm_native_context=3Don + +.. _drm: https://gitlab.freedesktop.org/virgl/virglrenderer/-/tree/main/sr= c/drm + virtio-gpu rutabaga ------------------- =20 diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 2610a32e408..1a999887481 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -100,6 +100,7 @@ enum virtio_gpu_base_conf_flags { VIRTIO_GPU_FLAG_RUTABAGA_ENABLED, VIRTIO_GPU_FLAG_VENUS_ENABLED, VIRTIO_GPU_FLAG_RESOURCE_UUID_ENABLED, + VIRTIO_GPU_FLAG_DRM_ENABLED, }; =20 #define virtio_gpu_virgl_enabled(_cfg) \ @@ -122,6 +123,8 @@ enum virtio_gpu_base_conf_flags { (_cfg.hostmem > 0) #define virtio_gpu_venus_enabled(_cfg) \ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_VENUS_ENABLED)) +#define virtio_gpu_drm_enabled(_cfg) \ + (_cfg.flags & (1 << VIRTIO_GPU_FLAG_DRM_ENABLED)) =20 struct virtio_gpu_base_conf { uint32_t max_outputs; diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c index 3e0680880e1..b941e9a4b78 100644 --- a/hw/display/virtio-gpu-gl.c +++ b/hw/display/virtio-gpu-gl.c @@ -159,6 +159,8 @@ static const Property virtio_gpu_gl_properties[] =3D { VIRTIO_GPU_FLAG_STATS_ENABLED, false), DEFINE_PROP_BIT("venus", VirtIOGPU, parent_obj.conf.flags, VIRTIO_GPU_FLAG_VENUS_ENABLED, false), + DEFINE_PROP_BIT("drm_native_context", VirtIOGPU, parent_obj.conf.flags, + VIRTIO_GPU_FLAG_DRM_ENABLED, false), }; =20 static void virtio_gpu_gl_device_unrealize(DeviceState *qdev) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index ae1880c358b..f5fe1bf4e73 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -1323,6 +1323,25 @@ int virtio_gpu_virgl_init(VirtIOGPU *g) if (virtio_gpu_venus_enabled(g->parent_obj.conf)) { flags |=3D VIRGL_RENDERER_VENUS | VIRGL_RENDERER_RENDER_SERVER; } + if (virtio_gpu_drm_enabled(g->parent_obj.conf)) { + flags |=3D VIRGL_RENDERER_DRM; + + if (!(flags & VIRGL_RENDERER_ASYNC_FENCE_CB)) { + /* + * Virglrenderer skips enabling DRM context support without + * enabled async-fence feature. VirtIO-GPU will initialize + * successfully, but DRM context won't be available in guest. + * + * For vrend async-fencing can be enabled only if EGL display + * is used. Vrend can't be disabled in QEMU, hence DRM implici= tly + * requires EGL too. + * + * Async-fence was bugged in virglrenderer versions <=3D 1.1.1. + */ + error_report("drm requires egl display and virglrenderer >=3D = 1.2.0"); + return -EINVAL; + } + } #endif =20 ret =3D virgl_renderer_init(g, flags, &virtio_gpu_3d_cbs); @@ -1386,5 +1405,14 @@ GArray *virtio_gpu_virgl_get_capsets(VirtIOGPU *g) } } =20 + if (virtio_gpu_drm_enabled(g->parent_obj.conf)) { + virgl_renderer_get_cap_set(VIRTIO_GPU_CAPSET_DRM, + &capset_max_ver, + &capset_max_size); + if (capset_max_size) { + virtio_gpu_virgl_add_capset(capset_ids, VIRTIO_GPU_CAPSET_DRM); + } + } + return capset_ids; } diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index a89d49aa8cc..de7a86a73d2 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -1517,6 +1517,21 @@ void virtio_gpu_device_realize(DeviceState *qdev, Er= ror **errp) #endif } =20 + if (virtio_gpu_drm_enabled(g->parent_obj.conf)) { +#ifdef VIRGL_VERSION_MAJOR + #if VIRGL_VERSION_MAJOR >=3D 1 + if (!virtio_gpu_blob_enabled(g->parent_obj.conf) || + !virtio_gpu_hostmem_enabled(g->parent_obj.conf)) { + error_setg(errp, "drm requires enabled blob and hostmem option= s"); + return; + } + #else + error_setg(errp, "old virglrenderer, drm unsupported"); + return; + #endif +#endif + } + if (!virtio_gpu_base_device_realize(qdev, virtio_gpu_handle_ctrl_cb, virtio_gpu_handle_cursor_cb, --=20 2.47.3