* [Qemu-devel] [PATCH v2 for-1.7] s390x: fix flat file load on 32 bit systems
@ 2013-11-21 12:52 Michael S. Tsirkin
2013-11-21 12:50 ` Alexander Graf
2013-11-21 13:29 ` Cornelia Huck
0 siblings, 2 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2013-11-21 12:52 UTC (permalink / raw)
To: qemu-devel
Cc: Michael S. Tsirkin, Alexander Graf, Dominik Dingel,
Christian Borntraeger, Andreas Färber, Richard Henderson
pc-bios/s390-zipl.rom is a flat image so it's expected that
loading it as elf will fail.
It should fall back on loading a flat file, but doesn't
on 32 bit systems, instead it fails printing:
qemu: hardware error: could not load bootloader 's390-zipl.rom'
The result is boot failure.
The reason is that a 64 bit unsigned interger which is set
to -1 on error is compared to -1UL which on a 32 bit system
with gcc is a 32 bit unsigned interger.
Since both are unsigned, no sign extension takes place and
comparison evaluates to non-equal.
There's no reason to do clever tricks: all functions
we call actually return int so just use int.
In fact ram_addr_t dos not make any sense -
it's meaning is "memory handle for migration".
And then we can use == -1 everywhere, consistently.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
Changes from v1:
better fix: use int everywhere
fix all places with same bug (e.g. -kernel was broken too)
hw/s390x/ipl.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c
index d69adb2..9570912 100644
--- a/hw/s390x/ipl.c
+++ b/hw/s390x/ipl.c
@@ -62,10 +62,9 @@ typedef struct S390IPLState {
static int s390_ipl_init(SysBusDevice *dev)
{
S390IPLState *ipl = S390_IPL(dev);
- ram_addr_t kernel_size = 0;
if (!ipl->kernel) {
- ram_addr_t bios_size = 0;
+ int bios_size;
char *bios_filename;
/* Load zipl bootloader */
@@ -80,7 +79,7 @@ static int s390_ipl_init(SysBusDevice *dev)
bios_size = load_elf(bios_filename, NULL, NULL, &ipl->start_addr, NULL,
NULL, 1, ELF_MACHINE, 0);
- if (bios_size == -1UL) {
+ if (bios_size == -1) {
bios_size = load_image_targphys(bios_filename, ZIPL_IMAGE_START,
4096);
ipl->start_addr = ZIPL_IMAGE_START;
@@ -90,17 +89,19 @@ static int s390_ipl_init(SysBusDevice *dev)
}
g_free(bios_filename);
- if ((long)bios_size < 0) {
+ if (bios_size == -1) {
hw_error("could not load bootloader '%s'\n", bios_name);
}
return 0;
} else {
+ int kernel_size;
+
kernel_size = load_elf(ipl->kernel, NULL, NULL, NULL, NULL,
NULL, 1, ELF_MACHINE, 0);
- if (kernel_size == -1UL) {
+ if (kernel_size == -1) {
kernel_size = load_image_targphys(ipl->kernel, 0, ram_size);
}
- if (kernel_size == -1UL) {
+ if (kernel_size == -1) {
fprintf(stderr, "could not load kernel '%s'\n", ipl->kernel);
return -1;
}
@@ -115,7 +116,8 @@ static int s390_ipl_init(SysBusDevice *dev)
ipl->start_addr = KERN_IMAGE_START;
}
if (ipl->initrd) {
- ram_addr_t initrd_offset, initrd_size;
+ hwaddr initrd_offset;
+ int initrd_size;
initrd_offset = INITRD_START;
while (kernel_size + 0x100000 > initrd_offset) {
@@ -123,7 +125,7 @@ static int s390_ipl_init(SysBusDevice *dev)
}
initrd_size = load_image_targphys(ipl->initrd, initrd_offset,
ram_size - initrd_offset);
- if (initrd_size == -1UL) {
+ if (initrd_size == -1) {
fprintf(stderr, "qemu: could not load initrd '%s'\n", ipl->initrd);
exit(1);
}
--
MST
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2 for-1.7] s390x: fix flat file load on 32 bit systems
2013-11-21 12:52 [Qemu-devel] [PATCH v2 for-1.7] s390x: fix flat file load on 32 bit systems Michael S. Tsirkin
@ 2013-11-21 12:50 ` Alexander Graf
2013-11-21 13:29 ` Cornelia Huck
1 sibling, 0 replies; 3+ messages in thread
From: Alexander Graf @ 2013-11-21 12:50 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Christian Borntraeger, Andreas Färber, QEMU Developers,
Dominik Dingel, Richard Henderson
On 21.11.2013, at 13:52, Michael S. Tsirkin <mst@redhat.com> wrote:
> pc-bios/s390-zipl.rom is a flat image so it's expected that
> loading it as elf will fail.
> It should fall back on loading a flat file, but doesn't
> on 32 bit systems, instead it fails printing:
> qemu: hardware error: could not load bootloader 's390-zipl.rom'
>
> The result is boot failure.
>
> The reason is that a 64 bit unsigned interger which is set
> to -1 on error is compared to -1UL which on a 32 bit system
> with gcc is a 32 bit unsigned interger.
> Since both are unsigned, no sign extension takes place and
> comparison evaluates to non-equal.
>
> There's no reason to do clever tricks: all functions
> we call actually return int so just use int.
> In fact ram_addr_t dos not make any sense -
> it's meaning is "memory handle for migration".
>
> And then we can use == -1 everywhere, consistently.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Alexander Graf <agraf@suse.de>
Alex
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2 for-1.7] s390x: fix flat file load on 32 bit systems
2013-11-21 12:52 [Qemu-devel] [PATCH v2 for-1.7] s390x: fix flat file load on 32 bit systems Michael S. Tsirkin
2013-11-21 12:50 ` Alexander Graf
@ 2013-11-21 13:29 ` Cornelia Huck
1 sibling, 0 replies; 3+ messages in thread
From: Cornelia Huck @ 2013-11-21 13:29 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: qemu-devel, Dominik Dingel, Alexander Graf, Christian Borntraeger,
Andreas Färber, Richard Henderson
On Thu, 21 Nov 2013 14:52:02 +0200
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> pc-bios/s390-zipl.rom is a flat image so it's expected that
> loading it as elf will fail.
> It should fall back on loading a flat file, but doesn't
> on 32 bit systems, instead it fails printing:
> qemu: hardware error: could not load bootloader 's390-zipl.rom'
>
> The result is boot failure.
>
> The reason is that a 64 bit unsigned interger which is set
> to -1 on error is compared to -1UL which on a 32 bit system
> with gcc is a 32 bit unsigned interger.
> Since both are unsigned, no sign extension takes place and
> comparison evaluates to non-equal.
>
> There's no reason to do clever tricks: all functions
> we call actually return int so just use int.
> In fact ram_addr_t dos not make any sense -
> it's meaning is "memory handle for migration".
>
> And then we can use == -1 everywhere, consistently.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>
> Changes from v1:
> better fix: use int everywhere
> fix all places with same bug (e.g. -kernel was broken too)
>
> hw/s390x/ipl.c | 18 ++++++++++--------
> 1 file changed, 10 insertions(+), 8 deletions(-)
>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-11-21 13:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-21 12:52 [Qemu-devel] [PATCH v2 for-1.7] s390x: fix flat file load on 32 bit systems Michael S. Tsirkin
2013-11-21 12:50 ` Alexander Graf
2013-11-21 13:29 ` Cornelia Huck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).