Skip to contentSkip to conversation

Revert "drivers: scsi: fix inaccurate block count reporting in scsi operations"

PATCH In review Tony Dinh 3 participants 12 messages Dec 9, 2025 – Dec 22, 2025 SCSI

lore
Share & tools
lore

Tony Dinh

author
#0 lore raw

PATCH 1/1 Revert "drivers: scsi: fix inaccurate block count reporting in scsi operations"

This reverts commit b32dda34506b4f486bc803d0c7251f987edd2455.

Currently, scsi is broken and causes data abort. I did a bisect and found that this commit was the cause. Reverting it and scsi is working again.

=== Error Log with data abort

U-Boot 2026.01-rc4-tld-1-g0e0a198a68be (Dec 08 2025 - 17:42:05 -0800) Synology DS116

DS116> scsi reset

Reset SCSI
scanning bus for devices...
Target spinup took 0 ms.
SATA link 1 timeout.
AHCI 0001.0000 32 slots 2 ports 6 Gbps 0x3 impl SATA mode
flags: 64bit ncq led only pmp fbss pio slum part sxs
Device 0: (0:0) Vendor: ATA Prod.: FUJITSU MHY2250B Rev: 890B
Type: Hard Disk
Capacity: 238475.1 MB = 232.8 GB (488397169 x 512)

DS116> ext2ls scsi 0:1 /boot
data abort

pc : [<3ffa5d3e>]	   lr : [<3ffc1515>]

sp : 3fb65ad8 ip : 0000000c fp : 3fb7f220
r10: 00002710 r9 : 3fb6aed0 r8 : 3fb85e40
r7 : f10a8100 r6 : 000003e8 r5 : 000003e8 r4 : 3fb65ae0
r3 : e38e39c1 r2 : 00000000 r1 : 3fb65ae0 r0 : 00931767
Flags: Nzcv IRQs off FIQs off Mode SVC_32 (T)

Code: 3ffd b510 6803 460c (6bdb) 681b

---

 drivers/scsi/scsi.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/scsi/scsi.c +7 -6
index b414d022f3f..715271b1d69 100644
@@ -228,11 +228,13 @@ static ulong scsi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
 			blocks = max_blks;
 			scsi_setup_read_ext(pccb, start, blocks);
 			start += max_blks;
+			blks -= max_blks;
 		} else {
 			pccb->datalen = block_dev->blksz * blks;
 			blocks = blks;
 			scsi_setup_read_ext(pccb, start, blocks);
 			start += blks;
+			blks = 0;
 		}
 		debug("scsi_read_ext: startblk " LBAF
 		      ", blccnt " LBAF " buffer %lX\n",
@@ -242,7 +244,6 @@ static ulong scsi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
 			blkcnt -= blks;
 			break;
 		}
-		blks -= blocks;
 		buf_addr += pccb->datalen;
 	} while (blks != 0);
 	debug("scsi_read_ext: end startblk " LBAF
@@ -285,11 +286,13 @@ static ulong scsi_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
 			blocks = max_blks;
 			scsi_setup_write_ext(pccb, start, blocks);
 			start += max_blks;
+			blks -= max_blks;
 		} else {
 			pccb->datalen = block_dev->blksz * blks;
 			blocks = blks;
 			scsi_setup_write_ext(pccb, start, blocks);
 			start += blks;
+			blks = 0;
 		}
 		debug("%s: startblk " LBAF ", blccnt " LBAF " buffer %lx\n",
 		      __func__, start, blocks, buf_addr);
@@ -298,7 +301,6 @@ static ulong scsi_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
 			blkcnt -= blks;
 			break;
 		}
-		blks -= blocks;
 		buf_addr += pccb->datalen;
 	} while (blks != 0);
 
@@ -320,7 +322,7 @@ static ulong scsi_erase(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt)
 	struct blk_desc *block_dev = dev_get_uclass_plat(dev);
 	struct udevice *bdev = dev->parent;
 	struct scsi_plat *uc_plat = dev_get_uclass_plat(bdev);
-	lbaint_t start, blks, max_blks, blocks;
+	lbaint_t start, blks, max_blks;
 	struct scsi_cmd *pccb = (struct scsi_cmd *)&tempccb;
 
 	/* Setup device */
