From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Ani Sinha <anisinha@redhat.com>
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Fabiano Rosas" <farosas@suse.de>,
"Laurent Vivier" <lvivier@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [PATCH v3] tests/qtest/libqos: add DMA support for writing and reading fw_cfg files
Date: Wed, 8 Jan 2025 13:20:25 +0000 [thread overview]
Message-ID: <Z357mUof2tOvS8gQ@redhat.com> (raw)
In-Reply-To: <591DC037-7D47-4DE0-B83E-E1A1BC452175@redhat.com>
On Wed, Jan 08, 2025 at 06:47:25PM +0530, Ani Sinha wrote:
>
>
> > On 8 Jan 2025, at 6:38 PM, Daniel P. Berrangé <berrange@redhat.com> wrote:
> >
> > On Wed, Jan 08, 2025 at 06:27:50PM +0530, Ani Sinha wrote:
> >> At present, the libqos/fw_cfg.c library does not support the modern DMA
> >> interface which is required to write to the fw_cfg files. It only uses the IO
> >> interface. Implement read and write methods based on DMA. This will enable
> >> developers to write tests that writes to the fw_cfg file(s). The structure of
> >> the code is taken from edk2 fw_cfg implementation. It has been tested by
> >> writing a qtest that writes to a fw_cfg file. This test will be part of a
> >> future patch series.
> >>
> >> Signed-off-by: Ani Sinha <anisinha@redhat.com>
> >> ---
> >> tests/qtest/libqos/fw_cfg.c | 204 ++++++++++++++++++++++++++++++++----
> >> tests/qtest/libqos/fw_cfg.h | 5 +
> >> 2 files changed, 186 insertions(+), 23 deletions(-)
> >
> >> +static bool
> >> +find_pdir_entry(QFWCFG *fw_cfg, const char *filename,
> >> + uint16_t *sel, uint32_t *size)
> >> +{
> >> + unsigned char *filesbuf = NULL;
> >
> > Use g_autofree here instead of later g_free.
>
> OK will send just a refactoring patch with this change.
>
> >
> >> + uint32_t count;
> >> + size_t dsize;
> >> + FWCfgFile *pdir_entry;
> >> + uint32_t i;
> >> + bool found = false;
> >> +
> >> + *size = 0;
> >> + *sel = 0;
> >> +
> >> + qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, &count, sizeof(count));
> >> + count = be32_to_cpu(count);
> >> + dsize = sizeof(uint32_t) + count * sizeof(struct fw_cfg_file);
> >> + filesbuf = g_malloc(dsize);
> >> + g_assert(filesbuf);
> >> + qfw_cfg_get(fw_cfg, FW_CFG_FILE_DIR, filesbuf, dsize);
> >> + pdir_entry = (FWCfgFile *)(filesbuf + sizeof(uint32_t));
> >
> > I'm not familiar with fwcfg data format, but I'm wondering
> > what the initial 'uint32_t' data field is that you're skipping
> > over, and whether its value should be validated before this
> > loop ?
>
> This part I left as is from previous code. From https://www.qemu.org/docs/master/specs/fw_cfg.html
>
> struct FWCfgFiles { /* the entire file directory fw_cfg item */
> uint32_t count; /* number of entries, in big-endian format */
> struct FWCfgFile f[]; /* array of file entries, see below */
> };
>
> struct FWCfgFile { /* an individual file entry, 64 bytes total */
> uint32_t size; /* size of referenced fw_cfg item, big-endian */
> uint16_t select; /* selector key of fw_cfg item, big-endian */
> uint16_t reserved;
> char name[56]; /* fw_cfg item name, NUL-terminated ascii */
> };
>
> So the code first reads the count and then allocates ‘count' entries for ‘count' files.
Ah right, so the first qfw_cfg_get already read count,
and the second qfw_cfg_get reads it again, followed by
the entries, so we can ignore that first field.
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
prev parent reply other threads:[~2025-01-08 13:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-08 12:57 [PATCH v3] tests/qtest/libqos: add DMA support for writing and reading fw_cfg files Ani Sinha
2025-01-08 13:08 ` Daniel P. Berrangé
2025-01-08 13:17 ` Ani Sinha
2025-01-08 13:20 ` Daniel P. Berrangé [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=Z357mUof2tOvS8gQ@redhat.com \
--to=berrange@redhat.com \
--cc=anisinha@redhat.com \
--cc=armbru@redhat.com \
--cc=farosas@suse.de \
--cc=kraxel@redhat.com \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.