qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Edmondson <dme@dme.org>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-block@nongnu.org, Xu Yandong <xuyandong2@huawei.com>,
	Markus Armbruster <armbru@redhat.com>,
	Max Reitz <mreitz@redhat.com>,
	Zheng Xiang <zhengxiang9@huawei.com>,
	haibinzhang <haibinzhang@tencent.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Stefano Garzarella <sgarzare@redhat.com>
Subject: Re: [RFC PATCH 3/3] hw/block/pflash: use memory_region_init_rom_device_from_file()
Date: Mon, 01 Mar 2021 13:38:41 +0000	[thread overview]
Message-ID: <m2a6rnat9a.fsf@dme.org> (raw)
In-Reply-To: <be6e184a-21e9-81f7-4f2e-363213a389b4@redhat.com>

On Monday, 2021-03-01 at 12:50:33 +01, Philippe Mathieu-Daudé wrote:

> On 2/26/21 9:23 AM, David Edmondson wrote:
>> On Friday, 2021-02-26 at 00:02:38 +01, Philippe Mathieu-Daudé wrote:
>> 
>>> If the block drive is read-only we will model a "protected" flash
>>> device. We can thus use memory_region_init_rom_device_from_file()
>>> which mmap the backing file when creating the MemoryRegion.
>>> If the same backing file is used by multiple QEMU instances, this
>>> reduces the memory footprint (this is often the case with the
>>> CODE flash image from OVMF and AAVMF).
>>>
>>> Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>>> ---
>>>  hw/block/pflash_cfi01.c | 20 ++++++++++++++------
>>>  hw/block/pflash_cfi02.c | 18 ++++++++++++++----
>>>  2 files changed, 28 insertions(+), 10 deletions(-)
>>>
>>> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
>>> index a5fa8d8b74a..5757391df1c 100644
>>> --- a/hw/block/pflash_cfi01.c
>>> +++ b/hw/block/pflash_cfi01.c
>>> @@ -743,11 +743,19 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
>>>          pfl->ro = 0;
>>>      }
>>>  
>>> -    memory_region_init_rom_device(
>>> -        &pfl->mem, OBJECT(dev),
>>> -        &pflash_cfi01_ops,
>>> -        pfl,
>>> -        pfl->name, total_len, errp);
>>> +    if (pfl->blk && pfl->ro) {
>>> +        memory_region_init_rom_device_from_file(&pfl->mem, OBJECT(dev),
>>> +                                                &pflash_cfi01_ops, pfl,
>>> +                                                pfl->name, total_len,
>>> +                                                qemu_real_host_page_size,
>>> +                                                RAM_SHARED,
>>> +                                                blk_bs(pfl->blk)->filename,
>> 
>> How will this behave if someone does:
>> 
>>     -drive file=OVMF_CODE.fd.qcow2,index=0,if=pflash,format=qcow2,readonly=on
>> 
>> Honestly, I'm not sure why they would, but it works today.
>
> OK I can add a check for "raw" driver, but I don't know to check for
> offset == 0.

This is pretty much where I got to when I tried using mmap() and gave up
(mostly because I figured that adding layer violating checks to the
pflash driver would not be well received, but also because we don't
share the same underlying file between multiple VMs and I wasn't sure
that it would eventually work well for writable devices).

dme.
-- 
Driving at 90 down those country lanes, singing to "Tiny Dancer".


  reply	other threads:[~2021-03-01 13:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-25 23:02 [RFC PATCH 0/3] hw/block/pflash: Mmap read-only backend files with MAP_SHARED Philippe Mathieu-Daudé
2021-02-25 23:02 ` [RFC PATCH 1/3] exec/memory: Introduce memory_region_init_rom_device_from_file() Philippe Mathieu-Daudé
2021-03-01 11:53   ` Stefano Garzarella
2021-03-01 11:59     ` Philippe Mathieu-Daudé
2021-02-25 23:02 ` [RFC PATCH 2/3] hw/block/pflash: Move code around Philippe Mathieu-Daudé
2021-02-26  8:21   ` David Edmondson
2021-02-25 23:02 ` [RFC PATCH 3/3] hw/block/pflash: use memory_region_init_rom_device_from_file() Philippe Mathieu-Daudé
2021-02-26  8:23   ` David Edmondson
2021-03-01 11:50     ` Philippe Mathieu-Daudé
2021-03-01 13:38       ` David Edmondson [this message]
2021-03-01 13:58         ` Philippe Mathieu-Daudé

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=m2a6rnat9a.fsf@dme.org \
    --to=dme@dme.org \
    --cc=armbru@redhat.com \
    --cc=haibinzhang@tencent.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=xuyandong2@huawei.com \
    --cc=zhengxiang9@huawei.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).