From patchwork Wed Sep 28 20:27:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 610095 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp505091pvb; Wed, 28 Sep 2022 14:02:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Y+p53CYNhaN+m6Nps3hYqn8PCjCw0KdCJ5jhdnUHBEag+ddV29WP5RBau8EWtZtpjE/zL X-Received: by 2002:ac8:58d0:0:b0:35c:eb96:5f38 with SMTP id u16-20020ac858d0000000b0035ceb965f38mr29305077qta.392.1664398953520; Wed, 28 Sep 2022 14:02:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664398953; cv=none; d=google.com; s=arc-20160816; b=ItnMHhSHC1IcMoAzqsi5aPSt3DIcfVnKzLtXwbBaxpnXTgW3ck7mqzbRZkrbOTBMWG ridv6osFoLRczuoe8A6alEC4H5O7CuusQgEFVG8/oPL+BECiakGPZpU8DcyRaH4ewrMn E2bEJP1DA5PMd2wG2Le669KSKAOE97+cEHw63RJpWoZqB2/ACG6ZRo8I+rEuloPPpKKT lSmfQOocTqyyt/7/o9QfhuW2iEb9aqAurggtb8O+CAK8AycTMbV5bH6QhseCZbrIKMWG 6Ta3msFyndaDuyEooN4SGrbc8XIlpSjBDRu3DV0q6IpWzwtnoGIPe0JbKqaNZS1SwUVP 2HSA== 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=Xu5ZYA0q7fKqcNO3p+Orp2kbGugTYczykR7Oo/W0m9w=; b=jBF2v4cPE0mt1/2xEDHxiJa7Aq3VPVwz/GRTFxguB6+BaQqsFSmdn98XOmpWkFAqGZ GlAop+I83C64OFd1O8wF96kGuM8KGStS65rYdsTTO7TAekt0x6aQK9StDzyIS8zxGTAO /X67XsodWA5cSwU85E4B4BuXCP8qlKhxd34YTYogXZLToWY6vnlHaZjED1PfMctyga7k o8mymKAa7Oj47EqiQ3LIzja95Taejz//BbkIZNRZniAKRQlFpTH63Iy12EOIaxC063xc TuvRtsKQn100XeFEnyax8L/qB8u3C0Kvdp7Y8BGG0Hi22g0a6c9oGO/k7n+6zudmkpte 7ZGw== 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 a29-20020aed279d000000b00343288592dcsi184362qtd.455.2022.09.28.14.02.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Sep 2022 14:02:33 -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]:46138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odeCP-0000tZ-3n for patch@linaro.org; Wed, 28 Sep 2022 17:02:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37012) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oddf4-0000bS-Nt for qemu-devel@nongnu.org; Wed, 28 Sep 2022 16:28:06 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:45253) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oddf2-0006Xe-2G for qemu-devel@nongnu.org; Wed, 28 Sep 2022 16:28:06 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1M7JnA-1oaLL348L6-007oPe; Wed, 28 Sep 2022 22:28:02 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Richard Henderson , Laurent Vivier Subject: [PULL 31/37] linux-user: Sink call to do_safe_futex Date: Wed, 28 Sep 2022 22:27:31 +0200 Message-Id: <20220928202737.793171-32-laurent@vivier.eu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220928202737.793171-1-laurent@vivier.eu> References: <20220928202737.793171-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:3Dsd8htV0Ts3QTvlCwAirljX2/FKlMrweXRllB2x8razXLD97+P tKSyEzY6naVsL7/VsZ1ql8zjfm5WtW7TPIlNXAAeyGXSWNu8MQhpbEQnyWNX2sZYDazTjLQ WdD/nWrjUC15bn6vhauj3wyVV7z69ZomCf/2VnaLBVegOtpwxZRm7OZXPxL6Uh0e3mrvhZN VP1lDkley9Ihi2bUkgRSg== X-UI-Out-Filterresults: notjunk:1;V03:K0:FKcYcn75Hsg=:Fo1Oq4HggXlxH7Ip9m7M1R lcAooG2HB7jze0gAJLzE3M4yuiCIuPxrC4DA5I51mjmOjak5gFphE/LCzthwwyx81xaJhJJ0n iIc+/1RmOSU0f2t2p3M7urp+AByYGJiRD0wE1GCMDQaWrUrkKpHudO2abYlVy+aC2ReT5cRq1 JqayIhIrDmJsjKKNdkukQHSeLn01jOL8i31EnKFT9rUEQ7eNzAUvRnL3hN4SGrXk46n2z49SP hNUSM46WZcMIPKtWuHKhnU6AOlq5n6gNrEhj+3KoK/mGlTUEy0kItYywiCvRa2tTlRdZ0C+DI wV68My3hdhZfWYddG6e6O3shOJquCOu7s96hO0bN04HcayPNVp8JNzKZr2bYD0oY4dbbznXMy qRTiAg/PBIrB0xlLXGwah6xsdL4g7BJqEu9ce7o/GpF6WtY3Mn+d/7s8b+yxvRANPVdwObH7l BocAS1A2Fz6t1ooWAHtKmYu23+cL7O6qnCS5hkKx5tXJSBZ/xizmmpxoHYOvVwN8QWVhisXPW 4wpFud7BQIX6gBxgXORrAOzeV5sLh7jGeBq1ZzQRCOAvAl7vdrUOjybpdXgjmvDgBgEn9Ap2b v/LiDsj+LrFVJE5l9NjybJDrR9InB7rcUrf2fJ0i+k5QzMdxJNK2+jUssmhblO+cWH1zOXtCs zFVRNzknyMGmnTU8vahogi3xoajLNGoFAaWmGgB2xrN8Kwb5A2ikhkgxjUdxVrty0fZGhiefE Lmx/+OqhcFEmt5C1EzTAREqvX5SKt5TlYXhDCY8fiwEaUJMWoAsl7xQkep3xl6NPoQssKjRau lwF9Wxz Received-SPF: none client-ip=212.227.126.130; 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_DNSWL_NONE=-0.0001, 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 Leave only the argument adjustments within the shift, and sink the actual syscall to the end. Sink the timespec conversion as well, as there will be more users. Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier Message-Id: <20220829021006.67305-3-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 60 +++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index af3a605fc458..17e17f480456 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7773,11 +7773,11 @@ 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; + struct timespec ts, *pts = NULL; + void *haddr2 = NULL; int base_op; - /* ??? We assume FUTEX_* constants are the same on both host - and target. */ + /* We assume FUTEX_* constants are the same on both host and target. */ #ifdef FUTEX_CMD_MASK base_op = op & FUTEX_CMD_MASK; #else @@ -7786,39 +7786,41 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr, switch (base_op) { case FUTEX_WAIT: case FUTEX_WAIT_BITSET: - if (timeout) { - pts = &ts; - if (time64 - ? target_to_host_timespec64(pts, timeout) - : target_to_host_timespec(pts, timeout)) { - return -TARGET_EFAULT; - } - } else { - pts = NULL; - } - return do_safe_futex(g2h(cpu, uaddr), - op, tswap32(val), pts, NULL, val3); + val = tswap32(val); + break; case FUTEX_WAKE: - return do_safe_futex(g2h(cpu, uaddr), - op, val, NULL, NULL, 0); + timeout = 0; + break; case FUTEX_FD: - return do_safe_futex(g2h(cpu, uaddr), - op, val, NULL, NULL, 0); - case FUTEX_REQUEUE: + timeout = 0; + break; case FUTEX_CMP_REQUEUE: + val3 = tswap32(val3); + /* fall through */ + case FUTEX_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)); + /* + * For these, the 4th argument is not TIMEOUT, but VAL2. + * But the prototype of do_safe_futex takes a pointer, so + * insert casts to satisfy the compiler. We do not need + * to tswap VAL2 since it's not compared to guest memory. + */ + pts = (struct timespec *)(uintptr_t)timeout; + timeout = 0; + haddr2 = g2h(cpu, uaddr2); + break; default: return -TARGET_ENOSYS; } + if (timeout) { + pts = &ts; + if (time64 + ? target_to_host_timespec64(pts, timeout) + : target_to_host_timespec(pts, timeout)) { + return -TARGET_EFAULT; + } + } + return do_safe_futex(g2h(cpu, uaddr), op, val, pts, haddr2, val3); } #endif