From nobody Fri Dec 19 19:38:15 2025 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8817B2FABF8 for ; Thu, 4 Dec 2025 02:48:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764816503; cv=none; b=HIYba9UudJuszJ3XihQGjm5jD86tCy6lCmcfFJzLIVCU/S82zSSfVYK+v06vvHCe2NRaHJfUbCQXlKOZLt+rUQ4js+gCAjXTy7n2hZi8Bxizd9eZap48g2gYfsJT2GENsm7X9im4H70cke9wNkf8kzHa39vGqi2KiKm1gGI8icE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764816503; c=relaxed/simple; bh=JLIdNXPMejF737Jv1xzF5GicNRibkuRDb9iX4pmjoI8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=p0hhXtxWiwWbrS4IzXhKMO7c0/rCa7EJY9MgB9HL6zwlu32VhxkgXkFOaapSTCAlqBGtGuSqgPOpNLn0YErDFwPXpQvAKmuRrcBpOgNF6wnB/y+V87pTB8WXcnDKnyBh8Mb5piD+pTSlcpdJAIbBQWzjCOdxI1EiRngNwV/fwuY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XnTVzxer; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XnTVzxer" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-7d26a7e5639so507942b3a.1 for ; Wed, 03 Dec 2025 18:48:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764816498; x=1765421298; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3B+NwUppxNtx5dO3GeNOAlGv3QVGc2Q+cteUdMRhiTw=; b=XnTVzxergD/1zjfx76F9BSZzo9o/r0VE4vDIgGpatGyKsylXlNTt8/JfEdgckLk/yr hkAFbZxasrhonowS2EDvdXciSVHsxS1pEeEoP8/jsN6c7EPCX8LgKfwHQRs00HoSy2lW l12VjGbzqTnuNwEfsX86Syi2dqwsBOwXG2OkPQ2C7m0Ym3ecytJMD5lRVQzeeZM6WiDF YZ3I4Jkqy2+DnLqyB2X1lej4eHSaRDqc1WxWgmdHns7VwFDY5nktnDDFdGLEaN3S2uln pQUl2mHUkCIasI1iUL6cJgi0HACsN38Yqbt/y36jBJ8IlOtC91rjigv9uWygK4qKoKyr nj9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764816498; x=1765421298; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=3B+NwUppxNtx5dO3GeNOAlGv3QVGc2Q+cteUdMRhiTw=; b=bKyDeHvKmbbIfG6tiINuZBM6MbuB1ziMCiCGv6eF0yk14B6na+EhP5uDc2yJm2LSkD Yn+v5GLH20ZbZ/TmZBrykYC0oWrRcyp4pPoHl5txDm+vUdFT2b2roZ71BKTCyo/5OIm5 vxqHJPu2KpcctuJFNdcMMlS4qVsa+E39NGUnwZwxqsndzADa5FGefOV/a+g4EV8e9t7H yHaCNYGetdHTcZkxfOtJDiYkKGLCA/V9UskQG6zTBTKez3l6tK4BiFfT7el9RYmFQ8bg CIbdiYFXC0hz0hUnhMdY/JGRXEYPDcb7+Ky2the+HTDbPEPQxEJ+yWRMwOJ1H7bEFyfR bSlw== X-Forwarded-Encrypted: i=1; AJvYcCWbt4eIuvlZSvJLAFuyr1CU1z6KeNVTevuFXhZAPlAIMs7XqoXjnH4Mf4ZKYRmZ+WY8ru/pz3J80qHkVQ8=@vger.kernel.org X-Gm-Message-State: AOJu0YxtnEY+iaf1qqo19rkedM/D9B3qOSxilyFDptQTSWuAZ/VCDEV8 qKXbfDbRdAUtI+Y8zeHB1LSq8eYNSWkbW4xAhLJ5xlIkowWRKmjsvAzk X-Gm-Gg: ASbGncv4SGNxBGVz7BuibhlIsrfm3tQO2MZH+FgfdpmzpUB4cgCkeKRpOX71PGfLwLQ wf3YsafYxi3FGYASNsLe7T963tRoZ/e+2u4b/mJLPd/PaWjGWLkt1cELgUh5dIepegyx8EjTu3t I71YmYNY7CVYjPBsy7Ft0+W26/11iDr2KrUPUT2EfcQAHm9PtaaLpj0xVtFWhTHC5kzE43xdnl/ PAa2KJVLzQJC/rmGNUAiGdocwrPnh0enPpN08gHDyVsronOLjN9bAjM62m1eyMsb496qUgVbOIk S2D/Sn614WtQQuLQRYcx8wTNgS2uqYi7YW0ZJ59BO5qp/EVQeBt9hyGI7fITIQoi4Ma1cGrOvEO jTma4VItf8SoQJ9YyED0aYJQwMTzt4D6OfghV/PRcaV1+HRUQBYo3mWgh63msoJTDzNTs3R54Of hEosnR38cDjFV3Clz4A95EyuilRg== X-Google-Smtp-Source: AGHT+IEThN9cBQeL3cXuDOIc1+uCaHf9ep2wDNPFjuh/TeOr5B3FR/bA1QanG4XfS+l/fJbBKZDCrQ== X-Received: by 2002:a05:7022:4595:b0:11d:f441:6c9b with SMTP id a92af1059eb24-11df4417192mr2091918c88.22.1764816497778; Wed, 03 Dec 2025 18:48:17 -0800 (PST) Received: from localhost.localdomain ([104.128.72.41]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-11df76e2f3csm1838847c88.5.2025.12.03.18.48.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Dec 2025 18:48:17 -0800 (PST) From: zhangshida X-Google-Original-From: zhangshida To: Johannes.Thumshirn@wdc.com, hch@infradead.org, agruenba@redhat.com, ming.lei@redhat.com, hsiangkao@linux.alibaba.com, csander@purestorage.com, colyli@fnnas.com Cc: linux-block@vger.kernel.org, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, zhangshida@kylinos.cn, starzhangzsd@gmail.com Subject: [PATCH v5 1/3] bcache: fix improper use of bi_end_io Date: Thu, 4 Dec 2025 10:47:46 +0800 Message-Id: <20251204024748.3052502-2-zhangshida@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20251204024748.3052502-1-zhangshida@kylinos.cn> References: <20251204024748.3052502-1-zhangshida@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Shida Zhang Don't call bio->bi_end_io() directly. Use the bio_endio() helper function instead, which handles completion more safely and uniformly. Suggested-by: Christoph Hellwig Signed-off-by: Shida Zhang Reviewed-by: Christoph Hellwig --- drivers/md/bcache/request.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c index af345dc6fde..82fdea7dea7 100644 --- a/drivers/md/bcache/request.c +++ b/drivers/md/bcache/request.c @@ -1104,7 +1104,7 @@ static void detached_dev_end_io(struct bio *bio) } =20 kfree(ddip); - bio->bi_end_io(bio); + bio_endio(bio); } =20 static void detached_dev_do_request(struct bcache_device *d, struct bio *b= io, @@ -1121,7 +1121,7 @@ static void detached_dev_do_request(struct bcache_dev= ice *d, struct bio *bio, ddip =3D kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO); if (!ddip) { bio->bi_status =3D BLK_STS_RESOURCE; - bio->bi_end_io(bio); + bio_endio(bio); return; } =20 @@ -1136,7 +1136,7 @@ static void detached_dev_do_request(struct bcache_dev= ice *d, struct bio *bio, =20 if ((bio_op(bio) =3D=3D REQ_OP_DISCARD) && !bdev_max_discard_sectors(dc->bdev)) - bio->bi_end_io(bio); + detached_dev_end_io(bio); else submit_bio_noacct(bio); } --=20 2.34.1 From nobody Fri Dec 19 19:38:15 2025 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD0D72FF166 for ; Thu, 4 Dec 2025 02:48:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764816509; cv=none; b=SU2+oVsKh5u5sa61KVbYlQH9joFZfX8Py9vc1j45keX8aZlVkt2T/stJ+KQrt2EbV5wIJlZ3aEvWI05e9zt7Pxwz2LIfsqsJd7FeowbZQ64hVqd+G8YTj3Vu3E3B8Yml7CxTdPD8mGqIIAR1En3fGRekdL6U1HcyiB5RGdMTSYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764816509; c=relaxed/simple; bh=KDrm5Wl7SwMy/FVrOjYy2K/P2b0W6LVDtJkcurNDtq8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Pemu6mJY54Ld5vG7qLbsnGUJjZWcbpnK/rqwtj5NMLq49XBDZmcI5hneeE1F3IEP4mJ/vgVUwSOWN8CkaIN6vwm21Qu/QHJ6IfZtWyKShHlTc4eg1DXDfIRrjg339WAIvXubh1Hi7Ag9oWAwHzQ2bxkSW/MCvHX/vQkRDRAYSr4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lso3dq6X; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lso3dq6X" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-7bb3092e4d7so427033b3a.0 for ; Wed, 03 Dec 2025 18:48:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764816502; x=1765421302; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/NLLZx+mFtUT/k/qGnCVEA9+fBUA5GMxbqrpW9T4NgE=; b=lso3dq6XMltP2n7vWp4NPUbzMAfBgjugOkewORA9IYtCLD0Qm7p3CdpvoETtMh9a+m MBvF8Yj44J5+J63A82m8WTed8Ns0OJvb3ulg1dS8O/y6HXaeRmlf242bY1FHExZo0OMV Htn1K2T3RcTBkWyxFn1PAb0dimTUEfsVMQyoegLDXHKnvehNYaHjYR2bHAcB/I/1+gst urR1i0OWxp8pppG02FU8OoX3e4JUMqYGurXta/+tUadZAKNXYmPzusDBXpqMVW7bKYLl lRyTF7Bx4Sy6Bf674MWmNaPGM3iZS+e5EfojPWCaT6LD9v1gv2U4I7uj/zRpzKG1tjUf IS9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764816502; x=1765421302; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:c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j9LvfaxCWoXMp6WXsu5RSyddB7iIrgjte/j ZheVWE0CUp4rTZRSFpX3UDKN83zg== X-Google-Smtp-Source: AGHT+IGYitTygcS9mzGlf9GhlZLT0eKknjI9LuN1aruThHXctHluTBM9GZL0ssswaZE5KQJhhrzPjA== X-Received: by 2002:a05:7022:fd04:b0:11a:a20a:4413 with SMTP id a92af1059eb24-11df0c3c92emr3346889c88.31.1764816501932; Wed, 03 Dec 2025 18:48:21 -0800 (PST) Received: from localhost.localdomain ([104.128.72.41]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-11df76e2f3csm1838847c88.5.2025.12.03.18.48.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Dec 2025 18:48:21 -0800 (PST) From: zhangshida X-Google-Original-From: zhangshida To: Johannes.Thumshirn@wdc.com, hch@infradead.org, agruenba@redhat.com, ming.lei@redhat.com, hsiangkao@linux.alibaba.com, csander@purestorage.com, colyli@fnnas.com Cc: linux-block@vger.kernel.org, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, zhangshida@kylinos.cn, starzhangzsd@gmail.com Subject: [PATCH v5 2/3] block: prohibit calls to bio_chain_endio Date: Thu, 4 Dec 2025 10:47:47 +0800 Message-Id: <20251204024748.3052502-3-zhangshida@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20251204024748.3052502-1-zhangshida@kylinos.cn> References: <20251204024748.3052502-1-zhangshida@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Shida Zhang Now that all potential callers of bio_chain_endio have been eliminated, completely prohibit any future calls to this function. Suggested-by: Ming Lei Suggested-by: Andreas Gruenbacher Suggested-by: Christoph Hellwig Signed-off-by: Shida Zhang Reviewed-by: Christoph Hellwig --- block/bio.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/bio.c b/block/bio.c index b3a79285c27..cfb751dfcf5 100644 --- a/block/bio.c +++ b/block/bio.c @@ -320,9 +320,13 @@ static struct bio *__bio_chain_endio(struct bio *bio) return parent; } =20 +/** + * This function should only be used as a flag and must never be called. + * If execution reaches here, it indicates a serious programming error. + */ static void bio_chain_endio(struct bio *bio) { - bio_endio(__bio_chain_endio(bio)); + BUG(); } =20 /** --=20 2.34.1 From nobody Fri Dec 19 19:38:15 2025 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60B962FD680 for ; Thu, 4 Dec 2025 02:48:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764816514; cv=none; b=aB35vzH4lpECotwe5RcauFbn9vKR273aSAwhnX0aP+FVdhsDp4kMoN3pF9GzGh0ULiFNjMRaGE3s+L600ZyQmrDhdZEUKnTI+0dJuJNFIuel8OIJXz34c703h90XIXRe+PapiH5sW5JE0bQ/IKt7ktttjMZOEyzG3goS21QuAUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764816514; c=relaxed/simple; bh=GWGqYe6NZTrI9deOI6ejOoQBWm5NR0OgoP9ZCzjXKGw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kCjtS2MqcvyF1pSGPSQHSSpelZDQGZyQTjwsNxPV17+1TD2wDMkDWs8Nyhyy9S1ZM+lRTiSOcmd2HvNvNSxXAEI0qYYo/69McWfuVfHujW/HojzMt7Q4OT8ktVPXeqLJlYQaTHD+NGk0B1bfXiwJQENNbie/2lF2LDFgzK9kpsk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=m1B06UWI; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m1B06UWI" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2956d816c10so5374305ad.1 for ; Wed, 03 Dec 2025 18:48:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764816507; x=1765421307; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ODLAjaeZWmKKDwhHXqzdB6DoouDdnHDHsOcQ2a6RqDY=; b=m1B06UWIUHYuAmSdR3uhDTaDpbqxedM8WF6af2dRS9/R62CHeg01oFYuFoxvDgsuq7 voBeipjgYzcV40KTCF2Qh7Syy29iTSkZHzs1SdGFmGMsusQ/IFqOXEoWLcPrgUWm4T9i A+92ZsFyniEPHedFbSJAR7OpqocbbqByi77fO1hVH9ey5zhVNLd+e9olloTkCkl8gb+9 BmBSlKtjmCQCXJQn3Xw5lBFcFdi9jNzJWJH3N3WnHgjoDI4KBfmXfcaN1nxVMvESiRr0 oGh6xuVih+AXtKIJIf47k4v7UHJqksZT33MwYKA6V2bcRRxdJ9L2Rhxd8yb8p7+IVVfx Kd+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764816507; x=1765421307; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ODLAjaeZWmKKDwhH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Mj7i4HTKVGT woiWpEe8hxQJHsAr9lN6Z+qargcA== X-Google-Smtp-Source: AGHT+IGM6SlIysHbulWdQG8xyoxU4IAcs1YhWt2VJRjAfRnb3Xvrgep+D+UgkBMDQdlNnkJeXkWtsQ== X-Received: by 2002:a05:7022:63aa:b0:11d:f464:38b3 with SMTP id a92af1059eb24-11df4643926mr2045006c88.2.1764816506518; Wed, 03 Dec 2025 18:48:26 -0800 (PST) Received: from localhost.localdomain ([104.128.72.41]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-11df76e2f3csm1838847c88.5.2025.12.03.18.48.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Dec 2025 18:48:26 -0800 (PST) From: zhangshida X-Google-Original-From: zhangshida To: Johannes.Thumshirn@wdc.com, hch@infradead.org, agruenba@redhat.com, ming.lei@redhat.com, hsiangkao@linux.alibaba.com, csander@purestorage.com, colyli@fnnas.com Cc: linux-block@vger.kernel.org, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, zhangshida@kylinos.cn, starzhangzsd@gmail.com, Christoph Hellwig Subject: [PATCH v5 3/3] block: prevent race condition on bi_status in __bio_chain_endio Date: Thu, 4 Dec 2025 10:47:48 +0800 Message-Id: <20251204024748.3052502-4-zhangshida@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20251204024748.3052502-1-zhangshida@kylinos.cn> References: <20251204024748.3052502-1-zhangshida@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Shida Zhang Andreas point out that multiple completions can race setting bi_status. If __bio_chain_endio() is called concurrently from multiple threads accessing the same parent bio, it should use WRITE_ONCE()/READ_ONCE() to access parent->bi_status and avoid data races. On x86 and ARM, these macros compile to the same instruction as a normal write, but they may be required on other architectures to prevent tearing, and to ensure the compiler does not add or remove memory accesses under the assumption that the values are not accessed concurrently. Adopting a cmpxchg approach, as used in other code paths, resolves all these issues, as suggested by Christoph. Suggested-by: Andreas Gruenbacher Suggested-by: Christoph Hellwig Suggested-by: Caleb Sander Mateos Reviewed-by: Christoph Hellwig Signed-off-by: Shida Zhang --- block/bio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/bio.c b/block/bio.c index cfb751dfcf5..51b57f9d8bd 100644 --- a/block/bio.c +++ b/block/bio.c @@ -314,8 +314,9 @@ static struct bio *__bio_chain_endio(struct bio *bio) { struct bio *parent =3D bio->bi_private; =20 - if (bio->bi_status && !parent->bi_status) - parent->bi_status =3D bio->bi_status; + if (bio->bi_status) + cmpxchg(&parent->bi_status, 0, bio->bi_status); + bio_put(bio); return parent; } --=20 2.34.1