[PATCH-for-10.1 v7 5/8] qemu: Convert target_words_bigendian() to TargetInfo API

Philippe Mathieu-Daudé posted 8 patches 5 months, 1 week ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, "Michael S. Tsirkin" <mst@redhat.com>, Igor Mammedov <imammedo@redhat.com>, Ani Sinha <anisinha@redhat.com>, Beniamino Galvani <b.galvani@gmail.com>, Peter Maydell <peter.maydell@linaro.org>, Strahinja Jankovic <strahinja.p.jankovic@gmail.com>, Tyrone Ting <kfting@nuvoton.com>, Hao Wu <wuhaotsh@google.com>, John Snow <jsnow@redhat.com>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, Jonathan Cameron <jonathan.cameron@huawei.com>, Fan Ni <fan.ni@samsung.com>, Helge Deller <deller@gmx.de>, Gerd Hoffmann <kraxel@redhat.com>, Pavel Pisa <pisa@cmp.felk.cvut.cz>, Francisco Iglesias <francisco.iglesias@amd.com>, Vikram Garhwal <vikram.garhwal@bytedance.com>, Jason Wang <jasowang@redhat.com>, Dmitry Fleytman <dmitry.fleytman@gmail.com>, Aurelien Jarno <aurelien@aurel32.net>, Nicholas Piggin <npiggin@gmail.com>, "Frédéric Barrat" <fbarrat@linux.ibm.com>, Bernhard Beschow <shentey@gmail.com>, Yoshinori Sato <yoshinori.sato@nifty.com>, Magnus Damm <magnus.damm@gmail.com>, Matthew Rosato <mjrosato@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Alex Williamson <alex.williamson@redhat.com>, "Cédric Le Goater" <clg@redhat.com>, Alexander Graf <agraf@csgraf.de>, Phil Dennis-Jordan <phil@philjordan.eu>, "Alex Bennée" <alex.bennee@linaro.org>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, Peter Xu <peterx@redhat.com>, Riku Voipio <riku.voipio@iki.fi>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>, Song Gao <gaosong@loongson.cn>, Huacai Chen <chenhuacai@kernel.org>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aleksandar Rikalo <arikalo@gmail.com>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>
There is a newer version of this series
[PATCH-for-10.1 v7 5/8] qemu: Convert target_words_bigendian() to TargetInfo API
Posted by Philippe Mathieu-Daudé 5 months, 1 week ago
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/exec/tswap.h       | 13 +------------
 include/qemu/target-info.h |  8 ++++++++
 cpu-target.c               |  7 -------
 hw/core/cpu-system.c       |  2 +-
 hw/display/vga.c           |  2 +-
 hw/virtio/virtio.c         |  2 +-
 system/memory.c            |  1 +
 system/qtest.c             |  1 +
 target-info.c              |  5 +++++
 9 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/include/exec/tswap.h b/include/exec/tswap.h
index 49511f26117..55ffa633598 100644
--- a/include/exec/tswap.h
+++ b/include/exec/tswap.h
@@ -9,18 +9,7 @@
 #define TSWAP_H
 
 #include "qemu/bswap.h"
-
-/**
- * target_big_endian:
- * Returns true if the (default) endianness of the target is big endian,
- * false otherwise. Common code should normally never need to know about the
- * endianness of the target, so please do *not* use this function unless you
- * know very well what you are doing!
- */
-bool target_big_endian(void);
-#ifdef COMPILING_PER_TARGET
-#define target_big_endian()   TARGET_BIG_ENDIAN
-#endif
+#include "qemu/target-info.h"
 
 /*
  * If we're in target-specific code, we can hard-code the swapping
diff --git a/include/qemu/target-info.h b/include/qemu/target-info.h
index dde0e7d968a..18a8c4ff6e8 100644
--- a/include/qemu/target-info.h
+++ b/include/qemu/target-info.h
@@ -38,4 +38,12 @@ const char *target_machine_typename(void);
  */
 const char *target_cpu_type(void);
 
+/**
+ * target_big_endian:
+ *
+ * Returns: %true if the (default) endianness of the target is big endian,
+ *          %false otherwise.
+ */
+bool target_big_endian(void);
+
 #endif
