qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: pbonzini@redhat.com, Anthony Liguori <aliguori@us.ibm.com>,
	Laszlo Ersek <lersek@redhat.com>,
	qemu-devel@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 for-1.6 v2 2/2] loader: put FW CFG ROM files into RAM
Date: Mon, 12 Aug 2013 21:56:13 +0300	[thread overview]
Message-ID: <20130812185612.GA1616@redhat.com> (raw)
In-Reply-To: <CAFEAcA9UntFLJ8GYKQScCCTN2BFARsT+7L8JGQSoQekpBwMjMA@mail.gmail.com>

On Mon, Aug 12, 2013 at 07:37:21PM +0100, Peter Maydell wrote:
> On 12 August 2013 19:16, Michael S. Tsirkin <mst@redhat.com> wrote:
> > +static void *rom_set_mr(Rom *rom, Object *owner, const char *name)
> > +{
> > +    /*
> > +     * Migration code expects that all RAM blocks are full pages.
> > +     * Round MR size up to satisfy this condition.
> > +     */
> > +    unsigned size = ROUND_UP(rom->datasize, qemu_migration_page_size);
> > +    void *data = g_malloc0(size);
> > +
> > +    memcpy(data, rom->data, rom->datasize);
> > +
> > +    rom->mr = g_malloc(sizeof(*rom->mr));
> > +    memory_region_init_ram_ptr(rom->mr, owner, name, size, data);
> > +    memory_region_set_readonly(rom->mr, true);
> > +    vmstate_register_ram_global(rom->mr);
> 
> So having thought about this a little I think the right answer
> here is "don't use memory_region_init_ram_ptr()". At the moment
> in-tree we have five users of this function:
> 
> hw/display/g364fb.c
> hw/i386/kvm/pci-assign.c
> hw/misc/ivshmem.c
> hw/misc/vfio.c
> target-ppc/kvm.c
> 
> The last four of these all absolutely have to have the guest
> use a specific host pointer, typically the result of mmap()ing
> something [shared file, PCI device, KVM_ALLOCATE_RMA fd, etc].
> The first one I think should be converted to use
> memory_region_init_ram() instead, because it doesn't need
> to use a particular buffer.
> 
> Similarly, what you're trying to do here doesn't require
> that the guest sees any specific host pointer, so you should
> just use memory_region_init_ram().

I was concerned that we are wasting resources here.
In particular, huge page memory might get allocated
and there's no need for it as it's never mapped
into guest.

Still if Paolo is OK with this too, I'll switch, and do
+ memory_region_init_ram_ptr(...)
+ data = memory_region_get_ram_ptr(rom->mr);

Paolo could you please confirm?


> 
> We should add an assert to the _init_ram_ptr functions that
> checks that the size is OK, as well.

At least for pci-assign and vfio it's the wrong thing
to do - they block migration so we don't need
the ram to be a multiple of migration page size.

> I seem to recall having a conversation with Paolo along these
> lines a few months back (we fixed the exynos devices which
> were incorrectly using the _ram_ptr function); he can correct
> me if I'm off-base here.
> 
> -- PMM

  reply	other threads:[~2013-08-12 18:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-12 18:15 [Qemu-devel] [PATCH v2 for-1.6 0/2] future proof rom loading for cross versiom migration Michael S. Tsirkin
2013-08-12 18:15 ` [Qemu-devel] [PATCH v2 for-1.6 v2 1/2] memory: export migration page size Michael S. Tsirkin
2013-08-12 18:16 ` [Qemu-devel] [PATCH v2 for-1.6 v2 2/2] loader: put FW CFG ROM files into RAM Michael S. Tsirkin
2013-08-12 18:37   ` Peter Maydell
2013-08-12 18:56     ` Michael S. Tsirkin [this message]
2013-08-13 14:47       ` Paolo Bonzini
2013-08-13 15:11         ` Michael S. Tsirkin
2013-08-12 22:03     ` Paolo Bonzini
2013-08-12 18:18 ` [Qemu-devel] [PATCH v2 for-1.6 0/2] future proof rom loading for cross versiom migration Michael S. Tsirkin

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=20130812185612.GA1616@redhat.com \
    --to=mst@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=kraxel@redhat.com \
    --cc=lersek@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 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).