Skip to contentSkip to conversation

s390-ccw.img: fix sporadic boot errors

GIT PULL Christian Borntraeger 4 participants 15 messages Feb 13, 2014

lore
Share & tools
lore
#0 lore raw

Peter, Anthony,

The following changes since commit 9d74f6fef0801ca2ce5c9d38d59b85bf03c27669:

Merge remote-tracking branch 'remotes/alon/pull-libcacard.glusterfs' into staging (2014-02-12 17:53:31 +0000)

are available in the git repository at:

git://github.com/borntraeger/qemu.git tags/ipl-20140213

for you to fetch changes up to 669d13daaf31e81463d081f59ee88e4f75dc7538:

s390-ccw.img: new binary rom to match latest fixes (2014-02-13 09:59:21 +0100)

These changes make the reipl more robust.
----------------------------------------------------------------
This fixes two sporadic errors on reboot when the s390-ccw.img is used. Both problems are related to qemus elf loader only caring about PT_LOAD sections: This results in a non-zero bss section after reboot. This makes static variables non-zero.

This quick fix initializes all variables. Long term we might also want to clear out the bss section.

----------------------------------------------------------------
Christian Borntraeger (3):
s390-ccw.img: Fix sporadic reboot hangs: Initialize next_idx s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css s390-ccw.img: new binary rom to match latest fixes

 pc-bios/s390-ccw.img      | Bin 9336 -> 9336 bytes
 pc-bios/s390-ccw/main.c   |   3 +--
 pc-bios/s390-ccw/virtio.c |   1 +
 3 files changed, 2 insertions(+), 2 deletions(-)
#1 lore raw

[Qemu-devel] [PULL 3/3] s390-ccw.img: new binary rom to match latest fixes

---
 pc-bios/s390-ccw.img | Bin 9336 -> 9336 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
pc-bios/s390-ccw.img binary +0 -0
index 6727f0ca39d6bf6d114974d1535cb7ad9e56355f..f6223e77c2aacfa86652d63b773dc05eca55570d 100644
GIT binary patch
Signature · 1 line
1.8.4.2
#2 lore raw

[Qemu-devel] [PULL 2/3] s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css

In reply to Christian Borntraeger

We have to set the cssid to 0, otherwise the stsch code will return an operand exception without the m bit. In the same way we should set m=0.

This case was triggered in some cases during reboot, if for some reason the location of blk_schid.cssid contains 1 and m was 0. Turns out that the qemu elf loader does not zero out the bss section. On first boot this is ok, but on reboots this might fail.

The symptom was an dump of the old kernel with several areas overwritten. The bootloader does not register a program check handler, so bios exception jumped back into the old kernel.

Lets just use a local struct with a designed initializer. That will guarantee that all other subelements are initialized to 0.

---
 pc-bios/s390-ccw/main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
pc-bios/s390-ccw/main.c +1 -2
index c5d5332..d7fc727 100644
@@ -10,7 +10,6 @@
 
 #include "s390-ccw.h"
 
-struct subchannel_id blk_schid;
 char stack[PAGE_SIZE * 8] __attribute__((__aligned__(PAGE_SIZE)));
 uint64_t boot_value;
 
