Skip to contentSkip to conversation

hw/xen: Build only once

PATCH In review Philippe Mathieu-Daudé 3 participants 12 messages Oct 22, 2025 – Oct 29, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover hw/xen: Build only once

Replace target-specific code to allow building
hw/xen/ files once.

Philippe Mathieu-Daudé (3):
hw/xen: Use BITS_PER_BYTE & MAKE_64BIT_MASK() in req_size_bits() hw/xen: Replace target_ulong by agnostic target_long_bits() hw/xen: Build only once

 hw/xen/xen-hvm-common.c |  9 ++++++---
 hw/xen/meson.build      | 22 +++++++++-------------
 2 files changed, 15 insertions(+), 16 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH 1/3 hw/xen: Use BITS_PER_BYTE & MAKE_64BIT_MASK() in req_size_bits()

Replace magic 8 by BITS_PER_BYTE, use MAKE_64BIT_MASK() instead of open coding it.

---
 hw/xen/xen-hvm-common.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/xen/xen-hvm-common.c +4 -1
index 52e2cce397a..258014370e1 100644
@@ -1,5 +1,6 @@
 #include "qemu/osdep.h"
 #include "qemu/units.h"
+#include "qemu/bitops.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "exec/target_long.h"
@@ -448,12 +449,14 @@ static void cpu_ioreq_config(XenIOState *state, ioreq_t *req)
 
 static void handle_ioreq(XenIOState *state, ioreq_t *req)
 {
+    size_t req_size_bits = req->size * BITS_PER_BYTE;
+
     trace_handle_ioreq(req, req->type, req->dir, req->df, req->data_is_ptr,
                        req->addr, req->data, req->count, req->size);
 
     if (!req->data_is_ptr && (req->dir == IOREQ_WRITE) &&
             (req->size < sizeof (target_ulong))) {
-        req->data &= ((target_ulong) 1 << (8 * req->size)) - 1;
+        req->data &= MAKE_64BIT_MASK(0, req_size_bits);
     }
 
     if (req->dir == IOREQ_WRITE)
Signature · 1 line
2.51.0
Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] hw/xen: Use BITS_PER_BYTE & MAKE_64BIT_MASK() in req_size_bits()

In reply to Philippe Mathieu-Daudé
Quoted 4 lines · Philippe Mathieu-Daudé

Replace magic 8 by BITS_PER_BYTE, use MAKE_64BIT_MASK() instead of open coding it.

Quoted 34 lines
---
 hw/xen/xen-hvm-common.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/xen/xen-hvm-common.c +4 -1
index 52e2cce397a..258014370e1 100644
@@ -1,5 +1,6 @@
 #include "qemu/osdep.h"
 #include "qemu/units.h"
+#include "qemu/bitops.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "exec/target_long.h"
@@ -448,12 +449,14 @@ static void cpu_ioreq_config(XenIOState *state, ioreq_t *req)
 
 static void handle_ioreq(XenIOState *state, ioreq_t *req)
 {
+    size_t req_size_bits = req->size * BITS_PER_BYTE;
+
     trace_handle_ioreq(req, req->type, req->dir, req->df, req->data_is_ptr,
                        req->addr, req->data, req->count, req->size);
 
     if (!req->data_is_ptr && (req->dir == IOREQ_WRITE) &&
             (req->size < sizeof (target_ulong))) {
-        req->data &= ((target_ulong) 1 << (8 * req->size)) - 1;
+        req->data &= MAKE_64BIT_MASK(0, req_size_bits);
     }
 
     if (req->dir == IOREQ_WRITE)
Signature · 1 line
2.51.0
#4 lore raw

PATCH 2/3 hw/xen: Replace target_ulong by agnostic target_long_bits()

In reply to Philippe Mathieu-Daudé

Both are equivalent:

target_long_bits()

sizeof(target_u?long) * BITS_PER_BYTE

Prefer the former which is target-agnostic.

---
 hw/xen/xen-hvm-common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/xen/xen-hvm-common.c +2 -2
index 258014370e1..b40ae0b3af0 100644
@@ -2,8 +2,8 @@
 #include "qemu/units.h"
 #include "qemu/bitops.h"
 #include "qemu/error-report.h"
+#include "qemu/target-info.h"
 #include "qapi/error.h"
-#include "exec/target_long.h"
 #include "exec/target_page.h"
 #include "trace.h"
 
@@ -455,7 +455,7 @@ static void handle_ioreq(XenIOState *state, ioreq_t *req)
                        req->addr, req->data, req->count, req->size);
 
     if (!req->data_is_ptr && (req->dir == IOREQ_WRITE) &&
-            (req->size < sizeof (target_ulong))) {
+            (req_size_bits < target_long_bits())) {
         req->data &= MAKE_64BIT_MASK(0, req_size_bits);
     }
 
Signature · 1 line
2.51.0
Reviewed-by on v1 2/3
#5 lore raw

Re: [PATCH 2/3] hw/xen: Replace target_ulong by agnostic target_long_bits()

Quoted 4 lines · Philippe Mathieu-Daudé

Both are equivalent:

target_long_bits()

Quoted 8 lines

sizeof(target_u?long) * BITS_PER_BYTE

Prefer the former which is target-agnostic.

---
  hw/xen/xen-hvm-common.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by on v1 2/3
#6 lore raw

Re: [PATCH 2/3] hw/xen: Replace target_ulong by agnostic target_long_bits()

In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

Both are equivalent:

target_long_bits()

sizeof(target_u?long) * BITS_PER_BYTE

