From: Thomas Huth <thuth@redhat.com>
To: Alistair Francis <alistair.francis@xilinx.com>,
Laurent Vivier <laurent@vivier.eu>
Cc: "qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] hw/core/generic-loader: Fix crash when running without CPU
Date: Thu, 26 Jan 2017 06:50:35 +0100 [thread overview]
Message-ID: <8a528a03-d97e-7c16-70f6-229b80563b2d@redhat.com> (raw)
In-Reply-To: <CAKmqyKMyzquxEGTF4Un_1WvwBNXOoJU1g67_9fFarVy-yeff+Q@mail.gmail.com>
On 26.01.2017 00:26, Alistair Francis wrote:
> On Wed, Jan 25, 2017 at 12:52 PM, Laurent Vivier <laurent@vivier.eu> wrote:
>> Le 25/01/2017 à 21:45, Thomas Huth a écrit :
>>> When running QEMU with "-M none -device loader,file=kernel.elf", it
>>> currently crashes with a segmentation fault, because the "none"-machine
>>> does not have any CPU by default and the generic loader code tries
>>> to dereference s->cpu. Fix it by adding an appropriate check for a
>>> NULL pointer.
>>>
>>> Reported-by: Laurent Vivier <laurent@vivier.eu>
>>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>>> ---
>>> hw/core/generic-loader.c | 9 +++++----
>>> 1 file changed, 5 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c
>>> index 58f1f02..4601267 100644
>>> --- a/hw/core/generic-loader.c
>>> +++ b/hw/core/generic-loader.c
>>> @@ -137,20 +137,21 @@ static void generic_loader_realize(DeviceState *dev, Error **errp)
>>> #endif
>>>
>>> if (s->file) {
>>> + AddressSpace *as = s->cpu ? s->cpu->as : NULL;
>>
>> Should we just abort if s->cpu is NULL?
>
> I agree, what is the use case where you are loading images without a CPU?
>
> If there is a use case (maybe some KVM thing?) then this patch looks fine to me.
I think there is no real use case yet. But this fix is 1) simpler than
doing an error_report() + exit() here, and 2) maybe the vision of
constructing machines on the fly with QEMU will eventually come true one
day in the distant future, so with that patch here, the code would
already be prepared for the case when QEMU gets started without CPUs and
the CPUs are then later added via QOM...
Well, I don't mind ... if you prefer an error message instead, feel free
to suggest another patch. I'm fine as long as we do not simply crash
with a segmentation fault here.
Thomas
next prev parent reply other threads:[~2017-01-26 5:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-25 20:45 [Qemu-devel] [PATCH] hw/core/generic-loader: Fix crash when running without CPU Thomas Huth
2017-01-25 20:52 ` Laurent Vivier
2017-01-25 23:26 ` Alistair Francis
2017-01-26 5:50 ` Thomas Huth [this message]
2017-01-26 8:38 ` Laurent Vivier
2017-01-26 22:24 ` Alistair Francis
2017-01-26 23:06 ` Peter Maydell
2017-02-28 1:42 ` Alistair Francis
2017-02-27 19:36 ` Thomas Huth
2017-04-23 17:34 ` Michael Tokarev
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=8a528a03-d97e-7c16-70f6-229b80563b2d@redhat.com \
--to=thuth@redhat.com \
--cc=alistair.francis@xilinx.com \
--cc=laurent@vivier.eu \
--cc=qemu-devel@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).