[PATCH 3/3] tests/tcg/plugins/mem.c: fix endian swap in update_region_info

Pierrick Bouvier posted 3 patches 1 week, 2 days ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, "Alex Bennée" <alex.bennee@linaro.org>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>
There is a newer version of this series
[PATCH 3/3] tests/tcg/plugins/mem.c: fix endian swap in update_region_info
Posted by Pierrick Bouvier 1 week, 2 days ago
value returned by qemu_plugin_mem_get_value() is always in host-endian
order, so we need to convert TO target endianness and not FROM it.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 tests/tcg/plugins/mem.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tests/tcg/plugins/mem.c b/tests/tcg/plugins/mem.c
index 1ee257f855b..6b0732dc0fd 100644
--- a/tests/tcg/plugins/mem.c
+++ b/tests/tcg/plugins/mem.c
@@ -154,20 +154,20 @@ static void update_region_info(uint64_t region, uint64_t offset,
         val_size = 1;
         break;
     case QEMU_PLUGIN_MEM_VALUE_U16:
-        swapped_value.data.u16 = be ? GUINT16_FROM_BE(value.data.u16) :
-            GUINT16_FROM_LE(value.data.u16);
+        swapped_value.data.u16 = be ? GUINT16_TO_BE(value.data.u16) :
+            GUINT16_TO_LE(value.data.u16);
         val_ptr = &swapped_value.data.u16;
         val_size = 2;
         break;
     case QEMU_PLUGIN_MEM_VALUE_U32:
-        swapped_value.data.u32 = be ? GUINT32_FROM_BE(value.data.u32) :
-            GUINT32_FROM_LE(value.data.u32);
+        swapped_value.data.u32 = be ? GUINT32_TO_BE(value.data.u32) :
+            GUINT32_TO_LE(value.data.u32);
         val_ptr = &swapped_value.data.u32;
         val_size = 4;
         break;
     case QEMU_PLUGIN_MEM_VALUE_U64:
-        swapped_value.data.u64 = be ? GUINT64_FROM_BE(value.data.u64) :
-            GUINT64_FROM_LE(value.data.u64);
+        swapped_value.data.u64 = be ? GUINT64_TO_BE(value.data.u64) :
+            GUINT64_TO_LE(value.data.u64);
         val_ptr = &swapped_value.data.u64;
         val_size = 8;
         break;
-- 
2.47.3
Re: [PATCH 3/3] tests/tcg/plugins/mem.c: fix endian swap in update_region_info
Posted by Alex Bennée 1 week, 1 day ago
Pierrick Bouvier <pierrick.bouvier@linaro.org> writes:

> value returned by qemu_plugin_mem_get_value() is always in host-endian
> order, so we need to convert TO target endianness and not FROM it.
>
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

> ---
>  tests/tcg/plugins/mem.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/tests/tcg/plugins/mem.c b/tests/tcg/plugins/mem.c
> index 1ee257f855b..6b0732dc0fd 100644
> --- a/tests/tcg/plugins/mem.c
> +++ b/tests/tcg/plugins/mem.c
> @@ -154,20 +154,20 @@ static void update_region_info(uint64_t region, uint64_t offset,
>          val_size = 1;
>          break;
>      case QEMU_PLUGIN_MEM_VALUE_U16:
> -        swapped_value.data.u16 = be ? GUINT16_FROM_BE(value.data.u16) :
> -            GUINT16_FROM_LE(value.data.u16);
> +        swapped_value.data.u16 = be ? GUINT16_TO_BE(value.data.u16) :
> +            GUINT16_TO_LE(value.data.u16);
>          val_ptr = &swapped_value.data.u16;
>          val_size = 2;
>          break;
>      case QEMU_PLUGIN_MEM_VALUE_U32:
> -        swapped_value.data.u32 = be ? GUINT32_FROM_BE(value.data.u32) :
> -            GUINT32_FROM_LE(value.data.u32);
> +        swapped_value.data.u32 = be ? GUINT32_TO_BE(value.data.u32) :
> +            GUINT32_TO_LE(value.data.u32);
>          val_ptr = &swapped_value.data.u32;
>          val_size = 4;
>          break;
>      case QEMU_PLUGIN_MEM_VALUE_U64:
> -        swapped_value.data.u64 = be ? GUINT64_FROM_BE(value.data.u64) :
> -            GUINT64_FROM_LE(value.data.u64);
> +        swapped_value.data.u64 = be ? GUINT64_TO_BE(value.data.u64) :
> +            GUINT64_TO_LE(value.data.u64);
>          val_ptr = &swapped_value.data.u64;
>          val_size = 8;
>          break;

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro
Re: [PATCH 3/3] tests/tcg/plugins/mem.c: fix endian swap in update_region_info
Posted by Pierrick Bouvier 1 week, 1 day ago
On 3/25/26 8:20 AM, Alex Bennée wrote:
> Pierrick Bouvier <pierrick.bouvier@linaro.org> writes:
> 
>> value returned by qemu_plugin_mem_get_value() is always in host-endian
>> order, so we need to convert TO target endianness and not FROM it.
>>
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> 
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> 
>> ---
>>   tests/tcg/plugins/mem.c | 12 ++++++------
>>   1 file changed, 6 insertions(+), 6 deletions(-)
>>

As a complement, GUINT*_FROM_* and GUINT*_TO_* do the same thing (they 
both swap value). The FROM/TO name simply acts as a documentation when 
reading the code. That's why it was working before as expected, even 
though it was sending the wrong hint for the reader.

Regards,
Pierrick