All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] x86/HVM: fully switch emulate.c to use xvmalloc_array()
@ 2025-07-28 11:25 Jan Beulich
  2025-07-28 12:04 ` Roger Pau Monné
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Beulich @ 2025-07-28 11:25 UTC (permalink / raw)
  To: xen-devel@lists.xenproject.org; +Cc: Andrew Cooper, Roger Pau Monné

Use the more "modern" forms consistently, thus doing away with
effectively open-coding xmalloc_array() at the same time. While there
is a difference in generated code, as xmalloc_bytes() forces
SMP_CACHE_BYTES alignment, if code really cared about such higher than
default alignment, it should request so explicitly.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
v3: Use xvmalloc_array().

--- a/xen/arch/x86/hvm/emulate.c
+++ b/xen/arch/x86/hvm/emulate.c
@@ -17,6 +17,7 @@
 #include <xen/paging.h>
 #include <xen/trace.h>
 #include <xen/vm_event.h>
+#include <xen/xvmalloc.h>
 
 #include <asm/altp2m.h>
 #include <asm/event.h>
@@ -2050,7 +2051,7 @@ static int cf_check hvmemul_rep_movs(
         dgpa -= bytes - bytes_per_rep;
 
     /* Allocate temporary buffer. Fall back to slow emulation if this fails. */
-    buf = xmalloc_bytes(bytes);
+    buf = xvmalloc_array(char, bytes);
     if ( buf == NULL )
         return X86EMUL_UNHANDLEABLE;
 
@@ -2060,7 +2061,7 @@ static int cf_check hvmemul_rep_movs(
 
         if ( rc != X86EMUL_OKAY)
         {
-            xfree(buf);
+            xvfree(buf);
             return rc;
         }
 
@@ -2082,7 +2083,7 @@ static int cf_check hvmemul_rep_movs(
     if ( rc == HVMTRANS_okay )
         rc = hvm_copy_to_guest_phys(dgpa, buf, bytes, curr);
 
-    xfree(buf);
+    xvfree(buf);
 
     switch ( rc )
     {
@@ -2162,7 +2163,7 @@ static int cf_check hvmemul_rep_stos(
         for ( ; ; )
         {
             bytes = *reps * bytes_per_rep;
-            buf = xmalloc_bytes(bytes);
+            buf = xvmalloc_array(char, bytes);
             if ( buf || *reps <= 1 )
                 break;
             *reps >>= 1;
@@ -2191,7 +2192,7 @@ static int cf_check hvmemul_rep_stos(
 
             default:
                 ASSERT_UNREACHABLE();
-                xfree(buf);
+                xvfree(buf);
                 return X86EMUL_UNHANDLEABLE;
             }
 
@@ -2202,7 +2203,7 @@ static int cf_check hvmemul_rep_stos(
         rc = hvm_copy_to_guest_phys(gpa, buf, bytes, curr);
 
         if ( buf != p_data )
-            xfree(buf);
+            xvfree(buf);
 
         switch ( rc )
         {


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

* Re: [PATCH v3] x86/HVM: fully switch emulate.c to use xvmalloc_array()
  2025-07-28 11:25 [PATCH v3] x86/HVM: fully switch emulate.c to use xvmalloc_array() Jan Beulich
@ 2025-07-28 12:04 ` Roger Pau Monné
  0 siblings, 0 replies; 2+ messages in thread
From: Roger Pau Monné @ 2025-07-28 12:04 UTC (permalink / raw)
  To: Jan Beulich; +Cc: xen-devel@lists.xenproject.org, Andrew Cooper

On Mon, Jul 28, 2025 at 01:25:14PM +0200, Jan Beulich wrote:
> Use the more "modern" forms consistently, thus doing away with
> effectively open-coding xmalloc_array() at the same time. While there
> is a difference in generated code, as xmalloc_bytes() forces
> SMP_CACHE_BYTES alignment, if code really cared about such higher than
> default alignment, it should request so explicitly.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Acked-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks, Roger.


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

end of thread, other threads:[~2025-07-28 12:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-28 11:25 [PATCH v3] x86/HVM: fully switch emulate.c to use xvmalloc_array() Jan Beulich
2025-07-28 12:04 ` Roger Pau Monné

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.