From patchwork Wed Jul 11 13:56:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141740 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp321109ljj; Wed, 11 Jul 2018 06:57:18 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcca4Hk0yhQEQwNBb3TF9Bh8FDfl1Vi+VkdoO4mnGS0CEf5mMg4X1ByHClGFesGVbNUWnFW X-Received: by 2002:a17:902:bf43:: with SMTP id u3-v6mr28740942pls.322.1531317438140; Wed, 11 Jul 2018 06:57:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317438; cv=none; d=google.com; s=arc-20160816; b=P1UfmYj6IGihUfSL7vD4OIq14YKmIiBMqebdVM8x0VSbgf7d467M3tii5XrMfYk4Ll EixU+Kjyj+6MhR+gN+x/KJ86I2xvogp2leBXZGEN9jFXW8EUL6/wdZtWqX7yb4hiYpkB VVg5kdnrYD4q5AkhUH/kxIN+m/CqqpMobija+XOQFXIIPGozgDchtEAsdOmGfNjRv4qV 1dgrcB6B4aJF6F0fYg5ii0CS0lx5/NhZ7flBtPsoa8EOjqCVbfjF52ZfsdWx+2w+GCwG oA2W7KTKb9y6x9O/956dMhxNmkAKPVsQI3jpxx3dp+4Vhq5KfFFmcPZTlnallta3IdAP Qz4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Y7XKzDQ0vFh1cwMZiAkFJVjdlBTry6n8VpmHxR3PUL0=; b=dr1jvBSpqSBPlfWwot1IL0yG5kCOT3o5ad5i2c0xfiL1tMaju+B9jczkppqk49w5HD 0WHsCXwk22erG9lWy0y8UTiAgLtniozd2SIP9CG89a92alB2NP2k+8MBCoIRJVdtKjnj +OrYlrsRNY+0EdrBY8Q+NrG9M1BnmWC7DZjKhwHH3nxFoQDorIbLqn3Xh7pqn7PdySxY ro780hStWF5485UbHaxLCiiYPnMiwBevAwyX/gocjkqpnd/HGxVYFaVcpeAH96yp4WK5 U8Uon5NrtNG/3yRrU9RCX7fPUSV7APqlckj5+ZwWckGTZ2dmrQf9ITogWq3jCTd4ApI6 Er2g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 17-v6si13699846pgp.289.2018.07.11.06.57.17; Wed, 11 Jul 2018 06:57:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388360AbeGKOBn (ORCPT + 23 others); Wed, 11 Jul 2018 10:01:43 -0400 Received: from foss.arm.com ([217.140.101.70]:36308 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388100AbeGKOBm (ORCPT ); Wed, 11 Jul 2018 10:01:42 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 539E815AD; Wed, 11 Jul 2018 06:57:14 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3A22A3F5B1; Wed, 11 Jul 2018 06:57:12 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 01/21] arm64: consistently use unsigned long for thread flags Date: Wed, 11 Jul 2018 14:56:36 +0100 Message-Id: <20180711135656.20670-2-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In do_notify_resume, we manipulate thread_flags as a 32-bit unsigned int, whereas thread_info::flags is a 64-bit unsigned long, and elsewhere (e.g. in the entry assembly) we manipulate the flags as a 64-bit quantity. For consistency, and to avoid problems if we end up with more than 32 flags, let's make do_notify_resume take the flags as a 64-bit unsigned long. Signed-off-by: Mark Rutland Reviewed-by: Dave Martin Acked-by: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/signal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.11.0 diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 511af13e8d8f..70287634706e 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -910,7 +910,7 @@ static void do_signal(struct pt_regs *regs) } asmlinkage void do_notify_resume(struct pt_regs *regs, - unsigned int thread_flags) + unsigned long thread_flags) { /* * The assembly code enters us with IRQs off, but it hasn't From patchwork Wed Jul 11 13:56:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141741 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp321151ljj; Wed, 11 Jul 2018 06:57:20 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdPs6T3BnMh+pSfiQBxsdYhtv40A7PnPWKiNxONalauh8+yFd4O6Q+7iSgtGukjxbt3i0li X-Received: by 2002:a17:902:c85:: with SMTP id 5-v6mr28983164plt.126.1531317440736; Wed, 11 Jul 2018 06:57:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317440; cv=none; d=google.com; s=arc-20160816; b=0pfcrWG23U1wT07kWK6UZrjW8KXLWlFavs9QO6IOnxgaHo4W59CBat1cManuu2OiZP 9JC0uUl0bx4ri4GYY1XVuTTajZW5q3C09IaHhHE8fNzxK5fF46OpincdSyXVWqiEWeJK P+wvoBJFElZSafMkaX6Wr1UR8ueAy5ISG8lUCJw9mdmUAkd28UZ+yQVrYxJGSpthBf6n jdkJUTYkeXDVtHF8ml7Z1TGynYh6XBHwBo7akrMJmOGFFgn6NNvznpBUKRogSXCxttOC l10H7o/IoO5zkE1nxaig47on04eGbydijXUV8jCiqLG28Yv2oTXxghyM4wx9vfFXsCnT bP+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=YklZ1fidCwq6PTbSL1XFdLvMzw0t21U3xqjybuSMIqk=; b=iUAkup3UqPx3tdfMrAihT43dctDIPGA+w3wbM7BL7MTNNhOtvxgk/16Q9toKsMK1mO QZpul6qR804IhtK6s8LV/SO1AcDxlfDZG0v+rm1oX1rBDPv+9lkhYVmDpVXdiez8UxRn xZwzOt6qMceJsodqbu9hUr0e+pH3ZV2DAnlDJSHdL+e1+ts9YssHcQEmj/28FOS2mur2 MLI//L5byjuLJUSXLhBrlhWI7HsZseBVowGScYNPOa/GviDV1Tij3xeoARE6s65vDt5v nCtExbWUb9qRmf7+20+ij06F06gNi/T4oC0HU0HkR2hfq47k2FB6GTQzriQi2EAdIb5t DRVA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 97-v6si19265843pld.345.2018.07.11.06.57.20; Wed, 11 Jul 2018 06:57:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388374AbeGKOBq (ORCPT + 23 others); Wed, 11 Jul 2018 10:01:46 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:36320 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388100AbeGKOBp (ORCPT ); Wed, 11 Jul 2018 10:01:45 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AA5E11650; Wed, 11 Jul 2018 06:57:17 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 99C1A3F5B1; Wed, 11 Jul 2018 06:57:15 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 02/21] arm64: move SCTLR_EL{1, 2} assertions to Date: Wed, 11 Jul 2018 14:56:37 +0100 Message-Id: <20180711135656.20670-3-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently we assert that the SCTLR_EL{1,2}_{SET,CLEAR} bits are self-consistent with an assertion in config_sctlr_el1(). This is a bit unusual, since config_sctlr_el1() doesn't make use of these definitions, and is far away from the definitions themselves. We can use the CPP #error directive to have equivalent assertions in , next to the definitions of the set/clear bits, which is a bit clearer and simpler. At the same time, lets fill in the upper 32 bits for both registers in their respective RES0 definitions. This could be a little nicer with GENMASK_ULL(63, 32), but this currently lives in , which cannot safely be included from assembly, as can. Note the when the preprocessor evaluates an expression for an #if directive, all signed or unsigned values are treated as intmax_t or uintmax_t respectively. To avoid ambiguity, we define explicitly define the mask of all 64 bits. Signed-off-by: Mark Rutland Acked-by: Catalin Marinas Cc: Dave Martin Cc: James Morse Cc: Will Deacon --- arch/arm64/include/asm/sysreg.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) -- 2.11.0 diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index a8f84812c6e8..fefc17dae8ee 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -436,7 +436,8 @@ #define SCTLR_EL2_RES0 ((1 << 6) | (1 << 7) | (1 << 8) | (1 << 9) | \ (1 << 10) | (1 << 13) | (1 << 14) | (1 << 15) | \ (1 << 17) | (1 << 20) | (1 << 24) | (1 << 26) | \ - (1 << 27) | (1 << 30) | (1 << 31)) + (1 << 27) | (1 << 30) | (1 << 31) | \ + (0xffffffffUL << 32)) #ifdef CONFIG_CPU_BIG_ENDIAN #define ENDIAN_SET_EL2 SCTLR_ELx_EE @@ -452,9 +453,9 @@ SCTLR_ELx_SA | SCTLR_ELx_I | SCTLR_ELx_WXN | \ ENDIAN_CLEAR_EL2 | SCTLR_EL2_RES0) -/* Check all the bits are accounted for */ -#define SCTLR_EL2_BUILD_BUG_ON_MISSING_BITS BUILD_BUG_ON((SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != ~0) - +#if (SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != 0xffffffffffffffff +#error "Inconsistent SCTLR_EL2 set/clear bits" +#endif /* SCTLR_EL1 specific flags. */ #define SCTLR_EL1_UCI (1 << 26) @@ -473,7 +474,8 @@ #define SCTLR_EL1_RES1 ((1 << 11) | (1 << 20) | (1 << 22) | (1 << 28) | \ (1 << 29)) #define SCTLR_EL1_RES0 ((1 << 6) | (1 << 10) | (1 << 13) | (1 << 17) | \ - (1 << 27) | (1 << 30) | (1 << 31)) + (1 << 27) | (1 << 30) | (1 << 31) | \ + (0xffffffffUL << 32)) #ifdef CONFIG_CPU_BIG_ENDIAN #define ENDIAN_SET_EL1 (SCTLR_EL1_E0E | SCTLR_ELx_EE) @@ -492,8 +494,9 @@ SCTLR_EL1_UMA | SCTLR_ELx_WXN | ENDIAN_CLEAR_EL1 |\ SCTLR_EL1_RES0) -/* Check all the bits are accounted for */ -#define SCTLR_EL1_BUILD_BUG_ON_MISSING_BITS BUILD_BUG_ON((SCTLR_EL1_SET ^ SCTLR_EL1_CLEAR) != ~0) +#if (SCTLR_EL1_SET ^ SCTLR_EL1_CLEAR) != 0xffffffffffffffff +#error "Inconsistent SCTLR_EL1 set/clear bits" +#endif /* id_aa64isar0 */ #define ID_AA64ISAR0_TS_SHIFT 52 @@ -743,9 +746,6 @@ static inline void config_sctlr_el1(u32 clear, u32 set) { u32 val; - SCTLR_EL2_BUILD_BUG_ON_MISSING_BITS; - SCTLR_EL1_BUILD_BUG_ON_MISSING_BITS; - val = read_sysreg(sctlr_el1); val &= ~clear; val |= set; From patchwork Wed Jul 11 13:56:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141742 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp321235ljj; Wed, 11 Jul 2018 06:57:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcPKCZMy+0wiClH25FXPMW1yKFiI3oORWInuL9IcJVclTaTUjFL4uc9S351HtUsrBrGGTGQ X-Received: by 2002:a63:67c3:: with SMTP id b186-v6mr26976109pgc.5.1531317444363; Wed, 11 Jul 2018 06:57:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317444; cv=none; d=google.com; s=arc-20160816; b=muhcvQgJt+MWGfQRzQABIcRIpdv1A/x1yZ5/3kYxJzPP85V+zcJFJR/6JRWCmFvVpS epZiHg834B7FREYlTZOJmfHHP7Eo4MMOIzhTKRUlcTU5So6mMVE+QUmdUHByI9dapdLf jk6J/dE9+MPr6lfZWCCyZa6KLIfimOaAHdembIL1SkY0/3SehGfQmk9Pg7EQeSoWjFuz Ifr3Dhs2ELOJTOj073MyJMXFzfUhs3J9/kkogNr4E7FByNYcxFOrsGhhi1i864rzVxJb DMfbJMqtB82YmqIQQBMTZY0rTRUGwpJ9s+dAMrv2J1JQzWvtUZByYaPgp/QEDZw2cEFw G/UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=jm+glYWgfEiukiYGZ04r0ofmwFgtWluAGYLURkdjnH8=; b=CUOjTfWFkN/CdkWCf3lZmIBL3Zzhhe3k56RTnx6Rz0AuC3m62zgluzj5AilLHA0t5g r7Byv1XW14KITj737qYhq60hXLmEySR+7OzNjyjeymy5g+gB2bfuhcF/hSjJLbnHxh2k 8H0j9cpv7IiMg2x8vIIhwYT84o1qySsLc9Hic9yfHONoP/5VDGnB9C9x1zKiLsQFuraP w9x7ihRi7mcYT7s07Pb8fa0id5CXb0R8Ghbge8C7veDvBAlgaZoJSFGvYVlXE4763TEi v3UUx7Qa0n3IhJmt7ND9unTeH5Bn2ookefRpdMLSoj6pNR5knVzx90W+Nwabq+lmDbHk WcBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f7-v6si19857879plt.4.2018.07.11.06.57.24; Wed, 11 Jul 2018 06:57:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388391AbeGKOBt (ORCPT + 23 others); Wed, 11 Jul 2018 10:01:49 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:36330 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388100AbeGKOBs (ORCPT ); Wed, 11 Jul 2018 10:01:48 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7D7BF1688; Wed, 11 Jul 2018 06:57:20 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6CDB93F5B1; Wed, 11 Jul 2018 06:57:18 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 03/21] arm64: kill config_sctlr_el1() Date: Wed, 11 Jul 2018 14:56:38 +0100 Message-Id: <20180711135656.20670-4-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that we have sysreg_clear_set(), we can consistently use this instead of config_sctlr_el1(). Signed-off-by: Mark Rutland Reviewed-by: Dave Martin Acked-by: Catalin Marinas Cc: James Morse Cc: Will Deacon --- arch/arm64/include/asm/sysreg.h | 10 ---------- arch/arm64/kernel/armv8_deprecated.c | 8 ++++---- arch/arm64/kernel/cpu_errata.c | 3 +-- arch/arm64/kernel/traps.c | 2 +- arch/arm64/mm/fault.c | 2 +- 5 files changed, 7 insertions(+), 18 deletions(-) -- 2.11.0 diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index fefc17dae8ee..e205ec8489e9 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -742,16 +742,6 @@ asm( write_sysreg(__scs_new, sysreg); \ } while (0) -static inline void config_sctlr_el1(u32 clear, u32 set) -{ - u32 val; - - val = read_sysreg(sctlr_el1); - val &= ~clear; - val |= set; - write_sysreg(val, sctlr_el1); -} - #endif #endif /* __ASM_SYSREG_H */ diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c index d4707abb2f16..d01c7fc0463c 100644 --- a/arch/arm64/kernel/armv8_deprecated.c +++ b/arch/arm64/kernel/armv8_deprecated.c @@ -511,9 +511,9 @@ static int cp15barrier_handler(struct pt_regs *regs, u32 instr) static int cp15_barrier_set_hw_mode(bool enable) { if (enable) - config_sctlr_el1(0, SCTLR_EL1_CP15BEN); + sysreg_clear_set(sctlr_el1, 0, SCTLR_EL1_CP15BEN); else - config_sctlr_el1(SCTLR_EL1_CP15BEN, 0); + sysreg_clear_set(sctlr_el1, SCTLR_EL1_CP15BEN, 0); return 0; } @@ -548,9 +548,9 @@ static int setend_set_hw_mode(bool enable) return -EINVAL; if (enable) - config_sctlr_el1(SCTLR_EL1_SED, 0); + sysreg_clear_set(sctlr_el1, SCTLR_EL1_SED, 0); else - config_sctlr_el1(0, SCTLR_EL1_SED); + sysreg_clear_set(sctlr_el1, 0, SCTLR_EL1_SED); return 0; } diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 1d2b6d768efe..92128ea53102 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -76,8 +76,7 @@ has_mismatched_cache_line_size(const struct arm64_cpu_capabilities *entry, static void cpu_enable_trap_ctr_access(const struct arm64_cpu_capabilities *__unused) { - /* Clear SCTLR_EL1.UCT */ - config_sctlr_el1(SCTLR_EL1_UCT, 0); + sysreg_clear_set(sctlr_el1, SCTLR_EL1_UCT, 0); } atomic_t arm64_el2_vector_last_slot = ATOMIC_INIT(-1); diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index d399d459397b..c27292703bd1 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -411,7 +411,7 @@ asmlinkage void __exception do_undefinstr(struct pt_regs *regs) void cpu_enable_cache_maint_trap(const struct arm64_cpu_capabilities *__unused) { - config_sctlr_el1(SCTLR_EL1_UCI, 0); + sysreg_clear_set(sctlr_el1, SCTLR_EL1_UCI, 0); } #define __user_cache_maint(insn, address, res) \ diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index b8eecc7b9531..ea591c9e5144 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -879,7 +879,7 @@ void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused) */ WARN_ON_ONCE(in_interrupt()); - config_sctlr_el1(SCTLR_EL1_SPAN, 0); + sysreg_clear_set(sctlr_el1, SCTLR_EL1_SPAN, 0); asm(SET_PSTATE_PAN(1)); } #endif /* CONFIG_ARM64_PAN */ From patchwork Wed Jul 11 13:56:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141743 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp321286ljj; Wed, 11 Jul 2018 06:57:27 -0700 (PDT) X-Google-Smtp-Source: AAOMgpePXPux2viMLLLzl9FnqoimHIjaAnOLYi3ty3F+5dr8w7IuDe0StaM9dPL+Nzh5POWJcHxk X-Received: by 2002:a17:902:1005:: with SMTP id b5-v6mr29221252pla.207.1531317447294; Wed, 11 Jul 2018 06:57:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317447; cv=none; d=google.com; s=arc-20160816; b=UvGHCueCDC9CYP8RtnljK3avopY8vsKjcRI/DLwznSsvBEq7SAqXu2iHM5IEOBvCIA CR+mIKHzsVScHat2BnV6clqgG6kznNQmO2PVFAwajvI1Oz8ZhWXU8VIx9JmbVj6S2H7o sVhnyz7Ts9iD9ji6SM8db1CmQE3LbORklnWb04Gh0Oxs4EsOktGCHmkMvrK15Y6KHH08 mFlb3fwolSrYFK2SfUELfiXtWXeudZKPygYO0GbWQgyWMJblFJakmeFcq7NUrKg2/+Xn 2XgB9M5JcdEe7r+6Gvf9eMRof6U1f/FNEulb7GNeXf1jJKNp9Fsx2d6DL0wdbZkoqbRk SCcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=nbK+er5HgoQSGfo6/Z1b6j32U5iuKiIZThXipRAjitI=; b=yVoRleiDljJS8O5GGLktWBWv+BTu3YaNvYLMQMJBl0B+9uKy1Tbjk8olwjEtVbyWqU wKLSF7NpKfYaOwNCAQ5lUQgrXjAcDF2zqQ2pjRGcehmlvJCNQ5xA4J4zlPjqsyJjEVZw IB+PWW4n14SK741sl8yEYpfiMKzaLjhNdDDoyYY+WPsbi/N3Hbqy7nRVafJUkNTZIVlt bRsEc091DHzOkB2W9OjlfVAehJZcb0gqsPhtXVCQXN046xDqDcKPuY3nnxzw59MZBtzv UG3f9TpNEIFWkIyHJG6eKHMOFMVVc/baqOPvxXDeNH2zzHzmAoR5vmVBm6HBWfZapoae JO6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p91-v6si19053443plb.457.2018.07.11.06.57.27; Wed, 11 Jul 2018 06:57:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388404AbeGKOBw (ORCPT + 23 others); Wed, 11 Jul 2018 10:01:52 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:36346 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388376AbeGKOBv (ORCPT ); Wed, 11 Jul 2018 10:01:51 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4456C16A3; Wed, 11 Jul 2018 06:57:23 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 343533F5B1; Wed, 11 Jul 2018 06:57:21 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 04/21] arm64: kill change_cpacr() Date: Wed, 11 Jul 2018 14:56:39 +0100 Message-Id: <20180711135656.20670-5-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that we have sysreg_clear_set(), we can use this instead of change_cpacr(). Note that the order of the set and clear arguments differs between change_cpacr() and sysreg_clear_set(), so these are flipped as part of the conversion. Also, sve_user_enable() redundantly clears CPACR_EL1_ZEN_EL0EN before setting it; this is removed for clarity. Signed-off-by: Mark Rutland Reviewed-by: Dave Martin Acked-by: Catalin Marinas Cc: James Morse Cc: Will Deacon --- arch/arm64/kernel/fpsimd.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) -- 2.11.0 diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index 84c68b14f1b2..a98a7f96aff1 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -159,23 +159,14 @@ static void sve_free(struct task_struct *task) __sve_free(task); } -static void change_cpacr(u64 val, u64 mask) -{ - u64 cpacr = read_sysreg(CPACR_EL1); - u64 new = (cpacr & ~mask) | val; - - if (new != cpacr) - write_sysreg(new, CPACR_EL1); -} - static void sve_user_disable(void) { - change_cpacr(0, CPACR_EL1_ZEN_EL0EN); + sysreg_clear_set(cpacr_el1, CPACR_EL1_ZEN_EL0EN, 0); } static void sve_user_enable(void) { - change_cpacr(CPACR_EL1_ZEN_EL0EN, CPACR_EL1_ZEN_EL0EN); + sysreg_clear_set(cpacr_el1, 0, CPACR_EL1_ZEN_EL0EN); } /* From patchwork Wed Jul 11 13:56:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141744 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp321353ljj; Wed, 11 Jul 2018 06:57:30 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeNIfd5xyNxcw/M/pK8afWeqQsp+B5SDXwHleRuXu03v1ltbA2TodtDv534EPzNQX/Vv8a5 X-Received: by 2002:a17:902:530a:: with SMTP id b10-v6mr29375576pli.316.1531317450476; Wed, 11 Jul 2018 06:57:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317450; cv=none; d=google.com; s=arc-20160816; b=cDEXG6K6HZYl35xuO1hKOYatZQalBjEWGPM9kp1GDdgJEArYv/u6rxsAncbDs/74aq tIeW/K2k0q0qA802StUXZAAe8V+BOg3oerBdQnN8k9bGdoyuce60aEF+CcVaQSHQqCr4 LnyURVxwnN3w5/XgJGcsOBD+d+/aUePc/Blvwx0Qcq3IFqgc5K81YtHkMZov1dqG5b0z PUxOVFf4M6ROgtYO5JTzyzI8QfiOKohY2puKS5dlTjf8IbZEWDIhcqWMzo5AkQc7jFoY qL5lN4cJ8P6+FoziWQg2wEV4eqyeoIPllIlywOOWh6/5Yk4gurC0tKSbRP+Ncbu4Mw4G S6kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=UiyU8iaUkqT4Z3X/mybfGktVPp2I94YgbXLg2VKEndM=; b=031b1BGj6YEHFt/hLEngGMMzWAlKmhG/BUlNLA6JcNg99dDMxq1O3/JmiFHtOT8Hcb Ssm91kDZ2RoILFYmswq/8GhiqCB0gXXY2xnlBcXipmd0LBguE9nu4vgqy7Erx/+apg2m hy2QD+PYZdK7E7kmybDnt+wHQQpLO3F5pQyt8jTYkXnxFo/w3fYQ2kHiTJmZbyTv3oNq Unrr+sdh0x0HAh+/c/ipxApJuerBNN2QLVozOsD8CHhhPXoUngnnrY/2lhA1kbeJ9oKk AjEOC7G2UJSLx3lzc1hF7PPaVASitnRu93+fShkNKkoRm4cM8d+sjLIKIr7gsMscSuAt ks0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e16-v6si17711792pgv.561.2018.07.11.06.57.30; Wed, 11 Jul 2018 06:57:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388419AbeGKOBz (ORCPT + 23 others); Wed, 11 Jul 2018 10:01:55 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:36356 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388376AbeGKOBy (ORCPT ); Wed, 11 Jul 2018 10:01:54 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 18C591713; Wed, 11 Jul 2018 06:57:26 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 074B23F5B1; Wed, 11 Jul 2018 06:57:23 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 05/21] arm64: move sve_user_{enable, disable} to Date: Wed, 11 Jul 2018 14:56:40 +0100 Message-Id: <20180711135656.20670-6-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In subsequent patches, we'll want to make use of sve_user_enable() and sve_user_disable() outside of kernel/fpsimd.c. Let's move these to where we can make use of them. To avoid ifdeffery in sequences like: if (system_supports_sve() && some_condition) sve_user_disable(); ... empty stubs are provided when support for SVE is not enabled. Note that system_supports_sve() contains as IS_ENABLED(CONFIG_ARM64_SVE), so the sve_user_disable() call should be optimized away entirely when CONFIG_ARM64_SVE is not selected. To ensure that this is the case, the stub definitions contain a BUILD_BUG(), as we do for other stubs for which calls should always be optimized away when the relevant config option is not selected. At the same time, the include list of is sorted while adding . Signed-off-by: Mark Rutland Acked-by: Catalin Marinas Reviewed-by: Dave Martin Cc: Will Deacon --- arch/arm64/include/asm/fpsimd.h | 17 ++++++++++++++++- arch/arm64/kernel/fpsimd.c | 10 ---------- 2 files changed, 16 insertions(+), 11 deletions(-) -- 2.11.0 diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h index fa92747a49c8..dd1ad3950ef5 100644 --- a/arch/arm64/include/asm/fpsimd.h +++ b/arch/arm64/include/asm/fpsimd.h @@ -16,13 +16,15 @@ #ifndef __ASM_FP_H #define __ASM_FP_H -#include #include +#include #include #include +#include #ifndef __ASSEMBLY__ +#include #include #include #include @@ -102,6 +104,16 @@ extern int sve_set_vector_length(struct task_struct *task, extern int sve_set_current_vl(unsigned long arg); extern int sve_get_current_vl(void); +static inline void sve_user_disable(void) +{ + sysreg_clear_set(cpacr_el1, CPACR_EL1_ZEN_EL0EN, 0); +} + +static inline void sve_user_enable(void) +{ + sysreg_clear_set(cpacr_el1, 0, CPACR_EL1_ZEN_EL0EN); +} + /* * Probing and setup functions. * Calls to these functions must be serialised with one another. @@ -128,6 +140,9 @@ static inline int sve_get_current_vl(void) return -EINVAL; } +static inline void sve_user_disable(void) { BUILD_BUG(); } +static inline void sve_user_enable(void) { BUILD_BUG(); } + static inline void sve_init_vq_map(void) { } static inline void sve_update_vq_map(void) { } static inline int sve_verify_vq_map(void) { return 0; } diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index a98a7f96aff1..58c53bc96928 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -159,16 +159,6 @@ static void sve_free(struct task_struct *task) __sve_free(task); } -static void sve_user_disable(void) -{ - sysreg_clear_set(cpacr_el1, CPACR_EL1_ZEN_EL0EN, 0); -} - -static void sve_user_enable(void) -{ - sysreg_clear_set(cpacr_el1, 0, CPACR_EL1_ZEN_EL0EN); -} - /* * TIF_SVE controls whether a task can use SVE without trapping while * in userspace, and also the way a task's FPSIMD/SVE state is stored From patchwork Wed Jul 11 13:56:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141745 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp321397ljj; Wed, 11 Jul 2018 06:57:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpetHy5ceuMXNgw1hdx0i0EPTpVvG9hzJjukPcKe2T+CQGx8n4jYR4/4MOCXuQQvohLuQmZJ X-Received: by 2002:a63:3f05:: with SMTP id m5-v6mr20535970pga.51.1531317452994; Wed, 11 Jul 2018 06:57:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317452; cv=none; d=google.com; s=arc-20160816; b=iEMLRtWMoAPUH8OQU90yfhIwo20OssqAIXVZ1/c3kxES6mtyN2TtVYSJ+TjVUFTn72 WIV04oDLvLAftXuWMPTRNoQevLYj4llmviOkl42ns/2pgw4sOuECra6Q79f6dkrUbgLL GQD3VoWtIgHBKH7ZXhr1gSmAvFbudrXCCMsMhiotl+LGD04U1M8j/RtkeIF5dTyLoZ1u e2RY4bZYubkNiJt82U+Oe3eNEhihue6tftGHTVmCFyusn88NYyd3/PLiWupGqDFlHlfR FYMTLsb5gWSL61XaIC44VjkXsyl6nn6olKjbqDOck9XeJj10El0VV/oooxGdyEnLnN9C 1ZZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=P/hA17uDZ0jhxGSc16p3GXmOP5chsEFVeBaB7SY3WfU=; b=l2pK5bH1keMDlh4+dX/i+rXdcuicrsezHwigQp4Tbe1jtwUitK4QdUzWtZKV149Dgx tenTUErA2xVuJBBVgSFdOQG5NcRfsZaJjNO7Bxpsx02NloADCG89PhJjfObrnqEShOUw PkF7RrLBBfIQkLRI/8e5YUQOolJc/za+MzwsWlOiFjmAeVqRjGp3+LdPPrExTVfSrKyH YFl+oS/IxJaFM0A+SXMaULqGfsXo2y3p0LuJ8PMHOqqf8e8XTI5XohnL+Qv3DmpssX3I k7eRro/rAoGXAR+IFFhO/FdKFfTpaJJeO/k9aiWXYe0EOSoakVwRnR3G3O+y23PwcQjh NsPA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d33-v6si19701735pla.57.2018.07.11.06.57.32; Wed, 11 Jul 2018 06:57:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388435AbeGKOB6 (ORCPT + 23 others); Wed, 11 Jul 2018 10:01:58 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:36362 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388376AbeGKOB5 (ORCPT ); Wed, 11 Jul 2018 10:01:57 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D2AB819BF; Wed, 11 Jul 2018 06:57:28 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C2BF33F5B1; Wed, 11 Jul 2018 06:57:26 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 06/21] arm64: remove sigreturn wrappers Date: Wed, 11 Jul 2018 14:56:41 +0100 Message-Id: <20180711135656.20670-7-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The arm64 sigreturn* syscall handlers are non-standard. Rather than taking a number of user parameters in registers as per the AAPCS, they expect the pt_regs as their sole argument. To make this work, we override the syscall definitions to invoke wrappers written in assembly, which mov the SP into x0, and branch to their respective C functions. On other architectures (such as x86), the sigreturn* functions take no argument and instead use current_pt_regs() to acquire the user registers. This requires less boilerplate code, and allows for other features such as interposing C code in this path. This patch takes the same approach for arm64. Signed-off-by: Mark Rutland Tentatively-reviewed-by: Dave Martin Reviewed-by: Catalin Marinas Cc: Will Deacon --- arch/arm64/include/asm/unistd32.h | 4 ++-- arch/arm64/kernel/entry.S | 8 -------- arch/arm64/kernel/entry32.S | 10 ---------- arch/arm64/kernel/signal.c | 3 ++- arch/arm64/kernel/signal32.c | 6 ++++-- arch/arm64/kernel/sys.c | 3 +-- arch/arm64/kernel/sys32.c | 4 ++-- 7 files changed, 11 insertions(+), 27 deletions(-) -- 2.11.0 diff --git a/arch/arm64/include/asm/unistd32.h b/arch/arm64/include/asm/unistd32.h index ef292160748c..ab95554b1734 100644 --- a/arch/arm64/include/asm/unistd32.h +++ b/arch/arm64/include/asm/unistd32.h @@ -260,7 +260,7 @@ __SYSCALL(117, sys_ni_syscall) #define __NR_fsync 118 __SYSCALL(__NR_fsync, sys_fsync) #define __NR_sigreturn 119 -__SYSCALL(__NR_sigreturn, compat_sys_sigreturn_wrapper) +__SYSCALL(__NR_sigreturn, compat_sys_sigreturn) #define __NR_clone 120 __SYSCALL(__NR_clone, sys_clone) #define __NR_setdomainname 121 @@ -368,7 +368,7 @@ __SYSCALL(__NR_getresgid, sys_getresgid16) #define __NR_prctl 172 __SYSCALL(__NR_prctl, sys_prctl) #define __NR_rt_sigreturn 173 -__SYSCALL(__NR_rt_sigreturn, compat_sys_rt_sigreturn_wrapper) +__SYSCALL(__NR_rt_sigreturn, compat_sys_rt_sigreturn) #define __NR_rt_sigaction 174 __SYSCALL(__NR_rt_sigaction, compat_sys_rt_sigaction) #define __NR_rt_sigprocmask 175 diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 28ad8799406f..62f2876f9c63 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -1138,14 +1138,6 @@ __entry_tramp_data_start: #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ /* - * Special system call wrappers. - */ -ENTRY(sys_rt_sigreturn_wrapper) - mov x0, sp - b sys_rt_sigreturn -ENDPROC(sys_rt_sigreturn_wrapper) - -/* * Register switch for AArch64. The callee-saved registers need to be saved * and restored. On entry: * x0 = previous task_struct (must be preserved across the switch) diff --git a/arch/arm64/kernel/entry32.S b/arch/arm64/kernel/entry32.S index f332d5d1f6b4..f9461696dde4 100644 --- a/arch/arm64/kernel/entry32.S +++ b/arch/arm64/kernel/entry32.S @@ -30,16 +30,6 @@ * System call wrappers for the AArch32 compatibility layer. */ -ENTRY(compat_sys_sigreturn_wrapper) - mov x0, sp - b compat_sys_sigreturn -ENDPROC(compat_sys_sigreturn_wrapper) - -ENTRY(compat_sys_rt_sigreturn_wrapper) - mov x0, sp - b compat_sys_rt_sigreturn -ENDPROC(compat_sys_rt_sigreturn_wrapper) - ENTRY(compat_sys_statfs64_wrapper) mov w3, #84 cmp w1, #88 diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 70287634706e..f03e664f773f 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -539,8 +539,9 @@ static int restore_sigframe(struct pt_regs *regs, return err; } -asmlinkage long sys_rt_sigreturn(struct pt_regs *regs) +asmlinkage long sys_rt_sigreturn(void) { + struct pt_regs *regs = current_pt_regs(); struct rt_sigframe __user *frame; /* Always make any pending restarted system calls return -EINTR */ diff --git a/arch/arm64/kernel/signal32.c b/arch/arm64/kernel/signal32.c index 77b91f478995..cb10588a7cb2 100644 --- a/arch/arm64/kernel/signal32.c +++ b/arch/arm64/kernel/signal32.c @@ -282,8 +282,9 @@ static int compat_restore_sigframe(struct pt_regs *regs, return err; } -asmlinkage int compat_sys_sigreturn(struct pt_regs *regs) +asmlinkage int compat_sys_sigreturn(void) { + struct pt_regs *regs = current_pt_regs(); struct compat_sigframe __user *frame; /* Always make any pending restarted system calls return -EINTR */ @@ -312,8 +313,9 @@ asmlinkage int compat_sys_sigreturn(struct pt_regs *regs) return 0; } -asmlinkage int compat_sys_rt_sigreturn(struct pt_regs *regs) +asmlinkage int compat_sys_rt_sigreturn(void) { + struct pt_regs *regs = current_pt_regs(); struct compat_rt_sigframe __user *frame; /* Always make any pending restarted system calls return -EINTR */ diff --git a/arch/arm64/kernel/sys.c b/arch/arm64/kernel/sys.c index 72981bae10eb..31045f3fed92 100644 --- a/arch/arm64/kernel/sys.c +++ b/arch/arm64/kernel/sys.c @@ -48,8 +48,7 @@ SYSCALL_DEFINE1(arm64_personality, unsigned int, personality) /* * Wrappers to pass the pt_regs argument. */ -asmlinkage long sys_rt_sigreturn_wrapper(void); -#define sys_rt_sigreturn sys_rt_sigreturn_wrapper +asmlinkage long sys_rt_sigreturn(void); #define sys_personality sys_arm64_personality #undef __SYSCALL diff --git a/arch/arm64/kernel/sys32.c b/arch/arm64/kernel/sys32.c index a40b1343b819..1ef103c95410 100644 --- a/arch/arm64/kernel/sys32.c +++ b/arch/arm64/kernel/sys32.c @@ -25,8 +25,8 @@ #include #include -asmlinkage long compat_sys_sigreturn_wrapper(void); -asmlinkage long compat_sys_rt_sigreturn_wrapper(void); +asmlinkage long compat_sys_sigreturn(void); +asmlinkage long compat_sys_rt_sigreturn(void); asmlinkage long compat_sys_statfs64_wrapper(void); asmlinkage long compat_sys_fstatfs64_wrapper(void); asmlinkage long compat_sys_pread64_wrapper(void); From patchwork Wed Jul 11 13:56:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141746 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp321436ljj; Wed, 11 Jul 2018 06:57:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcGNc4vUlKgBQ46krIEhteTZ94yprDlgyHCdPyWdDJAWhzoPLO1z9sfkZhd6+tf9aKUFhTb X-Received: by 2002:a63:ab4c:: with SMTP id k12-v6mr20660000pgp.386.1531317455739; Wed, 11 Jul 2018 06:57:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317455; cv=none; d=google.com; s=arc-20160816; b=bbMnTjiz7uLLHJ5A9UZp6Dybk+GAWrM2Jecr4l3Nbqp94wXZwo2P+0wBBbk2MViujB MMttaVCoDvvYY5LszZJPqZvKlDH4iU7pByoG3hyaUHnz9Qb5SHkTbPr6nNsB3wm2rRL9 rFmDiKEX4mjmbbefmYrvxClt1nP3Hc1DgOOriXAhGlzO9A7lauPfTypj+kPvkHLg5LsA wHbd6BrcAupbKLdwfwV+LmomvgKIL1AGXR/QYA7CLvDjXnOxslkGgkHCndu64PdhTClg SE4A+93WVYh7ZRj/0E7GS+yMQNqrO1TD1Du1y4rNwNiGibXhdtW1KpiXlUIPvsRPeTWR Ub8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=TDyLpZPLXLJayhPCAckYc8F6TMQDiStF7VCf1Hi/Drs=; b=dCkJNtUAezV87Nsjf4Rea0XTmme5zESSot+fig2OML1PnRmXvvMStOkEy0ZXFAbEAk YK3B7CvsvBYYZl2ny2k2ovD1aaFb53BLPOlGXZ/Ei9JSZ3SvX3DwZ2fdUmRAc941OxYt IF7R+RrQek04FnJXIsg1RzNAYzSidAhiRxJgLJt12EUIyj4BFrF71B90tGTqJSwZIfgl HZxfR2vAtIyUoT2dTt5EgYTWvzKK/gNRrnxLYPxyJFwwwfuqquD7ztgXgXznugUUWozz 981uK9Jpt5+3CY+diQ+1fBMB9jaov2Gou7UN0mBypniolpZ47G0wid3nxxmCnb/BwvIU ab1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 62-v6si21092990pfu.79.2018.07.11.06.57.35; Wed, 11 Jul 2018 06:57:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388451AbeGKOCB (ORCPT + 23 others); Wed, 11 Jul 2018 10:02:01 -0400 Received: from foss.arm.com ([217.140.101.70]:36374 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388376AbeGKOB7 (ORCPT ); Wed, 11 Jul 2018 10:01:59 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A279E19F6; Wed, 11 Jul 2018 06:57:31 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 91ECB3F5B1; Wed, 11 Jul 2018 06:57:29 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 07/21] arm64: introduce syscall_fn_t Date: Wed, 11 Jul 2018 14:56:42 +0100 Message-Id: <20180711135656.20670-8-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for invoking arbitrary syscalls from C code, let's define a type for an arbitrary syscall, matching the parameter passing rules of the AAPCS. There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/include/asm/syscall.h | 6 +++++- arch/arm64/kernel/sys.c | 8 +++++--- arch/arm64/kernel/sys32.c | 8 +++++--- 3 files changed, 15 insertions(+), 7 deletions(-) -- 2.11.0 diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index 709a574468f0..50841cb1bfa9 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -20,7 +20,11 @@ #include #include -extern const void *sys_call_table[]; +typedef long (*syscall_fn_t)(unsigned long, unsigned long, + unsigned long, unsigned long, + unsigned long, unsigned long); + +extern const syscall_fn_t sys_call_table[]; static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) diff --git a/arch/arm64/kernel/sys.c b/arch/arm64/kernel/sys.c index 31045f3fed92..7f0907261269 100644 --- a/arch/arm64/kernel/sys.c +++ b/arch/arm64/kernel/sys.c @@ -25,7 +25,9 @@ #include #include #include + #include +#include asmlinkage long sys_mmap(unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags, @@ -52,13 +54,13 @@ asmlinkage long sys_rt_sigreturn(void); #define sys_personality sys_arm64_personality #undef __SYSCALL -#define __SYSCALL(nr, sym) [nr] = sym, +#define __SYSCALL(nr, sym) [nr] = (syscall_fn_t)sym, /* * The sys_call_table array must be 4K aligned to be accessible from * kernel/entry.S. */ -void * const sys_call_table[__NR_syscalls] __aligned(4096) = { - [0 ... __NR_syscalls - 1] = sys_ni_syscall, +const syscall_fn_t sys_call_table[__NR_syscalls] __aligned(4096) = { + [0 ... __NR_syscalls - 1] = (syscall_fn_t)sys_ni_syscall, #include }; diff --git a/arch/arm64/kernel/sys32.c b/arch/arm64/kernel/sys32.c index 1ef103c95410..d993214118aa 100644 --- a/arch/arm64/kernel/sys32.c +++ b/arch/arm64/kernel/sys32.c @@ -25,6 +25,8 @@ #include #include +#include + asmlinkage long compat_sys_sigreturn(void); asmlinkage long compat_sys_rt_sigreturn(void); asmlinkage long compat_sys_statfs64_wrapper(void); @@ -40,13 +42,13 @@ asmlinkage long compat_sys_fallocate_wrapper(void); asmlinkage long compat_sys_mmap2_wrapper(void); #undef __SYSCALL -#define __SYSCALL(nr, sym) [nr] = sym, +#define __SYSCALL(nr, sym) [nr] = (syscall_fn_t)sym, /* * The sys_call_table array must be 4K aligned to be accessible from * kernel/entry.S. */ -void * const compat_sys_call_table[__NR_compat_syscalls] __aligned(4096) = { - [0 ... __NR_compat_syscalls - 1] = sys_ni_syscall, +const syscall_fn_t compat_sys_call_table[__NR_compat_syscalls] __aligned(4096) = { + [0 ... __NR_compat_syscalls - 1] = (syscall_fn_t)sys_ni_syscall, #include }; From patchwork Wed Jul 11 13:56:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141747 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp321488ljj; Wed, 11 Jul 2018 06:57:39 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeZ22UqfXrgoIv9fF+7ez2c00dQ0xeeXfJEMerVZIjaZqCRXoOt/FKFfylT0oLa9PnERpkW X-Received: by 2002:a17:902:b401:: with SMTP id x1-v6mr7017150plr.236.1531317458885; Wed, 11 Jul 2018 06:57:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317458; cv=none; d=google.com; s=arc-20160816; b=yLFvU75v/X2CgXKpdL8wJQDhxmb6GROrK/jxKjZqH0b/0MU7Z6yoPcM72hx0Ah2IRu TIwKOeuy1+0IMGQ0IH9FI7P3LtQzwTCaJacY3fWZjtDAOsKUJOxW0j9X6vyCcA6nL5Ou rq3gZCLsWAd86axf5BAQ2bpsGAfYRlKoO1kk2Yq7p6IzSOcws5uNStkDfT0QXdFo4LUj oC+pFoGxgRZyIi7YK2E2hRr1sMswe88Bhquu45OVSAz9Dr4slvJUrxqO9Bmd18MBm7uw ncNi3XZiMnFmWWEwnm32/WYuZKe1N6bGqP077822FxipcerxwqGWXyCMlt9h3CVLcDZX Tr8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=WR8/6GYJ5ZiB9tKl+UzZx4nKpU2vxxBOEXQH8R0shQ8=; b=iBLiy2CInzIUJIY8gspZws0ILNawEzF2lQ79HPmvk7d5zUJjJHronB2zmVEA86gddq QL36YOnsh926K2jVXN5vsO4Uqncw+pXbhxHOZcyHdOLkEnAn1xS4gmvb2v7g3C0e0+GN HFYBTIuf+tk0M9iWppAV8GP12k4KwDgX9KId5rcBX1Gk4UX1hLZUE63yYDdJWrGdfNWO GwQnh4lEDQhLAvFEvlvj682FR5+dqbcToVG6yVDPr7FiUmU6kQ7NKz57iZFOWMtScTRA psprVvwvVPVUftK4E1INk3b5Yzx0eYvT4RZ4NJSv9bpjyrYjDc6ZpohtQo1j9N+pjflq JNmw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e125-v6si4454190pgc.424.2018.07.11.06.57.38; Wed, 11 Jul 2018 06:57:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388467AbeGKOCE (ORCPT + 23 others); Wed, 11 Jul 2018 10:02:04 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:36380 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388376AbeGKOCC (ORCPT ); Wed, 11 Jul 2018 10:02:02 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A80511AC1; Wed, 11 Jul 2018 06:57:34 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 97D763F5B1; Wed, 11 Jul 2018 06:57:32 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 08/21] arm64: convert raw syscall invocation to C Date: Wed, 11 Jul 2018 14:56:43 +0100 Message-Id: <20180711135656.20670-9-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As a first step towards invoking syscalls with a pt_regs argument, convert the raw syscall invocation logic to C. We end up with a bit more register shuffling, but the unified invocation logic means we can unify the tracing paths, too. Previously, assembly had to open-code calls to ni_sys() when the system call number was out-of-bounds for the relevant syscall table. This case is now handled by invoke_syscall(), and the assembly no longer need to handle this case explicitly. This allows the tracing paths to be simplified and unified, as we no longer need the __ni_sys_trace path and the __sys_trace_return label. This only converts the invocation of the syscall. The rest of the syscall triage and tracing is left in assembly for now, and will be converted in subsequent patches. Signed-off-by: Mark Rutland Reviewed-by: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/Makefile | 3 ++- arch/arm64/kernel/entry.S | 36 ++++++++++------------------------ arch/arm64/kernel/syscall.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/traps.c | 16 --------------- 4 files changed, 59 insertions(+), 43 deletions(-) create mode 100644 arch/arm64/kernel/syscall.c -- 2.11.0 diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 0025f8691046..4e24d2244bd1 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -18,7 +18,8 @@ arm64-obj-y := debug-monitors.o entry.o irq.o fpsimd.o \ hyp-stub.o psci.o cpu_ops.o insn.o \ return_address.o cpuinfo.o cpu_errata.o \ cpufeature.o alternative.o cacheinfo.o \ - smp.o smp_spin_table.o topology.o smccc-call.o + smp.o smp_spin_table.o topology.o smccc-call.o \ + syscall.o extra-$(CONFIG_EFI) := efi-entry.o diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 62f2876f9c63..c0392f78e392 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -903,7 +903,6 @@ ENDPROC(el0_error) */ ret_fast_syscall: disable_daif - str x0, [sp, #S_X0] // returned x0 ldr x1, [tsk, #TSK_TI_FLAGS] // re-check for syscall tracing and x2, x1, #_TIF_SYSCALL_WORK cbnz x2, ret_fast_syscall_trace @@ -976,15 +975,11 @@ el0_svc_naked: // compat entry point tst x16, #_TIF_SYSCALL_WORK // check for syscall hooks b.ne __sys_trace - cmp wscno, wsc_nr // check upper syscall limit - b.hs ni_sys - mask_nospec64 xscno, xsc_nr, x19 // enforce bounds for syscall number - ldr x16, [stbl, xscno, lsl #3] // address in the syscall table - blr x16 // call sys_* routine - b ret_fast_syscall -ni_sys: mov x0, sp - bl do_ni_syscall + mov w1, wscno + mov w2, wsc_nr + mov x3, stbl + bl invoke_syscall b ret_fast_syscall ENDPROC(el0_svc) @@ -1001,29 +996,18 @@ __sys_trace: bl syscall_trace_enter cmp w0, #NO_SYSCALL // skip the syscall? b.eq __sys_trace_return_skipped - mov wscno, w0 // syscall number (possibly new) - mov x1, sp // pointer to regs - cmp wscno, wsc_nr // check upper syscall limit - b.hs __ni_sys_trace - ldp x0, x1, [sp] // restore the syscall args - ldp x2, x3, [sp, #S_X2] - ldp x4, x5, [sp, #S_X4] - ldp x6, x7, [sp, #S_X6] - ldr x16, [stbl, xscno, lsl #3] // address in the syscall table - blr x16 // call sys_* routine -__sys_trace_return: - str x0, [sp, #S_X0] // save returned x0 + mov x0, sp + mov w1, wscno + mov w2, wsc_nr + mov x3, stbl + bl invoke_syscall + __sys_trace_return_skipped: mov x0, sp bl syscall_trace_exit b ret_to_user -__ni_sys_trace: - mov x0, sp - bl do_ni_syscall - b __sys_trace_return - .popsection // .entry.text #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c new file mode 100644 index 000000000000..93d36f22647e --- /dev/null +++ b/arch/arm64/kernel/syscall.c @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include + +#include + +long compat_arm_syscall(struct pt_regs *regs); + +asmlinkage long do_ni_syscall(struct pt_regs *regs) +{ +#ifdef CONFIG_COMPAT + long ret; + if (is_compat_task()) { + ret = compat_arm_syscall(regs); + if (ret != -ENOSYS) + return ret; + } +#endif + + return sys_ni_syscall(); +} + +static long __invoke_syscall(struct pt_regs *regs, syscall_fn_t syscall_fn) +{ + return syscall_fn(regs->regs[0], regs->regs[1], regs->regs[2], + regs->regs[3], regs->regs[4], regs->regs[5]); +} + +asmlinkage void invoke_syscall(struct pt_regs *regs, unsigned int scno, + unsigned int sc_nr, + const syscall_fn_t syscall_table[]) +{ + long ret; + + if (scno < sc_nr) { + syscall_fn_t syscall_fn; + syscall_fn = syscall_table[array_index_nospec(scno, sc_nr)]; + ret = __invoke_syscall(regs, syscall_fn); + } else { + ret = do_ni_syscall(regs); + } + + regs->regs[0] = ret; +} diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index c27292703bd1..039e9ff379cc 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -547,22 +547,6 @@ asmlinkage void __exception do_sysinstr(unsigned int esr, struct pt_regs *regs) do_undefinstr(regs); } -long compat_arm_syscall(struct pt_regs *regs); - -asmlinkage long do_ni_syscall(struct pt_regs *regs) -{ -#ifdef CONFIG_COMPAT - long ret; - if (is_compat_task()) { - ret = compat_arm_syscall(regs); - if (ret != -ENOSYS) - return ret; - } -#endif - - return sys_ni_syscall(); -} - static const char *esr_class_str[] = { [0 ... ESR_ELx_EC_MAX] = "UNRECOGNIZED EC", [ESR_ELx_EC_UNKNOWN] = "Unknown/Uncategorized", From patchwork Wed Jul 11 13:56:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141748 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp321562ljj; Wed, 11 Jul 2018 06:57:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeIs4PdAzC8+lAWKkn8UwXHu2Lg+53SfZvmJ7QSp++7ssRy9hGx8c23Q5xrKGA8WSVTAXXZ X-Received: by 2002:a63:8341:: with SMTP id h62-v6mr26072833pge.298.1531317462614; Wed, 11 Jul 2018 06:57:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317462; cv=none; d=google.com; s=arc-20160816; b=l99VM1yi7W7w+NgOLuI7w3Dn0eIvxxjXnUEvzBQVkSwChbMA6cF0rQj9U4e7OwIDcY pwcEu1T3QU6ACpqf4A6u8/iWyVDWbQcroIP6wjjtW/PvswQKatzlaMxpKOWPf+pygkIH 094LHchSibfqUDHkRnypm+579ZtLyDSTN8sseN1RsSdpcOqHGwxeLIDHOOrmI3BV2MQW fOJrRBy10rDuElcC6ejChsOh5LVXZVLSX/EfBwCXLUMBlLLB20damkhH2GW/hCcdz+mS by+uCMJ+MRu3tR2LitRfQkU+iSDiUqn4ENTNDHHSKlwxddq2JPzR1GPysgSw2YSFuOGD M4GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=qH0okJ6e3H9p0gJ4tzgFpNKQZHLyDPyaFTZzWT6sXhE=; b=MRPLS7XsHcIam93cQaZ9OJEhToQqomnNcRwhTe39xGkG7KBYylnqg26+G+iVveRB87 mj5WVpGsuAC7W4Ya4fzeFAFk7D+WuR3FD3LTLl0LVuBoM3DiB68bveqhTSIUok9W5iCq lW06ccoRFUgHMnCmuRvErWF952rUhcUXAoa222tkrsBU+FSoZsWq/gx7xciMwF25AP+W KxXwpf+sAhm5uusfMK1MzJKgtlnHDxp9YITVnrnt86HsaABGUkoXU7m62aZu7Ypl6pJj vOUuaK8YEHHzCv42DKX4OJy37x5AYk26H7E94tEG3MnhF1Uot02YFzatBiOYW0CQrwKi nnSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b4-v6si17999667pgc.654.2018.07.11.06.57.42; Wed, 11 Jul 2018 06:57:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388482AbeGKOCI (ORCPT + 23 others); Wed, 11 Jul 2018 10:02:08 -0400 Received: from foss.arm.com ([217.140.101.70]:36390 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388376AbeGKOCG (ORCPT ); Wed, 11 Jul 2018 10:02:06 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C25A11BA8; Wed, 11 Jul 2018 06:57:37 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B13353F5B1; Wed, 11 Jul 2018 06:57:35 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 09/21] arm64: convert syscall trace logic to C Date: Wed, 11 Jul 2018 14:56:44 +0100 Message-Id: <20180711135656.20670-10-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently syscall tracing is a tricky assembly state machine, which can be rather difficult to follow, and even harder to modify. Before we start fiddling with it for pt_regs syscalls, let's convert it to C. This is not intended to have any functional change. Signed-off-by: Mark Rutland Reviewed-by: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/entry.S | 53 ++--------------------------------------- arch/arm64/kernel/syscall.c | 57 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 54 deletions(-) -- 2.11.0 diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index c0392f78e392..05b9f03f3e00 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -896,24 +896,6 @@ el0_error_naked: b ret_to_user ENDPROC(el0_error) - -/* - * This is the fast syscall return path. We do as little as possible here, - * and this includes saving x0 back into the kernel stack. - */ -ret_fast_syscall: - disable_daif - ldr x1, [tsk, #TSK_TI_FLAGS] // re-check for syscall tracing - and x2, x1, #_TIF_SYSCALL_WORK - cbnz x2, ret_fast_syscall_trace - and x2, x1, #_TIF_WORK_MASK - cbnz x2, work_pending - enable_step_tsk x1, x2 - kernel_exit 0 -ret_fast_syscall_trace: - enable_daif - b __sys_trace_return_skipped // we already saved x0 - /* * Ok, we need to do extra processing, enter the slow path. */ @@ -969,44 +951,13 @@ alternative_else_nop_endif #endif el0_svc_naked: // compat entry point - stp x0, xscno, [sp, #S_ORIG_X0] // save the original x0 and syscall number - enable_daif - ct_user_exit 1 - - tst x16, #_TIF_SYSCALL_WORK // check for syscall hooks - b.ne __sys_trace mov x0, sp mov w1, wscno mov w2, wsc_nr mov x3, stbl - bl invoke_syscall - b ret_fast_syscall -ENDPROC(el0_svc) - - /* - * This is the really slow path. We're going to be doing context - * switches, and waiting for our parent to respond. - */ -__sys_trace: - cmp wscno, #NO_SYSCALL // user-issued syscall(-1)? - b.ne 1f - mov x0, #-ENOSYS // set default errno if so - str x0, [sp, #S_X0] -1: mov x0, sp - bl syscall_trace_enter - cmp w0, #NO_SYSCALL // skip the syscall? - b.eq __sys_trace_return_skipped - - mov x0, sp - mov w1, wscno - mov w2, wsc_nr - mov x3, stbl - bl invoke_syscall - -__sys_trace_return_skipped: - mov x0, sp - bl syscall_trace_exit + bl el0_svc_common b ret_to_user +ENDPROC(el0_svc) .popsection // .entry.text diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index 93d36f22647e..3e1df8ca1e79 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -1,11 +1,15 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include #include #include #include #include +#include #include +#include long compat_arm_syscall(struct pt_regs *regs); @@ -29,9 +33,9 @@ static long __invoke_syscall(struct pt_regs *regs, syscall_fn_t syscall_fn) regs->regs[3], regs->regs[4], regs->regs[5]); } -asmlinkage void invoke_syscall(struct pt_regs *regs, unsigned int scno, - unsigned int sc_nr, - const syscall_fn_t syscall_table[]) +static void invoke_syscall(struct pt_regs *regs, unsigned int scno, + unsigned int sc_nr, + const syscall_fn_t syscall_table[]) { long ret; @@ -45,3 +49,50 @@ asmlinkage void invoke_syscall(struct pt_regs *regs, unsigned int scno, regs->regs[0] = ret; } + +static inline bool has_syscall_work(unsigned long flags) +{ + return unlikely(flags & _TIF_SYSCALL_WORK); +} + +int syscall_trace_enter(struct pt_regs *regs); +void syscall_trace_exit(struct pt_regs *regs); + +asmlinkage void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, + const syscall_fn_t syscall_table[]) +{ + unsigned long flags = current_thread_info()->flags; + + regs->orig_x0 = regs->regs[0]; + regs->syscallno = scno; + + local_daif_restore(DAIF_PROCCTX); + user_exit(); + + if (has_syscall_work(flags)) { + /* set default errno for user-issued syscall(-1) */ + if (scno == NO_SYSCALL) + regs->regs[0] = -ENOSYS; + scno = syscall_trace_enter(regs); + if (scno == NO_SYSCALL) + goto trace_exit; + } + + invoke_syscall(regs, scno, sc_nr, syscall_table); + + /* + * The tracing status may have changed under our feet, so we have to + * check again. However, if we were tracing entry, then we always trace + * exit regardless, as the old entry assembly did. + */ + if (!has_syscall_work(flags)) { + local_daif_mask(); + flags = current_thread_info()->flags; + if (!has_syscall_work(flags)) + return; + local_daif_restore(DAIF_PROCCTX); + } + +trace_exit: + syscall_trace_exit(regs); +} From patchwork Wed Jul 11 13:56:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141749 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp321629ljj; Wed, 11 Jul 2018 06:57:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdrVG//PTs4YKSMHlRoATd9d7mzZqCpr8trt7BHLmhB3f4bdd4c+sxbqDnPorNd1X1kuc8c X-Received: by 2002:a65:4888:: with SMTP id n8-v6mr27210101pgs.149.1531317466705; Wed, 11 Jul 2018 06:57:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317466; cv=none; d=google.com; s=arc-20160816; b=u4RO4ss9sNDCWLdiUStfqGW5d/JAZuhpfLp8jxRnTRItReqyFo6ZwexCfUv0x5LNb7 3Cctq1+dXFad6z5MdMlRU/TVMSLCoWUrlBqCJlystvFzbmLbTMvvLNTStMxxBy/3h2lV rDNBo3JQpG0bfktuh6o3IOW0u2wt6a9ISfKStbTQMicCvqzR3t1oDi2+re6IgIXv5GtG 4Wh8+ML37n7iloFpCkhbDq9xpPH8P+Z+ld2a4msu6Dxb8evvhLClkAVZvZ3JukvcRlzz tmkz4n1aDxouzkOd3acoklmT4LjT3Qrc3tP64UMSpqB1FBP907eHlLH9GlSMGpEGGLwh xjlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=iqDBGQvIfM25QE/x+62w3uJ8nhHrhMpkYUDuqJglmbk=; b=cOQuNjPLxKYf6MWE/OoktssUH9QDi9UWxBP5rJYqZLAOX2t19D/fTag2LbI7sIF4TE Ph9oVDSKYedcVkUqczrWLEsoiYYAtqa2ibeWeV4wvu753DmwyP9olJYLz3mxI1j7zQZy uolqVx/qNhYS9GqNKNA3lnwYg3t+0TfjF3kam/cYU99uAm3x0OCvxa7ydH/+t6uqxEtQ ZaG1/bnyB1KMn39yIHiV87P2Awm9gR/G5Q71XEKel+kFTOeH8NJCQ2D4HP4CfdeVVDdU ZPvCcj7p+4cCIWfOtzai4y0414SY6F+rrUEFHDEggIaEdF4k3W8EcJKZbwkbct46TpHd /gew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t62-v6si11897404pgd.485.2018.07.11.06.57.46; Wed, 11 Jul 2018 06:57:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388509AbeGKOCM (ORCPT + 23 others); Wed, 11 Jul 2018 10:02:12 -0400 Received: from foss.arm.com ([217.140.101.70]:36396 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388274AbeGKOCJ (ORCPT ); Wed, 11 Jul 2018 10:02:09 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 30AFF1BB0; Wed, 11 Jul 2018 06:57:41 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 20A1D3F5B1; Wed, 11 Jul 2018 06:57:38 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 10/21] arm64: convert native/compat syscall entry to C Date: Wed, 11 Jul 2018 14:56:45 +0100 Message-Id: <20180711135656.20670-11-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that the syscall invocation logic is in C, we can migrate the rest of the syscall entry logic over, so that the entry assembly needn't look at the register values at all. The SVE reset across syscall logic now unconditionally clears TIF_SVE, but sve_user_disable() will only write back to CPACR_EL1 when SVE is actually enabled. Signed-off-by: Mark Rutland Reviewed-by: Catalin Marinas Reviewed-by: Dave Martin Cc: Will Deacon --- arch/arm64/include/asm/syscall.h | 4 ++++ arch/arm64/kernel/entry.S | 42 ++++------------------------------------ arch/arm64/kernel/syscall.c | 37 +++++++++++++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 40 deletions(-) -- 2.11.0 diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index 50841cb1bfa9..b83d0e6980a3 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -26,6 +26,10 @@ typedef long (*syscall_fn_t)(unsigned long, unsigned long, extern const syscall_fn_t sys_call_table[]; +#ifdef CONFIG_COMPAT +extern const syscall_fn_t compat_sys_call_table[]; +#endif + static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) { diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 05b9f03f3e00..156c4e3fd1a4 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -720,14 +720,9 @@ el0_sync_compat: b.ge el0_dbg b el0_inv el0_svc_compat: - /* - * AArch32 syscall handling - */ - ldr x16, [tsk, #TSK_TI_FLAGS] // load thread flags - adrp stbl, compat_sys_call_table // load compat syscall table pointer - mov wscno, w7 // syscall number in w7 (r7) - mov wsc_nr, #__NR_compat_syscalls - b el0_svc_naked + mov x0, sp + bl el0_svc_compat_handler + b ret_to_user .align 6 el0_irq_compat: @@ -925,37 +920,8 @@ ENDPROC(ret_to_user) */ .align 6 el0_svc: - ldr x16, [tsk, #TSK_TI_FLAGS] // load thread flags - adrp stbl, sys_call_table // load syscall table pointer - mov wscno, w8 // syscall number in w8 - mov wsc_nr, #__NR_syscalls - -#ifdef CONFIG_ARM64_SVE -alternative_if_not ARM64_SVE - b el0_svc_naked -alternative_else_nop_endif - tbz x16, #TIF_SVE, el0_svc_naked // Skip unless TIF_SVE set: - bic x16, x16, #_TIF_SVE // discard SVE state - str x16, [tsk, #TSK_TI_FLAGS] - - /* - * task_fpsimd_load() won't be called to update CPACR_EL1 in - * ret_to_user unless TIF_FOREIGN_FPSTATE is still set, which only - * happens if a context switch or kernel_neon_begin() or context - * modification (sigreturn, ptrace) intervenes. - * So, ensure that CPACR_EL1 is already correct for the fast-path case: - */ - mrs x9, cpacr_el1 - bic x9, x9, #CPACR_EL1_ZEN_EL0EN // disable SVE for el0 - msr cpacr_el1, x9 // synchronised by eret to el0 -#endif - -el0_svc_naked: // compat entry point mov x0, sp - mov w1, wscno - mov w2, wsc_nr - mov x3, stbl - bl el0_svc_common + bl el0_svc_handler b ret_to_user ENDPROC(el0_svc) diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index 3e1df8ca1e79..d1c66e6bd359 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -8,8 +8,10 @@ #include #include +#include #include #include +#include long compat_arm_syscall(struct pt_regs *regs); @@ -58,8 +60,8 @@ static inline bool has_syscall_work(unsigned long flags) int syscall_trace_enter(struct pt_regs *regs); void syscall_trace_exit(struct pt_regs *regs); -asmlinkage void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, - const syscall_fn_t syscall_table[]) +static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, + const syscall_fn_t syscall_table[]) { unsigned long flags = current_thread_info()->flags; @@ -96,3 +98,34 @@ asmlinkage void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, trace_exit: syscall_trace_exit(regs); } + +static inline void sve_user_discard(void) +{ + if (!system_supports_sve()) + return; + + clear_thread_flag(TIF_SVE); + + /* + * task_fpsimd_load() won't be called to update CPACR_EL1 in + * ret_to_user unless TIF_FOREIGN_FPSTATE is still set, which only + * happens if a context switch or kernel_neon_begin() or context + * modification (sigreturn, ptrace) intervenes. + * So, ensure that CPACR_EL1 is already correct for the fast-path case. + */ + sve_user_disable(); +} + +asmlinkage void el0_svc_handler(struct pt_regs *regs) +{ + sve_user_discard(); + el0_svc_common(regs, regs->regs[8], __NR_syscalls, sys_call_table); +} + +#ifdef CONFIG_COMPAT +asmlinkage void el0_svc_compat_handler(struct pt_regs *regs) +{ + el0_svc_common(regs, regs->regs[7], __NR_compat_syscalls, + compat_sys_call_table); +} +#endif From patchwork Wed Jul 11 13:56:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141760 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp322678ljj; Wed, 11 Jul 2018 06:58:54 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdUyEFrP8+P7eb8XeQAa2sOlROYHMmIzW77+KCdD7wBzqn2f4QVp37QAi3ztOLovQribbG0 X-Received: by 2002:a63:5055:: with SMTP id q21-v6mr21366265pgl.397.1531317534330; Wed, 11 Jul 2018 06:58:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317534; cv=none; d=google.com; s=arc-20160816; b=ldkoW5J3c2auhp1NXytqCw8FAa6Q50E1GQXV3hG1nubWObr6wPZC+B+ej/pLaKnDh3 y6ZUL6salsZfQxgf2TXGv53wqNR6w5HaYJrGLXyFXbbvmXWD2F4Pp60d+leZRqMvKxwT kxTKnDCnfzL18ZpSTSTcoVDzNivtCH/zNTeRdf/aMkc4EnPVzOjw8fPJAn/9Oua5dPkh wVSAWNgemIUlB/sE7Z9aSj9FvlSM115CNHoYimlx0oN5Luy1hWbyV/l3Qv8sR8luoZjx +7Yqz1u51FQTQboPxfSr9wCUC+2yO/Wo58J93IALENz/IPMrpDDR+MeEXeBaESwIA3XH y1rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=zNbjAjnrOAp96HEwYnANsdAn3on7A0B2numUzNw1UI8=; b=m/aTDrTdRsay2KirFq8Q5ImtgRxvV+4HZf+DVEQofErjgtAs8JaBzpS7czGCxWQkqu r3IwMZOmlVmxtRg3dJkHYnlLS4TcJAzOPjSrrxgMBia6l0zZO0hL8vNVcSDCPnxeMK/K Su5Rk3A/NiCKHJ+m0o01A80YExfEefHHIpiyjXxHE9a8WVZ60zgHICfuJvJmsV6Ty3K1 Gxxuw7NaUr8vPqKkloBlbui6zWTyyWTdeS4jjTwyJuin+vuKT2JU6w9vTs7gv7wrH8Bf PDCOHlzgCj3T2ZoZP4uMfOMf9UWLNV3CPEqTDrheSMzD+DlgiUhakzf2H03d7GLO+O5T Sw6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s84-v6si20304623pfd.288.2018.07.11.06.58.54; Wed, 11 Jul 2018 06:58:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388496AbeGKOCM (ORCPT + 23 others); Wed, 11 Jul 2018 10:02:12 -0400 Received: from foss.arm.com ([217.140.101.70]:36408 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388287AbeGKOCL (ORCPT ); Wed, 11 Jul 2018 10:02:11 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 057B51BC0; Wed, 11 Jul 2018 06:57:44 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E00783F5B1; Wed, 11 Jul 2018 06:57:41 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 11/21] arm64: don't restore GPRs when context tracking Date: Wed, 11 Jul 2018 14:56:46 +0100 Message-Id: <20180711135656.20670-12-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that syscalls are invoked with pt_regs, we no longer need to ensure that the argument regsiters are live in the entry assembly, and it's fine to not restore them after context_tracking_user_exit() has corrupted them. Signed-off-by: Mark Rutland Acked-by: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/entry.S | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) -- 2.11.0 diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 156c4e3fd1a4..c41b84d06644 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -41,19 +41,9 @@ * Context tracking subsystem. Used to instrument transitions * between user and kernel mode. */ - .macro ct_user_exit, syscall = 0 + .macro ct_user_exit #ifdef CONFIG_CONTEXT_TRACKING bl context_tracking_user_exit - .if \syscall == 1 - /* - * Save/restore needed during syscalls. Restore syscall arguments from - * the values already saved on stack during kernel_entry. - */ - ldp x0, x1, [sp] - ldp x2, x3, [sp, #S_X2] - ldp x4, x5, [sp, #S_X4] - ldp x6, x7, [sp, #S_X6] - .endif #endif .endm From patchwork Wed Jul 11 13:56:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141750 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp321710ljj; Wed, 11 Jul 2018 06:57:51 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcIIHg5oXHhjg+vk7Ixtqp8pz46ZxEGGP4bdldcCHTo33pk5thr+ZJfox20N4XUFGpWEW55 X-Received: by 2002:a63:f:: with SMTP id 15-v6mr20642015pga.430.1531317471144; Wed, 11 Jul 2018 06:57:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317471; cv=none; d=google.com; s=arc-20160816; b=WO2CYukU5Fkn0iF/ITc0xO92x/kKMTu4CkOV7rEOJ6xkmrjplMpDXF37sGI/eBqfdH vsF1cO/LKCWeLYcVLNU31JAWMwfBS71QLtvrIotykJExYPDgEAOqPEz5jqgbdO3/JegC zhSut3AT/OCeek00rDTIGE1LN00cNEB/1Xk5x/S/SGsy/bT60xfeueVI3ptGtmEoH4Tb tleLiCIVGtaHmc+29zUyh7/RbjGVnceHDbapZBWcXaVrwZ1Ox9g44kGjmZ8iaph52cF+ f8cLQ94xyjO4cNLSrPtMW0zl6d7SIfmhEktLaR+yWKutkrjMvjLgZidBfCIugKOw34ym HRYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=fP45ynOLSmMbZmSqYsXJEGfZGarwNPjFIW5eM4+kWVA=; b=i5YhVrikYx14Byiwu3SPX8dXiRqxOEePyWX1SHaE9NYnzXpHMORwfgUpBT05xP5tjV zHYPFLBhFDGA6uoPYTa/PYtwD0Or71/X5aLD6aIH0+9DukOPa9CpJcw7u/uhTsGoN7KZ ddfZP/aeDo/OxrX57huJ08O6lWkWGJWQPUTVnbOpsNwIFckeVjiPCAa4B5X829Vk66P2 q2yxXWpXtfbO92Z0sOOjBxvlAeIblWc6mIx2ysk6KD8FvSP0EAnOdjmoR4pJS3IsFnIr oO/Ri2mIoZDDCEYfXWYuSav2x3AEaEnD1IWk/y4w+0zipFtR2WznsWKKHuOq9OmApsZh aeSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 92-v6si18680531pli.518.2018.07.11.06.57.50; Wed, 11 Jul 2018 06:57:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388521AbeGKOCQ (ORCPT + 23 others); Wed, 11 Jul 2018 10:02:16 -0400 Received: from foss.arm.com ([217.140.101.70]:36418 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388274AbeGKOCQ (ORCPT ); Wed, 11 Jul 2018 10:02:16 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2740C1BF7; Wed, 11 Jul 2018 06:57:48 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 16E0C3F5B1; Wed, 11 Jul 2018 06:57:45 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 12/21] arm64: don't reload GPRs after apply_ssbd Date: Wed, 11 Jul 2018 14:56:47 +0100 Message-Id: <20180711135656.20670-13-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that all of the syscall logic works on the saved pt_regs, apply_ssbd can safely corrupt x0-x3 in the entry paths, and we no longer need to restore them. So let's remove the logic doing so. With that logic gone, we can fold the branch target into the macro, so that callers need not deal with this. GAS provides \@, which provides a unique value per macro invocation, which we can use to create a unique label. Signed-off-by: Mark Rutland Acked-by: Marc Zyngier Acked-by: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/entry.S | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) -- 2.11.0 diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index c41b84d06644..22b240da949b 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -130,20 +130,21 @@ alternative_else_nop_endif // This macro corrupts x0-x3. It is the caller's duty // to save/restore them if required. - .macro apply_ssbd, state, targ, tmp1, tmp2 + .macro apply_ssbd, state, tmp1, tmp2 #ifdef CONFIG_ARM64_SSBD alternative_cb arm64_enable_wa2_handling - b \targ + b .L__asm_ssbd_skip\@ alternative_cb_end ldr_this_cpu \tmp2, arm64_ssbd_callback_required, \tmp1 - cbz \tmp2, \targ + cbz \tmp2, .L__asm_ssbd_skip\@ ldr \tmp2, [tsk, #TSK_TI_FLAGS] - tbnz \tmp2, #TIF_SSBD, \targ + tbnz \tmp2, #TIF_SSBD, .L__asm_ssbd_skip\@ mov w0, #ARM_SMCCC_ARCH_WORKAROUND_2 mov w1, #\state alternative_cb arm64_update_smccc_conduit nop // Patched to SMC/HVC #0 alternative_cb_end +.L__asm_ssbd_skip\@: #endif .endm @@ -173,13 +174,7 @@ alternative_cb_end ldr x19, [tsk, #TSK_TI_FLAGS] // since we can unmask debug disable_step_tsk x19, x20 // exceptions when scheduling. - apply_ssbd 1, 1f, x22, x23 - -#ifdef CONFIG_ARM64_SSBD - ldp x0, x1, [sp, #16 * 0] - ldp x2, x3, [sp, #16 * 1] -#endif -1: + apply_ssbd 1, x22, x23 mov x29, xzr // fp pointed to user-space .else @@ -321,8 +316,7 @@ alternative_if ARM64_WORKAROUND_845719 alternative_else_nop_endif #endif 3: - apply_ssbd 0, 5f, x0, x1 -5: + apply_ssbd 0, x0, x1 .endif msr elr_el1, x21 // set up the return data From patchwork Wed Jul 11 13:56:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141751 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp321752ljj; Wed, 11 Jul 2018 06:57:54 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdF4N1Wc72m5lBz4xtrUftlLXt2VWI7cKoohWteXS2fPicroS1zjKybNztZ4NbiTeZU2+Oj X-Received: by 2002:a17:902:a60b:: with SMTP id u11-v6mr28753953plq.158.1531317473978; Wed, 11 Jul 2018 06:57:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317473; cv=none; d=google.com; s=arc-20160816; b=VYKHqguloC9PPs2MGK3XBcWkbC7uqSRyCDcV5G3/GE4y65HwBAuHhFMd9uYZO7ZIXd zeduwLuPFwHYbB34QG0tKbmMIHYKvgbKbRzqQboQiSTj+Ld7cEjJH/63EPI8su5ix9Qz K+caOwuZkOZBn7wHTW8czteGQg/fLwfhD/hDTA4YttiEBsoS/ryWkbVxoF+zm+InA60+ p5Ej0B3D1n0B9nhPO3lF1VwHUEZL8YYjCxkjl0MDLkwAQ4HPtgHYYVc+ytM4S6oWIKcl oX6L+dqhNIp56yjXPgxofgdiORUX6SrYSiFwCXm4fiEw+TCoVNw99vl05H50FZTBs+wf J69w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=CdNx5ytEQi1xOvCR88zjZ5/+eGrz52EcsN0dA4JQPRU=; b=ZX5gqOQCL3ooVppV+jG7erzvCrqcwA431tDTeO4O3QVe/fftYQFt/Kxbw1pPMlc3vN gWcgvhpw4ZluxiqZIS9Azq52uqS0CRyYPfweuBaiEVdfrcorPooqQQSAbSx6OxllP0Uh Z0kM0j7B4EQwqLkoldajk/CsH0WSarc5VBwaGF4DBmo6kkfTxrGs+Rzrwt/WLZ8kZtyL of33TXPzH1pRqPrmPrvsZlDwEYfAAcey/zj7rLJ+TlFs22CeZZ3VGChofA3vkFzCh9iI vpODVM+/3ACrsNKB5ywAZJojmarIVGKGdfEziWjfObdfu94fTON2PygR/XpbyxHOFdMn 42Rw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w19-v6si19544479pfn.160.2018.07.11.06.57.53; Wed, 11 Jul 2018 06:57:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388536AbeGKOCT (ORCPT + 23 others); Wed, 11 Jul 2018 10:02:19 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:36430 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388274AbeGKOCS (ORCPT ); Wed, 11 Jul 2018 10:02:18 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0DD5322C7; Wed, 11 Jul 2018 06:57:51 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F19A23F5B1; Wed, 11 Jul 2018 06:57:48 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 13/21] arm64: zero GPRs upon entry from EL0 Date: Wed, 11 Jul 2018 14:56:48 +0100 Message-Id: <20180711135656.20670-14-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We can zero GPRs x0 - x29 upon entry from EL0 to make it harder for userspace to control values consumed by speculative gadgets. We don't blat x30, since this is stashed much later, and we'll blat it before invoking C code. Signed-off-by: Mark Rutland Acked-by: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/entry.S | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) -- 2.11.0 diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 22b240da949b..d1440f84668b 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -53,6 +53,12 @@ #endif .endm + .macro clear_gp_regs + .irp n,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29 + mov x\n, xzr + .endr + .endm + /* * Bad Abort numbers *----------------- @@ -169,6 +175,7 @@ alternative_cb_end stp x28, x29, [sp, #16 * 14] .if \el == 0 + clear_gp_regs mrs x21, sp_el0 ldr_this_cpu tsk, __entry_task, x20 // Ensure MDSCR_EL1.SS is clear, ldr x19, [tsk, #TSK_TI_FLAGS] // since we can unmask debug @@ -176,7 +183,6 @@ alternative_cb_end apply_ssbd 1, x22, x23 - mov x29, xzr // fp pointed to user-space .else add x21, sp, #S_FRAME_SIZE get_thread_info tsk From patchwork Wed Jul 11 13:56:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141752 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp321799ljj; Wed, 11 Jul 2018 06:57:58 -0700 (PDT) X-Google-Smtp-Source: AAOMgpehUXnE63GwSAwfDLGDAhGGpVCgnMmF8hkUpjld5Luf9e8wHpYpP7ZG7fHT8kzk7VXpY0y3 X-Received: by 2002:a63:b256:: with SMTP id t22-v6mr27580447pgo.101.1531317478021; Wed, 11 Jul 2018 06:57:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317478; cv=none; d=google.com; s=arc-20160816; b=B7dfAQFiqYfpAiW0t6jvB7FgKWqrFaf6+GUO2QENY+ph8vuJCtLFP6H7ZsocZMPcnl wJ9dRAwRBaf1k/UUoxorpmbSsqZ0QBgJEEYQB3j0HgptAjuMEYSM9mWOO5jlTcCHOAi7 WfHsV3DdKQLmsmDOo/+kK6NY+FV5w3Hv3j+Pt5QN45wPZu8I3tW0JUhny+uF6SmrGKQC Po0PXVOT38Jag9Y8eRsEgl+irTq3IH4QSzYKXKcAb1y3grm3HOhvj2Iw+VZP0mnevwmx SX1e7YIVNhxtbO+NtT7ZX8lQmI5T44qnJxmG/fo2eKIGEKCtSBUaBlBDyqKCKUQneWh6 /4gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=oG3sIR5CHO3tp+UNaooC7a/PJ9vjBOkp45B82Qxr54g=; b=Y7XoSg3sCJJMhaRQa9ttcLTyWjAoY2L5SQw/2Lb8ypyTrBYM+35l1Ezj1bvnirEnQX Te57p9XngzqRahgSa+3MPXwPKPf4C3rtanGL1WsAN/3TUHlX6D/jwgVe5v1y8z1Zmjmw R++rcR9nVXzFL13874uRHyuzIRJKrJ36excX7Eak2sFFyDthAgw788/lyZpYd6ZTVOjl fvh6Hxt+GKeomgAKSJzR0pWTa3H8yK9e4KIwF+p6Kl+h+yaZmnLwEoMtOv2EOmNPf7UE YdhXISWttdfv6Py36KJSbADhzT3PLKs68+1kiZeaEFVyymbC9vUgjoKLdmo9dCvjHvBy /6Zg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w19-v6si19544479pfn.160.2018.07.11.06.57.57; Wed, 11 Jul 2018 06:57:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388551AbeGKOCX (ORCPT + 23 others); Wed, 11 Jul 2018 10:02:23 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:36436 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388274AbeGKOCW (ORCPT ); Wed, 11 Jul 2018 10:02:22 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7D2DE22C8; Wed, 11 Jul 2018 06:57:54 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6CCB33F5B1; Wed, 11 Jul 2018 06:57:52 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 14/21] arm64: drop alignment from syscall tables Date: Wed, 11 Jul 2018 14:56:49 +0100 Message-Id: <20180711135656.20670-15-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Our syscall tables are aligned to 4096 bytes, which allowed their addresses to be generated with a single adrp in entry.S. This has the unfortunate property of wasting space in .rodata for the necessary padding. Now that the address is generated by C code, we can rely on the compiler to do the right thing, and drop the alignemnt. Signed-off-by: Mark Rutland Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/sys.c | 6 +----- arch/arm64/kernel/sys32.c | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) -- 2.11.0 diff --git a/arch/arm64/kernel/sys.c b/arch/arm64/kernel/sys.c index 7f0907261269..df8180175515 100644 --- a/arch/arm64/kernel/sys.c +++ b/arch/arm64/kernel/sys.c @@ -56,11 +56,7 @@ asmlinkage long sys_rt_sigreturn(void); #undef __SYSCALL #define __SYSCALL(nr, sym) [nr] = (syscall_fn_t)sym, -/* - * The sys_call_table array must be 4K aligned to be accessible from - * kernel/entry.S. - */ -const syscall_fn_t sys_call_table[__NR_syscalls] __aligned(4096) = { +const syscall_fn_t sys_call_table[__NR_syscalls] = { [0 ... __NR_syscalls - 1] = (syscall_fn_t)sys_ni_syscall, #include }; diff --git a/arch/arm64/kernel/sys32.c b/arch/arm64/kernel/sys32.c index d993214118aa..4ddeaae90128 100644 --- a/arch/arm64/kernel/sys32.c +++ b/arch/arm64/kernel/sys32.c @@ -44,11 +44,7 @@ asmlinkage long compat_sys_mmap2_wrapper(void); #undef __SYSCALL #define __SYSCALL(nr, sym) [nr] = (syscall_fn_t)sym, -/* - * The sys_call_table array must be 4K aligned to be accessible from - * kernel/entry.S. - */ -const syscall_fn_t compat_sys_call_table[__NR_compat_syscalls] __aligned(4096) = { +const syscall_fn_t compat_sys_call_table[__NR_compat_syscalls] = { [0 ... __NR_compat_syscalls - 1] = (syscall_fn_t)sys_ni_syscall, #include }; From patchwork Wed Jul 11 13:56:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141753 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp321821ljj; Wed, 11 Jul 2018 06:58:01 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcsMsC7m26TpD5capoeYV2zHrJIEiOPs7mUSkO2UkjNtVvILHSwRRG64LTUnQHL6BGyqivX X-Received: by 2002:a17:902:aa01:: with SMTP id be1-v6mr28776227plb.296.1531317481011; Wed, 11 Jul 2018 06:58:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317481; cv=none; d=google.com; s=arc-20160816; b=he9tJ4+kzWCwZ38Ws2t+hKV2E5bLvmViJQl8G75Azw+Gt4xQpsnllzzMkvwVeMRv20 +yE6LNBeV5ojXEBmyMPeS1GgQFkqRiFtProblvD0U096blKPPdGfn+iouABWQSsAhYQz ndvT5F2LMZ2QLQNy1VJSBCaxdLJa8nOnkTgKJCqHMq/aOJJWzJE/ecULJQZ1aIu3Y+95 28IDyMtvjHOtsSwmFHKg/heAHa61vQt+0O8fUS9EyKzg0hlb8vWG+EW7B38Lea7f6WLC 9XtaQgYDKtFKNHI9ZXjdI9KBhFIqqu22LTvtKSFmwXVNHq7FK/fRoaHpEoCj8EmFe169 edKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=QR6AYj0erSu4mrb/hQXJOFPO1fLRJozeG1ZhKnAPjDE=; b=Q+pk1dw47IJ5zNfK9bQ8qiaJsArLUiMJX+H8in7RR5emgPeT/u/xk8eR9O5zFu22pg QKPcFLN70b1bwSv0zJJKrrgyBv2WsdggUHYVHxC6j8PXWybGzAKXi5viNp51IxQQMMp9 JLf2sR42ZL0ybazGxIprfM67JxGFkeST9aTIBdjJzs6M8gjZR4dUF8B3E6YD5iIhUtQL +WpaSJ6Der16qsdun6Xd78swr3NMgCtRNcDXBD7jQCh8wBO2/WThDTpB6nj+1E3YUpiy QY3cgMzoiLdMxmPM4pD5jR566G/EZNam4rZk0s1CQdY5FOH15eGimoK2I6uGnahhN1V6 afLA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j21-v6si3368461pgg.303.2018.07.11.06.58.00; Wed, 11 Jul 2018 06:58:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388565AbeGKOC0 (ORCPT + 23 others); Wed, 11 Jul 2018 10:02:26 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:36444 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388274AbeGKOCZ (ORCPT ); Wed, 11 Jul 2018 10:02:25 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8ABB622F8; Wed, 11 Jul 2018 06:57:57 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7A7283F5B1; Wed, 11 Jul 2018 06:57:55 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 15/21] kernel: add ksys_personality() Date: Wed, 11 Jul 2018 14:56:50 +0100 Message-Id: <20180711135656.20670-16-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using this helper allows us to avoid the in-kernel call to the sys_personality() syscall. The ksys_ prefix denotes that this function is meant as a drop-in replacement for the syscall. In particular, it uses the same calling convention as sys_personality(). Since ksys_personality is trivial, it is implemented directly in , as we do for ksys_close() and friends. This helper is necessary to enable conversion of arm64's syscall handling to use pt_regs wrappers. Signed-off-by: Mark Rutland Reviewed-by: Dominik Brodowski Cc: Al Viro Cc: Christoph Hellwig Cc: Dave Martin --- include/linux/syscalls.h | 11 +++++++++++ 1 file changed, 11 insertions(+) -- 2.11.0 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index a368a68cb667..abfe12d8a9c5 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -80,6 +80,7 @@ union bpf_attr; #include #include #include +#include #include #ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER @@ -1281,4 +1282,14 @@ static inline long ksys_truncate(const char __user *pathname, loff_t length) return do_sys_truncate(pathname, length); } +static inline unsigned int ksys_personality(unsigned int personality) +{ + unsigned int old = current->personality; + + if (personality != 0xffffffff) + set_personality(personality); + + return old; +} + #endif From patchwork Wed Jul 11 13:56:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141754 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp321885ljj; Wed, 11 Jul 2018 06:58:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc/FY+5ah/k3pENz+8Wa7sq7mmfYb2z1EPKteAaKcsi3cqXMz828UGTDxzfeA51BDD/hsEA X-Received: by 2002:a65:6252:: with SMTP id q18-v6mr27211951pgv.106.1531317485178; Wed, 11 Jul 2018 06:58:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317485; cv=none; d=google.com; s=arc-20160816; b=ca8JHbkoGc2pQrwDCeUEt3YVsrQ84plezYZHNDxj3MXGz3uQbWbtqLXqPtYvhP+fdt uEs2O6GilYNxHkfNMi8FSHwrFSOi9B0Lp8DQjl5p6m4Y+vbnB8aZ4NMaIZJryRYuHWPd 8CiCvnHd5hMUW0tvEuJ0rf3THQGgCQ4rAycULhSc5seNBFT1EyixLgRKy2tOQ+RBC2Md WqGe0aB17VUTfKqAuo5vDJ8NtnsqoxqwF6iW2C7kzVPz24zpSe6iSYswJFrxRDJsQRjW dXRhayMyTDwbsnbtr75JjE2pLtA5+RL0nxCrjUFhM0GroqAwyVb8roOEr2cLzL0mqeBs FL/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=VHIBZD6OjHpcIqa5o8v0gxQRO/xJp3kWA0Kavz9205g=; b=EiAw280OXAyuFcaboM71NFu7hBrGJZLbkN9lo+B9Ncej1uEU67Jfr2jPGgYBsx035e wtlxAUcyyypggRM7lrPEwJY8o7xyG8aNslACfgeb+tNcnH6gHARjND+MwjB7Ripv9rP0 BccuewXNDNfdeTJfX0fBgdY39eiuV+iXDgcM72FTmaFaaqHpUw1kjxfH4puc1m8Uvi/B +4pKNktkAMUyZEcTW0aaKGnqyvfbH1OQxN/LZjREfRK1pfi/GdfkRPPTHudISZYfxi7Z sNNHpCCfWRIm0HgYZ9WKmdTiRqQBS/993MKFCM9gtG4LdY38YnYq17uXAPJegRZ1f14B vGkA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q11-v6si18208757pgb.102.2018.07.11.06.58.04; Wed, 11 Jul 2018 06:58:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388580AbeGKOCa (ORCPT + 23 others); Wed, 11 Jul 2018 10:02:30 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:36452 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388274AbeGKOCa (ORCPT ); Wed, 11 Jul 2018 10:02:30 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 46B1C2379; Wed, 11 Jul 2018 06:58:02 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3627F3F5B1; Wed, 11 Jul 2018 06:58:00 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 16/21] kernel: add kcompat_sys_{f,}statfs64() Date: Wed, 11 Jul 2018 14:56:51 +0100 Message-Id: <20180711135656.20670-17-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using this helper allows us to avoid the in-kernel calls to the compat_sys_{f,}statfs64() sycalls, as are necessary for parameter mangling in arm64's compat handling. Following the example of ksys_* functions, kcompat_sys_* functions are intended to be a drop-in replacement for their compat_sys_* counterparts, with the same calling convention. This is necessary to enable conversion of arm64's syscall handling to use pt_regs wrappers. Signed-off-by: Mark Rutland Reviewed-by: Dominik Brodowski Cc: Al Viro Cc: linux-fsdevel@vger.kernel.org --- fs/statfs.c | 14 ++++++++++++-- include/linux/compat.h | 11 +++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) -- 2.11.0 diff --git a/fs/statfs.c b/fs/statfs.c index 5b2a24f0f263..f0216629621d 100644 --- a/fs/statfs.c +++ b/fs/statfs.c @@ -335,7 +335,7 @@ static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstat return 0; } -COMPAT_SYSCALL_DEFINE3(statfs64, const char __user *, pathname, compat_size_t, sz, struct compat_statfs64 __user *, buf) +int kcompat_sys_statfs64(const char __user * pathname, compat_size_t sz, struct compat_statfs64 __user * buf) { struct kstatfs tmp; int error; @@ -349,7 +349,12 @@ COMPAT_SYSCALL_DEFINE3(statfs64, const char __user *, pathname, compat_size_t, s return error; } -COMPAT_SYSCALL_DEFINE3(fstatfs64, unsigned int, fd, compat_size_t, sz, struct compat_statfs64 __user *, buf) +COMPAT_SYSCALL_DEFINE3(statfs64, const char __user *, pathname, compat_size_t, sz, struct compat_statfs64 __user *, buf) +{ + return kcompat_sys_statfs64(pathname, sz, buf); +} + +int kcompat_sys_fstatfs64(unsigned int fd, compat_size_t sz, struct compat_statfs64 __user * buf) { struct kstatfs tmp; int error; @@ -363,6 +368,11 @@ COMPAT_SYSCALL_DEFINE3(fstatfs64, unsigned int, fd, compat_size_t, sz, struct co return error; } +COMPAT_SYSCALL_DEFINE3(fstatfs64, unsigned int, fd, compat_size_t, sz, struct compat_statfs64 __user *, buf) +{ + return kcompat_sys_fstatfs64(fd, sz, buf); +} + /* * This is a copy of sys_ustat, just dealing with a structure layout. * Given how simple this syscall is that apporach is more maintainable diff --git a/include/linux/compat.h b/include/linux/compat.h index c68acc47da57..43f4ed44c5d5 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -1028,6 +1028,17 @@ static inline struct compat_timeval ns_to_compat_timeval(s64 nsec) return ctv; } +/* + * Kernel code should not call compat syscalls (i.e., compat_sys_xyzyyz()) + * directly. Instead, use one of the functions which work equivalently, such + * as the kcompat_sys_xyzyyz() functions prototyped below. + */ + +int kcompat_sys_statfs64(const char __user * pathname, compat_size_t sz, + struct compat_statfs64 __user * buf); +int kcompat_sys_fstatfs64(unsigned int fd, compat_size_t sz, + struct compat_statfs64 __user * buf); + #else /* !CONFIG_COMPAT */ #define is_compat_task() (0) From patchwork Wed Jul 11 13:56:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141755 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp321938ljj; Wed, 11 Jul 2018 06:58:08 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfPyLsviz9IIhsMQTir4rDEfaYtCSE/WinMGD0gpWvV1iabAsqc6mfUgEls+mBRij690N9B X-Received: by 2002:a17:902:822:: with SMTP id 31-v6mr28533162plk.172.1531317488778; Wed, 11 Jul 2018 06:58:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317488; cv=none; d=google.com; s=arc-20160816; b=YpALUq6hyXMKAcH5gL4/1DYR8iC6oKE9Ksow687N05jraK+mwu1BrCMibJ2sxj0Fi9 9YbxdlLtLxXtOhVgdgd8xLoft6t+1ta8tq9gJ6PNIOATYzVPD1ELxF9onjeKtwNYFHHl o21hZ56vj2mdfXXc9iRSixvrGJHvAZPWS3hzpD+d6RmktzG2thj93DhIgMxcSZJh1YFd kvMfnMAeYAMJ7NkB9WUjMspdAx3LjO7Xn1ciz9O8QuNdvTmf7VvNuTls1Q3Xab2Yvl7H bfKjnVyr7Z+sAYr18GcjyVvhBO8T2u3zA0KA3WWNjuDhT7A6mcYDUQq8gJS0wk0kOa6b UKlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=M20LfC1zyd2XdVhO/3fVHF+kz2qhwrW7DPcVBawHgjY=; b=a3DbqRosrgVQ9fbX+nckaoyWojzUfnrRjyFnBZkuPhaQwD5Q1/7sbUG9Z1PTvu3pZR Ou8J4BOsly9zBLJ/u59HW9b7W9yy9xoUhxeFWirHpfrkHtU283o5aWsGezgJF2DK2IJ2 Un84xOJtCjueyp5RL2FKFbY24LFBPGosUS4UMkhxTYy+Cc5pAVQt4H8pKc1SP7latsPN P1A5sQxvkZWoOp8kKCAzSJo/w7x4QBZDSNm/6vFIJO7tjBFS1J+6Q+gAhOzsSPQd8syW rBH2j9/V43GncNwq8aKL1+u8SDGzcMTC20VTaUwgXA1cwj3dnURduCg/wRgzx2BWApFv Ac+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a1-v6si9337667pgg.326.2018.07.11.06.58.08; Wed, 11 Jul 2018 06:58:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388595AbeGKOCe (ORCPT + 23 others); Wed, 11 Jul 2018 10:02:34 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:36458 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388274AbeGKOCd (ORCPT ); Wed, 11 Jul 2018 10:02:33 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 45DDB237B; Wed, 11 Jul 2018 06:58:05 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2C6463F5B1; Wed, 11 Jul 2018 06:58:03 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 17/21] arm64: remove in-kernel call to sys_personality() Date: Wed, 11 Jul 2018 14:56:52 +0100 Message-Id: <20180711135656.20670-18-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With pt_regs syscall wrappers, the calling convention for sys_personality() will change. Use ksys_personality(), which is functionally equivalent. Signed-off-by: Mark Rutland Acked-by: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/sys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.11.0 diff --git a/arch/arm64/kernel/sys.c b/arch/arm64/kernel/sys.c index df8180175515..f4e02f6aceb8 100644 --- a/arch/arm64/kernel/sys.c +++ b/arch/arm64/kernel/sys.c @@ -44,7 +44,7 @@ SYSCALL_DEFINE1(arm64_personality, unsigned int, personality) if (personality(personality) == PER_LINUX32 && !system_supports_32bit_el0()) return -EINVAL; - return sys_personality(personality); + return ksys_personality(personality); } /* From patchwork Wed Jul 11 13:56:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141756 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp321981ljj; Wed, 11 Jul 2018 06:58:11 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfyy2tFNUTn6Ly/b5zSJLFiIy60+ii6QKw2dkgAP6f1+kloO2jkOgPPtjgtg7OtM7TLJV5l X-Received: by 2002:a17:902:7c8b:: with SMTP id y11-v6mr28121777pll.222.1531317491486; Wed, 11 Jul 2018 06:58:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317491; cv=none; d=google.com; s=arc-20160816; b=afG+jvs4WrEezx5AwLjCYlMYpi6R4ankTggg59G7tNRqcG+BVUo9H61ZtCHAzrZzSK am7vvFLHXLidh8X3QGV87Hrs+YNVinqXe1wLxuRKXA3jADfERl8D7hbZ3/6s3i6Bm8VF l+wcWPhjq65EvOabt5Rc2P3SbWhxmih5g1ispJHYe6Ouasu1/1NncXDUJXBMzGnlHisY CIA1Z/ugTWvWoNoqYpYDXnmUPrwLyGnrI9flT1cy9Esfimb9z+4FL79lU5nHrGgBlr6U 8pc2Z+Sh2NJrMC5xQp7ewYDJZV5t0zIEP53DW96bT5MbbPPKYhXRoz1vhM5audE1jPHF X+JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=dNZTG/yjSHgfmqGyppguNX2LFtvIHMlmBGfddDd3lvM=; b=EaeQ+p0GPRFyOakxHj9vrV+3GZzgJ0bvUrKAZnSjpTgYgPgxxygGGXYJkc3pZFezUz 3cwxRDZXI1tYMq5azLUs7PbJNsXaW27SN75CToscbNGNe42FktHDIIMpWiyhkUmKORDa wBICh0eEw4R54uA6O89VJ/WlzCyS0U//2n2JXvatglS/cEcJUMalgst7z5SY07S/R4vQ vTiwxPH7SDtomwAY3XeaL4nW99BjzT2xyfJxPv60seyLUZ0Sjrs7ESZlgM0jzdwI1vpw 4Z7CN6ZR6K3pOrhhYXflru/TRs+BVjZRqf9apAy0dauIz38u/iI0cYgf3q0v8tZJzX/H hJyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o3-v6si19472538plk.321.2018.07.11.06.58.11; Wed, 11 Jul 2018 06:58:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388610AbeGKOCh (ORCPT + 23 others); Wed, 11 Jul 2018 10:02:37 -0400 Received: from foss.arm.com ([217.140.101.70]:36468 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388274AbeGKOCg (ORCPT ); Wed, 11 Jul 2018 10:02:36 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2BB342381; Wed, 11 Jul 2018 06:58:08 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1AC173F5B1; Wed, 11 Jul 2018 06:58:05 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 18/21] arm64: use {COMPAT,}SYSCALL_DEFINE0 for sigreturn Date: Wed, 11 Jul 2018 14:56:53 +0100 Message-Id: <20180711135656.20670-19-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We don't currently annotate our various sigreturn functions as syscalls, as we need to do to use pt_regs syscall wrappers. Let's mark them as real syscalls. For compat_sys_sigreturn and compat_sys_rt_sigreturn, this changes the return type from int to long, matching the prototypes in sys32.c. Signed-off-by: Mark Rutland Reviewed-by: Dominik Brodowski Acked-by: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/signal.c | 2 +- arch/arm64/kernel/signal32.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) -- 2.11.0 diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index f03e664f773f..f8b0ba50e55e 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -539,7 +539,7 @@ static int restore_sigframe(struct pt_regs *regs, return err; } -asmlinkage long sys_rt_sigreturn(void) +SYSCALL_DEFINE0(rt_sigreturn) { struct pt_regs *regs = current_pt_regs(); struct rt_sigframe __user *frame; diff --git a/arch/arm64/kernel/signal32.c b/arch/arm64/kernel/signal32.c index cb10588a7cb2..1948566dcccf 100644 --- a/arch/arm64/kernel/signal32.c +++ b/arch/arm64/kernel/signal32.c @@ -282,7 +282,7 @@ static int compat_restore_sigframe(struct pt_regs *regs, return err; } -asmlinkage int compat_sys_sigreturn(void) +COMPAT_SYSCALL_DEFINE0(sigreturn) { struct pt_regs *regs = current_pt_regs(); struct compat_sigframe __user *frame; @@ -313,7 +313,7 @@ asmlinkage int compat_sys_sigreturn(void) return 0; } -asmlinkage int compat_sys_rt_sigreturn(void) +COMPAT_SYSCALL_DEFINE0(rt_sigreturn) { struct pt_regs *regs = current_pt_regs(); struct compat_rt_sigframe __user *frame; From patchwork Wed Jul 11 13:56:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141757 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp322039ljj; Wed, 11 Jul 2018 06:58:15 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeJjiDvsjCiIMdlp6IBthTlsp01UVkQHWN8kBRgGTub+My3GEY82cEAXojwsCDVahZVYZ4H X-Received: by 2002:a63:6e0a:: with SMTP id j10-v6mr20869328pgc.321.1531317495040; Wed, 11 Jul 2018 06:58:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317495; cv=none; d=google.com; s=arc-20160816; b=zGwCSu5ienEbDZLSbQRz4Gn+4u94IPRHcG0tOoMrdtKJyxJAk6yA66oq1Aaw51tpLF Q227v5uSTMvkDaHcJ9YL14mjj7V4ubv44rb5PHsDP0ragq/xUXDgLnKAWEs3NNwNJvhW YY6FXo3iy/GDP9pEq/HfblKFOLCKZJGVm943U+UVqFWG1DEPShezuxNpfip1a6/9lBe/ +e7YoVLazjGf8OclOcc0822ZBUqKHoULO4FLMPm6XLZZMx+GxH1xXNtEXbPAtsfofTuI sZyzCiL2ACLwfv1OiKyxXrUck/CNrSmEXWmmQERngEIvm+uynd6v4J0f5xUO3E6pHDYa dwSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=zBnpfzzYX0x6s11u4AXHyhpfmMT/Om+ciyc376Y96Ss=; b=yvuYCDGvEIorzl8idXgrvG+PqCYx2xztyJLx2J0XYXQ3/t5PmjdEYRleGxLx/p4sqz NWxlvCSZgN1WNFjRQDb9FYLMMqp1ew1eLHQ0IVYXsIS5543mXQe/ATGhu5DjiAHSnI8h ycy15i+Ri2YDY6QCBlR6/HTFiS0L1dysgEbIf0E6uHdU8/2/edKl5Rb7cFli/mw00/Kv jgxqlEy9g8fLVszyiGNzALFwPvXw2fpD2s9H8A+ocHVtvvsYlwkfO4WMpKrExxZCONvQ fYdc7qHW/6ctzMfoYgJl6GAJ4ErLaV7k4Zdr7ch/3VevdEgpndv/43dyXHng5Zau7mto kwrw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 16-v6si20217726pfy.169.2018.07.11.06.58.14; Wed, 11 Jul 2018 06:58:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388625AbeGKOCk (ORCPT + 23 others); Wed, 11 Jul 2018 10:02:40 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:36480 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388274AbeGKOCj (ORCPT ); Wed, 11 Jul 2018 10:02:39 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5994028AC; Wed, 11 Jul 2018 06:58:11 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3FE613F5B1; Wed, 11 Jul 2018 06:58:09 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 19/21] arm64: use SYSCALL_DEFINE6() for mmap Date: Wed, 11 Jul 2018 14:56:54 +0100 Message-Id: <20180711135656.20670-20-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We don't currently annotate our mmap implementation as a syscall, as we need to do to use pt_regs syscall wrappers. Let's mark it as a real syscall. There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland Reviewed-by: Dominik Brodowski Acked-by: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/sys.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 2.11.0 diff --git a/arch/arm64/kernel/sys.c b/arch/arm64/kernel/sys.c index f4e02f6aceb8..f249d9735f4c 100644 --- a/arch/arm64/kernel/sys.c +++ b/arch/arm64/kernel/sys.c @@ -29,9 +29,9 @@ #include #include -asmlinkage long sys_mmap(unsigned long addr, unsigned long len, - unsigned long prot, unsigned long flags, - unsigned long fd, off_t off) +SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len, + unsigned long, prot, unsigned long, flags, + unsigned long, fd, off_t, off) { if (offset_in_page(off) != 0) return -EINVAL; From patchwork Wed Jul 11 13:56:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141758 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp322088ljj; Wed, 11 Jul 2018 06:58:18 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf1aJlNlo5zDbpMpCGK9T5EtJYIHvfGrtXyd2Tm2DQYjT2/mIfmtMYjq6x0SnOyf2SHNK7g X-Received: by 2002:a63:375b:: with SMTP id g27-v6mr27103908pgn.59.1531317498629; Wed, 11 Jul 2018 06:58:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317498; cv=none; d=google.com; s=arc-20160816; b=L5oOKqNpqR7dctmNseoFrxiitVEXT3O6Wnd8WKRjknaJhJ90o2QRnfePOwb0WWEcrv BnkePmJsrJfMrrHu++BXDARZw/9XW13M0M7fTbkEyuIOyCs93wfIL9UlgcL6nim8NYIA FWJhuJa7KYm/eXWK/e6x8iw5FPuhYoj5tnZyO72kmNgAtKKWy5sf0pBwGOoath9xvKHu 80b0f89/0RF0dYRcu3rTvbmZLIAb5LxAlvijrofE6Er8qLGZhHOpovuxIUOq9y+ZXolN NkG9D420QeH+Gq5Kg5STFkpgc5wHfpiP8wJ3cVfGY0NnI/wYDb5CzK4wRbC0s0/SlXQ2 bt2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Z8ekWA7zfONbOvRaYCiWAo9cVE0qzuTYrM7CINRdQnc=; b=jXJ194q/trfB5xNeLE0GwJvR8CPRA5d9/epWCnbiCJHO9BLBDNp1UHKzKaz4oO0RDz pFoDI4c021Rek9Ac3xLxVuiMjxRr9LToyAP3SxMN+TqXsXULW/iCAIi7sZC3nsO0VAcT XrCPdPSfEeaFipiRGTWDVOM+/aw29sz7jwQ+YMcT9q1LxyJC6LbhPsb8oetOUQNIsigp kYMv6V39HRWffS+ZJhR2yGnzxPVMGsVOas3e3RXRb3ThAA7byw/7StVp/bNRfOJ40L4G kYa3GB/vA/Wu8zb70w9P1kMi+bxctNYzm1rXHk2vliZQvCOSAr2vbwgjbagbcaGY6vM5 LjZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r12-v6si17490118pgv.285.2018.07.11.06.58.18; Wed, 11 Jul 2018 06:58:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388640AbeGKOCn (ORCPT + 23 others); Wed, 11 Jul 2018 10:02:43 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:36490 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388274AbeGKOCn (ORCPT ); Wed, 11 Jul 2018 10:02:43 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A56C92A6B; Wed, 11 Jul 2018 06:58:14 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 953B53F5B1; Wed, 11 Jul 2018 06:58:12 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 20/21] arm64: convert compat wrappers to C Date: Wed, 11 Jul 2018 14:56:55 +0100 Message-Id: <20180711135656.20670-21-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation for converting to pt_regs syscall wrappers, convert our existing compat wrappers to C. This will allow the pt_regs wrappers to be automatically generated, and will allow for the compat register manipulation to be folded in with the pt_regs accesses. To avoid confusion with the upcoming pt_regs wrappers and existing compat wrappers provided by core code, the C wrappers are renamed to compat_sys_aarch32_. With the assembly wrappers gone, we can get rid of entry32.S and the associated boilerplate. Note that these must call the ksys_* syscall entry points, as the usual sys_* entry points will be modified to take a single pt_regs pointer argument. Signed-off-by: Mark Rutland Acked-by: Catalin Marinas Cc: Will Deacon --- arch/arm64/include/asm/unistd32.h | 22 ++++---- arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/entry32.S | 111 ------------------------------------- arch/arm64/kernel/sys32.c | 114 ++++++++++++++++++++++++++++++++++---- 4 files changed, 115 insertions(+), 134 deletions(-) delete mode 100644 arch/arm64/kernel/entry32.S -- 2.11.0 diff --git a/arch/arm64/include/asm/unistd32.h b/arch/arm64/include/asm/unistd32.h index ab95554b1734..0e3dd3265993 100644 --- a/arch/arm64/include/asm/unistd32.h +++ b/arch/arm64/include/asm/unistd32.h @@ -382,9 +382,9 @@ __SYSCALL(__NR_rt_sigqueueinfo, compat_sys_rt_sigqueueinfo) #define __NR_rt_sigsuspend 179 __SYSCALL(__NR_rt_sigsuspend, compat_sys_rt_sigsuspend) #define __NR_pread64 180 -__SYSCALL(__NR_pread64, compat_sys_pread64_wrapper) +__SYSCALL(__NR_pread64, compat_sys_aarch32_pread64) #define __NR_pwrite64 181 -__SYSCALL(__NR_pwrite64, compat_sys_pwrite64_wrapper) +__SYSCALL(__NR_pwrite64, compat_sys_aarch32_pwrite64) #define __NR_chown 182 __SYSCALL(__NR_chown, sys_chown16) #define __NR_getcwd 183 @@ -406,11 +406,11 @@ __SYSCALL(__NR_vfork, sys_vfork) #define __NR_ugetrlimit 191 /* SuS compliant getrlimit */ __SYSCALL(__NR_ugetrlimit, compat_sys_getrlimit) /* SuS compliant getrlimit */ #define __NR_mmap2 192 -__SYSCALL(__NR_mmap2, compat_sys_mmap2_wrapper) +__SYSCALL(__NR_mmap2, compat_sys_aarch32_mmap2) #define __NR_truncate64 193 -__SYSCALL(__NR_truncate64, compat_sys_truncate64_wrapper) +__SYSCALL(__NR_truncate64, compat_sys_aarch32_truncate64) #define __NR_ftruncate64 194 -__SYSCALL(__NR_ftruncate64, compat_sys_ftruncate64_wrapper) +__SYSCALL(__NR_ftruncate64, compat_sys_aarch32_ftruncate64) #define __NR_stat64 195 __SYSCALL(__NR_stat64, sys_stat64) #define __NR_lstat64 196 @@ -472,7 +472,7 @@ __SYSCALL(223, sys_ni_syscall) #define __NR_gettid 224 __SYSCALL(__NR_gettid, sys_gettid) #define __NR_readahead 225 -__SYSCALL(__NR_readahead, compat_sys_readahead_wrapper) +__SYSCALL(__NR_readahead, compat_sys_aarch32_readahead) #define __NR_setxattr 226 __SYSCALL(__NR_setxattr, sys_setxattr) #define __NR_lsetxattr 227 @@ -554,15 +554,15 @@ __SYSCALL(__NR_clock_getres, compat_sys_clock_getres) #define __NR_clock_nanosleep 265 __SYSCALL(__NR_clock_nanosleep, compat_sys_clock_nanosleep) #define __NR_statfs64 266 -__SYSCALL(__NR_statfs64, compat_sys_statfs64_wrapper) +__SYSCALL(__NR_statfs64, compat_sys_aarch32_statfs64) #define __NR_fstatfs64 267 -__SYSCALL(__NR_fstatfs64, compat_sys_fstatfs64_wrapper) +__SYSCALL(__NR_fstatfs64, compat_sys_aarch32_fstatfs64) #define __NR_tgkill 268 __SYSCALL(__NR_tgkill, sys_tgkill) #define __NR_utimes 269 __SYSCALL(__NR_utimes, compat_sys_utimes) #define __NR_arm_fadvise64_64 270 -__SYSCALL(__NR_arm_fadvise64_64, compat_sys_fadvise64_64_wrapper) +__SYSCALL(__NR_arm_fadvise64_64, compat_sys_aarch32_fadvise64_64) #define __NR_pciconfig_iobase 271 __SYSCALL(__NR_pciconfig_iobase, sys_pciconfig_iobase) #define __NR_pciconfig_read 272 @@ -704,7 +704,7 @@ __SYSCALL(__NR_get_robust_list, compat_sys_get_robust_list) #define __NR_splice 340 __SYSCALL(__NR_splice, sys_splice) #define __NR_sync_file_range2 341 -__SYSCALL(__NR_sync_file_range2, compat_sys_sync_file_range2_wrapper) +__SYSCALL(__NR_sync_file_range2, compat_sys_aarch32_sync_file_range2) #define __NR_tee 342 __SYSCALL(__NR_tee, sys_tee) #define __NR_vmsplice 343 @@ -726,7 +726,7 @@ __SYSCALL(__NR_timerfd_create, sys_timerfd_create) #define __NR_eventfd 351 __SYSCALL(__NR_eventfd, sys_eventfd) #define __NR_fallocate 352 -__SYSCALL(__NR_fallocate, compat_sys_fallocate_wrapper) +__SYSCALL(__NR_fallocate, compat_sys_aarch32_fallocate) #define __NR_timerfd_settime 353 __SYSCALL(__NR_timerfd_settime, compat_sys_timerfd_settime) #define __NR_timerfd_gettime 354 diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 4e24d2244bd1..95ac7374d723 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -28,7 +28,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE $(call if_changed,objcopy) arm64-obj-$(CONFIG_COMPAT) += sys32.o kuser32.o signal32.o \ - sys_compat.o entry32.o + sys_compat.o arm64-obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o entry-ftrace.o arm64-obj-$(CONFIG_MODULES) += arm64ksyms.o module.o arm64-obj-$(CONFIG_ARM64_MODULE_PLTS) += module-plts.o diff --git a/arch/arm64/kernel/entry32.S b/arch/arm64/kernel/entry32.S deleted file mode 100644 index f9461696dde4..000000000000 --- a/arch/arm64/kernel/entry32.S +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Compat system call wrappers - * - * Copyright (C) 2012 ARM Ltd. - * Authors: Will Deacon - * Catalin Marinas - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include - -#include -#include -#include -#include - -/* - * System call wrappers for the AArch32 compatibility layer. - */ - -ENTRY(compat_sys_statfs64_wrapper) - mov w3, #84 - cmp w1, #88 - csel w1, w3, w1, eq - b compat_sys_statfs64 -ENDPROC(compat_sys_statfs64_wrapper) - -ENTRY(compat_sys_fstatfs64_wrapper) - mov w3, #84 - cmp w1, #88 - csel w1, w3, w1, eq - b compat_sys_fstatfs64 -ENDPROC(compat_sys_fstatfs64_wrapper) - -/* - * Note: off_4k (w5) is always in units of 4K. If we can't do the - * requested offset because it is not page-aligned, we return -EINVAL. - */ -ENTRY(compat_sys_mmap2_wrapper) -#if PAGE_SHIFT > 12 - tst w5, #~PAGE_MASK >> 12 - b.ne 1f - lsr w5, w5, #PAGE_SHIFT - 12 -#endif - b sys_mmap_pgoff -1: mov x0, #-EINVAL - ret -ENDPROC(compat_sys_mmap2_wrapper) - -/* - * Wrappers for AArch32 syscalls that either take 64-bit parameters - * in registers or that take 32-bit parameters which require sign - * extension. - */ -ENTRY(compat_sys_pread64_wrapper) - regs_to_64 x3, x4, x5 - b sys_pread64 -ENDPROC(compat_sys_pread64_wrapper) - -ENTRY(compat_sys_pwrite64_wrapper) - regs_to_64 x3, x4, x5 - b sys_pwrite64 -ENDPROC(compat_sys_pwrite64_wrapper) - -ENTRY(compat_sys_truncate64_wrapper) - regs_to_64 x1, x2, x3 - b sys_truncate -ENDPROC(compat_sys_truncate64_wrapper) - -ENTRY(compat_sys_ftruncate64_wrapper) - regs_to_64 x1, x2, x3 - b sys_ftruncate -ENDPROC(compat_sys_ftruncate64_wrapper) - -ENTRY(compat_sys_readahead_wrapper) - regs_to_64 x1, x2, x3 - mov w2, w4 - b sys_readahead -ENDPROC(compat_sys_readahead_wrapper) - -ENTRY(compat_sys_fadvise64_64_wrapper) - mov w6, w1 - regs_to_64 x1, x2, x3 - regs_to_64 x2, x4, x5 - mov w3, w6 - b sys_fadvise64_64 -ENDPROC(compat_sys_fadvise64_64_wrapper) - -ENTRY(compat_sys_sync_file_range2_wrapper) - regs_to_64 x2, x2, x3 - regs_to_64 x3, x4, x5 - b sys_sync_file_range2 -ENDPROC(compat_sys_sync_file_range2_wrapper) - -ENTRY(compat_sys_fallocate_wrapper) - regs_to_64 x2, x2, x3 - regs_to_64 x3, x4, x5 - b sys_fallocate -ENDPROC(compat_sys_fallocate_wrapper) diff --git a/arch/arm64/kernel/sys32.c b/arch/arm64/kernel/sys32.c index 4ddeaae90128..a205d4ff4776 100644 --- a/arch/arm64/kernel/sys32.c +++ b/arch/arm64/kernel/sys32.c @@ -22,6 +22,7 @@ */ #define __COMPAT_SYSCALL_NR +#include #include #include @@ -29,17 +30,108 @@ asmlinkage long compat_sys_sigreturn(void); asmlinkage long compat_sys_rt_sigreturn(void); -asmlinkage long compat_sys_statfs64_wrapper(void); -asmlinkage long compat_sys_fstatfs64_wrapper(void); -asmlinkage long compat_sys_pread64_wrapper(void); -asmlinkage long compat_sys_pwrite64_wrapper(void); -asmlinkage long compat_sys_truncate64_wrapper(void); -asmlinkage long compat_sys_ftruncate64_wrapper(void); -asmlinkage long compat_sys_readahead_wrapper(void); -asmlinkage long compat_sys_fadvise64_64_wrapper(void); -asmlinkage long compat_sys_sync_file_range2_wrapper(void); -asmlinkage long compat_sys_fallocate_wrapper(void); -asmlinkage long compat_sys_mmap2_wrapper(void); + +COMPAT_SYSCALL_DEFINE3(aarch32_statfs64, const char __user *, pathname, + compat_size_t, sz, struct compat_statfs64 __user *, buf) +{ + /* + * 32-bit ARM applies an OABI compatibility fixup to statfs64 and + * fstatfs64 regardless of whether OABI is in use, and therefore + * arbitrary binaries may rely upon it, so we must do the same. + * For more details, see commit: + * + * 713c481519f19df9 ("[ARM] 3108/2: old ABI compat: statfs64 and + * fstatfs64") + */ + if (sz == 88) + sz = 84; + + return kcompat_sys_statfs64(pathname, sz, buf); +} + +COMPAT_SYSCALL_DEFINE3(aarch32_fstatfs64, unsigned int, fd, compat_size_t, sz, + struct compat_statfs64 __user *, buf) +{ + /* see aarch32_statfs64 */ + if (sz == 88) + sz = 84; + + return kcompat_sys_fstatfs64(fd, sz, buf); +} + +/* + * Note: off_4k is always in units of 4K. If we can't do the + * requested offset because it is not page-aligned, we return -EINVAL. + */ +COMPAT_SYSCALL_DEFINE6(aarch32_mmap2, unsigned long, addr, unsigned long, len, + unsigned long, prot, unsigned long, flags, + unsigned long, fd, unsigned long, off_4k) +{ + if (off_4k & (~PAGE_MASK >> 12)) + return -EINVAL; + + off_4k >>= (PAGE_SHIFT - 12); + + return ksys_mmap_pgoff(addr, len, prot, flags, fd, off_4k); +} + +#ifdef CONFIG_CPU_BIG_ENDIAN +#define arg_u32p(name) u32, name##_hi, u32, name##_lo +#else +#define arg_u32p(name) u32, name##_lo, u32, name##_hi +#endif + +#define arg_u64(name) (((u64)name##_hi << 32) | name##_lo) + +COMPAT_SYSCALL_DEFINE6(aarch32_pread64, unsigned int, fd, char __user *, buf, + size_t, count, u32, __pad, arg_u32p(pos)) +{ + return ksys_pread64(fd, buf, count, arg_u64(pos)); +} + +COMPAT_SYSCALL_DEFINE6(aarch32_pwrite64, unsigned int, fd, + const char __user *, buf, size_t, count, u32, __pad, + arg_u32p(pos)) +{ + return ksys_pwrite64(fd, buf, count, arg_u64(pos)); +} + +COMPAT_SYSCALL_DEFINE4(aarch32_truncate64, const char __user *, pathname, + u32, __pad, arg_u32p(length)) +{ + return ksys_truncate(pathname, arg_u64(length)); +} + +COMPAT_SYSCALL_DEFINE4(aarch32_ftruncate64, unsigned int, fd, u32, __pad, + arg_u32p(length)) +{ + return ksys_ftruncate(fd, arg_u64(length)); +} + +COMPAT_SYSCALL_DEFINE5(aarch32_readahead, int, fd, u32, __pad, + arg_u32p(offset), size_t, count) +{ + return ksys_readahead(fd, arg_u64(offset), count); +} + +COMPAT_SYSCALL_DEFINE6(aarch32_fadvise64_64, int, fd, int, advice, + arg_u32p(offset), arg_u32p(len)) +{ + return ksys_fadvise64_64(fd, arg_u64(offset), arg_u64(len), advice); +} + +COMPAT_SYSCALL_DEFINE6(aarch32_sync_file_range2, int, fd, unsigned int, flags, + arg_u32p(offset), arg_u32p(nbytes)) +{ + return ksys_sync_file_range(fd, arg_u64(offset), arg_u64(nbytes), + flags); +} + +COMPAT_SYSCALL_DEFINE6(aarch32_fallocate, int, fd, int, mode, + arg_u32p(offset), arg_u32p(len)) +{ + return ksys_fallocate(fd, mode, arg_u64(offset), arg_u64(len)); +} #undef __SYSCALL #define __SYSCALL(nr, sym) [nr] = (syscall_fn_t)sym, From patchwork Wed Jul 11 13:56:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 141759 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp322137ljj; Wed, 11 Jul 2018 06:58:21 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfjuKok2Kgm7kDL/1qC9elTAxSpsKrzSAjSdgKpw/pFOwIVrKlz/2vwQMu4NfjOD1Blzc02 X-Received: by 2002:a17:902:bd97:: with SMTP id q23-v6mr28646633pls.238.1531317501518; Wed, 11 Jul 2018 06:58:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531317501; cv=none; d=google.com; s=arc-20160816; b=gjjyIuZqeZiMQx6HhcIXlbazOacvuHN988TCfk+npCZkG/9vgnxzoXwCjNKTaejmtI prbM7R2fi2fO+gZh+Ohm1gneyMoG9NLi+ZEcqzytngRHUXrWRSkESrz6Qrce4PjEumYH dCGiEL9q/0tXH5Dhh0uQfsZV0PnqGlNd2b958B4NDQ0esdPpkzSQVz2TyF+/ymp8n7Vt 5ANBniTm7GvRDXT2KbuvufsWgtG+tjn4CwKEwqj6dK5k0ZFu67Je/RvHgjkOwL5QCDFi UtKUvFOyxgs6uaB74INl7I4J9N900tXubfLBDvNZMd0v+gGNYqGusf9lvPbCTurZLVoG fCYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=hBKzaMntS0wE9ypNgB/KbupJFzLHEI7dT5IkGSbWnQE=; b=0eoQwXm088owMG+AwnLxQYId0NRg8zuyVo5bEd38KjVk6iXNOJueAedtHifbjmLy2t QTk081YVZ9Q/5SpAuafSQ4+UxhvCGt02W75hMuCf1mPEzwOiKQ6wSqHLLkLV6kVr3Rlc emEsMJoOymRMQNBVXqsvD48oyOZU/UwuBUEav1OBi6NIPVwYnUaU8y4c8pxBkCGA/KEf RfIzxALjGYP/1GUBoGbD8VHuivKZFZQXY5vHDht+fwa0yH8GpEJ02XhFD1fpNKkLsCR4 LkMTFdefVw/QgKElK9Qs7Nvpc8n3HbEyK6O1YHMpJ5gKpT2sEeNC5cQFrhBPJWrLDOJr TYVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v16-v6si19294142plo.186.2018.07.11.06.58.21; Wed, 11 Jul 2018 06:58:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388656AbeGKOCr (ORCPT + 23 others); Wed, 11 Jul 2018 10:02:47 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:36498 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388274AbeGKOCq (ORCPT ); Wed, 11 Jul 2018 10:02:46 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 827DB2D95; Wed, 11 Jul 2018 06:58:17 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 72A613F5B1; Wed, 11 Jul 2018 06:58:15 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com Cc: catalin.marinas@arm.com, dave.martin@arm.com, hch@infradead.org, james.morse@arm.com, linux@dominikbrodowski.net, linux-fsdevel@vger.kernel.org, marc.zyngier@arm.com, mark.rutland@arm.com, viro@zeniv.linux.org.uk Subject: [PATCHv5 21/21] arm64: implement syscall wrappers Date: Wed, 11 Jul 2018 14:56:56 +0100 Message-Id: <20180711135656.20670-22-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180711135656.20670-1-mark.rutland@arm.com> References: <20180711135656.20670-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To minimize the risk of userspace-controlled values being used under speculation, this patch adds pt_regs based syscall wrappers for arm64, which pass the minimum set of required userspace values to syscall implementations. For each syscall, a wrapper which takes a pt_regs argument is automatically generated, and this extracts the arguments before calling the "real" syscall implementation. Each syscall has three functions generated: * __do_sys_ is the "real" syscall implementation, with the expected prototype. * __se_sys_ is the sign-extension/narrowing wrapper, inherited from common code. This takes a series of long parameters, casting each to the requisite types required by the "real" syscall implementation in __do_sys_. This wrapper *may* not be necessary on arm64 given the AAPCS rules on unused register bits, but it seemed safer to keep the wrapper for now. * __arm64__sys_ takes a struct pt_regs pointer, and extracts *only* the relevant register values, passing these on to the __se_sys_ wrapper. The syscall invocation code is updated to handle the calling convention required by __arm64__sys_, and passes a single struct pt_regs pointer. The compiler can fold the syscall implementation and its wrappers, such that the overhead of this approach is minimized. Note that we play games with sys_ni_syscall(). It can't be defined with SYSCALL_DEFINE0() because we must avoid the possibility of error injection. Additionally, there are a couple of locations where we need to call it from C code, and we don't (currently) have a ksys_ni_syscall(). While it has no wrapper, passing in a redundant pt_regs pointer is benign per the AAPCS. When ARCH_HAS_SYSCALL_WRAPPER is selected, no prototype is defines for sys_ni_syscall(). Since we need to treat it differently for in-kernel calls and the syscall tables, the prototype is defined as-required. The wrappers are largely the same as their x86 counterparts, but simplified as we don't have a variety of compat calling conventions that require separate stubs. Unlike x86, we have some zero-argument compat syscalls, and must define COMPAT_SYSCALL_DEFINE0() to ensure that these are also given an __arm64_compat_sys_ prefix. Signed-off-by: Mark Rutland Reviewed-by: Dominik Brodowski Reviewed-by: Catalin Marinas Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/syscall.h | 4 +- arch/arm64/include/asm/syscall_wrapper.h | 80 ++++++++++++++++++++++++++++++++ arch/arm64/kernel/sys.c | 10 +++- arch/arm64/kernel/sys32.c | 9 +++- arch/arm64/kernel/syscall.c | 5 +- 6 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 arch/arm64/include/asm/syscall_wrapper.h -- 2.11.0 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 42c090cf0292..2089aa3f27bc 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -24,6 +24,7 @@ config ARM64 select ARCH_HAS_SG_CHAIN select ARCH_HAS_STRICT_KERNEL_RWX select ARCH_HAS_STRICT_MODULE_RWX + select ARCH_HAS_SYSCALL_WRAPPER select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_HAVE_NMI_SAFE_CMPXCHG select ARCH_INLINE_READ_LOCK if !PREEMPT diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h index b83d0e6980a3..ad8be16a39c9 100644 --- a/arch/arm64/include/asm/syscall.h +++ b/arch/arm64/include/asm/syscall.h @@ -20,9 +20,7 @@ #include #include -typedef long (*syscall_fn_t)(unsigned long, unsigned long, - unsigned long, unsigned long, - unsigned long, unsigned long); +typedef long (*syscall_fn_t)(struct pt_regs *regs); extern const syscall_fn_t sys_call_table[]; diff --git a/arch/arm64/include/asm/syscall_wrapper.h b/arch/arm64/include/asm/syscall_wrapper.h new file mode 100644 index 000000000000..a4477e515b79 --- /dev/null +++ b/arch/arm64/include/asm/syscall_wrapper.h @@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * syscall_wrapper.h - arm64 specific wrappers to syscall definitions + * + * Based on arch/x86/include/asm_syscall_wrapper.h + */ + +#ifndef __ASM_SYSCALL_WRAPPER_H +#define __ASM_SYSCALL_WRAPPER_H + +#define SC_ARM64_REGS_TO_ARGS(x, ...) \ + __MAP(x,__SC_ARGS \ + ,,regs->regs[0],,regs->regs[1],,regs->regs[2] \ + ,,regs->regs[3],,regs->regs[4],,regs->regs[5]) + +#ifdef CONFIG_COMPAT + +#define COMPAT_SYSCALL_DEFINEx(x, name, ...) \ + asmlinkage long __arm64_compat_sys##name(const struct pt_regs *regs); \ + ALLOW_ERROR_INJECTION(__arm64_compat_sys##name, ERRNO); \ + static long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \ + static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \ + asmlinkage long __arm64_compat_sys##name(const struct pt_regs *regs) \ + { \ + return __se_compat_sys##name(SC_ARM64_REGS_TO_ARGS(x,__VA_ARGS__)); \ + } \ + static long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \ + { \ + return __do_compat_sys##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \ + } \ + static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) + +#define COMPAT_SYSCALL_DEFINE0(sname) \ + asmlinkage long __arm64_compat_sys_##sname(void); \ + ALLOW_ERROR_INJECTION(__arm64_compat_sys_##sname, ERRNO); \ + asmlinkage long __arm64_compat_sys_##sname(void) + +#define COND_SYSCALL_COMPAT(name) \ + cond_syscall(__arm64_compat_sys_##name); + +#define COMPAT_SYS_NI(name) \ + SYSCALL_ALIAS(__arm64_compat_sys_##name, sys_ni_posix_timers); + +#endif /* CONFIG_COMPAT */ + +#define __SYSCALL_DEFINEx(x, name, ...) \ + asmlinkage long __arm64_sys##name(const struct pt_regs *regs); \ + ALLOW_ERROR_INJECTION(__arm64_sys##name, ERRNO); \ + static long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \ + static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \ + asmlinkage long __arm64_sys##name(const struct pt_regs *regs) \ + { \ + return __se_sys##name(SC_ARM64_REGS_TO_ARGS(x,__VA_ARGS__)); \ + } \ + static long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \ + { \ + long ret = __do_sys##name(__MAP(x,__SC_CAST,__VA_ARGS__)); \ + __MAP(x,__SC_TEST,__VA_ARGS__); \ + __PROTECT(x, ret,__MAP(x,__SC_ARGS,__VA_ARGS__)); \ + return ret; \ + } \ + static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) + +#ifndef SYSCALL_DEFINE0 +#define SYSCALL_DEFINE0(sname) \ + SYSCALL_METADATA(_##sname, 0); \ + asmlinkage long __arm64_sys_##sname(void); \ + ALLOW_ERROR_INJECTION(__arm64_sys_##sname, ERRNO); \ + asmlinkage long __arm64_sys_##sname(void) +#endif + +#ifndef COND_SYSCALL +#define COND_SYSCALL(name) cond_syscall(__arm64_sys_##name) +#endif + +#ifndef SYS_NI +#define SYS_NI(name) SYSCALL_ALIAS(__arm64_sys_##name, sys_ni_posix_timers); +#endif + +#endif /* __ASM_SYSCALL_WRAPPER_H */ diff --git a/arch/arm64/kernel/sys.c b/arch/arm64/kernel/sys.c index f249d9735f4c..b44065fb1616 100644 --- a/arch/arm64/kernel/sys.c +++ b/arch/arm64/kernel/sys.c @@ -50,11 +50,17 @@ SYSCALL_DEFINE1(arm64_personality, unsigned int, personality) /* * Wrappers to pass the pt_regs argument. */ -asmlinkage long sys_rt_sigreturn(void); #define sys_personality sys_arm64_personality +asmlinkage long sys_ni_syscall(const struct pt_regs *); +#define __arm64_sys_ni_syscall sys_ni_syscall + +#undef __SYSCALL +#define __SYSCALL(nr, sym) asmlinkage long __arm64_##sym(const struct pt_regs *); +#include + #undef __SYSCALL -#define __SYSCALL(nr, sym) [nr] = (syscall_fn_t)sym, +#define __SYSCALL(nr, sym) [nr] = (syscall_fn_t)__arm64_##sym, const syscall_fn_t sys_call_table[__NR_syscalls] = { [0 ... __NR_syscalls - 1] = (syscall_fn_t)sys_ni_syscall, diff --git a/arch/arm64/kernel/sys32.c b/arch/arm64/kernel/sys32.c index a205d4ff4776..0f8bcb7de700 100644 --- a/arch/arm64/kernel/sys32.c +++ b/arch/arm64/kernel/sys32.c @@ -133,8 +133,15 @@ COMPAT_SYSCALL_DEFINE6(aarch32_fallocate, int, fd, int, mode, return ksys_fallocate(fd, mode, arg_u64(offset), arg_u64(len)); } +asmlinkage long sys_ni_syscall(const struct pt_regs *); +#define __arm64_sys_ni_syscall sys_ni_syscall + +#undef __SYSCALL +#define __SYSCALL(nr, sym) asmlinkage long __arm64_##sym(const struct pt_regs *); +#include + #undef __SYSCALL -#define __SYSCALL(nr, sym) [nr] = (syscall_fn_t)sym, +#define __SYSCALL(nr, sym) [nr] = (syscall_fn_t)__arm64_##sym, const syscall_fn_t compat_sys_call_table[__NR_compat_syscalls] = { [0 ... __NR_compat_syscalls - 1] = (syscall_fn_t)sys_ni_syscall, diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index d1c66e6bd359..1b1f3a329977 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -15,6 +15,8 @@ long compat_arm_syscall(struct pt_regs *regs); +long sys_ni_syscall(void); + asmlinkage long do_ni_syscall(struct pt_regs *regs) { #ifdef CONFIG_COMPAT @@ -31,8 +33,7 @@ asmlinkage long do_ni_syscall(struct pt_regs *regs) static long __invoke_syscall(struct pt_regs *regs, syscall_fn_t syscall_fn) { - return syscall_fn(regs->regs[0], regs->regs[1], regs->regs[2], - regs->regs[3], regs->regs[4], regs->regs[5]); + return syscall_fn(regs); } static void invoke_syscall(struct pt_regs *regs, unsigned int scno,