scsi: introduce a quirk for false cache reporting
Subsystems (4)
PATCH 1/1 scsi: introduce a quirk for false cache reporting
Some SATA to USB bridges fail to cooperate with some drives resulting in no cache being present being reported to the host. That causes the host to skip sending a command to synchronize caches. That causes data loss when the drive is powered down.
--- Documentation/kernel-parameters.txt | 2 ++ drivers/scsi/sd.c | 6 +++--- drivers/usb/storage/scsiglue.c | 4 ++++ drivers/usb/storage/unusual_devs.h | 7 +++++++ drivers/usb/storage/usb.c | 6 +++++- include/linux/usb_usual.h | 2 ++ include/scsi/scsi_device.h | 1 + 7 files changed, 24 insertions(+), 4 deletions(-)
Documentation/kernel-parameters.txt +2 -0
@@ -4182,6 +4182,8 @@ bytes respectively. Such letter suffixes can also be entirely omitted. u = IGNORE_UAS (don't bind to the uas driver); w = NO_WP_DETECT (don't test whether the medium is write-protected). + y = ALWAYS_SYNC (issue a SYNCHRONIZE_CACHE + even if the device claims no cache) Example: quirks=0419:aaf5:rl,0421:0433:rc user_debug= [KNL,ARM]
drivers/scsi/sd.c +3 -3
@@ -139,7 +139,7 @@ static void sd_set_flush_flag(struct scsi_disk *sdkp) {bool wc = false, fua = false; -if (sdkp->WCE) { +if (sdkp->WCE || sdkp->device->always_sync) { wc = true;if (sdkp->DPOFUA) fua = true;
@@ -3228,7 +3228,7 @@ static void sd_shutdown(struct device *dev)if (pm_runtime_suspended (dev))return ; -if (sdkp->WCE && sdkp->media_present) { +if ((sdkp->WCE || sdkp->device->always_sync) && sdkp->media_present) {sd_printk (KERN_NOTICE , sdkp,"Synchronizing SCSI cache\n" );sd_sync_cache (sdkp); }
@@ -3247,7 +3247,7 @@ static int sd_suspend_common(struct device *dev, bool ignore_stop_errors)if (!sdkp)/* E.g.: runtime suspend following sd_remove() */ return 0 ; -if (sdkp->WCE && sdkp->media_present) { +if ((sdkp->WCE || sdkp->device->always_sync) && sdkp->media_present) {sd_printk (KERN_NOTICE , sdkp,"Synchronizing SCSI cache\n" ); ret =sd_sync_cache (sdkp);if (ret) {
drivers/usb/storage/scsiglue.c +4 -0
@@ -296,6 +296,10 @@ static int slave_configure(struct scsi_device *sdev)if (us->fflags &US_FL_BROKEN_FUA ) sdev->broken_fua =1 ; +/* Some even totally fail to indicate a cache */ +if (us->fflags &US_FL_ALWAYS_SYNC ) + sdev->always_sync =1 ; + }else {/*
drivers/usb/storage/unusual_devs.h +7 -0
@@ -338,6 +338,13 @@ UNUSUAL_DEV( 0x046b, 0xff40, 0x0100, 0x0100, USB_SC_DEVICE, USB_PR_DEVICE, NULL, US_FL_NO_WP_DETECT), +/* Reported by Egbert Eich <eich-IBi9RG/[email protected]> */ +UNUSUAL_DEV (0x0480 ,0xd010 ,0x0100 ,0x9999 , +"Toshiba" , +"External USB 3.0" , +USB_SC_DEVICE ,USB_PR_DEVICE ,NULL , +US_FL_ALWAYS_SYNC ), +/* Patch submitted by Philipp Friedrich <[email protected]> */ UNUSUAL_DEV( 0x0482, 0x0100, 0x0100, 0x0100, "Kyocera",
drivers/usb/storage/usb.c +5 -1
@@ -498,7 +498,8 @@ void usb_stor_adjust_quirks(struct usb_device *udev, unsigned long *fflags)US_FL_NO_READ_DISC_INFO |US_FL_NO_READ_CAPACITY_16 |US_FL_INITIAL_READ10 |US_FL_WRITE_CACHE |US_FL_NO_ATA_1X |US_FL_NO_REPORT_OPCODES | - US_FL_MAX_SECTORS_240 | US_FL_NO_REPORT_LUNS); +US_FL_MAX_SECTORS_240 |US_FL_NO_REPORT_LUNS | + US_FL_ALWAYS_SYNC); p = quirks;while (*p) {
@@ -581,6 +582,9 @@ void usb_stor_adjust_quirks(struct usb_device *udev, unsigned long *fflags)case 'w' : f |=US_FL_NO_WP_DETECT ;break ; +case 'y' : + f |=US_FL_ALWAYS_SYNC ; +break ;/* Ignore unrecognized flag characters */ } }
include/linux/usb_usual.h +2 -0
@@ -81,6 +81,8 @@/* Sets max_sectors to 240 */ \US_FLAG (NO_REPORT_LUNS ,0x10000000 ) \ /* Cannot handle REPORT_LUNS */ \ +US_FLAG (ALWAYS_SYNC ,0x20000000 ) \ + /* lies about caching, so always sync */ \#define US_FLAG (name, value) US_FL_##name = value ,enum {US_DO_ALL_FLAGS };
include/scsi/scsi_device.h +1 -0
@@ -179,6 +179,7 @@ struct scsi_device { unsigned try_rc_10_first:1; /* Try READ_CAPACACITY_10 first */ unsigned is_visible:1; /* is the device visible in sysfs */ unsigned wce_default_on:1; /* Cache is ON by default */ + unsigned always_sync:1; /* synchronize cache in every case*/ unsigned no_dif:1; /* T10 PI (DIF) should be disabled */ unsigned broken_fua:1; /* Don't set FUA bit */ unsigned lun_in_cdb:1; /* Store LUN bits in CDB[1] */
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Oliver" == Oliver Neukum <[email protected]> writes:
Oliver> Some SATA to USB bridges fail to cooperate with some drives Oliver> resulting in no cache being present being reported to the Oliver> host. That causes the host to skip sending a command to Oliver> synchronize caches. That causes data loss when the drive is Oliver> powered down.
Alan?
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Quoted 9 lines · Martin K. Petersen
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Oliver" == Oliver Neukum <[email protected]> writes:
Oliver> Some SATA to USB bridges fail to cooperate with some drives Oliver> resulting in no cache being present being reported to the Oliver> host. That causes the host to skip sending a command to Oliver> synchronize caches. That causes data loss when the drive is Oliver> powered down.
Alan?
Oliver originally submitted this at least a month ago. I don't see any changes since then, so:
Alan Stern
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Oliver" == Oliver Neukum <[email protected]> writes:
Oliver> Some SATA to USB bridges fail to cooperate with some drives Oliver> resulting in no cache being present being reported to the Oliver> host. That causes the host to skip sending a command to Oliver> synchronize caches. That causes data loss when the drive is Oliver> powered down.
include/scsi/scsi_device.h +1 -0
@@ -179,6 +179,7 @@ struct scsi_device { unsigned try_rc_10_first:1; /* Try READ_CAPACACITY_10 first */ unsigned is_visible:1; /* is the device visible in sysfs */ unsigned wce_default_on:1; /* Cache is ON by default */ + unsigned always_sync:1; /* synchronize cache in every case*/ unsigned no_dif:1; /* T10 PI (DIF) should be disabled */ unsigned broken_fua:1; /* Don't set FUA bit */ unsigned lun_in_cdb:1; /* Store LUN bits in CDB[1] */
I must be missing something. How is always_sync different from just setting wce_default_on?
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Quoted 21 lines · Martin K. Petersen
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Oliver" == Oliver Neukum <oneukum-IBi9RG/[email protected]> writes:
Oliver> Some SATA to USB bridges fail to cooperate with some drives Oliver> resulting in no cache being present being reported to the Oliver> host. That causes the host to skip sending a command to Oliver> synchronize caches. That causes data loss when the drive is Oliver> powered down.
include/scsi/scsi_device.h +1
-0@@ -179,6 +179,7 @@ struct scsi_device { unsigned try_rc_10_first:1; /* Try READ_CAPACACITY_10 first */ unsigned is_visible:1; /* is the device visible in sysfs */ unsigned wce_default_on:1; /* Cache is ON by default */ + unsigned always_sync:1; /* synchronize cache in every case*/ unsigned no_dif:1; /* T10 PI (DIF) should be disabled */ unsigned broken_fua:1; /* Don't set FUA bit */ unsigned lun_in_cdb:1; /* Store LUN bits in CDB[1] */
Quoted 2 lines
I must be missing something. How is
always_syncdifferent from just settingwce_default_on?
Hi,
wce_default_on controls the default if the device provides no indication. The problem here is that the indication the device provides must be overridden, as they are false.
Regards
Oliver
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Oliver" == Oliver Neukum <oneukum-IBi9RG/[email protected]> writes:
Oliver,
Oliver> wce_default_on controls the default if the device provides no Oliver> indication. The problem here is that the indication the device Oliver> provides must be overridden, as they are false.
Can't you just blacklist the mode select on the device in question?
Something like:
if (us->fflags & US_FL_ALWAYS_SYNC) {
sdev->skip_ms_page_3f = 1;
sdev->skip_ms_page_8 = 1;
sdev->wce_default_on = 1;
}?
Signature · 5 lines
Martin K. Petersen Oracle Linux Engineering -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 12 lines · Martin K. Petersen
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Oliver" == Oliver Neukum <oneukum-IBi9RG/[email protected]> writes:
Oliver,
Oliver>
wce_default_oncontrols the default if the device provides no Oliver> indication. The problem here is that the indication the device Oliver> provides must be overridden, as they are false.Can't you just blacklist the mode select on the device in question?
Something like:
Quoted 7 lines
if (us->fflags & US_FL_ALWAYS_SYNC) { sdev->skip_ms_page_3f = 1; sdev->skip_ms_page_8 = 1; sdev->wce_default_on = 1; }?
Hi,
this looks like a workable option. I am preparing a patch.
Regards
Oliver
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html