[PATCH v3 14/33] softmmu/physmem: Remove HOST_PAGE_ALIGN

Richard Henderson posted 33 patches 10 months, 4 weeks ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Riku Voipio <riku.voipio@iki.fi>, Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Stefan Berger <stefanb@linux.vnet.ibm.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, Laurent Vivier <laurent@vivier.eu>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, David Hildenbrand <david@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Nicholas Piggin <npiggin@gmail.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, "Cédric Le Goater" <clg@kaod.org>, "Alex Bennée" <alex.bennee@linaro.org>, Yoshinori Sato <ysato@users.sourceforge.jp>
There is a newer version of this series
[PATCH v3 14/33] softmmu/physmem: Remove HOST_PAGE_ALIGN
Posted by Richard Henderson 10 months, 4 weeks ago
Align allocation sizes to the maximum of host and target page sizes.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 system/physmem.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/system/physmem.c b/system/physmem.c
index c09953270f..c1e48dfb6a 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -1680,7 +1680,8 @@ int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp)
 
     assert(block);
 
-    newsize = HOST_PAGE_ALIGN(newsize);
+    newsize = TARGET_PAGE_ALIGN(newsize);
+    newsize = REAL_HOST_PAGE_ALIGN(newsize);
 
     if (block->used_length == newsize) {
         /*
@@ -1916,7 +1917,9 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
         return NULL;
     }
 
-    size = HOST_PAGE_ALIGN(size);
+    size = TARGET_PAGE_ALIGN(size);
+    size = REAL_HOST_PAGE_ALIGN(size);
+
     file_size = get_file_size(fd);
     if (file_size > offset && file_size < (offset + size)) {
         error_setg(errp, "backing store size 0x%" PRIx64
@@ -2014,13 +2017,17 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
 {
     RAMBlock *new_block;
     Error *local_err = NULL;
+    int align;
 
     assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC |
                           RAM_NORESERVE)) == 0);
     assert(!host ^ (ram_flags & RAM_PREALLOC));
 
-    size = HOST_PAGE_ALIGN(size);
-    max_size = HOST_PAGE_ALIGN(max_size);
+    align = qemu_real_host_page_size();
+    align = MAX(align, TARGET_PAGE_SIZE);
+    size = ROUND_UP(size, align);
+    max_size = ROUND_UP(max_size, align);
+
     new_block = g_malloc0(sizeof(*new_block));
     new_block->mr = mr;
     new_block->resized = resized;
-- 
2.34.1
Re: [PATCH v3 14/33] softmmu/physmem: Remove HOST_PAGE_ALIGN
Posted by Ilya Leoshkevich 10 months ago
On Tue, Jan 02, 2024 at 12:57:49PM +1100, Richard Henderson wrote:
> Align allocation sizes to the maximum of host and target page sizes.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  system/physmem.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)

Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com>
Re: [PATCH v3 14/33] softmmu/physmem: Remove HOST_PAGE_ALIGN
Posted by Pierrick Bouvier 10 months, 3 weeks ago
On 1/2/24 05:57, Richard Henderson wrote:
> Align allocation sizes to the maximum of host and target page sizes.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   system/physmem.c | 15 +++++++++++----
>   1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/system/physmem.c b/system/physmem.c
> index c09953270f..c1e48dfb6a 100644
> --- a/system/physmem.c
> +++ b/system/physmem.c
> @@ -1680,7 +1680,8 @@ int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp)
>   
>       assert(block);
>   
> -    newsize = HOST_PAGE_ALIGN(newsize);
> +    newsize = TARGET_PAGE_ALIGN(newsize);
> +    newsize = REAL_HOST_PAGE_ALIGN(newsize);
>   
>       if (block->used_length == newsize) {
>           /*
> @@ -1916,7 +1917,9 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
>           return NULL;
>       }
>   
> -    size = HOST_PAGE_ALIGN(size);
> +    size = TARGET_PAGE_ALIGN(size);
> +    size = REAL_HOST_PAGE_ALIGN(size);
> +
>       file_size = get_file_size(fd);
>       if (file_size > offset && file_size < (offset + size)) {
>           error_setg(errp, "backing store size 0x%" PRIx64
> @@ -2014,13 +2017,17 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
>   {
>       RAMBlock *new_block;
>       Error *local_err = NULL;
> +    int align;
>   
>       assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC |
>                             RAM_NORESERVE)) == 0);
>       assert(!host ^ (ram_flags & RAM_PREALLOC));
>   
> -    size = HOST_PAGE_ALIGN(size);
> -    max_size = HOST_PAGE_ALIGN(max_size);
> +    align = qemu_real_host_page_size();
> +    align = MAX(align, TARGET_PAGE_SIZE);
> +    size = ROUND_UP(size, align);
> +    max_size = ROUND_UP(max_size, align);
> +
>       new_block = g_malloc0(sizeof(*new_block));
>       new_block->mr = mr;
>       new_block->resized = resized;

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>