* [PATCH] linux-user/syscall: xtensa: fix target_msqid_ds and ipc_perm conversion
@ 2024-03-29 6:31 Max Filippov
2024-03-29 12:48 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 3+ messages in thread
From: Max Filippov @ 2024-03-29 6:31 UTC (permalink / raw)
To: qemu-devel; +Cc: Max Filippov, qemu-stable
- target_ipc_perm::mode and target_ipc_perm::__seq fields are 32-bit wide
on xtensa and thus need to use tswap32
- target_msqid_ds::msg_*time field pairs are reversed on big-endian
xtensa
Both issues result in incorrect conversion results on big-endian xtensa
targets, spotted by the libc-test http://nsz.repo.hu/git/?p=libc-test
Cc: qemu-stable@nongnu.org
Fixes: a3da8be5126b ("target/xtensa: linux-user: fix sysv IPC structures")
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
---
linux-user/syscall.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e384e1424890..cb334e90d6f0 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3758,12 +3758,13 @@ static inline abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip,
host_ip->gid = tswap32(target_ip->gid);
host_ip->cuid = tswap32(target_ip->cuid);
host_ip->cgid = tswap32(target_ip->cgid);
-#if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_PPC)
+#if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_PPC) || \
+ defined(TARGET_XTENSA)
host_ip->mode = tswap32(target_ip->mode);
#else
host_ip->mode = tswap16(target_ip->mode);
#endif
-#if defined(TARGET_PPC)
+#if defined(TARGET_PPC) || defined(TARGET_XTENSA)
host_ip->__seq = tswap32(target_ip->__seq);
#else
host_ip->__seq = tswap16(target_ip->__seq);
@@ -3786,12 +3787,13 @@ static inline abi_long host_to_target_ipc_perm(abi_ulong target_addr,
target_ip->gid = tswap32(host_ip->gid);
target_ip->cuid = tswap32(host_ip->cuid);
target_ip->cgid = tswap32(host_ip->cgid);
-#if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_PPC)
+#if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_PPC) || \
+ defined(TARGET_XTENSA)
target_ip->mode = tswap32(host_ip->mode);
#else
target_ip->mode = tswap16(host_ip->mode);
#endif
-#if defined(TARGET_PPC)
+#if defined(TARGET_PPC) || defined(TARGET_XTENSA)
target_ip->__seq = tswap32(host_ip->__seq);
#else
target_ip->__seq = tswap16(host_ip->__seq);
@@ -4111,6 +4113,14 @@ static inline abi_long do_semtimedop(int semid,
struct target_msqid_ds
{
struct target_ipc_perm msg_perm;
+#if defined(TARGET_XTENSA) && TARGET_BIG_ENDIAN
+ abi_ulong __unused1;
+ abi_ulong msg_stime;
+ abi_ulong __unused2;
+ abi_ulong msg_rtime;
+ abi_ulong __unused3;
+ abi_ulong msg_ctime;
+#else
abi_ulong msg_stime;
#if TARGET_ABI_BITS == 32
abi_ulong __unused1;
@@ -4122,6 +4132,7 @@ struct target_msqid_ds
abi_ulong msg_ctime;
#if TARGET_ABI_BITS == 32
abi_ulong __unused3;
+#endif
#endif
abi_ulong __msg_cbytes;
abi_ulong msg_qnum;
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] linux-user/syscall: xtensa: fix target_msqid_ds and ipc_perm conversion
2024-03-29 6:31 [PATCH] linux-user/syscall: xtensa: fix target_msqid_ds and ipc_perm conversion Max Filippov
@ 2024-03-29 12:48 ` Philippe Mathieu-Daudé
2024-03-29 21:42 ` Max Filippov
0 siblings, 1 reply; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-03-29 12:48 UTC (permalink / raw)
To: Max Filippov, qemu-devel; +Cc: qemu-stable
Hi Max,
On 29/3/24 07:31, Max Filippov wrote:
> - target_ipc_perm::mode and target_ipc_perm::__seq fields are 32-bit wide
> on xtensa and thus need to use tswap32
> - target_msqid_ds::msg_*time field pairs are reversed on big-endian
> xtensa
Please split in 2 distinct patches.
> Both issues result in incorrect conversion results on big-endian xtensa
> targets, spotted by the libc-test http://nsz.repo.hu/git/?p=libc-test
>
> Cc: qemu-stable@nongnu.org
> Fixes: a3da8be5126b ("target/xtensa: linux-user: fix sysv IPC structures")
> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
> ---
> linux-user/syscall.c | 19 +++++++++++++++----
> 1 file changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index e384e1424890..cb334e90d6f0 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -3758,12 +3758,13 @@ static inline abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip,
> host_ip->gid = tswap32(target_ip->gid);
> host_ip->cuid = tswap32(target_ip->cuid);
> host_ip->cgid = tswap32(target_ip->cgid);
> -#if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_PPC)
> +#if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_PPC) || \
> + defined(TARGET_XTENSA)
> host_ip->mode = tswap32(target_ip->mode);
> #else
> host_ip->mode = tswap16(target_ip->mode);
> #endif
> -#if defined(TARGET_PPC)
> +#if defined(TARGET_PPC) || defined(TARGET_XTENSA)
> host_ip->__seq = tswap32(target_ip->__seq);
> #else
> host_ip->__seq = tswap16(target_ip->__seq);
> @@ -3786,12 +3787,13 @@ static inline abi_long host_to_target_ipc_perm(abi_ulong target_addr,
> target_ip->gid = tswap32(host_ip->gid);
> target_ip->cuid = tswap32(host_ip->cuid);
> target_ip->cgid = tswap32(host_ip->cgid);
> -#if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_PPC)
> +#if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_PPC) || \
> + defined(TARGET_XTENSA)
> target_ip->mode = tswap32(host_ip->mode);
> #else
> target_ip->mode = tswap16(host_ip->mode);
> #endif
> -#if defined(TARGET_PPC)
> +#if defined(TARGET_PPC) || defined(TARGET_XTENSA)
> target_ip->__seq = tswap32(host_ip->__seq);
> #else
> target_ip->__seq = tswap16(host_ip->__seq);
> @@ -4111,6 +4113,14 @@ static inline abi_long do_semtimedop(int semid,
> struct target_msqid_ds
> {
> struct target_ipc_perm msg_perm;
> +#if defined(TARGET_XTENSA) && TARGET_BIG_ENDIAN
Why restrict to only Xtensa here?
> + abi_ulong __unused1;
> + abi_ulong msg_stime;
> + abi_ulong __unused2;
> + abi_ulong msg_rtime;
> + abi_ulong __unused3;
> + abi_ulong msg_ctime;
> +#else
> abi_ulong msg_stime;
> #if TARGET_ABI_BITS == 32
> abi_ulong __unused1;
> @@ -4122,6 +4132,7 @@ struct target_msqid_ds
> abi_ulong msg_ctime;
> #if TARGET_ABI_BITS == 32
> abi_ulong __unused3;
> +#endif
> #endif
> abi_ulong __msg_cbytes;
> abi_ulong msg_qnum;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] linux-user/syscall: xtensa: fix target_msqid_ds and ipc_perm conversion
2024-03-29 12:48 ` Philippe Mathieu-Daudé
@ 2024-03-29 21:42 ` Max Filippov
0 siblings, 0 replies; 3+ messages in thread
From: Max Filippov @ 2024-03-29 21:42 UTC (permalink / raw)
To: Philippe Mathieu-Daudé; +Cc: qemu-devel, qemu-stable
On Fri, Mar 29, 2024 at 5:48 AM Philippe Mathieu-Daudé
<philmd@linaro.org> wrote:
>
> Hi Max,
>
> On 29/3/24 07:31, Max Filippov wrote:
> > - target_ipc_perm::mode and target_ipc_perm::__seq fields are 32-bit wide
> > on xtensa and thus need to use tswap32
> > - target_msqid_ds::msg_*time field pairs are reversed on big-endian
> > xtensa
>
> Please split in 2 distinct patches.
Ok.
> > struct target_msqid_ds
> > {
> > struct target_ipc_perm msg_perm;
> > +#if defined(TARGET_XTENSA) && TARGET_BIG_ENDIAN
>
> Why restrict to only Xtensa here?
I have detected and tested it on xtensa.
I see other architectures (mips, parisc, ppc, sparc) that may need
that, but AFAICS it's not that it's applicable for all big endians.
> > + abi_ulong __unused1;
> > + abi_ulong msg_stime;
> > + abi_ulong __unused2;
> > + abi_ulong msg_rtime;
> > + abi_ulong __unused3;
> > + abi_ulong msg_ctime;
> > +#else
--
Thanks.
-- Max
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-29 21:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-29 6:31 [PATCH] linux-user/syscall: xtensa: fix target_msqid_ds and ipc_perm conversion Max Filippov
2024-03-29 12:48 ` Philippe Mathieu-Daudé
2024-03-29 21:42 ` Max Filippov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).