s390-ccw.img: fix sporadic boot errors
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(-)
[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
Signature · 1 line
1.8.4.2
[Qemu-devel] [PULL 2/3] s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css
In reply to Christian BorntraegerWe 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
@@ -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
Cornelia Huck
Reviewed-byRe: [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.
Signed-off-by Christian Borntraeger <[email protected]>--- pc-bios/s390-ccw/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Re: [Qemu-devel] [PULL 2/3] s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css
In reply to Christian BorntraegerQuoted 3 lines · Christian Borntraeger
static void
virtio_setup(uint64_t dev_info)
{
+ structsubchannel_idblk_schid= { .one = 1};
Missing space before the "}" I think.
thanks
-- PMM
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)
{
+ structsubchannel_idblk_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
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)
{
+ structsubchannel_idblk_schid= { .one = 1};
Quoted 7 lines
Quoted 1 line
Missing space before the "}" I think.
checkpatch accepts both ways:
a) structsubchannel_idblk_schid= { .one = 1};
b) structsubchannel_idblk_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
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)
{
+ structsubchannel_idblk_schid= { .one = 1};Quoted 7 lines
Quoted 1 line
Missing space before the "}" I think.
checkpatch accepts both ways:
a) structsubchannel_idblk_schid= { .one = 1};
b) structsubchannel_idblk_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
[Qemu-devel] [PULL 1/3] s390-ccw.img: Fix sporadic reboot hangs: Initialize next_idx
In reply to Christian BorntraegerThe 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
@@ -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
Cornelia Huck
Reviewed-byRe: [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_idxas the qemu elf loader does not zero the bss section.
Make the initialization explicit.Signed-off-by Christian Borntraeger <[email protected]>--- pc-bios/s390-ccw/virtio.c | 1 + 1 file changed, 1 insertion(+)
Re: [Qemu-devel] [PULL 1/3] s390-ccw.img: Fix sporadic reboot hangs: Initialize next_idx
In reply to Christian BorntraegerQuoted 15 lines · Christian Borntraeger
The current code does not initialize
next_idxas the qemu elf loader does not zero the bss section.
Make the initialization explicit.Signed-off-by Christian Borntraeger <[email protected]>--- pc-bios/s390-ccw/virtio.c | 1 + 1 file changed, 1 insertion(+)pc-bios/s390-ccw/virtio.c +0
-0
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~
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_idxas the qemu elf loader does not zero the bss section.
Make the initialization explicit.Signed-off-by Christian Borntraeger <[email protected]>--- pc-bios/s390-ccw/virtio.c | 1 + 1 file changed, 1 insertion(+)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 ;
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
-0debug_print_addr ("init vr" , vr); }FWIW, I believe that
rom_resetneeds 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
[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_idxas the qemu elf loader does not zero the bss section.
Make the initialization explicit.Signed-off-by Christian Borntraeger <[email protected]>--- pc-bios/s390-ccw/virtio.c | 1 + 1 file changed, 1 insertion(+)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 ;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
-0debug_print_addr ("init vr" , vr); }FWIW, I believe that
rom_resetneeds 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
@@ -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
@@ -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
@@ -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);
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.gittags/ipl-20140213for 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 aboutPT_LOADsections: 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: Initializenext_idxs390-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
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.gittags/ipl-20140213for 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 aboutPT_LOADsections: 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: Initializenext_idxs390-ccw.img: Fix sporadic errors with ccw boot image - initialize css s390-ccw.img: new binary rom to match latest fixesI 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