Re: BUG in kernel: Wrong Handling of USB HDDâs in scsiglue(slave_configure) and scsi/sd(sd_read_cache_type)

From: NamJae Jeon
Date: Fri Sep 30 2011 - 03:06:19 EST


2011/9/30 Amit Sahrawat <amit.sahrawat83@xxxxxxxxx>:
> Hi James,
>
> [root@localhost Tools]# sg_inq --page=0x0 /dev/sdb
> ÂOnly hex output supported. sg_vpd decodes more pages.
> VPD INQUIRY, page code=0x00:
> Â [PQual=0 ÂPeripheral device type: disk]
> Â Supported VPD pages:
> Â Â 0x1f
> [root@localhost Tools]#
>
>
>
> [root@localhost Tools]# sg_modes --page=0x3f /dev/sdb
> Â ÂSAMSUNG Â HM501IX Â Â Â Â Â Â Âperipheral_type: disk [0x0]
> Mode parameter header from MODE SENSE(10):
> ÂMode data length=66, medium type=0x00, WP=0, DpoFua=0, longlba=0
> ÂBlock descriptor length=0
>>> Read-Write error recovery, page_control: current
> Â00 Â Â 01 0a 00 00 00 00 00 00 Â00 00 00 00
>>> Flexible geometry (obsolete), page_control: current
> Â00 Â Â 05 0a ff ff 10 3f 02 00 Â3f ff 00 00
>>> Caching, page_control: current
> Â00 Â Â 08 12 00 00 00 00 00 00 Â00 00 00 00 01 00 00 00
> Â10 Â Â 00 00 00 00
>>> page_code: 0x1b, page_control: current
> Â00 Â Â 1b 0a 00 01 00 00 00 00 Â00 00 00 00
>>> Unit Attention condition [vendor specific format], page_control: current
> Â00 Â Â 00 00
> [root@localhost Tools]#
>
>
>
> [root@localhost Tools]# sginfo -A /dev/sdb
> INQUIRY response (cmd: 0x12)
> ----------------------------
> Device Type            Â0
> Vendor: Â Â Â Â Â Â Â Â Â ÂSAMSUNG
> Product: Â Â Â Â Â Â Â Â Â HM501IX
> Revision level:
>
> No serial number (bad format for supported VPDs)
>
> Read-Write Error Recovery mode page (0x1)
> -----------------------------------------
> AWRE Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0
> ARRE Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0
> TB Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0
> RC Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0
> EER Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â0
> PER Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â0
> DTE Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â0
> DCR Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â0
> Read Retry Count          0
> Correction Span          Â0
> Head Offset Count         Â0
> Data Strobe Offset Count      0
> Write Retry Count         Â0
> Recovery Time Limit (ms) Â Â Â Â Â 0
>
> mode page: 0x05 Â [Flexible Disk]
> ---------------
> 0x02 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0xff
> 0x03 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0xff
> 0x04 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0x10
> 0x05 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0x3f
> 0x06 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0x02
> 0x07 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0x00
> 0x08 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0x3f
> 0x09 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0xff
> 0x0a                0x00
> 0x0b                0x00
>
> Caching mode page (0x8)
> -----------------------
> Initiator Control         Â0
> ABPF Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0
> CAP Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â0
> DISC Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0
> SIZE Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0
> Write Cache Enabled        Â0
> MF Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0
> Read Cache Disabled        Â0
> Demand Read Retention Priority   0
> Demand Write Retention Priority  Â0
> Disable Pre-fetch Transfer Length Â0
> Minimum Pre-fetch         Â0
> Maximum Pre-fetch         Â0
> Maximum Pre-fetch Ceiling     Â0
> FSW Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â0
> LBCSS Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â0
> DRA Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â0
> NV_DIS Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1
> Number of Cache Segments      0
> Cache Segment size         0
> Non-Cache Segment size       0
>
> mode page: 0x1b
> ---------------
> 0x02 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0x00
> 0x03 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0x01
> 0x04 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0x00
> 0x05 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0x00
> 0x06 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0x00
> 0x07 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0x00
> 0x08 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0x00
> 0x09 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0x00
> 0x0a                0x00
> 0x0b                0x00
>
> mode page: 0x00 Â [Vendor (non-page format)]
> ---------------
> 0x00 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0x00
> 0x01 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 0x00
>
> [root@localhost Tools]#
>
> Comparision for USB HDD and Normal Hard disk connected to system.(For
> USB HDD it showing Write Cache - False, for normal Hard disk - Write
> Cache - True)
> [root@localhost Tools]# sg_modes --page=0x3f /dev/sdb
> Â ÂSAMSUNG Â HM501IX Â Â Â Â Â Â Âperipheral_type: disk [0x0]
> Mode parameter header from MODE SENSE(10):
> ÂMode data length=66, medium type=0x00, WP=0, DpoFua=0, longlba=0
> ÂBlock descriptor length=0
>>> Read-Write error recovery, page_control: current
> Â00 Â Â 01 0a 00 00 00 00 00 00 Â00 00 00 00
>>> Flexible geometry (obsolete), page_control: current
> Â00 Â Â 05 0a ff ff 10 3f 02 00 Â3f ff 00 00
>>> Caching, page_control: current
> Â00 Â Â 08 12 00 00 00 00 00 00 Â00 00 00 00 01 00 00 00
> Â10 Â Â 00 00 00 00
>>> page_code: 0x1b, page_control: current
> Â00 Â Â 1b 0a 00 01 00 00 00 00 Â00 00 00 00
>>> Unit Attention condition [vendor specific format], page_control: current
> Â00 Â Â 00 00
> [root@localhost Tools]# sg_modes --page=0x3f /dev/sda
> Â ÂATA Â Â Â SAMSUNG HD502HJ Â 1AJ1 Â peripheral_type: disk [0x0]
> Mode parameter header from MODE SENSE(10):
> ÂMode data length=60, medium type=0x00, WP=0, DpoFua=0, longlba=0
> ÂBlock descriptor length=8
>> Direct access device block descriptors:
> Â Density code=0x0
> Â00 Â Â 00 00 00 00 00 00 02 00
>
>>> Read-Write error recovery, page_control: current
> Â00 Â Â 01 0a 80 00 00 00 00 00 Â00 00 00 00
>>> Caching, page_control: current
> Â00 Â Â 08 12 04 00 00 00 00 00 Â00 00 00 00 00 00 00 00
> Â10 Â Â 00 00 00 00
>>> Control, page_control: current
> Â00 Â Â 0a 0a 02 00 00 00 00 00 Âff ff 00 1e
> [root@localhost Tools]#
>
> Now, for the USB HDD which do have write cache - sginfo is showing
> them to Write Cache Enabled as false.
> Why do the result of hdparm identification and sginfo varies- (I know
> they have different interface to work with and hdparm takes care of
> that by using SG_IO interface from it's code)? hdparm showed me
> correct results - that lead me to digging in the kernel code and
> checking the performance for USB HDD with Write cache enabled/disabled
> - which also showed that QUEUE ordering chosen for USB HDD is not
> correct.
> I have a large number of USB HDD's - with different vendors, and for
> all of them - it is showing Write Cache Enabled as false.
> The code works only for the Pen Drives or the USB HDD which do not
> have internal cache.
>
> Also, for journalling filesystem being used on USB HDD - it does
> becomes a cause of concern.
Filesystem can not prevent important data(ex, jounal data) by wrtite
barrier on this issue.
write barrier should be also support on USB HDD(usb driver) like ATA driver.
>
> Please share your opinion, I guess we need a change for mode sensing
> in the kernel code for USB HDD.
>
> Thanks & Regards,
> Amit Sahrawat
>
>
>
> On Fri, Sep 30, 2011 at 12:01 AM, James Bottomley
> <James.Bottomley@xxxxxxxxxxxxxxxxxxxxx> wrote:
>> On Thu, 2011-09-29 at 13:27 -0500, James Bottomley wrote:
>>> On Thu, 2011-09-29 at 14:49 +0530, Amit Sahrawat wrote:
>>> > The patch did not work, although it did get pass the earlier condition
>>> > which I mentioned- but still Write Cache is not taken into account â
>>> > seems mode sensing in sd_read_cache_type() does not send proper
>>> > request to the device â or does not read in proper bytes for this(as
>>> > per hdparm command analysis):
>>> >
>>> > Logs After Connecting:
>>> > scsi 0:0:0:0: Direct-Access   Seagate ÂPortable     0130 PQ: 0 ANSI: 4
>>> > sd 0:0:0:0: [sda] 488397168 512-byte logical blocks: (250 GB/232 GiB)
>>> > sd 0:0:0:0: [sda] Write Protect is off
>>> > sd 0:0:0:0: [sda] No Caching mode page present
>>>
>>> This line means that a request for page 0x0 didn't turn up the caching
>>> mode page in the list of supported pages.
>>>
>>> What does
>>>
>>> sg_inq Â--page=0x0 /dev/sda
>>
>> Um, lets try that again, this time with the correct information. ÂWhat
>> we're looking for is the list of mode pages, so
>>
>> sg_modes --page=0x3f /dev/sda
>>
>> Should return it.
>>
>> Thanks,
>>
>> James
>>
>>
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
> Please read the FAQ at Âhttp://www.tux.org/lkml/
>
èº{.nÇ+‰·Ÿ®‰­†+%ŠËlzwm…ébëæìr¸›zX§»®w¥Š{ayºÊÚë,j­¢f£¢·hš‹àz¹®w¥¢¸ ¢·¦j:+v‰¨ŠwèjØm¶Ÿÿ¾«‘êçzZ+ƒùšŽŠÝj"ú!¶iO•æ¬z·švØ^¶m§ÿðà nÆàþY&—