From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: Laurent Vivier <laurent@vivier.eu>, Matus Kysel <mkysel@tachyum.com>
Subject: [PULL 2/7] linux-user: refactor ipc syscall and support of semtimedop syscall
Date: Tue, 14 Jul 2020 09:32:54 +0200 [thread overview]
Message-ID: <20200714073259.1464675-3-laurent@vivier.eu> (raw)
In-Reply-To: <20200714073259.1464675-1-laurent@vivier.eu>
From: Matus Kysel <mkysel@tachyum.com>
Refactoring ipc syscall for s390x and SPARC, so it matches glibc implementation
We should add support of semtimedop syscall as new version of glibc
2.31 uses semop based on semtimedop
(commit: https://gitlab.com/freedesktop-sdk/mirrors/sourceware/glibc/-/commit/765cdd0bffd77960ae852104fc4ea5edcdb8aed3 ).
Signed-off-by: Matus Kysel <mkysel@tachyum.com>
Message-Id: <20200626124612.58593-2-mkysel@tachyum.com>
Message-Id: <20200626124612.58593-3-mkysel@tachyum.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
[lv: merged PATCH 1 & 2 to avoid build break on PATCH 1]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/syscall.c | 84 ++++++++++++++++++++++++++++++++++++++++----
1 file changed, 77 insertions(+), 7 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e9f53340cd65..1211e759c26c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -817,9 +817,14 @@ safe_syscall4(int, clock_nanosleep, const clockid_t, clock, int, flags,
const struct timespec *, req, struct timespec *, rem)
#endif
#ifdef __NR_ipc
+#ifdef __s390x__
+safe_syscall5(int, ipc, int, call, long, first, long, second, long, third,
+ void *, ptr)
+#else
safe_syscall6(int, ipc, int, call, long, first, long, second, long, third,
void *, ptr, long, fifth)
#endif
+#endif
#ifdef __NR_msgsnd
safe_syscall4(int, msgsnd, int, msgid, const void *, msgp, size_t, sz,
int, flags)
@@ -1230,7 +1235,8 @@ static inline abi_long copy_to_user_timeval64(abi_ulong target_tv_addr,
defined(TARGET_NR_pselect6) || defined(TARGET_NR_pselect6) || \
defined(TARGET_NR_nanosleep) || defined(TARGET_NR_clock_settime) || \
defined(TARGET_NR_utimensat) || defined(TARGET_NR_mq_timedsend) || \
- defined(TARGET_NR_mq_timedreceive)
+ defined(TARGET_NR_mq_timedreceive) || defined(TARGET_NR_ipc) || \
+ defined(TARGET_NR_semop) || defined(TARGET_NR_semtimedop)
static inline abi_long target_to_host_timespec(struct timespec *host_ts,
abi_ulong target_addr)
{
@@ -3878,25 +3884,53 @@ static inline abi_long target_to_host_sembuf(struct sembuf *host_sembuf,
return 0;
}
-static inline abi_long do_semop(int semid, abi_long ptr, unsigned nsops)
+#if defined(TARGET_NR_ipc) || defined(TARGET_NR_semop) || \
+ defined(TARGET_NR_semtimedop)
+
+/*
+ * This macro is required to handle the s390 variants, which passes the
+ * arguments in a different order than default.
+ */
+#ifdef __s390x__
+#define SEMTIMEDOP_IPC_ARGS(__nsops, __sops, __timeout) \
+ (__nsops), (__timeout), (__sops)
+#else
+#define SEMTIMEDOP_IPC_ARGS(__nsops, __sops, __timeout) \
+ (__nsops), 0, (__sops), (__timeout)
+#endif
+
+static inline abi_long do_semtimedop(int semid,
+ abi_long ptr,
+ unsigned nsops,
+ abi_long timeout)
{
struct sembuf sops[nsops];
+ struct timespec ts, *pts = NULL;
abi_long ret;
+ if (timeout) {
+ pts = &ts;
+ if (target_to_host_timespec(pts, timeout)) {
+ return -TARGET_EFAULT;
+ }
+ }
+
if (target_to_host_sembuf(sops, ptr, nsops))
return -TARGET_EFAULT;
ret = -TARGET_ENOSYS;
#ifdef __NR_semtimedop
- ret = get_errno(safe_semtimedop(semid, sops, nsops, NULL));
+ ret = get_errno(safe_semtimedop(semid, sops, nsops, pts));
#endif
#ifdef __NR_ipc
if (ret == -TARGET_ENOSYS) {
- ret = get_errno(safe_ipc(IPCOP_semtimedop, semid, nsops, 0, sops, 0));
+ ret = get_errno(safe_ipc(IPCOP_semtimedop, semid,
+ SEMTIMEDOP_IPC_ARGS(nsops, sops, (long)pts)));
}
#endif
return ret;
}
+#endif
struct target_msqid_ds
{
@@ -4056,8 +4090,13 @@ static inline abi_long do_msgsnd(int msqid, abi_long msgp,
#endif
#ifdef __NR_ipc
if (ret == -TARGET_ENOSYS) {
+#ifdef __s390x__
+ ret = get_errno(safe_ipc(IPCOP_msgsnd, msqid, msgsz, msgflg,
+ host_mb));
+#else
ret = get_errno(safe_ipc(IPCOP_msgsnd, msqid, msgsz, msgflg,
host_mb, 0));
+#endif
}
#endif
g_free(host_mb);
@@ -4066,6 +4105,20 @@ static inline abi_long do_msgsnd(int msqid, abi_long msgp,
return ret;
}
+#ifdef __NR_ipc
+#if defined(__sparc__)
+/* SPARC for msgrcv it does not use the kludge on final 2 arguments. */
+#define MSGRCV_ARGS(__msgp, __msgtyp) __msgp, __msgtyp
+#elif defined(__s390x__)
+/* The s390 sys_ipc variant has only five parameters. */
+#define MSGRCV_ARGS(__msgp, __msgtyp) \
+ ((long int[]){(long int)__msgp, __msgtyp})
+#else
+#define MSGRCV_ARGS(__msgp, __msgtyp) \
+ ((long int[]){(long int)__msgp, __msgtyp}), 0
+#endif
+#endif
+
static inline abi_long do_msgrcv(int msqid, abi_long msgp,
ssize_t msgsz, abi_long msgtyp,
int msgflg)
@@ -4094,7 +4147,7 @@ static inline abi_long do_msgrcv(int msqid, abi_long msgp,
#ifdef __NR_ipc
if (ret == -TARGET_ENOSYS) {
ret = get_errno(safe_ipc(IPCOP_CALL(1, IPCOP_msgrcv), msqid, msgsz,
- msgflg, host_mb, msgtyp));
+ msgflg, MSGRCV_ARGS(host_mb, msgtyp)));
}
#endif
@@ -4372,7 +4425,20 @@ static abi_long do_ipc(CPUArchState *cpu_env,
switch (call) {
case IPCOP_semop:
- ret = do_semop(first, ptr, second);
+ ret = do_semtimedop(first, ptr, second, 0);
+ break;
+ case IPCOP_semtimedop:
+ /*
+ * The s390 sys_ipc variant has only five parameters instead of six
+ * (as for default variant) and the only difference is the handling of
+ * SEMTIMEDOP where on s390 the third parameter is used as a pointer
+ * to a struct timespec where the generic variant uses fifth parameter.
+ */
+#if defined(TARGET_S390X)
+ ret = do_semtimedop(first, ptr, second, third);
+#else
+ ret = do_semtimedop(first, ptr, second, fifth);
+#endif
break;
case IPCOP_semget:
@@ -9684,7 +9750,11 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
#endif
#ifdef TARGET_NR_semop
case TARGET_NR_semop:
- return do_semop(arg1, arg2, arg3);
+ return do_semtimedop(arg1, arg2, arg3, 0);
+#endif
+#ifdef TARGET_NR_semtimedop
+ case TARGET_NR_semtimedop:
+ return do_semtimedop(arg1, arg2, arg3, arg4);
#endif
#ifdef TARGET_NR_semctl
case TARGET_NR_semctl:
--
2.26.2
next prev parent reply other threads:[~2020-07-14 7:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-14 7:32 [PULL 0/7] Linux user for 5.1 patches Laurent Vivier
2020-07-14 7:32 ` [PULL 1/7] linux-user: Use EPROTONOSUPPORT for unimplemented netlink protocols Laurent Vivier
2020-07-14 7:32 ` Laurent Vivier [this message]
2020-07-14 7:32 ` [PULL 3/7] linux-user: Fix Coverity CID 1430271 / CID 1430272 Laurent Vivier
2020-07-14 7:32 ` [PULL 4/7] linux-user: add new netlink types Laurent Vivier
2020-07-14 7:32 ` [PULL 5/7] linux-user: add netlink RTM_SETLINK command Laurent Vivier
2020-07-14 7:32 ` [PULL 6/7] linux-user: fix the errno value in print_syscall_err() Laurent Vivier
2020-07-14 7:32 ` [PULL 7/7] linux-user: fix print_syscall_err() when syscall returned value is negative Laurent Vivier
2020-07-14 7:59 ` [PULL 0/7] Linux user for 5.1 patches no-reply
2020-07-14 20:21 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200714073259.1464675-3-laurent@vivier.eu \
--to=laurent@vivier.eu \
--cc=mkysel@tachyum.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).