From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796475557; b=lHDKjwdaETB5U0OYYr4MHm8I40lTm7yhNapZkc3JErRHoYlAb/qFrqj/ULwhzuUP1wIl 7IQo1IaYruNg0GmL+LogGizWxNtImX8lhd4iE2U0aCdfhftD8p3/xAXoZac0bR+pfLgYw JIrfdiU//aZMfskvhvZi8l8+64eVdwC5B86h4nfbcejSp6sJntdRmkqWpxTj0RFr4Qp4c 414LSknZM37U1n5OSvsZAoqDh9GEUcoUwz4XhYfA4wsAc5WuVEbJNWS+kUmUuthZbwgRW mWjCF673C2XkgykVhXcmWGz+AnFeuQfg4N8OiBpYaei0osxLRG3g5FpJSUShg1nIQxw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796475557; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=9E0DZify3CbXPwVWSH4Rpyl8loJvEWURbfKIKxE5lMI=; b=HJqJm1vl9GkilQAReTvP2zXVvT/yCF2+NO1mvg4xHhTcjl4BbdMLG8NuA9I6A9dvtAVJ pDW95cY+dsyW7hxchX2O+PsYRd5tIARH+PKkrVTs0BnT0LQvkydVxz2/Z8gheX2tAIdG6 RhwlFY1KX+VCl4N0vRARkYdAl6nfLM2e0rhPRlyVIkM3aY+K6r26OyjIyduNgybHlSEcH Dq4fVDebU1DMqwha8ojItCaIhWmSOu99IW/w1G4bSCBuRgtpBEtwSb1TdoZPaXHzqvsYf G+M6ojroTZ1AVVOPpWulqT7/R9CeADcUYBqkp4ASK9IX3hNoF0H0aUPW/Phul5TXFXA== 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=OU8Pu882; arc=none smtp.remote-ip=91.218.175.44 Received: from mta0.migadu.com (out-44.mta0.migadu.com [91.218.175.44]) (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 E1762606A322 for ; Sat, 5 Dec 2026 12:59:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E1762606A322 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=OU8Pu882 X-Envelope-To: linux-block@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=GD4pmXIdwltwS2o/YSqnHqWb2wpy8Co5bN7pyBEFWfE=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796475555; v=1; x=1797080355; b=OU8Pu882Ns7laBT+uLeLs9rQcSYpKp5oT9yT/bu+ClUmXg1UpwecFZ2XDfDse/IRX5FNOSMa r3PzA7FCKXrsU0Y99Ps3f5I5JLOJ5xxP4IDa7ARnPH/Rl6FTsGw7+uK670ufL+z8NDJDsNGIHhF idRoOLIJHtoEf8otCc6KhRfw= X-Envelope-To: linux-block@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 0230c1defdfe60ab; Sat, 05 Dec 2026 12:59:15 +0000 X-Mizu-Trace-ID: 0230c1defdfe60ab X-Migadu-Flow: FLOW_OUT Message-ID: Date: Sat, 5 Dec 2026 13:59:14 +0100 X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] block: hold the disk while error injection delays a bio To: Jens Axboe , linux-block@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Jonathan Corbet , linux-doc@vger.kernel.org References: <20261205125510.29717-1-haris.iqbal@linux.dev> <20261205125510.29717-3-haris.iqbal@linux.dev> Content-Language: en-US From: Haris Iqbal In-Reply-To: <20261205125510.29717-3-haris.iqbal@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/5/26 13:55, Md Haris Iqbal wrote: > 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 Ugh. Apologies for the mixup. Please drop the patches marked */2 (this one, and another one), as they were an older batch and they got sent because I mistakenly used "send-email 000*" > --- > 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);