From patchwork Wed Sep 28 08:15:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 610084 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp141717pvb; Wed, 28 Sep 2022 02:35:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5rFjg12Foy91WV+cqzVZ1Rgo6rMMeVBzYkpuN5BfOFQnhYTy3+CIebzMM/CYxOQEADZ5HH X-Received: by 2002:a05:620a:240d:b0:6ce:7f55:1191 with SMTP id d13-20020a05620a240d00b006ce7f551191mr20319351qkn.644.1664357756527; Wed, 28 Sep 2022 02:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664357756; cv=none; d=google.com; s=arc-20160816; b=wwCykbvyUb3s5vG5aeGukOqciLoy1qZIHnlInqssozoXDTf6JL/eiQtSvLq4e0YHuu LLPi8D4TYF0gZT7sjkJBoJlyUvM70VdWKt5i9UbK7aQ+X1iosCxMmjIuaWTnovajykFl kZ4lewrSZtkfIAir+q/pgjV5FU/BHEXKYDoCe5wMLVAANEwweMbHXKzuI9SFX3YXLCCp n9rKG3fZWGVetgoe56sHgp5uucEcFxNdymG0I7h1C7SniSftYogZmWw4eYahf9a2ml0a hLZ9eRZg25htaSVL6SRh036yd5OAUXFu5PlIZ0ZlHWrw+/e6mrQtQqSGHbBdYGdxcIaW fukQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=6wnqkVmwXtbq0Y1JFwFpZSePdxl9eCRyQLBvrmXyKyU=; b=CidhEoldFcbagnyzEv1EAGT5pfaP8zSgUBrwYpil0Fd1v7pGEVXuI68KfBNa+daJdN effO8TaY3It50q5TD+svdBJVqsXm3j13yzxsE8RR0A3XyTN3J1gOwnqHUKKSGTDDltTw vWqXIrDHqSameV/0hoA/wn/80YFIKYVwp4q4HMlioaJfParp51ZBJhQZ7V4ZwmjwtYuJ FgNtTvdhNXbWTwU9/sgcO4HU1bhCJT3n7thmfmQCGBOvuRgukRVLvNUHDThItREwIM9w Zjv9w6KxodkJlzgy1AFoQVLSbgS8Qsc404EFgfJ9M0E/5r2dhLx+Hkz7JiJHwUYoxBw8 0hUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id gi9-20020a056214248900b00497021b7fd8si2677807qvb.182.2022.09.28.02.35.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Sep 2022 02:35:56 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:57966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odTTv-0004ku-Ri for patch@linaro.org; Wed, 28 Sep 2022 05:35:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34302) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odSEI-0008Ef-8a for qemu-devel@nongnu.org; Wed, 28 Sep 2022 04:15:48 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:48711) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odSEC-0008Eq-Fj for qemu-devel@nongnu.org; Wed, 28 Sep 2022 04:15:38 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MHnZQ-1oPl6e1TNu-00EspI; Wed, 28 Sep 2022 10:15:34 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Richard Henderson , Laurent Vivier Subject: [PULL 30/38] linux-user: Combine do_futex and do_futex_time64 Date: Wed, 28 Sep 2022 10:15:09 +0200 Message-Id: <20220928081517.734954-31-laurent@vivier.eu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220928081517.734954-1-laurent@vivier.eu> References: <20220928081517.734954-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:SamJiBJS15wz51R/KWLWvc/jxcfEH2F6VLID+yWqWPvWdsSzIEw HGfejNoJvTaq1ExzrUF4kMO24kb9lsa/IGYjAYSk6h4WTkRuUw7xoBx3uqrZOstwdXgAkFn VCy3FWkNNlXJK6XG5NQrwu2/8bZj7aDO9vAghMWFfXrMjrKZ1kiLeEiNeWXGySMYQPpW2Js NxxEXI7qQQXNGiYVfg16w== X-UI-Out-Filterresults: notjunk:1;V03:K0:WtBhKx43KF0=:8BsGNwnM35D+lT0Utjiz3C NzLxxK4SDGduF48NrDbi3Mo4IdBOqzHQerRAvPKSlPYyqcolwLEfNMDP0ZqPm2rPmGyi9W3bx n7bWETMZKkcv4EpHj1JiwdhZ9r18Et9iUPSHEez7ixEObtbFRcE6hN2bokle5zgHd4NCKduIV 7uQtQTmRSjqoJQRimxOtLrHaA73C9rJPS6hOlEAHApszvx5VKXscwEav/1wOyQFKJ0k1Ehwy+ fccxyelPV5ywtr1gUg7M4fIbkpjAzD/DF1PdiWevo5AzYYPfBVVkrkfJdwlOCDT1OrdgLTe11 LYe84iqlcaiyYKAOWjMmRfC37HLN+48ENz8bqZRew35iCaiIpeLtzRgaIR627ZDzkNaArrcG3 DVnm6db6gGGS6gjQeY4/V+1KvcyL5Owu5evAGCxZwp2mz9ilSJOA9B2dz1AAfzelw/eESju/e 9wpD+jISg8a+qLwZ/dlou6SaPH4oxUh4o05FIQTBMivUfX5I2QNCjuDAHWKD2kA01rfn0S4Oy CAN7RVltNu7QRxO6O0K5GcsQ6mYcgrdD4PTTWx5K1sTGIJmfkWLQFGRnYXl/MyqrODSbKYMqB TOvP4WUylgp19TK8LDvEbOZL7VOb0pRzQz76mY/tXADzcRNDFFZd6VA6ECxUdUivmR6r5b5T0 iH/g/W2eaIHO7dOTl9ybo0IWomxKfQUJMUn2lJ0HXkAnr2AKo4LgJM1AYr/yhqWQ6jymLA/l/ htR09ST7zeCbEGqmCU3n52MaGVF1IL75jWRd/6cP8P9fpa4S9eX3ypsngWk6kDfGHt/7PW+JV re8fLiK Received-SPF: none client-ip=212.227.17.13; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de 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, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Pass a boolean to select between time32 and time64. Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier Message-Id: <20220829021006.67305-2-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 67 ++++++++------------------------------------ 1 file changed, 11 insertions(+), 56 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e0e0f058121f..af3a605fc458 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7768,9 +7768,10 @@ static int do_safe_futex(int *uaddr, int op, int val, futexes locally would make futexes shared between multiple processes tricky. However they're probably useless because guest atomic operations won't work either. */ -#if defined(TARGET_NR_futex) -static int do_futex(CPUState *cpu, target_ulong uaddr, int op, int val, - target_ulong timeout, target_ulong uaddr2, int val3) +#if defined(TARGET_NR_futex) || defined(TARGET_NR_futex_time64) +static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr, + int op, int val, target_ulong timeout, + target_ulong uaddr2, int val3) { struct timespec ts, *pts; int base_op; @@ -7787,7 +7788,11 @@ static int do_futex(CPUState *cpu, target_ulong uaddr, int op, int val, case FUTEX_WAIT_BITSET: if (timeout) { pts = &ts; - target_to_host_timespec(pts, timeout); + if (time64 + ? target_to_host_timespec64(pts, timeout) + : target_to_host_timespec(pts, timeout)) { + return -TARGET_EFAULT; + } } else { pts = NULL; } @@ -7817,56 +7822,6 @@ static int do_futex(CPUState *cpu, target_ulong uaddr, int op, int val, } #endif -#if defined(TARGET_NR_futex_time64) -static int do_futex_time64(CPUState *cpu, target_ulong uaddr, int op, - int val, target_ulong timeout, - target_ulong uaddr2, int val3) -{ - struct timespec ts, *pts; - int base_op; - - /* ??? We assume FUTEX_* constants are the same on both host - and target. */ -#ifdef FUTEX_CMD_MASK - base_op = op & FUTEX_CMD_MASK; -#else - base_op = op; -#endif - switch (base_op) { - case FUTEX_WAIT: - case FUTEX_WAIT_BITSET: - if (timeout) { - pts = &ts; - if (target_to_host_timespec64(pts, timeout)) { - return -TARGET_EFAULT; - } - } else { - pts = NULL; - } - return do_safe_futex(g2h(cpu, uaddr), op, - tswap32(val), pts, NULL, val3); - case FUTEX_WAKE: - return do_safe_futex(g2h(cpu, uaddr), op, val, NULL, NULL, 0); - case FUTEX_FD: - return do_safe_futex(g2h(cpu, uaddr), op, val, NULL, NULL, 0); - case FUTEX_REQUEUE: - case FUTEX_CMP_REQUEUE: - case FUTEX_WAKE_OP: - /* For FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, and FUTEX_WAKE_OP, the - TIMEOUT parameter is interpreted as a uint32_t by the kernel. - But the prototype takes a `struct timespec *'; insert casts - to satisfy the compiler. We do not need to tswap TIMEOUT - since it's not compared to guest memory. */ - pts = (struct timespec *)(uintptr_t) timeout; - return do_safe_futex(g2h(cpu, uaddr), op, val, pts, g2h(cpu, uaddr2), - (base_op == FUTEX_CMP_REQUEUE - ? tswap32(val3) : val3)); - default: - return -TARGET_ENOSYS; - } -} -#endif - #if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE) static abi_long do_name_to_handle_at(abi_long dirfd, abi_long pathname, abi_long handle, abi_long mount_id, @@ -12372,11 +12327,11 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, #endif #ifdef TARGET_NR_futex case TARGET_NR_futex: - return do_futex(cpu, arg1, arg2, arg3, arg4, arg5, arg6); + return do_futex(cpu, false, arg1, arg2, arg3, arg4, arg5, arg6); #endif #ifdef TARGET_NR_futex_time64 case TARGET_NR_futex_time64: - return do_futex_time64(cpu, arg1, arg2, arg3, arg4, arg5, arg6); + return do_futex(cpu, true, arg1, arg2, arg3, arg4, arg5, arg6); #endif #ifdef CONFIG_INOTIFY #if defined(TARGET_NR_inotify_init)