From: "Dr. David Alan Gilbert" <dave@treblig.org>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
"Yanan Wang" <wangyanan55@huawei.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Fabiano Rosas" <farosas@suse.de>,
"Eric Blake" <eblake@redhat.com>,
"Laurent Vivier" <lvivier@redhat.com>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Zhao Liu" <zhao1.liu@intel.com>,
"Eduardo Habkost" <eduardo@habkost.net>
Subject: Re: [PATCH v3] hw/uefi: add "info firmware-log" + "query-firmware-log" monitor commands
Date: Mon, 13 Oct 2025 13:12:48 +0000 [thread overview]
Message-ID: <aOz60EZlbViTKhqr@gallifrey> (raw)
In-Reply-To: <wz4s6ty4jsmi57i7i6th4f2gdpbamiz67cfhyrbhdiusbis4ov@qcdqmui3a52r>
* Gerd Hoffmann (kraxel@redhat.com) wrote:
> Hi,
Hi Gerd,
> > > +typedef struct {
> > > + uint64_t Magic1;
> > > + uint64_t Magic2;
> > > +} MEM_DEBUG_LOG_MAGIC;
> > > +
> > > +/* find log buffer in guest memory by searching for the magic cookie */
> > > +static dma_addr_t find_ovmf_log_range(dma_addr_t start, dma_addr_t end)
> > > +{
> > > + static const MEM_DEBUG_LOG_MAGIC magic = {
> > > + .Magic1 = MEM_DEBUG_LOG_MAGIC1,
> > > + .Magic2 = MEM_DEBUG_LOG_MAGIC2,
> > > + };
> > > + MEM_DEBUG_LOG_MAGIC check;
> > > + dma_addr_t step = 4 * KiB;
> > > + dma_addr_t offset;
> > > +
> > > + for (offset = start; offset < end; offset += step) {
> > > + if (dma_memory_read(&address_space_memory, offset,
> > > + &check, sizeof(check),
> > > + MEMTXATTRS_UNSPECIFIED)) {
> > > + /* dma error -> stop searching */
> > > + break;
> > > + }
> > > + if (memcmp(&magic, &check, sizeof(check)) == 0) {
> > > + return offset;
> > > + }
> > > + }
> >
> > This feels like a genericy function for searching memory
> > that could go in util/ - if we haven't already got one
> > (and then passing the magic in).
>
> Quick grep doesn't look like we already have one.
> Are there more possible users?
It just felt a bit more generic.
> > Also, why is this dma_addr_t - is that for IO addressing?
>
> dma_memory_read takes dma_addr_t (and I want use that so I get errors
> back when trying to read address space not backed by ram.
OK, I did wonder if there was a risk of hitting IO.
> > > + if (target_arch() == SYS_EMU_TARGET_X86_64 &&
> > > + object_dynamic_cast(OBJECT(ms), TYPE_X86_MACHINE)) {
> > > + X86MachineState *x86ms = X86_MACHINE(ms);
> > > +
> > > + /* early log buffer, static allocation in memfd, sec + early pei */
> > > + offset = find_ovmf_log_range(0x800000, 0x900000);
> > > + if (offset != -1) {
> > > + return offset;
> > > + }
> > > +
> > > + /*
> > > + * normal log buffer, dynamically allocated close to end of low memory,
> > > + * late pei + dxe phase
> > > + */
> > > + end = x86ms->below_4g_mem_size;
> > > + start = end - MIN(end, 128 * MiB);
> > > + offset = find_ovmf_log_range(start, end);
> > > + return offset;
> > > + }
> > > +
> > > + if (target_arch() == SYS_EMU_TARGET_AARCH64 &&
> > > + object_dynamic_cast(OBJECT(ms), TYPE_VIRT_MACHINE)) {
> > > + /* edk2 ArmVirt firmware allocations are in the first 128 MB */
> > > + VirtMachineState *vms = VIRT_MACHINE(ms);
> > > + start = vms->memmap[VIRT_MEM].base;
> > > + end = start + 128 * MiB;
> > > + offset = find_ovmf_log_range(start, end);
> > > + return offset;
> > > + }
> >
> > Have you considered punting this to the machine type definition
> > somehow; like making it set a list of {start, end} (and maybe
> > a flag to say it's ovmf if it knows) ?
>
> Advantage being?
>
> The memory areas searched are quite specific to the firmware log, I
> don't see other use cases being able to reuse that ...
I was guessing the list will grow over time; I'm assuming you'll want
to add RISC V, and you might gain some none-virt machines and then you'd
end up having to deal with a growing list, where as you could leave
that to the architecture maintainers to deal with.
Again, just suggestion.
Dave
> take care,
> Gerd
>
--
-----Open up your eyes, open up your mind, open up your code -------
/ Dr. David Alan Gilbert | Running GNU/Linux | Happy \
\ dave @ treblig.org | | In Hex /
\ _________________________|_____ http://www.treblig.org |_______/
next prev parent reply other threads:[~2025-10-13 13:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-10 7:10 [PATCH v3] hw/uefi: add "info firmware-log" + "query-firmware-log" monitor commands Gerd Hoffmann
2025-10-10 9:12 ` Daniel P. Berrangé
2025-10-10 9:27 ` Gerd Hoffmann
2025-10-10 9:31 ` Daniel P. Berrangé
2025-10-13 8:42 ` Gerd Hoffmann
2025-10-10 11:41 ` Markus Armbruster
2025-10-10 17:36 ` Markus Armbruster
2025-10-10 20:23 ` Dr. David Alan Gilbert
2025-10-11 4:43 ` Markus Armbruster
2025-10-11 9:29 ` Markus Armbruster
2025-10-13 9:19 ` Gerd Hoffmann
2025-10-13 10:43 ` Markus Armbruster
2025-10-13 11:47 ` Gerd Hoffmann
2025-10-10 20:36 ` Dr. David Alan Gilbert
2025-10-13 11:55 ` Gerd Hoffmann
2025-10-13 13:12 ` Dr. David Alan Gilbert [this message]
2025-10-13 19:11 ` Philippe Mathieu-Daudé
2025-10-14 13:02 ` Daniel P. Berrangé
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=aOz60EZlbViTKhqr@gallifrey \
--to=dave@treblig.org \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=eduardo@habkost.net \
--cc=farosas@suse.de \
--cc=kraxel@redhat.com \
--cc=lvivier@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=wangyanan55@huawei.com \
--cc=zhao1.liu@intel.com \
/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).