From: Daniel Henrique Barboza <danielhb413@gmail.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>,
qemu-arm@nongnu.org
Subject: Re: [PATCH 1/1] hw/arm: do not free machine->fdt in arm_load_dtb()
Date: Thu, 23 Mar 2023 17:15:12 -0300 [thread overview]
Message-ID: <2b7edf21-9825-ca5e-0329-1ef3e411439d@gmail.com> (raw)
In-Reply-To: <CAFEAcA_MXhG7-J9qAv-9cmHKC-qx5nKfZPHi7jXyqdoYumH5-A@mail.gmail.com>
On 3/23/23 14:59, Peter Maydell wrote:
> On Thu, 23 Mar 2023 at 17:54, Daniel Henrique Barboza
> <danielhb413@gmail.com> wrote:
>>
>>
>>
>> On 3/23/23 14:38, Peter Maydell wrote:
>>> On Thu, 23 Mar 2023 at 16:11, Daniel Henrique Barboza
>>> <danielhb413@gmail.com> wrote:
>>>> - g_free(fdt);
>>>> + /* Set ms->fdt for 'dumpdtb' QMP/HMP command */
>>>> + ms->fdt = fdt;
>>>
>>> With this we're now setting ms->fdt twice for the virt board: we set
>>> it in create_fdt() in hw/arm/virt.c, and then we set it again here.
>>> Which is the right place to set it?
>>>
>>> Is the QMP 'dumpdtb' command intended to dump the DTB only for
>>> board types where the DTB is created at runtime by QEMU? Or
>>> is it supposed to also work for DTBs that were originally
>>> provided by the user using the '-dtb' command line? The docs
>>> don't say. If we want the former, then we should be setting
>>> ms->fdt in the board code; if the latter, then here is right.
>>
>> My original intent with this command was to dump the current state of the FDT,
>> regardless of whether the FDT was loaded via -dtb or at runtime.
>
> Mmm. I think that makes sense; we do make a few tweaks to the DTB
> even if it was user-provided and you might want to check those
> for debug purposes. So we should keep this assignment, and remove
> the now-unneeded setting of ms->fdt in create_fdt().
I don't think we can remove it. arm_load_dtb() does the following:
if (binfo->dtb_filename) {
(...)
} else {
fdt = binfo->get_dtb(binfo, &size);
if (!fdt) {
fprintf(stderr, "Board was unable to create a dtb blob\n");
goto fail;
}
}
So if we don't have a '-dtb' option, fdt = binfo->get_dtb(). For the 'virt' machine,
machvirt_dtb(), will return ms->fdt. So we would SIGSEG right at the start.
And now that I think more about it, this patch is leaking the board FDT if we're
using the FDT from dtb_filename, isn't it? We're assigning a new ms->fdt on top
of the existing ms->fdt from the board. I'll send a new version.
Also, given that we're not using the board FDT at all if '-dtb' is present, I
think it would be good to move create_fdt() from machvirt_init() to machvirt_dtb().
Some code juggling would be required (some functions from init() are using ms->fdt)
but it think it would make the code clearer - create the fdt board only if we're
really going to use it. I'll see if I can pull this off and send a 8.1 patch
with it.
Thanks,
Daniel
>
> thanks
> -- PMM
prev parent reply other threads:[~2023-03-23 20:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-23 16:10 [PATCH 0/1] fix dumpdtb crash with ARM machines Daniel Henrique Barboza
2023-03-23 16:10 ` [PATCH 1/1] hw/arm: do not free machine->fdt in arm_load_dtb() Daniel Henrique Barboza
2023-03-23 17:38 ` Peter Maydell
2023-03-23 17:54 ` Daniel Henrique Barboza
2023-03-23 17:59 ` Peter Maydell
2023-03-23 20:15 ` Daniel Henrique Barboza [this message]
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=2b7edf21-9825-ca5e-0329-1ef3e411439d@gmail.com \
--to=danielhb413@gmail.com \
--cc=armbru@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--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).