From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: qemu-devel@nongnu.org
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>,
Paolo Bonzini <pbonzini@redhat.com>,
qemu-ppc@nongnu.org, Alexander Graf <agraf@suse.de>,
Anthony Liguori <anthony@codemonkey.ws>
Subject: [Qemu-devel] [RFC PATCH] elf loader: exit if incompatible architecture is detected
Date: Tue, 7 Jan 2014 15:35:53 +1100 [thread overview]
Message-ID: <1389069353-13467-1-git-send-email-aik@ozlabs.ru> (raw)
If we know for sure that the image in "-kernel" is an ELF and we know its
architecture and it is not supported by the current QEMU, there is no
point to continue trying booting this image so let's exit once we deteced
this fact.
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
One of our users tried an X86 image with qemu-system-ppc64. Instead of
printing some reasonable message (which is possible in this case as the image
is ELF), QEMU (spapr.c) simply copied the image in RAM as a raw image and
SLOF failed to boot from it.
The patch fixes the issue but there are still questions.
1. Do we need more sophisticated error checking here? Return -2 instead of exit(1)
and do exit(1) few levels up?
2. The patch does not handle x86's vmlinuz case - these images are not ELFs
but "Linux kernel x86 boot executable bzImage" and QEMU does not parse them.
As a result, SLOF crashes with the registers dump. Do we really care to handle this?
---
include/hw/elf_ops.h | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
index acc701e..6bcc61f 100644
--- a/include/hw/elf_ops.h
+++ b/include/hw/elf_ops.h
@@ -212,21 +212,21 @@ static int glue(load_elf, SZ)(const char *name, int fd,
case EM_PPC64:
if (EM_PPC64 != ehdr.e_machine)
if (EM_PPC != ehdr.e_machine)
- goto fail;
+ goto arch_fail;
break;
case EM_X86_64:
if (EM_X86_64 != ehdr.e_machine)
if (EM_386 != ehdr.e_machine)
- goto fail;
+ goto arch_fail;
break;
case EM_MICROBLAZE:
if (EM_MICROBLAZE != ehdr.e_machine)
if (EM_MICROBLAZE_OLD != ehdr.e_machine)
- goto fail;
+ goto arch_fail;
break;
default:
if (elf_machine != ehdr.e_machine)
- goto fail;
+ goto arch_fail;
}
if (pentry)
@@ -306,4 +306,9 @@ static int glue(load_elf, SZ)(const char *name, int fd,
g_free(data);
g_free(phdr);
return -1;
+
+arch_fail:
+ fprintf(stderr, "qemu: could not load arch-incompatible kernel '%s'\n",
+ name);
+ exit(1);
}
--
1.8.4.rc4
next reply other threads:[~2014-01-07 4:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-07 4:35 Alexey Kardashevskiy [this message]
2014-01-20 15:11 ` [Qemu-devel] [RFC PATCH] elf loader: exit if incompatible architecture is detected Alexander Graf
2014-01-21 4:04 ` Alexey Kardashevskiy
2014-01-21 9:12 ` Alexander Graf
2014-01-20 15:24 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1389069353-13467-1-git-send-email-aik@ozlabs.ru \
--to=aik@ozlabs.ru \
--cc=agraf@suse.de \
--cc=anthony@codemonkey.ws \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).