From patchwork Thu Mar 24 08:20:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 553897 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1248:0:0:0:0 with SMTP id z8csp4184575mag; Thu, 24 Mar 2022 01:21:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbYi39VLneTYuLLQfPyOx4+hzk5mTc/HrgmZXPPwG+zh+XeUbtlGTi7cCg2t3VYzU7aQX3 X-Received: by 2002:a05:6214:d0a:b0:441:2e06:8822 with SMTP id 10-20020a0562140d0a00b004412e068822mr3367705qvh.123.1648110118828; Thu, 24 Mar 2022 01:21:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648110118; cv=none; d=google.com; s=arc-20160816; b=nra7hdrqnoWWgFlVFPr6NUYbsXflPkr81yP4kDTKFEzH0NDOP1jyMfP0R9qcxIXfea +0O38NmWRRjdg4iNhcCaymzQ5K+myjtkLhG/uGRkZrldwd+cFdpyjLnUqyDTLhvcvO5l xcSPjX322YUIlUE0ie6iuIAgYnRk7Ark/sN8QdG9lc6agv0mzHUbRwMmOCjkT04lM1wg x/g9m5wqvFnMn6Cr0YJ81iK68sVPmfavrXI+wBtLTm3U2haVQtLSwnA3kdQdSWT1XWo/ UA2r4BP1q3l5oPZa69WOnXbSOvlQQSaFMrko8TCTiJKShDlxoCKcGJSfG29mdkMvcxca 0lSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from; bh=FgrGQjODeI1ZB/L9qbSOoXvaHTOyQoJ8AzvJOQm7FTg=; b=CCCzd0f7HaXQHK2qz4/PUMjLNwwG+VNUKC2yi2N/j/AnxuWWysAX9z3g+Jnl0nqQyg BkZTsaMFmq9wlxuDCJSIx8ibbd2vns9zyufQ/Nx3s77s0Yu6hxeLsVFMrFxg/Gsbjs36 XWFVYywJQ/zwtDKGSXve1Z2qJy5oLnQUXl4GXO4IYgW7KCjkWbJhMjMqJoWCI3IhxTms fOMZgwDaFlWAb0DAQNznjaKfr4Zgv1cPo/lUQUANOAJShnYeyzX6sb8744wG/8t1DSAX EKcpxXtOmYWucyR2rxjyUcHqzMPhK3KoZVTkT10j9u6q6x9uSNNtqR3arAmkE+ys5R59 BO+Q== 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 bp9-20020a05620a458900b0067ec954803bsi2732570qkb.716.2022.03.24.01.21.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Mar 2022 01:21:58 -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]:56906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXIjG-0005xn-Cb for patch@linaro.org; Thu, 24 Mar 2022 04:21:58 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52192) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIhm-0005wJ-4A for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:26 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:37997) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIhk-0003OF-Ao for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:25 -0400 Received: from quad ([82.142.12.150]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mxlmw-1oHAUs2r8g-00zHFM; Thu, 24 Mar 2022 09:20:20 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 02/10] linux-user/alpha: Fix sigsuspend for big-endian hosts Date: Thu, 24 Mar 2022 09:20:08 +0100 Message-Id: <20220324082016.3463521-3-laurent@vivier.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220324082016.3463521-1-laurent@vivier.eu> References: <20220324082016.3463521-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:43bgUBuOuPLymVy2drw/4Xgq5LQTluwPpkoFEOmKPZ2duv5PnCW ZpWiF3dZW8gLgJTbVsHNNtYh8Naq93PJBY73MxKhwVI41r3fb6rWYNU+ok1rCE2CkGD8Fj+ TozOzgVhC63z8EA6iNQT6RpT3+lsmPsI3vP4Brup6pxdJBEj0qf8Y+lVtMt3vcwZLfaVviT CE+a5hG+0nyJLxAmkvcgg== X-UI-Out-Filterresults: notjunk:1;V03:K0:h7SI9Mo7S84=:P6PGxjkOyd+M02QKJv7UCP etm+Kj0tZ074dvtbpTeo0WKtxdZvkw0P1gVuTglaTnoD2+i1kcNWTq2OZub/nNG2DpFWG/C2c GeTsHIrmYeWN9Fz0jlb2cfLJfQYD/dQwx2dgSsy/yZMZL6VlLdjAYn9H5vDttiKGqq8gYsxhx smQxIm+uXgBT/VS4nW6o+Xj8GZZaYYkoDB1PcxAS0C46aO2ByXjARnjd34BbTA18TsP2aQ7e2 S7lWEFi6Qdol/YbT2AcdCAi0jBjUIewU7tJDYS0+F+EHYPU2Ro/x/wh2gjLszsuTUn9e/JqFW Z5Ibr5lO/vUPjdAtwmDQTaHiwUI6/vfBhuqjZafHJ3Mz7ULNXckGIP4b/s2ovwh9snbzHjvAL ahwy6cQARp81HRA0jcz4LRMaFeZ/TOL8HmsI+TRfJ0qTjECO9wR/gu8/siEzMv3YZyBZWEjEs 2ERDoSE4yglRGaf/4yWOuLFVIT7to12aXtUIvrCiSNrZuTMZDCwOHTMMsEWt6bFybv/EjkWGF LhavNZVUEhf1WJ6Is4jhZQMyDYA4rPXXX58xe1Sqe8GY0Dkl/Xeym8PR3pvsffXOxgGuR6gNS Wupd49ffLxJAcGdrV2BSrsZ92I85j1MFOHYijUxz1/qFFOZSAnZ4pDNW6fqvzv4kPL0ck8+3+ A3xSAiPI+KEzE+Lo5GoFMjUyav9gOMVUJUEyxdINMibJaeRhxKtdoVXgvfVORx4Le+bE= Received-SPF: none client-ip=212.227.126.135; 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=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: , Cc: Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson On alpha, the sigset argument for sigsuspend is in a register. When we drop that into memory that happens in host-endianness, but target_to_host_old_sigset will treat it as target-endianness. Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier Message-Id: <20220315084308.433109-2-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 75ed71eb461d..77cd88b53785 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9559,7 +9559,8 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, { TaskState *ts = cpu->opaque; #if defined(TARGET_ALPHA) - abi_ulong mask = arg1; + /* target_to_host_old_sigset will bswap back */ + abi_ulong mask = tswapal(arg1); target_to_host_old_sigset(&ts->sigsuspend_mask, &mask); #else if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1))) From patchwork Thu Mar 24 08:20: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: 553896 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1248:0:0:0:0 with SMTP id z8csp4184537mag; Thu, 24 Mar 2022 01:21:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKi8C6VPghux9OSWrEGxBnriD5ZOrJg4GhUplrR7dS+M/Ks/diTeeGoMtjecJzScu2Zpzd X-Received: by 2002:a05:620a:17a9:b0:67d:9929:dd8d with SMTP id ay41-20020a05620a17a900b0067d9929dd8dmr2552872qkb.474.1648110112428; Thu, 24 Mar 2022 01:21:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648110112; cv=none; d=google.com; s=arc-20160816; b=RM6AyPecZYrLa8jMGB5szfRmKZIFyUwgCfEucsy5OXCU4YlKtz4J/jLRVyAh/ACvRE VRobMIPJw/yqSJFa/OmOhSYs6d1DWETX/v/Qh7JFSbDGQpn/DIznmsOuqYrx+3B6ekUI UFftFeR55YrrF2U/VHIlsuQN/it2Fh6VbqaeTwjWGfIkwFxeSreyGvtzH8fgQx3lJTMo 2/2wOJOrRtLdRbWsmQdtlI+SEOONVYlmtZcIQ8wBDnR8ga52ELBkqGrakdfiX1i5R+TU Rc8mo0g8Ptar3nCrBk3yew1671wIBEMXkrkRRGd2JncwwL7psgNqfYU08J0e8Oj9ds2e jb2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from; bh=27bO+TCKU3hRCiFvbYJRKYjscRb8D/swNaDbapHFnYA=; b=h4dRX6ddpDvSP0roy11+CWYVCRg2p9NtM3yyq0wp0VDSoSKyXG+cqBlC8EcVn0eD56 ruTryrQ5BATAFtsvXg9UgZF7ctJaCR06oEZKhkd9Ki+zIQVMz7864f0DHlnTje6g5L5i uphMA6bH0T+jEPMnb1qkgCxHjia8HQYp/HW7j3TMM6UOMlFlQFUkoKxylOe/5kjzc6vU PQO033aD2/yuAUDp9EhaWGwvkI70VKF1/QHV/yw69INOR5X9sA7vOPgQ/hn5b1dZTPwh MpKm5/iP8fHp7rhXxFarmjZ4xEUgpdx5TpkTcnZrgNnTutl7Lrq4tAdnRH5NH2DKo6wW yc5A== 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 k6-20020a05622a03c600b002e1fbf3bffbsi5765642qtx.492.2022.03.24.01.21.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Mar 2022 01:21:52 -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]:56920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXIjA-0005yf-0H for patch@linaro.org; Thu, 24 Mar 2022 04:21:52 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIhn-0005ws-00 for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:27 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:50943) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIhk-0003OW-Ao for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:26 -0400 Received: from quad ([82.142.12.150]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Ml6Zo-1nuUun0f8O-00lTl8; Thu, 24 Mar 2022 09:20:21 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 03/10] linux-user: Split out helpers for sigsuspend Date: Thu, 24 Mar 2022 09:20:09 +0100 Message-Id: <20220324082016.3463521-4-laurent@vivier.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220324082016.3463521-1-laurent@vivier.eu> References: <20220324082016.3463521-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:h/hiLCYON9mf8iCUsZb+jRyt3rv6XTzgK0T3aX4p84MSt87Vob8 oRHX5kpanZA0ZDmU9NSDBxzbHNbPLffD684tuYuh5037wq5D41+kUDB0DVYe3e0DKAgBFde jPDUtgC86834AsAjjYIKYKoW6CdBMIlzR3kVl0DHfxTsS/QayZSWcoJF2eG7N6lPFT58C9t BhG6n3D45Sj7Auh1RsF6w== X-UI-Out-Filterresults: notjunk:1;V03:K0:lAP70PINeZE=:EyxbdLcmu0vMgirTlViHdN H6u6EoCiG/VvqGBsCFwuMCPG8i33eUzpnOBjmSzCeEXlmKE5O1xn/zKYj9MJbk5XwmBamCeJA UF06r2EoYZPTdmkrFWIw6BruW5/CqfCJSXP1W11W33bBlotzuArjREMmhn3mPkXmc1oArsJJm QKJnxomoNVPn2aeTCKargey0JN9RaDd0zIEbghpnII6mgYAmbBFarcUw5rGHjAx3vEjYM1her KlOV1UmvEl7grbHkrKMKP9/OK5SPe05yUTUpeeIfeF4KhOH3JYIDlXry99R28nsX/sHLKs+S6 jiRT13Y3fWIVGjTGRBBkkVfJgDWlGXEqQ64YbBL94y0XZI6M3YnDjzOX+eVkH5ewCE0VPlknY MrTN9Zep10zdZ19LcaUb6kum6bVgwKQ0ImY19QfvBiITa/JPgpcI2piADyvAuU/2c2s68RmWX K3Cx4nw1F8TJoVBOPois5VE8TMf7H9pM2WfgSRR8NghVuV6T+juL82PYn8HCsTxTrZvXp0TCV EPKtqxnraG41Vu36kmhHqz++AZt39yhHv5DC+JWFB/GtVNmhHQWxYruP3I0f3zqyo214E0Aza wMteeCPrFVFMmtVCXbUXJaG+j+936hRzLocn43jbua4H9yLRVBheA34pCBVq5xFlvfzdMOJSX hieYP/vyDEE+Ju2HsTvjk5PpaS0MocftavQTyKxRms30TFu9hz8ztx9B61gMgp3Wwz4g= Received-SPF: none client-ip=212.227.126.131; 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=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: , Cc: Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Two new functions: process_sigsuspend_mask and finish_sigsuspend_mask. Move the size check and copy-from-user code. Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier Message-Id: <20220315084308.433109-3-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/signal-common.h | 26 +++++++++++++++++++++++++ linux-user/signal.c | 23 ++++++++++++++++++++++ linux-user/syscall.c | 40 ++++++++++++++++---------------------- 3 files changed, 66 insertions(+), 23 deletions(-) diff --git a/linux-user/signal-common.h b/linux-user/signal-common.h index 2113165a7583..6a7e4a93fc13 100644 --- a/linux-user/signal-common.h +++ b/linux-user/signal-common.h @@ -92,4 +92,30 @@ abi_long do_swapcontext(CPUArchState *env, abi_ulong uold_ctx, */ int block_signals(void); /* Returns non zero if signal pending */ +/** + * process_sigsuspend_mask: read and apply syscall-local signal mask + * + * Read the guest signal mask from @sigset, length @sigsize. + * Convert that to a host signal mask and save it to sigpending_mask. + * + * Return value: negative target errno, or zero; + * store &sigpending_mask into *pset on success. + */ +int process_sigsuspend_mask(sigset_t **pset, target_ulong sigset, + target_ulong sigsize); + +/** + * finish_sigsuspend_mask: finish a sigsuspend-like syscall + * + * Set in_sigsuspend if we need to use the modified sigset + * during process_pending_signals. + */ +static inline void finish_sigsuspend_mask(int ret) +{ + if (ret != -QEMU_ERESTARTSYS) { + TaskState *ts = (TaskState *)thread_cpu->opaque; + ts->in_sigsuspend = 1; + } +} + #endif diff --git a/linux-user/signal.c b/linux-user/signal.c index 2a3f3cc23f92..092e70b80c6f 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -1199,3 +1199,26 @@ void process_pending_signals(CPUArchState *cpu_env) } ts->in_sigsuspend = 0; } + +int process_sigsuspend_mask(sigset_t **pset, target_ulong sigset, + target_ulong sigsize) +{ + TaskState *ts = (TaskState *)thread_cpu->opaque; + sigset_t *host_set = &ts->sigsuspend_mask; + target_sigset_t *target_sigset; + + if (sigsize != sizeof(*target_sigset)) { + /* Like the kernel, we enforce correct size sigsets */ + return -TARGET_EINVAL; + } + + target_sigset = lock_user(VERIFY_READ, sigset, sigsize, 1); + if (!target_sigset) { + return -TARGET_EFAULT; + } + target_to_host_sigset(host_set, target_sigset); + unlock_user(target_sigset, sigset, 0); + + *pset = host_set; + return 0; +} diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 77cd88b53785..d9b5662ff820 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9557,41 +9557,35 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, #ifdef TARGET_NR_sigsuspend case TARGET_NR_sigsuspend: { - TaskState *ts = cpu->opaque; + sigset_t *set; + #if defined(TARGET_ALPHA) + TaskState *ts = cpu->opaque; /* target_to_host_old_sigset will bswap back */ abi_ulong mask = tswapal(arg1); - target_to_host_old_sigset(&ts->sigsuspend_mask, &mask); + set = &ts->sigsuspend_mask; + target_to_host_old_sigset(set, &mask); #else - if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1))) - return -TARGET_EFAULT; - target_to_host_old_sigset(&ts->sigsuspend_mask, p); - unlock_user(p, arg1, 0); -#endif - ret = get_errno(safe_rt_sigsuspend(&ts->sigsuspend_mask, - SIGSET_T_SIZE)); - if (ret != -QEMU_ERESTARTSYS) { - ts->in_sigsuspend = 1; + ret = process_sigsuspend_mask(&set, arg1, sizeof(target_sigset_t)); + if (ret != 0) { + return ret; } +#endif + ret = get_errno(safe_rt_sigsuspend(set, SIGSET_T_SIZE)); + finish_sigsuspend_mask(ret); } return ret; #endif case TARGET_NR_rt_sigsuspend: { - TaskState *ts = cpu->opaque; + sigset_t *set; - if (arg2 != sizeof(target_sigset_t)) { - return -TARGET_EINVAL; - } - if (!(p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1))) - return -TARGET_EFAULT; - target_to_host_sigset(&ts->sigsuspend_mask, p); - unlock_user(p, arg1, 0); - ret = get_errno(safe_rt_sigsuspend(&ts->sigsuspend_mask, - SIGSET_T_SIZE)); - if (ret != -QEMU_ERESTARTSYS) { - ts->in_sigsuspend = 1; + ret = process_sigsuspend_mask(&set, arg1, arg2); + if (ret != 0) { + return ret; } + ret = get_errno(safe_rt_sigsuspend(set, SIGSET_T_SIZE)); + finish_sigsuspend_mask(ret); } return ret; #ifdef TARGET_NR_rt_sigtimedwait From patchwork Thu Mar 24 08:20:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 553903 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1248:0:0:0:0 with SMTP id z8csp4189842mag; Thu, 24 Mar 2022 01:31:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyj5cYDroEkMJFZUUHJZS3N3JJUWecnoMddnF4XaC2cfGtaL1Dugu6/PbcvZQNyaGx1auYr X-Received: by 2002:ac8:7ee3:0:b0:2e1:a508:c500 with SMTP id r3-20020ac87ee3000000b002e1a508c500mr3328337qtc.117.1648110718261; Thu, 24 Mar 2022 01:31:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648110718; cv=none; d=google.com; s=arc-20160816; b=ZHJd5ojdxPaG4VaaNY5Y0CuPYhP4TWIx5d2MiR8M+4+irAvgbFezt2sah/tkEUMiAO 5oXyM+LyMD1fvFumxSQO48lAgY3k3aEZK22wnXY6S+30UywwTHHBi/6MIPAfCenaEGPh ETycTOBseta43ryuUwEHGgzln9GAfo4iEUicCBL5f6aKQ2W1+S1kYLYd+Jv8w6qlo5Bw GWuFHzAUU1hLwfqMkJAtlzFNFrvQCcsANQQ17Bk1MEao+dVg1Hw+3gUGlTQcd3Yqw/LM 1/9ToUldj/vKlYIkhIRwISg1jK+wUafgDKYQK2q7pt9TQthqUt9UG4tu2vSXQu8v6dEn KfhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from; bh=q7Pwvdrf+6AIIz1HH/QSNujx5ns/6diDptxRae/YdH4=; b=EGZVsNVUERboCLbaslBqV09kLk9VryT9iaUYSRKPst+ECiZq0SGZSc27muEr6aiaHj uqNRKZn+8I9Eyux79JnX53uDZTJJhNZaerFZnmtm88buet/X7KsStBwYMno0Ui7VQgRH h+v5uHBH4hxFc8bhjE+CosnMZUaw5iQCLdRdDz0Q4q87VVIoU7w9ymRNCEwspgPotLRv zIIBY4A6FFP/AVyjSkKYBimh+Xv+VQn6twBukX04y/mqr10n6PohYdWpPBuUoetRXnwV dmvfLibj/kX5i9mr1S/o2kXGc15Qn0Fy/faoHcSB8qz3NRJTN4C2u3qNuD1+4GpbvWu9 2ezw== 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 m14-20020ad44a0e000000b00441070e4808si4782054qvz.50.2022.03.24.01.31.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Mar 2022 01:31:58 -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]:45648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXIsv-0000pQ-Kp for patch@linaro.org; Thu, 24 Mar 2022 04:31:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52212) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIhm-0005wn-V1 for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:27 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:54823) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIhk-0003On-Bm for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:26 -0400 Received: from quad ([82.142.12.150]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MEVJq-1nIQc32Yuo-00G0tU; Thu, 24 Mar 2022 09:20:21 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 04/10] linux-user: Properly handle sigset arg to pselect Date: Thu, 24 Mar 2022 09:20:10 +0100 Message-Id: <20220324082016.3463521-5-laurent@vivier.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220324082016.3463521-1-laurent@vivier.eu> References: <20220324082016.3463521-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:bfJ3jrAxtj2L4It4OZ/JdzQGDXMGqrZYZOJ9DbZJkKRuPxDZgVo 5q0HsXVLAYHGZb24Zaumk/+GVjS8LRZxNv3d8sPSQck5QYdT8BcBwDaw+prLDMrf5zooBlk OKkzN2vhbonA4vDZxRW/kr3jld30s4bLgWY5JyzdaH3V6GI7Flt7witUp7/kcthobYaYXCW 6ja4doaNCJWAHJENaAwIg== X-UI-Out-Filterresults: notjunk:1;V03:K0:sJYDj1PbD/c=:aZVY0KofkaVghyr4xM3rHy dnAMZgXmoNDlXzMDioxhJ8St2vKkZ7ctrZKU4BUDCXhg3j/U+71RmPHkInqTKFplJx6FyMa5U QoP9NF8ZUNJ9YIkupeWWhE8NHmudShn6KM2+2rI2l/uqC+k6QUQpsEGPW2rujQNvlakxYB9HE r4WGwRP5ZqUdApCUilxNLTM30U8wR9H5coLpMwUSJxht1C4daIqY4XiKE7wFf/u9ytsMi2YrE 69UzjrnTWrHaSMWtn7tnFbpTt4CPPM414dQjPXNnTHzFUKGOLimrVz3PCxrCrGmjmlcpeSu0y ebDNk8fQN9xx6TM3pWzfTTZbTW6hgq0XF8cXHqI/dmEmUQkNRq2vIWfSf6rUSS8SBNK2XU5yd Sb1HL9K+uELhOy8s9lWhO5Ddw5D/7cNm8pW7TwyAJ4Kel1/v0FdLCl5m5WvPS8CsMr7a7OJG1 sWR4CdfLn/GhtlS456HysWAO0cLvZn1yGcEgcrnTvJXj+s3JO+GtzbradjDOIToLhdjQ922lo A9/edBmU2MF/XE5rWbpuHoyl56SFoZh9wE0p069gAZilac2FklspUzUlPQP57Jgsx8+OmRu+P MTDeba03AwJEUIQesnc6QSa+lBX+uMQjXSh/Ygtlxs5cDkiPogKxlb4Yhh1jSlnBlioXqN8L0 kWvwu730FM2YwcCq00wdSwnxDvYz+/zLJoW91zn3JZENq/Fg5hADWqZD4VK1L1uLpRGQ= Received-SPF: none client-ip=212.227.126.135; 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=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: , Cc: Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Unblocked signals are never delivered, because we didn't record the new mask for process_pending_signals. Handle this with the same mechanism as sigsuspend. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/834 Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier Message-Id: <20220315084308.433109-4-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index d9b5662ff820..ffd4cefc8b7a 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1391,14 +1391,12 @@ static abi_long do_pselect6(abi_long arg1, abi_long arg2, abi_long arg3, * The 6th arg is actually two args smashed together, * so we cannot use the C library. */ - sigset_t set; struct { sigset_t *set; size_t size; } sig, *sig_ptr; abi_ulong arg_sigset, arg_sigsize, *arg7; - target_sigset_t *target_sigset; n = arg1; rfd_addr = arg2; @@ -1439,10 +1437,8 @@ static abi_long do_pselect6(abi_long arg1, abi_long arg2, abi_long arg3, } /* Extract the two packed args for the sigset */ + sig_ptr = NULL; if (arg6) { - sig_ptr = &sig; - sig.size = SIGSET_T_SIZE; - arg7 = lock_user(VERIFY_READ, arg6, sizeof(*arg7) * 2, 1); if (!arg7) { return -TARGET_EFAULT; @@ -1452,28 +1448,22 @@ static abi_long do_pselect6(abi_long arg1, abi_long arg2, abi_long arg3, unlock_user(arg7, arg6, 0); if (arg_sigset) { - sig.set = &set; - if (arg_sigsize != sizeof(*target_sigset)) { - /* Like the kernel, we enforce correct size sigsets */ - return -TARGET_EINVAL; - } - target_sigset = lock_user(VERIFY_READ, arg_sigset, - sizeof(*target_sigset), 1); - if (!target_sigset) { - return -TARGET_EFAULT; + ret = process_sigsuspend_mask(&sig.set, arg_sigset, arg_sigsize); + if (ret != 0) { + return ret; } - target_to_host_sigset(&set, target_sigset); - unlock_user(target_sigset, arg_sigset, 0); - } else { - sig.set = NULL; + sig_ptr = &sig; + sig.size = SIGSET_T_SIZE; } - } else { - sig_ptr = NULL; } ret = get_errno(safe_pselect6(n, rfds_ptr, wfds_ptr, efds_ptr, ts_ptr, sig_ptr)); + if (sig_ptr) { + finish_sigsuspend_mask(ret); + } + if (!is_error(ret)) { if (rfd_addr && copy_to_user_fdset(rfd_addr, &rfds, n)) { return -TARGET_EFAULT; From patchwork Thu Mar 24 08:20:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 553900 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1248:0:0:0:0 with SMTP id z8csp4187341mag; Thu, 24 Mar 2022 01:27:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWZYy+uEes52l6RWg4HOIQetMti/+VUduSYcdwVamDkVW1ZEHGJ9rKRFBfr0aE2OTAQ2j8 X-Received: by 2002:a05:622a:1305:b0:2e1:e697:31e7 with SMTP id v5-20020a05622a130500b002e1e69731e7mr3454672qtk.97.1648110441988; Thu, 24 Mar 2022 01:27:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648110441; cv=none; d=google.com; s=arc-20160816; b=f+3BVJNVQN4TYla5oqlZh8N0Kyaj77cFI8cpWEynJKPv6k/qkb3oNLTD3EkwOn473k RkKuZQgcH3LXgAaMq2840r4NJo1RM0mmTbN2fcPrnQqFo6bGOuc0mhFP72cq4bjaXNoP EYTCMKMgznVa5A4sX0UM6UJEv1h3MJ0ezv1ANvf7F97nWNrMUzMrV1yByIUS2R6NMOi8 UteqUqfgvnbHyognhy9nqTdLTMQajVRfdoZXEHsXDhihxLmh/KGzR+8cDqKrBW6PGyOc K3Bb3dqRey17G345k9mMxm8dA0NfAkD0S/+gM6VEkyvDeEeHO7yr/szTBstymgOoE78a D6Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from; bh=2SA4mxlLKGwCthdQAz/eA1rhYocJhomRJT6mF9J+sNY=; b=tdOjmxdEK2kYqzxqTaZ6aU43bXBi6fpRPdf4n1zIA1QeJrXD8h2SUBcOQtFnEiaP3d t+1hYjNWXcT8yJYppzhs7y23UX/RJ/+vweOaAT6qQgMI7uLwnrhvRjUXzCNVV/+tCo27 Ayr0bqUJGKnSbL8Oq+SOWCV4p338E9IX5u8CwdAk2qhrXtnWzMW1UGFW8Vn+5oIMDihj uW9/hckpWmT7CowdR6fcem51NBev1SIPrDUAHx7JARQvtaKqHaqZ6U7kFkVlhDaDhjAk k/rOSS4xGVjqg5ZumdJdLPlIf7qFpc19sdd9u8iVhZngNr55a5Cv+JHUz2pIuvhoyzFR GpwA== 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 o15-20020a05620a2a0f00b0067e67999d4bsi6107999qkp.653.2022.03.24.01.27.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Mar 2022 01:27:21 -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]:37098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXIoT-0003Q7-KL for patch@linaro.org; Thu, 24 Mar 2022 04:27:21 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIhm-0005wo-UL for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:27 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:42009) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIhk-0003Ov-D5 for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:26 -0400 Received: from quad ([82.142.12.150]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MTi9N-1nd6WR0H8v-00U5V1; Thu, 24 Mar 2022 09:20:22 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 05/10] linux-user: Properly handle sigset arg to epoll_pwait Date: Thu, 24 Mar 2022 09:20:11 +0100 Message-Id: <20220324082016.3463521-6-laurent@vivier.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220324082016.3463521-1-laurent@vivier.eu> References: <20220324082016.3463521-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:v2D7+tvf13oh60xk8WP5a54Aq2Ag0XesnjnpCQnlE84OKqPPW2P Z9oOu5HCdhO33syVBaDqaiLIEPt6tvxefn75XXxfp2uvQm5DjYb7UBwJt4o4H6Qi7hnzGHh RUJlpHP1zhH/YUF5zV3mv+turQpE4kHov+wjQbFQoXKjRCjHoIftsgb8nDLYaqxoSgqeVNc ryBGzUWWilo2FfMbFoPxA== X-UI-Out-Filterresults: notjunk:1;V03:K0:2mnjocTbFFw=:JdZptCg3aeanSe9c6vNYX8 oj2PXYKQ997yF4dVBzFauOnSxL4enzx1zjIQM/vNq8y7uVO+Fl1CllTaXJdMf62yZdD8Dx44S Uzzklkd/9m5l6fnZVhYbv/i3KAz7VV1xJIzrGNGfDd4P6tvkU8ofHq3zhV9/APM2dDPayUfr2 bLVmwEJ+Sf8EbGZVXDFHq1Ucil3gXcvGFN01vE82y+PjonK5xgj4hUog5mtuLDuKddg+Dsgl8 QReoVM4ECc5N2HHZpVQt7z/CEGY3KFESXDGx3LNXBY6h5fpZ8Vr9hoNkFXoloM1PDtFHxTYr4 cDQihkO6hyJgYF5ip099OQJ6h1anwgdPKlhiu4JoTImwFHrrdyMeidauU4WFevaKij4FePk5L kaEePSXhoKTQqpZZWrAwRlxzqpJG4WKwSk5c1aqd5q98u5HqDD7pqg//VsB88TAuYi+F2ADyE iS1WaYZoZAVO6KQTbvpHy3h/S5e0ZY/qvlTf7AgH5PUReja0c/kPpMGvjEX3spNaB8gPKOVY0 nzzpqr7IrwyvMbEDY6PPScFhA3R0/9ZIPUdfpKd+RJV9WcPaYpsh9pIvLGaJPEToBXsPKiIVf wR31wfqm9pp9LesExumhCzapIlzm+b14+K4B8LGd1Ah8KN0bVn7fcp9i7Y8r50vG7taMF26fS yVptMAjTomlvnrQI6QG1E73Urei+/hv2E8LTxlA9TgIjwIJ3ntlF2dIrf8bWbIJDi134= Received-SPF: none client-ip=212.227.126.131; 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=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: , Cc: Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Unblocked signals are never delivered, because we didn't record the new mask for process_pending_signals. Handle this with the same mechanism as sigsuspend. Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier Message-Id: <20220315084308.433109-5-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index ffd4cefc8b7a..67af40deac07 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -12694,29 +12694,21 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, #if defined(TARGET_NR_epoll_pwait) case TARGET_NR_epoll_pwait: { - target_sigset_t *target_set; - sigset_t _set, *set = &_set; + sigset_t *set = NULL; if (arg5) { - if (arg6 != sizeof(target_sigset_t)) { - ret = -TARGET_EINVAL; - break; - } - - target_set = lock_user(VERIFY_READ, arg5, - sizeof(target_sigset_t), 1); - if (!target_set) { - ret = -TARGET_EFAULT; + ret = process_sigsuspend_mask(&set, arg5, arg6); + if (ret != 0) { break; } - target_to_host_sigset(set, target_set); - unlock_user(target_set, arg5, 0); - } else { - set = NULL; } ret = get_errno(safe_epoll_pwait(epfd, ep, maxevents, timeout, set, SIGSET_T_SIZE)); + + if (set) { + finish_sigsuspend_mask(ret); + } break; } #endif From patchwork Thu Mar 24 08:20:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 553902 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1248:0:0:0:0 with SMTP id z8csp4189802mag; Thu, 24 Mar 2022 01:31:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJYvGppJT5rR2Y4oxGLrukwwV9RBCaGHnURln25QvXcXg7OKNWhS7EI4qKC+X8zG4jIZqR X-Received: by 2002:ac8:5a47:0:b0:2e1:e78c:8367 with SMTP id o7-20020ac85a47000000b002e1e78c8367mr3471339qta.126.1648110714363; Thu, 24 Mar 2022 01:31:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648110714; cv=none; d=google.com; s=arc-20160816; b=k40LF5KliBn3mnOrkmTbCykwZG4ARbJYQkWzdOC+MOXTCfY9+nQur0NAWa0LaaacoD icOxrx2ovP8a3X+Du6Jia3Arp6Rw63qAa5PB16azGAw80I6uLVCdVcVPau8IAy5VuvCh m/LaYgG7HHjOMO8e2kLFzXrV0PiWcAimc3IXltFNKSO1fFgI36ISh0pBcJ80a8mro4po ankPxP9pdr/J13Pikcvo0QzB4wPG9T8OzEpHdKqarT7uep0J+RzBw+f9Iau9DL6rQRfJ aX9QFj+BGAbJUwtZxZF7fvf6bs0D2TFb+p/3tSGLy63EkAKC/jXKsp5eclo9cvC/dkRj SjRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from; bh=5hnvLsiljUmEh3ipLvN3djysVLtYndXhLCEV/PT4I7M=; b=lHRdg2h+/vsgJnt/iuxJKqQghDpHr4VIcAbBxcBrhCMX7HpMCynCxoDG+HjpQsmeHO z+MZoBnyS1NjDSMR/iDxB9Djh/en8khQB7t0wXymjm7IcSjMlBgL22peijdJhtrJeV8l Eb/s6EIXfh0hRUls7yNQN62W3Jv1MmlRdB74NBGE1KO4l4VjAkmQbF3/TrZ2uQBUXJx9 DvCM5ViAp0W8fOzkU24NNQ9AlGkhUWZDpp/lJak8I4IM45WSpIFSWFtEEQ4QKJ+FhqSm GiAsvry4fxzbEdtG7zQdvvpwr/y2UinhjoT96vCWYyXlZRTxUuNHPT7MYKJwXdYSBk/X TSrw== 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 v129-20020a379387000000b0067e4be237e4si4871826qkd.41.2022.03.24.01.31.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Mar 2022 01:31:54 -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]:45590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXIsr-0000ms-Pc for patch@linaro.org; Thu, 24 Mar 2022 04:31:53 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52216) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIhm-0005wp-Us for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:27 -0400 Received: from mout.kundenserver.de ([212.227.126.133]:52963) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIhk-0003P6-Nl for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:26 -0400 Received: from quad ([82.142.12.150]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MYedH-1ncZtN2BQB-00VkSn; Thu, 24 Mar 2022 09:20:22 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 06/10] linux-user: Properly handle sigset arg to ppoll Date: Thu, 24 Mar 2022 09:20:12 +0100 Message-Id: <20220324082016.3463521-7-laurent@vivier.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220324082016.3463521-1-laurent@vivier.eu> References: <20220324082016.3463521-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:MQj22sMYeCS9DSnLGnftAziUQubUY1cVCcQYrGZ/TXFuChSRtpp MBqTNR7JVpT/DmGopMRWVlAOtLxQKeUwBUlIplTmo7cxhH9hL2aeTrXDkPngF/vQoZDQPz7 dFtA7j9AOQ9Mj+2CJDiJKg8V2WQSVCjcZnKnij0UoimmIlvpOa5n4qSARTYdzFGBiKrmMEn PXWGmiQYq+Y/QRZ4WQNVw== X-UI-Out-Filterresults: notjunk:1;V03:K0:Ok2kemLSHks=:xJFPqQEB73fSWlGhuF1DmZ oRp29qwRfb2PFvt+8d4NsZzw1+4MdBHV5rb3Kp1/Y53L/a+DNdKpjTHSSUHqrbnX2DnupuNY8 sgJ/8XzRSzU6ZaN9tPj7eO33sy1+94zM5Jf0D4tpmKwc3UirQNmaNp/AjIQdgJ6+OnjAIJyCr lPANd25mJL1cGIpiCuCPWru1ogcM3QiQYvNp8OPrCyB/tjKrvSh6edq1jzXYKCiKabTP0dYvJ Y4H/N/d92w9chuMfWH+090RZ7ICIWVSiwk4thYT7ClpvXYTKcAqUkbOMMASnbcA7KYkgTIq4X 9P1boUDdfMdpQKqFT31UfjHujHTYqflAHOODWoaV3Q2N3xhm7y6IhmE9MTfpclw8JZWEjNMsg nxdvhY7mlDkRHIS8Hu9m9yRMvoeKgpz3j9FLJRHYbbxKLVMJhdGjqr2FWfv0cpKtOEDwMeWZC XBIoMAVu15xohtAga5hwPGbFAjXC6fRXdEpNsTEPNMrj01qv70X9atPiHiV/zxaCv3wezVsUE +aidZ9gwdQ8xCX1deD/5gA9ZUi2Ts04lsjCys3HZYZlFm8a3Czxh7XgAYcDJbEpcCFeHljWoX VLpzeVxUJ+tdIyGVLPyCiAzbpntVxIOxNJIfpgtWB0JpSajz0PKqCdSaTKK3oVvaF4wxStam+ XCSHCQQR2ujYy6blO5kAo22SJixXhNUBkr+fwqlJ+D4u6Bz57tlConu50sUOYsUdGjWk= Received-SPF: none client-ip=212.227.126.133; 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, 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: , Cc: Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Unblocked signals are never delivered, because we didn't record the new mask for process_pending_signals. Handle this with the same mechanism as sigsuspend. Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier Message-Id: <20220315084308.433109-6-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 67af40deac07..f65045efe6a2 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1519,8 +1519,7 @@ static abi_long do_ppoll(abi_long arg1, abi_long arg2, abi_long arg3, } if (ppoll) { struct timespec _timeout_ts, *timeout_ts = &_timeout_ts; - target_sigset_t *target_set; - sigset_t _set, *set = &_set; + sigset_t *set = NULL; if (arg3) { if (time64) { @@ -1539,25 +1538,19 @@ static abi_long do_ppoll(abi_long arg1, abi_long arg2, abi_long arg3, } if (arg4) { - if (arg5 != sizeof(target_sigset_t)) { - unlock_user(target_pfd, arg1, 0); - return -TARGET_EINVAL; - } - - target_set = lock_user(VERIFY_READ, arg4, - sizeof(target_sigset_t), 1); - if (!target_set) { + ret = process_sigsuspend_mask(&set, arg4, arg5); + if (ret != 0) { unlock_user(target_pfd, arg1, 0); - return -TARGET_EFAULT; + return ret; } - target_to_host_sigset(set, target_set); - } else { - set = NULL; } ret = get_errno(safe_ppoll(pfd, nfds, timeout_ts, set, SIGSET_T_SIZE)); + if (set) { + finish_sigsuspend_mask(ret); + } if (!is_error(ret) && arg3) { if (time64) { if (host_to_target_timespec64(arg3, timeout_ts)) { @@ -1569,9 +1562,6 @@ static abi_long do_ppoll(abi_long arg1, abi_long arg2, abi_long arg3, } } } - if (arg4) { - unlock_user(target_set, arg4, 0); - } } else { struct timespec ts, *pts; From patchwork Thu Mar 24 08:20:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 553898 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1248:0:0:0:0 with SMTP id z8csp4184669mag; Thu, 24 Mar 2022 01:22:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFO22ChJ+EdlaaQZZJCY+5P0tha5hjiIMGNZr8qbjAffHrK/Oc7FgPuEHHRaXIUh9/2xXY X-Received: by 2002:ac8:5fc5:0:b0:2e1:fd15:a68e with SMTP id k5-20020ac85fc5000000b002e1fd15a68emr3424142qta.140.1648110130532; Thu, 24 Mar 2022 01:22:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648110130; cv=none; d=google.com; s=arc-20160816; b=zB1sWwAaE75aVLHGk2amGVIzRH+To0+tS3MqS5DXVmsl+kcmBpRQotHB4zr9ymMOwF RIqLdlwI6+PhB4BOkyKtWAJtUhKZ+e27vQ+CTPMSQvrqao7f1s23QpgpDC/e4L+2jTm/ /mmCoObAUjg/6t3UqOwATXWlv1yl7at1ym0DvxRBOwiEPmsMJaWgVmpr4ATobxC4XB8o ScFlujUevBrxuWvI7uR+E/aTKWtvVECPjWySdQtce4SYHhB+ZI3SvLYnFhuRJF65UEAb BJIcnoxtVwiSsZEpkedMAd0ezKXTnUYw9fHM/oKYHFfgMo3gP+QZaor/QC1JmlnGuBpN EJ5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from; bh=aooQi0ERL/QdmFrGpEmqHN8H2NpJqSt7Izs2gmK3Fog=; b=pCH5Nq3Wyywq3GSdMoTSLPALmI0+FGqmt68stQwbXdzurbVGVaaw/0XyPUUj2McC9m fV/A2H78eO5yaweT5imak44gmVgvQOtDnlIeuDiXXxWxCe3LK3bdSs9p3MPw/ynHqJrj g9S5CpB98ZU65A1yYt62FtQxt4VHDwWuegOg6PWl2JBGbd5/YNrireenrhWbf2gNCMpR tdta8ZxaORX49O7bmydVRillow5vnfmOJhBB9IwNKqLxa5OJ99+F9ez4/nQXxLjG6teb XBjU1Z//ViUUXAV6GAYVOrBrinTEnUX4avyxOLHLzCYUthxczYmNnbCks5i0ITy7hzkg XJoQ== 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 p2-20020a0cfac2000000b00440e46a7ba4si4855067qvo.66.2022.03.24.01.22.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Mar 2022 01:22:10 -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]:57014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXIjR-00063C-HE for patch@linaro.org; Thu, 24 Mar 2022 04:22:09 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIhn-0005xg-SP for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:28 -0400 Received: from mout.kundenserver.de ([212.227.126.133]:39315) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIhl-0003Ps-Qv for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:27 -0400 Received: from quad ([82.142.12.150]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MyK1E-1oGcGZ3Ji0-00yjHa; Thu, 24 Mar 2022 09:20:23 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 08/10] linux-user/arm: Implement __kernel_memory_barrier Date: Thu, 24 Mar 2022 09:20:14 +0100 Message-Id: <20220324082016.3463521-9-laurent@vivier.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220324082016.3463521-1-laurent@vivier.eu> References: <20220324082016.3463521-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:Z/NlUyply1+7e9wKf2c6YVxP2JU/sJwneqMS8vQBL2bQbEIfwk6 pgUQ8zs5Hs5gdCuZT3iPrwKRuxHd5JIxHvZtkU7mOVrdO2K+xA02QA/AC2Ku2doUEWj4o8S rQijBXVyNebwx7Y7gxMVMGxnH1ritZipLKvPZhnd3VGK7QTZt0n1QHkyCbEDFElyxZNemuG WGW4T1Tj87OZNIb99BUoA== X-UI-Out-Filterresults: notjunk:1;V03:K0:d4ljv/EYbSw=:W04w696d/mx9U0qugvLbPC BhAhjaIeIC1LcKaRAgC7t+PJh0WRbAKLzibTB5UAaUD1ckGRg5EUAM9vW6JzGIGKwqa9lO404 YEh/2FZFei7BC7jWN9RGMfTgD5AZHGgyI155QzzEFg844/xp+Gg89r79eDIc8DTT9RMFwi3vM gHdKZR3oHbYA+7fMGHeKzQrVgfh8xAEg9RTeL7qWD022WnEOayWuzFDu/lGQSdsGDU71Hz7xh o8UmjFjDiZYnvtO8YFx2jMVxk0zfv9p6hl7UMLCzd7IMtlmzVuUDVrtD2DsaCZpCt7a4M3aCK eKvl+SWmhLr+5s9EamzNNyjlYrPLb7s6mHyx6XZJhgdLiwcQyL/Vka+oakHIb6tN4/BGG1NxW t073OkpcvAQWGuz30nvSrNxWT70BtuXDZFuJDNOFDguWrKbcbbq+14pmtjr+gTs7q4P55zO9O 5WEBdgGJYYGFthr3rytPU4Ckoe75JnAsHtUUa1MwadRmd6sPf2iRpdMDy/x68bl095VEdCOKb TQqrdxgzWRS1ImkGj17dprCOfRqgOJfCEUgkpr99HIAdDC+hM1Fhy1T3GKleRmiyIwfw2pSc7 5GzPRsCYh2vGa8WKEpWAf6qF86FU0NdFxE0Sh5rOLxvUpfjS3qG8tcjBcGZuy6+kvJtvttFGa xrCJ7sdrmvpiWR7ShRELhsgKx/bf6IWBasEICeuZdGyEclDtJS4iu0yjcC+92t72+Nsw= Received-SPF: none client-ip=212.227.126.133; 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, 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: , Cc: Peter Maydell , Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson This fallback syscall was stubbed out. It would only matter for emulating pre-armv6. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson Message-Id: <20220323005839.94327-2-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/arm/cpu_loop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c index 032e1ffddfbd..a0e43b261c7b 100644 --- a/linux-user/arm/cpu_loop.c +++ b/linux-user/arm/cpu_loop.c @@ -158,7 +158,7 @@ do_kernel_trap(CPUARMState *env) switch (env->regs[15]) { case 0xffff0fa0: /* __kernel_memory_barrier */ - /* ??? No-op. Will need to do better for SMP. */ + smp_mb(); break; case 0xffff0fc0: /* __kernel_cmpxchg */ /* XXX: This only works between threads, not between processes. From patchwork Thu Mar 24 08:20:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 553901 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1248:0:0:0:0 with SMTP id z8csp4187376mag; Thu, 24 Mar 2022 01:27:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyh/xheT29ZDcAuH3kFgBdbdNwt760WVA12s60Htq9Q7PMy9+JZ6UsUIvAxvlkwNmm28iro X-Received: by 2002:a05:6214:29c5:b0:441:a73:88b2 with SMTP id gh5-20020a05621429c500b004410a7388b2mr3176818qvb.108.1648110445709; Thu, 24 Mar 2022 01:27:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648110445; cv=none; d=google.com; s=arc-20160816; b=SFCYAFEEGFlo6cI7Nyy/HmdGkE6/gD+dRShSk5fm1oIQ3jj4/tCrCtqUyssr2w5os0 XiRZAYA/KISSy9eZ58EBDaMIvcU3dl45EOWnSw13rN5cPDhQI3D6TXUaLvd8mpnfmYKX tDCBKle6fmdBz6jZUyPJOr/Rw0TXS1sfVbpZL+ERACCTv03GdAd1sIKHwm7kHeptAfCn 7+MmUUVcdg8H4VKPeOJUCL6z8o+T4ieL4umbV0NoDtbI6wLsivLbtdXH0iaGhYYTaCJm Nvf3mxeWg0GhpNvy5hkb2oCH6hQ2JUDJBeufzQVl1CpT3xFRtbsooFsvLxb9/+WIBJBA wdmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from; bh=1p5HkghsmaduEwpNHDvTmvWe0aYKwrbWgOhq85C+Uok=; b=jMO7WvprMxIa0J78RvsUOpN4WcZ325FQpQJivb4gaoz5R2TS4v9t2vK/XLhZq4vS3/ LwESc1ZTjn+1TSZ20YW91kiMTcsq0d7p+DoIGMqORFtWds2JlLyUhohR9xtItPMpaLtX mQM0SfPbrUDzxrhi9WgMnfCXk8dyDoGWphkIPfZjFdZYhu8OFaDmFp6S1rf+1+Vnsf8V m7ijyX7POaNLJhN5jUXvwqqrWRLYuTZyCl/zN4Hk1CMNT+j0jaHIMUqCYkqZULPJuZAo 3fM75PUtaDnc+R8SKFG576QuuL18QLygPTxnAHz2WJomN100XInFmvoUn/QV8ATb1JM1 onkw== 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 de36-20020a05620a372400b0067e4be238ddsi5342872qkb.290.2022.03.24.01.27.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Mar 2022 01:27:25 -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]:37234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXIoX-0003VM-A6 for patch@linaro.org; Thu, 24 Mar 2022 04:27:25 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52248) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIhp-0005yo-6I for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:29 -0400 Received: from mout.kundenserver.de ([212.227.126.133]:33031) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIhn-0003Qp-DU for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:28 -0400 Received: from quad ([82.142.12.150]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MYedH-1ncZtT1JD9-00VkSn; Thu, 24 Mar 2022 09:20:24 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 09/10] linux-user/arm: Implement __kernel_cmpxchg with host atomics Date: Thu, 24 Mar 2022 09:20:15 +0100 Message-Id: <20220324082016.3463521-10-laurent@vivier.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220324082016.3463521-1-laurent@vivier.eu> References: <20220324082016.3463521-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:PM1c+FKR++/Uae2Fa016VcrHdR7QtG0yRnAg9ZqGXtdGzepLS1i n8wsx7TAczq1BQXTqCbFGZWSnYxXpdOl90/+53ZhjD5eJAzX4q/LCEHYaBu7oj6BvuRK0lz Q8y4c0bAWFOBQJtGronPa1o1Tt75OETsHvsvxc6UyAyulwWhEX+5QCc13lqGhO883YgcYnB KRKKuFiiGN1zmH5HU/fjg== X-UI-Out-Filterresults: notjunk:1;V03:K0:lxw+9ObZsSc=:AWvURXGJUxCERWDAHhBQKz nI1NOWYymFxiWWVYZFrnV2Lq+6FXcdrbiEXlMroQY2KRLi2uYfit3Vp19+x+ZtzVLdee194OZ HR5WwetbKKyLNm4drU++j2DIKu9oP5yDFwQHQiGLwSaZxbCJDK1J60q/4UJxwcWLp5+spX4h6 8EmCFWm2PAfzIyzYwa8KEdqfGIeq0LdocXxfc9Ki6sMpBFykazxtpuvBU79RfEB7tgsI0Ed6N ohc043DULcgr9+HbkqaVvbIjkvfV4Qd6HVBc/TkKrZKw+q9dAAjrv6Vk5PW5NJdJSSx1ybLPz KLr73E8X9TWm2hZbEiP/UD4m+CefYqaOEqZX+R+F+SS6DtXZaLlGeHcYKQMdEkWi/4e8jFj1E XfRwUB9il431aO3fS+ObxgBXIDFDvJktZ/IFI5/YSOxegDg8c5yaXjp1NuKp9K0PQRxEVEx7x vtVWan/fn7qgZW0HM+8KemsJmq3eQf4= Received-SPF: none client-ip=212.227.126.133; 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, 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: , Cc: Peter Maydell , Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson The existing implementation using start/end_exclusive does not provide atomicity across processes. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson Message-Id: <20220323005839.94327-3-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/arm/cpu_loop.c | 87 ++++++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 25 deletions(-) diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c index a0e43b261c7b..aa2d777bf449 100644 --- a/linux-user/arm/cpu_loop.c +++ b/linux-user/arm/cpu_loop.c @@ -75,7 +75,67 @@ put_user_u16(__x, (gaddr)); \ }) -/* Commpage handling -- there is no commpage for AArch64 */ +/* + * Similar to code in accel/tcg/user-exec.c, but outside the execution loop. + * Must be called with mmap_lock. + * We get the PC of the entry address - which is as good as anything, + * on a real kernel what you get depends on which mode it uses. + */ +static void *atomic_mmu_lookup(CPUArchState *env, uint32_t addr, int size) +{ + int need_flags = PAGE_READ | PAGE_WRITE_ORG | PAGE_VALID; + int page_flags; + + /* Enforce guest required alignment. */ + if (unlikely(addr & (size - 1))) { + force_sig_fault(TARGET_SIGBUS, TARGET_BUS_ADRALN, addr); + return NULL; + } + + page_flags = page_get_flags(addr); + if (unlikely((page_flags & need_flags) != need_flags)) { + force_sig_fault(TARGET_SIGSEGV, + page_flags & PAGE_VALID ? + TARGET_SEGV_ACCERR : TARGET_SEGV_MAPERR, addr); + return NULL; + } + + return g2h(env_cpu(env), addr); +} + +/* + * See the Linux kernel's Documentation/arm/kernel_user_helpers.rst + * Input: + * r0 = oldval + * r1 = newval + * r2 = pointer to target value + * + * Output: + * r0 = 0 if *ptr was changed, non-0 if no exchange happened + * C set if *ptr was changed, clear if no exchange happened + */ +static void arm_kernel_cmpxchg32_helper(CPUARMState *env) +{ + uint32_t oldval, newval, val, addr, cpsr, *host_addr; + + oldval = env->regs[0]; + newval = env->regs[1]; + addr = env->regs[2]; + + mmap_lock(); + host_addr = atomic_mmu_lookup(env, addr, 4); + if (!host_addr) { + mmap_unlock(); + return; + } + + val = qatomic_cmpxchg__nocheck(host_addr, oldval, newval); + mmap_unlock(); + + cpsr = (val == oldval) * CPSR_C; + cpsr_write(env, cpsr, CPSR_C, CPSRWriteByInstr); + env->regs[0] = cpsr ? 0 : -1; +} /* * See the Linux kernel's Documentation/arm/kernel_user_helpers.txt @@ -153,36 +213,13 @@ static int do_kernel_trap(CPUARMState *env) { uint32_t addr; - uint32_t cpsr; - uint32_t val; switch (env->regs[15]) { case 0xffff0fa0: /* __kernel_memory_barrier */ smp_mb(); break; case 0xffff0fc0: /* __kernel_cmpxchg */ - /* XXX: This only works between threads, not between processes. - It's probably possible to implement this with native host - operations. However things like ldrex/strex are much harder so - there's not much point trying. */ - start_exclusive(); - cpsr = cpsr_read(env); - addr = env->regs[2]; - /* FIXME: This should SEGV if the access fails. */ - if (get_user_u32(val, addr)) - val = ~env->regs[0]; - if (val == env->regs[0]) { - val = env->regs[1]; - /* FIXME: Check for segfaults. */ - put_user_u32(val, addr); - env->regs[0] = 0; - cpsr |= CPSR_C; - } else { - env->regs[0] = -1; - cpsr &= ~CPSR_C; - } - cpsr_write(env, cpsr, CPSR_C, CPSRWriteByInstr); - end_exclusive(); + arm_kernel_cmpxchg32_helper(env); break; case 0xffff0fe0: /* __kernel_get_tls */ env->regs[0] = cpu_get_tls(env); From patchwork Thu Mar 24 08:20:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 553899 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1248:0:0:0:0 with SMTP id z8csp4186819mag; Thu, 24 Mar 2022 01:26:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGB55oK38Fawvu8PPtO66UhRFkkc1URYGVJ98fzD+L96q6ZJCifi2+iSymPLRbYdeb+B8t X-Received: by 2002:a05:6214:1c8a:b0:440:f52d:8bcf with SMTP id ib10-20020a0562141c8a00b00440f52d8bcfmr3198689qvb.60.1648110366849; Thu, 24 Mar 2022 01:26:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648110366; cv=none; d=google.com; s=arc-20160816; b=eYvfnaU/eKoE4hMKrBYgu8JhDdikKrfK8CzNUmXKJ9PG0HoOLf4oASOw1OJNM7FRy5 sfQSkUSIA7YIlox4rQBDSSrB+DE0R26Z+XD/eo0Kzowt9Efe0Vt9qwCXSK0zSgZ7qc8d PL+Es5XHgBH71mGWAkOupBgEIFeKIQx1BOLxzk4u+EyhPXNO8iBPHE7oyq2gDFxIhY/q DNxigbtU090ApjZJXmew1elQ4prmJxCTwe6qvpOQ8yDdf5mkKwTuey191hGQUUPYkOQO vs9R8udeAM+O5S+194i2kXEqFLnKAu4PBOOcF96cbjDtupFx9le1EWdyTqwhE88BPTPw FAVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from; bh=ISlSDPYVJwE3vp7bU03ufj/JKJQgcZoujK//JoxLpG4=; b=uBwinvpWPFxdRM9JJA2dmN3QIDiqSpH4lAXezhXasGKq+Klw1NyqPLqB0um7sUxkNp rLPgrmwz1joNElAeOfQgwL+mlXCeHu+aCh6j0s2hvb2bhm5xnJUrfx4aP/sqx1/6OXao ZDAlGiWOboIWlSj+BOCSd/gK5aU8Psrydyah7Wvh5IMRfg7kQKN1MtFbFjKnErBZOVKC V4ZSvwR75TJwuRzQ+5IFt8JIxRjJwuVZQfVJSmI4QjD9e58rZZnlHGV518SfK4NVjSG7 8yHzbiGLTT7wQar+9Uz21e65D21RNNBTR1rG4oJafCx4lrlI75fZ7+y/BwHLK+hsipJc H6jQ== 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 bn12-20020a05622a1dcc00b002e1fbf3c03bsi4931811qtb.556.2022.03.24.01.26.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Mar 2022 01:26:06 -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]:33820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXInG-000195-EW for patch@linaro.org; Thu, 24 Mar 2022 04:26:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52246) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIho-0005yJ-R7 for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:28 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:34009) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIhm-0003QQ-Rm for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:28 -0400 Received: from quad ([82.142.12.150]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MirX2-1o19oa3STs-00eqz8; Thu, 24 Mar 2022 09:20:25 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 10/10] linux-user/arm: Implement __kernel_cmpxchg64 with host atomics Date: Thu, 24 Mar 2022 09:20:16 +0100 Message-Id: <20220324082016.3463521-11-laurent@vivier.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220324082016.3463521-1-laurent@vivier.eu> References: <20220324082016.3463521-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:ua5RvGBo8oB2zsuxbQLVWRtT+OjtQ2Pfk3/fLBQl6+aovURTHLY PSrmwUgXtdmZdW42sVoWXWy9eMOj5CCglZj3aD+4YCo+O3OLjaOmsv6n8jhv42v9oI7rMZD RD/3uopGPmnJV7TJ2o0pLg5KpZZmvrR4/yJL9jzygi6Xlx0Jnu6IE40iEwWl6tz+Gj845N9 vNqpecH7qirhwhd599xrw== X-UI-Out-Filterresults: notjunk:1;V03:K0:nD2La7kckSI=:Y1Bp7ofW8gJmNW8Cw2FF4N jWsKOrOefLCgNyymmuA654IY+PdY6Q5q5HcQnwbW/p+YckffIED1LY9lwwVDkjBrNV7/CntTi lmNad9i5qbu4g06HLEAzofrLluuvmbaK/t3qvGOWIQt6IhtdcTsNEpkw/o/3kbEStrdZFaaUU tDcoCGztxWCmAqaKqBBJ794b2PQbyt1yxDEn3gUPjaUC1zc9dWeOWCr5AOUMVLwhzoQph+Vb0 AHhUzTIQ5yL78ps6112xtxm0C0uQUkYmpbDA6Wna38FHweqUttpLe7+ymNTXjRY1C4IPPnuME ykYrabz10xXw46jRbi7LnfEFnVnbHqpgNwQmrqxni64oGgGMkzD48v0eP43zmytflGn1+hghG RGkKecD0H9EvsioCiy7Xe/NOUhfUZMbGfyc1hq6jdvB1vaNIxX7NCY475GwMchTN/8jgHfvSo BgmKvE8Qe4z1Q+AKBLo/ksDpFBM/ygKkPelq53aTAe1jE0W3/x+xFibnJrjXhzofxhro7VFNx W8yXd9w3P3937Z2VkArvrBJbsLF1qGhtWzsEWGV0jdcP4rmKDgmDbNkNj7V2QY5wMnfEolovM /VYl1TsRo9ZlpGxjWQUmVg78XJR30OVp87gYzs/pkKGoylcL6OoGdRHEYJ3/AfhoYwcrgcxlJ UE4vjcWar8WQlXmldtYUsp6kRx2Q+PXe3ZgdkAx+gKUPc9PSlRtcjB9SUW1CYvXIvVNo= 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, 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: , Cc: Peter Maydell , Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson If CONFIG_ATOMIC64, we can use a host cmpxchg and provide atomicity across processes; otherwise we have no choice but to continue using start/end_exclusive. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson Message-Id: <20220323005839.94327-4-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier --- linux-user/arm/cpu_loop.c | 75 +++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c index aa2d777bf449..aae375d61792 100644 --- a/linux-user/arm/cpu_loop.c +++ b/linux-user/arm/cpu_loop.c @@ -138,7 +138,7 @@ static void arm_kernel_cmpxchg32_helper(CPUARMState *env) } /* - * See the Linux kernel's Documentation/arm/kernel_user_helpers.txt + * See the Linux kernel's Documentation/arm/kernel_user_helpers.rst * Input: * r0 = pointer to oldval * r1 = pointer to newval @@ -155,57 +155,54 @@ static void arm_kernel_cmpxchg64_helper(CPUARMState *env) { uint64_t oldval, newval, val; uint32_t addr, cpsr; + uint64_t *host_addr; - /* Based on the 32 bit code in do_kernel_trap */ - - /* XXX: This only works between threads, not between processes. - It's probably possible to implement this with native host - operations. However things like ldrex/strex are much harder so - there's not much point trying. */ - start_exclusive(); - cpsr = cpsr_read(env); - addr = env->regs[2]; - - if (get_user_u64(oldval, env->regs[0])) { - env->exception.vaddress = env->regs[0]; + addr = env->regs[0]; + if (get_user_u64(oldval, addr)) { goto segv; - }; + } - if (get_user_u64(newval, env->regs[1])) { - env->exception.vaddress = env->regs[1]; + addr = env->regs[1]; + if (get_user_u64(newval, addr)) { goto segv; - }; + } - if (get_user_u64(val, addr)) { - env->exception.vaddress = addr; - goto segv; + mmap_lock(); + addr = env->regs[2]; + host_addr = atomic_mmu_lookup(env, addr, 8); + if (!host_addr) { + mmap_unlock(); + return; } +#ifdef CONFIG_ATOMIC64 + val = qatomic_cmpxchg__nocheck(host_addr, oldval, newval); + cpsr = (val == oldval) * CPSR_C; +#else + /* + * This only works between threads, not between processes, but since + * the host has no 64-bit cmpxchg, it is the best that we can do. + */ + start_exclusive(); + val = *host_addr; if (val == oldval) { - val = newval; - - if (put_user_u64(val, addr)) { - env->exception.vaddress = addr; - goto segv; - }; - - env->regs[0] = 0; - cpsr |= CPSR_C; + *host_addr = newval; + cpsr = CPSR_C; } else { - env->regs[0] = -1; - cpsr &= ~CPSR_C; + cpsr = 0; } - cpsr_write(env, cpsr, CPSR_C, CPSRWriteByInstr); end_exclusive(); +#endif + mmap_unlock(); + + cpsr_write(env, cpsr, CPSR_C, CPSRWriteByInstr); + env->regs[0] = cpsr ? 0 : -1; return; -segv: - end_exclusive(); - /* We get the PC of the entry address - which is as good as anything, - on a real kernel what you get depends on which mode it uses. */ - /* XXX: check env->error_code */ - force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR, - env->exception.vaddress); + segv: + force_sig_fault(TARGET_SIGSEGV, + page_get_flags(addr) & PAGE_VALID ? + TARGET_SEGV_ACCERR : TARGET_SEGV_MAPERR, addr); } /* Handle a jump to the kernel code page. */