From patchwork Thu Jun 5 16:26:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 894181 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:ecd:b0:3a4:ee3f:8f15 with SMTP id ea13csp42792wrb; Thu, 5 Jun 2025 09:27:47 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUVslVTN0BtwGtESmzlwTR1ErZF1OqiRs5sc7pJ2F1Q4qlWSekSBClpm3VLIj7mhkn03vV7Yw==@linaro.org X-Google-Smtp-Source: AGHT+IG6toEnbSMYxKxRlle4qmfkpJbGGa/e+xiwTJA3WA/sdwzvAIvgTMLTXHk9g4agHN8PoGSm X-Received: by 2002:a05:622a:22a6:b0:49e:5a3:efa8 with SMTP id d75a77b69052e-4a5ae5478edmr71522251cf.0.1749140866971; Thu, 05 Jun 2025 09:27:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1749140866; cv=none; d=google.com; s=arc-20240605; b=SaUMyIAnM429sHLNLwksYnYrc8rViY9qlXh2TJG9+XNKKtAgImwtEpqafoAunnDndU JOaf8utCPAf0l7AYNsoB0/vWPuIk1kwGHexfKpVZdek2Udo4lu0XDuSF5hf8qsXA0vjw X2v4z7owpqOXCde/SJ+AgYOPYq/lrsV21xJyE06I8Tf5v7CNgH8NR1F/RoQt4jmVkqRl gi2ENNXUh+bfF7pMFDfzHG0yZUuwtt4DOc1AD4uCqG+nV/n8edhguGYaqZFENz+JK9qK ZscOEPmUB4c7JLD+gaczdnvU/9iZnro5ySlLC6O0wxof3KKnZKL8DUJzJbpbV+oVE8le snDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pi6A9pXASDCw44aREzrVY17X7X6kOk2Sy2xWECnN1gI=; fh=WUAup+jSAWbrJiCUIQb+ol9Uu6E0l5YRgtDIdPfrrH8=; b=UjwUXSo7Sov/ulHZYjbyNUWpJA0nWICPMv85eMtrtWoKFDoDu+0ppgHVpkqzJSQTsq svpx2cxETvCdS1eg95g8e4KIbyDEXX8RFf3Vl75FjexOfmeDHs6J+OSyWzexFGjv53Ib iuWxLKTS/fhQPkFTTXjdQl3vCZUEH1LuLkIx7B0mx5jcv0Wd05rPxWBKYPysMcmeI+Az 3aR4SWhEXiiKOVwkR93GQzzR09+1KxZmkfGBNIumKAtu9FMF1cl7vGLxxstNIrA5fesp jZ1Eq4gIDgqipmyrApxGd7JEe5aCW4ZMidml3nKsxE5Aq+uDYCu1yM4H5rj1yV6EbcjQ JZlw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h60IYiXO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-4a4359fb5b1si175920911cf.202.2025.06.05.09.27.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 05 Jun 2025 09:27:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h60IYiXO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uNDQo-00073W-54; Thu, 05 Jun 2025 12:27:06 -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 1uNDQl-00071g-GV for qemu-devel@nongnu.org; Thu, 05 Jun 2025 12:27:03 -0400 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uNDQi-0007x3-QO for qemu-devel@nongnu.org; Thu, 05 Jun 2025 12:27:03 -0400 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-ad88105874aso189382866b.1 for ; Thu, 05 Jun 2025 09:27:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1749140819; x=1749745619; 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=pi6A9pXASDCw44aREzrVY17X7X6kOk2Sy2xWECnN1gI=; b=h60IYiXOJceUNvJGYkNXJAl2X7LSc0z9qEZO9LV5DiA1d+9Lp2NMNG3P2xmJOhjjZf 8ogKhF0HagDrfETbdygZeccpjhtdKK72eA80mIu5zRk2r8GlrSgNtyVGd7KR3b5OZcPC sgT+b/bSDiBsU3dbXl555MHTHN5VkcHLqvMCQbjrsDwn3AhnRWzARWnK/kJPYrCq55u+ bo1cFUYuOXLRTzA7L5eudQk812FF26bFzXr8iNjHphlMLOM9KAYNUPMdbvAJ+FVNHf3e kt0aoaur+S8Eg2jgoPtSW/kJXQm6+y0G9n+OzntB4SfEtPlWO7uUHC9+gi3CcYVBGf+I jiHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749140819; x=1749745619; 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=pi6A9pXASDCw44aREzrVY17X7X6kOk2Sy2xWECnN1gI=; b=obBobml1FSpltYfAgnNAlwwuw2VAWncyc7St7Q22NiKjntXoXi+TSkKIyIidRSqTka Zp/+YM0cvn+Gf7yHT4XpxTs4XWrYotK/VTaemqQVjzWZXGCL1UD44sUK0MNz1BqPzivc bqVj6wg9KpNIjdmxUka2EoD4eVZqTWpWaPEopPeeZaTbO5WpcbR7W/pB2gw5BH+LUwFy wm6SmYg8uCbZkuL7vgigvN6olnOG8Zdea3gwV96RfETatFtsRR/TFajKvGbrR7fqNEV5 fcckSs7UFz8iDFBxiGTi1bMpf4A9dUoASCKXyrEad4VZD7XxU/yHwc2T8vGG3bn9nfJR d0Dg== X-Gm-Message-State: AOJu0YwFIru6u1gVcGVlM3dNL9NL+sWaPSVXJkhQaK7295/CP2U0avtP NCxV9A1AvTc9djOSTNt0Rfa7fDT3TxJrvnCm3rYEG14qcKlUKLIjOq0rXtfMnGHjn1o= X-Gm-Gg: ASbGncu4UT/32so+3Qs5UGHEGzZ22Z415AELqYATe0g2KXKGgMhWb0w5Qq0/6YD9Tof NiRtlR5U3g9v1qNCNpfEJ5L1zjpKEeWRyxzd41jwaFub5E0YR/u5t+cPMkEUCOIb6SlIStEvsti 31nUw8GG6COh8Qj1kmmdfHwSC+xvZcalvYKRddiXxDB/R6wBuB9jm6inj/yNWprRNVZ77HdKXWb oR7tgZSwpPI5tsp80UC4+Nlr42re5nZHX2YqpiVZEvgx1tvkW4MED2VP/rZTxzUxNaDznlb7tN7 irmCLZL2t14onhzcLd9kXoG/5s+SpSDKEeBjZRJK0zArnDDsv78E X-Received: by 2002:a17:907:94cd:b0:ad8:9c97:c2de with SMTP id a640c23a62f3a-addf8cec8a1mr719972266b.16.1749140818922; Thu, 05 Jun 2025 09:26:58 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-added7edf9asm364342466b.152.2025.06.05.09.26.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jun 2025 09:26:57 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 8095E5F830; Thu, 05 Jun 2025 17:26:52 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Yiwei Zhang , qemu-stable@nongnu.org, Dmitry Osipenko , =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , "Michael S. Tsirkin" Subject: [PULL 12/17] virtio-gpu: support context init multiple timeline Date: Thu, 5 Jun 2025 17:26:45 +0100 Message-ID: <20250605162651.2614401-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250605162651.2614401-1-alex.bennee@linaro.org> References: <20250605162651.2614401-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::635; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x635.google.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Yiwei Zhang Venus and later native contexts have their own fence context along with multiple timelines within. Fences wtih VIRTIO_GPU_FLAG_INFO_RING_IDX in the flags must be dispatched to be created on the target context. Fence signaling also has to be handled on the specific timeline within that target context. Before this change, venus fencing is completely broken if the host driver doesn't support implicit fencing with external memory objects. Frames can go backwards along with random artifacts on screen if the host driver doesn't attach an implicit fence to the render target. The symptom could be hidden by certain guest wsi backend that waits on a venus native VkFence object for the actual payload with limited present modes or under special configs. e.g. x11 mailbox or xwayland. After this change, everything related to venus fencing starts making sense. Confirmed this via guest and host side perfetto tracing. Cc: qemu-stable@nongnu.org Fixes: 94d0ea1c1928 ("virtio-gpu: Support Venus context") Signed-off-by: Yiwei Zhang Reviewed-by: Dmitry Osipenko Message-Id: <20250518152651.334115-1-zzyiwei@gmail.com> [AJB: remove version history from commit message] Tested-by: Dmitry Osipenko Signed-off-by: Alex Bennée Message-ID: <20250603110204.838117-13-alex.bennee@linaro.org> diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index b4aa8abb96..cea2e12eb9 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -978,6 +978,15 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, } trace_virtio_gpu_fence_ctrl(cmd->cmd_hdr.fence_id, cmd->cmd_hdr.type); +#if VIRGL_VERSION_MAJOR >= 1 + if (cmd->cmd_hdr.flags & VIRTIO_GPU_FLAG_INFO_RING_IDX) { + virgl_renderer_context_create_fence(cmd->cmd_hdr.ctx_id, + VIRGL_RENDERER_FENCE_FLAG_MERGEABLE, + cmd->cmd_hdr.ring_idx, + cmd->cmd_hdr.fence_id); + return; + } +#endif virgl_renderer_create_fence(cmd->cmd_hdr.fence_id, cmd->cmd_hdr.type); } @@ -991,6 +1000,11 @@ static void virgl_write_fence(void *opaque, uint32_t fence) * the guest can end up emitting fences out of order * so we should check all fenced cmds not just the first one. */ +#if VIRGL_VERSION_MAJOR >= 1 + if (cmd->cmd_hdr.flags & VIRTIO_GPU_FLAG_INFO_RING_IDX) { + continue; + } +#endif if (cmd->cmd_hdr.fence_id > fence) { continue; } @@ -1005,6 +1019,29 @@ static void virgl_write_fence(void *opaque, uint32_t fence) } } +#if VIRGL_VERSION_MAJOR >= 1 +static void virgl_write_context_fence(void *opaque, uint32_t ctx_id, + uint32_t ring_idx, uint64_t fence_id) { + VirtIOGPU *g = opaque; + struct virtio_gpu_ctrl_command *cmd, *tmp; + + QTAILQ_FOREACH_SAFE(cmd, &g->fenceq, next, tmp) { + if (cmd->cmd_hdr.flags & VIRTIO_GPU_FLAG_INFO_RING_IDX && + cmd->cmd_hdr.ctx_id == ctx_id && cmd->cmd_hdr.ring_idx == ring_idx && + cmd->cmd_hdr.fence_id <= fence_id) { + trace_virtio_gpu_fence_resp(cmd->cmd_hdr.fence_id); + virtio_gpu_ctrl_response_nodata(g, cmd, VIRTIO_GPU_RESP_OK_NODATA); + QTAILQ_REMOVE(&g->fenceq, cmd, next); + g_free(cmd); + g->inflight--; + if (virtio_gpu_stats_enabled(g->parent_obj.conf)) { + trace_virtio_gpu_dec_inflight_fences(g->inflight); + } + } + } +} +#endif + static virgl_renderer_gl_context virgl_create_context(void *opaque, int scanout_idx, struct virgl_renderer_gl_ctx_param *params) @@ -1039,11 +1076,18 @@ static int virgl_make_context_current(void *opaque, int scanout_idx, } static struct virgl_renderer_callbacks virtio_gpu_3d_cbs = { +#if VIRGL_VERSION_MAJOR >= 1 + .version = 3, +#else .version = 1, +#endif .write_fence = virgl_write_fence, .create_gl_context = virgl_create_context, .destroy_gl_context = virgl_destroy_context, .make_current = virgl_make_context_current, +#if VIRGL_VERSION_MAJOR >= 1 + .write_context_fence = virgl_write_context_fence, +#endif }; static void virtio_gpu_print_stats(void *opaque)