From patchwork Mon Aug 29 02:10:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 600853 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp1683288mae; Sun, 28 Aug 2022 19:11:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR4nTf2iH37AylOtyM3LggxgwkvwJDewhDA9vW0EqjCgEBDoabEbjln7MlUdrLqPky1MjTPy X-Received: by 2002:ac8:7f0f:0:b0:344:2fd8:8a66 with SMTP id f15-20020ac87f0f000000b003442fd88a66mr8623186qtk.98.1661739092326; Sun, 28 Aug 2022 19:11:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661739092; cv=none; d=google.com; s=arc-20160816; b=RI62t7K6urJW/qA7ORQxzATm6/f7LndjqbCDgeFa1OjouuCG4VapqIv0cSlEAVFEMj YhX4G7Gr20wAyj9MhjStdyF909wDEldf33580zr9rpwT8kKk1dtWYQoZ+7QXDShGZ6/g 8xZ1eWS65PfRSVWYZI6OvZ4FjZ2LfmjivjjHsGMmkvUikBk8F2ihwH6V3tk3uM3S1GGw 1yr8q34OXbQ2suFRELRM8iOTjAYTiPgQYTqEZqrX7E/RrsHVqDaDAp4t8CK2hyx7vMVr Xvas2OgwGL2nyvhE2W0wJpplz3k5pmbtuDXQbjGqXc4ubNMA2pZk/Ywr1SGst1ytsooB I8Uw== 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:dkim-signature; bh=MtNh2w+4V2y5mwzf678UGVcQqp1eS0dpxGcLnKcxRPA=; b=Kf09gP2DAZzMTVOc1fBTW62Xw90aYQCFHo330kgouzSgp/lHEJqCWtDW/SvrRXf34M FawtKFlL3TjDSQi01zTcpBJWl7GE8lh8sdYZSqB0rq8Jzk+QM9AS2GkpcX2syeKef41T LBGIe+hOLfCfp315eE7By4x0QEjAxTPpvNbCUtYS0fvQAHLLyNWHmEH5QoWEWScNCxMb YoBq4vNCQOMF2DQgzhTth4p/DRjxnpcHnCvRQLolNrEJuSl1qDw6hWR02tdNRwPXLNE6 7lU/zVgkDbMUbwmCeqRlWd4wf26/ehIzAPJ/rJsbRX/R5ycg0JfpIdWmWYtUXrlxyDk3 nglA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ykxb3D+j; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id kk8-20020a056214508800b004744c9be1aasi3057871qvb.156.2022.08.28.19.11.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 28 Aug 2022 19:11:32 -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; dkim=pass header.i=@linaro.org header.s=google header.b=ykxb3D+j; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45720 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oSUFP-0003T3-UE for patch@linaro.org; Sun, 28 Aug 2022 22:11:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSUEA-0003Rh-F8 for qemu-devel@nongnu.org; Sun, 28 Aug 2022 22:10:14 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:34653) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oSUE8-0001bC-MV for qemu-devel@nongnu.org; Sun, 28 Aug 2022 22:10:14 -0400 Received: by mail-pl1-x629.google.com with SMTP id f24so3857462plr.1 for ; Sun, 28 Aug 2022 19:10:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=MtNh2w+4V2y5mwzf678UGVcQqp1eS0dpxGcLnKcxRPA=; b=ykxb3D+jBicZuCoKrxF2tf0nUUnJpeuYoCdvWAQpGUaIMA8p1FGZRNVlb85I6jEct5 1zPi3NHjRJvn+wkIuZ9Zz0msqzvSwVRIS3Cn1yk+bMCFSILCLptBzIH7Bk2/zjl2bxFX MEIbbiZyVYzvD6Ugzx+8Wiuj8GuaMlJyDFWew4CI2FrGPogtPr6JwcMF1ZEgvrpFHsS8 CHnlQ00mS8CZ9EgIbVi9RgsWBe40HdEKHR0zePW+UJ8KGa3484f1rS+wmJG9/vddev6V WIEPi+HLRs4H6SSFcKxqCGJUYK5djIv5srYGyCsOgVqIs2MXu4kmDhsLht6b4425tTJ2 fEkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=MtNh2w+4V2y5mwzf678UGVcQqp1eS0dpxGcLnKcxRPA=; b=CrL1zWnDuZV1rm4JFSb8E0QnL7TYkBrlHCihFI9NIKdcR5N9SGu7vnYAJxU/EEKvng 0IGJYTQvY01gxkkyeyf55lWWG9ao3BXiZOxYtGU+Y1Eyw2COLf1WFcUpWzf2Gai4DznI zOTXlK0f0yESFELBMVPFNB9UHGDEcxy+7E1cHEO3TdLEY2gM7bRqhU5fzTxVluaoXJwc DJlthei06x36bq5kamXe8clRpn9RO2F5hcGc0sEUX4EeAQTDAnRrB2h2nnUC/PfSJHQ7 Z/m7d1rOwJbeIs8vq9aA8B+23PmU2zlkcprpcchRKbYIwmvjFXtQ9O7+bSdI0RZiWCgX Nolw== X-Gm-Message-State: ACgBeo0oy9RS3iacjKJKWkBeSmdLQz0OX/jwSmG3XNTwsMMrBMRUFgC5 c7FguzEi1UL5DNI7+6e3itcbZ/HVoIHPNQ== X-Received: by 2002:a17:90b:1c8e:b0:1f7:524f:bfcc with SMTP id oo14-20020a17090b1c8e00b001f7524fbfccmr16186305pjb.132.1661739011064; Sun, 28 Aug 2022 19:10:11 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:2fa6:2ab5:a96e:2a35]) by smtp.gmail.com with ESMTPSA id ik30-20020a170902ab1e00b0016bdc98730bsm6035139plb.151.2022.08.28.19.10.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Aug 2022 19:10:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu Subject: [PATCH 2/8] linux-user: Sink call to do_safe_futex Date: Sun, 28 Aug 2022 19:10:00 -0700 Message-Id: <20220829021006.67305-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220829021006.67305-1-richard.henderson@linaro.org> References: <20220829021006.67305-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" 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 --- 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 a7e66d8d28..8fbd5a9556 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7758,11 +7758,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 @@ -7771,39 +7771,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