Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3257760pxa; Tue, 18 Aug 2020 10:24:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxecL7B75S0xV+JwYLQ4sVJNBt7Tr3af6jy6Gf00zIa5BH7IhVaPNG3DNnfIdGMa0AAanQq X-Received: by 2002:a05:6402:22bc:: with SMTP id cx28mr20197842edb.171.1597771450665; Tue, 18 Aug 2020 10:24:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597771450; cv=none; d=google.com; s=arc-20160816; b=rOl9XtRgb12h8P1TkgaG/ilX1jJD50/OPwg9gk93BBIs/2so/CF7W081WwlpZIDIj4 2/pOHp8Aneswoeqw67y8tedUgJDNhVG6U1DPmdl/+Sm5np+ce1dqnkt9wnsSZJv3L5H0 PbaA8pA1zYnzjbIiE0+9L/UIEbsA1KDj20yoLWKZIm2SqR+HYrz3ZNygZfHim5l96vUS t9b7TT/kKJCqC2TKGS0jBQA3iV29/eAWEY00UbclEBccnp9yOKqNrD7qMz7Ga9KDIqtj 31wk0BxW7Ekyva51NUCWJo3uUFsC9DJozMijSI7AVw8QJ50U1GlOm0dyfts+Xj/l1JdA NzUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id; bh=6EyWTYIHIxvA8t6HdV4kUPR3RPQ1/H1HSZ1EaOFgBGI=; b=lGbKvdT7mEL4AptzQ0h036f1MgfgswTAbIntmFW/NARncw2Q4CFHN8eR+dZcBDq+AD MgNJ0VWuuagpulyPCzK9ssoKPFYI74OGiHr4Wr3CerJWo3yN6BlE1BHePG7L3bto14/l UEAhpNPBUL7YraC0omFqeMj/UHuTcOVjAm3x1MAbAU6dlvkr49TaLsrm2mI9QpLMQ0v0 Up+tsF+vMImAm/kamBO+X8tro6JtvDGqX75uDhxUT9MLPBVO3mZPOm9JYI9anxg6Whae vwzlUvuneq4JAJhUKYgPiCou89P6MSKuvXulIGxamSFRMTBc/hriZ1ScksagecPtWStE gMFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j2si13774913edt.577.2020.08.18.10.23.46; Tue, 18 Aug 2020 10:24:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728388AbgHRRUg (ORCPT + 99 others); Tue, 18 Aug 2020 13:20:36 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:24246 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728417AbgHRRTf (ORCPT ); Tue, 18 Aug 2020 13:19:35 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4BWHhh5Nyvz9vCy3; Tue, 18 Aug 2020 19:19:32 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id eK0WypmNrd3Z; Tue, 18 Aug 2020 19:19:32 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4BWHhh4bHHz9vCxg; Tue, 18 Aug 2020 19:19:32 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 840808B7EC; Tue, 18 Aug 2020 19:19:34 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id ZQ4LR3HHLaeN; Tue, 18 Aug 2020 19:19:34 +0200 (CEST) Received: from po17688vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 476BA8B7D7; Tue, 18 Aug 2020 19:19:34 +0200 (CEST) Received: by po17688vm.idsi0.si.c-s.fr (Postfix, from userid 0) id CFF1A65CF4; Tue, 18 Aug 2020 17:19:33 +0000 (UTC) Message-Id: <06def97e87ac1c4ae8e3197e0982e1fab7b3c8ae.1597770847.git.christophe.leroy@csgroup.eu> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v2 21/25] powerpc/signal32: Add and use unsafe_put_sigset_t() To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Tue, 18 Aug 2020 17:19:33 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org put_sigset_t() calls copy_to_user() for copying two words. This is terribly inefficient for copying two words. By switching to unsafe_put_user(), we end up with something as simple as: 3cc: 81 3d 00 00 lwz r9,0(r29) 3d0: 91 26 00 b4 stw r9,180(r6) 3d4: 81 3d 00 04 lwz r9,4(r29) 3d8: 91 26 00 b8 stw r9,184(r6) Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/signal_32.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c index 310d3b8d9ad5..3f9f315dd036 100644 --- a/arch/powerpc/kernel/signal_32.c +++ b/arch/powerpc/kernel/signal_32.c @@ -87,6 +87,8 @@ static inline int put_sigset_t(compat_sigset_t __user *uset, sigset_t *set) return put_compat_sigset(uset, set, sizeof(*uset)); } +#define unsafe_put_sigset_t unsafe_put_compat_sigset + static inline int get_sigset_t(sigset_t *set, const compat_sigset_t __user *uset) { @@ -141,6 +143,13 @@ static inline int put_sigset_t(sigset_t __user *uset, sigset_t *set) return copy_to_user(uset, set, sizeof(*uset)); } +#define unsafe_put_sigset_t(uset, set, label) do { \ + sigset_t __user *__us = uset ; \ + const sigset_t *__s = set; \ + \ + unsafe_copy_to_user(__us, __s, sizeof(*__us), label); \ +} while (0) + static inline int get_sigset_t(sigset_t *set, const sigset_t __user *uset) { return copy_from_user(set, uset, sizeof(*uset)); @@ -780,10 +789,10 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, failed); unsafe_put_user(PPC_INST_SC, &mctx->mc_pad[1], failed); } + unsafe_put_sigset_t(&frame->uc.uc_sigmask, oldset, failed); + user_write_access_end(); - if (put_sigset_t(&frame->uc.uc_sigmask, oldset)) - goto badframe; if (copy_siginfo_to_user(&frame->info, &ksig->info)) goto badframe; -- 2.25.0