Skip to contentSkip to conversation

scsi: sg: use queue_logical_block_size() in max_sectors_bytes()

PATCH In review Tom Yan 2 participants 4 messages Sep 23, 2020 – Sep 28, 2020

Subsystems (3)
lore
Share & tools
lore

Tom Yan

author
#0 lore raw

PATCH 1/2 scsi: sg: use queue_logical_block_size() in max_sectors_bytes()

Logical block size was never / is no longer necessarily 512.

---
 drivers/scsi/sg.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/scsi/sg.c +3 -2
index 20472aaaf630..8a2cca71017f 100644
@@ -848,10 +848,11 @@ static int srp_done(Sg_fd *sfp, Sg_request *srp)
 static int max_sectors_bytes(struct request_queue *q)
 {
 	unsigned int max_sectors = queue_max_sectors(q);
+	max_sectors *= queue_logical_block_size(q);
 
-	max_sectors = min_t(unsigned int, max_sectors, INT_MAX >> 9);
+	max_sectors = min_t(unsigned int, max_sectors, INT_MAX);
 
-	return max_sectors << 9;
+	return max_sectors;
 }
 
 static void
Signature · 1 line
2.28.0
author
#1 lore raw

PATCH 2/2 block/scsi_ioctl.c: use queue_logical_block_size() in max_sectors_bytes()

Logical block size was never / is no longer necessarily 512.

---
 block/scsi_ioctl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
block/scsi_ioctl.c +3 -2
index ef722f04f88a..82ed73f07460 100644
@@ -73,10 +73,11 @@ static int sg_set_timeout(struct request_queue *q, int __user *p)
 static int max_sectors_bytes(struct request_queue *q)
 {
 	unsigned int max_sectors = queue_max_sectors(q);
+	max_sectors *= queue_logical_block_size(q);
 
-	max_sectors = min_t(unsigned int, max_sectors, INT_MAX >> 9);
+	max_sectors = min_t(unsigned int, max_sectors, INT_MAX);
 
-	return max_sectors << 9;
+	return max_sectors;
 }
 
 static int sg_get_reserved_size(struct request_queue *q, int __user *p)
Signature · 1 line
2.28.0
#2 lore raw
In reply to Tom Yan
Quoted 13 lines · Tom Yan

Logical block size was never / is no longer necessarily 512.

---
 drivers/scsi/sg.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/scsi/sg.c +0 -0
index 20472aaaf630..8a2cca71017f 100644
@@ -848,10 +848,11 @@ static int srp_done(Sg_fd *sfp, Sg_request *srp)
 static int max_sectors_bytes(struct request_queue *q)

drivers/scsi/sg.c static int srp_done(Sg_fd *sfp, Sg_request *srp) · line 856

Quoted 10 lines
drivers/scsi/sg.c +3 -2
 {
 	unsigned int max_sectors = queue_max_sectors(q);
+	max_sectors *= queue_logical_block_size(q);
 
-	max_sectors = min_t(unsigned int, max_sectors, INT_MAX >> 9);
+	max_sectors = min_t(unsigned int, max_sectors, INT_MAX);
 
-	return max_sectors << 9;
+	return max_sectors;
 }

I think the above patch is wrong and also that it breaks code that is correct. In the Linux kernel, "one sector" is by definition 512 bytes. See also the definition of the SECTOR_SIZE and SECTOR_SHIFT constants.

Bart.

author
#3 lore raw

Oh right, that's what logical_to_sectors()'s for. Thanks! :-)

Quoted 31 lines · Bart Van Assche
Quoted 13 lines · Tom Yan

Logical block size was never / is no longer necessarily 512.

---
 drivers/scsi/sg.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/scsi/sg.c +0 -0
index 20472aaaf630..8a2cca71017f 100644
@@ -848,10 +848,11 @@ static int srp_done(Sg_fd *sfp, Sg_request *srp)
 static int max_sectors_bytes(struct request_queue *q)

drivers/scsi/sg.c static int srp_done(Sg_fd *sfp, Sg_request *srp) · line 856

Quoted 10 lines
drivers/scsi/sg.c +3 -2
 {
      unsigned int max_sectors = queue_max_sectors(q);
+     max_sectors *= queue_logical_block_size(q);
 
-     max_sectors = min_t(unsigned int, max_sectors, INT_MAX >> 9);
+     max_sectors = min_t(unsigned int, max_sectors, INT_MAX);
 
-     return max_sectors << 9;
+     return max_sectors;
 }

I think the above patch is wrong and also that it breaks code that is correct. In the Linux kernel, "one sector" is by definition 512 bytes. See also the definition of the SECTOR_SIZE and SECTOR_SHIFT constants.

Bart.