qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Michal Privoznik <mprivozn@redhat.com>, qemu-devel@nongnu.org
Cc: david@redhat.com, imammedo@redhat.com
Subject: Re: [PATCH v2 4/4] backends/hostmem: Report error when memory size is unaligned
Date: Fri, 31 May 2024 09:53:36 +0200	[thread overview]
Message-ID: <3ec04dc4-f837-419c-b83a-b82a484ab5df@linaro.org> (raw)
In-Reply-To: <58295d1f6c995c0c444e375348436e799689126c.1717140354.git.mprivozn@redhat.com>

Hi Michal,

On 31/5/24 09:29, Michal Privoznik wrote:
> If memory-backend-{file,ram} has a size that's not aligned to
> underlying page size it is not only wasteful, but also may lead
> to hard to debug behaviour. For instance, in case
> memory-backend-file and hugepages, madvise() and mbind() fail.
> Rightfully so, page is the smallest unit they can work with. And
> even though an error is reported, the root cause it not very
> clear:
> 
>    qemu-system-x86_64: Couldn't set property 'dump' on 'memory-backend-file': Invalid argument
> 
> After this commit:
> 
>    qemu-system-x86_64: backend memory size must be multiple of 0x200000
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>   backends/hostmem.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
> 
> diff --git a/backends/hostmem.c b/backends/hostmem.c
> index 012a8c190f..5f9c9ea8f5 100644
> --- a/backends/hostmem.c
> +++ b/backends/hostmem.c
> @@ -337,6 +337,7 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
>       HostMemoryBackendClass *bc = MEMORY_BACKEND_GET_CLASS(uc);
>       void *ptr;
>       uint64_t sz;
> +    size_t pagesize;
>       bool async = !phase_check(PHASE_LATE_BACKENDS_CREATED);
>   
>       if (!bc->alloc) {
> @@ -348,6 +349,13 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
>   
>       ptr = memory_region_get_ram_ptr(&backend->mr);
>       sz = memory_region_size(&backend->mr);
> +    pagesize = qemu_ram_pagesize(backend->mr.ram_block);
> +
> +    if (!QEMU_IS_ALIGNED(sz, pagesize)) {
> +        error_setg(errp, "backend memory size must be multiple of 0x%"
> +                   PRIx64, pagesize);

Can we use size_to_str() instead?

Also display backend name:

"backend '%s' memory size must be multiple of %s"

> +        return;
> +    }
>   
>       if (backend->merge &&
>           qemu_madvise(ptr, sz, QEMU_MADV_MERGEABLE)) {



  reply	other threads:[~2024-05-31  7:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-31  7:28 [PATCH v2 0/4] backends/hostmem: Report more errors on failures Michal Privoznik
2024-05-31  7:28 ` [PATCH v2 1/4] osdep: Make qemu_madvise() to set errno in all cases Michal Privoznik
2024-05-31  7:57   ` Philippe Mathieu-Daudé
2024-05-31  8:01     ` David Hildenbrand
2024-05-31  8:12       ` Philippe Mathieu-Daudé
2024-05-31  9:08         ` David Hildenbrand
2024-05-31 11:10           ` Michal Prívozník
2024-05-31  7:28 ` [PATCH v2 2/4] osdep: Make qemu_madvise() return ENOSYS on unsupported OSes Michal Privoznik
2024-05-31  7:48   ` Philippe Mathieu-Daudé
2024-05-31  7:53   ` David Hildenbrand
2024-05-31  8:02     ` Philippe Mathieu-Daudé
2024-05-31  7:28 ` [PATCH v2 3/4] backends/hostmem: Report error on qemu_madvise() failures Michal Privoznik
2024-05-31  7:49   ` Philippe Mathieu-Daudé
2024-05-31  9:10   ` David Hildenbrand
2024-05-31  7:29 ` [PATCH v2 4/4] backends/hostmem: Report error when memory size is unaligned Michal Privoznik
2024-05-31  7:53   ` Philippe Mathieu-Daudé [this message]
2024-06-05  7:12   ` Mario Casquero

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=3ec04dc4-f837-419c-b83a-b82a484ab5df@linaro.org \
    --to=philmd@linaro.org \
    --cc=david@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=mprivozn@redhat.com \
    --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).