diff --git a/cpu-target.c b/cpu-target.c
index 1c90a307593..20db5ff3108 100644
--- a/cpu-target.c
+++ b/cpu-target.c
@@ -22,7 +22,6 @@
 #include "system/accel-ops.h"
 #include "system/cpus.h"
 #include "exec/cpu-common.h"
-#include "exec/tswap.h"
 #include "exec/replay-core.h"
 #include "exec/log.h"
 #include "hw/core/cpu.h"
@@ -85,9 +84,3 @@ void cpu_abort(CPUState *cpu, const char *fmt, ...)
 #endif
     abort();
 }
-
-#undef target_big_endian
-bool target_big_endian(void)
-{
-    return TARGET_BIG_ENDIAN;
-}
diff --git a/hw/core/cpu-system.c b/hw/core/cpu-system.c
index 3c84176a0c5..a975405d3a0 100644
--- a/hw/core/cpu-system.c
+++ b/hw/core/cpu-system.c
@@ -24,7 +24,7 @@
 #include "exec/cputlb.h"
 #include "system/memory.h"
 #include "exec/tb-flush.h"
-#include "exec/tswap.h"
+#include "qemu/target-info.h"
 #include "hw/qdev-core.h"
 #include "hw/qdev-properties.h"
 #include "hw/core/sysemu-cpu-ops.h"
diff --git a/hw/display/vga.c b/hw/display/vga.c
index 20475ebbd31..90b89cf4044 100644
--- a/hw/display/vga.c
+++ b/hw/display/vga.c
@@ -26,7 +26,7 @@
 #include "qemu/units.h"
 #include "system/reset.h"
 #include "qapi/error.h"
-#include "exec/tswap.h"
+#include "qemu/target-info.h"
 #include "hw/display/vga.h"
 #include "hw/i386/x86.h"
 #include "hw/pci/pci.h"
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 82a285a31d1..0f4d28033d7 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -20,7 +20,7 @@
 #include "qemu/log.h"
 #include "qemu/main-loop.h"
 #include "qemu/module.h"
-#include "exec/tswap.h"
+#include "qemu/target-info.h"
 #include "qom/object_interfaces.h"
 #include "hw/core/cpu.h"
 #include "hw/virtio/virtio.h"
diff --git a/system/memory.c b/system/memory.c
index e8d9b15b28f..38da62f5052 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -22,6 +22,7 @@
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
 #include "qemu/qemu-print.h"
+#include "qemu/target-info.h"
 #include "qom/object.h"
 #include "trace.h"
 #include "system/ram_addr.h"
diff --git a/system/qtest.c b/system/qtest.c
index 301b03be2d3..fa42c9f9215 100644
--- a/system/qtest.c
+++ b/system/qtest.c
@@ -29,6 +29,7 @@
 #include "qemu/error-report.h"
 #include "qemu/module.h"
 #include "qemu/cutils.h"
+#include "qemu/target-info.h"
 #include "qom/object_interfaces.h"
 
 #define MAX_IRQ 256
diff --git a/target-info.c b/target-info.c
index a756c0714c4..3110ab32f75 100644
--- a/target-info.c
+++ b/target-info.c
@@ -47,3 +47,8 @@ EndianMode target_endian_mode(void)
 {
     return target_info()->endianness;
 }
+
+bool target_big_endian(void)
+{
+    return target_endian_mode() == ENDIAN_MODE_BIG;
+}
-- 
2.49.0


Re: [PATCH-for-10.1 v7 5/8] qemu: Convert target_words_bigendian() to TargetInfo API
Posted by Pierrick Bouvier 5 months, 1 week ago
On 7/8/25 10:19 AM, Philippe Mathieu-Daudé wrote:
> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   include/exec/tswap.h       | 13 +------------
>   include/qemu/target-info.h |  8 ++++++++
>   cpu-target.c               |  7 -------
>   hw/core/cpu-system.c       |  2 +-
>   hw/display/vga.c           |  2 +-
>   hw/virtio/virtio.c         |  2 +-
>   system/memory.c            |  1 +
>   system/qtest.c             |  1 +
>   target-info.c              |  5 +++++
>   9 files changed, 19 insertions(+), 22 deletions(-)

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


