Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: John Garry <john.g.garry@oracle.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 07/17] scsi-multipath: failover handling
Date: Mon, 6 Jul 2026 16:32:08 +0100	[thread overview]
Message-ID: <cec1f810-cfab-4585-88a0-385eb57f5c86@oracle.com> (raw)
In-Reply-To: <20260703114052.6437E1F000E9@smtp.kernel.org>

On 03/07/2026 12:40, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
> - [High] Unchecked dereference of `sdev` returned by `scsi_device_from_queue()` leading to an immediate kernel panic.
> - [High] Leaking a reference to `scsi_device` acquired by `scsi_device_from_queue()`.
> - [High] Calling a sleepable synchronization function in `bio_end_io` atomic context.
> --
> 
> commit 8a70735872bb7cb2125e8980a60e0bae2a38b040
> Author: John Garry <john.g.garry@oracle.com>
> 
> scsi-multipath: failover handling
> 
> This commit implements failover handling for scsi commands that fail due to
> the target device's transport going down. It requeues the master bio of each
> bio attached to the request by handling the failover inside the
> scsi_mpath_clone_end_io() completion handler.
> 
>> diff --git a/drivers/scsi/scsi_multipath.c b/drivers/scsi/scsi_multipath.c
>> index 0f3f3f9fa5fae..f22e3677cf2ad 100644
>> --- a/drivers/scsi/scsi_multipath.c
>> +++ b/drivers/scsi/scsi_multipath.c
> [ ... ]
>> @@ -242,11 +242,44 @@ static int scsi_multipath_sdev_init(struct scsi_device *sdev)
>>   static void scsi_mpath_clone_end_io(struct bio *clone)
>>   {
>>   	struct bio *master_bio = clone->bi_private;
>>   
>>   	master_bio->bi_status = clone->bi_status;
>> +
>> +	if (clone->bi_status && blk_path_error(clone->bi_status)) {
>> +		struct block_device *bi_bdev = clone->bi_bdev;
>> +		struct request_queue *q = bi_bdev->bd_queue;
>> +		struct scsi_device *sdev = scsi_device_from_queue(q);
>> +		struct scsi_mpath_device *scsi_mpath_dev = sdev->scsi_mpath_dev;
> 
> [Severity: High]
> Can scsi_device_from_queue() return NULL here? If a path error occurs
> concurrently with a device removal or hot-unplug, get_device() inside
> scsi_device_from_queue() could fail. If sdev is NULL, wouldn't accessing
> sdev->scsi_mpath_dev on the very next line cause an immediate NULL pointer
> dereference?

will fix

> 
>> +		struct mpath_device *mpath_device = &scsi_mpath_dev->mpath_device;
>> +		struct mpath_head *mpath_head = mpath_device->mpath_head;
>> +		unsigned long flags;
>> +
>> +		scsi_mpath_dev_clear_path(scsi_mpath_dev);
> 
> [Severity: High]
> Is it safe to call scsi_mpath_dev_clear_path() from a bio completion handler?
> Since scsi_mpath_clone_end_io() runs in atomic softirq context, and
> scsi_mpath_dev_clear_path() can call mpath_synchronize() which might sleep
> to wait for grace periods, could this trigger a sleeping in atomic context
> BUG?

I'd like more info for when this is called from softirq context. From my 
experience we the failover completion call from blk_mq_work_fn in ... 
scsi_queue_rq() -> blk_update_request()

> 
>> +
>> +		spin_lock_irqsave(&mpath_head->requeue_lock, flags);
>> +		bio_list_add_clone(&mpath_head->requeue_list, clone);
>> +		spin_unlock_irqrestore(&mpath_head->requeue_lock, flags);
>> +
>> +		mpath_schedule_requeue_work(mpath_head);
>> +		return;
> 
> [Severity: High]
> Does this return path leak the reference to the scsi_device?
> 
> When scsi_device_from_queue() is called earlier, it increments the device's
> kobject reference count via get_device(). There doesn't appear to be a
> corresponding put_device() before returning here, which might permanently
> prevent device cleanup on unplug if repeated failovers occur.

will fix

> 
>> +	}
>> +
>>   	bio_put(clone);
>>   	bio_endio(master_bio);
>>   }
> 


  reply	other threads:[~2026-07-06 15:32 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-03 10:33 [PATCH v3 00/17] Native SCSI multipath support John Garry
2026-07-03 10:33 ` [PATCH v3 01/17] scsi-multipath: introduce basic SCSI device support John Garry
2026-07-03 10:53   ` sashiko-bot
2026-07-06 14:39     ` John Garry
2026-07-03 10:33 ` [PATCH v3 02/17] scsi-multipath: introduce scsi_device head structure John Garry
2026-07-03 10:49   ` sashiko-bot
2026-07-06 14:45     ` John Garry
2026-07-03 10:33 ` [PATCH v3 03/17] scsi-multipath: provide sysfs link from to scsi_device John Garry
2026-07-03 11:04   ` sashiko-bot
2026-07-03 10:33 ` [PATCH v3 04/17] scsi-multipath: support iopolicy John Garry
2026-07-03 11:10   ` sashiko-bot
2026-07-06 14:49     ` John Garry
2026-07-03 10:33 ` [PATCH v3 05/17] scsi-multipath: clone each bio John Garry
2026-07-03 11:26   ` sashiko-bot
2026-07-06 14:53     ` John Garry
2026-07-03 10:33 ` [PATCH v3 06/17] scsi-multipath: clear path when device is blocked John Garry
2026-07-03 11:32   ` sashiko-bot
2026-07-06 15:04     ` John Garry
2026-07-03 10:33 ` [PATCH v3 07/17] scsi-multipath: failover handling John Garry
2026-07-03 11:40   ` sashiko-bot
2026-07-06 15:32     ` John Garry [this message]
2026-07-03 10:33 ` [PATCH v3 08/17] scsi-multipath: provide callbacks for path state John Garry
2026-07-03 11:49   ` sashiko-bot
2026-07-06 15:38     ` John Garry
2026-07-03 10:33 ` [PATCH v3 09/17] scsi-multipath: add scsi_mpath_{start,end}_request() John Garry
2026-07-03 11:53   ` sashiko-bot
2026-07-06 15:44     ` John Garry
2026-07-03 10:33 ` [PATCH v3 10/17] scsi-multipath: block PR commands John Garry
2026-07-03 12:03   ` sashiko-bot
2026-07-03 10:33 ` [PATCH v3 11/17] scsi-multipath: add delayed disk removal support John Garry
2026-07-03 12:08   ` sashiko-bot
2026-07-06 15:49     ` John Garry
2026-07-03 10:33 ` [PATCH v3 12/17] scsi: sd: add multipath disk class John Garry
2026-07-03 10:33 ` [PATCH v3 13/17] scsi: sd: support multipath disk John Garry
2026-07-03 12:24   ` sashiko-bot
2026-07-07  9:18     ` John Garry
2026-07-03 10:33 ` [PATCH v3 14/17] scsi: sd: add multipath disk attr groups John Garry
2026-07-03 12:25   ` sashiko-bot
2026-07-07  9:09     ` John Garry
2026-07-03 10:34 ` [PATCH v3 15/17] scsi: sd: add mpath_dev file John Garry
2026-07-03 12:43   ` sashiko-bot
2026-07-06 15:56     ` John Garry
2026-07-03 10:34 ` [PATCH v3 16/17] scsi: sd: add mpath_numa_nodes dev attribute John Garry
2026-07-03 12:44   ` sashiko-bot
2026-07-06 15:57     ` John Garry
2026-07-03 10:34 ` [PATCH v3 17/17] scsi: sd: add mpath_queue_depth " John Garry
2026-07-03 12:57   ` sashiko-bot
2026-07-06 15:59     ` John Garry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cec1f810-cfab-4585-88a0-385eb57f5c86@oracle.com \
    --to=john.g.garry@oracle.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox