Skip to contentSkip to conversation

sd: Clear PS bit before Mode Select.

PATCH Applied Gabriel Krisman Bertazi 2 participants 2 messages Oct 30, 2015 – Nov 12, 2015 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sd: Clear PS bit before Mode Select.

According to SPC-4, in a Mode Select, the PS bit in Mode Pages is reserved and must be set to 0 by the driver. In the sd implementation, function cache_type_store does a Mode Sense, which might set the PS bit on the read buffer, followed by a Mode Select, which receives the same buffer, without explicitly clearing the PS bit. So, in cases where target supports saving the Mode Page to a non-volatile location, we end up doing a Mode Select with the PS bit set, which could cause an illegal request error if the target is checking this.

This was observed on a new firmware change, which was subsequently reverted, but this changes sd.c to be more compliant with SPC-4.

This patch clears the PS bit in the buffer returned by Mode Select, right before it is used in the Mode Select command.

---
 drivers/scsi/sd.c | 1 +
 1 file changed, 1 insertion(+)
drivers/scsi/sd.c +1 -0
index 3f37022..f724777 100644
@@ -204,6 +204,7 @@ cache_type_store(struct device *dev, struct device_attribute *attr,
 	buffer_data[2] &= ~0x05;
 	buffer_data[2] |= wce << 2 | rcd;
 	sp = buffer_data[0] & 0x80 ? 1 : 0;
+	buffer_data[0] &= ~0x80;
 
 	if (scsi_mode_select(sdp, 1, sp, 8, buffer_data, len, SD_TIMEOUT,
 			     SD_MAX_RETRIES, &data, &sshdr)) {
Signature · 1 line
2.1.0
#1 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Gabriel" == Gabriel Krisman Bertazi <[email protected]> writes:

Gabriel> This patch clears the PS bit in the buffer returned by Mode Gabriel> Select, right before it is used in the Mode Select command.

Applied.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering