All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] util/oslib-win32: Fix fatal assertion in qemu_try_memalign
@ 2021-06-11 10:58 Stefan Weil
  2021-06-11 11:06 ` Philippe Mathieu-Daudé
  2021-06-19 15:48 ` Richard Henderson
  0 siblings, 2 replies; 4+ messages in thread
From: Stefan Weil @ 2021-06-11 10:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-trivial, Richard Henderson, Philippe Mathieu-Daudé,
	Stefan Weil

The function is called with alignment == 0 which caused an assertion.
Use the code from oslib_posix.c to fix that regression (introduced
by commit ed6f53f9ca9).

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 util/oslib-win32.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index ca99356fdf..7b318ea835 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -57,7 +57,11 @@ void *qemu_try_memalign(size_t alignment, size_t size)
     void *ptr;
 
     g_assert(size != 0);
-    g_assert(is_power_of_2(alignment));
+    if (alignment < sizeof(void *)) {
+        alignment = sizeof(void *);
+    } else {
+        g_assert(is_power_of_2(alignment));
+    }
     ptr = _aligned_malloc(size, alignment);
     trace_qemu_memalign(alignment, size, ptr);
     return ptr;
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] util/oslib-win32: Fix fatal assertion in qemu_try_memalign
  2021-06-11 10:58 [PATCH] util/oslib-win32: Fix fatal assertion in qemu_try_memalign Stefan Weil
@ 2021-06-11 11:06 ` Philippe Mathieu-Daudé
  2021-06-11 11:12   ` Stefan Weil
  2021-06-19 15:48 ` Richard Henderson
  1 sibling, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-06-11 11:06 UTC (permalink / raw)
  To: Stefan Weil, qemu-devel; +Cc: qemu-trivial, Richard Henderson

On 6/11/21 12:58 PM, Stefan Weil wrote:
> The function is called with alignment == 0 which caused an assertion.
> Use the code from oslib_posix.c to fix that regression (introduced
> by commit ed6f53f9ca9).
> 

Oops.

Can we replace '(introduced by commit ed6f53f9ca9)' by:
Fixes: ed6f53f9ca9 ("util/oslib: Assert qemu_try_memalign() alignment is
a power of 2")

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>  util/oslib-win32.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> index ca99356fdf..7b318ea835 100644
> --- a/util/oslib-win32.c
> +++ b/util/oslib-win32.c
> @@ -57,7 +57,11 @@ void *qemu_try_memalign(size_t alignment, size_t size)
>      void *ptr;
>  
>      g_assert(size != 0);
> -    g_assert(is_power_of_2(alignment));
> +    if (alignment < sizeof(void *)) {
> +        alignment = sizeof(void *);
> +    } else {
> +        g_assert(is_power_of_2(alignment));
> +    }
>      ptr = _aligned_malloc(size, alignment);
>      trace_qemu_memalign(alignment, size, ptr);
>      return ptr;
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] util/oslib-win32: Fix fatal assertion in qemu_try_memalign
  2021-06-11 11:06 ` Philippe Mathieu-Daudé
@ 2021-06-11 11:12   ` Stefan Weil
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Weil @ 2021-06-11 11:12 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: qemu-trivial, Richard Henderson

Am 11.06.21 um 13:06 schrieb Philippe Mathieu-Daudé:

> On 6/11/21 12:58 PM, Stefan Weil wrote:
>> The function is called with alignment == 0 which caused an assertion.
>> Use the code from oslib_posix.c to fix that regression (introduced
>> by commit ed6f53f9ca9).
>>
> Oops.
>
> Can we replace '(introduced by commit ed6f53f9ca9)' by:
> Fixes: ed6f53f9ca9 ("util/oslib: Assert qemu_try_memalign() alignment is
> a power of 2")
>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>


Sure, that's fine for me, too. I think the text can be changed without a 
v2 of the patch.

Stefan




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: util/oslib-win32: Fix fatal assertion in qemu_try_memalign
  2021-06-11 10:58 [PATCH] util/oslib-win32: Fix fatal assertion in qemu_try_memalign Stefan Weil
  2021-06-11 11:06 ` Philippe Mathieu-Daudé
@ 2021-06-19 15:48 ` Richard Henderson
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2021-06-19 15:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: sw, philmd

> The function is called with alignment == 0 which caused an assertion.
> Use the code from oslib_posix.c to fix that regression (introduced
> by commit ed6f53f9ca9).
> 
> Signed-off-by: Stefan Weil <sw@weilnetz.de>

I'll queue this to tcg-next, as I'm about to do a PR for that.
I'll add the Fixed: tag as suggested by Phil.


r~


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-19 15:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-11 10:58 [PATCH] util/oslib-win32: Fix fatal assertion in qemu_try_memalign Stefan Weil
2021-06-11 11:06 ` Philippe Mathieu-Daudé
2021-06-11 11:12   ` Stefan Weil
2021-06-19 15:48 ` Richard Henderson

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.