From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.20 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796475330; b=kxTlWFve1wPBQYJNUx3rp9joFBt6/bM7uqjXwvnO6OBcDxVXw55xhM3yeNRaAIBdeIq6 cRVeB2DUr6F+My9PsMO6mjBr0zg/v9EZ5mCF5GL9VgRvU9jQ6SkoFu7TcAoqoepgla7im BhNbnuBWKJiPu9RKlHK1ECsQThq/gPD0qWrej6IsyIB20l2XR0kxEAvMfu79v+t8/fiDG sfo/RnVypQDkuicxJLC30cI4yznmrTF0WeB0FyqoYz0/ULSehe9yHHahpkjI2z6a0C/Vc SJY8stya9Dtv2wIXzqDghVmx87UDlS/B5pNrCgdDsnVtNg9VpSAbj4ROzI47UbZbMvA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796475330; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=E6C7Hr0zPfc3jeIyE/GqQW1AHt4XKFvDcTKAXjcCtN4=; b=5n9E4L6GJfIJo1nfBieC0uXYonZKG5WFsUV2lfYuiaFjDyXdcGnllN+XMVimAcHFmueH 8xMIb9AwUbmisNTOxwYPGSphC12Z+Y1so7OUXC56aX+iVd4+xS57mhzfhhdzPxostQJjW gPiCzkJUZMd+mHjL5AyK9FbLAtz4k1gDnpfEb5RYfFZUdyAdr4ljBgo8V91OEue75NC19 kenlRDdw71YF8gylEpxHZgyz5qvtGWJxr61PzxTPiTz83uv1CibSjZTUbXwW6b1Ex6gHk 2NWOO+IiHJBWU1xo2qsyxshtYx/A0Vhjp1zsPAYdfM4lrWSL5Dt/wTZxnxnMKQ/0H8Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=YMQXOssa; arc=none smtp.remote-ip=91.218.175.20 Received: from mta0.migadu.com (out-20.mta0.migadu.com [91.218.175.20]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDF4A606A685 for ; Sat, 5 Dec 2026 12:55:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EDF4A606A685 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=YMQXOssa X-Envelope-To: linux-doc@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=ijK/340XAfHtwiXLJPqAKc70mYx0zoUqgaFjSBAar2c=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796475328; v=1; x=1797080128; b=YMQXOssar6ZhplEPa5tTtpESxjvVyshzBHOmCVpBF74MvMVlQhNg7A4H68AFDFoKSYTuXjnr C+k5C5BWRiYJXR+OawhIx351yXRJGsHF7Dvu1+lDvpf++DlU4+f2zsTTp2Ss+IB59exyGcvkTIs M1Nhv/S29t6YbumG/3TVp03w= X-Envelope-To: linux-doc@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 945b8b9f915e2e8d; Sat, 05 Dec 2026 12:55:26 +0000 X-Mizu-Trace-ID: 945b8b9f915e2e8d X-Migadu-Flow: FLOW_OUT From: Md Haris Iqbal To: Jens Axboe , linux-block@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Jonathan Corbet , linux-doc@vger.kernel.org, Md Haris Iqbal Subject: [PATCH 1/2] block: hold the disk while error injection delays a bio Date: Sat, 5 Dec 2026 13:55:07 +0100 Message-ID: <20261205125510.29717-3-haris.iqbal@linux.dev> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261205125510.29717-1-haris.iqbal@linux.dev> References: <20261205125510.29717-1-haris.iqbal@linux.dev> X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A bio delayed by an error injection rule is resubmitted from a workqueue, up to 600 seconds later. Nothing holds the disk during that time: the bio has not entered the queue yet, so it holds no queue usage counter and del_gendisk() does not wait for it. The comment claiming that the submitter holds the bdev open is wrong: nvme multipath remaps bios to the hidden namespace disk without opening it, so the disk can be freed while the bio waits. For disks that don't own their queue, such as sd and sr, the queue is no longer dying after del_gendisk(), and the resubmitted bio reaches the driver after the device was removed. Take a reference to the bdev and the driver module when delaying a bio, and fail the bio instead of resubmitting it if the disk is dead by then. The module reference is needed because dropping the last disk reference can call the driver's ->free_disk(). Fixes: 6bd856cc9996 ("block: allow error injection rules to delay bios") Signed-off-by: Md Haris Iqbal --- block/error-injection.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/block/error-injection.c b/block/error-injection.c index a6de52229ef3..51fba46990b2 100644 --- a/block/error-injection.c +++ b/block/error-injection.c @@ -33,10 +33,11 @@ struct blk_error_inject { /* * A bio held by a delay rule. It does not point back at the rule, so rules - * can be removed while delayed bios are outstanding. The submitter holds the - * bdev open until the bio completes, so the disk and queue stay allocated. - * A delayed bio holds no queue usage counter reference, so it does not hold - * up a queue freeze either. + * can be removed while delayed bios are outstanding. Not every submitter holds + * the bdev open, so a delayed bio holds a reference to its bdev and to the + * driver module, and is failed instead of resubmitted if the disk is dead by + * then. A delayed bio holds no queue usage counter reference, so it does not + * hold up a queue freeze either. */ struct blk_error_inject_delay { struct delayed_work dwork; @@ -62,21 +63,26 @@ static void blk_error_inject_delay_work(struct work_struct *work) struct blk_error_inject_delay *d = container_of(to_delayed_work(work), struct blk_error_inject_delay, dwork); struct bio *bio = d->bio; + struct block_device *bdev = bio->bi_bdev; + struct module *owner = bdev->bd_disk->fops->owner; blk_status_t status = d->status; kfree(d); - if (status != BLK_STS_OK) { - blk_error_inject_fail(bio, status); - return; - } - /* * Resubmit. The BIO_ERROR_INJECTED flag ensures that a bio that was * delayed once skips error injection entirely from here on, including * any other rule that covers it. */ - submit_bio_noacct_nocheck(bio, false); + if (test_bit(GD_DEAD, &bdev->bd_disk->state)) + bio_io_error(bio); + else if (status != BLK_STS_OK) + blk_error_inject_fail(bio, status); + else + submit_bio_noacct_nocheck(bio, false); + + put_device(&bdev->bd_device); + module_put(owner); } static bool blk_error_inject_delay(struct gendisk *disk, struct bio *bio, @@ -98,6 +104,12 @@ static bool blk_error_inject_delay(struct gendisk *disk, struct bio *bio, return false; } + if (!try_module_get(disk->fops->owner)) { + kfree(d); + return false; + } + get_device(&bio->bi_bdev->bd_device); + pr_info_ratelimited("%pg: delaying %s at sector %llu:%u by %uus\n", disk->part0, blk_op_str(bio_op(bio)), bio->bi_iter.bi_sector, bio_sectors(bio), delay_us); -- 2.53.0