Prefer the former which is target-agnostic.

Quoted 30 lines
---
 hw/xen/xen-hvm-common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/xen/xen-hvm-common.c +2 -2
index 258014370e1..b40ae0b3af0 100644
@@ -2,8 +2,8 @@
 #include "qemu/units.h"
 #include "qemu/bitops.h"
 #include "qemu/error-report.h"
+#include "qemu/target-info.h"
 #include "qapi/error.h"
-#include "exec/target_long.h"
 #include "exec/target_page.h"
 #include "trace.h"
 
@@ -455,7 +455,7 @@ static void handle_ioreq(XenIOState *state, ioreq_t *req)
                        req->addr, req->data, req->count, req->size);
 
     if (!req->data_is_ptr && (req->dir == IOREQ_WRITE) &&
-            (req->size < sizeof (target_ulong))) {
+            (req_size_bits < target_long_bits())) {
         req->data &= MAKE_64BIT_MASK(0, req_size_bits);
     }
 
Signature · 1 line
2.51.0
#7 lore raw

PATCH 3/3 hw/xen: Build only once

In reply to Philippe Mathieu-Daudé

Now than hw/xen/ files don't use any target-specific code, we can build all file units once, removing the need for the xen_specific_ss[] source set.

---
 hw/xen/meson.build | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
hw/xen/meson.build +9 -13
index a1850e76988..dcd2b7e1df3 100644
@@ -7,21 +7,16 @@ system_ss.add(when: ['CONFIG_XEN_BUS'], if_true: files(
   'xen_pvdev.c',
 ))
 
-system_ss.add(when: ['CONFIG_XEN', xen], if_true: files(
-  'xen-operations.c',
-),
-if_false: files(
-  'xen_stubs.c',
-))
-
-xen_specific_ss = ss.source_set()
-xen_specific_ss.add(files(
-  'xen-mapcache.c',
+xen_common_ss = ss.source_set()
+xen_common_ss.add(files(
   'xen-hvm-common.c',
+  'xen-mapcache.c',
+  'xen-operations.c',
   'xen-pvh-common.c',
 ))
+
 if have_xen_pci_passthrough
-  xen_specific_ss.add(files(
+  xen_common_ss.add(files(
     'xen-host-pci-device.c',
     'xen_pt.c',
     'xen_pt_config_init.c',
@@ -30,7 +25,8 @@ if have_xen_pci_passthrough
     'xen_pt_msi.c',
   ))
 else
-  xen_specific_ss.add(files('xen_pt_stub.c'))
+  xen_common_ss.add(files('xen_pt_stub.c'))
 endif
 
-specific_ss.add_all(when: ['CONFIG_XEN', xen], if_true: xen_specific_ss)
+system_ss.add_all(when: ['CONFIG_XEN', xen], if_true: xen_common_ss)
+system_ss.add(when: ['CONFIG_XEN', xen], if_false: files('xen_stubs.c'))
Signature · 1 line
2.51.0
Reviewed-by on v1 3/3
#9 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 5 lines · Philippe Mathieu-Daudé

Now than hw/xen/ files don't use any target-specific code, we can build all file units once, removing the need for the xen_specific_ss[] source set.

Quoted 50 lines
---
 hw/xen/meson.build | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
hw/xen/meson.build +9 -13
index a1850e76988..dcd2b7e1df3 100644
@@ -7,21 +7,16 @@ system_ss.add(when: ['CONFIG_XEN_BUS'], if_true: files(
   'xen_pvdev.c',
 ))
 
-system_ss.add(when: ['CONFIG_XEN', xen], if_true: files(
-  'xen-operations.c',
-),
-if_false: files(
-  'xen_stubs.c',
-))
-
-xen_specific_ss = ss.source_set()
-xen_specific_ss.add(files(
-  'xen-mapcache.c',
+xen_common_ss = ss.source_set()
+xen_common_ss.add(files(
   'xen-hvm-common.c',
+  'xen-mapcache.c',
+  'xen-operations.c',
   'xen-pvh-common.c',
 ))
+
 if have_xen_pci_passthrough
-  xen_specific_ss.add(files(
+  xen_common_ss.add(files(
     'xen-host-pci-device.c',
     'xen_pt.c',
     'xen_pt_config_init.c',
@@ -30,7 +25,8 @@ if have_xen_pci_passthrough
     'xen_pt_msi.c',
   ))
 else
-  xen_specific_ss.add(files('xen_pt_stub.c'))
+  xen_common_ss.add(files('xen_pt_stub.c'))
 endif
 
-specific_ss.add_all(when: ['CONFIG_XEN', xen], if_true: xen_specific_ss)
+system_ss.add_all(when: ['CONFIG_XEN', xen], if_true: xen_common_ss)
+system_ss.add(when: ['CONFIG_XEN', xen], if_false: files('xen_stubs.c'))
Signature · 1 line
2.51.0
#10 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Replace target-specific code to allow building
hw/xen/ files once.

Philippe Mathieu-Daudé (3):
hw/xen: Use BITS_PER_BYTE & MAKE_64BIT_MASK() in req_size_bits() hw/xen: Replace target_ulong by agnostic target_long_bits() hw/xen: Build only once

ping?

#11 lore raw
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Replace target-specific code to allow building
hw/xen/ files once.

Philippe Mathieu-Daudé (3):
   hw/xen: Use BITS_PER_BYTE & MAKE_64BIT_MASK() in req_size_bits() hw/xen: Replace target_ulong by agnostic target_long_bits() hw/xen: Build only once

ping?

Series queued, thanks!