From: 胡连勤 <hulianqin@vivo.com>
To: Christoph Hellwig <hch@lst.de>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
"Martin K. Petersen" <mkp@kernel.org>,
Bart Van Assche <bvanassche@acm.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Alan Stern <stern@rowland.harvard.edu>,
Jens Axboe <axboe@kernel.dk>, Hannes Reinecke <hare@suse.de>,
Mike Christie <michael.christie@oracle.com>,
Damien Le Moal <dlemoal@kernel.org>,
John Garry <john.g.garry@oracle.com>,
Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>,
"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"usb-storage@lists.one-eyed-alien.net"
<usb-storage@lists.one-eyed-alien.net>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: 答复: [PATCH v5 1/2] scsi: sd: mark disk dead on surprise host removal to avoid I/O hang
Date: Tue, 13 Oct 2026 02:14:06 +0000 [thread overview]
Message-ID: <TYUPR06MB62172FD04314EFE34D8091EAD29E2@TYUPR06MB6217.apcprd06.prod.outlook.com> (raw)
In-Reply-To: <20261012144923.GA10852@lst.de>
Hi Christoph,
> > unsigned short_inquiry:1;
> >
> > + /* Device is physically gone; skip sync in sd_remove() */
> > + unsigned surprise_removal:1;
>
> Placing this right in the middle of static fields is a bit weird.
>
> Maybe we should get started with an unsigned long and atomic bitops
> for something like that actually is known to set it at any point in
> runtime and thus most suspect to corruption non-atomic bitfields?
Thanks for the review. You're right on both points.
I plan to change it as follows:
drivers/scsi/sd.c | 4 ++++
include/scsi/scsi_host.h | 7 +++++++
2 files changed, 11 insertions(+)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index a1b21ea14e54..075a50c08404 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -4272,6 +4272,10 @@ static void sd_remove(struct scsi_device *sdp)
scsi_autopm_get_device(sdkp->device);
+ /* Device is gone; avoid sync_filesystem() hang in del_gendisk(). */
+ if (test_bit(SHOST_SURPRISE_REMOVAL, &sdkp->device->host->flags))
+ blk_mark_disk_dead(sdkp->disk);
+
device_del(&sdkp->disk_dev);
del_gendisk(sdkp->disk);
if (!sdkp->suspended)
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index 16243ec376cd..66aa9ae607de 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -757,6 +757,13 @@ struct Scsi_Host {
/* Delay for runtime autosuspend */
int rpm_autosuspend_delay;
+ /*
+ * Host flags for runtime state that may be set concurrently.
+ * Use atomic bitops (set_bit/test_bit) to access.
+ */
+ unsigned long flags;
+#define SHOST_SURPRISE_REMOVAL 0
+
/*
* We should ensure that this is aligned, both for better performance
* and also because some compilers (m68k) don't automatically force
drivers/usb/storage/usb.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 064c7fc8e368..3a5a0cac2b78 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -930,6 +930,9 @@ static void quiesce_and_remove_host(struct us_data *us)
if (us->pusb_dev->state == USB_STATE_NOTATTACHED) {
set_bit(US_FLIDX_DISCONNECTING, &us->dflags);
wake_up(&us->delay_wait);
+
+ /* Device is physically gone, cannot handle I/O */
+ set_bit(SHOST_SURPRISE_REMOVAL, &host->flags);
}
The flags field is placed after rpm_autosuspend_delay, away from the
static bitfields. set_bit()/test_bit() ensure atomic access when the
flag is set at disconnect time and read in sd_remove().
Regards,
Lianqin
next prev parent reply other threads:[~2026-10-13 2:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 11:29 胡连勤
2026-10-12 14:49 ` Christoph Hellwig
2026-10-13 2:14 ` 胡连勤 [this message]
2026-10-13 15:22 ` 答复: " Bart Van Assche
2026-10-14 2:20 ` 答复: " 胡连勤
2026-10-14 19:50 ` Bart Van Assche
2026-10-15 1:48 ` 答复: " 胡连勤
2026-10-16 8:04 ` 胡连勤
2026-10-13 8:14 ` [usb-storage] " Oliver Neukum
2026-10-13 9:14 ` 答复: " 胡连勤
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=TYUPR06MB62172FD04314EFE34D8091EAD29E2@TYUPR06MB6217.apcprd06.prod.outlook.com \
--to=hulianqin@vivo.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=dlemoal@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=john.g.garry@oracle.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=michael.christie@oracle.com \
--cc=mkp@kernel.org \
--cc=shinichiro.kawasaki@wdc.com \
--cc=stable@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=usb-storage@lists.one-eyed-alien.net \
/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
all inboxes | Powered by JetHome®