Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "John Garry" <john.g.garry@oracle.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 17/17] scsi: sd: add mpath_queue_depth dev attribute
Date: Fri, 03 Jul 2026 12:57:02 +0000	[thread overview]
Message-ID: <20260703125702.9604B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260703103402.3725011-18-john.g.garry@oracle.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [Critical] The patch calls an undeclared function `mpath_qd_iopolicy()`, which will cause a build failure.
- [Low] Returning 0 from a sysfs `show` callback yields an empty read (EOF) instead of a proper error code.

Pre-existing issues:
- [High] Concurrent sysfs read of `mpath_queue_depth` during device teardown accesses a freed `sd_mpath_disk`.
--

commit d24252fbed25782c1f5fb88edab9e008070c4b9c
Author: John Garry <john.g.garry@oracle.com>

scsi: sd: add mpath_queue_depth dev attribute

Add a queue_depth file so that the multipath dynamic queue depth can be
looked up from per-path gendisk (scsi_disk) directory.

> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 5e0514304d81f..f6feccd557e76 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
[ ... ]
> @@ -4088,9 +4088,27 @@ static ssize_t sd_mpath_numa_nodes_show(struct device *dev,
>  }
>  static DEVICE_ATTR(mpath_numa_nodes, 0444, sd_mpath_numa_nodes_show, NULL);
>  
> +static ssize_t sd_mpath_queue_depth_show(struct device *dev,
> +		struct device_attribute *attr, char *buf)
> +{
> +	struct gendisk *gd = dev_to_disk(dev);
> +	struct scsi_disk *sdkp = gd->private_data;
> +	struct scsi_device *sdev = sdkp->device;
> +	struct sd_mpath_disk *sd_mpath_disk = sdkp->sd_mpath_disk;
> +	struct scsi_mpath_head *scsi_mpath_head = sd_mpath_disk->scsi_mpath_head;

[Severity: High]
This is a pre-existing issue, but can this sysfs read race with device
removal and cause a use-after-free?

During device removal in sd_remove(), sd_mpath_remove() is called to drop
the reference to sd_mpath_disk (and free it when the refcount hits zero):

sd_remove() {
        ...
        if (sdp->scsi_mpath_dev)
                sd_mpath_remove(sdkp);
        
        scsi_autopm_get_device(sdkp->device);
        
        device_del(&sdkp->disk_dev);
        del_gendisk(sdkp->disk);
}

Since device_del() and del_gendisk() happen later in the removal process,
local userspace can trigger a use-after-free by reading this attribute in a
loop while the multipath device is being hot-unplugged.

> +	struct Scsi_Host *shost = sdev->host;
> +
> +	if (!mpath_qd_iopolicy(&scsi_mpath_head->iopolicy))

[Severity: Critical]
Is mpath_qd_iopolicy() declared anywhere in the tree?

Compiling the kernel with CONFIG_SCSI_MULTIPATH enabled will attempt to
compile this code, but a search of the source tree indicates this function
is neither defined nor declared, which will cause the build to fail.

> +		return 0;

[Severity: Low]
Does returning 0 here result in an unexpected End-Of-File?

Returning 0 from a sysfs show callback causes the VFS to report 0 bytes
read, which userspace interpreters like cat treat as an immediate EOF,
resulting in empty output.

Should this return a standard error code like -EOPNOTSUPP instead?

> +
> +	return sysfs_emit(buf, "%d\n", atomic_read(&shost->mpath_nr_active));
> +}
> +static DEVICE_ATTR(mpath_queue_depth, 0444, sd_mpath_queue_depth_show, NULL);
> +
>  static struct attribute *sd_mpath_dev_attrs[] = {

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260703103402.3725011-1-john.g.garry@oracle.com?part=17

  reply	other threads:[~2026-07-03 12:57 UTC|newest]

Thread overview: 46+ 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
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-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-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 [this message]
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=20260703125702.9604B1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=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