@@ -337,20 +339,19 @@ static ulong scsi_erase(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt)
 	      __func__, block_dev->devnum, start, blks);
 	do {
 		if (blks > max_blks) {
-			blocks = max_blks;
 			scsi_setup_erase_ext(pccb, start, max_blks);
 			start += max_blks;
+			blks -= max_blks;
 		} else {
-			blocks = blks;
 			scsi_setup_erase_ext(pccb, start, blks);
 			start += blks;
+			blks = 0;
 		}
 		if (scsi_exec(bdev, pccb)) {
 			scsi_print_error(pccb);
 			blkcnt -= blks;
 			break;
 		}
-		blks -= blocks;
 	} while (blks != 0);
 	return blkcnt;
 }
Signature · 4 lines
2.47.3

base-commit: 0e0a198a68be71148f5ec27ef86796174f91436f
branch: master
#1 lore raw
Quoted 25 lines · Tony Dinh

This reverts commit b32dda34506b4f486bc803d0c7251f987edd2455.

Currently, scsi is broken and causes data abort. I did a bisect and found that this commit was the cause. Reverting it and scsi is working again.

=== Error Log with data abort

U-Boot 2026.01-rc4-tld-1-g0e0a198a68be (Dec 08 2025 - 17:42:05 -0800) Synology DS116

DS116> scsi reset

Reset SCSI
scanning bus for devices...
Target spinup took 0 ms.
SATA link 1 timeout.
AHCI 0001.0000 32 slots 2 ports 6 Gbps 0x3 impl SATA mode
flags: 64bit ncq led only pmp fbss pio slum part sxs
Device 0: (0:0) Vendor: ATA Prod.: FUJITSU MHY2250B Rev: 890B
Type: Hard Disk
Capacity: 238475.1 MB = 232.8 GB (488397169 x 512)

DS116> ext2ls scsi 0:1 /boot
data abort

pc : [<3ffa5d3e>]	   lr : [<3ffc1515>]
Quoted 8 lines

sp : 3fb65ad8 ip : 0000000c fp : 3fb7f220
r10: 00002710 r9 : 3fb6aed0 r8 : 3fb85e40
r7 : f10a8100 r6 : 000003e8 r5 : 000003e8 r4 : 3fb65ae0
r3 : e38e39c1 r2 : 00000000 r1 : 3fb65ae0 r0 : 00931767
Flags: Nzcv IRQs off FIQs off Mode SVC_32 (T)

Code: 3ffd b510 6803 460c (6bdb) 681b

Any comments Balaji ?

Signature · 1 line
Tom
#2 lore raw
Quoted 34 lines · Tom Rini
Quoted 32 lines · Tony Dinh

This reverts commit b32dda34506b4f486bc803d0c7251f987edd2455.

Currently, scsi is broken and causes data abort. I did a bisect and found that this commit was the cause. Reverting it and scsi is working again.

=== Error Log with data abort

U-Boot 2026.01-rc4-tld-1-g0e0a198a68be (Dec 08 2025 - 17:42:05 -0800) Synology DS116

DS116> scsi reset

Reset SCSI
scanning bus for devices...
Target spinup took 0 ms.
SATA link 1 timeout.
AHCI 0001.0000 32 slots 2 ports 6 Gbps 0x3 impl SATA mode
flags: 64bit ncq led only pmp fbss pio slum part sxs
Device 0: (0:0) Vendor: ATA Prod.: FUJITSU MHY2250B Rev: 890B
Type: Hard Disk
Capacity: 238475.1 MB = 232.8 GB (488397169 x 512)

DS116> ext2ls scsi 0:1 /boot
data abort

pc : [<3ffa5d3e>]	   lr : [<3ffc1515>]

sp : 3fb65ad8 ip : 0000000c fp : 3fb7f220
r10: 00002710 r9 : 3fb6aed0 r8 : 3fb85e40
r7 : f10a8100 r6 : 000003e8 r5 : 000003e8 r4 : 3fb65ae0
r3 : e38e39c1 r2 : 00000000 r1 : 3fb65ae0 r0 : 00931767
Flags: Nzcv IRQs off FIQs off Mode SVC_32 (T)

Code: 3ffd b510 6803 460c (6bdb) 681b
Quoted 3 lines
Quoted 1 line

Any comments Balaji ?

Again, any comments Balaji? I'm otherwise inclined to take this revert this week and sort things out again in the next branch / post v2026.01.

Signature · 1 line
Tom
#3 lore raw

Hi Tom,

Apologies for late reply. Somehow missed the mail.

Upon analysis, it seems the most likely root cause is Tony's 238GB disk triggers the CONFIG_SYS_64BIT_LBA code path in scsi_read function. Any read beyond block 268,435,455 blocks enters this path.

