From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-block@nongnu.org, Xu Yandong <xuyandong2@huawei.com>,
Markus Armbruster <armbru@redhat.com>,
qemu-devel@nongnu.org,
David Edmondson <david.edmondson@oracle.com>,
haibinzhang <haibinzhang@tencent.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Max Reitz <mreitz@redhat.com>,
Stefano Garzarella <sgarzare@redhat.com>
Subject: Re: [RFC PATCH v2 3/3] hw/block/pflash: use memory_region_init_rom_device_from_file()
Date: Tue, 2 Mar 2021 08:04:46 +0100 [thread overview]
Message-ID: <bc4b3dee-4af4-7ce2-aeaa-70c0cfde679f@redhat.com> (raw)
In-Reply-To: <YD0uvW+vzfQjBecY@stefanha-x1.localdomain>
On 3/1/21 7:13 PM, Stefan Hajnoczi wrote:
> On Mon, Mar 01, 2021 at 12:53:29PM +0100, 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 | 39 +++++++++++++++++++++++++++++++--------
>> 1 file changed, 31 insertions(+), 8 deletions(-)
>>
>> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
>> index a5fa8d8b74a..ec290636298 100644
>> --- a/hw/block/pflash_cfi01.c
>> +++ b/hw/block/pflash_cfi01.c
>> @@ -702,6 +702,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
>> int ret;
>> uint64_t blocks_per_device, sector_len_per_device, device_len;
>> int num_devices;
>> + bool romd_mr_shared_mapped;
>>
>> if (pfl->sector_len == 0) {
>> error_setg(errp, "attribute \"sector-length\" not specified or zero.");
>> @@ -743,19 +744,41 @@ 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 (*errp) {
>> - return;
>> + if (pfl->ro && pfl->blk) {
>> + BlockDriverState *bs = blk_bs(pfl->blk);
>> +
>> + /* If "raw" driver used, try to mmap the backing file as RAM_SHARED */
>> + if (bs->drv == &bdrv_raw) { /* FIXME check offset=0 ? */
>
> Bypassing the block layer is tricky because there are a lot of features
> that conflict (you already pointed out the offset= option). Checking
> bdrv_raw is not enough because the underlying protocol driver could be
> GlusterFS, iSCSI, etc.
OK.
> I think the goal here is to avoid changing the command-line/QMP so that
> users don't need to modify their guests. Therefore changing the pflash
> qdev properties is not desirable (we could have added a separate code
> path that bypasses the block layer cleanly).
Yes, this is the limitation.
> This seems like a
> worthwhile optimization that the block layer should support. I suggest
> adding a new API like:
>
> /* Returns a filename string if @blk supports read-only mmap */
> char *blk_get_read_only_mmap_filename(BlockBackend *blk, Error **errp);
>
> Then block/raw-format.c would forward the call to bs->file and
> block/raw-posix.c would implement it by returning a new filename string
> when bs->read_only is true.
Thanks :) Kevin suggested something similar too.
>
> FWIW this API isn't perfect because the file could be reopened with QMP
> and the existing mmap would remain in place.
Can you show me a QMP example or point me at the command?
This shouldn't happen with the pflash.
Thanks for reviewing,
Phil.
next prev parent reply other threads:[~2021-03-02 7:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-01 11:53 [RFC PATCH v2 0/3] hw/block/pflash: Mmap read-only backend files with MAP_SHARED Philippe Mathieu-Daudé
2021-03-01 11:53 ` [RFC PATCH v2 1/3] exec/memory: Introduce memory_region_init_rom_device_from_file() Philippe Mathieu-Daudé
2021-03-01 11:53 ` [RFC PATCH v2 2/3] hw/block/pflash: Move code around Philippe Mathieu-Daudé
2021-03-01 11:53 ` [RFC PATCH v2 3/3] hw/block/pflash: use memory_region_init_rom_device_from_file() Philippe Mathieu-Daudé
2021-03-01 18:13 ` Stefan Hajnoczi
2021-03-02 7:04 ` Philippe Mathieu-Daudé [this message]
2021-03-02 10:54 ` Stefan Hajnoczi
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=bc4b3dee-4af4-7ce2-aeaa-70c0cfde679f@redhat.com \
--to=philmd@redhat.com \
--cc=armbru@redhat.com \
--cc=david.edmondson@oracle.com \
--cc=haibinzhang@tencent.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.com \
--cc=stefanha@redhat.com \
--cc=xuyandong2@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).