Skip to contentSkip to conversation

ide: Check validity of logical block size

PATCH Applied Kevin Wolf 3 participants 5 messages Dec 3, 2014

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 ide: Check validity of logical block size

Our IDE emulation can't handle logical block sizes other than 512. Check for it.

The original assumption was that other values would silently be ignored (which is bad enough), but it's not quite true: The physical block size is exposed in IDENTIFY DEVICE as a multiple of the logical block size. Setting a logical block size therefore also corrupts the physical block size (4096/4096 doesn't silently downgrade to 4096/512, but 512/512).

---
 hw/ide/qdev.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/ide/qdev.c +5 -0
index b4f096e..1ebb58d 100644
@@ -163,6 +163,11 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
         return -1;
     }
 
+    if (dev->conf.logical_block_size != 512) {
+        error_report("logical_block_size must be 512 for IDE");
+        return -1;
+    }
+
     blkconf_serial(&dev->conf, &dev->serial);
     if (kind != IDE_CD) {
         blkconf_geometry(&dev->conf, &dev->chs_trans, 65536, 16, 255, &err);
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Kevin Wolf

Our IDE emulation can't handle logical block sizes other than 512. Check for it.

I guess this is in part due to the 512 literals sprinkled all over the IDE code.

Quoted 7 lines

The original assumption was that other values would silently be ignored (which is bad enough), but it's not quite true: The physical block size is exposed in IDENTIFY DEVICE as a multiple of the logical block size. Setting a logical block size therefore also corrupts the physical block size (4096/4096 doesn't silently downgrade to 4096/512, but 512/512).

author
#2 lore raw

Am 03.12.2014 um 15:37 hat Markus Armbruster geschrieben:

Quoted 7 lines
Quoted 2 lines · Kevin Wolf

Our IDE emulation can't handle logical block sizes other than 512. Check for it.

I guess this is in part due to the 512 literals sprinkled all over the IDE code.

Yes, this is one part. The other part is where the 512 literals are missing and sector numbers are passed on to the block layer.

Kevin

Reviewed-by on v1 1/1
#3 lore raw
In reply to Kevin Wolf
Quoted 21 lines · Kevin Wolf

Our IDE emulation can't handle logical block sizes other than 512. Check for it.

The original assumption was that other values would silently be ignored (which is bad enough), but it's not quite true: The physical block size is exposed in IDENTIFY DEVICE as a multiple of the logical block size. Setting a logical block size therefore also corrupts the physical block size (4096/4096 doesn't silently downgrade to 4096/512, but 512/512).

---
  hw/ide/qdev.c | 5 +++++
  1 file changed, 5 insertions(+)
hw/ide/qdev.c +0 -0
index b4f096e..1ebb58d 100644
@@ -163,6 +163,11 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
          return -1;

hw/ide/qdev.c static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind) · line 173

Quoted 10 lines
hw/ide/qdev.c +5 -0
      }
 
+    if (dev->conf.logical_block_size != 512) {
+        error_report("logical_block_size must be 512 for IDE");
+        return -1;
+    }
+
      blkconf_serial(&dev->conf, &dev->serial);
      if (kind != IDE_CD) {
          blkconf_geometry(&dev->conf, &dev->chs_trans, 65536, 16, 255, &err);

There are so many 512 literals in the IDE code that I actually assumed we already enforced this, or otherwise just always used 512 regardless.

author Applied
#4 lore raw
In reply to Kevin Wolf

Am 03.12.2014 um 13:35 hat Kevin Wolf geschrieben:

Quoted 10 lines

Our IDE emulation can't handle logical block sizes other than 512. Check for it.

The original assumption was that other values would silently be ignored (which is bad enough), but it's not quite true: The physical block size is exposed in IDENTIFY DEVICE as a multiple of the logical block size. Setting a logical block size therefore also corrupts the physical block size (4096/4096 doesn't silently downgrade to 4096/512, but 512/512).

Applied to block-next.

Kevin