'blks' is decremented both inside the 64-bit LBA block AND after successful scsi_exec(), causing incorrect block count tracking and (most likely) the data abort observed.

The fix is to remove 'blks -= blocks;' from inside the CONFIG_SYS_64BIT_LBA block in scsi_read() function.

Hi Tony, can you please check with this change?

Tom, shall I raise a new patch for this now?

Regards,

Balaji

Quoted 40 lines · Tom Rini
Quoted 34 lines · Tom Rini
Quoted 32 lines · Tony Dinh

This reverts commit b32dda34506b4f486bc803d0c7251f987edd2455.

Currently, scsi is broken and causes data abort. I did a bisect and found that this commit was the cause. Reverting it and scsi is working again.

=== Error Log with data abort

U-Boot 2026.01-rc4-tld-1-g0e0a198a68be (Dec 08 2025 - 17:42:05 -0800) Synology DS116

DS116> scsi reset

Reset SCSI
scanning bus for devices...
Target spinup took 0 ms.
SATA link 1 timeout.
AHCI 0001.0000 32 slots 2 ports 6 Gbps 0x3 impl SATA mode
flags: 64bit ncq led only pmp fbss pio slum part sxs
Device 0: (0:0) Vendor: ATA Prod.: FUJITSU MHY2250B Rev: 890B
Type: Hard Disk
Capacity: 238475.1 MB = 232.8 GB (488397169 x 512)

DS116> ext2ls scsi 0:1 /boot
data abort

pc : [<3ffa5d3e>]	   lr : [<3ffc1515>]

sp : 3fb65ad8 ip : 0000000c fp : 3fb7f220
r10: 00002710 r9 : 3fb6aed0 r8 : 3fb85e40
r7 : f10a8100 r6 : 000003e8 r5 : 000003e8 r4 : 3fb65ae0
r3 : e38e39c1 r2 : 00000000 r1 : 3fb65ae0 r0 : 00931767
Flags: Nzcv IRQs off FIQs off Mode SVC_32 (T)

Code: 3ffd b510 6803 460c (6bdb) 681b
Quoted 2 lines
Quoted 1 line

Any comments Balaji ?

Again, any comments Balaji? I'm otherwise inclined to take this revert this week and sort things out again in the next branch / post v2026.01.

#4 lore raw
Quoted 12 lines · Balaji Selvanathan

Hi Tom,

Apologies for late reply. Somehow missed the mail.

Upon analysis, it seems the most likely root cause is Tony's 238GB disk triggers the CONFIG_SYS_64BIT_LBA code path in scsi_read function. Any read beyond block 268,435,455 blocks enters this path.

'blks' is decremented both inside the 64-bit LBA block AND after successful scsi_exec(), causing incorrect block count tracking and (most likely) the data abort observed.

Quoted 6 lines

The fix is to remove 'blks -= blocks;' from inside the CONFIG_SYS_64BIT_LBA block in scsi_read() function.

Hi Tony, can you please check with this change?

Tom, shall I raise a new patch for this now?

Thanks for looking in to this now. Yes, please post a proper patch for it so Tony can test and add a Tested-by if it works, that'll make pulling to master before release easiest.

Signature · 1 line
Tom
author
#5 lore raw

Hi Balaji,

Quoted 17 lines · Tom Rini
Quoted 15 lines · Balaji Selvanathan

Hi Tom,

Apologies for late reply. Somehow missed the mail.

Upon analysis, it seems the most likely root cause is Tony's 238GB disk triggers the CONFIG_SYS_64BIT_LBA code path in scsi_read function. Any read beyond block 268,435,455 blocks enters this path.

'blks' is decremented both inside the 64-bit LBA block AND after successful scsi_exec(), causing incorrect block count tracking and (most likely) the data abort observed.

The fix is to remove 'blks -= blocks;' from inside the CONFIG_SYS_64BIT_LBA block in scsi_read() function.

Quoted 7 lines
Quoted 3 lines

Hi Tony, can you please check with this change?

Tom, shall I raise a new patch for this now?

Thanks for looking in to this now. Yes, please post a proper patch for it so Tony can test and add a Tested-by if it works, that'll make pulling to master before release easiest.

FYI, I will be traveling a week from now. So it would be best if you can send the patch in the next couple days. Otherwise, someone else needs to do the test in time for the Jan 05 release.

All the best,
Tony

Quoted 3 lines

--
Tom

