From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.32 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796475329; b=K8L5+XiPAaFdRjrucPHW06ZjtWa/+gQxKRmg8r8ZUTHPfCpahu9B/eXnXvDRae6aylGY rOSuzTw6zxbJWen3ktJS5mPDdi/YXhsJYq21fu+J02kx1XK73/H9XnE9OwpxW3QxXjbJe uhR3EnvUrFkEn60bnEsDED6aK2HbWnm4kU54HkTaIS38ci3EZS9JVgHY+6O7TX8FYYdsW 2GkXTYeD45SSfGdFMReDQCaZc6P7OXEL4mlqg9k8QfDMXOEh7pJR1DPUpczTnVcUvu0L+ 1bnZlytHwiXdVXwYKsHydfBMwI38c+wKnhrN3hc05tkK5wZFiA+3eHUOVFG19UrTJ+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796475329; 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=1FnLR3dd03tpH/Um+t2ZiJL/h2V6Th91GWkgKVTSB9O1/zR460YiF6RNf9mzx5CKVCKl TwZHYRpvBA6F2gOmJuWOVeJU3VbKgWhqWocw4CKC/7NqaWq0zkMta1z+5LGSdGis3zXAl LNjPWiLlKkIa5QOC7WgTc37RA19tsqx9bVZIcHZRhJLwDcAGRNlATUSQiWO4b9+sKsFcR hKBIsHElqmhNr0NR983tD/IuXRw4QmHtN+eOd8OGAWeEkB7hKUQ4t96ioxNPv2X6LXPTR HDuo5tBYDWAHmWMSo50W/XBAW/YYZ1AOMqZyGiu/kOQKV+waXB62fUzwKkI2aiyHHgw== 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=Xc0TkR63; arc=none smtp.remote-ip=95.215.58.32 Received: from mta1.migadu.com (out-32.mta1.migadu.com [95.215.58.32]) (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 D829E606A33A for ; Sat, 5 Dec 2026 12:55:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D829E606A33A 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=Xc0TkR63 X-Envelope-To: linux-kernel@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=1796475327; v=1; x=1797080127; b=Xc0TkR63jzz1H24CvNwxGAwhUY1xFM4l2wOCjaJD9++VwinmkjqnOH9h7d1cqp9Fykk6o0Qp KZxakBe0G6GBCzDq/MRHeO6EaSba6G18rAXYFBlbbeWRo0Br9E3FToRpu4MPeR3LUyriwBUc5tQ CUQVtJwSW6uP8CFob1ELFkLY= X-Envelope-To: linux-kernel@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-kernel@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