From nobody Fri Nov 14 18:17:44 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=1761669365; cv=none; d=zohomail.com; s=zohoarc; b=W8yRnogEToY7ojk2qWwyej9OyYv29DUf2ZAbIr4Y68OpsIDcAUzG6ROoMkNvLFg//eObJTNqoqnSCwt35FyNvHdpszBYGIGbS/9UqqaQbivyUwG/jgN+Fvm588EVOMAh7cg0BQV8FD2sJ4Se/HrJ6nfp0f10NeihRAGBF81wM2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761669365; 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=9SKZtrOmHUmq+rD18X1HIMI/6NZVlZ/S6570rCbBKQA=; b=myt8LEm/pBlA46iA0nPk5ceZmYTpOyBncnTTJPFnaaQtdBKsV3+n03NvGaG0k4hIA1+7iO5iWh0eW52ZmeDOctBt/qSkJYKjSL1Nv+UOb78zGLId4LTnZLHWgPyfZmMZqneeKS3kaMWFqYVxYmGAl3keeVQyRRkHIePPe//34eE= 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 1761669365237234.38039426833575; Tue, 28 Oct 2025 09:36:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDmeJ-00084Q-8x; Tue, 28 Oct 2025 12:34:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDme6-00081a-MX for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:07 -0400 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 1vDme2-0003UT-EY for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:06 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-561-4ofXVH8bNFOxrrKJTt_r7g-1; Tue, 28 Oct 2025 12:33:54 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-475dca91610so17512285e9.3 for ; Tue, 28 Oct 2025 09:33:54 -0700 (PDT) Received: from localhost (p200300cfd7171feeff88afa910cb665f.dip0.t-ipconnect.de. [2003:cf:d717:1fee:ff88:afa9:10cb:665f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47719004d79sm22970895e9.5.2025.10.28.09.33.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 09:33:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761669235; 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=9SKZtrOmHUmq+rD18X1HIMI/6NZVlZ/S6570rCbBKQA=; b=Crk841O+CUUZU1ED8GZh77SkK1OGzob/jj4mwIJ2Fa0OUZQhLFgk1aYDf6fNJukF1jklrQ X3tPHhVCz4UbORXoa7Jp56tNsAlraUwO/my/mrgk15E1JHYUypTIe5QZ5eXXK6PIHHbS1O +b5gmkks45H8pFbpjF6Pm/LNpd7z0VI= X-MC-Unique: 4ofXVH8bNFOxrrKJTt_r7g-1 X-Mimecast-MFC-AGG-ID: 4ofXVH8bNFOxrrKJTt_r7g_1761669233 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761669233; x=1762274033; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9SKZtrOmHUmq+rD18X1HIMI/6NZVlZ/S6570rCbBKQA=; b=NYr2k0ppAiZoDB9VjJBR8+ERkcv/KnzSdMO1TFwHNQHg48d4qKGSLnTPEmmB59XnBr roah75D6APpU0fLy4605OFkkfRqj+DeqQW/HDDEBBVhz6ofxergASGhpAvu16obg+TIV i8C8MhGBz2Zotr5FlDynHaEQMQxWeUPbbA3FUwsjeDkV9f8o1CdKu6cglVyIjJYq2HGw 8OscAIillFXJBxzgkK+ONpokfXOrqLFlwcqaEQT6HVkFpJ+svbo7m92frygtb8j03SCq PDC3UDXZDYTL0md06F+er1stukV0xFgIJwrxHPpH7K7rHSVZCCXJMuiJ8HZP9wpSbJL6 561A== X-Gm-Message-State: AOJu0Yy+7J/o4ZIFPljFkyZZUf6WJF8dGvyITkvemThBgIE/905QN2Rm KkPhvTblSw2oXEyXXu6gq8bTM0XbUuUoRUVStIbNTckWXqPTuOVTVMDZia3VNvD4CPQxDj+Fq+N H3NDkb5CYnYJB3T+0JRGeavc5bmkvZKN7VJav8L0aIdjWianb25fng0pF X-Gm-Gg: ASbGncvnEgI2eDU9I8jp0Hzkh/S0A3xkQIrYH5wNyHlSaDzwm5vOaFG1jUbAWg5bPDI kR7FQrzGWssERo6XwSreVQcZbdD/RvFaXi5xh2Yrmen/+UBlqC9lDXjJdOMizeJFHv2qMXLLvWu HKNRBiSuthzJCNfxUIU9hpFfwCP2Dku5a/P0qpJtHBL5Qcmk4c4/vz6EVqfDzCY+21rHvUiIWGK YwD3X8fhQ1SS8SIKK/JZp/SHP8aVL0baErR5kL9F+ElwNh0lFDAX4QEv/GeD6xr4qwPFPm+sgHM FuqtJ//a006O2796P1ZDAKiFhm+Jlu0RdTYmRSTDNTi4/B6wu0RwTubskCQxayBm3WVpQMro3Vf FBVJCOCUyc0yf7a5LkMexlRoPXM6DMdglYQ9xYNV7PyhijAOPzCTVdFlG/A== X-Received: by 2002:a05:600c:3f14:b0:46f:d897:516f with SMTP id 5b1f17b1804b1-4771e24b039mr751615e9.34.1761669232937; Tue, 28 Oct 2025 09:33:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGkXhoh1BxDXlbv5TlueEMZkpM22xzWPrU6xjTbl5Bc0pa7ufOWQvlFUxOcXxDJ3H2us+jIbw== X-Received: by 2002:a05:600c:3f14:b0:46f:d897:516f with SMTP id 5b1f17b1804b1-4771e24b039mr751195e9.34.1761669232499; Tue, 28 Oct 2025 09:33:52 -0700 (PDT) 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 01/16] block: Note on aio_co_wake use if not yet yielding Date: Tue, 28 Oct 2025 17:33:27 +0100 Message-ID: <20251028163343.116249-2-hreitz@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251028163343.116249-1-hreitz@redhat.com> References: <20251028163343.116249-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: 1761669368594158500 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.0 From nobody Fri Nov 14 18:17:44 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=1761669671; cv=none; d=zohomail.com; s=zohoarc; b=acI31QG82Wg6qmm5R30svfEzfr41TsUFvqqBPVmhJUQZlceJfBCx/ZlhWFzvLqakofUWRiJpxsTR+qoZ3s42ky/NDP+XaE6hOzvfNJPoxHx+us6HVD+fmY8yVSbTOOKX8azezfEzuDFw7XNsjqQKX/r4+kLO/tre2E+u9IcM3pk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761669671; 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=gR8MtG0BVWnvKf6Erh8dGKDS/UGOnXD1GBQG6hP9q5w=; b=N0cijL/unpOEI4WfGJbLXcP+tOUsAZ/nsG3RdkgQoodiM87bW/58y8pbf8GxbKsFIb+MBSE3r+2DUCzFITuLofELuA+UKfS07AaVSonCik6+U4xwKDqgTsE1Q+Xrq/St6o/qyU3cVkjEp5zyMxhceLdSOGaCM1ozZwU9N+Eupkc= 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 1761669671777571.8157410755194; Tue, 28 Oct 2025 09:41:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDmeD-000831-Mb; Tue, 28 Oct 2025 12:34:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDme6-00081Z-HR for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:07 -0400 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 1vDme2-0003VR-CP for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:06 -0400 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-195-ow11Hb1lNDuv-T3T3hluew-1; Tue, 28 Oct 2025 12:33:56 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-4278c82dce6so3733954f8f.3 for ; Tue, 28 Oct 2025 09:33:56 -0700 (PDT) Received: from localhost (p200300cfd7171feeff88afa910cb665f.dip0.t-ipconnect.de. [2003:cf:d717:1fee:ff88:afa9:10cb:665f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-429952b7a94sm25114579f8f.5.2025.10.28.09.33.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 09:33:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761669238; 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=gR8MtG0BVWnvKf6Erh8dGKDS/UGOnXD1GBQG6hP9q5w=; b=cQZDziNCxPtXaUWZM6Syxd6bgPob7st1G7avoDjot5BaEQHXldg6Pu0jn6mvdcVEJyNe50 m7nF/mCNpDWcNFU2FKE/O9nfEDJkH7IOwH0Vuq+vZYAuUFBbQHT7plZEQt0T5baZoY5u1n xWpk8bZgOgO643tMihJEhhDetXy6uwk= X-MC-Unique: ow11Hb1lNDuv-T3T3hluew-1 X-Mimecast-MFC-AGG-ID: ow11Hb1lNDuv-T3T3hluew_1761669236 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761669235; x=1762274035; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gR8MtG0BVWnvKf6Erh8dGKDS/UGOnXD1GBQG6hP9q5w=; b=nErrNqI9x9uUx+bg6+bpZ5wsJVpV1hHYKltO2BiOXZV89aa4ovT+Rgx8EQIykiMmd8 zvNtUq8eDKeRH8ctMyZLqarmOmft10+NGGHU91eJm4IsGgtCJL2kF6oxEdiT742X6dum SLwXFM4/iEjdp8okS9LpkUFfXEdLqynWGc0jWOTns6B9JPo4yG60cnru1uDaq02zrMsO 66WoRA3Zoqqf8j/HnGWfrn0tk/srjDU66/T9mEsRpyOABahM1XUdGF1yJkNxWPwEWeHU 3B6BQilaufJ8TE4Yyg3n4xMrUyskdJC/yRdzeN9N2QJ0jr0PawyEmvbPZvUl2GH8J6I3 bqvw== X-Gm-Message-State: AOJu0Yzq9j/Wszb5giD9xaliJEuQs9hNflxbdtI29juFvgYiwMaTN3C+ HMsWvRlhg8cEviG41MxtTehGwai+MD7n/vEKTn/kUM2RjhGrKKh8sIKeYYzyCdHnRPDLkGFzQbD fvR/AQFE4hRhhIE7e87pzqQq+6GXAxNz6yXZkwCl4DPs6g2ZSYJXYtHcO X-Gm-Gg: ASbGncuRI33GtYl38QxQNpTeRJ9z6jr8r/uf4Tgw+IvIaMy09Hjkipu7/pwztmNNfn7 uVYiSqgpvDmB/nCvRcbW7ko80LVk3MObu2pr3bgEbSNfviZL+xTqaDvSCHzcoG1rI2DwE98kwMr xvsbEZAWVrtm3GSOo6VosxRFxVt0e2hexo+bTuV0dNn5YvUhNYGJ/05FT1PVT862mugCdWQtgQS nBuDxbJnlCEA8x6Znx2jEJhrzVyidiyZIu+fPKwYqRwNzX0+xACSdXcIGMtM1rtyC9JS5Zwo6qe WsMoCv5WIjOkUjXqvqSDi9jtIiTRY9/CO04c1GEMLNEpJgyUx0kt536Dt3Y3bl0zbJkX36hEErz 7jB6tBfUv/NLR/yGS4zVJ34e8LxOap7eRdj9dwh0It17rbrGkOb/Vy7lm+A== X-Received: by 2002:a05:6000:402b:b0:429:8b01:c08c with SMTP id ffacd0b85a97d-429a7e52ea1mr3155744f8f.19.1761669235570; Tue, 28 Oct 2025 09:33:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6M7Yv6zGU7DNnVtewoLK9lznqHNtdYpMEEzLg+qT4xsSVy9OH17HuM5lRCpvl5ud6a7S0vw== X-Received: by 2002:a05:6000:402b:b0:429:8b01:c08c with SMTP id ffacd0b85a97d-429a7e52ea1mr3155713f8f.19.1761669235052; Tue, 28 Oct 2025 09:33:55 -0700 (PDT) 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 02/16] =?UTF-8?q?rbd:=20Run=20co=20BH=20CB=20in=20the=20co?= =?UTF-8?q?routine=E2=80=99s=20AioContext?= Date: Tue, 28 Oct 2025 17:33:28 +0100 Message-ID: <20251028163343.116249-3-hreitz@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251028163343.116249-1-hreitz@redhat.com> References: <20251028163343.116249-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: 1761669680209158500 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.0 From nobody Fri Nov 14 18:17:44 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=1761669575; cv=none; d=zohomail.com; s=zohoarc; b=HRvA+Z4QThp4b+1+QlDorqrWWCPtBwwM3ljIkfGFzuhnMPkv/AG3rdYGtus+rbrQ0doxfEUNiLrmkYJ5QcADCC1/nKfLhHWtvyU7eUmWj92h2onXn3PyxN5+JBt44raz/hCCKpnvj3YUgYi6u7MK6H1SD1dvKGzDfURtFN/XMj0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761669575; 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=6fT6mtzR5u0lZZ0ban5hvgxpPszfsK/X1TDCxFw5a88=; b=eiq+EMkyEBKwmELpNx7aGqdyvEKk6GuszFDI9+5oKPtDfkcv4pBNc55p2l0JUeeams97akEUnRH16IylgADnGunRmEq0WVOE8yqf6wUQLaW8CW9Qn0ee6oqYisFFyLb5KLoSrm7+arw40szShhl5OqrctZL4DkBidmc/a3Zvp6s= 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 1761669575638509.0041260037517; Tue, 28 Oct 2025 09:39:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDmeY-0008BN-Nr; Tue, 28 Oct 2025 12:34:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDmeH-00084U-Ln for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:19 -0400 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 1vDme8-0003Y9-Es for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:17 -0400 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-413-DNW2A8wAOIWH0iBXz8jD7Q-1; Tue, 28 Oct 2025 12:33:59 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-47111dc7c5dso431565e9.0 for ; Tue, 28 Oct 2025 09:33:59 -0700 (PDT) Received: from localhost (p200300cfd7171feeff88afa910cb665f.dip0.t-ipconnect.de. [2003:cf:d717:1fee:ff88:afa9:10cb:665f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-429952cb7dcsm21979902f8f.11.2025.10.28.09.33.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 09:33:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761669245; 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=6fT6mtzR5u0lZZ0ban5hvgxpPszfsK/X1TDCxFw5a88=; b=husxOrhji3BkLFKy7sNhdBiT8YyKS7dsEMa9fek/Pld7gbZmMifoYiwv4FHtAelXyeN7VR 27zDTl42XjNYxh+WtKJrg+yN+BsyP+34J3XqX1QtEsyHBo7SMj1kyoYJLVDUHu1uuegAt4 9A1QwSW+4fhzU8NWpYyT6wA9HTnT49M= X-MC-Unique: DNW2A8wAOIWH0iBXz8jD7Q-1 X-Mimecast-MFC-AGG-ID: DNW2A8wAOIWH0iBXz8jD7Q_1761669238 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761669238; x=1762274038; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6fT6mtzR5u0lZZ0ban5hvgxpPszfsK/X1TDCxFw5a88=; b=jS58Cnh6WftnmCpEeOfS33p7cpMKiMev14w3DIfTMogLxxMHH7M87vL9pj8oCgcVzB H5mWOZ7L69esZBvr/IfykS73vGoGmYEcKVJK/mdoc0ruLo5PPd1KXvEKP2K8TqduHNox 53Udd7kcWWjQ1KaZDJcK/iqkN/2N70Sg47M1pne/+B/Tvv5SgRvH+Y0p7u8tnP+9ftYy vSP4xMDY2oNuVnP+0n20ZfKSHxR2/Qs8t2qDZr1vwf8yy6oSMJ6f0QYnOgDHdK3hBMNQ VQqbiB33JhAknCbqwc8yP6F9MVU7qecHFIIdfdWL+aH4CRz31d5ST1ilJ9aCCy6luEre f9+g== X-Gm-Message-State: AOJu0Yy6vtijw2jgwE15Ymh6XChPIIoUcSQBlM9EjK0N2Antzj2Ih5zs 5srZuCUzyLDxxMj7SbKyQA0uo2i7KdjDEDmDmBOLORbD2qX8klCRf+pEYlEWg9Am3kPilalWU/w f13/xBGgZRafzNxbb64ig+B0HuccDiroNFsaOwkeNXtfYJcfuSjwOMtFf X-Gm-Gg: ASbGnctsQEBxGTJEr8cu9eWzTZEXIcV8GU/MRbGuT6bMq5DoIlHE1i7hbK2Tziihrdn TvDDPAYhGZecgaT/OPK2spbXI3fw4UjcAt/jBBfzfTU7SQbBdxusWdZhKG1v12yUwRsWj3QyheE 5nheGtyVcAvIgpLlh3duq1wK9sy2kfddNWW9SHW8NjA0U/SPY+jV3ib+KQFg0PgbpJ1fdKyZLt6 jtzpH3xVRaFDKSvEYs7GSy9SA4Sv8uP5CMUbVZTTqQLNexcpIIvdPVtQg8NLs3bEPLMfhePfkJv X6Ot5VkvRCs685ruZmUUQkeYb3zeWsMGtDO6HzcxvW5knXwCHXDj9PZERXb4IFBzGjRCLVHZ7SO GNcuCkSKVUD0lJhn8u9atCMpzIv8+NI816sPNJ8Oc38SmEDv8Ly7SXVL4mA== X-Received: by 2002:a05:600c:c10f:b0:475:d7fd:5c59 with SMTP id 5b1f17b1804b1-4771819772amr25163855e9.16.1761669238295; Tue, 28 Oct 2025 09:33:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGOeyGHVXYZ85irW03JhyRix5r8yuu3zLuUZHaKA1+29RrLT2PcnJiHm7nIPcsmIrdPrRn8Jg== X-Received: by 2002:a05:600c:c10f:b0:475:d7fd:5c59 with SMTP id 5b1f17b1804b1-4771819772amr25163605e9.16.1761669237738; Tue, 28 Oct 2025 09:33:57 -0700 (PDT) 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 03/16] =?UTF-8?q?iscsi:=20Run=20co=20BH=20CB=20in=20the=20?= =?UTF-8?q?coroutine=E2=80=99s=20AioContext?= Date: Tue, 28 Oct 2025 17:33:29 +0100 Message-ID: <20251028163343.116249-4-hreitz@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251028163343.116249-1-hreitz@redhat.com> References: <20251028163343.116249-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: 1761669583188158500 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, and actually, for the former, we could drop it and run aio_co_wake() directly from scsi_co_generic_cb() to the same effect; but that would remove the replay_bh_schedule_oneshot_event(), and I assume we shouldn=E2=80=99t do that. At least schedule both the BH and the timer = in the coroutine=E2=80=99s AioContext to make them simple wrappers 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 | 39 ++++++++++----------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 15b96ee880..76c15e20ea 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; @@ -183,18 +182,13 @@ iscsi_schedule_bh(IscsiAIOCB *acb) static void iscsi_co_generic_bh_cb(void *opaque) { struct IscsiTask *iTask =3D opaque; - - iTask->complete =3D 1; aio_co_wake(iTask->co); } =20 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 +233,7 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int st= atus, { struct IscsiTask *iTask =3D opaque; struct scsi_task *task =3D command_data; + AioContext *itask_ctx =3D qemu_coroutine_get_aio_context(iTask->co); =20 iTask->status =3D status; iTask->do_retry =3D 0; @@ -263,9 +258,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 +279,7 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int s= tatus, } } =20 - if (iTask->co) { - replay_bh_schedule_oneshot_event(iTask->iscsilun->aio_context, - iscsi_co_generic_bh_cb, iTask); - } else { - iTask->complete =3D 1; - } + replay_bh_schedule_oneshot_event(itask_ctx, iscsi_co_generic_bh_cb, iT= ask); } =20 static void coroutine_fn @@ -592,12 +582,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 +657,6 @@ retry: } =20 if (iTask.do_retry) { - iTask.complete =3D 0; goto retry; } =20 @@ -740,7 +727,6 @@ retry: scsi_free_scsi_task(iTask.task); iTask.task =3D NULL; } - iTask.complete =3D 0; goto retry; } =20 @@ -902,7 +888,6 @@ retry: } =20 if (iTask.do_retry) { - iTask.complete =3D 0; goto retry; } =20 @@ -940,7 +925,6 @@ retry: } =20 if (iTask.do_retry) { - iTask.complete =3D 0; goto retry; } =20 @@ -1184,7 +1168,6 @@ retry: } =20 if (iTask.do_retry) { - iTask.complete =3D 0; goto retry; } =20 @@ -1301,7 +1284,6 @@ retry: } =20 if (iTask.do_retry) { - iTask.complete =3D 0; goto retry; } =20 @@ -2390,7 +2372,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.0 From nobody Fri Nov 14 18:17:44 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=1761669352; cv=none; d=zohomail.com; s=zohoarc; b=ZaJge6XDIhrhTeGR54paD7a2pqYgGJBkA7BTBzJKYn4eVdvvY0YOgWD5bad9P31g3ujksXzFGJuCrZLWtGcfdvLZ6amvcxOtOFDxmT6lBUvK+Wdqda5MHbGApd271YhXsY6oqctKABn7rJYC8p11HTxeuDtPnTvfnlHfIlkN81I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761669352; 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=xWepIFUxkv0l/eNVnDUu6hPjEIOeUyCJAp9pfFkwuz4=; b=VyAvVhGaBRzU4+tqsnJIRfxZs6tsyKfHPZMoHaULdEhTnwwYSNq/O98Pl5wuFbbTDCJwYSpjcBAPB+NkuFP66zqAC0nDJeuLbi/pZfW4/gCAHg/1nY+0xvtzNpbPFLEgHp28nUfJ6VbBeU7ysKJb+kZ2CfOexDhBcjwOZqMDjmM= 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 1761669352574764.3096442822605; Tue, 28 Oct 2025 09:35:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDmeO-00085D-TA; Tue, 28 Oct 2025 12:34:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDmeB-00082T-G0 for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:11 -0400 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 1vDme6-0003Xf-8Z for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:09 -0400 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-680-dUQLGb1hM0OrlGsWxuL0ug-1; Tue, 28 Oct 2025 12:34:02 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-426ce339084so5873964f8f.0 for ; Tue, 28 Oct 2025 09:34:02 -0700 (PDT) Received: from localhost (p200300cfd7171feeff88afa910cb665f.dip0.t-ipconnect.de. [2003:cf:d717:1fee:ff88:afa9:10cb:665f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47718489d96sm25054745e9.0.2025.10.28.09.33.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 09:33:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761669243; 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=xWepIFUxkv0l/eNVnDUu6hPjEIOeUyCJAp9pfFkwuz4=; b=C+3j76I0UVoakuNqfSu6cRFOSEttgRtTNFzMP+jwouuN5wmqOnkyjfKxfuzj/1/W8qJnyq MXAmHszr8JzGt+uTPHCFFVXRewXJfFcr0epfJbMQqmymGJi6s6FPV6CpbkCQfwemRKUznO yoIKwwRQRmMF28tuUB6ljHFp+5Vw7zA= X-MC-Unique: dUQLGb1hM0OrlGsWxuL0ug-1 X-Mimecast-MFC-AGG-ID: dUQLGb1hM0OrlGsWxuL0ug_1761669241 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761669241; x=1762274041; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xWepIFUxkv0l/eNVnDUu6hPjEIOeUyCJAp9pfFkwuz4=; b=k/UjRNPEXrvriYddjsSiwVBq245BsdmNZwhSMQjltYdSldQ7zJN5rF03c1KilCZ+q1 C1JEwbQJvjDeZyN1zgT2NhdzhYwPTWqr/wQSVQc1QfH56oHhaYsp/Kkexgibd2ZVoOVR vthuDBIWwul1uj6sxT0jyZo2id/qvZYm2Y3e9iLdAS/O4z/hMpL1gvyrisyfhMCzxmPl +v+Y8LN0X1jpHxPabFl+nVGjjhnqg5knweh6Tc3Svd+tY+TlttWG30Anzu3nvmN3vGsa ucJoQ+lR0eXQtA3TeK9xulpFZbf5TqNVlNpim+w9m+xnuwv4NNVvw3QbJM7YvIPt2zHl ztmw== X-Gm-Message-State: AOJu0Yx7tduX1M61X17qzT/yKQAFhQlmCgojH4MouLDxKrejxwBxsx8b jfDLmX4LcnCodVcbmGTAajyjIgm8jboxTnrG5ss3VQbqPEPpBnUKV9GJGC6I7bYjNI5m5EuCa9o DHC2afztkIdcGOeCD8Mz42f0YMu1lrB70xWWAUsfq9FqAVFA1HpxdKO4Q X-Gm-Gg: ASbGncvkS3LODO4rD9gRq9hdzq12mNTWv3p2IeaBPQq2xn/b6I72ZspoeN4ddQNgdt0 kbpXgj5JdulYDTg/NAoH83Z2GwvzwvupBvakeUTh1JIva3O0AiVDdhb7Op6nAIQAEw+XdYuKYgT ghvjXtnwyr5YqFmEFLMSK+lhPTXONRuCqVPF7oQF+3B2CvxQ3Ono18hXuP3hzGduBxzi32332qA Hc+e+KEhQj9ByCyVTRuDuFYJj2oxB5zVecZIBroX8TN5T4vmtLDapxkF+CVZHC+zE3ir7TIm1sH utYjNfHZ9aT5nrHTKQY5GGcUY1eBwWsoYkQrREaJ5KEjA0vncViQnrPFoi4SxJBiToSHFHiY3Qf GK3QWLi3u3VtYJDlgDVskycV6OhuMVK3AiDQanntzdGQqO2W4PD40Yc6XhA== X-Received: by 2002:a05:6000:2303:b0:427:8fe:435f with SMTP id ffacd0b85a97d-429a7e96d76mr3624229f8f.57.1761669241074; Tue, 28 Oct 2025 09:34:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH2P6ULcQLL83cnpmkwsziXSisvEEEBUyPGQtbIVoYiNiFnfWmA4b2yaG334qLpXdEDURwrsA== X-Received: by 2002:a05:6000:2303:b0:427:8fe:435f with SMTP id ffacd0b85a97d-429a7e96d76mr3624192f8f.57.1761669240665; Tue, 28 Oct 2025 09:34:00 -0700 (PDT) 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 04/16] =?UTF-8?q?nfs:=20Run=20co=20BH=20CB=20in=20the=20co?= =?UTF-8?q?routine=E2=80=99s=20AioContext?= Date: Tue, 28 Oct 2025 17:33:30 +0100 Message-ID: <20251028163343.116249-5-hreitz@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251028163343.116249-1-hreitz@redhat.com> References: <20251028163343.116249-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: 1761669358600158500 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, and we could just run aio_co_wake() directly from nfs_co_generic_cb(). Like in iscsi, we don=E2=80=99t do that= , so as to keep the replay_bh_schedule_oneshot_event(), but we should at least run the BH in the coroutine=E2=80=99s context to remove further BH indirection. Cc: qemu-stable@nongnu.org Signed-off-by: Hanna Czenczek --- block/nfs.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/block/nfs.c b/block/nfs.c index 0a7d38db09..4667d49416 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; @@ -233,8 +232,6 @@ static void coroutine_fn nfs_co_init_task(BlockDriverSt= ate *bs, NFSRPC *task) static void nfs_co_generic_bh_cb(void *opaque) { NFSRPC *task =3D opaque; - - task->complete =3D 1; aio_co_wake(task->co); } =20 @@ -256,7 +253,7 @@ nfs_co_generic_cb(int ret, struct nfs_context *nfs, voi= d *data, if (task->ret < 0) { error_report("NFS Error: %s", nfs_get_error(nfs)); } - replay_bh_schedule_oneshot_event(task->client->aio_context, + replay_bh_schedule_oneshot_event(qemu_coroutine_get_aio_context(task->= co), nfs_co_generic_bh_cb, task); } =20 @@ -278,9 +275,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 +323,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 +351,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,7 +714,7 @@ 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, + replay_bh_schedule_oneshot_event(qemu_coroutine_get_aio_context(task->= co), nfs_co_generic_bh_cb, task); } =20 @@ -748,9 +739,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.0 From nobody Fri Nov 14 18:17:44 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=1761669524; cv=none; d=zohomail.com; s=zohoarc; b=WVnY3bax2Q8lEbyCRC/iBGhZYixaiiCgBrVv3gc882heHr2LQBCziOeg6yTgkTtqBlZTvrYJXVpcwN54XkovO0SiIQwzfvfHUUjjc8cMGuNsvgwE4JAaX9qwcBXoH//Uqm8lNc3HR8EHzFVxwny/6mOA6jJpmEka1wzB2oThgX0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761669524; 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=eLJdOJSUssWGwBsyDBm1U43bSPC0FcgCsDPLVbyx2Ps=; b=WfC0R0Gbm0wFY0bPmqDkfhev6mB8GCy+0J1RVLofvF7tanwWUSIuZETjB/2Jg5aUAxCU+HZTNbiOci1NNYSSr4OBIq3CAYd0L2vy72u8/FwobF/AGW5yC+K/U3ROxowROKAYLmWP647T4Qq2vHaOqm+cs4PhvBlLMqT4g1cGGzE= 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 1761669524450816.8677818722921; Tue, 28 Oct 2025 09:38:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDmeb-0008Ds-DT; Tue, 28 Oct 2025 12:34:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDmeI-00084b-G2 for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:19 -0400 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 1vDmeB-0003Yv-9I for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:18 -0400 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-118-miq4GeeLN6KAAvW4-MPLcg-1; Tue, 28 Oct 2025 12:34:06 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-477171bbf51so6378845e9.3 for ; Tue, 28 Oct 2025 09:34:05 -0700 (PDT) Received: from localhost (p200300cfd7171feeff88afa910cb665f.dip0.t-ipconnect.de. [2003:cf:d717:1fee:ff88:afa9:10cb:665f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4771843eabfsm23986055e9.2.2025.10.28.09.34.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 09:34:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761669247; 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=eLJdOJSUssWGwBsyDBm1U43bSPC0FcgCsDPLVbyx2Ps=; b=VOJjSVJA691hqW2p2jtpiXJSVHJYUmFIFE32k6w2EHYzx3P5J6rJ/3mk/co9GGLu8QT6nY DE0AS2kh/6kLqX2d7MRTRRvvpP0u2j2Pxxb0m7nWqzYgz51X+mhCbARy3NNYCF7WeqXuF1 Tcb80BgB9YXWaW6tralmTtg7MKxrPZ8= X-MC-Unique: miq4GeeLN6KAAvW4-MPLcg-1 X-Mimecast-MFC-AGG-ID: miq4GeeLN6KAAvW4-MPLcg_1761669245 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761669245; x=1762274045; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eLJdOJSUssWGwBsyDBm1U43bSPC0FcgCsDPLVbyx2Ps=; b=ZASpx+7ouLcRA3fsbUjmDCNt+mVwVxIHuYBAwTMX21okKmr8FrSWl5/EXY4qmnPbAx jodWGpj35MEEsnBH45PsDoZkcAq4cSXgw0TMHe+snyTa6SFZyTO6qZlJrZNIExhrhdEI GNTYrv9IyLaWjPKqPfomaKWRdsQu9NJYlXqTtIM4m4+bTQ9IQw/4QcsJ5pP2FSsprEw6 EYph1d7XhGLCWLIgpU4vn5fpC4oqm/HzxO0KOSKdJfhGcPQE9K6No6CVYxjTnpOTOIbA 7z50L5h7p1UEIem+wo1DN6PMu00TYeZ7W0LPflc7Zrx7VvODndT64Sgbz7M4bVSPK317 Mvew== X-Gm-Message-State: AOJu0YwDeVUy4B6TgSxg83Yrvygh6aJSfO4yM/1sZbljazEUDU+2MxUR +lU6qR8TvzIc6oiBrv5gGxkeduvlq6xLJALtLRg4C4rs+Tn2KzagKuWPRiftFQDjR3MTOVM5qJW 21foX9rigin2PLh3pxWblP0cFfJC8GLdS1S46lGwsVBcQdKuWkgzNO6G2 X-Gm-Gg: ASbGncs/66Adz269OM/8Vc4aTHvHA1Ns+fuii1rQJuDZUd0EpuWvhENwDroAF0vjRnF MfYBgEhyajaT1qJodUYOgiLYFrFN56P4SuW4kFSJsLZ00LSMixhLnkw6Cdy+DEph0e2xNB7+Xay plTLUUcZGgP+g+gGa9D2+c4RVhbSbZY2dMqzUYkSrLknvLEYFeSLoAwnxXrM4VAo/NEIVmcc5Zu vTPJdlSMQ2ofYVyyfCvLvDnaGeny1OxspC1XbC2svnvE+YQIY3eBfUe9/2swee+r5W9sjiyuYnV X/cYvb3HVoc3QICFbD8XfVPJ9lKUG4kembhqWfQuZCOcQMswiZvAOYKqXX5y0oqCfPiaWJhWRoc pXuPy+3aY1gJW9cIgazFugO2E3IoeVnArhj2uVrAX25x73BT0Z7eS8M8/EQ== X-Received: by 2002:a05:600c:5197:b0:477:1be1:9afe with SMTP id 5b1f17b1804b1-4771e180d92mr1010945e9.9.1761669244548; Tue, 28 Oct 2025 09:34:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHOcMewunCj8cVxj/IW7iuNFMakC0UnB92LOjFdg0o3aFT95YE1qnQx00MZztGgwfwdelYyNQ== X-Received: by 2002:a05:600c:5197:b0:477:1be1:9afe with SMTP id 5b1f17b1804b1-4771e180d92mr1010515e9.9.1761669243976; Tue, 28 Oct 2025 09:34:03 -0700 (PDT) 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 05/16] curl: Fix coroutine waking Date: Tue, 28 Oct 2025 17:33:31 +0100 Message-ID: <20251028163343.116249-6-hreitz@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251028163343.116249-1-hreitz@redhat.com> References: <20251028163343.116249-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: 1761669538625158500 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, drop the loop and just yield exactly once, unless the request is served from the cache or failed before it was submitted =E2=80=93 that last part m= akes it a bit complicated, as the result of curl_find_buf() now needs to be a tristate. (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 | 55 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/block/curl.c b/block/curl.c index 68cf83ce55..65996a8866 100644 --- a/block/curl.c +++ b/block/curl.c @@ -124,6 +124,16 @@ typedef struct BDRVCURLState { char *proxypassword; } BDRVCURLState; =20 +/** Possible result states of curl_find_buf() */ +typedef enum { + /* No buffer found, need to create new request */ + CURL_NO_BUF_FOUND, + /* Buffer found, request filled and done */ + CURL_REQUEST_FILLED, + /* Ongoing request found, need to yield */ + CURL_REQUEST_ONGOING, +} CURLFindBufResult; + static void curl_clean_state(CURLState *s); static void curl_multi_do(void *arg); =20 @@ -258,8 +268,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 CURLFindBufResult curl_find_buf(BDRVCURLState *s, uint64_t start, + uint64_t len, CURLAIOCB *acb) { int i; uint64_t end =3D start + len; @@ -289,7 +299,7 @@ static bool curl_find_buf(BDRVCURLState *s, uint64_t st= art, uint64_t len, qemu_iovec_memset(acb->qiov, clamped_len, 0, len - clamped= _len); } acb->ret =3D 0; - return true; + return CURL_REQUEST_FILLED; } =20 // Wait for unfinished chunks @@ -307,13 +317,13 @@ static bool curl_find_buf(BDRVCURLState *s, uint64_t = start, uint64_t len, for (j=3D0; jacb[j]) { state->acb[j] =3D acb; - return true; + return CURL_REQUEST_ONGOING; } } } } =20 - return false; + return CURL_NO_BUF_FOUND; } =20 /* Called with s->mutex held. */ @@ -378,6 +388,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 +888,8 @@ out_noclean: return -EINVAL; } =20 -static void coroutine_fn curl_setup_preadv(BlockDriverState *bs, CURLAIOCB= *acb) +/* Return whether a request was submitted that requires yielding */ +static bool coroutine_fn curl_setup_preadv(BlockDriverState *bs, CURLAIOCB= *acb) { CURLState *state; int running; @@ -877,13 +898,15 @@ static void coroutine_fn curl_setup_preadv(BlockDrive= rState *bs, CURLAIOCB *acb) =20 uint64_t start =3D acb->offset; uint64_t end; + CURLFindBufResult find_buf_res; =20 - qemu_mutex_lock(&s->mutex); + QEMU_LOCK_GUARD(&s->mutex); =20 // In case we have the requested data already (e.g. read-ahead), // we can just call the callback and be done. - if (curl_find_buf(s, start, acb->bytes, acb)) { - goto out; + find_buf_res =3D curl_find_buf(s, start, acb->bytes, acb); + if (find_buf_res !=3D CURL_NO_BUF_FOUND) { + return find_buf_res =3D=3D CURL_REQUEST_ONGOING; } =20 // No cache found, so let's start a new request @@ -898,7 +921,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; + return false; } =20 acb->start =3D 0; @@ -913,7 +936,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; + return false; } state->acb[0] =3D acb; =20 @@ -925,14 +948,12 @@ static void coroutine_fn curl_setup_preadv(BlockDrive= rState *bs, CURLAIOCB *acb) acb->ret =3D -EIO; =20 curl_clean_state(state); - goto out; + return false; } =20 /* Tell curl it needs to kick things off */ curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running); - -out: - qemu_mutex_unlock(&s->mutex); + return true; } =20 static int coroutine_fn curl_co_preadv(BlockDriverState *bs, @@ -941,14 +962,12 @@ static int coroutine_fn curl_co_preadv(BlockDriverSta= te *bs, { CURLAIOCB acb =3D { .co =3D qemu_coroutine_self(), - .ret =3D -EINPROGRESS, .qiov =3D qiov, .offset =3D offset, .bytes =3D bytes }; =20 - curl_setup_preadv(bs, &acb); - while (acb.ret =3D=3D -EINPROGRESS) { + if (curl_setup_preadv(bs, &acb)) { qemu_coroutine_yield(); } return acb.ret; --=20 2.51.0 From nobody Fri Nov 14 18:17:44 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=1761669367; cv=none; d=zohomail.com; s=zohoarc; b=aimZGjtYt0lZKpqI3K7O8Bn2PuKiPVe7cT4LSOekFK5lSmZmHybKm+L1ksquXDkoT8gqJoE7CEsQD67WY8F8XoJC3GBLYIvOKoW6PtAWYsDKXYH2dcJDiSA83tDJNaFQzV8qfgUxq8w+05oNsvAspKdgmghSoninJqcJCDpDxTs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761669367; 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=bHq9mmLlrYs9rcZFc5mEPJ7OIilm7sukDYP8D9Whs5g=; b=MugC52FFqd5TNO9qYS5RoQ0mAxmqCMMaqSEIexFJU60vXBNw92CYZ1rbuncslFEsrkLCO/X5VIq2Ph5OYnJeoBVBNXFEtsWvNljGK3+HjMPdpN7gYkFUCj5pIZFIPxsS5A5053IfeZMiau4zZWIyobDN9d7uuA++BsRw8kj4k60= 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 1761669367043688.4512615569935; Tue, 28 Oct 2025 09:36:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDmec-0008EJ-Vp; Tue, 28 Oct 2025 12:34:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDmeK-00085x-FF for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:24 -0400 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 1vDmeD-0003ap-9h for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:19 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-112-lA01VmRHPA2PdcMlJczPGQ-1; Tue, 28 Oct 2025 12:34:09 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4770dea2551so64727835e9.0 for ; Tue, 28 Oct 2025 09:34:09 -0700 (PDT) Received: from localhost (p200300cfd7171feeff88afa910cb665f.dip0.t-ipconnect.de. [2003:cf:d717:1fee:ff88:afa9:10cb:665f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4771904fc1bsm22117125e9.11.2025.10.28.09.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 09:34:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761669251; 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=bHq9mmLlrYs9rcZFc5mEPJ7OIilm7sukDYP8D9Whs5g=; b=UZfJYUQpEorIsiyakVZO0v4x0vWcXSPhyY7aqiztxUpnTz5i0TyXboG2knV+mzFqrCYRxi 08ZgacYUZ75HuQ5178vl2em6XRJP/wwXjfgr4BHnSwbP8ghjw2dRSTpxWSoN2Ua04MRghH ZyjTsBWQDcuaOA5nNPDKgnEs3t5DIwo= X-MC-Unique: lA01VmRHPA2PdcMlJczPGQ-1 X-Mimecast-MFC-AGG-ID: lA01VmRHPA2PdcMlJczPGQ_1761669248 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761669248; x=1762274048; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bHq9mmLlrYs9rcZFc5mEPJ7OIilm7sukDYP8D9Whs5g=; b=t1c9HwLD6OGwpxOfEw+1JwDBRAAOAsH47NeiCZSgU33v54PbUek2gTXNP3iEqoOoQU 3THr7kgrdtqTOITFLjJOozqoShwg9HdDugmm4yY1Onwq8CwLoHc85gYBSmoEY/uNMEDd 4TXQ3YaDDqZ0Mfk/Fc2i50yuAS9qcQB/hlPId2B0fQXeYoIDM8So/0Vu6dGwv/0Vng+p /d6Eu+2FQUBqFjrh0dhaSw0LSjpp8IV4MOgFcmltyFa8yF50g3z4QW75cVc3qjYQamRl il0571EM8okqko8FxUeylgkIyBvAeeMVSI0ZgSVjE5T+Bp68riazDhWhWg0o+CYifOs2 ciBw== X-Gm-Message-State: AOJu0Yw2bz3Cdq9uyHP9LSh180EQqZMJAdEqt1jpDTrQ237Gj7tHI4co 03HVkn+F45/Kxix3kpCPHAFJHWgUfdmJEUM8VNND8jQ5d28YMKPtgySsDsChrKgZZeBXg66EpEd 192GeU5sl8hQzK8JdmIywONbCNDTPjhTsBbtALjRThPFsrw/bjDJhaDTT X-Gm-Gg: ASbGncvCoEYlUzgD5jZzcwv8oJiSdoJZrUnzbb/ndiEOYV2922Rl7qd8/hSFpIcxpuy WKMJAnjtOnEAwyLpX13IOIcVV4lxgjVMwdUXfY7VdeB4l49JCGo4NFAgv0g96LPCT0KwOdr5S4K uF01TNyINwG++eDkY/sLNYSyyzYaIOVGrFlbM2YTA14guiwu2fEppryiS3i7CqeSENmUnOmXgnC 2vcydOtfopGoM0k9zdOClALI254oZj4wYIwmW/ZK3Vv383glQo5N89mMJRVKOyrNRua7Q4qNdPG rPpRavigWh2rf/EbANRxDAKrkz7iq0YtjVV0xzF581PE6L9NhlfBAKzfI3+pn7hCzDyCM6hfyJO tKs1ebSBJHMuIMKuoN2kUjEI2v3e/zlJThEhnNZOvu52SeRUaaAMtgIaISg== X-Received: by 2002:a05:600c:4ec8:b0:477:1af2:f40a with SMTP id 5b1f17b1804b1-4771e18d791mr1188445e9.17.1761669247971; Tue, 28 Oct 2025 09:34:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFScE3eHeyARGVLAKjMGFdU+ElWS1sPV1QuWOU4oXxhPd5Src8DwUHVXB9YzJdUAGOEiG4ByA== X-Received: by 2002:a05:600c:4ec8:b0:477:1af2:f40a with SMTP id 5b1f17b1804b1-4771e18d791mr1188105e9.17.1761669247478; Tue, 28 Oct 2025 09:34:07 -0700 (PDT) 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 06/16] gluster: Do not move coroutine into BDS context Date: Tue, 28 Oct 2025 17:33:32 +0100 Message-ID: <20251028163343.116249-7-hreitz@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251028163343.116249-1-hreitz@redhat.com> References: <20251028163343.116249-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: 1761669368976154100 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, which feels wrong, but I=E2=80=99m not = sure whether it can actually produce hard bugs. I=E2=80=99ll leave it to others=E2=80=99 opinions whether to keep or drop t= his patch under these circumstances. 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.0 From nobody Fri Nov 14 18:17:44 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=1761669475; cv=none; d=zohomail.com; s=zohoarc; b=WezHLNPXYYYx95bkAMVDtVrlAHmY0c8dYSS8bYDHdGLd4feUUi//68+vOtUbbH6cg4xbCEFOTculeRfqC8acT7KTYu/S38KFpIioMjWzZ0+am85gznY5163rMqciXXPFQpveCbY2yGEhQXHHNX6lwHY+Y3lkr5LhoWxyKJTghYc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761669475; 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=tSxoatfzMDx1FQebyVCdNFm5edJW1MYIL+ghwwVgSOQ=; b=X/f/3MzxT5H0LLkcq7ad43+kgT9le3au8fKmcLiY0e19KOaKuy3nJLsdUqiVcezSHV03U7OqZIL39ZqYv1SrxB1kODNfYoPuFyR9Oqn2rYdVnZMd+0STd/mi9l/v6TJ3UxYVTkf9SQjpNjiQ/Btk/gr0RiPBymktNiw3ho5y4xU= 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 1761669475287787.4127096908555; Tue, 28 Oct 2025 09:37:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDmee-0008Ft-9g; Tue, 28 Oct 2025 12:34:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDmeJ-00085N-NW for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:24 -0400 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 1vDmeE-0003cw-Ol for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:19 -0400 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-270-0KjXFGZZOiuKF8KhynkSow-1; Tue, 28 Oct 2025 12:34:11 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-426ce339084so5874113f8f.0 for ; Tue, 28 Oct 2025 09:34:11 -0700 (PDT) Received: from localhost (p200300cfd7171feeff88afa910cb665f.dip0.t-ipconnect.de. [2003:cf:d717:1fee:ff88:afa9:10cb:665f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-429952d5768sm21837119f8f.24.2025.10.28.09.34.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 09:34:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761669253; 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=tSxoatfzMDx1FQebyVCdNFm5edJW1MYIL+ghwwVgSOQ=; b=BIE8iGJG5cyS8DoF3bE89oQ2nXDkB+ixA9voyP+7Fvh5+yhzZrENRAVcpyHEp2L4rnr29b nb8ZRiwk+JO9qRq63wUylipPb0Yk3AedQg9ypDFvXi8Rw+N0KHk5UER+5WMXUi49mz2lNs /SGf4G/i3Js6nmitSmIzX5uQoVLfyC8= X-MC-Unique: 0KjXFGZZOiuKF8KhynkSow-1 X-Mimecast-MFC-AGG-ID: 0KjXFGZZOiuKF8KhynkSow_1761669251 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761669251; x=1762274051; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tSxoatfzMDx1FQebyVCdNFm5edJW1MYIL+ghwwVgSOQ=; b=TmIYIsgCaLvqIn7DcJccnsQ61KZG49Ss3wFfnzYdS5bm0kYbG/T54+mV7UKQmEoFQM GNUZF0DRAhr4q1KPvLLI0NZzI2BCZcjHU/wuMgovDZjpDyD6uFvnJ61BGgebnl0aLxMe 2JiY4yfGb7DJGjMHR+/zjt7T4tpz/Ii0KWgNe1JtS8VuEnG6seJilVGjaT+QhzqgHLl3 ipXnIkgBi/DC+IkHS7lXu2LSvBrjr5toI2CX5adyFD5glqWUae4yjNj/73nBIg3+w4Fo Vi1MN8aVWvxk70PVJQL9snyzwcVqCItONjGCz5u8hLgGzAhpQ13ImBRGgrHiIXUKLCOA +xhw== X-Gm-Message-State: AOJu0YwpBmzGyo0TW0H0cFgON9/9SasXYvHYOY22PQz/u2QZiUCb6zYS wpaEH+rvi+DwD73257ztoY/a5ltEDhUaC8RlH9AcBhII3fNdFPu0MFitX4vOhPMeYP15GFnBpQA xOYkFPLgAVvqyQkTRCWQmH81UtVEFeiFyPcLKA8eJyokcLCh9frP+4Tep X-Gm-Gg: ASbGncuDOy6p3z7OlDM29pIJ2HImd2sGWPCVem1TL0tHBjcnQV0WW4ftWe15Mvq5RaE hBm2XcEz2FU1+ai14zjEIENaRGst7fpp5GxtbJLAEiu9Q5L/NVnd8P8U9Gs9gGezvo/gYEN3+Wt rGhXIn1dLXGhnosyGqRWfaemv69P2p7Wpcz/erEnXRjXOYl1ZblXMBpy+kd4IihJYPdJ827LrRk wtyH5Tl1DEqN3+Nwj3qTaBof+Oz631lsGpFgNj1omsc5+DsplC6GQ6QKv9+uOmWJZFI6JYRxX6Y UzdAK+RMkjzBzV64d/dNDktxVqEUg+iT8MOOIhjPgTsJc+UGaSjZv4FlTt8F53H7o+RtHZoZxTT JyND6MB6EqBuKFJzSYKgRP1vzokK2Fy7/hzjGe1sVQxyuw86HrPgxVTid9A== X-Received: by 2002:a05:6000:2203:b0:428:4004:8241 with SMTP id ffacd0b85a97d-429a7e7a0cfmr3969482f8f.40.1761669250659; Tue, 28 Oct 2025 09:34:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE2+ewm7VHCtLLYz9cH7gOPSYYbQqSCMh7D7394XVxx5QepaxmUdddXXKSFR9JTD7DTITjuSQ== X-Received: by 2002:a05:6000:2203:b0:428:4004:8241 with SMTP id ffacd0b85a97d-429a7e7a0cfmr3969446f8f.40.1761669250205; Tue, 28 Oct 2025 09:34:10 -0700 (PDT) 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 07/16] nvme: Kick and check completions in BDS context Date: Tue, 28 Oct 2025 17:33:33 +0100 Message-ID: <20251028163343.116249-8-hreitz@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251028163343.116249-1-hreitz@redhat.com> References: <20251028163343.116249-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: 1761669478018154100 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.0 From nobody Fri Nov 14 18:17:44 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=1761669769; cv=none; d=zohomail.com; s=zohoarc; b=Q4xHm1oWyYZ+1VIgH3Yn38iEXLH6giFCLWAwCjoRdspmn9sRQBF8bBKjiuTx6FwMpC5JVb7jqHTSas/AaTa2R173ZGjOcX+B37cvmy1XlMuiDSp4+4eiVj7dhpiYYSGWjC/gJtOhygE4y3Nyci7VMLIsWwiCbBh4n27KdM+FsJU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761669769; 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=2U80ME5X7xSKjsO4KLvJ1M0GL7cSpjh3xsJvtFdCoFc=; b=EedL73WUzJZd1q+CGEfS05Te+UHTpYCNh/Y3UQBkXxtHOnguj1Wd35BnbASar5laxi2/2WXyM3p2JfVwmT/rKaI31GdaDy+OFTrll6E6aEIMvBVH+3lzSKDne9ZOEPZ493qeXtWTdIsvvUAbJGis2tMa7mIGejrHT6U6XOy6pjQ= 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 1761669769872563.5670940431521; Tue, 28 Oct 2025 09:42:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDmeg-0008Gf-I3; Tue, 28 Oct 2025 12:34:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDmeQ-00087a-7P for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:29 -0400 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 1vDmeK-0003gP-Lb for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:24 -0400 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-26-kG7K8c9RNqWQ0iWL7HGmzw-1; Tue, 28 Oct 2025 12:34:16 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-477171bbf51so6380455e9.3 for ; Tue, 28 Oct 2025 09:34:16 -0700 (PDT) Received: from localhost (p200300cfd7171feeff88afa910cb665f.dip0.t-ipconnect.de. [2003:cf:d717:1fee:ff88:afa9:10cb:665f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-429952e3201sm21260003f8f.47.2025.10.28.09.34.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 09:34:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761669258; 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=2U80ME5X7xSKjsO4KLvJ1M0GL7cSpjh3xsJvtFdCoFc=; b=QV8BT0kLrzjEDUvzjEY8ROwtcDJGYul3k2h6Dg6KX4wPsxgbYnlF+DHMCE15RAycyQettF kYpFu3zTF49cAaaakBLjgXM00pRuUVDVqO6syf9MAoXNSLXLK94XDIb6Nb3KbvdPTia+XL uYQFJ9InlURN1ggLiYhW4eVxZBKmOhw= X-MC-Unique: kG7K8c9RNqWQ0iWL7HGmzw-1 X-Mimecast-MFC-AGG-ID: kG7K8c9RNqWQ0iWL7HGmzw_1761669255 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761669255; x=1762274055; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2U80ME5X7xSKjsO4KLvJ1M0GL7cSpjh3xsJvtFdCoFc=; b=FkysiQUUKuuxjd7VSqPW4R1hLN0kaDw52dGjESWS+wwwF1vl+bN034z7Qb306JRjke fCqpw8rUQRN4BVxfKQXkvTZRE3IWGNV4HNy7Mn7OlfiqRQJCm4duBkfFmERAVj3ThMbC GLVcWNAhOn/5biIooW1yD0N30KSieD2H+D1/fa+N8aD38KrPDubISThLk88N3AEUdfMq CUKAfAHZepVUBcgTLa/6nEhIyxd3FDFe2WFaICTIp01XBVTRAmuBdSZuZnAC748Hn9Rh cIT7X8eChSvHpUTeWx4D3LwEG/pY3vV76OUyX6rgm3wfC4ziWx1Dp7u95ZOVKh2JijGn 2A4Q== X-Gm-Message-State: AOJu0Yy3XsPI66N7i65lCiIDwyPPmknwgewJ98tTnnodYD9xfI9WewQj UOyt/nyPLGZnWThRqHD5r/W2c2rQRlgP63QJqXe4vNbdC1PEiz50bGiCYMyf7FC1awW99NEAKFu auiWfKzE5XGXSwkoMD75gu5YCyhrrrU9y1SzdNo3Tw+4ACljS8GxnRyG1 X-Gm-Gg: ASbGncsWS+uZ+W0OecHRDbewAl7tVk7Dv5J+73leKR4AtzmOqcE48EeN0bO5Stn14No rE3NxKZBDZW3vGFWYJ+UfIgV5KcwdtKQAjXBI3f3wGr0IRwBBoMNsjk3FStxOnuB5ooez6x+Wiz IZRPTckQ5u6ypMesykFeGlXDwQch76Q+kml+Z4gzEyckk3qAqlmS6SEbovntw637SedbdOFp3oX PLM6XTUclQjQIx5Ix2ctNHJskAff9zdGbafaRxySvX0bdabcLDES8ltVWeV3hdJYB77JBWfqV9O dpPXE+UbC38QsZDB6LwV6rJ/UXxgDvpR+CwpukJzCU1GqFUIbcV/TTkwnDXtmpRLVn2QQFNpAqy nMpM88WCKR4/jFR9erHv0RrGh7XqGHEfvdJIuwHR2Musyls3sg22oe+cxdQ== X-Received: by 2002:a05:600c:34d0:b0:46e:41b0:f0cb with SMTP id 5b1f17b1804b1-4771e1cb177mr804425e9.25.1761669254417; Tue, 28 Oct 2025 09:34:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQmkNTSEvC5o3/eBH7QlX9nY4qlj2NbJKwfNhzskrzuXwQP7QV8ynPHtkIfl5f4zuTSbdj7Q== X-Received: by 2002:a05:600c:34d0:b0:46e:41b0:f0cb with SMTP id 5b1f17b1804b1-4771e1cb177mr803925e9.25.1761669253409; Tue, 28 Oct 2025 09:34:13 -0700 (PDT) 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 08/16] nvme: Fix coroutine waking Date: Tue, 28 Oct 2025 17:33:34 +0100 Message-ID: <20251028163343.116249-9-hreitz@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251028163343.116249-1-hreitz@redhat.com> References: <20251028163343.116249-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: 1761669773357158501 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, schedule nvme_rw_cb_bh() in the coroutine AioContext. (Just like in the preceding iscsi and nfs patches, we could drop the trivial nvme_rw_cb_bh() and just use aio_co_wake() directly, but don=E2=80= =99t do that to keep replay_bh_schedule_oneshot_event().) 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, 23 insertions(+), 33 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 7ed5f570bc..4b1f623e7d 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -1176,8 +1176,8 @@ fail: =20 typedef struct { Coroutine *co; + bool skip_yield; int ret; - AioContext *ctx; } NVMeCoData; =20 static void nvme_rw_cb_bh(void *opaque) @@ -1189,12 +1189,22 @@ static void nvme_rw_cb_bh(void *opaque) static void nvme_rw_cb(void *opaque, int ret) { NVMeCoData *data =3D opaque; + AioContext *ctx; + 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 { + ctx =3D qemu_coroutine_get_aio_context(data->co); + replay_bh_schedule_oneshot_event(ctx, nvme_rw_cb_bh, data); } - replay_bh_schedule_oneshot_event(data->ctx, nvme_rw_cb_bh, data); } =20 static coroutine_fn int nvme_co_prw_aligned(BlockDriverState *bs, @@ -1217,10 +1227,7 @@ static coroutine_fn int nvme_co_prw_aligned(BlockDri= verState *bs, .cdw11 =3D cpu_to_le32(((offset >> s->blkshift) >> 32) & 0xFFFFFFF= F), .cdw12 =3D cpu_to_le32(cdw12), }; - NVMeCoData data =3D { - .ctx =3D bdrv_get_aio_context(bs), - .ret =3D -EINPROGRESS, - }; + NVMeCoData data =3D { .co =3D qemu_coroutine_self() }; =20 trace_nvme_prw_aligned(s, is_write, offset, bytes, flags, qiov->niov); assert(s->queue_count > 1); @@ -1235,9 +1242,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 @@ -1332,18 +1337,13 @@ static coroutine_fn int nvme_co_flush(BlockDriverSt= ate *bs) .opcode =3D NVME_CMD_FLUSH, .nsid =3D cpu_to_le32(s->nsid), }; - NVMeCoData data =3D { - .ctx =3D bdrv_get_aio_context(bs), - .ret =3D -EINPROGRESS, - }; + NVMeCoData data =3D { .co =3D qemu_coroutine_self() }; =20 assert(s->queue_count > 1); 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 @@ -1383,10 +1383,7 @@ static coroutine_fn int nvme_co_pwrite_zeroes(BlockD= riverState *bs, .cdw11 =3D cpu_to_le32(((offset >> s->blkshift) >> 32) & 0xFFFFFFF= F), }; =20 - NVMeCoData data =3D { - .ctx =3D bdrv_get_aio_context(bs), - .ret =3D -EINPROGRESS, - }; + NVMeCoData data =3D { .co =3D qemu_coroutine_self() }; =20 if (flags & BDRV_REQ_MAY_UNMAP) { cdw12 |=3D (1 << 25); @@ -1404,9 +1401,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 @@ -1433,10 +1428,7 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriver= State *bs, .cdw11 =3D cpu_to_le32(1 << 2), /*deallocate bit*/ }; =20 - NVMeCoData data =3D { - .ctx =3D bdrv_get_aio_context(bs), - .ret =3D -EINPROGRESS, - }; + NVMeCoData data =3D { .co =3D qemu_coroutine_self() }; =20 if (!s->supports_discard) { return -ENOTSUP; @@ -1479,9 +1471,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.0 From nobody Fri Nov 14 18:17:44 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=1761669631; cv=none; d=zohomail.com; s=zohoarc; b=Aq4NCT0zgTQx9b+NkVY1p9ISKxlNdF2jeVsWUG+NPRmyk62F0KTjCvUQVSU+YrJpuckSINa0HHghsYVShdYiPlguL4XE3oLrR5WBgwL9Lo5Eep1QR5L48pOH+hQ3I1t5n8wPcL1sZM4ZZWMc1RbV5OSSRVMCJRjA6bxK/hupOjI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761669631; 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=H8pa3E2fGggwnU3WGnqZTwjKApxvhV+ccDzx1XffCOw=; b=LchusyFLN5Tx7ICdyMb+ZeItRHYpkpQqbzr27oyebKlGz1q3zHEWOjXzENGkf8wM3W/DgCLV8sNsqVJZU5rgw18cqO9NZTTvMFB1gVW6pR+i6DvJwahasK3ahYgWc33hza0IMqb6+SgTJaOW7glohXS5TSzh0DCNzXFbaMvpUd8= 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 1761669631209188.89605842885805; Tue, 28 Oct 2025 09:40:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDmef-0008GJ-Nv; Tue, 28 Oct 2025 12:34:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDmeP-00087K-5R for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:25 -0400 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 1vDmeL-0003gZ-J8 for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:24 -0400 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-410-zKa9_W6fMEGvHcyB_zqA1A-1; Tue, 28 Oct 2025 12:34:17 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-475dd9906e1so19575125e9.0 for ; Tue, 28 Oct 2025 09:34:16 -0700 (PDT) Received: from localhost (p200300cfd7171feeff88afa910cb665f.dip0.t-ipconnect.de. [2003:cf:d717:1fee:ff88:afa9:10cb:665f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-429952df6b9sm22061204f8f.44.2025.10.28.09.34.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 09:34:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761669258; 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=H8pa3E2fGggwnU3WGnqZTwjKApxvhV+ccDzx1XffCOw=; b=Lu7kuXT9MxZiSZ6f13yYKtrJCPyt04KZnMMWHCxi+PUsKzcLzMnj2k+WQzRKFS7VPMMzSg JAOgRoTKupGw4R3XxK46rfM8iK8eOm9QSAXZV+QuHWP95Rubjc1hAeZrUggzZAAvdTaK9f fviEiJg397cAJkwHq5vIoqCh5GqOzZ4= X-MC-Unique: zKa9_W6fMEGvHcyB_zqA1A-1 X-Mimecast-MFC-AGG-ID: zKa9_W6fMEGvHcyB_zqA1A_1761669256 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761669256; x=1762274056; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H8pa3E2fGggwnU3WGnqZTwjKApxvhV+ccDzx1XffCOw=; b=M/TcE77xSqiSgCKWZCIMII4uNjmLqUwVR1hAHSbMiuWA/4w205qbCFsK1wtDqgIY+V 6CCd7Atn5LeBiFAaMp55MvcxaywaSm+Qqjfap5vr8ftzLFMM1tyn/7cVrHnZpA/4KV6C 3+kp5zJliqo9WrvxwdfzVXMYDZR5ngW57rfM9+DsPEz6FTykQPDehlWvjIgADU2XeSKw FmznmTg7+nS/zd/bOb7S+tKbERpb6hSKUTFCXl8ULYxM7tfQjyKndZRRItOUB+/leQDP PXwuNKajL+B/BhCXRmcAD3OCZ7IxtDYrvCY/2pee0L7/MeO8V5NVa9Y0WCo+cMqIY1z6 Aipw== X-Gm-Message-State: AOJu0YwLvsDoxRoGxM3kTc9ZMiII3igfee/h6tG2cAAkNg0SRPOHfGLw JYP2PXEyk+9DLrgQWx1JTMJ0jQ2Lt/VP8tEgeFE5pp7ODKXM22OfdC7VVjOI/+MnA45urP8l2nu LtKC3+bkyLelmni6M5uQ8KRvkIFfZcZA6cBLEROujcM7BLbPkmJV/SPaK X-Gm-Gg: ASbGncszLUp1tJFyAA19GA5TGdzBGEZbAVRT9Ko6oyqvxIQMP6fUCApHsoXo+l2+su6 siT3lHmEpIMpFBdklHOW99Zr3IZ4yD7zgOvk7HGcnA31H45e7F5q/OnnzSPGuAGmKkskpLGmFFt 4lXhsQzss1NLY5mFcpk76QpY+YF9bnY3uwR7uJkTUl0YzzypF/n9C5Mu0mtsmyohCdSH1hWriSc Uejq974GHzbvlhV8qNsrtJB5Ol1OEXyS6yAAH9Rus79pVkd4xvC3nnv+tAkTOXsnDXUTqX1WkyV MLPfaGvP7f/thUeFFJ1uCd4H2Z2rd/IOz5ztVJj2TyhyRsYX+BrsCYB/e8oJa7rMwhmLwONkVCc aDWtyyYn9l1nvJcbr4DGy4Ubn5PagqnjsCQd7+1mU2yH1wXIehUnG5jhSXg== X-Received: by 2002:a05:600c:190d:b0:475:dd9a:f791 with SMTP id 5b1f17b1804b1-4771e3ab004mr97805e9.28.1761669255806; Tue, 28 Oct 2025 09:34:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFBefty/iKIJFguef+AlhNtGh9Ly7/T4sJ8jGnXLfUY8XY3h5Ld7thGmSEX9B4+wBHB+O88ZA== X-Received: by 2002:a05:600c:190d:b0:475:dd9a:f791 with SMTP id 5b1f17b1804b1-4771e3ab004mr97265e9.28.1761669255430; Tue, 28 Oct 2025 09:34:15 -0700 (PDT) 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 09/16] block/io: Take reqs_lock for tracked_requests Date: Tue, 28 Oct 2025 17:33:35 +0100 Message-ID: <20251028163343.116249-10-hreitz@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251028163343.116249-1-hreitz@redhat.com> References: <20251028163343.116249-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: 1761669637723158500 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 9bd8ba8431..37df1e0253 100644 --- a/block/io.c +++ b/block/io.c @@ -721,11 +721,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.0 From nobody Fri Nov 14 18:17:44 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=1761669358; cv=none; d=zohomail.com; s=zohoarc; b=Y2ALhrufQ25lQAuQQug2IDNTUhRBiioUIVOVNiQj3xxXbe3sKvpwy5H4OakFa1PE4NlYfv8d7BvOEx5SE5gLT/2g4/WBAIZERW7i7+JwXfYTTq7d/EcyFmEb3xrvq8jomOCp8FCLd17dNTMZZt5Rtowp+CG8tBfTt0VC5cNHQNw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761669358; 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=kTGB8gOhueJ3jKj4uM+Nweg0jGwZeEwR9/cdDjlApd8=; b=Y1tjJxd0dG5oKxR3KLjOEM0F6c9MQxtx2bAnkOGHmnxi9sQsjemlRrNy2HETzZzQsrKnBOXECG7c6A/EwleaFXR1Hm6NPTw6krqUotNgrzMbjfrJ55kmTAb5qAocIEbUVxlz6xTvj13dcvpgsF4y82yvPR0czrWaPNLWLsz0t3E= 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 176166935877888.93531429377822; Tue, 28 Oct 2025 09:35:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDmew-0008Vc-Rb; Tue, 28 Oct 2025 12:34:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDmek-0008Hx-CD for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:48 -0400 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 1vDmeX-0003kt-HJ for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:44 -0400 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-453-pTywmqgvPRaMTwbN_sFc5g-1; Tue, 28 Oct 2025 12:34:20 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-4270a61ec48so5277389f8f.1 for ; Tue, 28 Oct 2025 09:34:20 -0700 (PDT) Received: from localhost (p200300cfd7171feeff88afa910cb665f.dip0.t-ipconnect.de. [2003:cf:d717:1fee:ff88:afa9:10cb:665f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-429952b7b22sm20964879f8f.9.2025.10.28.09.34.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 09:34:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761669268; 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=kTGB8gOhueJ3jKj4uM+Nweg0jGwZeEwR9/cdDjlApd8=; b=FHvxDRtvlwpLN0pbJnLAdnTZngEFcdQ+Va3vbP5sabguRswiwL/vlklZ7WjHiJ72AAdooZ gaXUJd9uoZhheb8Oth4LRYhqMMhDyifgDv5HKkjn/3DVCmApTBtSzbcVs20M0CadngiqR0 kxWTAlGFp5Vw4dfX0H3eHybOmGq75mY= X-MC-Unique: pTywmqgvPRaMTwbN_sFc5g-1 X-Mimecast-MFC-AGG-ID: pTywmqgvPRaMTwbN_sFc5g_1761669260 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761669260; x=1762274060; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kTGB8gOhueJ3jKj4uM+Nweg0jGwZeEwR9/cdDjlApd8=; b=TC8gx12v3OulDqiP/NKsDyr5cTLkS0OwAcmKVUzJWCyN/lTcwRRVdOxw+MZnOj/p4R ZohkO8hbGT65XCc73yd7b+ligkw+GxMP7YPEfvjDCp+JKr2LwqMUvL3b8xbxcA6Z7g+H LKmBVP5aeQKm2RDMkHxem2J2rffaWlRVBLrz6+QZ8tXVjZh7n6MIajSqvQj/nvn6kRki 2SHhtFDdlZ/bVdJmE2WJLG0x1YEWU+gohqXJTXqv3kaICbn7hsfXnpilZFpnFQG8mMBk WsH17jltV/YPCVWWe2JCDPsvP8CSg4pKOch8bEQXCE3F4RkVTLCduxiAyFYSvhS3Yv09 I1Eg== X-Gm-Message-State: AOJu0YxEYa1zNrvh2o7uXvM6EY8x4guPstphiw+3PxG1U/oeS7bX4zFq CTxWj2YZeZLEXQcWHmLT6Slmg5ojySP1yCizQ0zrbVXYHy8encCxG5MzQ4wZur02TDiDMgxMw81 2L0DL6P9qXYoltPDBssZgX1UyeOXDjV0Gtn1YN9Jp/bPeO32/jiKddUjF X-Gm-Gg: ASbGncvEXUFMSEyliPUXK0WrkbU/wmU0vTA9TxTs0mKajMke5WhnogOFiVIw5/I8TbF GVUNP+nPMhb1dSttHF27+K2ruswTULNV38bGAd5RvvgG07zS+xrj57OrPAWM5HCJ++CWFDK2/oS ZJwPU1yRuiJXrXGdXrdnLUcKSaWJlnf6TlMqNsHh+8a0pQacK8wEJJmnqkTfZEk6dRrJkB9Bryt mykAVFVso1IKyzhtoBS8V/CY1bQGdXZCkkBvy7oX3Ng7pWqNdBdDvV/VDycS1AKec1fb0oarSRL wFj2m28L5XyidYA0mgkqqSew5kNr9DEUKDhBv+6Jq0cDgaaNSC/UOOwBq2lQF8MEylLkXo4MRkn w4VXqHX94eFKcGfkp124HZI1O/LBjATzNcqZ5XeTs9GLDchAq5FSCqa89dQ== X-Received: by 2002:a5d:5d0a:0:b0:427:813:6a52 with SMTP id ffacd0b85a97d-429a7e70961mr3572700f8f.41.1761669259619; Tue, 28 Oct 2025 09:34:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgiPk4ivQXzTZpUOqP59lyKINIYmn+GCplZZI23RCIrh4aXGl9lu6VQxQU5tAs5CtKaL7ubA== X-Received: by 2002:a5d:5d0a:0:b0:427:813:6a52 with SMTP id ffacd0b85a97d-429a7e70961mr3572667f8f.41.1761669259134; Tue, 28 Oct 2025 09:34:19 -0700 (PDT) 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 10/16] qcow2: Fix cache_clean_timer Date: Tue, 28 Oct 2025 17:33:36 +0100 Message-ID: <20251028163343.116249-11-hreitz@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251028163343.116249-1-hreitz@redhat.com> References: <20251028163343.116249-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: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1761669362839158501 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 CB must enter such a coroutine. As a result, descheduling the timer is no longer a guarantee that the cache-cleaner will not run, because it may now be yielding in qemu_co_mutex_lock(). (Note even now this was only guaranteed for cache_clean_timer_del() callers that run in the BDS (the timer=E2=80=99s) AioContext. For callers running in the main context, the problem may have already existed, though maybe the BQL prevents timers from running in other contexts, I=E2= =80=99m not sure.) 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. (One cleaner idea may be to have a generic way to have timers run coroutines, and to await those when descheduling the timer. But while cleaner, it would also be more complicated, and I don=E2=80=99t think worth= it at this point.) (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 | 1 + block/qcow2.c | 90 ++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 79 insertions(+), 12 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index a9e3481c6e..272d34def1 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -347,6 +347,7 @@ typedef struct BDRVQcow2State { Qcow2Cache *refcount_block_cache; QEMUTimer *cache_clean_timer; unsigned cache_clean_interval; + bool cache_clean_running, cache_clean_polling; =20 QLIST_HEAD(, QCowL2Meta) cluster_allocs; =20 diff --git a/block/qcow2.c b/block/qcow2.c index 4aa9f9e068..ef851794c3 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -835,12 +835,38 @@ static const char *overlap_bool_option_names[QCOW2_OL= _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_co(void *opaque) { BlockDriverState *bs =3D opaque; BDRVQcow2State *s =3D bs->opaque; + + qemu_co_mutex_lock(&s->lock); + if (!s->cache_clean_timer) { + /* cache_clean_timer_del() has been called, skip doing anything */ + goto out; + } qcow2_cache_clean_unused(s->l2_table_cache); qcow2_cache_clean_unused(s->refcount_block_cache); + +out: + qemu_co_mutex_unlock(&s->lock); + qatomic_set(&s->cache_clean_running, false); + if (qatomic_xchg(&s->cache_clean_polling, false)) { + aio_wait_kick(); + } +} + +static void cache_clean_timer_cb(void *opaque) +{ + BlockDriverState *bs =3D opaque; + BDRVQcow2State *s =3D bs->opaque; + Coroutine *co; + + co =3D qemu_coroutine_create(cache_clean_timer_co, bs); + /* cleared in cache_clean_timer_co() */ + qatomic_set(&s->cache_clean_running, true); + qemu_coroutine_enter(co); + timer_mod(s->cache_clean_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + (int64_t) s->cache_clean_interval * 1000); } @@ -867,6 +893,39 @@ static void cache_clean_timer_del(BlockDriverState *bs) } } =20 +/* + * Delete the cache clean timer and await any yet running instance. + * Must be called from the main or BDS AioContext, holding s->lock. + */ +static void coroutine_fn +cache_clean_timer_locked_co_del_and_wait(BlockDriverState *bs) +{ + BDRVQcow2State *s =3D bs->opaque; + IO_OR_GS_CODE(); + cache_clean_timer_del(bs); + if (qatomic_read(&s->cache_clean_running)) { + qemu_co_mutex_unlock(&s->lock); + qatomic_set(&s->cache_clean_polling, true); + BDRV_POLL_WHILE(bs, qatomic_read(&s->cache_clean_running)); + qemu_co_mutex_lock(&s->lock); + } +} + +/* + * 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 cache_clean_timer_del_and_wait(BlockDriverState *bs) +{ + BDRVQcow2State *s =3D bs->opaque; + IO_OR_GS_CODE(); + cache_clean_timer_del(bs); + if (qatomic_read(&s->cache_clean_running)) { + qatomic_set(&s->cache_clean_polling, true); + BDRV_POLL_WHILE(bs, qatomic_read(&s->cache_clean_running)); + } +} + static void qcow2_detach_aio_context(BlockDriverState *bs) { cache_clean_timer_del(bs); @@ -1214,12 +1273,20 @@ 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 + if (s_locked) { + cache_clean_timer_locked_co_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 +1295,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 +1310,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 +1326,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 +1336,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 +1974,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_locked_co_del_and_wait(bs); if (s->l2_table_cache) { qcow2_cache_destroy(s->l2_table_cache); } @@ -2048,7 +2114,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 +2871,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 --=20 2.51.0 From nobody Fri Nov 14 18:17:44 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=1761669435; cv=none; d=zohomail.com; s=zohoarc; b=gWhNmc1Gm1Jx025/aRUFvbCf7W0vt4VoVpr8UwvKV1EXRXfwLgv+E6TpXA62pqzEniuFnZMDysVkJG9rcAQrD9ArhLVOzo8YG4iXg2v2mBV1S6gujEHX4UViPyatJhNYC0qGVUv25SGNEO1KW/Wv4ClYHTXjDKJs7CvuLKVkj0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761669435; 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=y0JjoR5QFLg5Ya/8VWQa0jjW4vk8Vly+iRXL6VOjsbk=; b=oBjbc62Ye1sS3O5AkU5btkPs/NdebxbKYl5DynLcqt4rMWqGpVq2xHg0qo9yeQTmRBE53u95/CBZlvwBerTf+iFseiErEmDYc+JM3lZ8HNmBTRhHgk4ckv+Zob3nJVE3qpAxYZ2Q7+ktpbdsP02i9KPjeg98pM0kG25dPVNkmzk= 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 1761669435828431.38267032279475; Tue, 28 Oct 2025 09:37:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDmew-0008UG-Az; Tue, 28 Oct 2025 12:34:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDmeb-0008Ep-Gw for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:37 -0400 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 1vDmeU-0003kl-Kq for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:37 -0400 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-250-H43xj-ftN-KbUvqBrq4-vg-1; Tue, 28 Oct 2025 12:34:25 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-471001b980eso39603195e9.1 for ; Tue, 28 Oct 2025 09:34:23 -0700 (PDT) Received: from localhost (p200300cfd7171feeff88afa910cb665f.dip0.t-ipconnect.de. [2003:cf:d717:1fee:ff88:afa9:10cb:665f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4771e3ace25sm38805e9.9.2025.10.28.09.34.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 09:34:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761669267; 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=y0JjoR5QFLg5Ya/8VWQa0jjW4vk8Vly+iRXL6VOjsbk=; b=EH5VgDJ/Sb2TA7wZmGC5Q2SwpHtEVfU3lRfqHfUsiXfJvepqZqxSctSp+CUMOCpjCPaUWF 8qSJ4YL6OROQmsurgdocdRp8gIFi8cbzo9v1PffmEcNSw9uDweD9a5o6TT5NOm/m0sx2/0 kUhMhVylVoko6TggWN96mqIOFIe3yGk= X-MC-Unique: H43xj-ftN-KbUvqBrq4-vg-1 X-Mimecast-MFC-AGG-ID: H43xj-ftN-KbUvqBrq4-vg_1761669263 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761669262; x=1762274062; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y0JjoR5QFLg5Ya/8VWQa0jjW4vk8Vly+iRXL6VOjsbk=; b=o8aJLsSQAmnyldB6utGvJ7Y0AuGAmRE09ToqXv7KlHmnXz5o2Mhvj57Q/pILkfIvFb PLedrG34/x/fD5VA9r3Ttj+22CkGR5dakR+jqzW/0cNtwHECv+/Bmz7uNS9i/Nq1YXLY qU4AR5De0b9G5q9xqi58OkgplwD1H92Qh2gZ/CrKNGVOPFB15vDCn7kcSOxKv0P0QFjd tmXQmqS7GeQSOkJtqxOzHnWMwcCIKdKw9/A3Wzmc/G36I+nMVxCamqAEvT44fh3FZDtf J5UnoT/kAKviaPX4d8kXx9Yjnpn7uiJoT/pwUocUdDEs8/JFE7mk27iSVaT8mJHX7Qe4 8CGA== X-Gm-Message-State: AOJu0YwR88L5YMkvcbOcrh+1anhevg9xO9hshhRKINm2IIjwMkDf1jht gXYjm4wQ7Zw3YGiF01q/lU1+/UJ+jHvXmDMAffYZ5ho6OW1xQwkRppCq83KQPnA5cI7/B9xm2NL 5RHOddzA9zG/F6oQmKoUwdWxJbzUAkPpBcZW3Xuhp8hhn/Zk6dWX8bMmH X-Gm-Gg: ASbGncsYjdFcwaA3yehcDFHonQ048rFKjBVvEw5JSioUGISWCBrEtLB5eqY8dPnc1wx naZw9CKd7SVS8JjCq/+7bxNch3yOT6EQzmpc3NVTgkPVxQYN8FZFdhdHZKaxNHce0tyscMgl6Z6 FpB6uYrC5MfyLYvEIFyXLZ83xrvmVsdOT/fStS86ambtemxqc/f1JsA6ZNPzT5w9AZy+yIy9eqb 5AgjoxRWsBK+nmPHjM0SRJMnexeQikUjNjAyT9TXbOu33xTKDtgQiLB3xejkwrFh+aWALme7xT5 0c7AKzGh8Ld4BzWPj0zTaS3KL9fZoQOYVefH90yARbqyacU1ZXRqOlrhzFoh5pR0HFt0+zGh3KX 4CzF4a5VYUNGcoccXF55qazXOrF3ZMukdbFWldWQ1iwz//WbZyOreSWyGsA== X-Received: by 2002:a05:600c:4683:b0:46e:4883:27d with SMTP id 5b1f17b1804b1-4771e3aca51mr69955e9.30.1761669262500; Tue, 28 Oct 2025 09:34:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFsYdEGDyF3r0kYMxsuNQaA3yRv1rRLBfSmdZvKVr5ZxxBBxUOp0Nd2SX0UlHsrbEZGprzyA== X-Received: by 2002:a05:600c:4683:b0:46e:4883:27d with SMTP id 5b1f17b1804b1-4771e3aca51mr69685e9.30.1761669262053; Tue, 28 Oct 2025 09:34:22 -0700 (PDT) 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 11/16] ssh: Run restart_coroutine in current AioContext Date: Tue, 28 Oct 2025 17:33:37 +0100 Message-ID: <20251028163343.116249-12-hreitz@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251028163343.116249-1-hreitz@redhat.com> References: <20251028163343.116249-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, T_SPF_TEMPERROR=0.01 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: 1761669443547158500 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.0 From nobody Fri Nov 14 18:17:44 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=1761669449; cv=none; d=zohomail.com; s=zohoarc; b=YreWAQHut7QuZL/b6JxMyw9HrDG/7Z3Ky6TX5EPOKL6rH+0LERZI/7IfgMtBVkPxWPr9Hnd3a/N8csMF8L6BuJWxbKawE2TpL/TvZdHsJwjK+mfjA2d9z9E1uml//NUO7Kla4LDQ0gLD+TDZRF0zSwXw0LSKcSDl95JdRxpWmJ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761669449; 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=oYlDCqfePfKFAXzhes0Ls7/2EJ45+SPgejhrNbx5E00=; b=b61t7O7vhjwmBqSP1Sf8c8psYVCk2TNVxILIw6a+ZSwCp8fFtdJbcec6PT3mbBRUgn8MPMXqtHbv/n0iYhbr4ZTo8ztI23yQsJxcsJV0+b23+yZmviLyjJbu8MZUnd9z6UwF5IlxLwNELvd1B+ylQjx61Nzyp3539ubW/nT6xZA= 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 1761669449887566.577849926442; Tue, 28 Oct 2025 09:37:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDmem-0008Hp-EL; Tue, 28 Oct 2025 12:34:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDmeh-0008H9-5O for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:43 -0400 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 1vDmeZ-0003l5-Eq for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:42 -0400 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-363-0k-JpHIjNQuukrkB0fo3WA-1; Tue, 28 Oct 2025 12:34:27 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-475db4369b1so27077715e9.3 for ; Tue, 28 Oct 2025 09:34:26 -0700 (PDT) Received: from localhost (p200300cfd7171feeff88afa910cb665f.dip0.t-ipconnect.de. [2003:cf:d717:1fee:ff88:afa9:10cb:665f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4771843eabfsm23992195e9.2.2025.10.28.09.34.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 09:34:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761669270; 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=oYlDCqfePfKFAXzhes0Ls7/2EJ45+SPgejhrNbx5E00=; b=btL1gO72d5ENCuI7ZcHKXF/7E9tR43z6n39fxVlc3m9gNrAAwJvrU6ro6gq41LK5M7HpsU kgDG8QU2eyWQ5A16x0Sa7135/4g0ZReUysBQZrU/25P6lGJYLSrKpFM43fE2hmsHHUx9HZ q3vVXmtOUeUzq11ZRJtCnfOS9jYwZOM= X-MC-Unique: 0k-JpHIjNQuukrkB0fo3WA-1 X-Mimecast-MFC-AGG-ID: 0k-JpHIjNQuukrkB0fo3WA_1761669266 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761669266; x=1762274066; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oYlDCqfePfKFAXzhes0Ls7/2EJ45+SPgejhrNbx5E00=; b=dsJF+7SctdnuIp8P6SrJkWywMA6TFQaynBXjEYO10Wm9VhC1jNNMK+Xf8YFObf5hoH mkryhtHPu+SG2sgNfnTq9cNPAVBjxHfjHLeZmxpPbEiqrctbDJjFa4/oRdiAbQAsOOU8 1tw0mTmUDpHrMGBfS6deIGX5O34tVIq957iUHQDgZybRqz9P4eUEgHuTobugIr3nFLAv r8V9Ia+LKjxJgGXY0cguva2rJ6HE257nZpTyklf8dH0SjhBuqShdKNXXBiKATxAtjOKO Fq5sYSw4AZSNjpDiRu0Ve0q2s88Ou3/oV1xr+WlghmM5Yqig/LrNh9JhamsqVw/SIlvF vuyw== X-Gm-Message-State: AOJu0YwcJkxgPWExq1robxt6vxSoYG4441jfKYO7JCBbYAgWya3CJWAA A4QHi94oFvTjAo8UaMUF23PLQGhjQO38iS6BK4FSbV31MprLIvYNO/yh3DRQP+ZyrOTel92wT9B oY0P2Q51XYjv6aSESnx9aHdaYxOfv0ZpmxQbKDBnBQ5TXjI8QsjFmQNW0 X-Gm-Gg: ASbGncuPkBGhHuJRavfV7PHy5HclAf/YiCon1BIhnozPjBiFUIMOy8RF62Yi/WJJ7Zw rmbO6Czem+/3xv51vJLlryfbOsRd3velulp9FXsr2kaBWdhxBeRt5ILrz+jQY2sIzj/+rT7I8ob 7swK3DkdOMBeJ9iNh4LV6kIBc1OTr0+VlsdqfmXo0gnp4hHrgFDDP9+5bPcfgmBSZnRgxWrKt3j 6pNosTC08L8ynonfWlDzJ2NG2s501649sHwSwzNlek4CB/DbN+ElxJftfrUyTRqRzra7KNKvlwE E5404ndwK+ce4Yck+Y+RiH4ASSXil+ooefHuukKh6XqY84PkISpCOTTZcswHQO3Uxi1bU25mVoB 0TK4iwvGnIcfCF1B18T+XhldXCFci+TP+D3r0/oFnjT1CYvIPyzP2lFKx/Q== X-Received: by 2002:a05:600c:3510:b0:475:da13:257c with SMTP id 5b1f17b1804b1-4771e1f13c5mr663065e9.27.1761669265646; Tue, 28 Oct 2025 09:34:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGhkIvbcR4QbAFi8hx1inKcbX9Ru+1SQW4EkZSduZY4GHBpz6oA7dyde1zZtZnCBkQ/cMYa+g== X-Received: by 2002:a05:600c:3510:b0:475:da13:257c with SMTP id 5b1f17b1804b1-4771e1f13c5mr662855e9.27.1761669265191; Tue, 28 Oct 2025 09:34:25 -0700 (PDT) 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 12/16] =?UTF-8?q?blkreplay:=20Run=20BH=20in=20coroutine?= =?UTF-8?q?=E2=80=99s=20AioContext?= Date: Tue, 28 Oct 2025 17:33:38 +0100 Message-ID: <20251028163343.116249-13-hreitz@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251028163343.116249-1-hreitz@redhat.com> References: <20251028163343.116249-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, T_SPF_TEMPERROR=0.01 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: 1761669455637158500 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.0 From nobody Fri Nov 14 18:17:44 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=1761669365; cv=none; d=zohomail.com; s=zohoarc; b=gqjm0n+8s2USYI2TGyDZeRIh82D/P+bkSsafVkbNTkiSpztjks+BlLbLQjrEDNQQPsud0ZTH02HFD8Am70zyw0Ih2yi7izJFHUmXzAWVUKov0PkFB8ybL49j//Kqr+iZiXQG3zvr34DVNOj9s+dsr6WMkHzeEonoHsuF49ajvO0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761669365; 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=GKOwvkHLUYnigJBYnl941OtlXmHokaK+jt9YcTIOSMc=; b=Npp910R9GJhA5nKstrYuPtpNZH+AHTLJ2rZNPEYwII245lsP0mPO2osuOLxNaiZhEeCEgNXewjDIKYkaY55SSpH6W9MPb/sNTPmLkh2LZr0vjlutQzQwRRIYtFz3SUTqRNtR4AIuA5aHOhgY6shnExhw7/oCw7eNZYfheR0Dd3o= 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 1761669365208955.2594252964827; Tue, 28 Oct 2025 09:36:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDmeh-0008HA-G9; Tue, 28 Oct 2025 12:34:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDmee-0008Fw-NM for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:41 -0400 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 1vDmeY-0003lN-A6 for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:40 -0400 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-614-XsAn8cpDNkSjJtsD5VeHsw-1; Tue, 28 Oct 2025 12:34:29 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-42705afbf19so36172f8f.1 for ; Tue, 28 Oct 2025 09:34:29 -0700 (PDT) Received: from localhost (p200300cfd7171feeff88afa910cb665f.dip0.t-ipconnect.de. [2003:cf:d717:1fee:ff88:afa9:10cb:665f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-429952d5773sm23040414f8f.27.2025.10.28.09.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 09:34:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761669271; 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=GKOwvkHLUYnigJBYnl941OtlXmHokaK+jt9YcTIOSMc=; b=Tkp631uHSFoGMU8BW7dLVd44ZPtsCrnzBWlHBnazfGQCL5oARgBQL7lA8jRfYp0I9N2Mos jC98IaSwU/yueHIjUO8G1Rhhg9ovv1I2pQ/ploZzpvzapREu332EtDzDAltGLy3d6kmKhq 85eypMUBN+r/XvqZurN7+T4LxbUAjvQ= X-MC-Unique: XsAn8cpDNkSjJtsD5VeHsw-1 X-Mimecast-MFC-AGG-ID: XsAn8cpDNkSjJtsD5VeHsw_1761669269 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761669268; x=1762274068; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GKOwvkHLUYnigJBYnl941OtlXmHokaK+jt9YcTIOSMc=; b=pAvAM5Sf29+MirsWpKrPCyZPbXjmaQdP68r6wQ7ClkFmeOduUddiRh/veY/xe2PjmS velAYZ93sN/cMiUsYn+1m40hWiktQvR4kod7l9ZG4MfFYP0XWnf3Ke0gIxWx5xz/75xe V9NbhvBfgR4Gl0uP/CRDY2AfmjNNmoXPpG4WvKwNj4QcXI8E2I8NLgTtmggX1tHSWAyP 0AhcEtHKMwuQFmhR2/z5OvmlOZZ0v0mWH9BdG39SNU63UqsCRq5vVoV6hSxOV4Wcb/2a 2ne62nerc6j4KEAVRA/B2Cvo4Xl25NyE3abbOKISNk2PcLomVlHcJKV2ZGYUvfzy/Uyn Rk0w== X-Gm-Message-State: AOJu0Yxs/EHYGjVYUJIUgYnsyJaoKJnFFjusrd6549hDLcJ0x6gAkxnp ldo198JoyR8GToIkF3WbPtyWspvRPng9Mri0OAb6Ipy6Ry65Z6qGnTga0ute96YzjsILPDidkkE ANCv1zDxB2fe6aM6RaZ9CrhObA6Doj8ggAeHpTv4vM0gP+Yz3YyVF9HTU X-Gm-Gg: ASbGncs2dQwpEGUha7AwPk/E6v9RmKhj8GEd0/ein7PJTc5AD2+YKMxebYpYKTWvzSe Fw71D35A+m08R9W4Z3BOzqTOuB1eigvird/MmE4AQ5Z3ebUs0OOBhWFO4BDTyFqbBvafhPnPJ5S RbvMC+wHig6/UE6AxvsHZt/3lPXZRGRn8WKd8rBWfwNO1ER/dPn4iexP5xcLpQZzZERbGHdjy1T 4HfHgwpDtyVpl8EgKiBCzU7hSHP5vSkLPw35+b7aXQvMVMbkhEke3XhqCwmaCcwBZuBy/0xe1BQ 6RKH6o5Oc9oKrDk1yi+vUovnnnVbAA2Ih95fpDngSK64bn1eHefBwTtjwM7nWl3sastmuzhxREh ZOxIo58fl7tFzES3sQDSIif/yGKb7SXf+DT6y5RUFDs4qZ0ij45BjM9P5rw== X-Received: by 2002:a05:6000:2c09:b0:428:3bf5:b3a3 with SMTP id ffacd0b85a97d-429a81a8479mr2893533f8f.1.1761669268443; Tue, 28 Oct 2025 09:34:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGBFbDG+5hwsnNdhEaoQ2eKmk3Nahb0xzwUB5LQN6en183Vbl+UhHk/vqF+CUXOe+rByFgYfg== X-Received: by 2002:a05:6000:2c09:b0:428:3bf5:b3a3 with SMTP id ffacd0b85a97d-429a81a8479mr2893509f8f.1.1761669267989; Tue, 28 Oct 2025 09:34:27 -0700 (PDT) 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 13/16] block: Note in which AioContext AIO CBs are called Date: Tue, 28 Oct 2025 17:33:39 +0100 Message-ID: <20251028163343.116249-14-hreitz@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251028163343.116249-1-hreitz@redhat.com> References: <20251028163343.116249-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: 1761669368948154100 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 034c0634c8..a584f20aea 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.0 From nobody Fri Nov 14 18:17:44 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=1761669785; cv=none; d=zohomail.com; s=zohoarc; b=aG52Zx//esHkSxYi+1oS/QlNQS0YFrkhfjWph8qycAdwQok8X4lIYgf1wiwJqPLI1plO8ti1+F9C2hmEZNI6EiE7c7G7OPfRg11IUy/3rABhdJHCVvWdHgDbUBHarCwFcj/4PImEP3fn5K6Rg1EBpCHCqx1MaGYiykOiCWL9CFc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761669785; 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=Y7vN7dYOLZeNiNRrf7J0asvJiliVksASXq2s0Nvc4go=; b=SY4Gpj1cJIZ0Q0VVjTx3DfWUIr0Rw7qJFa1jfkvg6dRGMifnsCNDooGIrslNfjFYpaJcPU+yedPEQCQwCXEmP29mT/ciEIIGugWBx8GDDIEvWtYhgSqR+zofxiSR5f1Jvjpb5EQKNvUuwf6ZiRgdH/Se8RLOoRM3nan10dmD7uo= 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 1761669785010622.327486585368; Tue, 28 Oct 2025 09:43:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDmf7-0000Gp-64; Tue, 28 Oct 2025 12:35:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDmem-0008LQ-NL for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:50 -0400 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 1vDmec-0003m2-Sp for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:48 -0400 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-657-P60vn5q8MU2jxtbqBljKoA-1; Tue, 28 Oct 2025 12:34:32 -0400 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-475dabb63f2so15603535e9.3 for ; Tue, 28 Oct 2025 09:34:32 -0700 (PDT) Received: from localhost (p200300cfd7171feeff88afa910cb665f.dip0.t-ipconnect.de. [2003:cf:d717:1fee:ff88:afa9:10cb:665f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4771e39380dsm95705e9.7.2025.10.28.09.34.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 09:34:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761669274; 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=Y7vN7dYOLZeNiNRrf7J0asvJiliVksASXq2s0Nvc4go=; b=cim9FdY211QsVrTCLjxaqv5EbmfyZOVNxYz+jvxxDG6pxxZsvJXQs8+y2bzw+y6/doxQEr p+1fnATNtUpsHN7E9HyWGketqQidn8TgkybcR0xLeXzsP72xewyEN+tAVW9NYim9/y+znG i+ofaTqEsqZCHpkgBtrgw5Ki9lath/s= X-MC-Unique: P60vn5q8MU2jxtbqBljKoA-1 X-Mimecast-MFC-AGG-ID: P60vn5q8MU2jxtbqBljKoA_1761669271 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761669271; x=1762274071; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y7vN7dYOLZeNiNRrf7J0asvJiliVksASXq2s0Nvc4go=; b=vteG4aMgcfRZRF6Nj54ErcLU4/j8LhInUh2MrfZKAkPRXO7aNqplRpKrr6OM8uWOAV BFTiEtOPfdbaBMcZ8w/Ud2I3ADABFaaTTnO52OCnmSdt8OrMrcLJYBStUzxT6oygZT1i toiPIqWXoKbyccWGtQTGWPHeekqouOJrcMClohSs1ktSySibeXaPOAqlQSRA3yPKIfIN yMsckO12uuVv5tWDZoq2OLo7VXQfgH3c9LSOnKjLp1M4SC2aADchNo+16nWejaaoGDWt I8KJdIehMURR4rfowcbIUcM1QJEegxLbiPR3o6X0BUH8vFbEmvzO5mKLUXLKPaZI48Ci JX4w== X-Gm-Message-State: AOJu0YxYrw+Ye+Xjkg0m+6sckDhXDClPhJAL2NP6ovItQ9pRRvSBobdP mWA74yDwYrCtXDP2K03OrEnMVdxwykR9ftXYVvI8C4WhYMVKTbgC+ICde2X/3UEt+OQJRD9zKAr HECIjpizzsrzJvv6XdQWUD0q2S9340reGzcFNVVidp+UttOWSJdXcK5iX X-Gm-Gg: ASbGncsB8jkEC5tNY9yArsdzbbjNX0OG+EJD9UTjmOUZlWHiAmEEvOJ2R2eGjmGi6ZG cdeUuk99W84lGkQCF+HtOzPSqUcpp8fXGsJMkX503tW8SaGH12VRp+PmH8IAIREAWbBVwxNmini mSmDFFzwtACK8YLUSCSc5aRj+4YSjaqZuRzACwdPLjhCO2GIep0k4HrdBKI0NuxtiHCEYgKjYkS Toj/F045FAto9pZDF+eSysGkMmkPD1R1LERJAEkymjcE9hGBcVn4PLM3k58iVjwaVQ5vEaASaZs EvBz4j7xX/EtBov8y9Av/bFzasD+36y607fKV53P3L4s15E1ygTW1KIrA1sy4l+VBb4bY3kTP9h eOPGorKaJCUN/WfFxTQx/xJlUM08439xn639luQu/Op1TJgeIQoPemfkCcA== X-Received: by 2002:a05:600c:310f:b0:475:daba:d03c with SMTP id 5b1f17b1804b1-4771e3339c3mr260715e9.13.1761669271126; Tue, 28 Oct 2025 09:34:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYdxb5RuBi2BxLrhzHud9f3ArSrcaCNYdXmynVY1hNDnIS8dWweyLNA++8eM6eDEVpLgtluA== X-Received: by 2002:a05:600c:310f:b0:475:daba:d03c with SMTP id 5b1f17b1804b1-4771e3339c3mr260425e9.13.1761669270690; Tue, 28 Oct 2025 09:34:30 -0700 (PDT) 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 14/16] iscsi: Create AIO BH in original AioContext Date: Tue, 28 Oct 2025 17:33:40 +0100 Message-ID: <20251028163343.116249-15-hreitz@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251028163343.116249-1-hreitz@redhat.com> References: <20251028163343.116249-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: 1761669787475154100 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 76c15e20ea..fd51aae692 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 @@ -1007,8 +1008,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); } @@ -1025,6 +1025,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.0 From nobody Fri Nov 14 18:17:44 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=1761669380; cv=none; d=zohomail.com; s=zohoarc; b=h9DFFKVfHQbWf+KWmwKzXydA1tHpJBLtXSvTnN0jtdSmlutXr3C9z+4BnKZavvpqvO6Vn3DM4HU2Q3jM9R58P2pbVmUttNnRoA8IeGL5vk0nzR8NPTOGxduVtmxc0OTMBjINrpeCuJskYAvAl0eInlQ7ed12pi6JWgbpcJJidrA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761669380; 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=IkfdsjarwHSxOpg3pQ0lv1QR6fFd3UpdDIRhxBkgC2g=; b=NJbd88zyUnj6+1vFsUN2tWifaiggT5ZQl+qE/wi3zjd94Jzvmi0ikSLzO3e1KgQTOpfhNB6uty8PBhRcVdNt1/wZfcT1yCcX/roOEKP4pWjQXWqE4xzQikCx1FsphR20SjBj9d4jdSID5SNrFdPdAbNEEsEFaafs4zc96tb8qAs= 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 1761669380458544.20025759666; Tue, 28 Oct 2025 09:36:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDmfc-0000da-9X; Tue, 28 Oct 2025 12:35:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDmev-0008Tc-Hn for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:57 -0400 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 1vDmed-0003mi-1Y for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:56 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-679-zUoj0JiIN12SaqQnJzM1eg-1; Tue, 28 Oct 2025 12:34:35 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-47496b3c1dcso47215635e9.3 for ; Tue, 28 Oct 2025 09:34:35 -0700 (PDT) Received: from localhost (p200300cfd7171feeff88afa910cb665f.dip0.t-ipconnect.de. [2003:cf:d717:1fee:ff88:afa9:10cb:665f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4771e3b9994sm11855e9.16.2025.10.28.09.34.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 09:34:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761669277; 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=IkfdsjarwHSxOpg3pQ0lv1QR6fFd3UpdDIRhxBkgC2g=; b=WkIniiy24mwyp2Oo9euf/XV6B6yR5/3qGTAR9a8XBaGdawD3vc+59bIQHqEx+jSO5hyEYu hsNbWMrM9liHpv4d+LdWkW72f03g0aXT2oNVtGtEOAzNmITD7lhdMGs2J8OIjuqwrvVR5Z xPeDbgw1bxmqe/7HoKWPmPZS1qTEXJg= X-MC-Unique: zUoj0JiIN12SaqQnJzM1eg-1 X-Mimecast-MFC-AGG-ID: zUoj0JiIN12SaqQnJzM1eg_1761669274 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761669274; x=1762274074; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IkfdsjarwHSxOpg3pQ0lv1QR6fFd3UpdDIRhxBkgC2g=; b=YoG43DVqjmPLxbgmMRPQFDB4DHah+ZOaeJd8XbeKq2+dKtjnuppVYIle19bzZum1sK PU18XYvXtlAQwLyP8EmZqB8cjIq2rMpZiTYmuaOcdF/eyjWD9NhDLZvcrzhswehoLrxW T2Jt13FJGdcu9dbkc2x2tJ+vpiS90hrKrQ5TH+dhk3uGXd03xEq9Mn80OSYPRgsnUW1H zozS/9rqMhm2OdNyGrvNg60vuX80v/EuietfSStcuWu5pRZMj2VQl40osrHd0pFAmfX4 kVkG1l7a9qTrJ66yyxu58pQ/6WajP/0cysfX640BlOsCoYN9L7VuCuAzK3IlhOO7jXg7 lIyg== X-Gm-Message-State: AOJu0Yx5OQcHE+aPN/8jc4qRHNXn3vcK/mm8MxhBBVJ0Bh8sBk4odZIM zAozIKDq102moaIXYXz20FTu7PQM+bbMcAMmynOLOvFdb1Upi+nDi5OmXMDGciJ+q7bppXgI8rL ObDG62h1IuojUoCvJuAr4ZHdrZhboqPRBCi9ZNxTpsfl/rIpM+AHqUw6s X-Gm-Gg: ASbGnct0yJuSUW5/HDb7FtG0rhw1zv0iXYBb2KiAUPkn9mGsb0ZoeI4xVEQO1f2/5wd 4g6u6uQ8wBHT1W8BUJWtYojWmNw+u1mFXYq/aZiuACVusNBeRFNHQJcZ3Z4xdOdHWuqQsiN5kEb HFZOsx8ix+tUJNQ6hz7rrlVuW6vdXuuttvBZxwZDA+Wb1hkSUMWL6HaPZtw0kvpSNpUyQlt5q8T 40IZLa96XlvOHD+pKVTgHax1pdQcVBXcLiKgH20Xyvw3FhkKOTVtz0lT2nvlb0j/7PQr5jO5J0B 0mYlQURpFqSJxgb/YSYw4vIXsf8kOzARBuxNBYLSrkcj4kvB6P7PYVEk9w8diyKeaYjBFOAR2J1 BmyG11NPvCV+b2WiWGwcfR8MdQAKDbMOReY/jDnYci1TEY0cdkStiFGvH8A== X-Received: by 2002:a05:600c:4ec6:b0:475:df91:ddf0 with SMTP id 5b1f17b1804b1-4771e1f0f49mr760445e9.33.1761669274273; Tue, 28 Oct 2025 09:34:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGzuN+T4OqxC5NpkyDonmtKiOglbvQDKTB5SQJ+NZyiBtDg6FfrRmEe9vMwhtNh7NpzfWhpSA== X-Received: by 2002:a05:600c:4ec6:b0:475:df91:ddf0 with SMTP id 5b1f17b1804b1-4771e1f0f49mr760165e9.33.1761669273803; Tue, 28 Oct 2025 09:34:33 -0700 (PDT) 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 15/16] null-aio: Run CB in original AioContext Date: Tue, 28 Oct 2025 17:33:41 +0100 Message-ID: <20251028163343.116249-16-hreitz@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251028163343.116249-1-hreitz@redhat.com> References: <20251028163343.116249-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_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: 1761669382746158500 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.0 From nobody Fri Nov 14 18:17:44 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=1761669480; cv=none; d=zohomail.com; s=zohoarc; b=I/mgtleHY5uedhn3ng80tScGjtzo90qpyxqNgasdXspmOrqCoPp/z9XtmTHqvDu7vO2sSfx+Tt2/dity5RHU6SGKbbwip0sVtXdkQF5/rpQPpOm/oKpCtDrpQH7Osz9oEni/3U7vokB2fsRHV6pmVSn9fyivsd/ElyOsK/bvY5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761669480; 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=auuHryN5cCB+q/vS4sVe6ErpZM58tUub9h+/jBkDl4o=; b=KQf554CAW5Sjz3oZd2mtS2N424lM4kbdtaXq5f7uWEmbH8n3G50zpvFnO6SBXDy6pu17QJXtRT9jP9vO/F+LXv7QbtLb5uomwD0J3pCMYki25+YLJd4VnvZQRSWv4YZkW7eFtIVL+luzFs3mPxW4ZVpD/d5CtDhj4S5W+iPf//A= 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 1761669480395506.7023896312239; Tue, 28 Oct 2025 09:38:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDmf6-0000Ga-1D; Tue, 28 Oct 2025 12:35:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDmev-0008Ta-GN for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:57 -0400 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 1vDmek-0003nv-Bp for qemu-devel@nongnu.org; Tue, 28 Oct 2025 12:34:55 -0400 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-85-zP-FGVKRMQKnM95r8EfX9g-1; Tue, 28 Oct 2025 12:34:38 -0400 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-427a125c925so3108248f8f.2 for ; Tue, 28 Oct 2025 09:34:38 -0700 (PDT) Received: from localhost (p200300cfd7171feeff88afa910cb665f.dip0.t-ipconnect.de. [2003:cf:d717:1fee:ff88:afa9:10cb:665f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-429952d5768sm21839628f8f.24.2025.10.28.09.34.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 09:34:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761669280; 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=auuHryN5cCB+q/vS4sVe6ErpZM58tUub9h+/jBkDl4o=; b=SAbTQf+z5FJwwyw0YoN+s7p9xj1J4BYsfa3JC2ed8rv08ioeJaHNjIB8eBbxkvz6hdn7b1 a7Hvd2wJanxC99uB9xXIMAq3HG18ihxyb8GEwbUsapEkLQ5LQvf+WAOnNlm1MyC1doiWAK CEPJR1V4pcKidmFGTZCcfDIJCSXxpUg= X-MC-Unique: zP-FGVKRMQKnM95r8EfX9g-1 X-Mimecast-MFC-AGG-ID: zP-FGVKRMQKnM95r8EfX9g_1761669277 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761669277; x=1762274077; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=auuHryN5cCB+q/vS4sVe6ErpZM58tUub9h+/jBkDl4o=; b=edOFOxxAPDiSZwREmlI29TljxjzPpJGQKc1XcwZ+K1nYBXc32W3cj74R7xmvEAzXoy WEbp/4VumdI3uv0eKvFAhD98cvjXvdFmD9TuAPfA03ZEnVDOrR1fJIcFsRwKnSSRqFtq HLhsAr1FjkKKkq7I2c9fc1DZw3KnR20PGJht0eL/ttNZdHx6gtOe0UQPJ0IELNPcclwl VWzPecrHxyS/aqV4dUT6PrZJzbxHmsd2IUVQLGaXHSJNKbBsIof+wr/HOskpXeV3o63e vJL7VHA88UhOPTkmwWDjv2dUQBhYV/VxACtuJdBgBpvqOjyEmjO0Tdft4I0iiE01O3e1 i8rA== X-Gm-Message-State: AOJu0YyP14nLqugRNLPZQ9821I15smjC2hArl/g00525ypslZal/rVoF 27FgQQOTBoD+Ztq2TuoBbQE3AQILwRcIciMLOHVaFHK4m7l1qxooTIwQIeIWKKDlxA9k8eX9blA y/EHgmbD6A5EbREXOeWxuP+ciZQR/7ac7TMymQZx1a8jdziR3tPdFFg7u X-Gm-Gg: ASbGnct1qvH6k1PYCCIweM6f2tHx1HJ4lDTMYtKDNvW2817lgZkbL0yeQSQbcoa5/gY 5woY9WayLfdxCaG5xEwPTdaXgcthYoYcYsA+ClNY4mnlw3bMS554Jaz027nNUerbH9tAsLilqTW sJONbyTb/Yb0nnKLgr0wgH/olXf5trWtvK6p7MP+gE4KOJqCYTy3TqTa9OVcbHUSMpFwuhJghYb a1NKYtA7I9IzpfPjJd503XWlRz8XbWfAsQMVNuvw+amMBZXWPeNCG7HSNxhWeZ3WmMXjLyVjB4e Pjpx5+anW1qzxgiD3Wx5Z8DRkckIWc3fWFWl/QnO1tiP0LL50UVzVhIH3MNUrhTaUM+m62/rJTR tihYjsaI8oZjRob7gtZLc6MeIIixsfzMozvQq2HS4y3PL3uhsCOJq6vId3w== X-Received: by 2002:a05:6000:611:b0:428:4354:aa27 with SMTP id ffacd0b85a97d-429a7e8b8f0mr3494780f8f.46.1761669277238; Tue, 28 Oct 2025 09:34:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGxBVko4PJ83bqeJR0GtHD8wbRPRF1jRxhZEWLxfDqqFxpLVFzUNu6zxK0N8Ne7jjFSBDuisQ== X-Received: by 2002:a05:6000:611:b0:428:4354:aa27 with SMTP id ffacd0b85a97d-429a7e8b8f0mr3494747f8f.46.1761669276828; Tue, 28 Oct 2025 09:34:36 -0700 (PDT) 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 16/16] win32-aio: Run CB in original context Date: Tue, 28 Oct 2025 17:33:42 +0100 Message-ID: <20251028163343.116249-17-hreitz@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251028163343.116249-1-hreitz@redhat.com> References: <20251028163343.116249-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: 1761669488008158500 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.0