author
#6 lore raw

Hi Balaji,

Quoted 22 lines · Tony Dinh

Hi Balaji,

Quoted 18 lines · Tom Rini
Quoted 16 lines · Balaji Selvanathan

Hi Tom,

Apologies for late reply. Somehow missed the mail.

Upon analysis, it seems the most likely root cause is Tony's 238GB disk triggers the CONFIG_SYS_64BIT_LBA code path in scsi_read function. Any read beyond block 268,435,455 blocks enters this path.

'blks' is decremented both inside the 64-bit LBA block AND after successful scsi_exec(), causing incorrect block count tracking and (most likely) the data abort observed.

The fix is to remove 'blks -= blocks;' from inside the CONFIG_SYS_64BIT_LBA block in scsi_read() function.

Hi Tony, can you please check with this change?

Confirmed that the above fix works fine! I was able to boot the Linux kernel from the 238GB HDD.

All the best,
Tony

Quoted 17 lines
Quoted 6 lines
Quoted 2 lines

Tom, shall I raise a new patch for this now?

Thanks for looking in to this now. Yes, please post a proper patch for it so Tony can test and add a Tested-by if it works, that'll make pulling to master before release easiest.

FYI, I will be traveling a week from now. So it would be best if you can send the patch in the next couple days. Otherwise, someone else needs to do the test in time for the Jan 05 release.

All the best,
Tony

Quoted 3 lines

--
Tom

#7 lore raw
Quoted 22 lines · Tony Dinh

Hi Balaji,

Quoted 19 lines · Tony Dinh

Hi Balaji,

Quoted 16 lines · Tom Rini
Quoted 15 lines · Balaji Selvanathan

Hi Tom,

Apologies for late reply. Somehow missed the mail.

Upon analysis, it seems the most likely root cause is Tony's 238GB disk triggers the CONFIG_SYS_64BIT_LBA code path in scsi_read function. Any read beyond block 268,435,455 blocks enters this path.

'blks' is decremented both inside the 64-bit LBA block AND after successful scsi_exec(), causing incorrect block count tracking and (most likely) the data abort observed.

The fix is to remove 'blks -= blocks;' from inside the CONFIG_SYS_64BIT_LBA block in scsi_read() function.

Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

Hi Tony, can you please check with this change?

Confirmed that the above fix works fine! I was able to boot the Linux kernel from the 238GB HDD.

All the best,
Tony

Thanks Tony for testing.

Quoted 14 lines
Quoted 14 lines
Quoted 5 lines
Quoted 2 lines

Tom, shall I raise a new patch for this now?

Thanks for looking in to this now. Yes, please post a proper patch for it so Tony can test and add a Tested-by if it works, that'll make pulling to master before release easiest.

FYI, I will be traveling a week from now. So it would be best if you can send the patch in the next couple days. Otherwise, someone else needs to do the test in time for the Jan 05 release.

All the best,
Tony

Quoted 2 lines

--
Tom

#8 lore raw
In reply to Tony Dinh
Quoted 21 lines · Tony Dinh

Hi Balaji,

Quoted 18 lines · Tom Rini
Quoted 17 lines · Balaji Selvanathan

Hi Tom,

Apologies for late reply. Somehow missed the mail.

Upon analysis, it seems the most likely root cause is Tony's 238GB disk triggers the CONFIG_SYS_64BIT_LBA code path in scsi_read function. Any read beyond block 268,435,455 blocks enters this path.

'blks' is decremented both inside the 64-bit LBA block AND after successful scsi_exec(), causing incorrect block count tracking and (most likely) the data abort observed.

The fix is to remove 'blks -= blocks;' from inside the CONFIG_SYS_64BIT_LBA block in scsi_read() function.

Hi Tony, can you please check with this change?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Tom, shall I raise a new patch for this now?

Thanks for looking in to this now. Yes, please post a proper patch for it so Tony can test and add a Tested-by if it works, that'll make pulling to master before release easiest.

FYI, I will be traveling a week from now. So it would be best if you can send the patch in the next couple days. Otherwise, someone else needs to do the test in time for the Jan 05 release.

Hi Tony,

Have posted patch for this: https://lore.kernel.org/u-boot/[email protected]/

Request you to add Tested-by acknowledgement.

Regards,

Balaji

Quoted 6 lines

All the best,
Tony

Quoted 2 lines

--
Tom

author
#9 lore raw

Hi Balaji,

Quoted 32 lines · Balaji Selvanathan
Quoted 21 lines · Tony Dinh

