Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: ������ <hulianqin@vivo.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v4] scsi: sd: mark disk dead on surprise host removal to avoid I/O hang
Date: Thu, 08 Oct 2026 12:04:10 +0000	[thread overview]
Message-ID: <sashiko-outbox-164131@kernel.org> (raw)
In-Reply-To: <TYUPR06MB6217570B9AFA4B5980FCCED0D2932@TYUPR06MB6217.apcprd06.prod.outlook.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] scsi: Data loss on orderly host teardown due to misidentified surprise removal
--

commit 9a3b48997b6a95bc55f9d45d1fe71786ff63438c
Author:  <hulianqin@vivo.com>

scsi: sd: mark disk dead on surprise host removal to avoid I/O hang

This commit adds a scsi_host_in_cancel() check in sd_remove() to mark the
disk dead before del_gendisk(). This is intended to skip sync_filesystem()
during surprise removals where the device can no longer handle I/O.

> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index b0d2542fd3172..00cf408513ce4 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -4270,6 +4270,16 @@ static void sd_remove(struct scsi_device *sdp)
>  
>  	scsi_autopm_get_device(sdkp->device);
>  
> +	/*
> +	 * If the host is being torn down (e.g. USB surprise removal),
> +	 * the device cannot handle I/O anymore.
> +	 * Mark the disk dead before del_gendisk() so that new I/O is
> +	 * rejected immediately and sync_filesystem() in del_gendisk()
> +	 * is skipped, avoiding a hang waiting for I/O that can never
> +	 * complete.
> +	 */
> +	if (scsi_host_in_cancel(sdkp->device->host))
> +		blk_mark_disk_dead(sdkp->disk);

[Severity: High]
Will this logic conflate all host removals with surprise removals?

The patch aims to skip sync_filesystem() only during surprise removals by
checking if the host is in SHOST_CANCEL. However, scsi_remove_host() in
drivers/scsi/hosts.c unconditionally transitions the host state to
SHOST_CANCEL for all host teardowns:

drivers/scsi/hosts.c:scsi_remove_host() {
    ...
    if (scsi_host_set_state(shost, SHOST_CANCEL))
    ...
}

Because SHOST_CANCEL is the standard teardown state for all removals,
including orderly ones like rmmod usb-storage or sysfs driver unbinding,
blk_mark_disk_dead() will set GD_DEAD for every host removal.

When del_gendisk() executes, it will bypass its own
blk_report_disk_dead(disk, false) because GD_DEAD is already set.

Could this skip sync_filesystem() entirely, causing all pending dirty page
cache data to be discarded instead of written back during an orderly unbind
or unload, resulting in data loss?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/TYUPR06MB6217570B9AFA4B5980FCCED0D2932@TYUPR06MB6217.apcprd06.prod.outlook.com?part=1

      reply	other threads:[~2026-10-08 12:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-08 11:51 [PATCH v4] scsi: sd: mark disk dead on surprise host removal to avoid I/O hang 胡连勤
2026-10-08 12:04 ` sashiko-bot [this message]

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-164131@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=hulianqin@vivo.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