From nobody Sun May 5 03:15:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1593176254; cv=none; d=zohomail.com; s=zohoarc; b=fr+C2Nhy5LTgg2zqCCwVvL7kQPCaw4PQ16AE0ooTa1tiDM10yt4Vby48BULzOSy3Y7UZcmX2nlwJryY6Dx2CSvTQ9IyasZaT/a7CyJUa4+Soswa1Dx7QVlvzpNjG4gAQBeLyru4mYpzlhxl0BJ5s7A94WYwaXH7COHF7Y5xI1sQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593176254; h=Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=YlvdoiyEczuIguOpu3Bdp7EHsqZK+cUDT4fPIJajXY4=; b=QLKsrBIMhGbYNmQOfTt5bC+kDJAzmgnvFtCTZXH5+35SS9DGzdnW+SZ9JcQzrqneVZNUW3b1lcQcaD2hPvkgMSEP3yQfHR0SUZg+yRTolsd9etWcXltQyP03nRFEvXIeXYtbAVWpCfSPA1JH8poO0PerU5RCJhQKDuf+OU9LG8s= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593176254183395.67503601137525; Fri, 26 Jun 2020 05:57:34 -0700 (PDT) Received: from localhost ([::1]:59196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jonvB-0003fC-0q for importer@patchew.org; Fri, 26 Jun 2020 08:57:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51200) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jonu7-0002P3-IW for qemu-devel@nongnu.org; Fri, 26 Jun 2020 08:56:27 -0400 Received: from mx1.tachyum.com ([66.160.133.170]:34941 helo=mail.tachyum.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jonu5-0001Ty-Tu for qemu-devel@nongnu.org; Fri, 26 Jun 2020 08:56:27 -0400 Received: by mail.tachyum.com (Postfix, from userid 1001) id CF935858; Fri, 26 Jun 2020 05:56:24 -0700 (PDT) Received: from tsk-dev-swd001.tachyum.sk (unknown [93.184.71.90]) by mail.tachyum.com (Postfix) with ESMTP id 5ABBB64D; Fri, 26 Jun 2020 05:56:16 -0700 (PDT) From: Matus Kysel To: mkysel@tachyum.com, riku.voipio@iki.fi, laurent@vivier.eu, qemu-devel@nongnu.org Subject: [PATCH v3 1/2] linux-user: refactor ipc syscall Date: Fri, 26 Jun 2020 14:46:11 +0200 Message-Id: <20200626124612.58593-2-mkysel@tachyum.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200626124612.58593-1-mkysel@tachyum.com> References: <20200626124612.58593-1-mkysel@tachyum.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=66.160.133.170; envelope-from=mkysel@tachyum.com; helo=mail.tachyum.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/26 07:27:33 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Refactoring ipc syscall for s390x and SPARC, so it matches glibc implementa= tion Signed-off-by: Matus Kysel Reviewed-by: Laurent Vivier --- linux-user/syscall.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 97de9fb5c9..990412733b 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -814,9 +814,14 @@ safe_syscall4(int, clock_nanosleep, const clockid_t, c= lock, 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) @@ -4053,8 +4058,13 @@ static inline abi_long do_msgsnd(int msqid, abi_long= msgp, #endif #ifdef __NR_ipc if (ret =3D=3D -TARGET_ENOSYS) { +#ifdef __s390x__ + ret =3D get_errno(safe_ipc(IPCOP_msgsnd, msqid, msgsz, msgflg, + host_mb)); +#else ret =3D get_errno(safe_ipc(IPCOP_msgsnd, msqid, msgsz, msgflg, host_mb, 0)); +#endif } #endif g_free(host_mb); @@ -4063,6 +4073,20 @@ static inline abi_long do_msgsnd(int msqid, abi_long= msgp, return ret; } =20 +#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) @@ -4091,7 +4115,7 @@ static inline abi_long do_msgrcv(int msqid, abi_long = msgp, #ifdef __NR_ipc if (ret =3D=3D -TARGET_ENOSYS) { ret =3D get_errno(safe_ipc(IPCOP_CALL(1, IPCOP_msgrcv), msqid, msg= sz, - msgflg, host_mb, msgtyp)); + msgflg, MSGRCV_ARGS(host_mb, msgtyp))); } #endif =20 --=20 2.17.1 From nobody Sun May 5 03:15:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1593176322; cv=none; d=zohomail.com; s=zohoarc; b=AX3ae+EzehR3YG0fM9fOCcKBySqf0OL96VIKsk03rg7SJN+NREsMol8s434gQlYbESkm/gY6OI9Hfuqva3WLhQ11zWxSLnW84xmirAQ40tIyJQMMzZIa4n3QlshIt5EUAaacp2XsVi6JVH+YTSJJ4jJEWV1AtXFDDWjlLO/Whg0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593176322; h=Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=x5fXisi0ZKzjsGqYBs2QncM4nAsBg9o2QdvjCTTjGd4=; b=jiSGiLoyx08djoYfgVv0b1ZVsKAnRpYMQaLo2P1QVVZg3+hPi2NstgG7K+BmDnkxFdBvNWfRnrnVxUwrvLmNhw/bNd7gIXTV4vRQTBDL+8XNwZyJy3sBeXy7N8qjgFh7wUGyHzxbhZvznvfgZriCNwZ4HOijQjVBPPdIQViyXz8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593176322627638.5323104256232; Fri, 26 Jun 2020 05:58:42 -0700 (PDT) Received: from localhost ([::1]:34544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jonwH-00059u-D0 for importer@patchew.org; Fri, 26 Jun 2020 08:58:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51202) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jonu7-0002Pp-Tx for qemu-devel@nongnu.org; Fri, 26 Jun 2020 08:56:27 -0400 Received: from mx1.tachyum.com ([66.160.133.170]:31153 helo=mail.tachyum.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jonu5-0001U0-VE for qemu-devel@nongnu.org; Fri, 26 Jun 2020 08:56:27 -0400 Received: by mail.tachyum.com (Postfix, from userid 1001) id D1A15859; Fri, 26 Jun 2020 05:56:24 -0700 (PDT) Received: from tsk-dev-swd001.tachyum.sk (unknown [93.184.71.90]) by mail.tachyum.com (Postfix) with ESMTP id 2BFA5857; Fri, 26 Jun 2020 05:56:23 -0700 (PDT) From: Matus Kysel To: mkysel@tachyum.com, riku.voipio@iki.fi, laurent@vivier.eu, qemu-devel@nongnu.org Subject: [PATCH v3 2/2] linux-user: support of semtimedop syscall Date: Fri, 26 Jun 2020 14:46:12 +0200 Message-Id: <20200626124612.58593-3-mkysel@tachyum.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200626124612.58593-1-mkysel@tachyum.com> References: <20200626124612.58593-1-mkysel@tachyum.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=66.160.133.170; envelope-from=mkysel@tachyum.com; helo=mail.tachyum.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/26 07:27:33 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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/-/comm= it/765cdd0bffd77960ae852104fc4ea5edcdb8aed3 ). Signed-off-by: Matus Kysel Reviewed-by: Laurent Vivier --- linux-user/syscall.c | 58 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 990412733b..538a7e673c 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1232,7 +1232,8 @@ static inline abi_long copy_to_user_timeval64(abi_ulo= ng 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) { @@ -3880,25 +3881,53 @@ static inline abi_long target_to_host_sembuf(struct= sembuf *host_sembuf, return 0; } =20 -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 =3D NULL; abi_long ret; =20 + if (timeout) { + pts =3D &ts; + if (target_to_host_timespec(pts, timeout)) { + return -TARGET_EFAULT; + } + } + if (target_to_host_sembuf(sops, ptr, nsops)) return -TARGET_EFAULT; =20 ret =3D -TARGET_ENOSYS; #ifdef __NR_semtimedop - ret =3D get_errno(safe_semtimedop(semid, sops, nsops, NULL)); + ret =3D get_errno(safe_semtimedop(semid, sops, nsops, pts)); #endif #ifdef __NR_ipc if (ret =3D=3D -TARGET_ENOSYS) { - ret =3D get_errno(safe_ipc(IPCOP_semtimedop, semid, nsops, 0, sops= , 0)); + ret =3D get_errno(safe_ipc(IPCOP_semtimedop, semid, + SEMTIMEDOP_IPC_ARGS(nsops, sops, (long)pt= s))); } #endif return ret; } +#endif =20 struct target_msqid_ds { @@ -4393,7 +4422,20 @@ static abi_long do_ipc(CPUArchState *cpu_env, =20 switch (call) { case IPCOP_semop: - ret =3D do_semop(first, ptr, second); + ret =3D 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 =3D do_semtimedop(first, ptr, second, third); +#else + ret =3D do_semtimedop(first, ptr, second, fifth); +#endif break; =20 case IPCOP_semget: @@ -9644,7 +9686,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: --=20 2.17.1