Skip to content

Commit 4475997

Browse files
im-0martinkpetersen
authored andcommitted
scsi: sd: Fix cache_type_store()
Changing of caching mode via /sys/devices/.../scsi_disk/.../cache_type may fail if device responds to MODE SENSE command with DPOFUA flag set, and then checks this flag to be not set on MODE SELECT command. In this scenario, when trying to change cache_type, write always fails: # echo "none" >cache_type bash: echo: write error: Invalid argument And following appears in dmesg: [13007.865745] sd 1:0:1:0: [sda] Sense Key : Illegal Request [current] [13007.865753] sd 1:0:1:0: [sda] Add. Sense: Invalid field in parameter list From SBC-4 r15, 6.5.1 "Mode pages overview", description of DEVICE-SPECIFIC PARAMETER field in the mode parameter header: ... The write protect (WP) bit for mode data sent with a MODE SELECT command shall be ignored by the device server. ... The DPOFUA bit is reserved for mode data sent with a MODE SELECT command. ... The remaining bits in the DEVICE-SPECIFIC PARAMETER byte are also reserved and shall be set to zero. [mkp: shuffled commentary to commit description] Cc: stable@vger.kernel.org Signed-off-by: Ivan Mironov <mironov.ivan@gmail.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent bfeffd1 commit 4475997

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/scsi/sd.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ cache_type_store(struct device *dev, struct device_attribute *attr,
206206
sp = buffer_data[0] & 0x80 ? 1 : 0;
207207
buffer_data[0] &= ~0x80;
208208

209+
/*
210+
* Ensure WP, DPOFUA, and RESERVED fields are cleared in
211+
* received mode parameter buffer before doing MODE SELECT.
212+
*/
213+
data.device_specific = 0;
214+
209215
if (scsi_mode_select(sdp, 1, sp, 8, buffer_data, len, SD_TIMEOUT,
210216
SD_MAX_RETRIES, &data, &sshdr)) {
211217
if (scsi_sense_valid(&sshdr))

0 commit comments

Comments
 (0)