@@ -23,13 +22,13 @@ void virtio_panic(const char *string)
 
 static void virtio_setup(uint64_t dev_info)
 {
+    struct subchannel_id blk_schid = { .one = 1};
     struct schib schib;
     int i;
     int r;
     bool found = false;
     bool check_devno = false;
     uint16_t dev_no = -1;
-    blk_schid.one = 1;
 
     if (dev_info != -1) {
         check_devno = true;
Signature · 1 line
1.8.4.2
Reviewed-by
#3 lore raw

Re: [Qemu-devel] [PULL 2/3] s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css

Quoted 13 lines · On Thu, 13 Feb 2014 10:17:10 +0100 Christian Borntraeger…

We have to set the cssid to 0, otherwise the stsch code will return an operand exception without the m bit. In the same way we should set m=0.

This case was triggered in some cases during reboot, if for some reason the location of blk_schid.cssid contains 1 and m was 0. Turns out that the qemu elf loader does not zero out the bss section. On first boot this is ok, but on reboots this might fail.

The symptom was an dump of the old kernel with several areas overwritten. The bootloader does not register a program check handler, so bios exception jumped back into the old kernel.

Quoted 7 lines

Lets just use a local struct with a designed initializer. That will guarantee that all other subelements are initialized to 0.

---
 pc-bios/s390-ccw/main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
#4 lore raw

Re: [Qemu-devel] [PULL 2/3] s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css

In reply to Christian Borntraeger
Quoted 3 lines · Christian Borntraeger

static void virtio_setup(uint64_t dev_info)
{
+ struct subchannel_id blk_schid = { .one = 1};

Missing space before the "}" I think.

thanks
-- PMM

#5 lore raw

Re: [Qemu-devel] [PULL 2/3] s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css

Quoted 6 lines · Peter Maydell
Quoted 3 lines · Christian Borntraeger

static void virtio_setup(uint64_t dev_info)
{
+ struct subchannel_id blk_schid = { .one = 1};

Missing space before the "}" I think.

checkpatch accepts both ways:
a) struct subchannel_id blk_schid = { .one = 1};
b) struct subchannel_id blk_schid = { .one = 1 };

so, change it or keep it?

Christian

#6 lore raw

Re: [Qemu-devel] [PULL 2/3] s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css

Quoted 6 lines · Christian Borntraeger
Quoted 5 lines · Peter Maydell
Quoted 3 lines · Christian Borntraeger

static void virtio_setup(uint64_t dev_info)
{
+ struct subchannel_id blk_schid = { .one = 1};

Quoted 7 lines
Quoted 1 line

Missing space before the "}" I think.

checkpatch accepts both ways:
a) struct subchannel_id blk_schid = { .one = 1};
b) struct subchannel_id blk_schid = { .one = 1 };

so, change it or keep it?

checkpatch isn't infallible. I think having the space looks better. In any case you should be consistent about whether you use a space with both the opening and the closing brace -- at the moment you've got a space at one end and not the other.

thanks
-- PMM

#7 lore raw

Re: [Qemu-devel] [PULL 2/3] s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css

Quoted 15 lines · Peter Maydell
Quoted 6 lines · Christian Borntraeger
Quoted 5 lines · Peter Maydell
Quoted 3 lines · Christian Borntraeger

static void virtio_setup(uint64_t dev_info)
{
+ struct subchannel_id blk_schid = { .one = 1};

Quoted 7 lines
Quoted 1 line

Missing space before the "}" I think.

checkpatch accepts both ways:
a) struct subchannel_id blk_schid = { .one = 1};
b) struct subchannel_id blk_schid = { .one = 1 };

so, change it or keep it?

Quoted 7 lines

checkpatch isn't infallible. I think having the space looks better. In any case you should be consistent about whether you use a space with both the opening and the closing brace -- at the moment you've got a space at one end and not the other.

thanks

Ok changed. Will wait for some more feedback and send an updated pull requests.

Christian

#8 lore raw

[Qemu-devel] [PULL 1/3] s390-ccw.img: Fix sporadic reboot hangs: Initialize next_idx

In reply to Christian Borntraeger

The current code does not initialize next_idx as the qemu elf loader does not zero the bss section.
Make the initialization explicit.

---
 pc-bios/s390-ccw/virtio.c | 1 +
 1 file changed, 1 insertion(+)
pc-bios/s390-ccw/virtio.c +1 -0
index 4d6e48f..a46914d 100644
@@ -124,6 +124,7 @@ static void vring_init(struct vring *vr, unsigned int num, void *p,
     vr->used->flags = VRING_USED_F_NO_NOTIFY;
     vr->used->idx = 0;
     vr->used_idx = 0;
+    vr->next_idx = 0;
 
     debug_print_addr("init vr", vr);
 }
Signature · 1 line
1.8.4.2
Reviewed-by
#9 lore raw

Re: [Qemu-devel] [PULL 1/3] s390-ccw.img: Fix sporadic reboot hangs: Initialize next_idx

Quoted 8 lines · On Thu, 13 Feb 2014 10:17:09 +0100 Christian Borntraeger…

The current code does not initialize next_idx as the qemu elf loader does not zero the bss section.
Make the initialization explicit.

---
 pc-bios/s390-ccw/virtio.c | 1 +
 1 file changed, 1 insertion(+)
#10 lore raw

Re: [Qemu-devel] [PULL 1/3] s390-ccw.img: Fix sporadic reboot hangs: Initialize next_idx

In reply to Christian Borntraeger
Quoted 15 lines · Christian Borntraeger

The current code does not initialize next_idx as the qemu elf loader does not zero the bss section.
Make the initialization explicit.

---
 pc-bios/s390-ccw/virtio.c | 1 +
 1 file changed, 1 insertion(+)
pc-bios/s390-ccw/virtio.c +0 -0
index 4d6e48f..a46914d 100644

