From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762789952; cv=none; d=zohomail.com; s=zohoarc; b=O11JSMlT9/kOuzY4yBtemlg5Sw6jgf12YhmFMBd23M+3B7kH4LzLFZMTJ1KHXbAXKfUuPDJESeWKrZ5HVEp080G5oUya6d/TPl6KxTMvS2GYVLNYe4sG2Ki9li8sqfc6xwC0kdrQWUpy8YftScKZcyrLS+py9xElIe04//CWZ/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762789952; 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=af5GtFfITY+8ZJcw7D4xylDZ0e1hu3v0nZGeQF4gDhk=; b=OBddiJ6TSP+KclDKJGTnTFyl3RYeox6NylhJDSZtRJDANQyszehBjYYWu8iCakIGT14M29c45c0d0ZV40fKmgwq07IQJjKbsFnI46C40XVVG/fcnCrGhw4+GqpVyPp4ERiQqshp4jaezvVnGQjPh2YCgpkc22erTp2Bx3d01+NI= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762789952607406.17571112696055; Mon, 10 Nov 2025 07:52:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIU8p-0005qV-Mf; Mon, 10 Nov 2025 10:49:15 -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 1vIU8n-0005kI-L8 for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU8m-0000qq-4Y for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:13 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-691-4so3lHFlNzKiPhjlx0vr4A-1; Mon, 10 Nov 2025 10:49:09 -0500 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-475dabb63f2so14605085e9.3 for ; Mon, 10 Nov 2025 07:49:09 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b422494easm409021f8f.38.2025.11.10.07.49.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789751; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=af5GtFfITY+8ZJcw7D4xylDZ0e1hu3v0nZGeQF4gDhk=; b=NFyCJ5ig4fwyb6VTZ6A5SYmAthyE84NFYRIOjoz52qmTdK2Ib1XBjiYLo23Q0k4T7NIqao C2AALIVgzFVB81tpSZUPc2kjcEsOrbX6uR+DykWlOD1cwLjCoOud5b+m6Xqy2Yybt4gwaJ 3lSfAbJdb+/UacxaiIRa+h0cLsCee4o= X-MC-Unique: 4so3lHFlNzKiPhjlx0vr4A-1 X-Mimecast-MFC-AGG-ID: 4so3lHFlNzKiPhjlx0vr4A_1762789749 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789748; x=1763394548; 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=af5GtFfITY+8ZJcw7D4xylDZ0e1hu3v0nZGeQF4gDhk=; b=tdE9juEstvN8ZrgtEbv7JtV9KLE54OFl9vbLlPjXJItNBdzBYLA7uAXZLvr02Tjmq4 IQD2a9Wwt4GCOUyVxp6/8H+l6Zg70Eam8g6K+5tRM9JEOmhR6Z++UUJwy/3y9Rm/2zhC iiJ7zaqtBKXcHLAOYcONE3XO9LrKdZQQQxBtMxDl9ncc/T3BrDVgfqA8Oumt3Zt523ob Ec8IT430zYISahcUys100Ou/l07WxmckuGhUcqLNroDgWylUQyK7idkEVleEFhc7lnHu 8XcUuIFQfyoY9Rq5z6vmOnsjwsf5EZyP66chQVObr7r79FAPlRIEPeM315oz+j1QYri2 9PMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789748; x=1763394548; 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=af5GtFfITY+8ZJcw7D4xylDZ0e1hu3v0nZGeQF4gDhk=; b=Bn277hGPl/vnU2wkS9RXl+fsHqinTQalsz+sXJv2ofaZsP3c53YY2U9zBxYNIkmU8W 2mODrU0hJjP+hJuKw98MvK5LzIfiwadfczTV5QrFAy2D+YMaCDNMSdJ5GVjDnMDrMMin Uh9OTUVfuGnOR7j8zaC8UASQQL8ajw3wdxVbaQUPoUdD2cyRoUaLIdOiDg0VQs/IDGX/ F8eecDL/H82ZFKbx3ipHsEpimA7AiSNp//XXnz5iSt/ufSgepSeBQqxPvAlnLDOgXhmY 4GgVAV/6jAjsLzDpLRlbHIWukkmJpg/eV3N3kuFLyRQDrE6mXw3eAKHOxeqUDU6MGbvr 6DzA== X-Gm-Message-State: AOJu0Yw7PWV0XwdjnHveKXBLQKPRl/cXZNVIrCG7R0gG0Jiji5jYYLnV lXcnltA+C1QP+5VEyf60uLjqfugClWhGullsqy+e+aymLTdTUqusv3Ya6y9gmQ8jarFJ1tdggFG G2C0MWbaSLGRmozuow/gFZj40nTIyqndcqRBxEfuNR+HCvWwD+NHC6rWE X-Gm-Gg: ASbGnctDRfOf/ViZJjs08cCd3IriAglc66ijrBQXKCJ0JyhDgUBR5E5z02co95StHoI nnp5im+HMqtaw1WxS/v6RXCO0p6kbqZwM4A6VXyv424oR4OjVOsxl0xzyfGjr5eZ6YF1uLQ1Lqp HfBgjWhwILLkfOs46G3FQpSOnmv+7/zwWVizR7e47QqsoBeUsYmJmw1D2XFyRn6E7rws7Mja8zO XM3mJ2JeyH8Fp4dSgscaozUpbjLSpI8WtonqMoV7G55voUFbvB7DZDPaLbs6gPKjc0tTVfUr4c7 FKR02Dm2U1B2P5xOwBcxA+DX/OZCDZHyp0rZwp4OS+UKpqZIFA+ZoGtzigerBaGdApM2JDYBBS6 x8NS+DNNWdHc5N/KC7XTjiuZ46KsZ/1GstmysRBZTCRwF2fAU24SP9R30/g== X-Received: by 2002:a05:600c:4fc6:b0:475:daba:d03c with SMTP id 5b1f17b1804b1-4777323abc7mr72005465e9.13.1762789748381; Mon, 10 Nov 2025 07:49:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IFUryoMUhmFhoOOUE3VcFLEoKVase1d+znZ1gkmToF/zXhqxQiybwwalxUqff+P2lxc7JuPRA== X-Received: by 2002:a05:600c:4fc6:b0:475:daba:d03c with SMTP id 5b1f17b1804b1-4777323abc7mr72005245e9.13.1762789747972; Mon, 10 Nov 2025 07:49:07 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 01/19] block: Note on aio_co_wake use if not yet yielding Date: Mon, 10 Nov 2025 16:48:36 +0100 Message-ID: <20251110154854.151484-2-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 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=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1762789954017158501 Content-Type: text/plain; charset="utf-8" aio_co_wake() is generally safe to call regardless of whether the coroutine is already yielding or not. If it is not yet yielding, it will be scheduled to run when it does yield. Caveats: - The caller must be independent of the coroutine (to ensure the coroutine must be yielding if both are in the same AioContext), i.e. must not be the same coroutine - The coroutine must yield at some point Make note of this so callers can reason that their use is safe. Signed-off-by: Hanna Czenczek --- include/block/aio.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/block/aio.h b/include/block/aio.h index 99ff48420b..6ed97f0a4c 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -650,6 +650,21 @@ void coroutine_fn aio_co_reschedule_self(AioContext *n= ew_ctx); * aio_co_wake may be executed either in coroutine or non-coroutine * context. The coroutine must not be entered by anyone else while * aio_co_wake() is active. + * + * If `co`'s AioContext differs from the current AioContext, this will call + * aio_co_schedule(), which makes this safe to use even when `co` has not + * yielded yet. In such a case, it will be entered once it yields. + * + * In contrast, if `co`'s AioContext is equal to the current one, it is + * required for `co` to currently be yielding. This is generally the case + * if the caller is not in `co` (i.e. invoked by `co`), because the only + * other way for the caller to be running then is for `co` to currently be + * yielding. + * + * Therefore, if there is no way for the caller to be invoked/entered by + * `co`, it is generally safe to call this regardless of whether `co` is + * known to already be yielding or not -- it only has to yield at some + * point. */ void aio_co_wake(Coroutine *co); =20 --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762790029; cv=none; d=zohomail.com; s=zohoarc; b=n1aAUq4emkWvK/K0YbxH8eZK2bUAleVAlUDPU6B3GZK0gBmuJ9qeTQTIFVPuGE+bP6O6PorDTQ17YyLvVQm36z4PBDAwam6h0VQOG1MzDjDOSZZFHJ4lOmlz2MvO1Z4KX2h2M31kKS0TuuDABSOwQDVpA5KH5YVg9z9YkNct5WE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762790029; 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=g4Z1tFL1FBJQybM45OX2q6ObGdIa2Hwwgev/yb60mMs=; b=D7drXYOASp7ohtVeLL7BL560pqxYY1Cn4Epk5H+5hB5ApF+OtaMNNpoQfslfw10Go4sFOU5OynSA4+gcRFCL9IEf2Yg4XGDCXZQjpjG3yHCQWtKvOFSwAGOddztE2HNlySnoUhStE0Vf/tzfkxEMkqsnqAWd48NF6AXc8YCbRv8= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762790029000445.3135310601832; Mon, 10 Nov 2025 07:53:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIU8r-0005uz-Q0; Mon, 10 Nov 2025 10:49:17 -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 1vIU8q-0005re-A1 for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU8o-0000rT-Ig for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:16 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-189-jB-BVaM9PGK4w4_M9awe_A-1; Mon, 10 Nov 2025 10:49:12 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-477771366cbso9862315e9.0 for ; Mon, 10 Nov 2025 07:49:12 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47761c2fe2asm270305485e9.5.2025.11.10.07.49.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789753; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g4Z1tFL1FBJQybM45OX2q6ObGdIa2Hwwgev/yb60mMs=; b=ieMWZEEAUBUKEKoy9Gmb/0uUjQYFxpXBbb2BTKmgCCVDlkXRiPoQRdP21MQYxGZeP/cbMR M99SASYJXrnoNt34lj3Lh1cWRapkvGhbhrZkIutyVNPm1qgQFYiYFSAAsC2oI8mEaWjTsh SfiCe9yluKXwy0M0UJeEPDHCeg/ozhI= X-MC-Unique: jB-BVaM9PGK4w4_M9awe_A-1 X-Mimecast-MFC-AGG-ID: jB-BVaM9PGK4w4_M9awe_A_1762789751 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789751; x=1763394551; 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=g4Z1tFL1FBJQybM45OX2q6ObGdIa2Hwwgev/yb60mMs=; b=BC5Y1Sl9mID6Wu+mCX+A5FtyetgEj0zivIeZeaNiXDe9rz9ZvxUR1tQ26l6vN+NsUC +pgKDPcPoU7g/bm9+Cf/TVFHCGEZYyv/yC+cZUmJH+C4PMOrtugajLLkt39xqwx9piJ8 R1YV5b6G8hYJWNpy8y7B9fID0P5zLjlN81/wG0JDiu3igGuMuxk8kGJAp0ChsU6SlkS5 VlEd3cdLBLjOblayVJDur3WZgsDv3zm6laLiTSwWBYUpIlowJ6GR52l3FHrVEYPc9kge bVYSfGNYmpkTYPumnkoBsHSzNrs9ULBK52dX3qAtFW2RIeplZ5ZSHQscV/UH4yBo/xNu sD+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789751; x=1763394551; 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=g4Z1tFL1FBJQybM45OX2q6ObGdIa2Hwwgev/yb60mMs=; b=Ps3n7WMWqVN1DZN2A+J99mX1NWfYoFHmvhZqGqz8e5fF/SxPth3raCsecnfldlSk+H qaCt+9HyGtviUAXoa+i+dco9uYtmxI8oFBLxpmejLE60h+QGQCRBwu1JFS0DCbOKXpye nrLk4lSr/qxqTTdn+gN+eZIgX90hZAriTtraCC4PLG6ycvUzgTaJ+6fIy6owd5bVrihs 7Y+RDH0ID9o9/sqt1q+W3mHdCvOv+f5lXzj/M5+XVl7SJJKTeoLyEK5bpk7auqbmpdPc Qa6J82KFKzykwBSbTn1W23zBi1riu41sf3GdqXkhr+dsX/2pNAvAVsc7Pq8csp5V+4my 3c+A== X-Gm-Message-State: AOJu0YzfjQIltVEIwYJsvXHqVoW6zTJkPTs5kVQ6NXwg3USWR+KAKZ/E qPVZvqQEstpqDqr4ywFGsYJCnriSQIFzfsBLMi0Lor/fa6SfDxqWmR/yr+El2xj/ZSG6HNnUXR3 SKx/B+06EnHvzpyxxntlI+SvipoQYHXm7pw7hPck4amehkr6M3t/dLTIR X-Gm-Gg: ASbGncu6+VA1thOuAv064/WdtSl7X3NUdKjSG6tOc59uyr0nxosiHc8L2t4a8Wwhegi foxUyA1TxzX9uI9CfKFo043yUT5njfFcGfqpWXdwLsoCyBWofbzJW9toHCe+drUl4n+YkutKv8j n31C9mQBEHbeP1sfgxBZlGkMoaQK0HzPvqq87s6XeKkfiW8TdWJykpZjY4scjxYgyftncOxkRgF iQHICW72hrgVydGp6T0Ii1W9rPZYdR/e7CqrO96C8pkl4EX2xYxstamkMRt1YHSTgHvMsxgYOzW UbhWoVnSzbzU67DQuZRh6J1lZlHiEivhHtroqIG2zmOXYLT3B3HbFHF3ANxvuJJJb1yRRDtQYhm TmLgJv/4iuiFJ+MSj231GN1IusSGJaDzSKsBJAH2PL0y0lpO732leXPos+Q== X-Received: by 2002:a05:600c:4ecd:b0:46e:32d4:46a1 with SMTP id 5b1f17b1804b1-4777327c110mr76294895e9.22.1762789751014; Mon, 10 Nov 2025 07:49:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IEKtTriYcA3TD9cazAT91fTSNcEad6mGbprJQniVFFySmu05jY53M7004+Ny/PXZd9i4wrUfg== X-Received: by 2002:a05:600c:4ecd:b0:46e:32d4:46a1 with SMTP id 5b1f17b1804b1-4777327c110mr76294555e9.22.1762789750604; Mon, 10 Nov 2025 07:49:10 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 02/19] =?UTF-8?q?rbd:=20Run=20co=20BH=20CB=20in=20the?= =?UTF-8?q?=20coroutine=E2=80=99s=20AioContext?= Date: Mon, 10 Nov 2025 16:48:37 +0100 Message-ID: <20251110154854.151484-3-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1762790031148158500 qemu_rbd_completion_cb() schedules the request completion code (qemu_rbd_finish_bh()) to run in the BDS=E2=80=99s AioContext, assuming that this is the same thread in which qemu_rbd_start_co() runs. To explain, this is how both latter functions interact: In qemu_rbd_start_co(): while (!task.complete) qemu_coroutine_yield(); In qemu_rbd_finish_bh(): task->complete =3D true; aio_co_wake(task->co); // task->co is qemu_rbd_start_co() For this interaction to work reliably, both must run in the same thread so that qemu_rbd_finish_bh() can only run once the coroutine yields. Otherwise, finish_bh() may run before start_co() checks task.complete, which will result in the latter seeing .complete as true immediately and skipping the yield altogether, even though finish_bh() still wakes it. With multiqueue, the BDS=E2=80=99s AioContext is not necessarily the thread start_co() runs in, and so finish_bh() may be scheduled to run in a different thread than start_co(). With the right timing, this will cause the problems described above; waking a non-yielding coroutine is not good, as can be reproduced by putting e.g. a usleep(100000) above the while loop in start_co() (and using multiqueue), giving finish_bh() a much better chance at exiting before start_co() can yield. So instead of scheduling finish_bh() in the BDS=E2=80=99s AioContext, sched= ule finish_bh() in task->co=E2=80=99s AioContext. In addition, we can get rid of task.complete altogether because we will get woken exactly once, when the task is indeed complete, no need to check. (We could go further and drop the BH, running aio_co_wake() directly in qemu_rbd_completion_cb() because we are allowed to do that even if the coroutine isn=E2=80=99t yet yielding and we=E2=80=99re in a different threa= d =E2=80=93 but the doc comment on qemu_rbd_completion_cb() says to be careful, so I decided not to go so far here.) Buglink: https://issues.redhat.com/browse/RHEL-67115 Reported-by: Junyao Zhao Cc: qemu-stable@nongnu.org Signed-off-by: Hanna Czenczek --- block/rbd.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index 3611dc81cf..2a70b5a983 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -110,9 +110,7 @@ typedef struct BDRVRBDState { } BDRVRBDState; =20 typedef struct RBDTask { - BlockDriverState *bs; Coroutine *co; - bool complete; int64_t ret; } RBDTask; =20 @@ -1309,7 +1307,6 @@ static int qemu_rbd_resize(BlockDriverState *bs, uint= 64_t size) static void qemu_rbd_finish_bh(void *opaque) { RBDTask *task =3D opaque; - task->complete =3D true; aio_co_wake(task->co); } =20 @@ -1326,7 +1323,7 @@ static void qemu_rbd_completion_cb(rbd_completion_t c= , RBDTask *task) { task->ret =3D rbd_aio_get_return_value(c); rbd_aio_release(c); - aio_bh_schedule_oneshot(bdrv_get_aio_context(task->bs), + aio_bh_schedule_oneshot(qemu_coroutine_get_aio_context(task->co), qemu_rbd_finish_bh, task); } =20 @@ -1338,7 +1335,7 @@ static int coroutine_fn qemu_rbd_start_co(BlockDriver= State *bs, RBDAIOCmd cmd) { BDRVRBDState *s =3D bs->opaque; - RBDTask task =3D { .bs =3D bs, .co =3D qemu_coroutine_self() }; + RBDTask task =3D { .co =3D qemu_coroutine_self() }; rbd_completion_t c; int r; =20 @@ -1401,9 +1398,8 @@ static int coroutine_fn qemu_rbd_start_co(BlockDriver= State *bs, return r; } =20 - while (!task.complete) { - qemu_coroutine_yield(); - } + /* Expect exactly a single wake from qemu_rbd_finish_bh() */ + qemu_coroutine_yield(); =20 if (task.ret < 0) { error_report("rbd request failed: cmd %d offset %" PRIu64 " bytes = %" --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762789862; cv=none; d=zohomail.com; s=zohoarc; b=ALSXmuhK41LA0RA2LaIR40DO+qgPtcGX2in5CkpQ23+XZdPjZC3NBhNwLtrFyFx6BXs06bC+hiI1R8B+WeVdGsQoIC7ofKDrS1P79nMO1ciHj6oUXCTmtc/DNufrWdw4AYCrtzjqoE+Q9GV1Ef1fmb/76EzRY+at23I+UQVImXk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762789862; 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=95UWx9bv5Qm9uHBp11oS3OtA++Y5vcpLhkYQtD3r7fI=; b=WGVRcSQHBCdN/1jvWULLM9CWtc/9BPEOphWBo21VlgZjyN3/N24SmS2dgZL6Lu0CVnz+8CMaWTJJYzEEPlg9KjdBCziL4BWLrla79EAK2ZjZBc7Ne6nwrL2fPY2E5PeAMTqVJ0ZC37teBSXEORQRLlgPe6o0Et73/vNJF+zDcO8= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762789862920214.6761296959644; Mon, 10 Nov 2025 07:51:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIU8v-000690-BK; Mon, 10 Nov 2025 10:49:21 -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 1vIU8t-00060g-9L for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU8r-0000ru-9I for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:18 -0500 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-301-6LNBMRyPMcGY_ZSEauEZ9w-1; Mon, 10 Nov 2025 10:49:15 -0500 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-42b352355a1so597157f8f.1 for ; Mon, 10 Nov 2025 07:49:14 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42abe63dfecsm23405854f8f.12.2025.11.10.07.49.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789756; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=95UWx9bv5Qm9uHBp11oS3OtA++Y5vcpLhkYQtD3r7fI=; b=LeXL4KcDzppCle1LjOHiQHeiuJ380e9Yt+jWsSUu0x0gmalSU8vZRNUceRU4fMmN03OwJ6 19BVeM4J3WaDfeJcaI3oLegBjUvnrV6qm4IrkM7dTHzKet6IuGDJAX1xKBVn6w+dBFurL6 5P5pb29cKXiWZwXQF3ieqSaGMCLHAtE= X-MC-Unique: 6LNBMRyPMcGY_ZSEauEZ9w-1 X-Mimecast-MFC-AGG-ID: 6LNBMRyPMcGY_ZSEauEZ9w_1762789754 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789754; x=1763394554; 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=95UWx9bv5Qm9uHBp11oS3OtA++Y5vcpLhkYQtD3r7fI=; b=h4bHzwIr84RGPjarbrw+GoGDPF4iFV7nTX1UwgoRh/fGBE9gnSbsmEkDntFdVbCejT Eodb8jQ2LqU8/dd5T+Uw9xCK/Zo3oBfXLDFj+vTQZYXWyPvURBqc1VcLpELMcAubu4Zc J39uDFGcYDcyVv9O1WHsyv5P5eu5wKwGdVwvancREzKxUad6hhQiuEVVFb3B5DXyAE9y DNsZD3e5bjkkSYHz0zGStw80lI5E1eoOeeE805DZNI0pTmdU4uW5kTDpGbQQh8qHhnHs lINfKwkybXLH5lwmuBiD5IZFOizZ4IBH7Pk0t2MgeUWDWOXIbkuIFH5bE1chDF8eQ22F EdOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789754; x=1763394554; 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=95UWx9bv5Qm9uHBp11oS3OtA++Y5vcpLhkYQtD3r7fI=; b=dATcn80KDhUayrjf/4r5AjdQQ2u2GL5E3U+qOel0jZX8xGI2Mlq58MptVUeYRa0Z9W 9naISrkNa73jzmjVgzMaSQhRzU7POz+eMI9YZMrF/p4UEulIP8qPK6N6YilKeq2Yt3Q6 x8987t5O6yQ9gOCl4b+qZrWEylPmA6Z9Nl1quqfIXAnYjCQnJGZmOtCm/7eG7qNzyUxN gSjzM/M03amY5fJcWrRgVTg6vr6HvGljcG/a9B8PMbs/9Kd25B2/myRO3Rx6lag2ehxS Edfld9ar1acsKmy90gyMPIB/YdR3WRlMl4yFn6DMLg1dATjaUeWo3hUvyYQSDG0o7r8S 4oLA== X-Gm-Message-State: AOJu0YyflnkeChuQmX2TL54kPbz96ektPFQcBOpYwgbrqPeBhXyosNTO XXlPtof8RXKsKvpgCMW1zkeEMWVwQK/i9JkcPaxs9sUObCoB8KgByVhRkmPHVon2ic8sB+F6LxB Zz4F9rrt98LDa4sJNHXDwpzA4J4YvbTG7zzKmkbAQ9HM3x+XWqAiof6iY X-Gm-Gg: ASbGncuTP/1Zjm7d1hMKfdvjYdY4RGZGxYdmpEQ0PzdGmo+DViVYO4DmGU/aE4d8XvX gz4jsy5I8R0xLfREjWayzKNJ7qhexsHzHoGuoQLL0XClrRu3rXgLqYj8olG5bF8ORqFSlKHLiFk YQJBTkX8fEBKQUdOkCMvsE/a8mzDQMsxfabDhlVgwRAaBL4kYG0jMz1qAQ2jaLrpt80buX8TDN9 gw3LTrquWg46xuDaFylLXa8qL0CRW3UdE39pMTNvOh5qBS7a5ny0uWdltDnJg5wNnYMwkO967XB vK0gDE4KZRoR/sfOQARJ344xb6XJCZ0qddPT8DDh2tpkRXbsUMCPwRff4ikPgJN6PRi3MlWC7t7 y/bj+OuoJe4iViFEca/yfm66IRUg/93EH+oZqDrcTnVDsggyP6eTd9uN0Bg== X-Received: by 2002:a05:6000:2809:b0:42b:3701:c4dc with SMTP id ffacd0b85a97d-42b3701c6b6mr3476560f8f.31.1762789753628; Mon, 10 Nov 2025 07:49:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IHO5r++23R4W9iXWJG96fnP70fFUBIkwFAGUbSuT1VJKvVrE7SVllB2faKEOdTTEtI/fui8YA== X-Received: by 2002:a05:6000:2809:b0:42b:3701:c4dc with SMTP id ffacd0b85a97d-42b3701c6b6mr3476529f8f.31.1762789753081; Mon, 10 Nov 2025 07:49:13 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 03/19] =?UTF-8?q?iscsi:=20Run=20co=20BH=20CB=20in=20the?= =?UTF-8?q?=20coroutine=E2=80=99s=20AioContext?= Date: Mon, 10 Nov 2025 16:48:38 +0100 Message-ID: <20251110154854.151484-4-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1762789864452158500 For rbd (and others), as described in =E2=80=9Crbd: Run co BH CB in the coroutine=E2=80=99s AioContext=E2=80=9D, the pattern of setting a completio= n flag and waking a coroutine that yields while the flag is not set can only work when both run in the same thread. iscsi has the same pattern, but the details are a bit different: iscsi_co_generic_cb() can (as far as I understand) only run through iscsi_service(), not just from a random thread at a random time. iscsi_service() in turn can only be run after iscsi_set_events() set up an FD event handler, which is done in iscsi_co_wait_for_task(). As a result, iscsi_co_wait_for_task() will always yield exactly once, because iscsi_co_generic_cb() can only run after iscsi_set_events(), after the completion flag has already been checked, and the yielding coroutine will then be woken only once the completion flag was set to true. So as far as I can tell, iscsi has no bug and already works fine. Still, we don=E2=80=99t need the completion flag because we know we have to yield exactly once, so we can drop it. This simplifies the code and makes it more obvious that the =E2=80=9Crbd bug=E2=80=9D isn=E2=80=99t pres= ent here. This makes iscsi_co_generic_bh_cb() and iscsi_retry_timer_expired() a bit boring, so at least the former we can drop and call aio_co_wake() directly from scsi_co_generic_cb() to the same effect. As for the latter, the timer needs a CB, so we can=E2=80=99t drop it (I suppose we cou= ld technically use aio_co_wake directly as the CB, but that would be nasty), but we can put it into the coroutine=E2=80=99s AioContext to make i= ts aio_co_wake() a simple wrapper around qemu_coroutine_enter() without a further BH indirection. Finally, remove the iTask->co !=3D NULL checks: This field is set by iscsi_co_init_iscsitask(), which all users of IscsiTask run before even setting up iscsi_co_generic_cb() as the callback, and it is never set or cleared elsewhere, so it is impossible to not be set in iscsi_co_generic_cb(). Signed-off-by: Hanna Czenczek --- block/iscsi.c | 56 +++++++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 15b96ee880..852ecccf0d 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -107,7 +107,6 @@ typedef struct IscsiLun { =20 typedef struct IscsiTask { int status; - int complete; int retries; int do_retry; struct scsi_task *task; @@ -180,21 +179,10 @@ iscsi_schedule_bh(IscsiAIOCB *acb) =20 #endif =20 -static void iscsi_co_generic_bh_cb(void *opaque) -{ - struct IscsiTask *iTask =3D opaque; - - iTask->complete =3D 1; - aio_co_wake(iTask->co); -} - static void iscsi_retry_timer_expired(void *opaque) { struct IscsiTask *iTask =3D opaque; - iTask->complete =3D 1; - if (iTask->co) { - aio_co_wake(iTask->co); - } + aio_co_wake(iTask->co); } =20 static inline unsigned exp_random(double mean) @@ -239,6 +227,8 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int st= atus, { struct IscsiTask *iTask =3D opaque; struct scsi_task *task =3D command_data; + IscsiLun *iscsilun =3D iTask->iscsilun; + AioContext *itask_ctx =3D qemu_coroutine_get_aio_context(iTask->co); =20 iTask->status =3D status; iTask->do_retry =3D 0; @@ -263,9 +253,9 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int st= atus, " (retry #%u in %u ms): %s", iTask->retries, retry_time, iscsi_get_error(iscsi)); - aio_timer_init(iTask->iscsilun->aio_context, - &iTask->retry_timer, QEMU_CLOCK_REALTIME, - SCALE_MS, iscsi_retry_timer_expired, iTask); + aio_timer_init(itask_ctx, &iTask->retry_timer, + QEMU_CLOCK_REALTIME, SCALE_MS, + iscsi_retry_timer_expired, iTask); timer_mod(&iTask->retry_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + retry_t= ime); iTask->do_retry =3D 1; @@ -284,12 +274,17 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int = status, } } =20 - if (iTask->co) { - replay_bh_schedule_oneshot_event(iTask->iscsilun->aio_context, - iscsi_co_generic_bh_cb, iTask); - } else { - iTask->complete =3D 1; - } + /* + * aio_co_wake() is safe to call: iscsi_service(), which called us, is= only + * run from the event_timer and/or the FD handlers, never from the req= uest + * coroutine. The request coroutine in turn will yield unconditionall= y. + * We must release the lock, though, in case we enter the coroutine + * directly. (Note that if do we enter the coroutine, iTask will prob= ably + * be dangling once aio_co_wake() returns.) + */ + qemu_mutex_unlock(&iscsilun->mutex); + aio_co_wake(iTask->co); + qemu_mutex_lock(&iscsilun->mutex); } =20 static void coroutine_fn @@ -592,12 +587,10 @@ static inline bool iscsi_allocmap_is_valid(IscsiLun *= iscsilun, static void coroutine_fn iscsi_co_wait_for_task(IscsiTask *iTask, IscsiLun *iscsilun) { - while (!iTask->complete) { - iscsi_set_events(iscsilun); - qemu_mutex_unlock(&iscsilun->mutex); - qemu_coroutine_yield(); - qemu_mutex_lock(&iscsilun->mutex); - } + iscsi_set_events(iscsilun); + qemu_mutex_unlock(&iscsilun->mutex); + qemu_coroutine_yield(); + qemu_mutex_lock(&iscsilun->mutex); } =20 static int coroutine_fn @@ -669,7 +662,6 @@ retry: } =20 if (iTask.do_retry) { - iTask.complete =3D 0; goto retry; } =20 @@ -740,7 +732,6 @@ retry: scsi_free_scsi_task(iTask.task); iTask.task =3D NULL; } - iTask.complete =3D 0; goto retry; } =20 @@ -902,7 +893,6 @@ retry: } =20 if (iTask.do_retry) { - iTask.complete =3D 0; goto retry; } =20 @@ -940,7 +930,6 @@ retry: } =20 if (iTask.do_retry) { - iTask.complete =3D 0; goto retry; } =20 @@ -1184,7 +1173,6 @@ retry: } =20 if (iTask.do_retry) { - iTask.complete =3D 0; goto retry; } =20 @@ -1301,7 +1289,6 @@ retry: } =20 if (iTask.do_retry) { - iTask.complete =3D 0; goto retry; } =20 @@ -2390,7 +2377,6 @@ retry: iscsi_co_wait_for_task(&iscsi_task, dst_lun); =20 if (iscsi_task.do_retry) { - iscsi_task.complete =3D 0; goto retry; } =20 --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762789853; cv=none; d=zohomail.com; s=zohoarc; b=UZGexhyxNQKeke2uYuxt7q52fwl849+ivAs6Qd7fbGkjNrGbNa7XnWgMmu0zrlV7037I8mNofTvWcH3tB1cx00xQkwtVD9GN2/QInwh9gRkNaeJUs1gb9gBt/sU0/d73eNkrY7j1vdrOFkUXPef0iCICUFDZL3jmbi4EQyvR4fc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762789853; 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=Jiylzld/JnerlFQ/PfscPcvSJTjubgAWnA1rA/xzymA=; b=R0eBX+fGucnxDTBkNwFUNapQw7TIjH2FhSK+gGsNKBAyQyH4iLf5wiCTKEo7fisnlar4wwM/4/iLUgekhfXlK0BP4jU11aGXiQUpqGiFzeuw+N5D4W0jgPcLTKcKeMJuQsqGUevgySu6w4cA6lg9eDCE7pdrMEPi8J2bFq3ccuA= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762789853229969.2489362140495; Mon, 10 Nov 2025 07:50:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIU8y-0006BO-G1; Mon, 10 Nov 2025 10:49:24 -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 1vIU8v-00068w-7x for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU8t-0000sG-Jo for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:20 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-495-q8a_SLFzOxumsuVa3KvpOQ-1; Mon, 10 Nov 2025 10:49:17 -0500 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-47496b3c1dcso24246465e9.3 for ; Mon, 10 Nov 2025 07:49:17 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47775e9c6c7sm63881105e9.2.2025.11.10.07.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789758; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Jiylzld/JnerlFQ/PfscPcvSJTjubgAWnA1rA/xzymA=; b=fu34WK6pGZEsgjvHiESpifIh2Nn69Pj4G2bmc86yV+xA7OcTGAnQOpGYym8aiI/B6V8l8D fKXxWGsfEeBqtl4ai5nw9KgwRnJEWe7sktOmuP5bCWVFU3DI7ax1ph1+U/5gdCgJizgYjR q7qkSXJIHU5PA1G+bPao+1i9dweM9TQ= X-MC-Unique: q8a_SLFzOxumsuVa3KvpOQ-1 X-Mimecast-MFC-AGG-ID: q8a_SLFzOxumsuVa3KvpOQ_1762789756 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789756; x=1763394556; 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=Jiylzld/JnerlFQ/PfscPcvSJTjubgAWnA1rA/xzymA=; b=krM5Bo8GVg52iLoa557K57glXqm42YHkiSUAisE+2/WQ48zV7qhuXzT3EchjEiVmiV cjRrQXMO4DZdRP3a2urK/7D/As53gO76Fl2ovAS+KqvsNdWqIRuAaZ9ulgcxQ/kvTPpL fBkAnOvJ8ythv4XAZkHGn5xxD6hIWGJFZq5uHAA+l7zUkta/5a/L4zwB85w7jxJRk+e8 StaIDg6xjnDNOsKDoAzO02YqpcPrVs3UoVUpERbzzkRcqYHOWMWbmk1aDcmawlkePO5V iWrT11tK9b0cwNW+VvyLu5Av5C3BsRABdr/HzjkhI7tGZkDW8q45tsHEeo+NK5hf58Sc tP3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789756; x=1763394556; 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=Jiylzld/JnerlFQ/PfscPcvSJTjubgAWnA1rA/xzymA=; b=OrGbSjnE7qIev0M0riJBYEMYP/v1nEXCLxu2lMcejyBjrOsWtL1O4FgCTViBrCKKOU z8aIff/oIB+h5u2kYea3ORbw3fjb2pzDaXR9+wyq5LBe6EVtLwTJdB9nM4Ui1ObuzphT rVFvffW8lztpXTKcgW9e/NmLbb2sYPGupzNvHt7Og3TS3XcxGw6vCEdUvwVey2svwtqX Ig0NUNC1ZRYGCF1q/kDBHRLjArhlVArmoWCm7k406fhHjMtIdwYWqSS8X4K7DK3cXoIY CbK///MnBkwXkw7qtcglAbfrM8SoewzJwKiv4Z/FL9rISccbYykbhgx7F4/KLYTTiXxC Y2XA== X-Gm-Message-State: AOJu0YwWmUAlPK4Uvr0kEIauXOiA73bYIuSBKd5mPLE22tOGnfne6loK +O5i4GlC7DLyxMEu4A5/fS/0GpfFmo4mBQJR+FtDsOkJWNkB0TaVqZ/F6NKRexZQVXi/g7Cnqp3 2xDjx2EVVIt8vw9KLz5K+xRr5ZXmlNvWPQO6rCcG/J+6teNLmgf1rRIMA X-Gm-Gg: ASbGncs/TAIFz+5ucdFW690qtJnzaLzPX6B3IhAiPFvqRmgiouEk7SGITI9y2raACyE 6wRO8hIgz9PmxbAS+EHhy6eEHIGchOVBCo4xL5nkCj4/bglzlrH+qwMh3aYIkn8S5mS5fvVXekX kmUrbyhDYwOrq8aKREqFOMj+LJUKgO7U1/eg1shWO2BkkcQSoznops5AJD3zpB/Jvw34MzOkGHp xzo4kkvdMpGBDykLIeKcU+84C8cYWzQPnL3lSoZiDVEJu5wfZs+NtCGODeTQfxxnowCcBe2Ed2o aJguDkG2bvOIFal9/8DTdBzG1QA+YfPa05L3BqKngiGksGsu9OCMcDgbGZYk5Z8Gn0tkfs1/N/T oDRIbhp9SkBkAhWxnshWd8A6fZbDaG8+7cp39qMdoIS8zCG0lMfN7eixjQQ== X-Received: by 2002:a05:600c:a41:b0:471:21:554a with SMTP id 5b1f17b1804b1-47773230acbmr76520645e9.13.1762789756249; Mon, 10 Nov 2025 07:49:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGH8mNsh0WnwQPic/UOrROnpqliRAe6zcHzdNEEsnLJGlhpXjHQWASX5GhNEZF2Snqzfc7N7A== X-Received: by 2002:a05:600c:a41:b0:471:21:554a with SMTP id 5b1f17b1804b1-47773230acbmr76520425e9.13.1762789755848; Mon, 10 Nov 2025 07:49:15 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 04/19] =?UTF-8?q?nfs:=20Run=20co=20BH=20CB=20in=20the?= =?UTF-8?q?=20coroutine=E2=80=99s=20AioContext?= Date: Mon, 10 Nov 2025 16:48:39 +0100 Message-ID: <20251110154854.151484-5-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1762789854452158501 Like in =E2=80=9Crbd: Run co BH CB in the coroutine=E2=80=99s AioContext=E2= =80=9D, drop the completion flag, yield exactly once, and run the BH in the coroutine=E2=80= =99s AioContext. (Can be reproduced with multiqueue by adding a usleep(100000) before the `while (!task.complete)` loops.) Like in =E2=80=9Ciscsi: Run co BH CB in the coroutine=E2=80=99s AioContext= =E2=80=9D, this makes nfs_co_generic_bh_cb() trivial, so we can drop it in favor of just calling aio_co_wake() directly. Cc: qemu-stable@nongnu.org Signed-off-by: Hanna Czenczek --- block/nfs.c | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/block/nfs.c b/block/nfs.c index 0a7d38db09..1d3a34a30c 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -69,7 +69,6 @@ typedef struct NFSClient { typedef struct NFSRPC { BlockDriverState *bs; int ret; - int complete; QEMUIOVector *iov; struct stat *st; Coroutine *co; @@ -230,14 +229,6 @@ static void coroutine_fn nfs_co_init_task(BlockDriverS= tate *bs, NFSRPC *task) }; } =20 -static void nfs_co_generic_bh_cb(void *opaque) -{ - NFSRPC *task =3D opaque; - - task->complete =3D 1; - aio_co_wake(task->co); -} - /* Called (via nfs_service) with QemuMutex held. */ static void nfs_co_generic_cb(int ret, struct nfs_context *nfs, void *data, @@ -256,8 +247,16 @@ nfs_co_generic_cb(int ret, struct nfs_context *nfs, vo= id *data, if (task->ret < 0) { error_report("NFS Error: %s", nfs_get_error(nfs)); } - replay_bh_schedule_oneshot_event(task->client->aio_context, - nfs_co_generic_bh_cb, task); + + /* + * Safe to call: nfs_service(), which called us, is only run from the = FD + * handlers, never from the request coroutine. The request coroutine = in + * turn will yield unconditionally. + * No need to release the lock, even if we directly enter the coroutin= e, as + * the lock is never re-taken after yielding. (Note: If we do enter t= he + * coroutine, @task will probably be dangling once aio_co_wake() retur= ns.) + */ + aio_co_wake(task->co); } =20 static int coroutine_fn nfs_co_preadv(BlockDriverState *bs, int64_t offset, @@ -278,9 +277,7 @@ static int coroutine_fn nfs_co_preadv(BlockDriverState = *bs, int64_t offset, =20 nfs_set_events(client); } - while (!task.complete) { - qemu_coroutine_yield(); - } + qemu_coroutine_yield(); =20 if (task.ret < 0) { return task.ret; @@ -328,9 +325,7 @@ static int coroutine_fn nfs_co_pwritev(BlockDriverState= *bs, int64_t offset, =20 nfs_set_events(client); } - while (!task.complete) { - qemu_coroutine_yield(); - } + qemu_coroutine_yield(); =20 if (my_buffer) { g_free(buf); @@ -358,9 +353,7 @@ static int coroutine_fn nfs_co_flush(BlockDriverState *= bs) =20 nfs_set_events(client); } - while (!task.complete) { - qemu_coroutine_yield(); - } + qemu_coroutine_yield(); =20 return task.ret; } @@ -723,8 +716,8 @@ nfs_get_allocated_file_size_cb(int ret, struct nfs_cont= ext *nfs, void *data, if (task->ret < 0) { error_report("NFS Error: %s", nfs_get_error(nfs)); } - replay_bh_schedule_oneshot_event(task->client->aio_context, - nfs_co_generic_bh_cb, task); + /* Safe to call, see nfs_co_generic_cb() */ + aio_co_wake(task->co); } =20 static int64_t coroutine_fn nfs_co_get_allocated_file_size(BlockDriverStat= e *bs) @@ -748,9 +741,7 @@ static int64_t coroutine_fn nfs_co_get_allocated_file_s= ize(BlockDriverState *bs) =20 nfs_set_events(client); } - while (!task.complete) { - qemu_coroutine_yield(); - } + qemu_coroutine_yield(); =20 return (task.ret < 0 ? task.ret : st.st_blocks * 512); } --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762789783; cv=none; d=zohomail.com; s=zohoarc; b=JGXDoik3jGM1NTkc4iKbnC3dzKEIDhxKoSC03EiGuYKWZzrxxdSnkcT4tyKyht6ZfqNYtf7qWCiytMtsi6hu+N3vrzR1NBxlgAn13W+n23w3n8CdBoN1dutq5DyUf1G9h9mPA7POtAYB8AZX96ZiGkE1FMTf7NuyUixbBw6vfw4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762789783; 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=wxwKLzXpm3vmJbzNMJpbBjWRq2Q+OhytwkFNiKUpHaw=; b=LPmsChUmWiBMTp+uULqE38UbDmEAU/MVR4A/HX/X3H1Amha1GEGZemlLRh3zhiApK814eZboLZ8JCLUtzjZbmOR5ePp3RTwiINqmTX8Vm5ZqaQTAs2TYKn88X6Rk+H2uiq+IpnSCpIpxv4gFYSI1O15B/LdK9jymIK27VuOmKP8= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762789783227885.7573950885492; Mon, 10 Nov 2025 07:49:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIU92-0006De-S8; Mon, 10 Nov 2025 10:49:28 -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 1vIU8y-0006BR-7y for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU8w-0000tL-G2 for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:23 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-390-PFxd7MicP9CXMfFeEhp-bA-1; Mon, 10 Nov 2025 10:49:20 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-475c422fd70so20623705e9.2 for ; Mon, 10 Nov 2025 07:49:20 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47761c2fe2asm270310165e9.5.2025.11.10.07.49.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789762; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wxwKLzXpm3vmJbzNMJpbBjWRq2Q+OhytwkFNiKUpHaw=; b=RTPhOOvxlwM7NXf8gwvAuX7Tr3CGUpjaXVLLar2T9rCTo5f70Qyi3L2zxHeT8/zA5zkBn7 UCWNxmRXQzzwIQnUs7IsgGHPl1/tnztHx60p+eVITJJTbE4bCwMy/WoT8x/aEX7WO00uaw mOQGo7RpWKvidNn4kwu+QQyyiWuvAAc= X-MC-Unique: PFxd7MicP9CXMfFeEhp-bA-1 X-Mimecast-MFC-AGG-ID: PFxd7MicP9CXMfFeEhp-bA_1762789759 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789759; x=1763394559; 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=wxwKLzXpm3vmJbzNMJpbBjWRq2Q+OhytwkFNiKUpHaw=; b=tUK9+AbIMK+33avj5D7ProsdH4M+jPYVhsqfOFIF9kq/Zv56EM2D+5Infkh8RixTyM 4dE4tV/1eGuTGA83uxH8jeQjtKM6jK+Cjrx6yloT1mhkG+0SaO2IWX4j9wtJLPvQUBNK HMrXpF+Pa2bdrzDAiBrNVIQH6Qd+hFgGnQR4sHu5Jn94MBqssDrUwlucEP1Trv5cM5GN +EpFUzN3avyKPWru3NgAavreDpiKD0eoBqg5Rn4KmEykGAdO7vDApJts71/tTLc4Y0uP 4KEf2h0GURLagMj+qUFezrN2sWRCJIjzN37Z6O+mQc+EyKZk4mOaGDVm71jf61brXZgu 1tkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789759; x=1763394559; 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=wxwKLzXpm3vmJbzNMJpbBjWRq2Q+OhytwkFNiKUpHaw=; b=vsDqmhGl/9zHFHJleVDN244qx6KSkwPyRK2cGnE3DPVk1HV+/PBGIkm1w28Xi2fqe/ 0338mbUPMqvZu47M6m3jJe3wd/wGtqv4oxpi2TlE0k5zQKehSh36baTA4gE6oMN9lQUQ 5DkAF4GsQLbdQqBFNk6O7muLj+8NhhYacsqK96ZyAMwbw63KQOuKNfeHTZRiQT8nlL60 a//IXOBd5a5k0h35WwDQHjPjSN+NpPc9Fq4XeNvbQc3pqE9edU1yXl1xIgxGcoryMWDp T25iJkRyOcil6bXIcADnvQ5QfFA7IgIccr8zWq5Uv8LC5/+RIbIYxM84Hw/RUm+iL+H2 STZQ== X-Gm-Message-State: AOJu0YwwFQSb2LYaFzA3VaplKmJAS3WACfbxd2tTL+mWcI8XRyzH5EhC F8jqIlAxW8CItLE2exK2e85vtkFl5BuPoMVBBDVJIhBWimeUm9gpqyRpPf+PCey6E+efdq9OFZ1 g9BIl7gcoqcOkA1wBh9hQR5hiaHstSJ8gkq6L0crpJPRiH1lFSEWQY234 X-Gm-Gg: ASbGncvzx62QpILXzvc+F/vqhAEDzVg54a3SQtVwni6oxcsRUlhQAqAkCjeocU7N8Jh xR/hWFY/QaN9mTfq1djSeoCGPgrfLPZ8NVLNI+ccgmmi35o4YitmmzuKM5YAHeeZJcL94YbeBK6 3ci9/BlCgfPHh4L46T3oBTnidgc/cnf+06aMNpiLEl/OR5GNmrZAhJ/OdASQNLxn05btNEaWiL3 sNmhG0otS/zth0nD9F3d4l3ca1foi7onk9wgr+wJaWj4GhjcKJPC6JUyDL0w0w1kEETmQbhT7TF QSnmBx3LUujEkjbySuO2+qPlZ3S3mpas72gKOLLjdKtQ9FUN07QEJ00W0TnLir4eKquOlkNxunI /WmuDNH7G8Ggnpb/pfUAtYhE/Qok227GHoyYPS8CckW1zG8hVoN+1SjNGig== X-Received: by 2002:a05:600c:4703:b0:45b:7d77:b592 with SMTP id 5b1f17b1804b1-4777322f0e3mr87220305e9.12.1762789758965; Mon, 10 Nov 2025 07:49:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IF689iDM4PvzzXgsH/nmIo02Qh0O8uRKKxTgU61rDIIto4ydx+wr4RISoawl9G02o+2y2Tj/Q== X-Received: by 2002:a05:600c:4703:b0:45b:7d77:b592 with SMTP id 5b1f17b1804b1-4777322f0e3mr87220005e9.12.1762789758510; Mon, 10 Nov 2025 07:49:18 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 05/19] curl: Fix coroutine waking Date: Mon, 10 Nov 2025 16:48:40 +0100 Message-ID: <20251110154854.151484-6-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1762789785580158500 If we wake a coroutine from a different context, we must ensure that it will yield exactly once (now or later), awaiting that wake. curl=E2=80=99s current .ret =3D=3D -EINPROGRESS loop may lead to the corout= ine not yielding if the request finishes before the loop gets run. To fix it, we must drop the loop and yield exactly once, if we need to yield. Finding out that latter part ("if we need to yield") makes it a bit complicated: Requests may be served from a cache internal to the curl block driver, or fail before being submitted. In these cases, we must not yield. However, if we find a matching but still ongoing request in the cache, we will have to await that, i.e. still yield. To address this, move the yield inside of the respective functions: - Inside of curl_find_buf() when awaiting ongoing concurrent requests, - Inside of curl_setup_preadv() when having created a new request. Rename curl_setup_preadv() to curl_do_preadv() to reflect this. (Can be reproduced with multiqueue by adding a usleep(100000) before the `while (acb.ret =3D=3D -EINPROGRESS)` loop.) Also, add a comment why aio_co_wake() is safe regardless of whether the coroutine and curl_multi_check_completion() run in the same context. Cc: qemu-stable@nongnu.org Signed-off-by: Hanna Czenczek --- block/curl.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/block/curl.c b/block/curl.c index d7d93d967f..4e77c93b46 100644 --- a/block/curl.c +++ b/block/curl.c @@ -258,8 +258,8 @@ read_end: } =20 /* Called with s->mutex held. */ -static bool curl_find_buf(BDRVCURLState *s, uint64_t start, uint64_t len, - CURLAIOCB *acb) +static bool coroutine_fn +curl_find_buf(BDRVCURLState *s, uint64_t start, uint64_t len, CURLAIOCB *a= cb) { int i; uint64_t end =3D start + len; @@ -307,6 +307,10 @@ static bool curl_find_buf(BDRVCURLState *s, uint64_t s= tart, uint64_t len, for (j=3D0; jacb[j]) { state->acb[j] =3D acb; + /* Await ongoing request */ + qemu_mutex_unlock(&s->mutex); + qemu_coroutine_yield(); + qemu_mutex_lock(&s->mutex); return true; } } @@ -378,6 +382,16 @@ static void curl_multi_check_completion(BDRVCURLState = *s) acb->ret =3D error ? -EIO : 0; state->acb[i] =3D NULL; qemu_mutex_unlock(&s->mutex); + /* + * Current AioContext is the BDS context, which may or may= not + * be the request (coroutine) context. + * - If it is, the coroutine must have yielded or the FD h= andler + * (curl_multi_do()/curl_multi_timeout_do()) could not h= ave + * been called and we would not be here + * - If it is not, it doesn't matter whether it has already + * yielded or not; it will be scheduled once it does yie= ld + * So aio_co_wake() is safe to call. + */ aio_co_wake(acb->co); qemu_mutex_lock(&s->mutex); } @@ -868,7 +882,7 @@ out_noclean: return -EINVAL; } =20 -static void coroutine_fn curl_setup_preadv(BlockDriverState *bs, CURLAIOCB= *acb) +static void coroutine_fn curl_do_preadv(BlockDriverState *bs, CURLAIOCB *a= cb) { CURLState *state; int running; @@ -880,10 +894,13 @@ static void coroutine_fn curl_setup_preadv(BlockDrive= rState *bs, CURLAIOCB *acb) =20 qemu_mutex_lock(&s->mutex); =20 - // In case we have the requested data already (e.g. read-ahead), - // we can just call the callback and be done. + /* + * In case we have the requested data already (e.g. read-ahead), + * we can just call the callback and be done. This may have to + * await an ongoing request, in which case it itself will yield. + */ if (curl_find_buf(s, start, acb->bytes, acb)) { - goto out; + goto dont_yield; } =20 // No cache found, so let's start a new request @@ -898,7 +915,7 @@ static void coroutine_fn curl_setup_preadv(BlockDriverS= tate *bs, CURLAIOCB *acb) if (curl_init_state(s, state) < 0) { curl_clean_state(state); acb->ret =3D -EIO; - goto out; + goto dont_yield; } =20 acb->start =3D 0; @@ -913,7 +930,7 @@ static void coroutine_fn curl_setup_preadv(BlockDriverS= tate *bs, CURLAIOCB *acb) if (state->buf_len && state->orig_buf =3D=3D NULL) { curl_clean_state(state); acb->ret =3D -ENOMEM; - goto out; + goto dont_yield; } state->acb[0] =3D acb; =20 @@ -925,13 +942,16 @@ static void coroutine_fn curl_setup_preadv(BlockDrive= rState *bs, CURLAIOCB *acb) acb->ret =3D -EIO; =20 curl_clean_state(state); - goto out; + goto dont_yield; } =20 /* Tell curl it needs to kick things off */ curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running); + qemu_mutex_unlock(&s->mutex); + qemu_coroutine_yield(); + return; =20 -out: +dont_yield: qemu_mutex_unlock(&s->mutex); } =20 @@ -947,10 +967,7 @@ static int coroutine_fn curl_co_preadv(BlockDriverStat= e *bs, .bytes =3D bytes }; =20 - curl_setup_preadv(bs, &acb); - while (acb.ret =3D=3D -EINPROGRESS) { - qemu_coroutine_yield(); - } + curl_do_preadv(bs, &acb); return acb.ret; } =20 --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762789974; cv=none; d=zohomail.com; s=zohoarc; b=U+rr0PFifCmCkH0tSpbt9OMfCQinb503gL4qpNtHuMjIhyLwRuwrEoELH7YXTqbfOTEOqtSHwmVkQ9IyQ5nv4yVPjJHX3+OYBCmUzhzEi2XqnQaLcseXPIg+6FsaVOGklWHMoX2WFRsRpOt8iYBrDAQ5qI/yBhc6wtO89euMZNY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762789974; 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=nqhZesfJg+z3U8THtkhPVMymF7wZcq2zgdkzZ1bqHh0=; b=LImqoCJlgV/vhbDOlyAp+SEgD7ybhh4r4TRLpTOo+JW3z88UPdoTZAodv5hyP6yX5TR3ebbZ7evjarfwHSk3nPhf+7Y5KHGJozkOsniJbeWWTpLvndmX+dQ0NwRMzwq2nGZANy+tqVuMpTE/qtXn8DXJKH24Zntr/8MpZqBCNcM= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762789974806353.4022066293152; Mon, 10 Nov 2025 07:52:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIU93-0006Il-Vn; Mon, 10 Nov 2025 10:49:30 -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 1vIU91-0006Dn-Aw for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU8z-0000x8-Qb for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:27 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-383-BHK2hOWROyCfRlhiZFKc2A-1; Mon, 10 Nov 2025 10:49:23 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-477632c240bso29447445e9.2 for ; Mon, 10 Nov 2025 07:49:22 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4775cd45466sm323132855e9.0.2025.11.10.07.49.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789765; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nqhZesfJg+z3U8THtkhPVMymF7wZcq2zgdkzZ1bqHh0=; b=KvldD4JZGhkKAFQmkUib/NQ5tN+WUl+f5ONS8UI6cMvrkOCCZpzBA4+2GZtFuk/zcwayq4 tZTQDEiSb+H2xXy9papaj3mD1I8PW3y21Oo6R1qgZGVa7M8LFhWkTUbdCmhnkCbs6JoMdB ByloQgzrOSKxKvfmCFXx4wf6tCR5KeA= X-MC-Unique: BHK2hOWROyCfRlhiZFKc2A-1 X-Mimecast-MFC-AGG-ID: BHK2hOWROyCfRlhiZFKc2A_1762789762 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789762; x=1763394562; 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=nqhZesfJg+z3U8THtkhPVMymF7wZcq2zgdkzZ1bqHh0=; b=e39vd3/RfRuL8ssF+cpv2fXUMGFAa9va5c3MWdSmCE1h2NoWHiRWw79e2FOO+yArIf MilAvFNjE1lTJOgobXj+UNWbCNZJESwa9Wp4cwcIXzIVDVZ2tyUOu0WurDGdUm1JwTgH O/DwFEKmcvKDxcKkPxFkvhOz4QeQTtyiCnMoXs6pOOE3AXD1Np09Q7vrwiSPWw/703Rw FS1K0Rhqz0jOikAjIbrBr89EPwQTXrIKE6dGjTSV//Zgv7wbJBtv2uFcyLfu1UG68cFp 2W133KJ7CEO1thDg1klQBBySuMqH1M4wFq0XXePLDAl/3f5PJmwIl5BsPoCLt/5Ah7NA Jt6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789762; x=1763394562; 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=nqhZesfJg+z3U8THtkhPVMymF7wZcq2zgdkzZ1bqHh0=; b=D7TBptwvzi/uoxUT+/r/XDkoIv4/SNjSmbXsxxfH35crVOMhaau6TOaV4b95auNYyF JB7Z3c6qlt8TSseghUmpAO4CqIJdLoEaywtn+oZ8skLvoAu7TBWzx0u8HniyWw5/ufKk vjwvkLACowmY0tu4zvVfCNQ8ZnLi3g5cRgi4/0uS4jv7U+pwei8WRSLhmIOGKGrv9WFS 7bXidSOkJ1zIQYzhfINCzD2LCN0ub5tRMHuSMzBKAuc6A5cJUAEnSCS9aZy7dMEsqilE SPj4BhUvmLCqS847lS4u6Y12/m1VuXwmJKlQMSrICrT0dat+Dfc4lX2f5X79h2GkKoZE 0bhw== X-Gm-Message-State: AOJu0YwgQCKKv4aArFRA75P96nhtFNTgnXPQ1GEtMiUdJRefBJB+W5Te 0Ey7OUrVfbVdmrzd0VgI2GFzFaluq/9trokA/o/S72BfLE3gQ8OysAmnkPY72h4II31rlAy61CQ 03oPXotV+RfDPZCVpEEq5YkSBCRPBnx7Ex79VY3CQAccTqBlNKOou02/1 X-Gm-Gg: ASbGncvucllmlK98o272vJ/wJZYcx+mj79RDThDFVpSbjlyGlRRetqBLyk0oNOqN5cV 45P5P5kFsHI53VRL4/UkI1wmlBbTSBv6cphIt7gqx378ofQvNaels1teYeYidSui4twdwhmkdQ2 Ls+boyM4HfeT68u7AEYZEDF++mN4n2xlk1UBq9nMCZXslfALfhkQZ3waF6v24bKKe70u8zrmkMA kPEEkW3PE5ypJ5QRpoL7oSHIKzU6ybjp6sue5OeedLS1k68bmNf6cJbT3UrSft5Ma+mf/iweb4+ pkAl8gNjcKB2O/AHWFS2T4LlK+zcrxKeVLxOcU9goL4s4vBVQEgDVLXssaM3NtX9aITJWxYR5VY xzwcBGeAeiPCmJ7xAs+DTHtgMs1YpflHwHB1s29XtBMKRrkfCSltHFQ1kxw== X-Received: by 2002:a05:600c:35d1:b0:477:7d94:9d05 with SMTP id 5b1f17b1804b1-4777d949e90mr26984185e9.35.1762789761742; Mon, 10 Nov 2025 07:49:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZExgFwiUxE1AUva6CmMz2LTGjZWaUziDKl4XN59PsAtzc5wzdD16+HlBbXn89wq4jeby4Rw== X-Received: by 2002:a05:600c:35d1:b0:477:7d94:9d05 with SMTP id 5b1f17b1804b1-4777d949e90mr26983775e9.35.1762789761330; Mon, 10 Nov 2025 07:49:21 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 06/19] gluster: Do not move coroutine into BDS context Date: Mon, 10 Nov 2025 16:48:41 +0100 Message-ID: <20251110154854.151484-7-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: 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 @redhat.com) X-ZM-MESSAGEID: 1762789976362158500 The request coroutine may not run in the BDS AioContext. We should wake it in its own context, not move it. With that, we can remove GlusterAIOCB.aio_context. Also add a comment why aio_co_schedule() is safe to use in this way. **Note:** Due to a lack of a gluster set-up, I have not tested this commit. It seemed safe enough to send anyway, just maybe not to qemu-stable. To be clear, I don=E2=80=99t know of any user-visible bugs th= at would arise from the state without this patch; the request coroutine is moved into the main BDS AioContext, so guest device completion code will run in a different context than where the request started, which can=E2=80= =99t be good, but I haven=E2=80=99t actually confirmed any bugs (due to not being able to test it). Signed-off-by: Hanna Czenczek --- block/gluster.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 89abd40f31..4fb25b2c6d 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -56,7 +56,6 @@ typedef struct GlusterAIOCB { int64_t size; int ret; Coroutine *coroutine; - AioContext *aio_context; } GlusterAIOCB; =20 typedef struct BDRVGlusterState { @@ -743,7 +742,17 @@ static void gluster_finish_aiocb(struct glfs_fd *fd, s= size_t ret, acb->ret =3D -EIO; /* Partial read/write - fail it */ } =20 - aio_co_schedule(acb->aio_context, acb->coroutine); + /* + * Safe to call: The coroutine will yield exactly once awaiting this + * scheduling, and the context is its own context, so it will be sched= uled + * once it does yield. + * + * (aio_co_wake() would call qemu_get_current_aio_context() to check w= hether + * we are in the same context, but we are not in a qemu thread, so we = cannot + * do that. Use aio_co_schedule() directly.) + */ + aio_co_schedule(qemu_coroutine_get_aio_context(acb->coroutine), + acb->coroutine); } =20 static void qemu_gluster_parse_flags(int bdrv_flags, int *open_flags) @@ -1006,7 +1015,6 @@ static coroutine_fn int qemu_gluster_co_pwrite_zeroes= (BlockDriverState *bs, acb.size =3D bytes; acb.ret =3D 0; acb.coroutine =3D qemu_coroutine_self(); - acb.aio_context =3D bdrv_get_aio_context(bs); =20 ret =3D glfs_zerofill_async(s->fd, offset, bytes, gluster_finish_aiocb= , &acb); if (ret < 0) { @@ -1184,7 +1192,6 @@ static coroutine_fn int qemu_gluster_co_rw(BlockDrive= rState *bs, acb.size =3D size; acb.ret =3D 0; acb.coroutine =3D qemu_coroutine_self(); - acb.aio_context =3D bdrv_get_aio_context(bs); =20 if (write) { ret =3D glfs_pwritev_async(s->fd, qiov->iov, qiov->niov, offset, 0, @@ -1251,7 +1258,6 @@ static coroutine_fn int qemu_gluster_co_flush_to_disk= (BlockDriverState *bs) acb.size =3D 0; acb.ret =3D 0; acb.coroutine =3D qemu_coroutine_self(); - acb.aio_context =3D bdrv_get_aio_context(bs); =20 ret =3D glfs_fsync_async(s->fd, gluster_finish_aiocb, &acb); if (ret < 0) { @@ -1299,7 +1305,6 @@ static coroutine_fn int qemu_gluster_co_pdiscard(Bloc= kDriverState *bs, acb.size =3D 0; acb.ret =3D 0; acb.coroutine =3D qemu_coroutine_self(); - acb.aio_context =3D bdrv_get_aio_context(bs); =20 ret =3D glfs_discard_async(s->fd, offset, bytes, gluster_finish_aiocb,= &acb); if (ret < 0) { --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762789810; cv=none; d=zohomail.com; s=zohoarc; b=cP4yZSpp5tjFpUt9IGg2bjsqN88Pr5L5hdUNgWXZL6iXIaeYSdPCMOPIIBBpnhUOghAialNBE7yLb7XcbxoI2WoyrDVmJhyQvKPwrNCMOHj54rvTzL5bXyXcKExwFL8Np3XzzqmUmi64/uo85yzz5PRpuLKG6rRYmcC70lzNMYI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762789810; 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=kcZ9cJ7XI8zX0UMxvj6MtEZfatW1I55Tpkyvd/DszeM=; b=cO+xhh1w87kqGCpBtEYJPu6I5zEKvM80o6zqv1zVTcmyLjAcau69/vopLIMokddiuHowUcsB5ev13OGq4YQ51HbGE53KExaW82b5fIBDJs/BoWOt8Iv38re/zVMrCx46H5mPHzQTUiE4YaUdFc6xMoopWZt3ecVPE+iHKylP0Do= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762789809986921.955685661034; Mon, 10 Nov 2025 07:50:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIU96-0006TU-LP; Mon, 10 Nov 2025 10:49:32 -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 1vIU94-0006Jv-H0 for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU92-0000xT-5a for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:29 -0500 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609--rNLfSNwOC-PsTFK1DoyZw-1; Mon, 10 Nov 2025 10:49:25 -0500 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-429c5f1e9faso2506313f8f.3 for ; Mon, 10 Nov 2025 07:49:25 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b32c1ad2bsm11323758f8f.6.2025.11.10.07.49.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789767; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kcZ9cJ7XI8zX0UMxvj6MtEZfatW1I55Tpkyvd/DszeM=; b=AZ4N9SSJ5fnZi7ME7llYwuNvrUPOtWKrYBoJrOiM3nMrVS+13/kqSmXOBTcvRRhkBiKkcT f+KMIDeQ28H0Ak69S0791qw7A0vEx3SuRvX24a7h5hfZpPoxtNLk9LEjVLiZlzOjHUf70i hwcS9I/eoITsAyVjOhL6C9J1kOCMD2Y= X-MC-Unique: -rNLfSNwOC-PsTFK1DoyZw-1 X-Mimecast-MFC-AGG-ID: -rNLfSNwOC-PsTFK1DoyZw_1762789765 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789764; x=1763394564; 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=kcZ9cJ7XI8zX0UMxvj6MtEZfatW1I55Tpkyvd/DszeM=; b=OuEA9Xw2eJ0Oc2mYE7sG+cZbd2NPJzzZKYebmOZC2a85WpTXjIGbFPz5F/98FNgxT3 QcXJoYTPntv1qlHGbXArEtt2kFq4HYiB+3lnm5DCviLG5C4tThiQjM4VmULaKf0jaPlr VpUHY7nqJhySCRVDay/YYVsW3R7CbIppnghwKGZYVrvZzz07xKRNx3D9J+RGPZwFBAfZ psChpLt/Wd7zOkj4b6cSozrI/qPk0a2uQuikXcLGPWq+TGphCPa48as4W8nh/Qr07gJE gGTX2GKSUPgaiY660Hh1E0dUuGEUNRxbidANXd+MpPKBLGph6j+lt7l1XMBXGvYfBTye /h7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789764; x=1763394564; 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=kcZ9cJ7XI8zX0UMxvj6MtEZfatW1I55Tpkyvd/DszeM=; b=bk0bOlPOPvN5Wd7Ct5UxcegicQaN3Vd9ZO9RY1ltTxXpZuGTsv8+xCG2OWtA5vRfND 2Y2A82zllwa3Hi3iCiW2maefZJ5BCVj6WG63RDkK+GIng9gt4B86Pr//2P4T4/S9IlXm XPxAbjvep3hsNjrEkACdUx7MpHfKx4tRZ3H980ZWQfIi1gZYnPzHx00oF6YA4WZOU44j jzDsFfVjuWrXtX+qxl/t2pfMj0AF948RLhgp3LCPoLGQ38Q92MmEbKv6ImFt/RgAQUpo T7p5BQLrbsgcqjVBJ39o9oNsT7RKmsHsrdxBJ0AKN2z+C7m6IrtRJquTs8Rbgy+sSnRb lCzg== X-Gm-Message-State: AOJu0Yyc4kOAlLlyFesVl/3EVTYG0UuBXPcr7ER7n+iNyyhXQK48QYAi Wdoz3+yR1kH7wUsrP3Kn9KXgrpksdshaT4kziUiSgEeqKT3RrK8WUTLTCTzpdGnT2136h5m8yim oGtRhVVh/enGAE65AhFw2EjZFgwsmtTdOu6tSEjdHd0yl1x9J6C5AmGt8 X-Gm-Gg: ASbGncu4ZNpUEBmomU0+/BL3lKkg+ZodVCTsKnpfYeMY+yBSy/mdnqMGWtQFSz884fg 2GEX+r2qpD2h163/0eIcoUcqs0+LDTj2aFdfVi/1DKtIwKP3cFiTxOHchkIA6H5Rju54kYMZaK6 hwFPIjXOk/2GKXkpSKTKynP4BTYx7ZXiDDlHrUZi1wy+mtICbX9NIDJiN3V+jSQpfGrfpUGeMgI +2AyPn5TrAMdiJsyVNd7/VSD/JYCpDMhznE0BRPT+zXPVaUOaeO5t0cyo7X9aadBefmcqxnsfxE 1MiXiqeq2XDTcSalg5Lg/KVRLbs3/t3OOHx+VukON3uRpuKsiALw8t1TBLyDl8YURp/tmJViKIW huyJogJQwETXbbjgQKuOov3TRmwk2VIWk3gUhocfeq0Il4lh0Jfu02S6iBQ== X-Received: by 2002:a05:6000:4212:b0:42b:3c25:cd06 with SMTP id ffacd0b85a97d-42b3c25d15emr2680114f8f.22.1762789764440; Mon, 10 Nov 2025 07:49:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IFMzYHbRYGc459AF8fuJ+BcXpot5aWeQZFSTZQxsQG73NJOnqkFgTeJXT+c4kjmUbrCZSYMrg== X-Received: by 2002:a05:6000:4212:b0:42b:3c25:cd06 with SMTP id ffacd0b85a97d-42b3c25d15emr2680084f8f.22.1762789764041; Mon, 10 Nov 2025 07:49:24 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 07/19] nvme: Kick and check completions in BDS context Date: Mon, 10 Nov 2025 16:48:42 +0100 Message-ID: <20251110154854.151484-8-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1762789811636158500 nvme_process_completion() must run in the main BDS context, so schedule a BH for requests that aren=E2=80=99t there. The context in which we kick does not matter, but let=E2=80=99s just keep k= ick and process_completion together for simplicity=E2=80=99s sake. (For what it=E2=80=99s worth, a quick fio bandwidth test indicates that on = my test hardware, if anything, this may be a bit better than kicking immediately before scheduling a pure nvme_process_completion() BH. But I wouldn=E2=80=99t take more from those results than that it doesn=E2=80=99= t really seem to matter either way.) Cc: qemu-stable@nongnu.org Signed-off-by: Hanna Czenczek --- block/nvme.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/block/nvme.c b/block/nvme.c index 8df53ee4ca..7ed5f570bc 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -481,7 +481,7 @@ static void nvme_trace_command(const NvmeCmd *cmd) } } =20 -static void nvme_deferred_fn(void *opaque) +static void nvme_kick_and_check_completions(void *opaque) { NVMeQueuePair *q =3D opaque; =20 @@ -490,6 +490,18 @@ static void nvme_deferred_fn(void *opaque) nvme_process_completion(q); } =20 +static void nvme_deferred_fn(void *opaque) +{ + NVMeQueuePair *q =3D opaque; + + if (qemu_get_current_aio_context() =3D=3D q->s->aio_context) { + nvme_kick_and_check_completions(q); + } else { + aio_bh_schedule_oneshot(q->s->aio_context, + nvme_kick_and_check_completions, q); + } +} + static void nvme_submit_command(NVMeQueuePair *q, NVMeRequest *req, NvmeCmd *cmd, BlockCompletionFunc cb, void *opaque) --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762789786; cv=none; d=zohomail.com; s=zohoarc; b=QBSAx/1jYrr3iy+a/vo2wI7IVd/hCCH+6D93iJlDw/Vfxib+ph4SVGFvSMZy3GllA/U+Eqz5XJ3xNUm8uVU2jxEGXpYNCC1qLWVwxvFlM7tzWdQVzEtrOENqvLnylZG41sCyjSydpmT35712Jpfpi9x4hTrpVG3WIaROO/fuWZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762789786; 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=NMx550ACO7zDOBBqwioSHioy3m7Jbt+MKTb/hDJ7dnk=; b=T5ZMBOrS4+4i36lrlbrunFWeA6cLufmitLxhrtW7Wfg4vLOSD3+Ohc80O2BLFWjN4ZMF2LxLeZ/GICKSwhNvz5bJ1kB+j+gPoTYUIuzFBkZY6GA/b93eaG84hrwCFpG96jZCTvHMInGsN3ML5kta1SQcik7EX1IxUi4gZhFP64I= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 176278978616873.00055771632526; Mon, 10 Nov 2025 07:49:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIU9E-0006mv-B9; Mon, 10 Nov 2025 10:49:40 -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 1vIU97-0006XU-6K for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU94-0000yD-Lf for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:32 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-398-BdNwteTAMvaY9w1kmAEPLQ-1; Mon, 10 Nov 2025 10:49:29 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-47106a388cfso17177955e9.0 for ; Mon, 10 Nov 2025 07:49:28 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b303386f1sm14432126f8f.3.2025.11.10.07.49.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NMx550ACO7zDOBBqwioSHioy3m7Jbt+MKTb/hDJ7dnk=; b=c/Ff04uE0hQzOfH5xRZJWz0qroJLhJjJ1LO3HHY5XKW+3CHyDW5GnsPPWvIDJbrMKSJN0o pOS6mnnwmAEmYhLmCBpScMcHHx7jxi69kuOdEZmQ3JFoyLU4ylmc+DRhR2zRr0QIDSsouI 55ONxd4e7DRvpQa8yWy0VeNlUeZiCjw= X-MC-Unique: BdNwteTAMvaY9w1kmAEPLQ-1 X-Mimecast-MFC-AGG-ID: BdNwteTAMvaY9w1kmAEPLQ_1762789768 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789768; x=1763394568; 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=NMx550ACO7zDOBBqwioSHioy3m7Jbt+MKTb/hDJ7dnk=; b=Ap01cP7dCjOssFqAJtXgJUCo6cGj7eBLHubTBzy80g0EFyohSAOJqb63aJWClY3UMW 64SwIfrRGnLWis3ztzWNl+psMi6z2vptr1WMGRr3rIeGpmQPrOZ/scKn1JwU05gXZfwp 15WN64NJWmaJUHSgDzvP06t7DlusUKNDQtFT2d0mq9as7VCLRHtsmcCVYZGy4T9e1HZH yEkgikVkgUR44aJJ0yhhKjkuPxsTZf2Q0iDpPayNEWZ6y3gKxZ6KGw9Wfx013YD/51wF f3lOufH9EOXVmjbtCb2X5jSKDpIuNUL0P8+WRWOSO6HWYNIJhFxbQCLaFEc9/sV6znvm uBAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789768; x=1763394568; 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=NMx550ACO7zDOBBqwioSHioy3m7Jbt+MKTb/hDJ7dnk=; b=aPt4iL6Y3lWQdhZT2HzNfYWUg/USp/bzivXNdV6aXNzVBhp5UUgvQvV83HljUB02x3 9xuuPx6gVFdFo4ngRgiN6ft3XnkJXw6yYP0qqb3ro52G/t3spFivkHHPXwzfeyQrrBhv y22tZj0UsMc0fTKnnUvD4eIfmUGyPh8bwI+JeipchYQPaPlnsgs28SEs8noU5cMGE7ZN C454QU+iDszvVgDVLzeRhL4Ah6RuF0I0A9mpZ+/R5lmtPxyYZVqAExX9q0g3d9bTbrCW gyLmrmWDe5Wo8wy9t1RWD6V3AghtvchokZ0cVTlKKCEMwNY8b7vJ5/v0IOV6s/uN2tAG Z5lw== X-Gm-Message-State: AOJu0YxgKJd2mgtzSQFCtwm/AGltB5A97ZXAPF4Z3BXs3P8GrNUmp/ZC jKiUSvRjlTb1FnVjgOenz95Qm6DIRGVdvSqoxxsmiWEbwR/UI/+1x2+jLkoeSSJHtQduh04/TjU 7kghYyvARLdbLtn2Hts1gCBOo8Bb8oDqFhr3IjybrwT6uy1IgLaYj2O9U X-Gm-Gg: ASbGnct2AD84K7v/GNIHwOdPkZVaZoVO0McZssdRbXmts56UxMaElV6GAfF+wsgaqAx BQQVQAM76fm8MI4N9l9lz8Ko91B21Qvz998cau43RS9JrpzjdtkvENDAHK18lujmq1CW/B0MbHP /s/jDIn7h9480VWrMiO/VFVC9ErVOsGN+QKlGQuv3Xu65surxdhI3BDwxQL2KgktL398Iq91tis Jzb3DpXxgUGIAhNfqzM2quUI2N1/CDZhbKERPdG/s7cOH/O4gjyj2IbY2bBaDmpDs3xUsEj3bS2 hz4qCZacdnPVQEMY8cmMKsk6zTvPM9ULNPAPs4bCxasR8Fi99EWbBxbz1ZcCKvSqbpDOLHNtUx/ rfsayaUmFhWLLUmpMmDc+VVNJuzxw9e6KxM23mocdI+39CDVX8ETIxtBRGw== X-Received: by 2002:a05:600c:3113:b0:477:e66:4077 with SMTP id 5b1f17b1804b1-477732939admr79689835e9.29.1762789767596; Mon, 10 Nov 2025 07:49:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHOK9MF2jSGA/iwWXhfy+PMefCuGoC6PvIkmluFJO0zeDJkoNik5ogboaaihZzutpy+zxQxuA== X-Received: by 2002:a05:600c:3113:b0:477:e66:4077 with SMTP id 5b1f17b1804b1-477732939admr79689445e9.29.1762789767159; Mon, 10 Nov 2025 07:49:27 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 08/19] nvme: Fix coroutine waking Date: Mon, 10 Nov 2025 16:48:43 +0100 Message-ID: <20251110154854.151484-9-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1762789787251158500 nvme wakes the request coroutine via qemu_coroutine_enter() from a BH scheduled in the BDS AioContext. This may not be the same context as the one in which the request originally ran, which would be wrong: - It could mean we enter the coroutine before it yields, - We would move the coroutine in to a different context. (Can be reproduced with multiqueue by adding a usleep(100000) before the `while (data.ret =3D=3D -EINPROGRESS)` loop.) To fix that, use aio_co_wake() to run the coroutine in its home context. Just like in the preceding iscsi and nfs patches, we can drop the trivial nvme_rw_cb_bh() and use aio_co_wake() directly. With this, we can remove NVMeCoData.ctx. Note the check of data->co =3D=3D NULL to bypass the BH/yield combination in case nvme_rw_cb() is called from nvme_submit_command(): We probably want to keep this fast path for performance reasons, but we have to be quite careful about it: - We cannot overload .ret for this, but have to use a dedicated .skip_yield field. Otherwise, if nvme_rw_cb() runs in a different thread than the coroutine, it may see .ret set and skip the yield, while nvme_rw_cb() will still schedule a BH for waking. Therefore, the signal to skip the yield can only be set in nvme_rw_cb() if waking too is skipped, which is independent from communicating the return value. - We can only skip the yield if nvme_rw_cb() actually runs in the request coroutine. Otherwise (specifically if they run in different AioContexts), the order between this function=E2=80=99s execution and the coroutine yielding (or not yielding) is not reliable. - There is no point to yielding in a loop; there are no spurious wakes, so once we yield, we will only be re-entered once the command is done. Replace `while` by `if`. Cc: qemu-stable@nongnu.org Signed-off-by: Hanna Czenczek --- block/nvme.c | 56 +++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 7ed5f570bc..b8262ebfd9 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -1176,25 +1176,35 @@ fail: =20 typedef struct { Coroutine *co; + bool skip_yield; int ret; - AioContext *ctx; } NVMeCoData; =20 -static void nvme_rw_cb_bh(void *opaque) -{ - NVMeCoData *data =3D opaque; - qemu_coroutine_enter(data->co); -} - static void nvme_rw_cb(void *opaque, int ret) { NVMeCoData *data =3D opaque; + data->ret =3D ret; - if (!data->co) { - /* The rw coroutine hasn't yielded, don't try to enter. */ - return; + + if (data->co =3D=3D qemu_coroutine_self()) { + /* + * Fast path: We are inside of the request coroutine (through + * nvme_submit_command, nvme_deferred_fn, nvme_process_completion). + * We can set data->skip_yield here to keep the coroutine from + * yielding, and then we don't need to schedule a BH to wake it. + */ + data->skip_yield =3D true; + } else { + /* + * Safe to call: The case where we run in the request coroutine is + * handled above, so we must be independent of it; and without + * skip_yield set, the coroutine will yield. + * No need to release NVMeQueuePair.lock (we are called without it + * held). (Note: If we enter the coroutine here, @data will + * probably be dangling once aio_co_wake() returns.) + */ + aio_co_wake(data->co); } - replay_bh_schedule_oneshot_event(data->ctx, nvme_rw_cb_bh, data); } =20 static coroutine_fn int nvme_co_prw_aligned(BlockDriverState *bs, @@ -1218,7 +1228,7 @@ static coroutine_fn int nvme_co_prw_aligned(BlockDriv= erState *bs, .cdw12 =3D cpu_to_le32(cdw12), }; NVMeCoData data =3D { - .ctx =3D bdrv_get_aio_context(bs), + .co =3D qemu_coroutine_self(), .ret =3D -EINPROGRESS, }; =20 @@ -1235,9 +1245,7 @@ static coroutine_fn int nvme_co_prw_aligned(BlockDriv= erState *bs, return r; } nvme_submit_command(ioq, req, &cmd, nvme_rw_cb, &data); - - data.co =3D qemu_coroutine_self(); - while (data.ret =3D=3D -EINPROGRESS) { + if (!data.skip_yield) { qemu_coroutine_yield(); } =20 @@ -1333,7 +1341,7 @@ static coroutine_fn int nvme_co_flush(BlockDriverStat= e *bs) .nsid =3D cpu_to_le32(s->nsid), }; NVMeCoData data =3D { - .ctx =3D bdrv_get_aio_context(bs), + .co =3D qemu_coroutine_self(), .ret =3D -EINPROGRESS, }; =20 @@ -1341,9 +1349,7 @@ static coroutine_fn int nvme_co_flush(BlockDriverStat= e *bs) req =3D nvme_get_free_req(ioq); assert(req); nvme_submit_command(ioq, req, &cmd, nvme_rw_cb, &data); - - data.co =3D qemu_coroutine_self(); - if (data.ret =3D=3D -EINPROGRESS) { + if (!data.skip_yield) { qemu_coroutine_yield(); } =20 @@ -1384,7 +1390,7 @@ static coroutine_fn int nvme_co_pwrite_zeroes(BlockDr= iverState *bs, }; =20 NVMeCoData data =3D { - .ctx =3D bdrv_get_aio_context(bs), + .co =3D qemu_coroutine_self(), .ret =3D -EINPROGRESS, }; =20 @@ -1404,9 +1410,7 @@ static coroutine_fn int nvme_co_pwrite_zeroes(BlockDr= iverState *bs, assert(req); =20 nvme_submit_command(ioq, req, &cmd, nvme_rw_cb, &data); - - data.co =3D qemu_coroutine_self(); - while (data.ret =3D=3D -EINPROGRESS) { + if (!data.skip_yield) { qemu_coroutine_yield(); } =20 @@ -1434,7 +1438,7 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverS= tate *bs, }; =20 NVMeCoData data =3D { - .ctx =3D bdrv_get_aio_context(bs), + .co =3D qemu_coroutine_self(), .ret =3D -EINPROGRESS, }; =20 @@ -1479,9 +1483,7 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverS= tate *bs, trace_nvme_dsm(s, offset, bytes); =20 nvme_submit_command(ioq, req, &cmd, nvme_rw_cb, &data); - - data.co =3D qemu_coroutine_self(); - while (data.ret =3D=3D -EINPROGRESS) { + if (!data.skip_yield) { qemu_coroutine_yield(); } =20 --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762789873; cv=none; d=zohomail.com; s=zohoarc; b=JjNFdIOsQ9hzt/4f6VbnF4rbI/qdFPqB8Xn2kN89AwEMz5OoZ5IH1AxGzySxa+rTJoRqjsm4zekjMuVR3TBxyBMtjPpGFsaQsRpr8y3zwQnpmtDoF+mReZ+3igReowGLKNnySf/mFu/0DuCCEtoiIN1Ndw+jtiSlZ290xIgdmZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762789873; 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=8wrcNkTgNRfkRNsQTS+diw+Pjtpi/kOJzRkxlDubojE=; b=m6vRzTUezRz3Gl/Z910ZcTTH5LR+ruzPw3jtjg1d+M0Hp5pLBDQG+uVC/PF+4+wscfMR03NRGawbqHYAZe4v6mWMGfducy/O0G4MLIIMZ+UHwYihhf4D71xVx2XZYgsF3tnvS6jHeLsqly2vpn33uAMNKO1Ic1NR9c2CNJvZmyY= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762789873018513.4464631566882; Mon, 10 Nov 2025 07:51:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIU9P-0007Fm-39; Mon, 10 Nov 2025 10:49:51 -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 1vIU99-0006nA-Sg for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU97-0000zS-Tu for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:35 -0500 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-528-aH-y71qQP-iRPR3Lg-GL9w-1; Mon, 10 Nov 2025 10:49:31 -0500 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-429c93a28ebso2418232f8f.1 for ; Mon, 10 Nov 2025 07:49:31 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b35ad7c16sm10061281f8f.15.2025.11.10.07.49.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789773; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8wrcNkTgNRfkRNsQTS+diw+Pjtpi/kOJzRkxlDubojE=; b=V4AuciP/pQ4xS5azpYGHJJd0xAspnveUDHNJoQlPnH+mAbxXNkWv3QcToUl7Wt2Xd+iM+U 1IfACPDo/evn/OF5lpZQH8QjLS86Pjg/sMtdwuDLtvDV3qFw3kXjgA4vDn80FRW4QOzoxN iQewf0HD57XHvZgA8F42dwFonJWRUVk= X-MC-Unique: aH-y71qQP-iRPR3Lg-GL9w-1 X-Mimecast-MFC-AGG-ID: aH-y71qQP-iRPR3Lg-GL9w_1762789771 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789770; x=1763394570; 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=8wrcNkTgNRfkRNsQTS+diw+Pjtpi/kOJzRkxlDubojE=; b=eHPQ5H/AZ1BSBePOZ4JIeQFmnKWzsLYoqrQ32iWvd4Y3ICRf504o9AO2HyZ+1BKQLy o+7sZ/KemkoBwZwzRiP5GzP/AU2sR7OvAhhY+SiVuPGRGUSdonoX8IMh4Mz9WWOoVw5+ +DQo2tCiBYQDua39i9gjdx8pBHVAUJhH0NErPGfRfjFg/z1EbMPNo4wEWJGvxQKUwM5y xjTJkRWra8qAaFXMgiHdNbEfT6KJ9C7nNdCUOcdDMi7ZHMoP6vXsJoDa2W46ue2izoPl nPpYcrceXsBePQtsVsGJ7ujP4Vj+0ZKsi0c15d6DesYF/y1iyr5Beir6V/1drrzt/AZg +uSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789770; x=1763394570; 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=8wrcNkTgNRfkRNsQTS+diw+Pjtpi/kOJzRkxlDubojE=; b=Uw7Eie/35gbqKbyh14nnog39ZCvFMqEfw17AKQSE3/Z6XTypoSu5uNC7mRwnrdBf7e uwa4y6NtbKRHQYESFY99Tb97PxDV8AzIdOiW/JRr50LjKR2FdoDpXrMnudcmi9HPWePC u5sT2REJ6Ukt0G7mYmyzQu29Gy80HPl/l92z35xIMq/2DUfXgwhi6Cl05n+juzsgWZsN RG6U8FlY2FPjKqwjsxOzo9zdTPaT797FWzEb0MP5WV3PB40kF0IoCzyYBgFLj4bLjNUF anxDbNGRZsVTcX2Fq41vPyEH3NAZr4uYl7lrqv2+7i6Ic1iWqKq67ULiqHrcGUJKt9g6 6rqQ== X-Gm-Message-State: AOJu0YyinLX7MXap/+m4hv7KzDt2P5Yd6VitZeybZZZjtUWNAjQm4cAM nEPEh1ThTCdHDUqAO+mcbpK7qXNSx/YCQXcsRBdHgCpq11um/eDFgW5fGDJxH9XWwhvtsZfpr3P eP66tOHhrxCW6CVEJali0cwwujhECaJd3r7C0CPFWSb2n5eSWJtVo0wwb X-Gm-Gg: ASbGncv/DlU+HwkJU7mtduQdXFl1gEdmoHtgfG1KXMB9EoRg0P35NY7/6zIgEVF+YOc w8FtRyzhGypSwExArglPrqSYSlnvMlWvQLI1kFgusOUoiQyN5dp2JtA3msu6Ut2rQtQoq3xR+7s gitdnYo9RF+yq/v+CJIEjdsoBUsuwxzf6Oeqe2M2BiRU2GdeLEatxwnX2ngSQNQ3/aE9MMrF6LY lBtMGlw5wjHekOCI2EdTKZknydgmt1l0nGx+wwFYnFIjK4ZRUlCinRqwTSVsd+FefHBo3tSeNrg wArGi1BkwuZR70eIl5fU7wEyDVwRTXA/ga3F8sPCdBX6bfdfO4uakNOJGx+31cpk23HchhpBDqH iGbB178XTV96xFRyOOq9p/IUTctMCPNV2oopHscFt3QR+t1A/+PnW/VICgg== X-Received: by 2002:a05:6000:42c9:b0:42b:2ea5:6191 with SMTP id ffacd0b85a97d-42b2ea564d3mr5113263f8f.60.1762789770412; Mon, 10 Nov 2025 07:49:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnLHqU9xlVoNCGbuzgYZ9KKJEA5tebxpveycihmXe9VnGsql7xSia63o2KNUEY6B/kq4GawQ== X-Received: by 2002:a05:6000:42c9:b0:42b:2ea5:6191 with SMTP id ffacd0b85a97d-42b2ea564d3mr5113229f8f.60.1762789769926; Mon, 10 Nov 2025 07:49:29 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 09/19] nvme: Note in which AioContext some functions run Date: Mon, 10 Nov 2025 16:48:44 +0100 Message-ID: <20251110154854.151484-10-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 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=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1762789874633158500 Content-Type: text/plain; charset="utf-8" Sprinkle comments throughout block/nvme.c noting for some functions (where it may not be obvious) that they require a certain AioContext, or in which AioContext they do happen to run (for callbacks, BHs, event notifiers). Suggested-by: Kevin Wolf Signed-off-by: Hanna Czenczek --- block/nvme.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index b8262ebfd9..919e14cef9 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -65,6 +65,7 @@ typedef struct { } NVMeQueue; =20 typedef struct { + /* Called from nvme_process_completion() in the BDS's main AioContext = */ BlockCompletionFunc *cb; void *opaque; int cid; @@ -84,6 +85,7 @@ typedef struct { uint8_t *prp_list_pages; =20 /* Fields protected by @lock */ + /* Coroutines in this queue are woken in their own context */ CoQueue free_req_queue; NVMeQueue sq, cq; int cq_phase; @@ -92,7 +94,7 @@ typedef struct { int need_kick; int inflight; =20 - /* Thread-safe, no lock necessary */ + /* Thread-safe, no lock necessary; runs in the BDS's main context */ QEMUBH *completion_bh; } NVMeQueuePair; =20 @@ -206,11 +208,13 @@ static void nvme_free_queue_pair(NVMeQueuePair *q) g_free(q); } =20 +/* Runs in the BDS's main AioContext */ static void nvme_free_req_queue_cb(void *opaque) { NVMeQueuePair *q =3D opaque; =20 qemu_mutex_lock(&q->lock); + /* qemu_co_enter_next() wakes the coroutine in its own AioContext */ while (q->free_req_head !=3D -1 && qemu_co_enter_next(&q->free_req_queue, &q->lock)) { /* Retry waiting requests */ @@ -281,7 +285,7 @@ fail: return NULL; } =20 -/* With q->lock */ +/* With q->lock, must be run in the BDS's main AioContext */ static void nvme_kick(NVMeQueuePair *q) { BDRVNVMeState *s =3D q->s; @@ -308,7 +312,10 @@ static NVMeRequest *nvme_get_free_req_nofail_locked(NV= MeQueuePair *q) return req; } =20 -/* Return a free request element if any, otherwise return NULL. */ +/* + * Return a free request element if any, otherwise return NULL. + * May be run from any AioContext. + */ static NVMeRequest *nvme_get_free_req_nowait(NVMeQueuePair *q) { QEMU_LOCK_GUARD(&q->lock); @@ -321,6 +328,7 @@ static NVMeRequest *nvme_get_free_req_nowait(NVMeQueueP= air *q) /* * Wait for a free request to become available if necessary, then * return it. + * May be called in any AioContext. */ static coroutine_fn NVMeRequest *nvme_get_free_req(NVMeQueuePair *q) { @@ -328,20 +336,21 @@ static coroutine_fn NVMeRequest *nvme_get_free_req(NV= MeQueuePair *q) =20 while (q->free_req_head =3D=3D -1) { trace_nvme_free_req_queue_wait(q->s, q->index); + /* nvme_free_req_queue_cb() wakes us in our own AioContext */ qemu_co_queue_wait(&q->free_req_queue, &q->lock); } =20 return nvme_get_free_req_nofail_locked(q); } =20 -/* With q->lock */ +/* With q->lock, may be called in any AioContext */ static void nvme_put_free_req_locked(NVMeQueuePair *q, NVMeRequest *req) { req->free_req_next =3D q->free_req_head; q->free_req_head =3D req - q->reqs; } =20 -/* With q->lock */ +/* With q->lock, may be called in any AioContext */ static void nvme_wake_free_req_locked(NVMeQueuePair *q) { if (!qemu_co_queue_empty(&q->free_req_queue)) { @@ -350,7 +359,7 @@ static void nvme_wake_free_req_locked(NVMeQueuePair *q) } } =20 -/* Insert a request in the freelist and wake waiters */ +/* Insert a request in the freelist and wake waiters (from any AioContext)= */ static void nvme_put_free_req_and_wake(NVMeQueuePair *q, NVMeRequest *req) { qemu_mutex_lock(&q->lock); @@ -381,7 +390,7 @@ static inline int nvme_translate_error(const NvmeCqe *c) } } =20 -/* With q->lock */ +/* With q->lock, must be run in the BDS's main AioContext */ static bool nvme_process_completion(NVMeQueuePair *q) { BDRVNVMeState *s =3D q->s; @@ -451,6 +460,7 @@ static bool nvme_process_completion(NVMeQueuePair *q) return progress; } =20 +/* As q->completion_bh, runs in the BDS's main AioContext */ static void nvme_process_completion_bh(void *opaque) { NVMeQueuePair *q =3D opaque; @@ -481,6 +491,7 @@ static void nvme_trace_command(const NvmeCmd *cmd) } } =20 +/* Must be run in the BDS's main AioContext */ static void nvme_kick_and_check_completions(void *opaque) { NVMeQueuePair *q =3D opaque; @@ -490,6 +501,7 @@ static void nvme_kick_and_check_completions(void *opaqu= e) nvme_process_completion(q); } =20 +/* Runs in nvme_submit_command()'s AioContext */ static void nvme_deferred_fn(void *opaque) { NVMeQueuePair *q =3D opaque; @@ -502,6 +514,7 @@ static void nvme_deferred_fn(void *opaque) } } =20 +/* May be run in any AioContext */ static void nvme_submit_command(NVMeQueuePair *q, NVMeRequest *req, NvmeCmd *cmd, BlockCompletionFunc cb, void *opaque) @@ -523,6 +536,7 @@ static void nvme_submit_command(NVMeQueuePair *q, NVMeR= equest *req, defer_call(nvme_deferred_fn, q); } =20 +/* Put into NVMeRequest.cb, so runs in the BDS's main AioContext */ static void nvme_admin_cmd_sync_cb(void *opaque, int ret) { int *pret =3D opaque; @@ -530,6 +544,7 @@ static void nvme_admin_cmd_sync_cb(void *opaque, int re= t) aio_wait_kick(); } =20 +/* Must be run in the BDS's or qemu's main AioContext */ static int nvme_admin_cmd_sync(BlockDriverState *bs, NvmeCmd *cmd) { BDRVNVMeState *s =3D bs->opaque; @@ -638,6 +653,7 @@ out: return ret; } =20 +/* Must be run in the BDS's main AioContext */ static void nvme_poll_queue(NVMeQueuePair *q) { const size_t cqe_offset =3D q->cq.head * NVME_CQ_ENTRY_BYTES; @@ -660,6 +676,7 @@ static void nvme_poll_queue(NVMeQueuePair *q) qemu_mutex_unlock(&q->lock); } =20 +/* Must be run in the BDS's main AioContext */ static void nvme_poll_queues(BDRVNVMeState *s) { int i; @@ -669,6 +686,7 @@ static void nvme_poll_queues(BDRVNVMeState *s) } } =20 +/* Run as an event notifier in the BDS's main AioContext */ static void nvme_handle_event(EventNotifier *n) { BDRVNVMeState *s =3D container_of(n, BDRVNVMeState, @@ -722,6 +740,7 @@ out_error: return false; } =20 +/* Run as an event notifier in the BDS's main AioContext */ static bool nvme_poll_cb(void *opaque) { EventNotifier *e =3D opaque; @@ -745,6 +764,7 @@ static bool nvme_poll_cb(void *opaque) return false; } =20 +/* Run as an event notifier in the BDS's main AioContext */ static void nvme_poll_ready(EventNotifier *e) { BDRVNVMeState *s =3D container_of(e, BDRVNVMeState, @@ -1050,7 +1070,7 @@ static int nvme_probe_blocksizes(BlockDriverState *bs= , BlockSizes *bsz) return 0; } =20 -/* Called with s->dma_map_lock */ +/* Called with s->dma_map_lock, may be run in any AioContext */ static coroutine_fn int nvme_cmd_unmap_qiov(BlockDriverState *bs, QEMUIOVector *qiov) { @@ -1061,13 +1081,17 @@ static coroutine_fn int nvme_cmd_unmap_qiov(BlockDr= iverState *bs, if (!s->dma_map_count && !qemu_co_queue_empty(&s->dma_flush_queue)) { r =3D qemu_vfio_dma_reset_temporary(s->vfio); if (!r) { + /* + * Queue access is protected by the dma_map_lock, and all + * coroutines are woken in their own AioContext + */ qemu_co_queue_restart_all(&s->dma_flush_queue); } } return r; } =20 -/* Called with s->dma_map_lock */ +/* Called with s->dma_map_lock, may be run in any AioContext */ static coroutine_fn int nvme_cmd_map_qiov(BlockDriverState *bs, NvmeCmd *c= md, NVMeRequest *req, QEMUIOVector *= qiov) { @@ -1180,6 +1204,7 @@ typedef struct { int ret; } NVMeCoData; =20 +/* Put into NVMeRequest.cb, so runs in the BDS's main AioContext */ static void nvme_rw_cb(void *opaque, int ret) { NVMeCoData *data =3D opaque; --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762789959; cv=none; d=zohomail.com; s=zohoarc; b=jQFRf+5xBxZSakyyxC9zobV4o+JoDLpBoTuKkWXqAxj2ftwHkskW8TaGRbpQcAfBBgvfHrEG6svRmU1GzQ1UkwVWi3uKbb4VTU/2D42kB0iwGTI+8dBP6iVlz+HmOYClC48aJHr5tZpka53IZBae9t716uWioDd6d736ky2vYug= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762789959; 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=vwv9oMOX+8cIAIEsBEPdJ3rvIMuXO+17mCsS5r9mpPo=; b=OnWg4uGwYwWaz1nF6CJQRI71CYcMWu3LZxaWaUGusrknw3o+w6s2PeEVUT/wP3BCo+oEALK1TX9UHwSRy6biAoO2Z9fVYdltvlsVAKY+9gCeOU5OKQ3NbUVlHvoUs254dzJxG8vaZAToA4eIGddo8AnCFy3eI+aSP7wP+21pF+s= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762789959436464.6802553963049; Mon, 10 Nov 2025 07:52:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIU9R-0007T2-32; Mon, 10 Nov 2025 10:49:54 -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 1vIU9H-00070G-Cg for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU9F-00011Q-Vq for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:43 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-582-bTScq2cYNXSkP67xKSY4MA-1; Mon, 10 Nov 2025 10:49:34 -0500 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-47496b3c1dcso24248475e9.3 for ; Mon, 10 Nov 2025 07:49:34 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b2dd927c9sm16143240f8f.27.2025.11.10.07.49.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vwv9oMOX+8cIAIEsBEPdJ3rvIMuXO+17mCsS5r9mpPo=; b=ae83U/wca6wfFtQUDySxHbwXlNb2NlSOjD7cD56c0B8vfCWau64TirUEmt+1/leQzEdT2N uYkvedlI7XmmYomwTJiEJaGKUS8ptgAtsU2mZN6ZckY8jWNAnkvZ66+mfFzh3s3la1TAzr mUw5fz26iAUYkUDz+7ZpZXNKsh/4Iwg= X-MC-Unique: bTScq2cYNXSkP67xKSY4MA-1 X-Mimecast-MFC-AGG-ID: bTScq2cYNXSkP67xKSY4MA_1762789774 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789773; x=1763394573; 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=vwv9oMOX+8cIAIEsBEPdJ3rvIMuXO+17mCsS5r9mpPo=; b=ZbRnT7etDTcauHSNoE1bG/6d8Wnc0u4GUAN6an6I6m3+l8JxOX4M2BXbMnNCYxMZ0d y384XL6PKQcyQs59MamglXDzwIYQAK1kkAtj/ZUkf9/jzHmmnhJyoCLIam7g7PetTUWy ISirk8X3eNao/oerxnwJBbyLvoPI7wOmvR054AEesgRbIkFweOLrKtBHATT1pxR57Q++ M9so265+8uzhtRSvoi16zHN+JICw4/qPVmMy+w7OPclOfnW2OnI8ZUfYjzZwufh6zSzq UnfgGogZsDpqBM3s1zYNNZMiX1F66AgNU8JwTmf89M56921lCrzav0gVKD/5dunG54tw hJHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789773; x=1763394573; 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=vwv9oMOX+8cIAIEsBEPdJ3rvIMuXO+17mCsS5r9mpPo=; b=F/6EZ8N/A0BReJf8QPU4QTpR20/VCQOJw/JwZ0P0dLGXZmDbfoTwZr2ZjHprRn5GBw LnmpWX9weO0x3KHKfAc9kEJxSWPBPoRwH169M4OAdKNgwCtpbQNy+Yu1QlJnuK2Q8QpJ AlolhgGFe/qunFp78QtdB40VaV6YCOAMZyZIeSnU394Q/fPJhllxg1aT4+eGgP0n+gBH 2m4l4tvBl0l8mu6Msox8A9UbvFTQaIEmi0ud58s5Paz2nxJz7v4B+oNaBgIjcNGxR31Z 6x4fQ3AGudncHYIXGBWi6CBRMrIP11/iKJoSXXJ5R/IMFNgv0/Qrg2T0Xrl5qHyaH+GQ hyfQ== X-Gm-Message-State: AOJu0Yyxy/gG5tJQWkS28mGERdlqhAE27LikUk3lxrZD5K//1exG8Znw F/cHykM7jYQ3KRiYgnwcnMiC7Il3MfiqZwQoT8/0nSPAad8FNdUIT/jGEL7I3EVRmQE3e6kt79m xCsLaeyrioYnjDEad5ZJNQJCzkgLRFBhGSgm6ziW/p+xk21uxBOfozI4G X-Gm-Gg: ASbGncu7fOHlhbGlymCfN7oKHkExRV9RI+GfPxJeF9LRzfPdzI+1cTaY6zvtgeCHEzG wpxoq+ymSt5eIM85irog3Xgpm7pmXRUwbmXOkKPijjnzbdwxImSYBqDTNVf2DY6uiYbaiFQWZ6Z C9lnxgFgBOLDkpzwjfRlUIJmpnqLVgV3Jx+9EjAqEsPjunWwHCS5Pzo+sS6Qdpq0j8S03EnZPRR kpQMrYFN6ksnkBncWDCp6QNdJaGN9oIQS6aOmCrmYEOPb0Nyvk2qwEgb4Rn1MUc/BkMSxMVTKKQ 6JISAkls1o9nU54wBKlok6bco8dcuJc6mmkqLD+WlSH6o0qsEf87ZC10Z3GqKY/82uAF3KiueyA DqpDKviPU0qYteVjl9SQjVXzcFHQuQWMrtHz5QJw2kGE9SuWXrzXTM4YB+w== X-Received: by 2002:a05:600c:4ecd:b0:46e:35a0:3587 with SMTP id 5b1f17b1804b1-4777327cb76mr79179815e9.27.1762789773571; Mon, 10 Nov 2025 07:49:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IGpaV4arM40qypXSWawm0vTzq4KbiDd06rS9qXROrg/4OpsUc3yBjsCDg2PT7Cc8o4jl2l18Q== X-Received: by 2002:a05:600c:4ecd:b0:46e:35a0:3587 with SMTP id 5b1f17b1804b1-4777327cb76mr79179615e9.27.1762789773147; Mon, 10 Nov 2025 07:49:33 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 10/19] block/io: Take reqs_lock for tracked_requests Date: Mon, 10 Nov 2025 16:48:45 +0100 Message-ID: <20251110154854.151484-11-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 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=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: 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 @redhat.com) X-ZM-MESSAGEID: 1762789960105158500 Content-Type: text/plain; charset="utf-8" bdrv_co_get_self_request() does not take a lock around iterating through bs->tracked_requests. With multiqueue, it may thus iterate over a list that is in the process of being modified, producing an assertion failure: ../block/file-posix.c:3702: raw_do_pwrite_zeroes: Assertion `req' failed. [0] abort() at /lib64/libc.so.6 [1] __assert_fail_base.cold() at /lib64/libc.so.6 [2] raw_do_pwrite_zeroes() at ../block/file-posix.c:3702 [3] bdrv_co_do_pwrite_zeroes() at ../block/io.c:1910 [4] bdrv_aligned_pwritev() at ../block/io.c:2109 [5] bdrv_co_do_zero_pwritev() at ../block/io.c:2192 [6] bdrv_co_pwritev_part() at ../block/io.c:2292 [7] bdrv_co_pwritev() at ../block/io.c:2225 [8] handle_alloc_space() at ../block/qcow2.c:2573 [9] qcow2_co_pwritev_task() at ../block/qcow2.c:2625 Fix this by taking reqs_lock. Cc: qemu-stable@nongnu.org Signed-off-by: Hanna Czenczek --- block/io.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/io.c b/block/io.c index 928c02d1ad..c4a4301321 100644 --- a/block/io.c +++ b/block/io.c @@ -718,11 +718,14 @@ BdrvTrackedRequest *coroutine_fn bdrv_co_get_self_req= uest(BlockDriverState *bs) Coroutine *self =3D qemu_coroutine_self(); IO_CODE(); =20 + qemu_mutex_lock(&bs->reqs_lock); QLIST_FOREACH(req, &bs->tracked_requests, list) { if (req->co =3D=3D self) { + qemu_mutex_unlock(&bs->reqs_lock); return req; } } + qemu_mutex_unlock(&bs->reqs_lock); =20 return NULL; } --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762789959; cv=none; d=zohomail.com; s=zohoarc; b=BxE8kt2NdbDqEut1zRUg/18J/ueaZ2QN6BXvO2NEk0yl3DW1KjUzTN7Y1flibXiy63oFTecLdXKHoy6fGwibtJcXp6G/Mxg7uu8ryZB9CJBEujyA4VDGGEv/cJQv3DbPn5qAxQSfu81MVL2oS9Al90qR4WLAc1bMGZ/fLbNop/8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762789959; 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=tRB05p19+Vj4BSBV3UAT/udACtKojjPOv6AwE4PFCW4=; b=mY/yqwaAlwWpnIaQfejTH7BpvT/sVcjqiY+0TrWiY5mmow5nb+MIagL4bNyspjX9YcGpvfkzMWMfHTAWsZKcSulRe7HzxS9knM5PbqJBYxesR5OlNg1JvGb6FB0ydxtCs/SsKiv/YCTBc4pzuikmHlZdi/vLRju+e2TRdXjEc3c= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 176278995995978.90700679005124; Mon, 10 Nov 2025 07:52:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIU9e-0007eM-Nz; Mon, 10 Nov 2025 10:50:08 -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 1vIU9F-0006uy-Fr for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU9E-00010o-2Q for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:41 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-141-LhegiWUjOweeSQev0H0DfA-1; Mon, 10 Nov 2025 10:49:37 -0500 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-47496b3c1dcso24248765e9.3 for ; Mon, 10 Nov 2025 07:49:37 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b2dd927c9sm16143499f8f.27.2025.11.10.07.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tRB05p19+Vj4BSBV3UAT/udACtKojjPOv6AwE4PFCW4=; b=bsCLTLs9DGT7HNfGsXjPbtf027N6QKvVPED3SEfpmw4YzSWFzcelwWEh25pMgdgfubKPtw oG51rEGeCDWeMcGPsfDX4zXTWpRRNlSIbd3xPw4FTaQuYwWT9HG0/+Cuit7SSpAeRV2PPi lXJlCZcuFYRAAsGfCGy9vopdaFg3D0s= X-MC-Unique: LhegiWUjOweeSQev0H0DfA-1 X-Mimecast-MFC-AGG-ID: LhegiWUjOweeSQev0H0DfA_1762789777 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789776; x=1763394576; 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=tRB05p19+Vj4BSBV3UAT/udACtKojjPOv6AwE4PFCW4=; b=Ix7GPw57lOyh99W/6YTTWdrx8MpawfPSIRMF3Zbwfs40nuBxzfMVW9fMuVLbhKOaqc LVBxmkaZY44GWa6cdCMZvJwGBvsTPGVeZEOqW9+8wY4mHAYs1GocoOyt4Mi+R2Rq9A6q xjGB6LBwfstXmq3vBkIyFX7T0FARqFNww/cqlhxPu8a/iWrUwaHMjS4DEY2Ez1anRpwb gO3hHfDCbkzLWtc6xhZArWBnmLBxKBrOYDq3sywPLELyX/CGgYDgMw8r4H3X6g9ydWJR xzSw2IKr2g3bv1YR5F1LoVead9Gw24iYot3JDnQwQJ05KTmAfjIpIt7dbg7wQsed+6SP KYkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789776; x=1763394576; 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=tRB05p19+Vj4BSBV3UAT/udACtKojjPOv6AwE4PFCW4=; b=pQLri5IjYoX2YlNLxCennwevNlE8ssjp9eFgSgi4uOCGQp47RDTOZysC5hoCaMcAym YCgxf2d2O4h34diQXFMYIvbuBy6NMtYnypNUrkIs/JanBJqirYAmu/AJqz/QXJnkzwqd mYCSA8TVNHxuuaSiGzgHLshgM0kx/Nb2CoumR1vzm85CBsiU1M8x4pZL7pW0zCEOdKgN U+9ugfqX0kxKciR4h3xmgDTPuuSY0S0lCX8K6vGY9YntKTSkAle1J58Ah8SXTOw58to4 0PfRPFBD2A7gI8HQhCF6zYIXS76gs+TlP+9U5BzxsWVN1AUdiWrAimwD4JEgrQ3XeX9v VyVA== X-Gm-Message-State: AOJu0YzSBWGMe/fRfALukcXXeJXeQjiVdCxvJaTBw7Y5REmxELPo9wMP icaakyBEkY8JjHphMPqgx4nojO61qcx5Dolsxmgi5YzgUkNO+S3I0a5EFjGJoXMb267a5MeIIZw 4ER4dH5UtLOqP2pkq8VaRd7esqPIqClrfvCq+afgdtnmKJetEBQYH30F6 X-Gm-Gg: ASbGnctmPYslaYdPWsfxevEuWusIcvsQI3lbLrKYwY6K54RyuTOZhGiN+ojNuLxwjog or5ww9kfX4qUS6smiGMm9DG8RmQYcQm5pHfQtUI1NJB19iIx78ABxVIk3HTDUBoCpLO9Wbe5VD+ tCCZfKqdyZigz0VR9d1QI0KGCLg5wAgQCpuj0XVz5B584nkaftCBlucMXsn3NQ9/0+Xx8GH/Jh2 LQRuEC/2vjV/ygWR4xjIxQrQSkye7p+ezP66YMBV2cGw5lwzJGB0SyxCIitaeL1eP1BCNeqSNaf CyDestQYoACm5KJMePgnQCdb0lURp1dpzhc2nSXZAnYFl3F0Qk90nKo38mANgRCx4IhOUhC2oCB sdKniCZaHwcmrURULS0Sf5wQgM2/Vt1cxs6ZbjMZ4UGp2MsFfOJ7m62q8QA== X-Received: by 2002:a05:600c:470d:b0:475:da1a:5418 with SMTP id 5b1f17b1804b1-477732298edmr67659445e9.1.1762789776650; Mon, 10 Nov 2025 07:49:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IEcm1cSjRaA6Kdh4svJRAYcVlQlEnq+Z2vmfpzW1lrhyKy/AVgJrr5nrUEyUET2ju06rKyJlQ== X-Received: by 2002:a05:600c:470d:b0:475:da1a:5418 with SMTP id 5b1f17b1804b1-477732298edmr67659135e9.1.1762789776127; Mon, 10 Nov 2025 07:49:36 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 11/19] qcow2: Re-initialize lock in invalidate_cache Date: Mon, 10 Nov 2025 16:48:46 +0100 Message-ID: <20251110154854.151484-12-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 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=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1762789962092158500 Content-Type: text/plain; charset="utf-8" After clearing our state (memset()-ing it to 0), we should re-initialize objects that need it. Specifically, that applies to s->lock, which is originally initialized in qcow2_open(). Given qemu_co_mutex_init() is just a memset() to 0, this is functionally a no-op, but still seems like the right thing to do. Signed-off-by: Hanna Czenczek --- block/qcow2.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index 4aa9f9e068..d6e38926c8 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2873,6 +2873,8 @@ qcow2_co_invalidate_cache(BlockDriverState *bs, Error= **errp) data_file =3D s->data_file; memset(s, 0, sizeof(BDRVQcow2State)); s->data_file =3D data_file; + /* Re-initialize objects initialized in qcow2_open() */ + qemu_co_mutex_init(&s->lock); =20 options =3D qdict_clone_shallow(bs->options); =20 --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762789940; cv=none; d=zohomail.com; s=zohoarc; b=eFfMNS34BREjluMcX4AIrWHHGGGTE7FP4v0DbcIJcyVdziWQvLo2M/YbNrEIjz9n+QgBbFzhYP8czpndoP8ZrVG1C8JnGDXVcY0SplGGRfZVw1Lm2mYdE17xn2r9qS5YQITKvZQslCNRCCWQrCv+pd0X9S8jgJ16W4rOgPVilhw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762789940; 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=axvsIn5J5PmuBysJYDENSvNzEyMwBuBNOcFRZTNar0U=; b=XmU3dDZAzBg1fX5Fvk63Mp7lPZ/p71FzSB1hzawZn2SC4vQ0wV/y2L9LLdu3f1xIFTh6bUsw0DFpo9CsI0SIibDKCRT3l4jAK7EzPpkSA3Ck37s9DaQB5D5FkWbFlyRvgr0WFEs6tUzQygK2VN7VCted43d8bJZMXpxkcoEe6Wo= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762789940055917.4322138184606; Mon, 10 Nov 2025 07:52:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIU9p-0007wN-0g; Mon, 10 Nov 2025 10:50:18 -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 1vIU9K-00072Q-3N for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU9H-00011m-B6 for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:45 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-219-P6pAiWKIM1GOff_F7YgaFQ-1; Mon, 10 Nov 2025 10:49:41 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-47106720618so22001085e9.1 for ; Mon, 10 Nov 2025 07:49:40 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47763e7a6desm110558515e9.8.2025.11.10.07.49.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=axvsIn5J5PmuBysJYDENSvNzEyMwBuBNOcFRZTNar0U=; b=czHVgJeRtQlvbAlibzIa/c0JfLj8uVPt+H4jZUwChkyVsaDzC8s6iFPlmlZKGWVc1/e0MA TgxQZrNuIX4ek/Gx4SJuRihwyCyefOlvm/BaU+2H9UnI+EffSUJbmX9UJ2hGc947w/1UYV 2z5caYh897KWT9JDidZzna/Ke5wC+S4= X-MC-Unique: P6pAiWKIM1GOff_F7YgaFQ-1 X-Mimecast-MFC-AGG-ID: P6pAiWKIM1GOff_F7YgaFQ_1762789780 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789780; x=1763394580; 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=axvsIn5J5PmuBysJYDENSvNzEyMwBuBNOcFRZTNar0U=; b=bRoQdFAFBE7KrJYAsoagfccTZrY+ZrmJkfRKzyIvIyRa1olsNggu34kYDz9Usf1HXR Mz3deInBGZNc8Tiu0RgyFvcubJ8H3dRjmSrLDRC3kaJF1TYaGZ951X8fmszMi3JNuqvv CK0xo9dO2t5DHBucAPheZBSAi9unLDM6FMcZFi6kR98qi/iMS0PWtEgMfiQUc3iNfkjC V1kP9X5Y9soLi9sITWzgvv8oJwnWaZtuoOkIHEqwXoCpim+48AxejPDXF3bwZ7S9JLKX Gqeq+ZQZd3h6OLi6Bxoil5fLpzJt2hbwXbmKLuWxcJbhRb6IZ24jPiIuaWVoFgZSE8YS Yn+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789780; x=1763394580; 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=axvsIn5J5PmuBysJYDENSvNzEyMwBuBNOcFRZTNar0U=; b=HKQ6ev6ttddMAKDn3NECNpL4Ew4ZSovEZISe9Qac9loQevRTW1vFDWRITRY64CE8Qr np1E22mb+NT+hElWi4UhOHfTE5UbgOiX39racRr6NID9awBn6ofxGiJKtOGUmNJhtYcM 1Z+qkx8QfmzttK4E1Z4z8696PhV3DDHVv8fMaC4DefC8YWIdRh+UHhH3YMhMKXYDiXI4 Z8muGZGDhn6DD6JEk9jTTMvZoyesZPd+e1zrMF0mWvwT+ITPgkP9sUsDNoZNMRTIqnwQ RsFhT/TQfYgo/OSNXL0vW79cbYW8zeR6lCDyHS8vOX6mNOrZUO7h2L+9DQXjcYRlCb5+ gfxg== X-Gm-Message-State: AOJu0Yx6Sfil8fXJcSYl7QSuwiWB7xZgS+4J8MPWksmhnTk31xFDHaa0 Nmjtcly3zTntQT5UbVdNI1Og3xHYt8NzhWvmfqrJVvYeUVzCLl7XFOknL/dgVqGgWmv5tZ/aJOM 9Fc6WMEnRQYjiaUYXA5wZ6xJ4NHsSDcfPx4S0592N5eZwRJcMv1CqjhRL X-Gm-Gg: ASbGnctZXH5/lMxk2vp7FvELJe+Z+ksqvY89/HSzGmJsiIwsZYk53BRw32yssjEIEH3 thmkdd1x8CQBwhhYM6WM4U6ujT9+3QiW3E2oF8oP37gWfVIhVD+GfohDwCzidsdxAtSfPHA7Gop YlaFN0+zZCmLjGk743SNxfrumeGj0xQ+luTc6ErAASmIjrQPTY8tNCvONyc3PaBHiGQkWidhB// f2+U/lYQvXe/cBnrz/1nbY94soDKs3LY2q38jxkPqPDZbFbP97CVuObURLudCIxZZhxaVrg/L/R VHhJkOW2uuWdbRscBNFSlCtCv8BC1JECMZf/HKl98jF7eDPUQh6L2+EJlKSZzXAYHky0dTj6Y5J JpzX81XW75b60MddnKf8E1Ai3PR6H0wHrKhbd25J2DNbmye8xuGUWrHX4fQ== X-Received: by 2002:a05:600c:4f94:b0:475:df09:c253 with SMTP id 5b1f17b1804b1-47773288f90mr77531635e9.38.1762789779623; Mon, 10 Nov 2025 07:49:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEFNahU8Mvbp+x6DKJNBFfhMNOHPkt0zXulSom/UII9P+NJcDSlTZli0bz/maN/jVD9kYOsaw== X-Received: by 2002:a05:600c:4f94:b0:475:df09:c253 with SMTP id 5b1f17b1804b1-47773288f90mr77531315e9.38.1762789779190; Mon, 10 Nov 2025 07:49:39 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 12/19] qcow2: Fix cache_clean_timer Date: Mon, 10 Nov 2025 16:48:47 +0100 Message-ID: <20251110154854.151484-13-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1762789941907158500 The cache-cleaner runs as a timer CB in the BDS AioContext. With multiqueue, it can run concurrently to I/O requests, and because it does not take any lock, this can break concurrent cache accesses, corrupting the image. While the chances of this happening are low, it can be reproduced e.g. by modifying the code to schedule the timer CB every 5 ms (instead of at most once per second) and modifying the last (inner) while loop of qcow2_cache_clean_unused() like so: while (i < c->size && can_clean_entry(c, i)) { for (int j =3D 0; j < 1000 && can_clean_entry(c, i); j++) { usleep(100); } c->entries[i].offset =3D 0; c->entries[i].lru_counter =3D 0; i++; to_clean++; } i.e. making it wait on purpose for the point in time where the cache is in use by something else. The solution chosen for this in this patch is not the best solution, I hope, but I admittedly can=E2=80=99t come up with anything strictly better. We can protect from concurrent cache accesses either by taking the existing s->lock, or we introduce a new (non-coroutine) mutex specifically for cache accesses. I would prefer to avoid the latter so as not to introduce additional (very slight) overhead. Using s->lock, which is a coroutine mutex, however means that we need to take it in a coroutine, so the timer must run in a coroutine. We can transform it from the current timer CB style into a coroutine that sleeps for the set interval. As a result, however, we can no longer just deschedule the timer to instantly guarantee it won=E2=80=99t run anymo= re, but have to await the coroutine=E2=80=99s exit. (Note even before this patch there were places that may not have been so guaranteed after all: Anything calling cache_clean_timer_del() from the QEMU main AioContext could have been running concurrently to an existing timer CB invocation.) Polling to await the timer to actually settle seems very complicated for something that=E2=80=99s rather a minor problem, but I can=E2=80=99t come u= p with any better solution that doesn=E2=80=99t again just overlook potential problems. (Not Cc-ing qemu-stable, as the issue is quite unlikely to be hit, and I=E2=80=99m not too fond of this solution.) Signed-off-by: Hanna Czenczek --- block/qcow2.h | 5 +- block/qcow2.c | 143 ++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 118 insertions(+), 30 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index a9e3481c6e..3e38bccd87 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -345,8 +345,11 @@ typedef struct BDRVQcow2State { =20 Qcow2Cache *l2_table_cache; Qcow2Cache *refcount_block_cache; - QEMUTimer *cache_clean_timer; + /* Non-NULL while the timer is running */ + Coroutine *cache_clean_timer_co; unsigned cache_clean_interval; + QemuCoSleep cache_clean_timer_wake; + CoQueue cache_clean_timer_exit; =20 QLIST_HEAD(, QCowL2Meta) cluster_allocs; =20 diff --git a/block/qcow2.c b/block/qcow2.c index d6e38926c8..ecff3bed0e 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -835,41 +835,113 @@ static const char *overlap_bool_option_names[QCOW2_O= L_MAX_BITNR] =3D { [QCOW2_OL_BITMAP_DIRECTORY_BITNR] =3D QCOW2_OPT_OVERLAP_BITMAP_DIRECTO= RY, }; =20 -static void cache_clean_timer_cb(void *opaque) +static void coroutine_fn cache_clean_timer(void *opaque) { - BlockDriverState *bs =3D opaque; - BDRVQcow2State *s =3D bs->opaque; - qcow2_cache_clean_unused(s->l2_table_cache); - qcow2_cache_clean_unused(s->refcount_block_cache); - timer_mod(s->cache_clean_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + - (int64_t) s->cache_clean_interval * 1000); + BDRVQcow2State *s =3D opaque; + uint64_t wait_ns; + + WITH_QEMU_LOCK_GUARD(&s->lock) { + wait_ns =3D s->cache_clean_interval * NANOSECONDS_PER_SECOND; + } + + while (wait_ns > 0) { + qemu_co_sleep_ns_wakeable(&s->cache_clean_timer_wake, + QEMU_CLOCK_VIRTUAL, wait_ns); + + WITH_QEMU_LOCK_GUARD(&s->lock) { + if (s->cache_clean_interval > 0) { + qcow2_cache_clean_unused(s->l2_table_cache); + qcow2_cache_clean_unused(s->refcount_block_cache); + } + + wait_ns =3D s->cache_clean_interval * NANOSECONDS_PER_SECOND; + } + } + + WITH_QEMU_LOCK_GUARD(&s->lock) { + s->cache_clean_timer_co =3D NULL; + qemu_co_queue_restart_all(&s->cache_clean_timer_exit); + } } =20 static void cache_clean_timer_init(BlockDriverState *bs, AioContext *conte= xt) { BDRVQcow2State *s =3D bs->opaque; if (s->cache_clean_interval > 0) { - s->cache_clean_timer =3D - aio_timer_new_with_attrs(context, QEMU_CLOCK_VIRTUAL, - SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL, - cache_clean_timer_cb, bs); - timer_mod(s->cache_clean_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTU= AL) + - (int64_t) s->cache_clean_interval * 1000); + assert(!s->cache_clean_timer_co); + s->cache_clean_timer_co =3D qemu_coroutine_create(cache_clean_time= r, s); + aio_co_enter(context, s->cache_clean_timer_co); + } +} + +/** + * Delete the cache clean timer and await any yet running instance. + * Called holding s->lock. + */ +static void coroutine_fn +cache_clean_timer_co_locked_del_and_wait(BlockDriverState *bs) +{ + BDRVQcow2State *s =3D bs->opaque; + + if (s->cache_clean_timer_co) { + s->cache_clean_interval =3D 0; + qemu_co_sleep_wake(&s->cache_clean_timer_wake); + qemu_co_queue_wait(&s->cache_clean_timer_exit, &s->lock); } } =20 -static void cache_clean_timer_del(BlockDriverState *bs) +/** + * Same as cache_clean_timer_co_locked_del_and_wait(), but takes s->lock. + */ +static void coroutine_fn +cache_clean_timer_co_del_and_wait(BlockDriverState *bs) { BDRVQcow2State *s =3D bs->opaque; - if (s->cache_clean_timer) { - timer_free(s->cache_clean_timer); - s->cache_clean_timer =3D NULL; + + WITH_QEMU_LOCK_GUARD(&s->lock) { + cache_clean_timer_co_locked_del_and_wait(bs); + } +} + +struct CacheCleanTimerDelAndWaitCoParams { + BlockDriverState *bs; + bool done; +}; + +static void coroutine_fn cache_clean_timer_del_and_wait_co_entry(void *opa= que) +{ + struct CacheCleanTimerDelAndWaitCoParams *p =3D opaque; + + cache_clean_timer_co_del_and_wait(p->bs); + p->done =3D true; + aio_wait_kick(); +} + +/** + * Delete the cache clean timer and await any yet running instance. + * Must be called from the main or BDS AioContext without s->lock held. + */ +static void coroutine_mixed_fn +cache_clean_timer_del_and_wait(BlockDriverState *bs) +{ + IO_OR_GS_CODE(); + + if (qemu_in_coroutine()) { + cache_clean_timer_co_del_and_wait(bs); + } else { + struct CacheCleanTimerDelAndWaitCoParams p =3D { .bs =3D bs }; + Coroutine *co; + + co =3D qemu_coroutine_create(cache_clean_timer_del_and_wait_co_ent= ry, &p); + qemu_coroutine_enter(co); + + BDRV_POLL_WHILE(bs, !p.done); } } =20 static void qcow2_detach_aio_context(BlockDriverState *bs) { - cache_clean_timer_del(bs); + cache_clean_timer_del_and_wait(bs); } =20 static void qcow2_attach_aio_context(BlockDriverState *bs, @@ -1214,12 +1286,24 @@ fail: return ret; } =20 +/* s_locked specifies whether s->lock is held or not */ static void qcow2_update_options_commit(BlockDriverState *bs, - Qcow2ReopenState *r) + Qcow2ReopenState *r, + bool s_locked) { BDRVQcow2State *s =3D bs->opaque; int i; =20 + /* + * We need to stop the cache-clean-timer before destroying the metadata + * table caches + */ + if (s_locked) { + cache_clean_timer_co_locked_del_and_wait(bs); + } else { + cache_clean_timer_del_and_wait(bs); + } + if (s->l2_table_cache) { qcow2_cache_destroy(s->l2_table_cache); } @@ -1228,6 +1312,10 @@ static void qcow2_update_options_commit(BlockDriverS= tate *bs, } s->l2_table_cache =3D r->l2_table_cache; s->refcount_block_cache =3D r->refcount_block_cache; + + s->cache_clean_interval =3D r->cache_clean_interval; + cache_clean_timer_init(bs, bdrv_get_aio_context(bs)); + s->l2_slice_size =3D r->l2_slice_size; =20 s->overlap_check =3D r->overlap_check; @@ -1239,12 +1327,6 @@ static void qcow2_update_options_commit(BlockDriverS= tate *bs, =20 s->discard_no_unref =3D r->discard_no_unref; =20 - if (s->cache_clean_interval !=3D r->cache_clean_interval) { - cache_clean_timer_del(bs); - s->cache_clean_interval =3D r->cache_clean_interval; - cache_clean_timer_init(bs, bdrv_get_aio_context(bs)); - } - qapi_free_QCryptoBlockOpenOptions(s->crypto_opts); s->crypto_opts =3D r->crypto_opts; } @@ -1261,6 +1343,7 @@ static void qcow2_update_options_abort(BlockDriverSta= te *bs, qapi_free_QCryptoBlockOpenOptions(r->crypto_opts); } =20 +/* Called with s->lock held */ static int coroutine_fn GRAPH_RDLOCK qcow2_update_options(BlockDriverState *bs, QDict *options, int flags, Error **errp) @@ -1270,7 +1353,7 @@ qcow2_update_options(BlockDriverState *bs, QDict *opt= ions, int flags, =20 ret =3D qcow2_update_options_prepare(bs, &r, options, flags, errp); if (ret >=3D 0) { - qcow2_update_options_commit(bs, &r); + qcow2_update_options_commit(bs, &r, true); } else { qcow2_update_options_abort(bs, &r); } @@ -1908,7 +1991,7 @@ qcow2_do_open(BlockDriverState *bs, QDict *options, i= nt flags, qemu_vfree(s->l1_table); /* else pre-write overlap checks in cache_destroy may crash */ s->l1_table =3D NULL; - cache_clean_timer_del(bs); + cache_clean_timer_co_locked_del_and_wait(bs); if (s->l2_table_cache) { qcow2_cache_destroy(s->l2_table_cache); } @@ -1963,6 +2046,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *op= tions, int flags, =20 /* Initialise locks */ qemu_co_mutex_init(&s->lock); + qemu_co_queue_init(&s->cache_clean_timer_exit); =20 assert(!qemu_in_coroutine()); assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context()); @@ -2048,7 +2132,7 @@ static void qcow2_reopen_commit(BDRVReopenState *stat= e) =20 GRAPH_RDLOCK_GUARD_MAINLOOP(); =20 - qcow2_update_options_commit(state->bs, state->opaque); + qcow2_update_options_commit(state->bs, state->opaque, false); if (!s->data_file) { /* * If we don't have an external data file, s->data_file was cleare= d by @@ -2805,7 +2889,7 @@ qcow2_do_close(BlockDriverState *bs, bool close_data_= file) qcow2_inactivate(bs); } =20 - cache_clean_timer_del(bs); + cache_clean_timer_del_and_wait(bs); qcow2_cache_destroy(s->l2_table_cache); qcow2_cache_destroy(s->refcount_block_cache); =20 @@ -2875,6 +2959,7 @@ qcow2_co_invalidate_cache(BlockDriverState *bs, Error= **errp) s->data_file =3D data_file; /* Re-initialize objects initialized in qcow2_open() */ qemu_co_mutex_init(&s->lock); + qemu_co_queue_init(&s->cache_clean_timer_exit); =20 options =3D qdict_clone_shallow(bs->options); =20 --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762789913; cv=none; d=zohomail.com; s=zohoarc; b=SqTqiwcJp4/mmVltNLeeFIXoO20pNJfiznbmPtus4SpIuP1hq4LTxIJvanU/H0elXf2BzpxDgb0SOWRScNAAjKnGuNygQ7WoOw9Cpos3eSj+Rrl/o7Ts3MQMA8+c6glKxKanoL57X5cPrXD2vPCmvek0NF2HayR9+k2kRsPLfxM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762789913; 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=OqSM+dsvZXQykYJy5mQtdb8MApZH6DwF1cy9voui00c=; b=i9pGK1guTxomFlwszievWsxorXfC0zq/HX884VbjKO/fXW1yTYz38ZnxaxIc0ad3xTC96A5SevPmUl8lRl7/IE2IT+RtC3ewBDv++f0bJD3bmLaCwF9Fx4Kz5gxj8r5v3Os4eoPIUXV5wMDPGFbbGfncqb0shGRPzedalTNxwjI= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762789913053120.69240421415668; Mon, 10 Nov 2025 07:51:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIU9X-0007WO-6E; Mon, 10 Nov 2025 10:50:01 -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 1vIU9N-00079O-F6 for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU9M-00012n-18 for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:49 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-149-8TAaWoohNp-MwO56TyED5g-1; Mon, 10 Nov 2025 10:49:44 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4776079ada3so27928885e9.1 for ; Mon, 10 Nov 2025 07:49:43 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4777bbb8cf3sm29825355e9.15.2025.11.10.07.49.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789787; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OqSM+dsvZXQykYJy5mQtdb8MApZH6DwF1cy9voui00c=; b=O3rZydZZim3mM/gtnh3/PRkUnSk2b78Zvn+bm3SLT3lWgX9d54/uSgGR6y2qN7uxbqg/tW f+2iRBbl8vz7F4AMixz5rpdlX+ro9o3gqebGbN+ANK/KLuqAFEiEbm7aAGJIB94nnw5Uej s773jzjjgWOYNwW7a62mSg649gfdecY= X-MC-Unique: 8TAaWoohNp-MwO56TyED5g-1 X-Mimecast-MFC-AGG-ID: 8TAaWoohNp-MwO56TyED5g_1762789783 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789783; x=1763394583; 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=OqSM+dsvZXQykYJy5mQtdb8MApZH6DwF1cy9voui00c=; b=FGveysU9jLhHQDkmZeH7whiNIhq+k3VsB+T8AY4WDJ7EcP9f1Tosal/cIcOhfrGbRu P+VRWbcFtX9SkM0D0jpzcm+kmNCU9xa5a+pN3CzexrZiexw22ynEaMfsQw7u/WD4Qqm7 zYePPNznyKe9kd1ufVhHhVKkgTNOrpY5CQ0r+OcRB1JARdljK0IUeusXdQgW3gB4rHRA z/xavleZjdgEnCcFi0A3eDRFHpqa2f6FVCdq6YAgXrFui/SPdbV6qk8fyBvNiwq64Izm PbxXAQcFolydwY/GIgLinRWV179VvMHa03hjDbMmwTjsfl+bJaPD2qpYRzWysUb7Atv7 iUnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789783; x=1763394583; 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=OqSM+dsvZXQykYJy5mQtdb8MApZH6DwF1cy9voui00c=; b=Zb1N6akExNxlpsUCiS+d79TxLT/zqJunajG/9oSB6xZx9z235tUJs4wjyfQORlZAqE R6aytA+5JfBUc5Iie3P+qfqqKiWEPJBZrq9kIpFVYqDhTLd12DT8/fEHY6FfrNZSn/RY IOe9ZAxjwPRmm8MUh5XHGnuX99/v+MclatT9oiu4Zkl5c+06BuchekUMlFny93vx9hNH aPVfFWCKECIuCtMxdEGXRs8KJoy0rvn1nn3wg3Po4udgjochddB1BOqVcGFPB+BiJOsa QU7vr8CyXkEfQQuPZduorPrktNhSRXKy3uW1b4uJnYEL81TSf75onXaKs/mRBZ+B9MvT MWyA== X-Gm-Message-State: AOJu0Yy8I3BDGTuFASmkzjGdjwPOoNol2wZfrG+pKyANClEavwkXAuXl OWSfU1lwPs8VA1hS4mRYqmFHOMHpl2ko6Cux2nuBH2+ElsS1TL8JHnb1XwzMITIX1VshVNCxS0g nxFStrklkOWcS1/dRuseayvjZv/ztIaEaC9826mdN5ZJGvmdaiE91d+BP X-Gm-Gg: ASbGncsJAjEg87hpJg6sOW0tlGh7BNaRMEroUDDyz71Wdlpfoyk/pcELJNC2qw3+cDO 29bNVV38BpAkOP67Ffg7sYLkHIuI7BA1i6YowUYTjwYwDnzYjqJ1ZajHMJupJhWgsEkhqcMgeTJ 4XQbtbItbFVopcHY8XGdYL09O9XKPj5R1qL6FLvolbK130mhJgReqoceGNvReoI8SKRakLn053e yt+0PKnjUf079EG9jlu17X9EmXbugJKYKEokaD0+2O9ipSK5TMj/3EUwkfkIsM1iYyKkcFyx/1d WukiXTZac5aLqBo56WC/zFSA3rMdoOAPaXLUKULVeymV2E4qwM7AaJianizYrE7j/7ocMdLueMX U+JqIH4gCX9ozT+YwPW9FU4N1c0B7TpdTa5BdDB9MAPtRZkgy5gNVPN6blA== X-Received: by 2002:a05:600c:190d:b0:477:79c7:8994 with SMTP id 5b1f17b1804b1-47779c78b39mr53508915e9.30.1762789782915; Mon, 10 Nov 2025 07:49:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IGt1YxYwg76iKXDrdcv89UqTKluLoQacPtKwgvQ545WvmCgRkSi7Q3yxgEFjIoxtvkSWRSKQw== X-Received: by 2002:a05:600c:190d:b0:477:79c7:8994 with SMTP id 5b1f17b1804b1-47779c78b39mr53508685e9.30.1762789782414; Mon, 10 Nov 2025 07:49:42 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 13/19] qcow2: Schedule cache-clean-timer in realtime Date: Mon, 10 Nov 2025 16:48:48 +0100 Message-ID: <20251110154854.151484-14-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 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=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: 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 @redhat.com) X-ZM-MESSAGEID: 1762789913409158500 Content-Type: text/plain; charset="utf-8" There is no reason why the cache cleaning timer should run in virtual time, run it in realtime instead. Suggested-by: Kevin Wolf Signed-off-by: Hanna Czenczek --- block/qcow2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index ecff3bed0e..d13cb9b42a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -846,7 +846,7 @@ static void coroutine_fn cache_clean_timer(void *opaque) =20 while (wait_ns > 0) { qemu_co_sleep_ns_wakeable(&s->cache_clean_timer_wake, - QEMU_CLOCK_VIRTUAL, wait_ns); + QEMU_CLOCK_REALTIME, wait_ns); =20 WITH_QEMU_LOCK_GUARD(&s->lock) { if (s->cache_clean_interval > 0) { --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762790031; cv=none; d=zohomail.com; s=zohoarc; b=Wi+frI7NFQq7XS1t8hJiEHl5xWQ7TDjrpa3UPtLpjX9lZwcVLsUZ3vRZZrdyLfcUGmX54NOcLnCfCHkaatu/ejmhTbF/AsNveKtlijz1544JFlhQpTnltZYXHzU+XqgN8ugzsXhsqMPC/X21FDeJfQO91G8YGfLw1NofsAHd8qQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762790031; 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=XiQZc0S9otfidhonOxKcoAmt4++DcUiIFzKq2jBQlWQ=; b=bARKfrRTQnEWDnPGvccsIaF0/h96ejOL9LyWU4+IArOXIwByvPqjYPTa0yFpK65MkZH+rVBL6i1xdGS78wGxMFiDhy52EI7dBgknug+cRrSLIU7omV14KOOt/Jkq7GfQ2up5HhxuLOeSBuI8eMikINwFEBmdRZGt5T70EqUpaKA= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762790031903172.53975240840293; Mon, 10 Nov 2025 07:53:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIU9r-00083D-Ru; Mon, 10 Nov 2025 10:50:20 -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 1vIU9Q-0007UU-Ur for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU9P-00013k-3W for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:52 -0500 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-576-Kjf5PYBsN3SckTZPtoZ9yQ-1; Mon, 10 Nov 2025 10:49:47 -0500 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-429c5c8ae3bso2582243f8f.0 for ; Mon, 10 Nov 2025 07:49:47 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b303386f1sm14433781f8f.3.2025.11.10.07.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789790; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XiQZc0S9otfidhonOxKcoAmt4++DcUiIFzKq2jBQlWQ=; b=iU77v+h+1hUantpkLxgMhGD44u/pt3W+x4EM1pYNsNviYY3hz39lB/rQTi2UbOX1WdyRak exwj+jeilXjGk/49zZecwJsGmLZDKSgwTdSe3CHtsp2zvRGLHNZxHeHvp7yG4XvehzQDIW RVlfRSVrhtfMr0GMtKkb+xuucbXvVeI= X-MC-Unique: Kjf5PYBsN3SckTZPtoZ9yQ-1 X-Mimecast-MFC-AGG-ID: Kjf5PYBsN3SckTZPtoZ9yQ_1762789786 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789786; x=1763394586; 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=XiQZc0S9otfidhonOxKcoAmt4++DcUiIFzKq2jBQlWQ=; b=sKjDxjSBo3zz4tKNStwI1kzcv9S7UKvAaCZu09aAcOMu6fP0CZh/YQLDP+LViqMNFr EBTxWlCWZYP82b8XZO6g9ET1b2Xg81CZiAjLjAjjQsVqqJmhsj18cG0LolK82RJjxjr/ 0vFi8WOnN+HPh+/kokUPXg6ugR1MjMBvP9qK2r/JPgciz7TrTysWoA4YTxSBYVU+TVtY LjHlA4htV4rKCo1WZXPhoagxXoIbqFTzoJdGlmkleOGUwaUlumhOkSyEuZFcnhr2SRqv HoLYbJRa02dc3RkL2rW1bWhhEEoe+MUfv/otzqx5SsONn3j/LtrMnjV7lbihHBoNObzF pNlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789786; x=1763394586; 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=XiQZc0S9otfidhonOxKcoAmt4++DcUiIFzKq2jBQlWQ=; b=wEJ/WHo698+tYl8Nq3rpan5p1dKjoZ9GC/srVL79t0t8QQmlWl5k19xdynr3gJ2+ru TwKKj4m690oInBqEKaZRbzX7i2cVDz1fjEzD1wTx1289d8dVc+XigkrvkPL8tFeedQrR 6LlVuiKoYsztR4JS73OJMswdghu/+ew5GBzUK2vVzdKaD/zy5oe7O8/gX7J1Ra27f8g7 M/ybPa65KFkdOwhrnHoXGarw2goY+ALbFgo1r5VqjIUo8PRWwVooVKtqQdZtZc8Hydq3 D7WwNa3J2YF45/1gazZv8bnZpfwv+Id+2Ck+Xelho6xxU2uoEHmAbEJP43zX9eKOjb4Q zkAw== X-Gm-Message-State: AOJu0Yx09VskjYZhqGT0RGc9RUnfvBwJAZgHw1IhVSQ5Zxg4NaRq+6Ys kobkmPLLWCGT7hCEJm9FOmZMJSZoTwOeOPee6EyT04zgWlGfS5GioJrHXhPHmdED1RcfPtOOvWW oAQ5ucDyDtvpalQkh8KIY+vQSC3jJalt9TqjPVk59gCwfQltFBn/JiBPP X-Gm-Gg: ASbGncup7zgNurM24vvFYGwNobkOnvy7WRM2XDJhrWygAe28qkSd81C9dHs79ZGLnRs pldovicNRe0r1oHw1GazSSjYKNFS6crP2jAA+v3+cno6LE9x4/WufuPuS6/xfeX3B9Y8I3J2Oei DVoTG3udbVusLAQ5wpnXPUW5CMXrI6OyvDL983xnhwcTm38rT1It5ZkBKi43pH68xCMlZewlTEc OkUUepQctM3QC8f66At7elRteEcqFA5lDUCCF0TlFOjQXjYgBLLovP3lRxyM6WlNKz85S2JXReU 9CHDjykET5Wo0glH1E3AR4OsLPSSp5+4Hngw4KqWbd+OceAx6bL5gEvNI+LQri5o/JV+eigqfLu rMjvZH/+ri35RRSuSPfEKiT2BOT22HQLso3stXbazPEJcXDuwKsIJHdJRWQ== X-Received: by 2002:a05:6000:2d12:b0:42b:2c61:86f1 with SMTP id ffacd0b85a97d-42b2dc7f5c0mr5011767f8f.35.1762789786024; Mon, 10 Nov 2025 07:49:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFS5PIegtasFArTob8lo4VL4RLFJ3/lIFDozxlnGZSs+0oRoXTg6ZcFPcc6Tufm6dULhULW8g== X-Received: by 2002:a05:6000:2d12:b0:42b:2c61:86f1 with SMTP id ffacd0b85a97d-42b2dc7f5c0mr5011745f8f.35.1762789785617; Mon, 10 Nov 2025 07:49:45 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 14/19] ssh: Run restart_coroutine in current AioContext Date: Mon, 10 Nov 2025 16:48:49 +0100 Message-ID: <20251110154854.151484-15-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 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=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: 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 @redhat.com) X-ZM-MESSAGEID: 1762790033171158500 Content-Type: text/plain; charset="utf-8" restart_coroutine() is attached as an FD handler just to wake the current coroutine after yielding. It makes most sense to attach it to the current (request) AioContext instead of the BDS main context. This way, the coroutine can be entered directly from the BH instead of having yet another indirection through AioContext.co_schedule_bh. Signed-off-by: Hanna Czenczek --- block/ssh.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/block/ssh.c b/block/ssh.c index 70fe7cf86e..bdec94e9e9 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -1010,19 +1010,18 @@ static int ssh_has_zero_init(BlockDriverState *bs) } =20 typedef struct BDRVSSHRestart { - BlockDriverState *bs; + BDRVSSHState *s; Coroutine *co; } BDRVSSHRestart; =20 static void restart_coroutine(void *opaque) { BDRVSSHRestart *restart =3D opaque; - BlockDriverState *bs =3D restart->bs; - BDRVSSHState *s =3D bs->opaque; - AioContext *ctx =3D bdrv_get_aio_context(bs); + BDRVSSHState *s =3D restart->s; =20 trace_ssh_restart_coroutine(restart->co); - aio_set_fd_handler(ctx, s->sock, NULL, NULL, NULL, NULL, NULL); + aio_set_fd_handler(qemu_get_current_aio_context(), s->sock, + NULL, NULL, NULL, NULL, NULL); =20 aio_co_wake(restart->co); } @@ -1031,12 +1030,13 @@ static void restart_coroutine(void *opaque) * handlers are set up so that we'll be rescheduled when there is an * interesting event on the socket. */ -static coroutine_fn void co_yield(BDRVSSHState *s, BlockDriverState *bs) +static coroutine_fn void co_yield(BDRVSSHState *s) { int r; IOHandler *rd_handler =3D NULL, *wr_handler =3D NULL; + AioContext *ctx =3D qemu_get_current_aio_context(); BDRVSSHRestart restart =3D { - .bs =3D bs, + .s =3D s, .co =3D qemu_coroutine_self() }; =20 @@ -1051,7 +1051,7 @@ static coroutine_fn void co_yield(BDRVSSHState *s, Bl= ockDriverState *bs) =20 trace_ssh_co_yield(s->sock, rd_handler, wr_handler); =20 - aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock, + aio_set_fd_handler(ctx, s->sock, rd_handler, wr_handler, NULL, NULL, &restart); qemu_coroutine_yield(); trace_ssh_co_yield_back(s->sock); @@ -1093,7 +1093,7 @@ static coroutine_fn int ssh_read(BDRVSSHState *s, Blo= ckDriverState *bs, trace_ssh_read_return(r, sftp_get_error(s->sftp)); =20 if (r =3D=3D SSH_AGAIN) { - co_yield(s, bs); + co_yield(s); goto again; } if (r =3D=3D SSH_EOF || (r =3D=3D 0 && sftp_get_error(s->sftp) =3D= =3D SSH_FX_EOF)) { @@ -1168,7 +1168,7 @@ static coroutine_fn int ssh_write(BDRVSSHState *s, Bl= ockDriverState *bs, trace_ssh_write_return(r, sftp_get_error(s->sftp)); =20 if (r =3D=3D SSH_AGAIN) { - co_yield(s, bs); + co_yield(s); goto again; } if (r < 0) { @@ -1233,7 +1233,7 @@ static coroutine_fn int ssh_flush(BDRVSSHState *s, Bl= ockDriverState *bs) again: r =3D sftp_fsync(s->sftp_handle); if (r =3D=3D SSH_AGAIN) { - co_yield(s, bs); + co_yield(s); goto again; } if (r < 0) { --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762789892; cv=none; d=zohomail.com; s=zohoarc; b=di98Bgv+kjDGx0Q2yuHxwh+q9qPsCGCV+isidtpdci+/j5OC1jeG5XjxSS0Ozhv5EUbwWtVuQkMvPDUFWdp9Nfa5CTvVZW9UIr0aPa66tSPYAVqtlIBCTsQ96nlhr/K1rCz/j1tGxGzHkwhf12ruzRwC4A4DD4THr2HZX4jcc0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762789892; 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=J2pGuJH4CZyEZq/sM/g3air/DGds7dY2gM0JmiMpLcY=; b=cnCKCuP5fmgAh0ZEcGXh96k0H6fmZmmxHFHLcr2yWWs/93iywV9IlralNxaNlK1NZg6ur5/4bvHVPjSAnMWb/q0vGQ15H74dZJ1+8iWxuPJcXgp/yyhmnXZdlYT0HDDydY6ygbaLWO6ho8Cz0iwUcLPXS7YWhwMAi5frbb9NyPQ= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762789892260348.79528401671735; Mon, 10 Nov 2025 07:51:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIU9w-0008U5-GQ; Mon, 10 Nov 2025 10:50:24 -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 1vIU9R-0007Y4-CF for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU9P-00013s-QR for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:53 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-102-dowbb93hNDqQuDtYqNzvKQ-1; Mon, 10 Nov 2025 10:49:49 -0500 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4777885a071so8636635e9.3 for ; Mon, 10 Nov 2025 07:49:49 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4777d9447eesm54863295e9.16.2025.11.10.07.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789791; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J2pGuJH4CZyEZq/sM/g3air/DGds7dY2gM0JmiMpLcY=; b=EhPnQI9U8NZefKEflshANL0mG8JbCYjYXplUfiWL4hlbE6qC1EqAiEhyPi8Dg5NuwHLw96 EzDMtxCHZK4eSgL4rnH+ZdR3l79ioFftQ2mQccBdAY8HHJx7FaE34C6eYc19jiFXxvd2cj lNwY9/s8WlF5b8gxMVVOPMkQkOL+rEg= X-MC-Unique: dowbb93hNDqQuDtYqNzvKQ-1 X-Mimecast-MFC-AGG-ID: dowbb93hNDqQuDtYqNzvKQ_1762789788 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789788; x=1763394588; 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=J2pGuJH4CZyEZq/sM/g3air/DGds7dY2gM0JmiMpLcY=; b=nuHDg7mPu+6Ujhzsr1WipqJWSjsgiOb4GSHb6LcgYCd5fHG0pasfdNSoOGmpPuBDT7 +ReGVtfdn81bDEFBvPCe5OSKrTkF727B3pIa3PJSMODxJ6JkVMdTDffxA+hqFCjDc/d3 KWingD3MF9JlrZ4Dbl15VcqU8ggg2TlKwIf5ov/PWleKNucDZF6jHv/2Aa5fJ8MA2cRg 6gsspeAzmgg5ASGUC0ze9RbEybhhKA22aY81k/IcdLDY2vYdu8UZ9tLlmmkC/63tEMJI 98RiM+6FmC+4PibNmf3YFBX5Qlgu8pvomDfyGuA6PsM0Zeu6Fz1E7JA95vM99471HxMT n4Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789788; x=1763394588; 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=J2pGuJH4CZyEZq/sM/g3air/DGds7dY2gM0JmiMpLcY=; b=WRiCzdf5HspEvoQfa6KxZ2kgTPt0jXP8HfeXJ/wQbOpPfc4+zNdvS/5x+qCeCk5kLT /EFSOkFHtdaT4BrHr0rboL4RKuUkQugC3Qf+IQ/WzsVRQ+AVvfxc8XJehTpGkRX0SxFB cfLdT8pC11ob+95MZ0R031vzNaePrMnhyxkE3Z9Xmxf68Vv9LHGAJtPC7i5SKXxBQ1Zy UEKbNxwkzYgSFbdkCNz0pOxOTLpCBM6DcNByuL1EgaYAZENIMcfp0zdVr+kmGcDUB75x 2dKaWmMBrnxqX3xqsmbD8xIDt24W0Z1/m71KVcYly1AvXwi8TUKIxqXYqQDAonT+TaPA SR4A== X-Gm-Message-State: AOJu0Ywr1QXP9ywBTgRFgDkwYGKGCZisTUQ0zCKkWBTOtSZIegHxZNkX 4zQbUsBQncjjaMuD2teTnUsERMX8JV4W0yLAEVQr3N1NDNyxXcTUolc2kQaR9s6UAmqFzMUiIVR 495oCW2J4SMQg7dfYCnd6GTw9BWr9Qhyy5k6aSlnB6Vl0ccdXvKL4pKI4 X-Gm-Gg: ASbGncsNOLcUytSXQrWJR5lvbsqkGzfpoifu+J5mYyLBL3rnZH9ZBnXoiy6XB/98x3V vOj8Y5i8qbm5kzwq4lV18hpsKEmWkjm8tfX37FHj/cVgAKBifTdRO5+TCL9/6LTP7NBgffr73TP jY7XtSt4xy07HOHx522CJGlST4gTayG+WAVz2AaFv7eDlKw3WwOtncVKmQVl47ZKWHhMFwCEo0i zwxfWI1wB2tN8Iv/51SCXlv0eByFWQw41dze4dT28ck3WO5r7VgP8WWXKlCh1RdDwaID8b9Nl5x 0e7uTQN2Q13cD2hlKMXMbBmJBcWqOVVno6dXuWit7Gm9BFH+G5V4FtjI3fMR61zRPWSi9kJPXTJ q/oHAwm+YdhdbwhEjIEi1jZ8KK9H+tHUj0Wszg715YB2iOWqctyKFmQSUmQ== X-Received: by 2002:a05:600c:450c:b0:477:55ce:f3c3 with SMTP id 5b1f17b1804b1-4777322d960mr71633955e9.5.1762789788496; Mon, 10 Nov 2025 07:49:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6DGILhuAdQ4Zz6x4jacr5qtFaYvDlrVMmNcmBd35VQG0DI9hsmJrF1Kdug8/S2E5jHQcgMw== X-Received: by 2002:a05:600c:450c:b0:477:55ce:f3c3 with SMTP id 5b1f17b1804b1-4777322d960mr71633645e9.5.1762789788101; Mon, 10 Nov 2025 07:49:48 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 15/19] =?UTF-8?q?blkreplay:=20Run=20BH=20in=20coroutine?= =?UTF-8?q?=E2=80=99s=20AioContext?= Date: Mon, 10 Nov 2025 16:48:50 +0100 Message-ID: <20251110154854.151484-16-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1762789892845158500 While it does not matter in which AioContext we run aio_co_wake() to continue an exactly-once-yielding coroutine, making this commit not strictly necessary, there is also no reason why the BH should run in any context but the request=E2=80=99s AioContext. Signed-off-by: Hanna Czenczek --- block/blkreplay.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/blkreplay.c b/block/blkreplay.c index 16d8b12dd9..8a6845425e 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -63,9 +63,10 @@ static void block_request_create(uint64_t reqid, BlockDr= iverState *bs, Coroutine *co) { Request *req =3D g_new(Request, 1); + AioContext *ctx =3D qemu_coroutine_get_aio_context(co); *req =3D (Request) { .co =3D co, - .bh =3D aio_bh_new(bdrv_get_aio_context(bs), blkreplay_bh_cb, req), + .bh =3D aio_bh_new(ctx, blkreplay_bh_cb, req), }; replay_block_event(req->bh, reqid); } --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762789959; cv=none; d=zohomail.com; s=zohoarc; b=huNoujvuFISZjJCWA7qu+J4NFrFZBeYzZj8pKioYvQOS5JXrluN3SSWkizhLxwZoKyQaqafQ3OUi4ayrRRYwpkeeKFQLsWXGqLv+ErafmzFGODVodjCpC8Sa4kTQbofgxwtcjebJcmD8COjDRE9xEgGCQVayWa8PPa4SmX4Olvg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762789959; 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=4urNL7p8q32yW3vnjExo0mWUQgRDxHTQkHCJr50ZGAA=; b=Df0dC4jMb1L8k1BwHr1pYSoDLGMEphsjcKyfkVnDrORxAXNO4CiQt+nIUito0qSC/mhyvEBJb90ChY6akwhhqLjUUzX14OuskCo2Y3LCS4PsFJaHIM0vZTybtszeoX/toOJxOrI1KoGpIqS62CaXywuzG5qXr+O1T9wMBGnjwpA= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 176278995932667.15700123393856; Mon, 10 Nov 2025 07:52:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIU9z-0000L2-59; Mon, 10 Nov 2025 10:50:27 -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 1vIU9V-0007d8-8I for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU9T-00014j-9Z for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:49:57 -0500 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-383-2Q3KUAzaMoqB4KSRwEHlCw-1; Mon, 10 Nov 2025 10:49:52 -0500 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-42b3086a055so1419188f8f.3 for ; Mon, 10 Nov 2025 07:49:52 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42ac67921c3sm23228671f8f.40.2025.11.10.07.49.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789793; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4urNL7p8q32yW3vnjExo0mWUQgRDxHTQkHCJr50ZGAA=; b=hbLY6B/rjXsF4nz3BILXYUbkOfnroekpkrh/LqsU3mc7tqnDfIaiAiL6A/xoBfK/Ao9szL GyIFUOFCAY45nqwYh741dUyEaW770DFdslm+N9rrRQ3vCcb0ribH9NfrGHaDyKMtClJMdp Uyn/sW743LL79rOQvIuZwbHCQec+ZWg= X-MC-Unique: 2Q3KUAzaMoqB4KSRwEHlCw-1 X-Mimecast-MFC-AGG-ID: 2Q3KUAzaMoqB4KSRwEHlCw_1762789791 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789791; x=1763394591; 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=4urNL7p8q32yW3vnjExo0mWUQgRDxHTQkHCJr50ZGAA=; b=O16+4Vh3+aDs0xlpeUEFSUXveMM7FBn6HVX/HFICxG8nRH6P0UNlM8APkHCtiEEf0I kzVH4z62ttwPAQ6HHocrJxd7NNv8fqRkb3DCXIp/viBKZnS/DIrgyIVvCnCwDifxwcfG t9DP/uHlLbJDV3FO50i7/SqETIozVaQY+JVlGk72nm/bqJXygjx3TM/ZePqjSUuXt4tZ aeOUl/NZ8arH1N1xe1TqubJv/XZ7gx0WvmyMRet9oD7hhyTTVoU5NTNq5o37HROIHlPJ SiRV95qs1qQ57okmc0ISrczMqrjT8BikBP+VITTvtQKKHmw5HqVstGfv8+6FT1WSU38P SDsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789791; x=1763394591; 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=4urNL7p8q32yW3vnjExo0mWUQgRDxHTQkHCJr50ZGAA=; b=J6pK0DxRb2TpBskwutAc0EGIeIIFaiRkFOQ8XVcoZqHsXW4xAnY8jnhl/ohxO0HSFy Qm+1aQBoWqJMh/yct0L2ZrogsVpx8iyjZEG0cnYHExw2EbEQEDzRmGPQpB/hColZPqxx HpXbpJikp+pNj7CLBXPOP/m09fGiOMTTv1ASA7a4NydJ0ujJtim3IFs1bbxLBgIt0u3a e2BlvqR/jTmQCxifYyGCWP3TLiTWwOSOn44uCs9v+T00qm3+gE/CtzUW16BM0Hqibggo U8zu5R70wEiNe6Xrag7sNnqrVUp6QA6I52ovcLt0scQ/oUSelR2BpLbFeIsuCHhmbo9C lx3A== X-Gm-Message-State: AOJu0Ywit0GUNqeTJvLud8CixRmXi2yPf/wuncRoNr9vCm31Xkk7I9ui y3zgghoH9TzY9nz2bDxnR6xBfBJ53YzkTh0xxmgzr+ZhKS9+Viul4JP3Gv59yl4urXXblPCR2bh oevw9itwAG5oXxvMesa87OtZdnRDKJ4cUtGVXfNGw+bD4/DjPExQ5Z+0K X-Gm-Gg: ASbGncsNwtoh/6Ke8pFerIWZX1kg/ExvmPB3h7kFgXdTUP47VQdSPF5qPvoDaneP810 tLxsSmgl4RXG9Ay1FiY8aLmrhMTW229RrC4KtEHj0z6yJ6HnoDXBAzCyGC2yT9hBJCAzaUuV4yx 09e7aJjK1GarfYqLtwW0arJid5PVZGj6VN7/jpKggjmvbGcuniHkXgxeHgpnpjIqCvVm9BzfG+9 qW3Mx02uMUVlzqigosYnx2WUBmmfWLu1PDga06ZueNow5sw0RMHydX2mHlgeC6Nw+4lKqR1uTan P0BSXa7s0Xas/FSbxE4wRn8EjsbrNgD+FiN0u01r51FDF+u4OROGVl67aNEufLpmDdms1cpoTH3 Qpbpnu3IVXUaI00U+4rOPGbhwkPFwsSwzmRaVgM5XwvxLMuEX3SQxva3TeQ== X-Received: by 2002:a05:6000:22c5:b0:42b:3220:9412 with SMTP id ffacd0b85a97d-42b32209687mr5078006f8f.28.1762789791050; Mon, 10 Nov 2025 07:49:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVynldXxCXJYEZMwyF3pQ5OuWWw0uHHjUE6doVcbTYH01/4I8RNEPeyDayhMghq38ADBVlNg== X-Received: by 2002:a05:6000:22c5:b0:42b:3220:9412 with SMTP id ffacd0b85a97d-42b32209687mr5077986f8f.28.1762789790634; Mon, 10 Nov 2025 07:49:50 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 16/19] block: Note in which AioContext AIO CBs are called Date: Mon, 10 Nov 2025 16:48:51 +0100 Message-ID: <20251110154854.151484-17-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1762789960104158501 This doesn=E2=80=99t seem to be specified anywhere, but is something we pro= bably want to be clear. I believe it is reasonable to implicitly assume that callbacks are run in the current thread (unless explicitly noted otherwise), so codify that assumption. Some implementations don=E2=80=99t actually fulfill this contract yet. The= next patches should rectify that. Note: I don=E2=80=99t know of any user-visible bugs produced by not running= AIO callbacks in the original context. AIO functionality is generally mapped to coroutines through the use of bdrv_co_io_em_complete(), which can run in any AioContext, and will always wake the yielding coroutine in its original context. The only benefit here is that running bdrv_co_io_em_complete() in the original context will make that aio_co_wake() most likely a simpler qemu_coroutine_enter() instead of scheduling the wakeup through AioContext.co_schedule_bh. Signed-off-by: Hanna Czenczek --- include/block/block_int-common.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index f2a4e863fc..cb0143ea77 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -508,7 +508,12 @@ struct BlockDriver { BlockDriverState *bs, BlockdevAmendOptions *opts, bool force, Error **errp); =20 - /* aio */ + /* + * AIO + * The given completion callback will be run in the same AioContext as= the + * one in which the AIO function was called. + */ + BlockAIOCB * GRAPH_RDLOCK_PTR (*bdrv_aio_preadv)(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque); --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762789961; cv=none; d=zohomail.com; s=zohoarc; b=NXUoTJka3rcdDWLWEqvnZX2L780JUpOordg3ojV8skE1RL+TBQPIebfbJaB0kSm0h9Tv9uS85/T6dxhwnaOJc3+qxsDoduJPPb+ihzKJ0W/dOqFYrV+k4Ua9yZNw0CyvYTpKKjOGSOiLHwMDje22pNCWeEe+aw2gkSmU5KLl0Co= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762789961; 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=PAXsKuSihMSjpHsg5qeXbwwqkrlPB91tL1NUu2U2BPI=; b=fBlj1tzqP/RAUaaymcSxgrc9UCpEj51BZpTlBmTkMt15/njs9DAB5j5MGy+mio7mZx2/NcDKDm2aJdoz+gzV6t/fo2QC/2ZpGa536xx/pG7E6Tprm6jYI9B4nUpptEjuMtO9gafb7MFzSdbcAxy4gKJ5+3RZOdOlgWOe/EZT3YY= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17627899615747.4638568032088415; Mon, 10 Nov 2025 07:52:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIUA2-0000gf-KE; Mon, 10 Nov 2025 10:50:31 -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 1vIU9Z-0007f9-0y for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:50:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU9X-00015h-4U for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:50:00 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-y5o1MSxsNeG4rNbSpBKjaA-1; Mon, 10 Nov 2025 10:49:55 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-46e39567579so17101175e9.0 for ; Mon, 10 Nov 2025 07:49:55 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47767749916sm248434295e9.4.2025.11.10.07.49.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PAXsKuSihMSjpHsg5qeXbwwqkrlPB91tL1NUu2U2BPI=; b=GTHNoEJkngFV2+7f0vFwjssVDJAD1dM4+sg6G+lJQilozhHfDdEhAjVyQWhAhHd5mtwO3Q /rmvFTleb03XKkRe8UpuuOkwKjasvIp5HTbTFHAv7iMmhAYRI/HAhRZCyuJAPRu3/70JUY wsKOxa+uWGIchZHDh7ju9LK51pGC2i8= X-MC-Unique: y5o1MSxsNeG4rNbSpBKjaA-1 X-Mimecast-MFC-AGG-ID: y5o1MSxsNeG4rNbSpBKjaA_1762789795 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789795; x=1763394595; 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=PAXsKuSihMSjpHsg5qeXbwwqkrlPB91tL1NUu2U2BPI=; b=s/9zhTdsi78xCF9AgXHUQu79FplLlohkGKVYD0MX7Y8FiGfLXU3Lx/xcwSFZW3UxUp yxMR6FDBibZzUKE6tM5VIjqACtOYmnWec1stUK6FuBPPaK0wAAYy+MzNhDJ2AEMJXu2g lB9Ifo8Bn6I725Dl5oTD74sZvGEPQ0rVHBtzj2eq73BknEPv6N3R8xk8g8vs5zt7yprN AjVsRJqv3ejTdSbDT/P7J/XdhUGwIQGQjIJYNXZ42RY1fKo58XaRNPZBCiNXY+hIV8Q7 kW/tmzou9xqGLguhwgxRb88GfbYuBaTq6nibfmbiNU1+S0caMirJSzDCk15WJtxwGvMz kcGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789795; x=1763394595; 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=PAXsKuSihMSjpHsg5qeXbwwqkrlPB91tL1NUu2U2BPI=; b=Z225YwLihfexRXK2dgjEyalhf7k5brAQwCsiBxX9ZYhhOsunG15bbxGa9TShx9U+yI QPyJ77Tmy5DgKlHysPOrPQXlewMrrn/f7WdIbZgKKfhg6JS60u/8EIe7aNwHbYL4Wvjt 7TuRgrOrULtZyZ10YxNfPONAW9l84/v9O4E1fdUndGTqFMkDYsVKV3HRbu8toMIct6hM wz3BYKevNgCYXsyX4fFy/eTEV7crSSgLSW70grmUoJIftn2iX7vSePUJRPKgF3fsZcGe pSa5AtoyzIswJXUyewwsVbh8RqIBsL88maZk49ciP+Xh+XRvSb+FNnFiuqqOBpoHEx1f uidw== X-Gm-Message-State: AOJu0YzEogYfxwWwzvKWObbPNZtpF8srcR1ssDft9JtuQ419DshlgSs6 FJAMmaSc5DoPlSv0EVv+fJlEuHXXre9tMG1ZgcDVAyeAEd3ewRlp+++q3quI+dC0QlBprc5OfDV IjopN+53EcbFmlxaF/jxRWz278j6AQYXGbgSx0LgtzCoCn4rA6tRE2JUH X-Gm-Gg: ASbGncv8jaQScP1fFsaFiAu2MGa6yyZ5JKStns/tKzE+97KRwTPCqBHmcGrnVdAocye AjyP7+lo92DaKRvrx0iTCbyCuLq9OobQhPD7wacqjyeSIVjhjLbCIs7cSy52kWVjjifY3C/acyG A8z0aoloUO0QCGuSU0wKZNckKqltmN/VclrYlm+U5Hr66uyF5XTeQssgZN72OPY9foBd4rX58FC ikhSDVz1VDu5kGeP3qEsnQn/cAQhCUzdOmBpaWBaE7IFS0dWO5qPWfj2D0FtdXfi677vmutnFJV H+6pQdsR9aRftBe0EgIK1fRIOabvT7WuRohThIQOGawRgSB9ZFHgsOv89jbEq1Oh/f7GRwZHFrK 5X7L4SSo4DYYgNA1s/+Wc06FZbuksXf1WzaBv18E0mYNoppEORIhuou22Jw== X-Received: by 2002:a05:600c:4f89:b0:475:de68:3c30 with SMTP id 5b1f17b1804b1-4777325ba75mr53342515e9.16.1762789794629; Mon, 10 Nov 2025 07:49:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1XdIXkU1sguoUTelxCNplPso0xhRwzhhCljeSED0jqUKlVFyrbycTo/eoovAZgMn67SS9EQ== X-Received: by 2002:a05:600c:4f89:b0:475:de68:3c30 with SMTP id 5b1f17b1804b1-4777325ba75mr53342235e9.16.1762789794251; Mon, 10 Nov 2025 07:49:54 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 17/19] iscsi: Create AIO BH in original AioContext Date: Mon, 10 Nov 2025 16:48:52 +0100 Message-ID: <20251110154854.151484-18-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: 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 @redhat.com) X-ZM-MESSAGEID: 1762789962082158500 AIO callbacks must be called in the original request=E2=80=99s AioContext, regardless of the BDS=E2=80=99s =E2=80=9Cmain=E2=80=9D AioContext. Signed-off-by: Hanna Czenczek --- block/iscsi.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 852ecccf0d..7d6bf185ea 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -119,6 +119,7 @@ typedef struct IscsiTask { =20 typedef struct IscsiAIOCB { BlockAIOCB common; + AioContext *ctx; QEMUBH *bh; IscsiLun *iscsilun; struct scsi_task *task; @@ -173,7 +174,7 @@ iscsi_schedule_bh(IscsiAIOCB *acb) if (acb->bh) { return; } - acb->bh =3D aio_bh_new(acb->iscsilun->aio_context, iscsi_bh_cb, acb); + acb->bh =3D aio_bh_new(acb->ctx, iscsi_bh_cb, acb); qemu_bh_schedule(acb->bh); } =20 @@ -1012,8 +1013,7 @@ static void iscsi_ioctl_handle_emulated(IscsiAIOCB *a= cb, int req, void *buf) ret =3D -EINVAL; } assert(!acb->bh); - acb->bh =3D aio_bh_new(bdrv_get_aio_context(bs), - iscsi_ioctl_bh_completion, acb); + acb->bh =3D aio_bh_new(acb->ctx, iscsi_ioctl_bh_completion, acb); acb->ret =3D ret; qemu_bh_schedule(acb->bh); } @@ -1030,6 +1030,7 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *= bs, acb =3D qemu_aio_get(&iscsi_aiocb_info, bs, cb, opaque); =20 acb->iscsilun =3D iscsilun; + acb->ctx =3D qemu_get_current_aio_context(); acb->bh =3D NULL; acb->status =3D -EINPROGRESS; acb->ioh =3D buf; --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762789987; cv=none; d=zohomail.com; s=zohoarc; b=BwhGvd8id1ar+hViUWa1k+v0Zmk5JYzc3u9hU0VRMSHRmyGpDcgmwrzo2fRIZy607FlCdeYbkZtYnGr+jHDWLJegwK4t7U5XBM8TBDiTZoqsz7WeH2FiXe6r3p55bh9WjvNnGSyM0awtf4/stsp2lsCCJOUG7LsGAZ2a2G3LPyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762789987; 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=jZKk3/icQIlk4wS9kJz5czI40TKjQtbEM/Odynr7F5U=; b=fE0JsAsx0NUlDmuyx08HqFTGOMUYV4g9yq5si5eVahLHjB2Hw3seddCrOw2/26HoKWWQuv3MYtkGXerrqmhUG1hc4Q2f7WlQ20lZIj+5Bzmkw4oM66EVo9UjgALjNgfdGn0Lk5KXZG/fHkY+XxjtHzf/S6LoorFDwQaN5byFedU= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762789987960603.0481063775843; Mon, 10 Nov 2025 07:53:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIUA7-0000vB-CZ; Mon, 10 Nov 2025 10:50:35 -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 1vIU9a-0007fp-Fq for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:50:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU9Y-00016A-Tv for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:50:02 -0500 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-202-LJpHF8hsMG6Xe_XsTNf22w-1; Mon, 10 Nov 2025 10:49:58 -0500 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-429ca3e7245so1362885f8f.3 for ; Mon, 10 Nov 2025 07:49:58 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b29e4b9bdsm19094756f8f.32.2025.11.10.07.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789800; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jZKk3/icQIlk4wS9kJz5czI40TKjQtbEM/Odynr7F5U=; b=gA2CFlopR79lEmkuQWL3O7VHBwtxR6O3pGqtUCF6yf3NO0Ij+WQMrpqD7c7EtUKQuEnDfw PkOs53xnCRQN9dOmVBwAXXXgnV2XjQtsCyeGdjfVGAaWUHwPuEyifw90fPWwXBWm5/QoTR bhkfc8I8rKjt3K7+Gmk3PTx7wlpvQ1E= X-MC-Unique: LJpHF8hsMG6Xe_XsTNf22w-1 X-Mimecast-MFC-AGG-ID: LJpHF8hsMG6Xe_XsTNf22w_1762789798 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789798; x=1763394598; 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=jZKk3/icQIlk4wS9kJz5czI40TKjQtbEM/Odynr7F5U=; b=p1Dw5K5/WtQi4CxCe6f1msodAvByjmP63I60D0VxTkahBOw8A+gLCKIfheJrk8sbyy WIpPGSddsFkmycKMKqm4UjEUyzBaIxIV85h3mHgDuSSXodz+qezPMffCxhjdPLCpI9i6 wFesagpbRQ9aoW0LMD2Hxrtecjw7Qn24Dwsu2vFhHVZXc5uFEAzkx2pTtk0dOunzJLof gf6fLybTmJua1OcwXi9RW/073tBsxnd7rmjm6LEJsgDBcpInq6XIaCu5ci/GZLS79yat A6wkPHb+/TGgcgCGJBWRABK/So+jMIUFGwlvnoVS9zahVhV1yzS96BQH9WSLpIZUO/mx FEaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789798; x=1763394598; 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=jZKk3/icQIlk4wS9kJz5czI40TKjQtbEM/Odynr7F5U=; b=vcMTG5NMSN3qzO86ClCb1TDBPvhe45sEuQgUddEsK4tphVbNw7NVSPRXG+ovzaPvtf R6S3MNTRzZs/r3p1uYwafFzipmLpE1i8dH7qiYq6UZ0TLrFY6iIg2XuDAGWDHJPgXUCH WgOddMzEuiAJrQ1JzqGke5pOAErGN7F6QUlYbICf12phlVgCNUjqsU2Pwb0ebowaOTTq BRdekH0KNijfKGnmUqQxia2eowVUEniyiv7nfntZQkQbpy1XFoBwNhpb+WXrf7cgI9Xn i0596zmnY/sceqyjWwDnHPzoFL0D55mjrUNNnvVTr8jP+dYqiSLXHKExRVC3tKBxDlPa Gwig== X-Gm-Message-State: AOJu0Yz0IcytYpdIn1tuwM2kwnNg7s4IUDbd97h89bS97U4NPI8FDW2R 5mOUxMEDGwvE9qEAKOndHN8C8HD/sm0ajsad65NAfTosXgZGR054Vox7SSfQ2t7RvaK1+ZpUDmc bbdsj87hDeV93W0csCJWXapLNE2FRQN//YjD0gTgwrdYMnc1RXWyywytP X-Gm-Gg: ASbGncs4MHgx30WOGeVMWiTCyVYi1CO3mpyBIgLwM5Bu2GlHPQJnDcc1HRgGlHOl4vU y9BtcWHApN6uEhjGMJCfaxheOS3Tumvjbfdzdx3lt1N/RypkrkqWyfDTUUM1GK4CJsAi26YUGMS a8Eqy3+WjfMRYfZTLYLxoXEKdIKMf2Hwez40vOusQiYJr18y753HhU4+hkGYWRtkov93lpxLiSA vb4DFxU61K+phKYsIXB/5pAq/LcfmvW7/J4mmOu0SWQkKPDB1ZSBYcCGYv0YEv4MVJzn2kCu9h/ e6RQhbxAOTzBdAwHQfkdnmu6Osy6+OUDU3vQwe9LGRqk0/cpI3bLJM6qHb738lH5C44IKytMAq0 n5LBs2vg/ZXYEo03/8lsWaxXw9Jf7Wo+Wxpq8dO8MaoiWSvG3EK64XYLFQA== X-Received: by 2002:a7b:c304:0:b0:477:259c:dbd7 with SMTP id 5b1f17b1804b1-4777324670dmr46774505e9.12.1762789797647; Mon, 10 Nov 2025 07:49:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IFDtZ2ceebBnyfWsJcOyvXIF1H3PO2b8f4d6dIOB9jgkxA3txlU7R04FlkUvUF4LakHm2eaUQ== X-Received: by 2002:a7b:c304:0:b0:477:259c:dbd7 with SMTP id 5b1f17b1804b1-4777324670dmr46774335e9.12.1762789797187; Mon, 10 Nov 2025 07:49:57 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 18/19] null-aio: Run CB in original AioContext Date: Mon, 10 Nov 2025 16:48:53 +0100 Message-ID: <20251110154854.151484-19-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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 @redhat.com) X-ZM-MESSAGEID: 1762789988495158500 AIO callbacks must be called in the originally calling AioContext, regardless of the BDS=E2=80=99s =E2=80=9Cmain=E2=80=9D AioContext. Signed-off-by: Hanna Czenczek --- block/null.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/block/null.c b/block/null.c index 4e448d593d..253d20ccbb 100644 --- a/block/null.c +++ b/block/null.c @@ -173,18 +173,17 @@ static inline BlockAIOCB *null_aio_common(BlockDriver= State *bs, { NullAIOCB *acb; BDRVNullState *s =3D bs->opaque; + AioContext *ctx =3D qemu_get_current_aio_context(); =20 acb =3D qemu_aio_get(&null_aiocb_info, bs, cb, opaque); /* Only emulate latency after vcpu is running. */ if (s->latency_ns) { - aio_timer_init(bdrv_get_aio_context(bs), &acb->timer, - QEMU_CLOCK_REALTIME, SCALE_NS, + aio_timer_init(ctx, &acb->timer, QEMU_CLOCK_REALTIME, SCALE_NS, null_timer_cb, acb); timer_mod_ns(&acb->timer, qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + s->latency_n= s); } else { - replay_bh_schedule_oneshot_event(bdrv_get_aio_context(bs), - null_bh_cb, acb); + replay_bh_schedule_oneshot_event(ctx, null_bh_cb, acb); } return &acb->common; } --=20 2.51.1 From nobody Fri Nov 14 18:19:09 2025 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1762789987; cv=none; d=zohomail.com; s=zohoarc; b=Ri7zP18dLrvtZz8X6wNG1N5XwvFYkXq61yoMv7nM9m79Am54P2Q4ul0qZ9Zj8cckAuzBQKQEl89IYdsEg3Gp7qjhJ5vLBZoO3cFl/k86diETpsOZpw4T+/qdab4FkQ9FdPxxUIYSsMFCiZezke2NN4LrvXMtlf4H/Frod2Jdplw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762789987; 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=97LWOWIVGNTslIhzn2F5UxuphWwRSGYYKiGjxX6b0oc=; b=QlNVaIQoOiq36enKGdTPyTK6XpbhtdBKH+sOhCc2ifUYhNkRIPP+hQgMrFdBVQyUO7ueokm64vVp0lvBDLBb6OrAetcFzEGuCPLombohFxEARp5wxVM1z2+8u4Kq1W4E9hP4V8ROcXiBQAJLqRV/lmYVyTFDvaNfyrjF3OVRnJ4= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 176278998749797.72366195684901; Mon, 10 Nov 2025 07:53:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vIUAs-00029s-FU; Mon, 10 Nov 2025 10:51:23 -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 1vIU9j-0007uE-1e for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:50:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vIU9g-0001Jf-Po for qemu-devel@nongnu.org; Mon, 10 Nov 2025 10:50:10 -0500 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-286-8yEOcJbtPsyaDKdNM1SZUA-1; Mon, 10 Nov 2025 10:50:01 -0500 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-42b2e448bd9so1297144f8f.1 for ; Mon, 10 Nov 2025 07:50:01 -0800 (PST) Received: from localhost (p200300cfd7171f537afd31f3f827a45e.dip0.t-ipconnect.de. [2003:cf:d717:1f53:7afd:31f3:f827:a45e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4776bd084d4sm261059595e9.14.2025.11.10.07.49.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 07:49:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762789807; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=97LWOWIVGNTslIhzn2F5UxuphWwRSGYYKiGjxX6b0oc=; b=fM3yxpCpAe2VHkFFtEB/uUbj7YUNzcusvfJdGceWppFB8ws6QjcrxnUQ6QE9ITF6I8OMFI vE1gCLQPA052b2AnvOVQGisyNVTnbiMfca+duCTvu0EX149TF2YFvLij2N3jhcFCSs1VS+ tORGg59uNIsQfvQ98newWW5xgSHuO5M= X-MC-Unique: 8yEOcJbtPsyaDKdNM1SZUA-1 X-Mimecast-MFC-AGG-ID: 8yEOcJbtPsyaDKdNM1SZUA_1762789800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1762789800; x=1763394600; 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=97LWOWIVGNTslIhzn2F5UxuphWwRSGYYKiGjxX6b0oc=; b=NETGIOoYX/VeS5QiIYkyqWdmSSI3jsq6I2/9rXNUrdP8gqVeVMcIlRavDTKTDRBgTU F64hT5DhpulfyCsgd08Cj/BOe/IfgeBalx5cQloTK5Ixa+2CD0Uwn+TRe/GV9grENuJ2 LIBmZbsBhKJR9cgRdLM5D3vg/Ypic7SKyiBSy14/uPtW1Y/gzyIFgJd+ZzYIvvCEB8wU Ds1xrCgy1+sa1+s35QSZIhRsGDz069ro0+PP/+43IhZfz/A4W9spo2b9QFu5Z2jw2PIg aOiLvSMfJesqvfuUxPD8IE+RLuRC23qQQgtJj63M8AAeHuMe63h1gau0z/MCao4oG9Pb 9E0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762789800; x=1763394600; 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=97LWOWIVGNTslIhzn2F5UxuphWwRSGYYKiGjxX6b0oc=; b=FQq/J8J8OECYqL6dx9R2SLko9lk42Y8/Cppbz7FnaYgN3BN5ohLdIjPW8bxKgn87AS 6sU244MaBx+ZjaqccIIW90HqAHAxzmJeUBTFzoKF5HG2fFKt2z7Br6boWcKKjXawZ1gD mcOQiclnRIDbas0meS2gAIeFZ6vSWjAcrvA6Ipt1DRP3FmZ0cymCACSkB+VUwC6RC3b7 NBWFpW4/PUZh0kTl960ISciuYwhnPcbmOiLY4AYfeKhVIpaNwuJ+xjJGaqIfkIIvdQOM RJy7yds/AjjjFZiXGehWCSY1ArwaL9FXlRMUqKlvhmz5mGxgJcczV9amfWKmAbvB30dY m0hA== X-Gm-Message-State: AOJu0Yz/w7bC0JKovUtnTJOfSYPiBRBRj1+qefNVYZAbGYQNB5ngh3I2 4Rr1WFEp9NnyIelMkecH79wvndm1J8p9LH+NH8c8aTVf+5jRlnqUJToJe9dspurBb4HKgxcSwvG oE7hYjw6sru4HMhX5uqd8HxXMaLudG/AtMCGyhywIdD6bg9LX8rvzCntO X-Gm-Gg: ASbGncsxX/JznMOz4ETNqdFy8ah3T6TK+LBxrr35CuDU69kuXjqN0uiMF96l/gHv6R4 x9LaDPbU/0TukHKcGcl1TBqfYyxqNHXBw6UiC/tCFrVArMzFNY8XK0ZwX/WJssrIxyp50DrkmMv G+YovnzG4w8OGdMEpyNY7+3o0txj3821DElX258jF7WUsN/FbIsSeERwVoCtI5fqQTAH6htJjoh 1tsi/WKjqKLh+uppdQnuzNcUjgH0fRVH4D3Go5jQ0+ggGRnZPYn4TiLkxiLvz7D1Lp5GyUEbLLU SaY5SKxgGoJxTtZAMZ+8QmlYw1paIdVhF8O1MNrIsrvprCHRiZJqtT2rSoj5Ysn4zXD42+TEZSN pCz/HO9PBxqGfTM1z3cyUUN9soqDqYKpZlcTZRemAZl243ZSbI/xBMJtRrw== X-Received: by 2002:a05:600c:1c97:b0:475:dc85:4667 with SMTP id 5b1f17b1804b1-4777322f29dmr74173315e9.15.1762789800426; Mon, 10 Nov 2025 07:50:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IEabPrGUNbKsMZYOk2DjBy70AWnZ2rsiHUUQFccs/agsINyOqR9bU9aSBYwhDCKDM1oiKSBzg== X-Received: by 2002:a05:600c:1c97:b0:475:dc85:4667 with SMTP id 5b1f17b1804b1-4777322f29dmr74173105e9.15.1762789800033; Mon, 10 Nov 2025 07:50:00 -0800 (PST) From: Hanna Czenczek To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Czenczek , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini , "Richard W . M . Jones" , Ilya Dryomov , Peter Lieven , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Fam Zheng , Ronnie Sahlberg Subject: [PATCH v2 19/19] win32-aio: Run CB in original context Date: Mon, 10 Nov 2025 16:48:54 +0100 Message-ID: <20251110154854.151484-20-hreitz@redhat.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251110154854.151484-1-hreitz@redhat.com> References: <20251110154854.151484-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-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: 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 @redhat.com) X-ZM-MESSAGEID: 1762789988512158500 AIO callbacks must be called in the originally calling AioContext, regardless of the BDS=E2=80=99s =E2=80=9Cmain=E2=80=9D AioContext. Note: I tried to test this (under wine), but failed. Whenever I tried to use multiqueue or even just an I/O thread for a virtio-blk (or virtio-scsi) device, I/O stalled, both with and without this patch. For what it=E2=80=99s worth, when not using an I/O thread, I/O continued to= work with this patch. Signed-off-by: Hanna Czenczek --- block/win32-aio.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/block/win32-aio.c b/block/win32-aio.c index 6327861e1d..f0689f3ee9 100644 --- a/block/win32-aio.c +++ b/block/win32-aio.c @@ -48,48 +48,62 @@ struct QEMUWin32AIOState { typedef struct QEMUWin32AIOCB { BlockAIOCB common; struct QEMUWin32AIOState *ctx; + AioContext *req_ctx; int nbytes; OVERLAPPED ov; QEMUIOVector *qiov; void *buf; bool is_read; bool is_linear; + int ret; } QEMUWin32AIOCB; =20 +static void win32_aio_completion_cb_bh(void *opaque) +{ + QEMUWin32AIOCB *waiocb =3D opaque; + + waiocb->common.cb(waiocb->common.opaque, waiocb->ret); + aio_context_unref(waiocb->req_ctx); + qemu_aio_unref(waiocb); +} + /* * Completes an AIO request (calls the callback and frees the ACB). */ static void win32_aio_process_completion(QEMUWin32AIOState *s, QEMUWin32AIOCB *waiocb, DWORD count) { - int ret; s->count--; =20 if (waiocb->ov.Internal !=3D 0) { - ret =3D -EIO; + waiocb->ret =3D -EIO; } else { - ret =3D 0; + waiocb->ret =3D 0; if (count < waiocb->nbytes) { /* Short reads mean EOF, pad with zeros. */ if (waiocb->is_read) { qemu_iovec_memset(waiocb->qiov, count, 0, waiocb->qiov->size - count); } else { - ret =3D -EINVAL; + waiocb->ret =3D -EINVAL; } } } =20 if (!waiocb->is_linear) { - if (ret =3D=3D 0 && waiocb->is_read) { + if (waiocb->ret =3D=3D 0 && waiocb->is_read) { QEMUIOVector *qiov =3D waiocb->qiov; iov_from_buf(qiov->iov, qiov->niov, 0, waiocb->buf, qiov->size= ); } qemu_vfree(waiocb->buf); } =20 - waiocb->common.cb(waiocb->common.opaque, ret); - qemu_aio_unref(waiocb); + if (waiocb->req_ctx =3D=3D s->aio_ctx) { + win32_aio_completion_cb_bh(waiocb); + } else { + aio_bh_schedule_oneshot(waiocb->req_ctx, win32_aio_completion_cb_b= h, + waiocb); + } } =20 static void win32_aio_completion_cb(EventNotifier *e) @@ -120,10 +134,13 @@ BlockAIOCB *win32_aio_submit(BlockDriverState *bs, DWORD rc; =20 waiocb =3D qemu_aio_get(&win32_aiocb_info, bs, cb, opaque); + waiocb->req_ctx =3D qemu_get_current_aio_context(); waiocb->nbytes =3D bytes; waiocb->qiov =3D qiov; waiocb->is_read =3D (type =3D=3D QEMU_AIO_READ); =20 + aio_context_ref(waiocb->req_ctx); + if (qiov->niov > 1) { waiocb->buf =3D qemu_try_blockalign(bs, qiov->size); if (waiocb->buf =3D=3D NULL) { --=20 2.51.1