Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "David Jeffery" <djeffery@redhat.com>
Cc: linux-scsi@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH 5/5] scsi: Enable async shutdown support
Date: Wed, 01 Jul 2026 14:06:41 +0000	[thread overview]
Message-ID: <20260701140641.92EE91F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260701135015.81937-6-djeffery@redhat.com>

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

Pre-existing issues:
- [High] Runtime PM usage counter and PM state leak on device_add error path.
- [High] Concurrent lockless bitfield mutations cause Data Race and PM state corruption.
--

commit 10ebc4309581b7d74ed1d3564b5f1af2a5cf5785
Author: David Jeffery <djeffery@redhat.com>

scsi: Enable async shutdown support

Like scsi's async suspend support, allow scsi devices to be shut down
asynchronously to reduce system shutdown time.

> diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
> index dfc3559e7e04f..8fd317aef37b4 100644
> --- a/drivers/scsi/scsi_sysfs.c
> +++ b/drivers/scsi/scsi_sysfs.c
> @@ -1386,6 +1386,7 @@ static int scsi_target_add(struct scsi_target *starget)
>  	pm_runtime_set_active(&starget->dev);
>  	pm_runtime_enable(&starget->dev);
>  	device_enable_async_suspend(&starget->dev);
> +	dev_set_async_shutdown(&starget->dev);

[Severity: High]
This is a pre-existing issue, but does adding dev_set_async_shutdown() here
exacerbate a data race with system suspend?

In scsi_target_add(), device_add() is called earlier, exposing the device
to the PM core. If a system-wide suspend happens concurrently,
device_prepare() may lock the device and set the is_prepared bitfield.

Since device_enable_async_suspend() and dev_set_async_shutdown() locklessly
mutate bitfields in dev->power in the same memory word, couldn't the
resulting read-modify-write instructions overwrite and clear the is_prepared
flag set by the PM core?

>  	return 0;
>  }

[ ... ]

> @@ -1412,6 +1413,7 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
>  	transport_configure_device(&starget->dev);
>  
>  	device_enable_async_suspend(&sdev->sdev_gendev);
> +	dev_set_async_shutdown(&sdev->sdev_gendev);

[Severity: High]
This isn't a bug introduced by this patch, but could the error path for
device_add(&sdev->sdev_gendev) leak the PM usage counter and runtime state?

When scsi_sysfs_add_sdev() is called, it increments the PM usage count via
scsi_autopm_get_device(sdev) and enables runtime PM. If the subsequent
device_add(&sdev->sdev_gendev) fails, the function returns the error directly
without dropping the usage counter or disabling runtime PM:

scsi_sysfs_add_sdev() {
    ...
    scsi_autopm_get_device(sdev);
    ...
    error = device_add(&sdev->sdev_gendev);
    if (error) {
        sdev_printk(...);
        return error;
    }
}

Would this prevent the device and its parent target from ever entering
runtime suspend, causing unbounded power drain?

>  	scsi_autopm_get_target(starget);
>  	pm_runtime_set_active(&sdev->sdev_gendev);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260701135015.81937-1-djeffery@redhat.com?part=5

  reply	other threads:[~2026-07-01 14:06 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 13:50 [PATCH v18 0/5] shut down devices asynchronously David Jeffery
2026-07-01 13:50 ` [PATCH 1/5] driver core: separate function to shutdown one device David Jeffery
2026-07-01 13:58   ` sashiko-bot
2026-07-01 13:50 ` [PATCH 2/5] driver core: do not always lock parent in shutdown David Jeffery
2026-07-01 14:02   ` sashiko-bot
2026-07-01 13:50 ` [PATCH 3/5] driver core: async device shutdown infrastructure David Jeffery
2026-07-01 14:11   ` sashiko-bot
2026-07-01 13:50 ` [PATCH 4/5] PCI: Enable async shutdown support David Jeffery
2026-07-01 14:07   ` sashiko-bot
2026-07-01 13:50 ` [PATCH 5/5] scsi: " David Jeffery
2026-07-01 14:06   ` sashiko-bot [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-06-16 15:22 [PATCH v17 0/5] shut down devices asynchronously David Jeffery
2026-06-16 15:22 ` [PATCH 5/5] scsi: Enable async shutdown support David Jeffery
2026-06-16 15:44   ` sashiko-bot
2026-05-18 19:31 [PATCH v16 0/5] shut down devices asynchronously David Jeffery
2026-05-18 19:32 ` [PATCH 5/5] scsi: Enable async shutdown support David Jeffery
2026-04-29 17:50 [PATCH v15 0/5] shut down devices asynchronously David Jeffery
2026-04-29 17:50 ` [PATCH 5/5] scsi: Enable async shutdown support David Jeffery
2026-04-20 15:26 [PATCH v14 0/5] shut down devices asynchronously David Jeffery
2026-04-20 15:26 ` [PATCH 5/5] scsi: Enable async shutdown support David Jeffery
2026-04-21  7:46   ` John Garry
2026-04-21 15:21   ` Pasha Tatashin
2026-04-07 15:35 [PATCH v13 0/5] shut down devices asynchronously David Jeffery
2026-04-07 15:35 ` [PATCH 5/5] scsi: enable async shutdown support David Jeffery
2026-04-07 16:34   ` John Garry
2026-04-08 14:16     ` David Jeffery
2026-04-08 15:53       ` John Garry
2026-04-08 19:35         ` David Jeffery
2026-04-09 12:17           ` John Garry
2026-04-09 20:36             ` David Jeffery
2026-03-19 14:11 [PATCH v12 0/5] shut down devices asynchronously David Jeffery
2026-03-19 14:11 ` [PATCH 5/5] scsi: enable async shutdown support David Jeffery
2026-03-20  2:20   ` Martin K. Petersen
2026-03-11 17:12 [PATCH 1/5] driver core: do not always lock parent in shutdown David Jeffery
2026-03-11 17:12 ` [PATCH 5/5] scsi: enable async shutdown support David Jeffery

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=20260701140641.92EE91F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=djeffery@redhat.com \
    --cc=linux-pci@vger.kernel.org \
    --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