Hi Balaji,

Quoted 18 lines · Tom Rini
Quoted 17 lines · Balaji Selvanathan

Hi Tom,

Apologies for late reply. Somehow missed the mail.

Upon analysis, it seems the most likely root cause is Tony's 238GB disk triggers the CONFIG_SYS_64BIT_LBA code path in scsi_read function. Any read beyond block 268,435,455 blocks enters this path.

'blks' is decremented both inside the 64-bit LBA block AND after successful scsi_exec(), causing incorrect block count tracking and (most likely) the data abort observed.

The fix is to remove 'blks -= blocks;' from inside the CONFIG_SYS_64BIT_LBA block in scsi_read() function.

Hi Tony, can you please check with this change?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Tom, shall I raise a new patch for this now?

Thanks for looking in to this now. Yes, please post a proper patch for it so Tony can test and add a Tested-by if it works, that'll make pulling to master before release easiest.

FYI, I will be traveling a week from now. So it would be best if you can send the patch in the next couple days. Otherwise, someone else needs to do the test in time for the Jan 05 release.

Quoted 6 lines

Hi Tony,

Have posted patch for this:
https://lore.kernel.org/u-boot/[email protected]/

Request you to add Tested-by acknowledgement.

Could you also send this patch to my email so I can reply and add Tested-by?

All the best,
Tony

Quoted 11 lines

Regards,

Balaji

Quoted 6 lines

All the best,
Tony

Quoted 2 lines

--
Tom

#10 lore raw
Quoted 36 lines · Tony Dinh

Hi Balaji,

Quoted 32 lines · Balaji Selvanathan
Quoted 21 lines · Tony Dinh

Hi Balaji,

Quoted 18 lines · Tom Rini
Quoted 17 lines · Balaji Selvanathan

Hi Tom,

Apologies for late reply. Somehow missed the mail.

Upon analysis, it seems the most likely root cause is Tony's 238GB disk triggers the CONFIG_SYS_64BIT_LBA code path in scsi_read function. Any read beyond block 268,435,455 blocks enters this path.

'blks' is decremented both inside the 64-bit LBA block AND after successful scsi_exec(), causing incorrect block count tracking and (most likely) the data abort observed.

The fix is to remove 'blks -= blocks;' from inside the CONFIG_SYS_64BIT_LBA block in scsi_read() function.

Hi Tony, can you please check with this change?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Tom, shall I raise a new patch for this now?

Thanks for looking in to this now. Yes, please post a proper patch for it so Tony can test and add a Tested-by if it works, that'll make pulling to master before release easiest.

FYI, I will be traveling a week from now. So it would be best if you can send the patch in the next couple days. Otherwise, someone else needs to do the test in time for the Jan 05 release.

Hi Tony,

Quoted 8 lines
Quoted 4 lines

Have posted patch for this:
https://lore.kernel.org/u-boot/[email protected]/

Request you to add Tested-by acknowledgement.

Could you also send this patch to my email so I can reply and add Tested-by?

All the best,
Tony

Have sent version v2 to your mail id: https://lore.kernel.org/u-boot/[email protected]/

Regards,

Balaji

Quoted 10 lines
Quoted 10 lines

Regards,

Balaji

Quoted 5 lines

All the best,
Tony

Quoted 2 lines

--
Tom

#11 lore raw
In reply to Tom Rini
Quoted 16 lines · Tom Rini
Quoted 15 lines · Balaji Selvanathan

Hi Tom,

Apologies for late reply. Somehow missed the mail.

Upon analysis, it seems the most likely root cause is Tony's 238GB disk triggers the CONFIG_SYS_64BIT_LBA code path in scsi_read function. Any read beyond block 268,435,455 blocks enters this path.

'blks' is decremented both inside the 64-bit LBA block AND after successful scsi_exec(), causing incorrect block count tracking and (most likely) the data abort observed.

The fix is to remove 'blks -= blocks;' from inside the CONFIG_SYS_64BIT_LBA block in scsi_read() function.

Quoted 6 lines
Quoted 3 lines

Hi Tony, can you please check with this change?

Tom, shall I raise a new patch for this now?

Thanks for looking in to this now. Yes, please post a proper patch for it so Tony can test and add a Tested-by if it works, that'll make pulling to master before release easiest.

Hi Tom,

Have posted patch for this: https://lore.kernel.org/u-boot/[email protected]/

Regards,

Balaji

Quoted 1 line