From nobody Fri Dec 19 11:46:42 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 D38112C21D4 for ; Sun, 7 Dec 2025 12:21:52 +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=1765110114; cv=none; b=i+BKBHMZLOI68TaiEDtETfqE1h09DgwWf7r0/A3ZjBv556hm58lRDuegskAS4LiqUDBWn1KiLO44lTnD06dzlRcN7Z7/tF7+mJu7AtH1IEN5QpJu9z0xf2/UivscNjAXrA1zbCizI+JR99Wrp3TFce3vtKEBTkVguoV9YekwKvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765110114; c=relaxed/simple; bh=54Xh/j2WhG2Ei4a1qEnIpkmDGonn8ZggrBoCMAcXO3g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bQktSDH8G25FcelRs3zGtEqbUjYYaea/qP9q8Nks2DKZKetd0TCkfR+UhuEOV8TxH/CZvp/Q1UGGni7Y0SxuXGvuIF17Sa8cIECXXRez30uHFJP0IzKU+gyTVOogyhfIef5nQfPPc9EFecOmCzYFji2uJ1R+imlqlKLpgiMJrQ4= 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=lIps9MXg; 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="lIps9MXg" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-29568d93e87so33314735ad.2 for ; Sun, 07 Dec 2025 04:21:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765110112; x=1765714912; 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=i/7vzy1FUoDsUfjpWUzueUpIzsuHBaOImPA4L+Mj+ZI=; b=lIps9MXgArmN91wavXUc49twuZy+fZdUvCItADOejMyZFcw7TxXGTVflAC0WSqz8yK K46EEucCKjjKQgXMDkX8wFF63Flc3R3ycovlyUIe22SSr6NrkjwFEV0JgMxzZ3umKlwp eyHn59khjfHUiY3+axufKMjbF0wl4fG/ZCsO0HW9THHMEYUJNEgiPJ8cTgiYglnQ+Xnw XREz95pgqYBZ5TSeQddJOvdqfpvKMRjN5sK8exIz0P3RBG60iI+K9Q4TREmlU+imLGQU +4OwGhDRhAPQ6uPKdCXeDM47Gmp8cius5zfZdEdGUNYhGikxV08seuV5GRvssIDLS3dX V4Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765110112; x=1765714912; 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=i/7vzy1FUoDsUfjpWUzueUpIzsuHBaOImPA4L+Mj+ZI=; b=aO1znPCsc63W9lFKafeVErQXabi7D1ZlPPcxBnW1zkuuiVA7QFp2FXSxAT5qWhH7kZ 9jHBsNUyHM7OCOzLeYqoQDELi5L5o97gGCjPrwTo0x2oUdsZ1PnR3o7L0e/3FMfnyWFO CsQmeURaZz38g7eI5UPM8GxrLQzZa4Qxkfj+CL0Vd/k2QYCkQe0/bFtfE3ORJNPl0sVb ztalKV+N0RK8BPua2B5CdHaOTIDIxBfmzyOO0L51MHMGFvJ3Ma0Hza0pzfU0T0oj5Cdg /eEhruyB7kdZs2NCZTLMco8n4J0qQchqcUdarNvp1FeFebT0xNhc7Q/35e7srOe8dfPM aA9g== X-Forwarded-Encrypted: i=1; AJvYcCUhdRUyAOwR+xl5P4QYP4yMKxauNLFTZBfdwRhe6fh+IXSHM3cLjm8aQqFYDmM67MGD1lMHX+0J7gbX0co=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+1cObMbm0oIQARYTr+80B/c4SaTJUIMpm5x4Y098nSnvVCsOa VQY9q14It28qwqxHEnaWwdUie/4kIRVt2lwO+NzdEpWH7HihoyJoNW5I X-Gm-Gg: ASbGnctzvnbU2n0fCiISraQrTUEwPR1bj1XkQKJrxXmuUc/XXpPGbF7eGRbdGjzYBZN H6cFFGKtIjSdeSvamGeSrGUmjUqZrHWQr8efxh6IhPIy6NcLe1VT/VRuZu6teUuP7azTzbtTj8Q q2gp6oWXY3FjIs4mtDxKzqQj5NHZLHh4ZqqbF5xTILmx0qETM4QGXeHZ49ou06QRUAfdi/iluhX gouVxD6t1bxwpjBJCNBHzWC6QBYYjXf/covFJ+xaeP7DD9jTexooq5Uo3BXkslOeOQPAMGLXbIm mPedO5zcHPI9a7/bchxL68tEd7VTgtF/n0FftXZ2OrZMcHnsTRBLkDUqEB1aRFJ8gRFlPBq8brx 8G5Pt4BoNcim0GphCXizmNnCgP3coCwGruCVCcPQQBX9U4bwt4OFP3Xrp2NgpFsg44eacUtMnEk +5QcQgmWfzl+U+zAka6t3Sw/hu+Q== X-Google-Smtp-Source: AGHT+IFnUgbCbzWKaHX3DgU1C71Wvw3pYFn2ma/gYdiJLLhx9hJu0uDqdIfBQDxlroW91cHZjfSAcw== X-Received: by 2002:a05:7022:21d:b0:11b:9d52:9102 with SMTP id a92af1059eb24-11e0315b334mr3249541c88.6.1765110111933; Sun, 07 Dec 2025 04:21:51 -0800 (PST) Received: from localhost.localdomain ([104.128.72.41]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-11df76e2f3csm38598822c88.5.2025.12.07.04.21.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Dec 2025 04:21:51 -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 v6 1/3] bcache: fix improper use of bi_end_io Date: Sun, 7 Dec 2025 20:21:24 +0800 Message-Id: <20251207122126.3518192-2-zhangshida@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20251207122126.3518192-1-zhangshida@kylinos.cn> References: <20251207122126.3518192-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 Reviewed-by: Christoph Hellwig Signed-off-by: Shida Zhang --- 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 11:46:42 2025 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 9E0792BE63A for ; Sun, 7 Dec 2025 12:21:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765110118; cv=none; b=oQILlpURzZtCbu4sTxQunZR8Awc3g28mZs0DetySuqj5Rw1NSJFHtEWCklYQ79/OJhvnJsxQuFoTPIDNLFY/yyXyk+fWT6nOHMoSK5rpMdeH+VsrlBhbWV7zF0SdXfgvbOMtXyrt/QmZhN+ZP9+hSOePrC8YuEdYG0hiE3lFG44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765110118; c=relaxed/simple; bh=4CeP8091EqjUK9CskNSlEn27rcVvsb9klIf5F54UFj4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=taCpMoApGenAjiHUzvURy5lcN6ayDaDxPz9+XiBhQavjAv/XDLMpUG4KcAKmaEUs1xdn846HplfKIX6LfhTBVzPImMLuBF40141aM5zKYiNyFVE8m2+jBuMVdUVhCnfqTANA9hTXgPiYYAaAUs6VpXqMospqiepoLy2BYpHqgzA= 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=Zy7D1DXB; arc=none smtp.client-ip=209.85.210.180 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="Zy7D1DXB" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-7e1651ae0d5so2586525b3a.1 for ; Sun, 07 Dec 2025 04:21:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765110116; x=1765714916; 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=FDKxCQi4WubAv8KgzENdDuZ74b0CZmQcA4s08IiUA3A=; b=Zy7D1DXBBrOd+V5D73IJWoEvycklFwPBBKr6XzogyF6jQvf7ceG6VznuaXR/pHC60X KhP6cGgcU0WhaEQejhvkvbajUmWUvJg7VH7bo4BRPCbLsmM5ezWJhSZXC/DKmk7X6Rx0 XG7+MHmqK95TWXjapl6YT9quA78X+FiY6N/fe91yUq/qNUaFX1EMrTbGuI585xYoHWIe B4emYF8X5v7q4+dvPz3Nsvj8LD8H2VhImgYL5Y7IHR44JrjaiD0mSC7ryygOyt8qaZI0 PQ5tgcxOE+Vq6wjDgmiueuyPcKnCOrIptsPu9N58AhKaBn+Pqh8336YMFZ/Qxxxtzpjo R1GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765110116; x=1765714916; 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=FDKxCQi4WubAv8KgzENdDuZ74b0CZmQcA4s08IiUA3A=; b=u4TxcCrba0rOjgfsoiZF8IKaC0vd6K2DNoSeBHhG2hCEVTmF6wkM6KIsEiSFUxhcnA Wc2E8qC5XM51BQLlqYrA3OjyASgVOnD14E2nAHKMv249uuqFySN5s507VYIrkIMOU/sw 93h0rAMQQpfiL6A0LHC+fdPoV+mPHvY79bcR01FPtSWBhlKOUMu8p7j0RnOlxg4bK298 3xGOgJUf0UmKf3btV37HxavihoqFuW+wr2GYZbcRgL0uTaLyxVZoZbTx1hdOBNCUXJhc 4zwjVWuzqpi+AwytbUYBHIqwx92gFU0BdDoZZZhRJehjcb7VThfa2Tza+il7oGwX4bcQ PL0g== X-Forwarded-Encrypted: i=1; AJvYcCV7tMnLOk3+ZrwJJ6/40J17Wex+VJZo2VC36BdC2uR89v6vwjbywNnNMT9u5vpEVrqAqHf+CsOCtHkDkgA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw9UyPNRTx7E2Z1OWdyX5/TqgTp0Bgt7ZJ/ieRtkqUyLChMMsy/ p6I3iwtP/n6DMt1/rcS+VOWrVNm3+nHzVm2z7A3XuQhN9IKN+2g8vo8T X-Gm-Gg: ASbGnctHeZJUMgvvCKv8uIsSGlIJ4xzJOpe2xLs3qCmx96bYGdggWvmaJkEU2j4FVFc 26iaMln+tDuL3GOpPwzSayHbCzFJMdpj7Fqstkdvo1cqOR19zZSfhLYZ41AEbzCFgwJup/E9vWX reoc8SOJVx50pHczqiZlvF1INI9DeQepCD5+MJGySgdPNlD0Cmyr8YPmDDQB8Iye0ZsXvBZSoBl VfMaH3bnapB3lXcpsXVlF2fEPbnn3ZEIgftO2/7LAD8jMIJ6t7oHvdUtTW2CUH/dLqL9kr4LmML xKJ7EELJxvMvc1Zua61qVQzEo0cJLE5k9meGL9MKVarTbvXA8GomAzsYDM0anW0X2jJfUwTjouE U1gSEueGHod/I0knAP4HzCjFCFuyUTL6w15gYGAOCn+qB2JXzIssm79V318+Guyfh7AJWz4JjRa C4i9FwqvSNtP3H93lJaYh9BaTWNQ== X-Google-Smtp-Source: AGHT+IEFoaufhtQhW9IvDY1RlPlNMuzHF+hZt/2aoSTSKZxkU4XhEbVtz7dv7vqUjHSWeE+D5TBt/w== X-Received: by 2002:a05:7022:408:b0:119:e56b:98a7 with SMTP id a92af1059eb24-11e0326a1damr3443282c88.14.1765110115829; Sun, 07 Dec 2025 04:21:55 -0800 (PST) Received: from localhost.localdomain ([104.128.72.41]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-11df76e2f3csm38598822c88.5.2025.12.07.04.21.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Dec 2025 04:21:55 -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 v6 2/3] block: prohibit calls to bio_chain_endio Date: Sun, 7 Dec 2025 20:21:25 +0800 Message-Id: <20251207122126.3518192-3-zhangshida@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20251207122126.3518192-1-zhangshida@kylinos.cn> References: <20251207122126.3518192-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 Reviewed-by: Christoph Hellwig Signed-off-by: Shida Zhang --- block/bio.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/bio.c b/block/bio.c index b3a79285c27..d236ca35271 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 11:46:42 2025 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.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 2E3802E172D for ; Sun, 7 Dec 2025 12:22:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765110121; cv=none; b=jiSa5bLUzLGwjQ9Bna0CEf+F5VKoDltIbyGSfptyB/R6e9BEVypTx1B0XpoiEkjrhuRF8fQXr1DpK5XAzlLsJnmlO2r7F81mTqhx4pn5KAbtOWBaw/fHFo5SVeTbMsLG/fqdR/Ui6seFCVg+OXbnmeP4atzrc7RkULnb0ygjI3g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765110121; c=relaxed/simple; bh=w8eGtVtlolLagnlYNt5x+XC8+sk1v+JVwx6mfbCwbOg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TSdC+6m0K+EkiMCO26NG5gkdv2drOS/9QJimEiMHZUu4HtOWsUu82F2abCBDjVf+dt2914sGtCB3e2WuN18xgEy0hxUhP2Y/hvK48Zcrgx/iKMdumR6+Gelm5uqFtjMxTtXxjtshVCunEi0yMTuINh6obqdqBbZGNUugbOsj6xw= 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=T20n3oaE; arc=none smtp.client-ip=209.85.214.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="T20n3oaE" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2953ad5517dso34515665ad.0 for ; Sun, 07 Dec 2025 04:22:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765110119; x=1765714919; 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=izKeaJNjYDUXJJUmuNDk2T6fLdmn69WrrecR/pMCWDY=; b=T20n3oaEQwzxXBknNtxQZvm1mNJm9vaJHB77antzABXhJJ0YhkOAOG7P429Hy9vUR5 ZLlqlOXFSRZBQkKYoryHdt8D2vbaNapTHpD/zD9zR8Ff8pPf7lE4iUCcJmRAS9lkLVoY wpCRjAfHXwdf7r5Aq/JkAlmxKb7xQIpdjyFWPZGQOBVI3MapzGQEwUBlgDSYTeWpb6t9 mL9JRfPMJbb9hh+i6FUA0Yj5Nv8oifhSxrYba3UW6xJRp1PCG6Uz/Gor70C2IqyKuC9C jUFiu7DaS2cylWolqkliroma1pEQ6g8Elv0SFLxqShmDDu0lcRv03eMxm12fQqpO0eU+ DchA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765110119; x=1765714919; 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=izKeaJNjYDUXJJUmuNDk2T6fLdmn69WrrecR/pMCWDY=; b=oE0X8Uk29chSvOL8liXz49qjoaDLLQuK8DbCINN1kBBEpxMlK9R07n8jxEEBCDO6w+ N+ZDNwg2GmRahI9O/RhEkx1VH4jGTU22FvtemchcMu+H/xOtyy5CbTl59svrIRawl369 TWOUDLxMV/FbXrxtc/WT2QOrZWW0ThJ5EXv4IyMuTWyA9KWIinR6d2LO91AmQXkTWvbM J/Uk7xe1lJCIYCvNXu4/06AoOZ+JC0gwp4grc6fYoKKS2RgO/6W3ebGWDn+eC2vKmsAV 7vjThEDgYOg9OXDuQCyG3wCmSiQbPA6oTiTAoHXm+5INFxJMc0Fphcb9bjvUyJcR+zTp s2Ag== X-Forwarded-Encrypted: i=1; AJvYcCVnn2TGZiAcXjiwQUssVpIC+XlpU+3WZr57z1/xMdvt0bt5DREYEZIX64C6ub7Oa089DDcxOmlbKv4URSU=@vger.kernel.org X-Gm-Message-State: AOJu0YxYL/0cd9A9ejyIk6BVLYTPrKeYxBqfRk+Xonutq43/qIb6pPxU t7bCL618puVsKLOb9X7n19NFqsfGhUKpJRG2c/lkC6vTbvirYbVVl2fZ X-Gm-Gg: ASbGnct1UPcUk2ShazFjT7jRqp4+3WSXhAGOrI2hjGWWWVObNtmfsV26ekVCVa7QbLQ 9eMONr8plsxxCe634horl3WnPWgZrgfAEUop1eugW/OHnodzzBY8XE0C2OElle/e5j+oIMqZ/wN h7QBvuerhQnji4Wf9+GnnQtYZY6miogyq7ynrltxNBniklytkFto4IzUHQ3L8pAUHwdS7JPFqql lwURtplFWKL9USjj3eVqkrn4i1PRdjUT/1EucCZBrlvzQKEg6gj3sfUh0qSnYLjtvBQkx/KmX5U zbxE58l52InR7i7AMzbqqcQATEtBCMh4cyrvns3T2v9RfspIJ6kfWMjqvhoqO1JiKauuBglexpB asEj38lCnjfQigfolZo55HvjJUVWZpmr+cuffPLkBz9XPpNcL3V/VJZ/++wLkJu+HpnkEg4Gh/3 nxmEyUwMB9ZWrYtic+0Ct1CSa7qA== X-Google-Smtp-Source: AGHT+IECvKJIBxL4NZCJGy3oY+S1k6hGdcU74QcxSoe7E6jhp3VaKBVwnJ2amzDXJrC/dyJKXDSsxg== X-Received: by 2002:a05:7022:f89:b0:119:e55a:9c04 with SMTP id a92af1059eb24-11e032ac37dmr3497724c88.32.1765110119410; Sun, 07 Dec 2025 04:21:59 -0800 (PST) Received: from localhost.localdomain ([104.128.72.41]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-11df76e2f3csm38598822c88.5.2025.12.07.04.21.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Dec 2025 04:21:59 -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 v6 3/3] block: prevent race condition on bi_status in __bio_chain_endio Date: Sun, 7 Dec 2025 20:21:26 +0800 Message-Id: <20251207122126.3518192-4-zhangshida@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20251207122126.3518192-1-zhangshida@kylinos.cn> References: <20251207122126.3518192-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 d236ca35271..8b4b6b4e210 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