From nobody Mon Feb 9 02:42:23 2026 Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.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 1239C21C9F9 for ; Thu, 15 Jan 2026 07:48:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768463321; cv=none; b=eAffyy+07hZL3GgD0J5SrLsjmDl6DqYtvLBn9OHhwac1jATie0WiLlgMw7D0rnrWmg1vzIg4R7G26aISU8Y319R6nm+z5i5IEOx5UsgrIhB6L0uR1+vmfB+wCRXhMrK88Z8oBWVm/u6pZZqaYtssYQnuP+R6rPONQNgWoy/szX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768463321; c=relaxed/simple; bh=0X42B03mCPCGzfI39C6/GCr6/8Z/3IApETRaB01pd9I=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=F7tYgUqHzTcq0BEFtrE1+EHGP3vRMDwnxIfexuWv1lrmU4SHL1Rvx/8mIkd35kiwEEZCnHzef4DUIJt0yJiqSmLx8hlyXdFl7NgiPOGwS/SeTiyT6d7PIalOeuOOFTUg122BWMxq3PxMkuG1rifPPbBrP9rp5/0IG7UjoT59Xjc= 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=hBB5Vr/f; arc=none smtp.client-ip=74.125.82.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="hBB5Vr/f" Received: by mail-dy1-f172.google.com with SMTP id 5a478bee46e88-2ae255ac8bdso1241523eec.0 for ; Wed, 14 Jan 2026 23:48:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768463319; x=1769068119; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=2TIYSBe8c2j7UeU4NjfNEF82mHDuPlUbUKvJDYdP08Q=; b=hBB5Vr/fGTU7pOPEILRKkS6qHpfowU3m8RLB1h4/SOoOl2EKaVdmJRjudqx21ihqYH bWys9ahKtEHhYtI0AZlzQoAApBIpG4XEsqPkP4c86k3rwDhgto+BI8DB8G3DryxcQHY1 nLD8ZSDCfbqD1pq2HydM2ajDG/TPCSpCnb3569gZI6VmVqusXtjdx+VT9Clp9Pa4lKgf AY9tnoF+b4l6VoKT3DmHYzhV9ILNwIWDzWCFQRm5BL2oZifUK39uSNC0f8GKEKlK6tgv HsKQnP5w1B6KvgLxvRKpicVZsWqH2d2xpqrtsfZzoQBBuEmzw76wHZpngj9JJbqsfNN9 H5DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768463319; x=1769068119; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2TIYSBe8c2j7UeU4NjfNEF82mHDuPlUbUKvJDYdP08Q=; b=wqKctnNMT3GHqC6jS5iymRrIkDrF3n2Fveyo4GZIoPDLOWhb6+0Qqhgo4ly4yAm9w6 NZFSKKQYVTN3IGKrIOTvbiw7PrWRkPfdZBQGcQqzmqCKQ4ZDmYMNGxdCBWHe2SBdlqu9 k+K3dD2woC/7DoIMI7R/PyMaFnrz941TcxvvX40fIs+axDhqHZAGesyQ3mtbeA+KWFDm FebHpV+i+Vxk2Q7+NkGirlqdvglL/dnfKlir/yH01honFnGHqPPH+Q/t0ONewq3vaZbi +M83OIG3xGPSgRoapusw/j824qQm7AoAkpdpR4Fu9Bp3dQlODnBn0XpH41qiWfsNwvMK HHzg== X-Forwarded-Encrypted: i=1; AJvYcCW6Ro2MeUC4qcQzVen16dU5l/YjErQpgUXVi+cG0id62tjJsKUaDpHyMoxanjrcYVVCoIs4sw/Mxzufloo=@vger.kernel.org X-Gm-Message-State: AOJu0YyvcQhY861y7zdq9DWmGh3HYS1f3At5Ir1OJdpJREfzoIJGHSi2 OXp6ueKkFtUZPl3xjcDy4vKodgYGtO4NtJnNmp9XNLUj/IZzI2MvVifA X-Gm-Gg: AY/fxX7TFfIMiB1brPTe0KveWzSsxtO1SYdiJCxRYbZ/Knv3xV6ffBAC+Oz2knMonzS AevJrUBnDi27qw3CtV9s9QRYsiyDqTSI+DusR/4eeyAbmnTUvEIVyzSkXrTOTDVnBegimZIJaYc 1pT4qyl02t6qbjHiL9WFx/uNj1EyHq6LoNF0s9B9SYUUYlzVW2Bdp1CLLiB5BP+L+xUYDKdTUrV sboVvK1hUoKWJ9S57hN302DBM0rpnEPi75Qs1kT/hJ36c7heXtbDujzwGFhVZdHsACw6rP8wfbu fGh06IpwjSMgMYYRY/25FfPSMi10T4Y4Uc0yLmhKMPI+SgNtpxdu9vDuiDjT/4Vfm84LzGWwP8H L7bkLxMmQG05ap86GYFMj9ARDEqocJ4BR8n78rvYBhJnnOzIeFBDZvqR2dTgTpEFRCJ7FhLRZps hA3yOg2AnuKwLjJNnyGWPInvCUBA== X-Received: by 2002:a05:693c:3104:b0:2ae:5b88:3499 with SMTP id 5a478bee46e88-2b48f6d41b6mr7379124eec.37.1768463319082; Wed, 14 Jan 2026 23:48:39 -0800 (PST) Received: from localhost.localdomain ([104.128.72.41]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b4549fc8e9sm5619748eec.28.2026.01.14.23.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jan 2026 23:48:38 -0800 (PST) From: zhangshida X-Google-Original-From: zhangshida To: colyli@fnnas.com, kent.overstreet@linux.dev, axboe@kernel.dk, sashal@kernel.org Cc: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, zhangshida@kylinos.cn, starzhangzsd@gmail.com Subject: [PATCH] bcache: fix double bio_endio completion in detached_dev_end_io Date: Thu, 15 Jan 2026 15:48:11 +0800 Message-Id: <20260115074811.230807-1-zhangshida@kylinos.cn> X-Mailer: git-send-email 2.25.1 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 Commit 53280e398471 ("bcache: fix improper use of bi_end_io") attempted to fix up bio completions by replacing manual bi_end_io calls with bio_endio(). However, it introduced a double-completion bug in the detached_dev path. In a normal completion path, the call stack is: blk_update_request bio_endio(bio) bio->bi_end_io(bio) -> detached_dev_end_io bio_endio(bio) <- BUG: second call To fix this, detached_dev_end_io() must manually call the next completion handler in the chain. However, in detached_dev_do_request(), if a discard is unsupported, the bio is rejected before being submitted to the lower level. In this case, we can use the standard bio_endio(). detached_dev_do_request bio_endio(bio) <- Correct: starts completion for unsubmitted bio Fixes: 53280e398471 ("bcache: fix improper use of bi_end_io") Signed-off-by: Shida Zhang --- drivers/md/bcache/request.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c index 82fdea7dea7..ec712b5879f 100644 --- a/drivers/md/bcache/request.c +++ b/drivers/md/bcache/request.c @@ -1104,7 +1104,14 @@ static void detached_dev_end_io(struct bio *bio) } =20 kfree(ddip); - bio_endio(bio); + /* + * This is an exception where bio_endio() cannot be used. + * We are already called from within a bio_endio() stack; + * calling it again here would result in a double-completion + * (decrementing bi_remaining twice). We must call the + * original completion routine directly. + */ + bio->bi_end_io(bio); } =20 static void detached_dev_do_request(struct bcache_device *d, struct bio *b= io, @@ -1136,7 +1143,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)) - detached_dev_end_io(bio); + bio_endio(bio); else submit_bio_noacct(bio); } --=20 2.34.1