pc-bios/s390-ccw/virtio.c static void vring_init(struct vring *vr, unsigned int num, void *p, · line 130

Quoted 7 lines
pc-bios/s390-ccw/virtio.c +1 -0
@@ -124,6 +124,7 @@ static void vring_init(struct vring *vr, unsigned int num, void *p,
     vr->used->flags = VRING_USED_F_NO_NOTIFY;
     vr->used->idx = 0;
     vr->used_idx = 0;
+    vr->next_idx = 0;
 
     debug_print_addr("init vr", vr);
 }

FWIW, I believe that rom_reset needs to do this re-zeroing of the bss. That seems to be the only place we don't take care for datasize != romsize.

r~

#11 lore raw

Re: [Qemu-devel] [PULL 1/3] s390-ccw.img: Fix sporadic reboot hangs: Initialize next_idx

Quoted 20 lines · Richard Henderson
Quoted 19 lines · Christian Borntraeger

The current code does not initialize next_idx as the qemu elf loader does not zero the bss section.
Make the initialization explicit.

---
 pc-bios/s390-ccw/virtio.c | 1 +
 1 file changed, 1 insertion(+)
pc-bios/s390-ccw/virtio.c +1 -0
index 4d6e48f..a46914d 100644
@@ -124,6 +124,7 @@ static void vring_init(struct vring *vr, unsigned int num, void *p,
     vr->used->flags = VRING_USED_F_NO_NOTIFY;
     vr->used->idx = 0;
     vr->used_idx = 0;
+    vr->next_idx = 0;
 
Quoted 7 lines

pc-bios/s390-ccw/virtio.c static void vring_init(struct vring *vr, unsigned int num, void *p, · line 130

Quoted 3 lines
pc-bios/s390-ccw/virtio.c +0 -0
     debug_print_addr("init vr", vr);
 }

FWIW, I believe that rom_reset needs to do this re-zeroing of the bss. That seems to be the only place we don't take care for datasize != romsize.

Indeed, initializing the data as in my patches isnt wrong (and allows to move that structures around e.g. from a global variable to stack), so it still makes sense to apply both patches, but the main problem was that the bss section is not cleared on reset.

So we need to memset from rom->data+rom->datasize to rom->data+rom->romsize to avoid more of these kind of problems in an add-on patch.

Christian

#12 lore raw

[Qemu-devel] [PATCH/RFC] clear bss memory of ROMS

Quoted 29 lines · Christian Borntraeger
Quoted 20 lines · Richard Henderson
Quoted 19 lines · Christian Borntraeger

The current code does not initialize next_idx as the qemu elf loader does not zero the bss section.
Make the initialization explicit.

---
 pc-bios/s390-ccw/virtio.c | 1 +
 1 file changed, 1 insertion(+)
pc-bios/s390-ccw/virtio.c +1 -0
index 4d6e48f..a46914d 100644
@@ -124,6 +124,7 @@ static void vring_init(struct vring *vr, unsigned int num, void *p,
     vr->used->flags = VRING_USED_F_NO_NOTIFY;
     vr->used->idx = 0;
     vr->used_idx = 0;
+    vr->next_idx = 0;
 
Quoted 7 lines

pc-bios/s390-ccw/virtio.c static void vring_init(struct vring *vr, unsigned int num, void *p, · line 130

Quoted 3 lines
pc-bios/s390-ccw/virtio.c +0 -0
     debug_print_addr("init vr", vr);
 }

FWIW, I believe that rom_reset needs to do this re-zeroing of the bss. That seems to be the only place we don't take care for datasize != romsize.

Quoted 7 lines

Indeed, initializing the data as in my patches isnt wrong (and allows to move that structures around e.g. from a global variable to stack), so it still makes sense to apply both patches, but the main problem was that the bss section is not cleared on reset.

So we need to memset from rom->data+rom->datasize to rom->data+rom->romsize to avoid more of these kind of problems in an add-on patch.

To correct myself. Actually only Patch 2/3 would be fixed by zeroing the bss. Patch 1/3 is still necessary, since the bios creates the virtqueue not in bss but in real memory. Still, bss clearing seems like a good idea, so what about something like the following:

loader: reset bss sections of ROMS

The bss section of ELF roms must be zeroed on reset.

[cborntra@r17lp39 qemu]$ git diff

exec.c +24 -0
index b69fd29..f0f6a94 100644
@@ -2097,6 +2097,30 @@ void cpu_physical_memory_rw(hwaddr addr, uint8_t *buf,
     address_space_rw(&address_space_memory, addr, buf, len, is_write);
 }
 
+void cpu_physical_memory_clear_rom(AddressSpace *as, hwaddr addr, size_t len)
+{
+    hwaddr l;
+    uint8_t *ptr;
+    hwaddr addr1;
+    MemoryRegion *mr;
+
+    while (len > 0) {
+        l = len;
+        mr = address_space_translate(as, addr, &addr1, &l, true);
+
+        if (!(memory_region_is_ram(mr) ||
+              memory_region_is_romd(mr))) {
+            /* do nothing */
+        } else {
+            addr1 += memory_region_get_ram_addr(mr);
+            ptr = qemu_get_ram_ptr(addr1);
+            memset(ptr, 0, l);
+        }
+        len -= l;
+        addr += l;
+    }
+}
+
 enum write_rom_type {
     WRITE_DATA,
     FLUSH_CACHE,
hw/core/loader.c +10 -3
index e1a8318..7998a3e 100644
@@ -786,13 +786,20 @@ static void rom_reset(void *unused)
         if (rom->fw_file) {
             continue;
         }
-        if (rom->data == NULL) {
-            continue;
-        }
         if (rom->mr) {
             void *host = memory_region_get_ram_ptr(rom->mr);
+            memset(host + rom->datasize, 0, rom->romsize - rom->datasize);
+            if (rom->data == NULL) {
+                continue;
+            }
             memcpy(host, rom->data, rom->datasize);
         } else {
+            cpu_physical_memory_clear_rom(&address_space_memory,
+                                          rom->addr + rom->datasize,
+                                          rom->romsize - rom->datasize);
+            if (rom->data == NULL) {
+                continue;
+            }
             cpu_physical_memory_write_rom(&address_space_memory,
                                           rom->addr, rom->data, rom->datasize);
         }
include/exec/cpu-common.h +1 -0
index a21b65a..948de83 100644
@@ -108,6 +108,7 @@ void stl_phys(AddressSpace *as, hwaddr addr, uint32_t val);
 void stq_phys(AddressSpace *as, hwaddr addr, uint64_t val);
 #endif
 
+void cpu_physical_memory_clear_rom(AddressSpace *as, hwaddr addr, size_t len);
 void cpu_physical_memory_write_rom(AddressSpace *as, hwaddr addr,
                                    const uint8_t *buf, int len);
 void cpu_flush_icache_range(hwaddr start, int len);
#13 lore raw
In reply to Christian Borntraeger
Quoted 23 lines · Christian Borntraeger

Peter, Anthony,

The following changes since commit 9d74f6fef0801ca2ce5c9d38d59b85bf03c27669:

Merge remote-tracking branch 'remotes/alon/pull-libcacard.glusterfs' into staging (2014-02-12 17:53:31 +0000)

are available in the git repository at:

git://github.com/borntraeger/qemu.git tags/ipl-20140213

for you to fetch changes up to 669d13daaf31e81463d081f59ee88e4f75dc7538:

s390-ccw.img: new binary rom to match latest fixes (2014-02-13 09:59:21 +0100)

These changes make the reipl more robust.
----------------------------------------------------------------
This fixes two sporadic errors on reboot when the s390-ccw.img is used. Both problems are related to qemus elf loader only caring about PT_LOAD sections: This results in a non-zero bss section after reboot. This makes static variables non-zero.

Quoted 8 lines

This quick fix initializes all variables. Long term we might also want to clear out the bss section.

----------------------------------------------------------------
Christian Borntraeger (3):
s390-ccw.img: Fix sporadic reboot hangs: Initialize next_idx s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css s390-ccw.img: new binary rom to match latest fixes

I couldn't find these patches anywhere on the list when I searched my archives -- have they been through the usual review process?

thanks
-- PMM

#14 lore raw
Quoted 27 lines · Peter Maydell
Quoted 26 lines · Christian Borntraeger

Peter, Anthony,

The following changes since commit 9d74f6fef0801ca2ce5c9d38d59b85bf03c27669:

Merge remote-tracking branch 'remotes/alon/pull-libcacard.glusterfs' into staging (2014-02-12 17:53:31 +0000)

are available in the git repository at:

git://github.com/borntraeger/qemu.git tags/ipl-20140213

for you to fetch changes up to 669d13daaf31e81463d081f59ee88e4f75dc7538:

s390-ccw.img: new binary rom to match latest fixes (2014-02-13 09:59:21 +0100)

These changes make the reipl more robust.
----------------------------------------------------------------
This fixes two sporadic errors on reboot when the s390-ccw.img is used. Both problems are related to qemus elf loader only caring about PT_LOAD sections: This results in a non-zero bss section after reboot. This makes static variables non-zero.

This quick fix initializes all variables. Long term we might also want to clear out the bss section.

Quoted 8 lines
Quoted 5 lines

----------------------------------------------------------------
Christian Borntraeger (3):
s390-ccw.img: Fix sporadic reboot hangs: Initialize next_idx s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css s390-ccw.img: new binary rom to match latest fixes

I couldn't find these patches anywhere on the list when I searched my archives -- have they been through the usual review process?

You are right, not yet on qemu-devel. Since these patches are also part of the mail thread, lets just wait some days and let also wait for Alex' NACK/ACK.

Christian