From: Juan Quintela <quintela@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org, imammedo@redhat.com, dgilbert@redhat.com,
Paolo Bonzini <pbonzini@redhat.com>,
Peter Crosthwaite <crosthwaite.peter@gmail.com>,
Richard Henderson <rth@twiddle.net>,
Alex Williamson <alex.williamson@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] memory: size can be different from ptr_size
Date: Wed, 05 Sep 2018 13:37:11 +0200 [thread overview]
Message-ID: <87va7k9nvc.fsf@trasno.org> (raw)
In-Reply-To: <20180905082919.6986-1-marcandre.lureau@redhat.com> ("Marc-André Lureau"'s message of "Wed, 5 Sep 2018 12:29:19 +0400")
Marc-André Lureau <marcandre.lureau@redhat.com> wrote:
> memory_region_init_ram*_ptr() take only the size of the MemoryRegion,
> and allocate a RAMBlock with the same size. However, it may be
> convenient to expose a smaller MemoryRegion (for ex: a few bytes) than
> the RAMBlock (which must be a multiple of TARGET_PAGE_SIZE).
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> include/exec/memory.h | 8 ++++++--
> exec.c | 3 +++
> hw/display/g364fb.c | 2 +-
> hw/vfio/common.c | 3 ++-
> hw/virtio/vhost-user.c | 2 +-
> memory.c | 10 ++++++----
> 6 files changed, 19 insertions(+), 9 deletions(-)
>
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index eb4f2fb249..03f257829b 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -700,6 +700,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr,
> * must be unique within any device
> * @size: size of the region.
> * @ptr: memory to be mapped; must contain at least @size bytes.
^^^^^
this comment gets wrong with your patches
> + * @ptr_size: size of @ptr buffer
> diff --git a/exec.c b/exec.c
> index 6826c8337d..fcea614e79 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -2361,6 +2361,9 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
> RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
> MemoryRegion *mr, Error **errp)
> {
> + assert(size >= TARGET_PAGE_SIZE);
> + assert(size % TARGET_PAGE_SIZE == 0);
> +
> return qemu_ram_alloc_internal(size, size, NULL, host, false,
> false, mr, errp);
> }
ok with this bit.
But how about to change instead to:
void memory_region_init_ram_ptr(MemoryRegion *mr,
Object *owner,
const char *name,
uint64_t size,
void *ptr)
{
uint64_t real_size = ROUND_UP_TARGET_PAGE_SIZE(size);
memory_region_init(mr, owner, name, real_size);
mr->ram = true;
mr->terminates = true;
mr->destructor = memory_region_destructor_ram;
mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
/* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL. */
assert(ptr != NULL);
mr->ram_block = qemu_ram_alloc_from_ptr(size, ptr, mr, &error_fatal);
}
For a suitable ROUND_UP_TARGET_PAGE_SIZE() macro. You get the idea.
And memory_region_device_ram_ptr() don't even need a change.
We need to adjust the comments, but it looks like an easier patch to me, no?
> diff --git a/hw/display/g364fb.c b/hw/display/g364fb.c
> index fbc2b2422d..f4f5643761 100644
> --- a/hw/display/g364fb.c
> +++ b/hw/display/g364fb.c
> @@ -475,7 +475,7 @@ static void g364fb_init(DeviceState *dev, G364State *s)
>
> memory_region_init_io(&s->mem_ctrl, NULL, &g364fb_ctrl_ops, s, "ctrl", 0x180000);
> memory_region_init_ram_ptr(&s->mem_vram, NULL, "vram",
> - s->vram_size, s->vram);
> + s->vram_size, s->vram, s->vram_size);
Having to change all the devices that use the function with exactly the
same parameter looks weird to me.
What do you think?
Later, Juan.
next prev parent reply other threads:[~2018-09-05 11:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-05 8:29 [Qemu-devel] [PATCH] memory: size can be different from ptr_size Marc-André Lureau
2018-09-05 11:37 ` Juan Quintela [this message]
2018-09-05 17:51 ` Marc-André Lureau
2018-09-05 19:45 ` Marc-André Lureau
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=87va7k9nvc.fsf@trasno.org \
--to=quintela@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=crosthwaite.peter@gmail.com \
--cc=dgilbert@redhat.com \
--cc=imammedo@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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.