Skip to contentSkip to conversation

hw/sparc64/niagara: use int64_t for vdisk size to avoid truncation

PATCH Applied Dmitry Pimenov 4 participants 6 messages Jul 11 – Jul 27

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/sparc64/niagara: use int64_t for vdisk size to avoid truncation

blk_getlength() returns int64_t, but niagara_init() stored it in an int, truncating the if=pflash virtual-ramdisk size for images >= 2 GiB. A ~4 GiB image truncated to 0/negative, failed the size > 0 check, and exit(1)'d before the CPU ran, ending with:

qemu-system-sparc64: could not load ram disk

AI-used-for: code (bug fix)

---
 hw/sparc64/niagara.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/sparc64/niagara.c +1 -1
index 1211ecb82d..ad5e5945a8 100644
@@ -137,7 +137,7 @@ static void niagara_init(MachineState *machine)
        outside of the partition RAM */
     if (dinfo) {
         BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
-        int size = blk_getlength(blk);
+        int64_t size = blk_getlength(blk);
         if (size > 0) {
             memory_region_init_ram(&s->vdisk_ram, NULL, "sun4v_vdisk.ram", size,
                                    &error_fatal);

--
2.43.0

Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Dmitry Pimenov

blk_getlength() returns int64_t, but niagara_init() stored it in an int, truncating the if=pflash virtual-ramdisk size for images >= 2 GiB. A ~4 GiB image truncated to 0/negative, failed the size > 0 check, and exit(1)'d before the CPU ran, ending with:

qemu-system-sparc64: could not load ram disk

AI-used-for: code (bug fix)

---
  hw/sparc64/niagara.c | 2 +-
#2 lore raw
In reply to Dmitry Pimenov
Quoted 11 lines · Dmitry Pimenov

blk_getlength() returns int64_t, but niagara_init() stored it in an int, truncating the if=pflash virtual-ramdisk size for images >= 2 GiB. A ~4 GiB image truncated to 0/negative, failed the size > 0 check, and exit(1)'d before the CPU ran, ending with:

qemu-system-sparc64: could not load ram disk

AI-used-for: code (bug fix)

---
  hw/sparc64/niagara.c | 2 +-

Queued, thanks.

Acked-by on v1 1/1
#3 lore raw
In reply to Dmitry Pimenov
Quoted 26 lines · Dmitry Pimenov

blk_getlength() returns int64_t, but niagara_init() stored it in an int, truncating the if=pflash virtual-ramdisk size for images >= 2 GiB. A ~4 GiB image truncated to 0/negative, failed the size > 0 check, and exit(1)'d before the CPU ran, ending with:

qemu-system-sparc64: could not load ram disk

AI-used-for: code (bug fix)

---
  hw/sparc64/niagara.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/sparc64/niagara.c +1 -2
index 1211ecb82d..ad5e5945a8 100644
@@ -137,7 +137,7 @@ static void niagara_init(MachineState *machine)
         outside of the partition RAM */
      if (dinfo) {
          BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
-        int size = blk_getlength(blk);
+        int64_t size = blk_getlength(blk);
          if (size > 0) {
              memory_region_init_ram(&s->vdisk_ram, NULL, "sun4v_vdisk.ram", size,
                                     &error_fatal);
--
Quoted 1 line

2.43.0

Oh, curious - is this a static/AI analysis find, or are you actively using the sun4v emulation? Anyhow:

ATB,

Mark.

#4 lore raw

Sorry for the late follow-up
Answering directly since it's still an open question: the bug was found by actually booting a >=2GiB pflash image against -M niagara and hitting the exact symptom described: exit(1) before the CPU ever ran, no OpenBoot output at all.
Tracing that to blk_getlength() returning int64_t while niagara_init() stored it in a plain int came after, as the explanation for what was observed, not before.

It helped advance the investigation into the bootability of the current sun4v images, especially for Solaris 10 DVD, bigger than 2GiB - several of those failed for exactly this reason before the fix.

Regards
Dmitry.

Quoted 44 lines · Mark Cave-Ayland
Quoted 2 lines · Dmitry Pimenov

blk_getlength() returns int64_t, but niagara_init() stored it in an int, truncating the if=pflash virtual-ramdisk size for images >= 2 GiB. A ~4

GiB

Quoted 15 lines

image truncated to 0/negative, failed the size > 0 check, and exit(1)'d before the CPU ran, ending with:

qemu-system-sparc64: could not load ram disk

AI-used-for: code (bug fix)

---
  hw/sparc64/niagara.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/sparc64/niagara.c +0 -0
index 1211ecb82d..ad5e5945a8 100644

hw/sparc64/niagara.c static void niagara_init(MachineState *machine) · line 142

Quoted 7 lines
hw/sparc64/niagara.c +1 -1
@@ -137,7 +137,7 @@ static void niagara_init(MachineState *machine)
         outside of the partition RAM */
      if (dinfo) {
          BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
-        int size = blk_getlength(blk);
+        int64_t size = blk_getlength(blk);
          if (size > 0) {
              memory_region_init_ram(&s->vdisk_ram, NULL,

"sun4v_vdisk.ram", size,

Quoted 3 lines
hw/sparc64/niagara.c +0 -1
                                     &error_fatal);
--

2.43.0

Oh, curious - is this a static/AI analysis find, or are you actively using the sun4v
emulation? Anyhow:

ATB,

Mark.

#5 lore raw
In reply to Dmitry Pimenov
Quoted 10 lines · Dmitry Pimenov

blk_getlength() returns int64_t, but niagara_init() stored it in an int, truncating the if=pflash virtual-ramdisk size for images >= 2 GiB. A ~4 GiB image truncated to 0/negative, failed the size > 0 check, and exit(1)'d before the CPU ran, ending with:

qemu-system-sparc64: could not load ram disk

AI-used-for: code (bug fix)

It feels like a qemu-stable material. I'm picking it up, please let me know if I should not.

Thank,s

/mjt