From nobody Mon Apr 13 12:34:37 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=1772826742; cv=none; d=zohomail.com; s=zohoarc; b=h1RKbXAUsfnepOiVG+8ODN4lv9I8O+Lo0ZtCb2WyEYfwn+i+cKUpnu7bmuQO0qZz9nL3VzhOm3cBHo98qgZl7vjB4jze0uVWP5sj9G0Iy5mL1NMqQHYal1dzqJtKluBd1PWCf5DCKl6H7XuhFcCLhKhSpNxjTeCxlCNk0K+f+cA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772826742; 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=jx8Lc4PU9gFc5YSQurhHft6B2Pg7POf9lPTDKPwGiY8=; b=Q82Y2uzeFHtJ6bACziIWsW4yyeC2/8GRgRG75nJhyWsTG/LyJjKIvi3gIDnZzjSw2A0BNTsN7ulrh1RutMjCt06Cq1ClC4z8kY7WaM4F4+Hcqdeb0csdrCPuCey+5uZUe7GN3YT6sznIAnSUzBWb7QgSHdWoTLpr02AoboN8Q9I= 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 1772826742683715.184834669059; Fri, 6 Mar 2026 11:52:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vybDS-0006J3-OS; Fri, 06 Mar 2026 14:52:06 -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 1vybCO-0004CW-1O for qemu-devel@nongnu.org; Fri, 06 Mar 2026 14:51:02 -0500 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vybCL-0000QL-9p for qemu-devel@nongnu.org; Fri, 06 Mar 2026 14:50:59 -0500 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4852a9c6309so4261835e9.0 for ; Fri, 06 Mar 2026 11:50:56 -0800 (PST) Received: from draig.lan ([185.124.0.126]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-485276b7571sm54152365e9.13.2026.03.06.11.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2026 11:50:53 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id C2EFA689D8; Fri, 06 Mar 2026 19:50:49 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1772826655; x=1773431455; 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=jx8Lc4PU9gFc5YSQurhHft6B2Pg7POf9lPTDKPwGiY8=; b=dIEnuew42qO3M49KQczvamTkWMCh7rQAhHsVbE1pcGT2MRFGRGFxOZKF0JbTw0Rg36 cqZGhDhLJuWG8QQVuehtOhRPdk4fWehd9mhU/n9EXeR9NYow6SusYqjE5WGLzunTfcw5 GTbfSODgcWLIkDAQx5UKLmMdwYaNi/gDZgOge5ztLC5K6nboQNBw4zzD1XIL6zEOP7Gk 82fPsPKV6Ewntekez09OuZPK+Ttf8VxMQO/p2wwTGH9YGQCaPxCLAG8p8b9fqQ4xtoq7 7bmTWbZbXAD2LHwSJabeWu4EyjzzEvLMWrF9+5leSB93GcjCQaQx+mXbpaAjgxwbbFmP XuXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772826655; x=1773431455; 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=jx8Lc4PU9gFc5YSQurhHft6B2Pg7POf9lPTDKPwGiY8=; b=pz2xFONiW7f1afOwZraq5hZNlFV1Sk44qwffBlqP3B8Mr/rgdX2FBoxiCAwlDwnpon ZHT69DTGFqCSWQjns8l+WzZZeXfUkkKPZG3cjTByxboKSNKnUqM9ceQBhLkFyyuCvdIg YNcoDAyGDF+FN1ykAtlE2aVOA1en3aWZBgCadl+bBBUF/+l0DVv3yEP6zKijvOjJrNv/ h9uXUH1Xt6I6lbVxmjxVjlTS8Jw51Zgc2du/GTyOgyOW7WL/1GEAwBCQOBvR+yOegwy0 JcOaZDLoWW7xJXVl5zjTMk5BJpdkZfrKW9OskYOUmtXlPY8L6n6E/WbnQi7XNG0dJ2K8 t4dQ== X-Gm-Message-State: AOJu0YyzM4RWCOd8vVAy7mcFZ8tA+YhqJa2L+dHUpItYuC/9Xl2dTBE7 B6XAITaMeQo1QEpFJp6BTOzzdaVHT2h/8JW9pfl1RfJuUpmzFy+yGhCweLRemlvjZ8I= X-Gm-Gg: ATEYQzxW3No7OjmFX8yx2QqsNXvK/Ig0VD/pLWXP4iSdINKk/yVkAJLaDtV3PzhMEy/ px3wZjZ0/tAPiyLunbighMgZjvBxpQvx1yTlDUJnJwWYjIkbVDaP6Q6VYXi0U0lmfi0BfGZeUQO 6OzSipLgRXcS3YIH6INkv4J7UM0c1/+O22l5kDLPzBvutCk5XdWSVGV+PixZLh0q/h1G5rcfDz3 z1XI1GemQbrLhJRDcO3/gEZdIsoiBf+wG7EFP9JO3Dhkr9OL+I50b3YLePI1wkoJ6b0wNpcuyI+ MbvfUfheZUvybodUkPf4cZDmBXBMFB/RpoTH3Gc838h3T1Xg0wYerOHPR9hD/qdvj9HJwJLQRDi 6MZ0ZQhX+5Ee3VvsW8foV9dWfEFZzDZqgynXTjRT/ci0uwrkrhZfrtaOuSSdYxIZgykh55LyKvX 4YYekmkgfiIift0O/tDwF2n3FYAS/8ngkxzQ== X-Received: by 2002:a05:600c:609a:b0:477:63a4:88fe with SMTP id 5b1f17b1804b1-48526919691mr56836275e9.2.1772826654838; Fri, 06 Mar 2026 11:50:54 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Dmitry Osipenko , qemu-stable@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Akihiko Odaki , "Michael S. Tsirkin" Subject: [PULL 09/20] virtio-gpu: Ensure BHs are invoked only from main-loop thread Date: Fri, 6 Mar 2026 19:50:36 +0000 Message-ID: <20260306195048.2869788-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260306195048.2869788-1-alex.bennee@linaro.org> References: <20260306195048.2869788-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::329; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x329.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=unavailable 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: 1772826744571154100 From: Dmitry Osipenko QEMU's display GL core is tied to main-loop thread and virtio-gpu interacts with display while processing GPU commands. Virtio-gpu BHs work in generic AIO context that can be invoked on vCPU thread, while GL and UI toolkits are bound to the main-loop thread. Make virtio-gpu BHs use iohandler AIO context that is handled in a main-loop thread only. 0 SDL_GL_MakeCurrent() (libSDL3) 1 SDL_GL_MakeCurrent_REAL() (libSDL2) 2 sdl2_gl_make_context_current() (ui/sdl2-gl.c:201) 3 make_current() (virglrenderer.c:639) 4 vrend_finish_context_switch() (vrend_renderer.c:11630) 5 vrend_hw_switch_context() (vrend_renderer.c:11613) 6 vrend_renderer_force_ctx_0() (vrend_renderer.c:12986) 7 virgl_renderer_force_ctx_0() (virglrenderer.c:460) 8 virtio_gpu_virgl_process_cmd() (virtio-gpu-virgl.c:1013) 9 virtio_gpu_process_cmdq() (virtio-gpu.c:1050) 10 virtio_gpu_gl_handle_ctrl() (virtio-gpu-gl.c:86) 11 aio_bh_poll() (util/async.c) 12 aio_poll() (util/aio-posix.c) 13 blk_pwrite() (block/block-gen.c:1985) 14 pflash_update() (pflash_cfi01.c:396) 15 pflash_write() (pflash_cfi01.c:541) 16 memory_region_dispatch_write() (system/memory.c:1554) 17 flatview_write() (system/physmem.c:3333) 18 address_space_write() (system/physmem.c:3453) 19 kvm_cpu_exec() (accel/kvm/kall-all.c:3248) 20 kvm_vcpu_thread_fn() (accel/kvm/kaccel-ops.c:53) Cc: qemu-stable@nongnu.org Signed-off-by: Dmitry Osipenko Message-ID: <20260303151422.977399-8-dmitry.osipenko@collabora.com> Message-ID: <20260304165043.1437519-10-alex.bennee@linaro.org> Signed-off-by: Alex Benn=C3=A9e diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 42d20899390..6344bd7b689 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -552,4 +552,14 @@ QEMUBH *virtio_bh_new_guarded_full(DeviceState *dev, #define virtio_bh_new_guarded(dev, cb, opaque) \ virtio_bh_new_guarded_full((dev), (cb), (opaque), (stringify(cb))) =20 +/* + * The "_io" variant runs BH only on a main-loop thread, while generic BH + * may run on a vCPU thread. + */ +QEMUBH *virtio_bh_io_new_guarded_full(DeviceState *dev, + QEMUBHFunc *cb, void *opaque, + const char *name); +#define virtio_bh_io_new_guarded(dev, cb, opaque) \ + virtio_bh_io_new_guarded_full((dev), (cb), (opaque), (stringify(cb))) + #endif diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 0f754829fb7..10c4b5160f4 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -1203,9 +1203,9 @@ int virtio_gpu_virgl_init(VirtIOGPU *g) } =20 #if VIRGL_VERSION_MAJOR >=3D 1 - gl->cmdq_resume_bh =3D aio_bh_new(qemu_get_aio_context(), - virtio_gpu_virgl_resume_cmdq_bh, - g); + gl->cmdq_resume_bh =3D virtio_bh_io_new_guarded(DEVICE(g), + virtio_gpu_virgl_resume_= cmdq_bh, + g); #endif =20 return 0; diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index b2af861f0d8..a89d49aa8cc 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -1526,9 +1526,9 @@ void virtio_gpu_device_realize(DeviceState *qdev, Err= or **errp) =20 g->ctrl_vq =3D virtio_get_queue(vdev, 0); g->cursor_vq =3D virtio_get_queue(vdev, 1); - g->ctrl_bh =3D virtio_bh_new_guarded(qdev, virtio_gpu_ctrl_bh, g); - g->cursor_bh =3D virtio_bh_new_guarded(qdev, virtio_gpu_cursor_bh, g); - g->reset_bh =3D qemu_bh_new(virtio_gpu_reset_bh, g); + g->ctrl_bh =3D virtio_bh_io_new_guarded(qdev, virtio_gpu_ctrl_bh, g); + g->cursor_bh =3D virtio_bh_io_new_guarded(qdev, virtio_gpu_cursor_bh, = g); + g->reset_bh =3D virtio_bh_io_new_guarded(qdev, virtio_gpu_reset_bh, g); qemu_cond_init(&g->reset_cond); QTAILQ_INIT(&g->reslist); QTAILQ_INIT(&g->cmdq); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 22d798e6cdd..4c5a4479bfa 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -4497,3 +4497,13 @@ QEMUBH *virtio_bh_new_guarded_full(DeviceState *dev, return qemu_bh_new_full(cb, opaque, name, &transport->mem_reentrancy_guard); } + +QEMUBH *virtio_bh_io_new_guarded_full(DeviceState *dev, + QEMUBHFunc *cb, void *opaque, + const char *name) +{ + DeviceState *transport =3D qdev_get_parent_bus(dev)->parent; + + return aio_bh_new_full(iohandler_get_aio_context(), cb, opaque, name, + &transport->mem_reentrancy_guard); +} --=20 2.47.3