From: Laszlo Ersek <lersek@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
Anthony Liguori <aliguori@us.ibm.com>,
pbonzini@redhat.com, qemu-devel@nongnu.org, kraxel@redhat.com
Subject: Re: [Qemu-devel] [PATCH v3 2/2] loader: put FW CFG ROM files into RAM
Date: Mon, 19 Aug 2013 13:15:36 +0200 [thread overview]
Message-ID: <5211FE58.7080202@redhat.com> (raw)
In-Reply-To: <5211FC1F.9080000@redhat.com>
On 08/19/13 13:06, Laszlo Ersek wrote:
> On 08/13/13 00:43, Michael S. Tsirkin wrote:
>> @@ -646,6 +669,7 @@ int rom_add_file(const char *file, const char *fw_dir,
>> if (rom->fw_file && fw_cfg) {
>> const char *basename;
>> char fw_file_name[56];
>> + void *data;
>>
>> basename = strrchr(rom->fw_file, '/');
>> if (basename) {
>> @@ -655,8 +679,15 @@ int rom_add_file(const char *file, const char *fw_dir,
>> }
>> snprintf(fw_file_name, sizeof(fw_file_name), "%s/%s", rom->fw_dir,
>> basename);
>> - fw_cfg_add_file(fw_cfg, fw_file_name, rom->data, rom->romsize);
>> snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name);
>> +
>> + if (rom_file_in_ram) {
>> + data = rom_set_mr(rom, OBJECT(fw_cfg), devpath);
>> + } else {
>> + data = rom->data;
>> + }
>> +
>> + fw_cfg_add_file(fw_cfg, fw_file_name, data, rom->romsize);
>
> This seems OK, but if "rom_file_in_ram" is nonzero, then we'll store the
> ROM contents in the qemu process twice -- once in "rom->data" (allocated
> just a bit higher up, not shown in context), and in the new RAMBlock.
>
> This is no bug of course, I'm just wondering if we could drop/repoint
> "rom->data" in this case.
>
>> } else {
>> snprintf(devpath, sizeof(devpath), "/rom@" TARGET_FMT_plx, addr);
>> }
>> @@ -731,7 +762,12 @@ static void rom_reset(void *unused)
>> if (rom->data == NULL) {
>> continue;
>> }
>> - cpu_physical_memory_write_rom(rom->addr, rom->data, rom->datasize);
>> + if (rom->mr) {
>> + void *host = memory_region_get_ram_ptr(rom->mr);
>> + memcpy(host, rom->data, rom->datasize);
>> + } else {
>> + cpu_physical_memory_write_rom(rom->addr, rom->data, rom->datasize);
>> + }
>
> Hmmm. Why is this (ie. the pre-patch resetting) necessary at all?
>
> Is this due to the writeability of fw_cfg files via the ioport
> (fw_cfg_write())? I think that modifies "rom->data" unconditionally
> (which is currently kept separate from the RAMBlock, see above).
>
> So, regarding the patched version:
> - not sure if the RAMBlock can change at all -- it is neither mapped
> into guest-phys address space, nor does fw_cfg_write() touch it,
> - *if* the guest modifies the contents under "rom->addr", via
> fw_cfg_write(), then the hva-space memcpy() is insufficient.
Sorry, I'm wrong here. The patched rom_add_file() ensures that
fw_cfg_write() modifies the correct backing store. Also, we need to keep
"rom->data" around even if "rom_file_in_ram" is set, because that's
where we restore the RAMBlock contents from, in case of a reset.
Laszlo
next prev parent reply other threads:[~2013-08-19 11:13 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-12 22:43 [Qemu-devel] [PATCH v3 0/2] future proof rom loading for cross versiom migration Michael S. Tsirkin
2013-08-12 22:43 ` [Qemu-devel] [PATCH v3 1/2] memory: export migration page size Michael S. Tsirkin
2013-08-19 9:59 ` Laszlo Ersek
2013-08-19 10:21 ` Peter Maydell
2013-08-19 11:09 ` Laszlo Ersek
2013-08-19 11:18 ` Michael S. Tsirkin
2013-08-19 11:33 ` Laszlo Ersek
2013-08-19 11:05 ` Michael S. Tsirkin
2013-08-12 22:43 ` [Qemu-devel] [PATCH v3 2/2] loader: put FW CFG ROM files into RAM Michael S. Tsirkin
2013-08-19 11:06 ` Laszlo Ersek
2013-08-19 11:10 ` Michael S. Tsirkin
2013-08-19 11:15 ` Laszlo Ersek [this message]
2013-08-19 11:21 ` Michael S. Tsirkin
2013-08-18 13:41 ` [Qemu-devel] [PATCH v3 0/2] future proof rom loading for cross versiom migration Michael S. Tsirkin
2013-08-19 11:37 ` Laszlo Ersek
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=5211FE58.7080202@redhat.com \
--to=lersek@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=kraxel@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@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.