Re: [PATCH-for-10.1 v7 5/8] qemu: Convert target_words_bigendian() to TargetInfo API
Posted by Richard Henderson 5 months, 1 week ago
On 7/8/25 11:19, Philippe Mathieu-Daudé wrote:
> -/**
> - * target_big_endian:
> - * Returns true if the (default) endianness of the target is big endian,
> - * false otherwise. Common code should normally never need to know about the
> - * endianness of the target, so please do *not* use this function unless you
> - * know very well what you are doing!
> - */
...
> +/**
> + * target_big_endian:
> + *
> + * Returns: %true if the (default) endianness of the target is big endian,
> + *          %false otherwise.
> + */
> +bool target_big_endian(void);

Perhaps retain the warning about not using this unless necessary.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

Re: [PATCH-for-10.1 v7 5/8] qemu: Convert target_words_bigendian() to TargetInfo API
Posted by Philippe Mathieu-Daudé 5 months, 1 week ago
On 8/7/25 19:39, Richard Henderson wrote:
> On 7/8/25 11:19, Philippe Mathieu-Daudé wrote:
>> -/**
>> - * target_big_endian:
>> - * Returns true if the (default) endianness of the target is big endian,
>> - * false otherwise. Common code should normally never need to know 
>> about the
>> - * endianness of the target, so please do *not* use this function 
>> unless you
>> - * know very well what you are doing!
>> - */
> ...
>> +/**
>> + * target_big_endian:
>> + *
>> + * Returns: %true if the (default) endianness of the target is big 
>> endian,
>> + *          %false otherwise.
>> + */
>> +bool target_big_endian(void);
> 
> Perhaps retain the warning about not using this unless necessary.

This is what I did in a previous version, but Thomas (or Pierrick?)
said something about this method now being safe, so the comment
obsolete.

I told Pierrick this method doesn't make sense to me in a
heterogeneous context, he said to not make change with the
current behavior, when run on a vCPU we'll eventually infer
via TargetInfo on the vCPU TLS area, and otherwise (I/O
thread) this method shouldn't be called so we should abort.
Such change LGTM. I can start updating the documentation
mentioning "the (default) endianness of the current vCPU."
Currently on I/O thread this is the endianness of the binary.

> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> 
> 
> r~


Re: [PATCH-for-10.1 v7 5/8] qemu: Convert target_words_bigendian() to TargetInfo API
Posted by Philippe Mathieu-Daudé 5 months, 1 week ago
On 8/7/25 22:51, Philippe Mathieu-Daudé wrote:
> On 8/7/25 19:39, Richard Henderson wrote:
>> On 7/8/25 11:19, Philippe Mathieu-Daudé wrote:
>>> -/**
>>> - * target_big_endian:
>>> - * Returns true if the (default) endianness of the target is big 
>>> endian,
>>> - * false otherwise. Common code should normally never need to know 
>>> about the
>>> - * endianness of the target, so please do *not* use this function 
>>> unless you
>>> - * know very well what you are doing!
>>> - */
>> ...
>>> +/**
>>> + * target_big_endian:
>>> + *
>>> + * Returns: %true if the (default) endianness of the target is big 
>>> endian,
>>> + *          %false otherwise.
>>> + */
>>> +bool target_big_endian(void);
>>
>> Perhaps retain the warning about not using this unless necessary.
> 
> This is what I did in a previous version, but Thomas (or Pierrick?)
> said something about this method now being safe, so the comment
> obsolete.

Bah I'm mixing various conversations, what Pierrick said
is different:
https://lore.kernel.org/qemu-devel/1227db2b-cfa9-4877-b42c-edd2a9e98d25@linaro.org/

> I told Pierrick this method doesn't make sense to me in a
> heterogeneous context, he said to not make change with the
> current behavior, when run on a vCPU we'll eventually infer
> via TargetInfo on the vCPU TLS area, and otherwise (I/O
> thread) this method shouldn't be called so we should abort.
> Such change LGTM. I can start updating the documentation
> mentioning "the (default) endianness of the current vCPU."
> Currently on I/O thread this is the endianness of the binary.
> 
>> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>>
>>
>> r~
>