From: sashiko-bot@kernel.org
To: "Phil Pemberton" <philpem@philpem.me.uk>
Cc: linux-scsi@vger.kernel.org, cassel@kernel.org,
dlemoal@kernel.org, linux-ide@vger.kernel.org
Subject: Re: [PATCH v10 13/15] scsi: add BLIST_NO_LUN_1F blacklist flag
Date: Fri, 09 Oct 2026 16:38:21 +0000 [thread overview]
Message-ID: <sashiko-outbox-165837@kernel.org> (raw)
In-Reply-To: <20261009155522.593045-14-philpem@philpem.me.uk>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] scsi: single_lun bitfield data race with expecting_lun_change
--
commit 15aed878e542873ad45c1f172fe5d87a9c1380de
Author: Phil Pemberton <philpem@philpem.me.uk>
scsi: add BLIST_NO_LUN_1F blacklist flag
This commit adds a new BLIST_NO_LUN_1F blacklist flag to prevent SCSI
scanning from adding spurious "No Device" entries for unpopulated LUNs
reporting PQ=0/PDT=0x1f. It also safely moves pdt_1f_for_no_lun to a
dedicated boolean to prevent scan-time writes from overwriting concurrent
I/O updates in shared bitfields.
> diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
> index 8694eeadd753e..a81a7c8cce18e 100644
> --- a/include/scsi/scsi_device.h
> +++ b/include/scsi/scsi_device.h
> @@ -360,13 +360,13 @@ struct scsi_target {
> unsigned int single_lun:1; /* Indicates we should only
> * allow I/O to one of the luns
> * for the device at a time. */
> - unsigned int pdt_1f_for_no_lun:1; /* PDT = 0x1f
> - * means no lun present. */
> unsigned int no_report_luns:1; /* Don't use
> * REPORT LUNS for scanning. */
> unsigned int expecting_lun_change:1; /* A device has reported
> * a 3F/0E UA, other devices on
> * the same target will also. */
[Severity: High]
Does leaving single_lun in the same bitfield block as expecting_lun_change
still leave us vulnerable to read-modify-write tearing?
While this patch correctly identifies the tearing risk and moves
pdt_1f_for_no_lun to its own bool, single_lun is also updated at scan time
in scsi_add_lun() under shost->scan_mutex:
drivers/scsi/scsi_scan.c:scsi_add_lun() {
...
if (*bflags & BLIST_SINGLELUN)
scsi_target(sdev)->single_lun = 1;
...
}
While LUN 1 (or later) is being scanned, LUN 0 is already visible and can
process I/O. If an I/O on LUN 0 triggers a Unit Attention or completes a
REPORT LUNS command, softirq block completion context updates
expecting_lun_change without holding scan_mutex:
drivers/scsi/scsi_error.c:scsi_report_lun_change() {
...
sdev->sdev_target->expecting_lun_change = 1;
...
}
Because both fields share the same memory word, the scan-time update to
single_lun can silently overwrite and erase the concurrent I/O update to
expecting_lun_change, leading to dropped I/O retries, spurious I/O errors,
or loss of single_lun serialization.
This race is explicitly triggered by follow-up patch 15 in this series,
which introduces a quirk setting BLIST_SINGLELUN for a multi-LUN device
(COMPAQ PD-1).
Should single_lun also be moved to a separate bool to completely resolve
this bitfield race?
> + /* Keep scan-time writes separate from I/O-updated bitfields. */
> + bool pdt_1f_for_no_lun; /* PDT = 0x1f means no LUN. */
> /* commands actually active on LLD. */
> atomic_t target_busy;
> atomic_t target_blocked;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261009155522.593045-1-philpem@philpem.me.uk?part=13
next prev parent reply other threads:[~2026-10-09 16:38 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 15:55 [PATCH v10 00/15] ata: add multi-LUN support for ATAPI devices Phil Pemberton
2026-10-09 15:55 ` [PATCH v10 01/15] ata: libata-acpi: pin the SCSI device while emitting a bay event Phil Pemberton
2026-10-09 15:55 ` [PATCH v10 02/15] scsi: core: release the device tree node at final device release Phil Pemberton
2026-10-09 15:55 ` [PATCH v10 03/15] ata: libata-zpodd: reference SCSI devices in PM callbacks Phil Pemberton
2026-10-09 15:55 ` [PATCH v10 04/15] ata: libata-zpodd: publish initialized state before registering notifications Phil Pemberton
2026-10-09 15:55 ` [PATCH v10 05/15] ata: libata-zpodd: serialize wake attribution with physical power-on Phil Pemberton
2026-10-09 15:55 ` [PATCH v10 06/15] ata: libata-core: pin SCSI devices during port detach Phil Pemberton
2026-10-09 15:55 ` [PATCH v10 07/15] scsi: scsi_devinfo: preserve full-width quirk identifiers Phil Pemberton
2026-10-09 15:55 ` [PATCH v10 08/15] scsi: sr: keep queue block sizes in sync with the medium Phil Pemberton
2026-10-09 15:55 ` [PATCH v10 09/15] scsi: sr: retry unfinished media revalidation on the next open Phil Pemberton
2026-10-09 15:55 ` [PATCH v10 10/15] ata: libata-scsi: add atapi_max_lun module parameter Phil Pemberton
2026-10-09 15:55 ` [PATCH v10 11/15] ata: libata-scsi: convert dev->sdev to per-LUN array Phil Pemberton
2026-10-09 15:55 ` [PATCH v10 12/15] ata: libata-scsi: route non-zero LUN commands for multi-LUN ATAPI Phil Pemberton
2026-10-09 15:55 ` [PATCH v10 13/15] scsi: add BLIST_NO_LUN_1F blacklist flag Phil Pemberton
2026-10-09 16:38 ` sashiko-bot [this message]
2026-10-09 15:55 ` [PATCH v10 14/15] ata: libata-scsi: probe additional LUNs for multi-LUN ATAPI devices Phil Pemberton
2026-10-09 16:44 ` sashiko-bot
2026-10-09 15:55 ` [PATCH v10 15/15] scsi: scsi_devinfo: add COMPAQ PD-1 multi-LUN ATAPI device quirk Phil Pemberton
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=sashiko-outbox-165837@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=cassel@kernel.org \
--cc=dlemoal@kernel.org \
--cc=linux-ide@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=philpem@philpem.me.uk \
--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