From patchwork Mon Jul 2 11:03:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140724 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3853999ljj; Mon, 2 Jul 2018 04:04:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpddzbPeSMZjHkwoj33GO+p4nOsEoE/pZ5Cd2xCCGHOAKqm9hbpUbZx2b6kgT6CXf9oDzFDA X-Received: by 2002:a65:41c6:: with SMTP id b6-v6mr7824475pgq.174.1530529472909; Mon, 02 Jul 2018 04:04:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529472; cv=none; d=google.com; s=arc-20160816; b=wNhGYRUGpmNJsdTYVdJrqVelSPeWw1mfhEA4karJdKmHAxxJ5X7GT4wVN2aXXonFBX zEE6zzoc1WEm7x8f4GvY8vgbPjg86U/A5QfcQF8Haa3wbu+qPR/kS8R41zjUzAOIoKvF ZeO2jtG0gpuFDz4kXIZ5J2Q2w5dLQjPyV3TicnK9YDHEZLmbP6iBtw7uRjZmvWDDsvV9 jwA4o7POk2iNa5d91mEooCOouapmFc77lpvzEfqWXZOP68qaolZXnMsxzC9OQ9xUK8VD e8VzEcm9nzFkegATK2qLSghMAcRuwfwnPt4wnztlGOQJAIRvMRri91VrwCwucTGwMS0J gfYw== 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=xqrZHPcfElVdDARNYwfhw+JIkWRpcWHThq2hcTtCcr3TzjcHy6HOYvChUtKtBnd194 ngp0FqpcsQjJd12yUv2CmkK17aaBO0V07QU91IrF309+TUKX6s/sAo6l/Mxlry/p80Up NoIAEmD01gKbg3602sJIdSSFTCzWH5gYinGsYxMpBWYCCmlY8lMitR+BIdjSdZysp/4C nbqHdUTvgcRRS1wb2fny8BsqYz2l8jrcFKOimTbVSLCUjTxcKzGrgJ9JOwM8Vjefpggf 7H4O7Qp5CC9ub/J6DGIsCfkAlEEoxSGHgtusSTy4a674L66dHwZNROdmXnLA/EhDWf/I LVLA== 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 b9-v6si17896170plk.111.2018.07.02.04.04.32; Mon, 02 Jul 2018 04:04: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 S934202AbeGBLEa (ORCPT + 31 others); Mon, 2 Jul 2018 07:04:30 -0400 Received: from foss.arm.com ([217.140.101.70]:57442 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933051AbeGBLEZ (ORCPT ); Mon, 2 Jul 2018 07:04: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 E03A81529; Mon, 2 Jul 2018 04:04:24 -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 C662A3F5BA; Mon, 2 Jul 2018 04:04:22 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 01/19] arm64: consistently use unsigned long for thread flags Date: Mon, 2 Jul 2018 12:03:57 +0100 Message-Id: <20180702110415.10465-2-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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 Mon Jul 2 11:03:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140742 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3859291ljj; Mon, 2 Jul 2018 04:09:33 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK+N5GbbqVxWEDhxUcbv/MzeuNRUJXscGz+l+PXcIDuRAwrH293nAx0QfgIrAOKDz3iiIE4 X-Received: by 2002:a65:6114:: with SMTP id z20-v6mr21523053pgu.312.1530529773810; Mon, 02 Jul 2018 04:09:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529773; cv=none; d=google.com; s=arc-20160816; b=xv7vDFsn45Qx8PELN6CoYn/EPLru99E5he+Wj/E6TTFCG7ofQsOO9YmSaLt3BkifuI Z6ZtjPmZVmaZCmZ2a77TIBNrxiapEmnnv7NP8H+7neIxEJrGcqn5XuJz58cKfO+QzTiu OV5xUmCzDkJDMGg5y9wkVYjhhgZMbkPHPRm7VO+rsj86g2ZqAXb7IISTOpm12pke5vT0 EGjcWYjy/LGztzv4jDqdtlM5OmoPMCIAZiQuQZlM+QXX9jwqOmDNAp6TtlroxwzsHgMD QPUH1rUAK3szMvTfHNaY4xKKBXktJ/Dz4t3Ukav+z1v6ZUWXqD6vPAvlOpU7UtWmrSb5 MRqw== 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=xIzNp+yLgyYeEXNJhkm1CJRGhnH1JD7kKlp8MOy2KIJaFo3JN0O8J3YWTQUgfJxp+z 2KENRf5URFCYzuTBdn8hSAu18rP9ihw3/vLofNh4xKAqVORvUFHrpicdv11yNQ6NkfS9 epfZGdVnHTn68akjan+0YDfZYjXGNUO3dhFatB7UkhqWdSykWx6omtFTEHZAU7A6Vqlt 2Ifq21ukyc+i8x6MoKwd3e0XKh6ODnCwdGttLqK3LTCKqWrD67iAm0b9pSHyrY0841zC Y4HiRwx/ESt91FAzMjCszQnEMIcTy/CDC9MIRWrpEJ9RgiYZgAktRQWRiMxhwwIJHkV8 yzVw== 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 i184-v6si4375613pfg.250.2018.07.02.04.09.33; Mon, 02 Jul 2018 04:09:33 -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 S934028AbeGBLJc (ORCPT + 31 others); Mon, 2 Jul 2018 07:09:32 -0400 Received: from foss.arm.com ([217.140.101.70]:57456 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934171AbeGBLE2 (ORCPT ); Mon, 2 Jul 2018 07:04:28 -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 A9DB715AD; Mon, 2 Jul 2018 04:04:27 -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 997C93F5BA; Mon, 2 Jul 2018 04:04:25 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 02/19] arm64: move SCTLR_EL{1, 2} assertions to Date: Mon, 2 Jul 2018 12:03:58 +0100 Message-Id: <20180702110415.10465-3-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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 Mon Jul 2 11:03:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140725 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3854095ljj; Mon, 2 Jul 2018 04:04:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKuiGpNAH1q8UUDFzSiz/3UOkyaejdthUVTu/nkiQERSjKehhR4I5qEcvxbAQAZ0Zmh5sSj X-Received: by 2002:a17:902:7202:: with SMTP id ba2-v6mr24866814plb.119.1530529477308; Mon, 02 Jul 2018 04:04:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529477; cv=none; d=google.com; s=arc-20160816; b=NOrxDW72ko1xphajC+2x4nSIHRdkJehwVWK/aXapmxQs3xe9RtX3GStUQ1aTR4rx/J GHJLryYZsf1DQhV2HiRYG6rUX31wphnyKveXz4D+9HDXtlvReaOSfXK+7rczSwXNuFON 0wmaKtkOTJsfgVbAExpnSvj3kRmlACRfjhHAV6Cpt70gjyTsiignp5LAxsO6joATmePf YYMJ94L/JSebziNFbarefD/U2qTeQRh1t5eXxh+BTPRGecBsao4e2Z3g8GS2MBKe/4gK 7DG5H94h3kHJPU1aEBQHxsmzVEYL2mgV4Bp+E3prl87eIVrWjf8FkH/oZ/jG6norqVhY fjKw== 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=FFvyokqwDGJWMrxNlvMxiopATndbyXU96bY+yciy4GaJfzV/UkWD9TRjaIqIpEFgu4 C7BGjzwE954HVLNHZBkb+YBh7MKPlkZQSXO+wxc+0uz32P1JtVjimlth1ft7EGTGKwpr N652IQIsPkK3FV7gdJ9YTZvb3c61dhhmtirUgTYApjePra48+IJaw5DO3pX5A4tpDVjh SHZKDo/RgzWWFV9TjkK4Pn2eqt0skthkh8fT9IDe/YN4bqBQhZMQF6ii2rpxkGbF6j5x TQ4nZQFYQ+/TYyfKv/9YVBSMJbNqNFhRai6xTyaFrsFrQvl9BJTQyHyIDDhfgVVzRQfz 3znQ== 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 g6-v6si6756237pgq.240.2018.07.02.04.04.36; Mon, 02 Jul 2018 04:04:37 -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 S1030277AbeGBLEe (ORCPT + 31 others); Mon, 2 Jul 2018 07:04:34 -0400 Received: from foss.arm.com ([217.140.101.70]:57468 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934201AbeGBLEa (ORCPT ); Mon, 2 Jul 2018 07:04: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 753FD1650; Mon, 2 Jul 2018 04:04:30 -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 64BEA3F5BA; Mon, 2 Jul 2018 04:04:28 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 03/19] arm64: kill config_sctlr_el1() Date: Mon, 2 Jul 2018 12:03:59 +0100 Message-Id: <20180702110415.10465-4-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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 Mon Jul 2 11:04:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140741 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3858745ljj; Mon, 2 Jul 2018 04:08:58 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcJq9uQITra4QuLDWopPCYvtIaMLBnebFZY6FtD+u+m2UXafxmGkOOl1+aYcFAEtm2VeqCS X-Received: by 2002:a17:902:da4:: with SMTP id 33-v6mr16800673plv.193.1530529737996; Mon, 02 Jul 2018 04:08:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529737; cv=none; d=google.com; s=arc-20160816; b=qdGYj43ilYU6l5MCwXhOivMFSJ8EDwVLfe08daym939oEHjwVXVE3GMLTWylhIHJbj nP02KdaVW2tBVV9JjlAp0xpYMiXJlia398Ae6WgLOFayo5D74JwdgvdW6F6jHkO33jaC KyrXirG3+sb0o7jFHwVpiYMRHqFX3/fBJu6lwRR5g1DuvJzme3xhzmoFryfzooa4x3cu /KwWbPTJSK993AsAhOGdF633IX3aBi7gyDFCmw5zsRyPmdBflMMv56pvLjVWmhiw0JYR 7xpEGjMHfhre2AExrTPbs6DrAQ3NmSOSA0h1oykOWMFnzhwgfgIP225CzCbXyVy6o2Ec xrQQ== 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=VaqMpkzZi822f7P6QmRtS8CKziYUPB59lvkoOtm32VAj819qyysNhy2UIiKCrFjNCy 5MsQKA1LTNpn877WrTIiu1qLvab1OZatYlFlvhmZa3IMbXYYP8unaw0i40rH1e6YcfOj fjqoHV1ihZZJa5Y4zzwBk2CytccFPZCTsQy8CUpYWC0P2pH75Tsh2g73gOz3+LieuwiK F96yX3AZYDH1abVhT06xW7WcoUL68eI9HaApGjnE3IouzmNsgzS3rqPmvP1I+kszbmoV /17tsPqGE7wVUiJNM6IdWkYnpWQQdEw74oopu6+v8PJiMh7QbZ8DIb5NW7EUYnUzaxIA tknA== 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 i184-v6si4375613pfg.250.2018.07.02.04.08.57; Mon, 02 Jul 2018 04:08:57 -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 S1754359AbeGBLIz (ORCPT + 31 others); Mon, 2 Jul 2018 07:08:55 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:57480 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934215AbeGBLEd (ORCPT ); Mon, 2 Jul 2018 07:04: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 290B51682; Mon, 2 Jul 2018 04:04:33 -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 1888E3F5BA; Mon, 2 Jul 2018 04:04:30 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 04/19] arm64: kill change_cpacr() Date: Mon, 2 Jul 2018 12:04:00 +0100 Message-Id: <20180702110415.10465-5-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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 Mon Jul 2 11:04:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140726 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3854173ljj; Mon, 2 Jul 2018 04:04:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdDcPyIzEN2s99uiqapgyQgZJYvf3bCq5tv4iGKnx2xJAIJDzU2m+yugSGXv8iBSmGvKbzP X-Received: by 2002:a63:7007:: with SMTP id l7-v6mr15918934pgc.206.1530529482693; Mon, 02 Jul 2018 04:04:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529482; cv=none; d=google.com; s=arc-20160816; b=vkchgWdFb1ViWwGVsuVPpoWWe2EWcU+Qdjy1uSbrhVEvmeK3cji2P9zoXVE9nYQ4Uv aW1dO0YboYhRatzo5A8sODrrl/xpiSk8J7382v8LF02F96gG9QTniqKuJfcJoGCHBueX dFRPYbSRAbPcbaZMhGFdY17HRb98ZEab2yYcelQ59dKSnAgu8FdRmRF5dEXbD2w+zkxV qxp63rWV4CBUVZsGnUydVajNlyZrWOIcNBIMMhSfG7EMs6ceTF3qUveA+AZ0gcNuMRkE oGDQvtsmzXn13erPi2fz2Yjpmx+HA+0go4U9Ax6NG0oX8tFtuGz8rSxCb3WE4L1a08gQ dD6g== 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=yW15KdnEva7ccBbSn15RvtIx2eLPg3Wkal7DQilv0/UK3dc3EwvvL9IpTbRV7L8VpI Ok1Wq9N91Wwwl53TSO6sPnYe7asUhEVuwy6nvtyHxIy2ABCqbH2oyCz6ie0XHHPxcF3i +6zEdlx6kNx++oFcWQ/Bc8Arte50i3xJFk+y2zG6bW+zJwbx/cnof8mgK3gwAihbEFns WtG5CSYQpX15vO6D9gXiwFFkAjqf+HjoUk1NiM4CRcFx66WfU43yqRRlBceaMDE5nT0d we8UFaSNz98Wjw/D2cX0BbaG7qCmxt73MQCpA2IOfM89ysXWWZS/9xsC+zKZnTmfm78n j1lQ== 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 g6-v6si6756237pgq.240.2018.07.02.04.04.42; Mon, 02 Jul 2018 04:04: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 S1030350AbeGBLEk (ORCPT + 31 others); Mon, 2 Jul 2018 07:04:40 -0400 Received: from foss.arm.com ([217.140.101.70]:57490 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030288AbeGBLEg (ORCPT ); Mon, 2 Jul 2018 07:04: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 D4F421688; Mon, 2 Jul 2018 04:04:35 -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 C466C3F5BA; Mon, 2 Jul 2018 04:04:33 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 05/19] arm64: move sve_user_{enable, disable} to Date: Mon, 2 Jul 2018 12:04:01 +0100 Message-Id: <20180702110415.10465-6-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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 Mon Jul 2 11:04:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140740 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3858419ljj; Mon, 2 Jul 2018 04:08:39 -0700 (PDT) X-Google-Smtp-Source: AAOMgpccga32kOgVCl4HJN8upFnneletCWPvL4yHbcOQhaQVUy/wMLYXIIUGr7wrp0FV5cZpBCIC X-Received: by 2002:a62:dd8:: with SMTP id 85-v6mr25047836pfn.202.1530529719690; Mon, 02 Jul 2018 04:08:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529719; cv=none; d=google.com; s=arc-20160816; b=lAeQ1FwlGvQOCe6niuzH3GYjIlC6A/TOOwbKn6XAcyWtX+l6MiaWnZfIjig9t+SEuR pYJg/x+YKtOg2P/VoTOeVZQi9a8SKlgAi6gn8yc87QGbuNT6uYf5z5lxeFf+QyzWJIy7 qX9CPdmr5oC4rQXAfifWEedPo1NMd42A76Gi99hTXDhdbKDlUtCMYDrerOHbS+4puUef fH8BSzdcgEj0DAG066J7NYaJsH0fjLcjGwQyVHYle2f7lWurJcZ/+EDlnmk78U/9L1/4 uah7QH1M2CA6nQj4KQxGDUKkYs/nw99qpwS8rkCBj9I/IGxHa9ad1hV3vs0l0xfIoGDQ svcw== 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=ZRQ2Hi1zPuOvFLExfsvHBkiGX8fCRjWyM1lz55VQUHOzkfqnU4GKiy020FbgFNuaQh WjX1ODb4TUZ8guaW0xIPbUkri3iENsx6jHEZvfcmUq93C6/K9mS1p3oDp8Ro8Vra40Jo T2NHycY33GA28WtetylqWbPoT+YNrNZHIWAR25rswrj9wgljbf4+WbZD/D3qvLtddmLd JUSjTHwcz+9MEEQaSv/DkXkt2iladDr1KXXMdu2Jyoqt2/SjzceR6J1uApoQlXEC3+KC fv/J5nrZVOQu7AiK4/zuJ35Mj9rRCDEfpdAknB++EJWvIZWjfa+fm4hsPKKJL2cAcBZa L8zQ== 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 n5-v6si9782485pgq.167.2018.07.02.04.08.39; Mon, 02 Jul 2018 04:08:39 -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 S934120AbeGBLIi (ORCPT + 31 others); Mon, 2 Jul 2018 07:08:38 -0400 Received: from foss.arm.com ([217.140.101.70]:57504 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933305AbeGBLEj (ORCPT ); Mon, 2 Jul 2018 07:04: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 9FDE116A3; Mon, 2 Jul 2018 04:04:38 -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 8FB6B3F5BA; Mon, 2 Jul 2018 04:04:36 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 06/19] arm64: remove sigreturn wrappers Date: Mon, 2 Jul 2018 12:04:02 +0100 Message-Id: <20180702110415.10465-7-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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 Mon Jul 2 11:04:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140727 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3854316ljj; Mon, 2 Jul 2018 04:04:51 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKpxY7vjyLyg4LplqctuddOzrC1M7O1DZVa36mqA6CiXz2TdivGxYGq2G2GfYzn52v/UcpV X-Received: by 2002:a63:a319:: with SMTP id s25-v6mr21436684pge.62.1530529491455; Mon, 02 Jul 2018 04:04:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529491; cv=none; d=google.com; s=arc-20160816; b=BctSn8yF7ytCH5HwLDlJXC10XvVt66qdaV/R3kBKtxDODmrUraCyDQDf9kbpEsfLYg MuMNMR8BKX7xKHGAZw6TDY6A5OfrNEftp2EmGc3yzf5RTb3WvO28ygwK4UfA1r69FGT+ sijwBa2ACzDdF98fd+7h6p8RZ8d32STdCCktpYHPiEePTqQJeD7dUaMjSFMu/NfanF/P +AUiVlcrWTfwNShzg8moTYVii9qGiOjDddNbVQqWXcNIkcmjw5rnpEv0lUN/sHuiehw2 cb8dbou03dlv3aPS7p+dNat+qlONH0kmGDegKJHvD0WZeVfM5bR5sxM9vuhyc7M5uwc/ DCzw== 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=qP1JbiGEHzcgsNqXZaaAv+4rVCCgQyflHV1xu4k6d0E=; b=gm9Ro9kWKVNnhscxTrc7jDlIIiBEETHgi6KyEbs6nw7hFs7U+fhuZItReJOs9CzJKv Qvg571MkKd/An42xFGav0OmzITCErkc5XW3fQfAuITgjwy8QXrQqsy5PkR0UEXdTnqNK 5Ut6F2CZOLKjGd/kPRTyNKf2s4PhXEXzF+vrv8cfDnERY/eHMbUujCeXla1rz2lcey/f 78HA2vemt1KIOTsuhSAecxWKv7CL4XA1P+jyFsrL2PsjFMTFcQQnn/r4jnBhQsX0yAVY gB3qo7hOmGQuXMYxcQEWGFdNNupXrekb+FtF0/9OSmWI27694sFDsWwnlccCE4LmPWkX Kk4g== 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 g2-v6si15461238pfi.212.2018.07.02.04.04.51; Mon, 02 Jul 2018 04:04: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 S1030370AbeGBLEs (ORCPT + 31 others); Mon, 2 Jul 2018 07:04:48 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:57510 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030288AbeGBLEl (ORCPT ); Mon, 2 Jul 2018 07:04:41 -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 72EAE1713; Mon, 2 Jul 2018 04:04: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 62BA83F5BA; Mon, 2 Jul 2018 04:04:39 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 07/19] arm64: convert raw syscall invocation to C Date: Mon, 2 Jul 2018 12:04:03 +0100 Message-Id: <20180702110415.10465-8-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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 | 49 +++++++++++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/traps.c | 16 --------------- 4 files changed, 61 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..8bc2530c8472 --- /dev/null +++ b/arch/arm64/kernel/syscall.c @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: GPL-2.0 + +#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(); +} + +typedef long (*syscall_fn_t)(unsigned long, unsigned long, + unsigned long, unsigned long, + unsigned long, unsigned long); + +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, + 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 Mon Jul 2 11:04:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140739 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3858126ljj; Mon, 2 Jul 2018 04:08:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLbjQvLRHtNZwWDfEocME+E0K/wh9CZwoMAoTLkmd6aJHRuiOtSLAzkYJuK8BMq51PoDYTs X-Received: by 2002:a17:902:1e4:: with SMTP id b91-v6mr25382886plb.155.1530529702029; Mon, 02 Jul 2018 04:08:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529702; cv=none; d=google.com; s=arc-20160816; b=evzU6GIKvryQdASz4T7vFcmVxQfV2gKIBsn80GeWjMsosPyC0l/qIQhWLbfzhc8C3g AdfO/1blxrn0tbIEoBRl4wNzVNpjBGI5Xn5lLRVG/8vK868NdofuR6WS0LmxImm2B9Sp Lo/OvykO9914BsBlqMm+uapOfL8dre6tySrTmvM01lLfLww4UkB6/ZpW+a8Qs2tKkF6o 3l6wCT88mxsxnn821+P1zVzEmPRW0lML+DtG8NURdgdmpZAREffNGQGkF1dhLIkvaP90 kTmJ3fnvBtS1YXO5tPZ8ltGPYu61gE9ofY5F1mxLmJ4ZG9Rd7WZF41IO77j4knsjKqCg mlWA== 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=nhlQzTdxWZJGhiUCO7dodA59o5m58dCrXjamqPPBMO0=; b=bMZ3SI5GwVbNiM1S7gj3fXlb/ptBKMzlIMGQN6fp0AiWUkkWl8L/0LBvMNphKdnNV9 OGhpt2IWHujhz2KoZMN8Fo10MolzZABrp3qn8IQKV/FE/kNXXKS5cV2n/vTXA+OCBkVg TS7Uvozt8TTpU/4VBLxDFlgK+wNgMumnWsXU/OCtEjLDiSnAnvxdSTcjn58ogEilQyxS E61flL55Z3tolPeHIoGP8DFdP8NGVvKJQFLEgfFZgsRUJ5eY/bjQjnrCg4a2Y8NAqFDi Dztnz2saykbzES39VWjZ5a2jQ58pklm1faGutfa+mVWJfBof4lItT3zEkVAf70qPq+e+ 2kvg== 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 n5-v6si9782485pgq.167.2018.07.02.04.08.21; Mon, 02 Jul 2018 04:08:22 -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 S933684AbeGBLIS (ORCPT + 31 others); Mon, 2 Jul 2018 07:08:18 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:57520 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030352AbeGBLEo (ORCPT ); Mon, 2 Jul 2018 07:04:44 -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 422D119BF; Mon, 2 Jul 2018 04:04: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 31E793F5BA; Mon, 2 Jul 2018 04:04:42 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 08/19] arm64: convert syscall trace logic to C Date: Mon, 2 Jul 2018 12:04:04 +0100 Message-Id: <20180702110415.10465-9-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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 | 58 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 57 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 8bc2530c8472..e3153ffe7f8e 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -1,10 +1,15 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include #include #include #include #include +#include +#include + long compat_arm_syscall(struct pt_regs *regs); asmlinkage long do_ni_syscall(struct pt_regs *regs) @@ -31,9 +36,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, - syscall_fn_t syscall_table[]) +static void invoke_syscall(struct pt_regs *regs, unsigned int scno, + unsigned int sc_nr, + syscall_fn_t syscall_table[]) { long ret; @@ -47,3 +52,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, + 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 Mon Jul 2 11:04:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140729 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3854574ljj; Mon, 2 Jul 2018 04:05:06 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKLteN/uhRyEtZTJ/r5LtkNRE8rs2kMR70IVhfQJxSYjzEZ3DvYU/0qt4AnP+J3Pv/ccfE6 X-Received: by 2002:a17:902:42c3:: with SMTP id h61-v6mr25338430pld.319.1530529505927; Mon, 02 Jul 2018 04:05:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529505; cv=none; d=google.com; s=arc-20160816; b=U1Fk3ipcf+12tNnBL9tbdOAM4X71AO0v+CugmSBcjbQxUkfn0Nff58EV53HhQ+yHN1 uv6MUjRSF8jA+vjBQ+75TbfFohZoHE+eUpScEGbS7h4BBk0HiGmaxOqfpfLPZYYWlY1+ knZGDBF+1Gv2VwIfAonEwB3MJ7gcDw59E/9d8ZzJuP4QPBoeWQjx134ythrDPco+FgT4 dotvJ9ObebtdtQWLQNFTBllkuqK/kBXd2prgVp5PdsSJWWPMyNShGN3+HbZwajyOPXHh GaVKEBqa3Ygox73r8T+MMW8gWB/rX3oeSa2+3bpAPq8//l7kaaVlIugJ/Fjio6QtyKw3 R+Fg== 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=TXa5+gHWn0cQttziSUEVZxI2S5M4PQBAz40AM59X4Wo=; b=MHHYpod3KjczXhUahuHl91oGyNq+rIkulRjWmAtRHmxgaqvN5WPlIosyIw4bQqnhGp cCjMctI8LmSaKc/dxQ+wymnGZiOF9iBe9X7y8ElRoW81YrQwI8t7OD6wtuicfuCy4kFO TeJtn3aZHOWbLbgQuEjsr6KKYaZbQaVsi1JM0GARRWsCE9VZ4WZ8cDHRnypXj2Ol1fa0 uW+D2EsRNUePfFDq1ZjZe04Z1ixiOeACTAuLhDc8JZVDgy1bSyY/tDANiRDVqYN9SbBK 6z3C7zb4ZTpZk5ZpjcVxFaKHTWcXGG8PQEuNQniT3yWzE8ho4R1DAslboLblfhFcSXTe R/cA== 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 k33-v6si12797585pld.269.2018.07.02.04.05.05; Mon, 02 Jul 2018 04:05: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 S1030437AbeGBLFE (ORCPT + 31 others); Mon, 2 Jul 2018 07:05:04 -0400 Received: from foss.arm.com ([217.140.101.70]:57540 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030359AbeGBLEr (ORCPT ); Mon, 2 Jul 2018 07:04:47 -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 09AFB18A; Mon, 2 Jul 2018 04:04:47 -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 ED63F3F5BA; Mon, 2 Jul 2018 04:04:44 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 09/19] arm64: convert native/compat syscall entry to C Date: Mon, 2 Jul 2018 12:04:05 +0100 Message-Id: <20180702110415.10465-10-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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/kernel/entry.S | 42 ++++-------------------------------------- arch/arm64/kernel/syscall.c | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 40 deletions(-) -- 2.11.0 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 e3153ffe7f8e..ea4fc5eea182 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -8,7 +8,9 @@ #include #include +#include #include +#include long compat_arm_syscall(struct pt_regs *regs); @@ -61,8 +63,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, - syscall_fn_t syscall_table[]) +static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, + syscall_fn_t syscall_table[]) { unsigned long flags = current_thread_info()->flags; @@ -99,3 +101,38 @@ 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(); +} + +extern syscall_fn_t sys_call_table[]; + +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 +extern syscall_fn_t compat_sys_call_table[]; + +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 Mon Jul 2 11:04:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140728 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3854497ljj; Mon, 2 Jul 2018 04:05:02 -0700 (PDT) X-Google-Smtp-Source: AAOMgpej1loDvOo0sRjrsV1yAUl8hYrZy9J2Fc11/pDEiLlxnMi6OQrivdFlkdPSir+IRr8oYfAU X-Received: by 2002:a62:df4e:: with SMTP id u75-v6mr12974127pfg.195.1530529502484; Mon, 02 Jul 2018 04:05:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529502; cv=none; d=google.com; s=arc-20160816; b=x87f4Qe0pt5eKdvpyibvED+9veZYVwITOeQymSXAbLnfkiSk/QROdYdjzjZ4nZFiQM bNTnXkMi7b96QhHv3Z5ULj6ovuXGqX20umwW7xSqHTjgRFjHIKDuhzD8+z/nfJySRPMV gDfb7gtV3dOQKGZOjE5u4ZtpWM2iM3SDGgaJxZPb43faGh/8vBVRQ2upbgq78XIyab+4 eUv2GLZK0xgz3JDJoFVjEj8GIh1cvafzpabp1ykQ/82uQT/n3EDJ8oUrVyFTacxwEyQ2 TIqfkVLS/5U140oqdAIXTo66BY0pHZcHZEFnmk5FV0i+sskuH8NAdUR3hod+axTDru47 cOdw== 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=JHEctIPvorZZzQGOxybEGSzp9TJdm6HDtKM03ZY2HpeXgac6Jf5TGOW4usQ8pnMdRp Qi+HeSruVYucHEPBLrDN0OXnYt3zCBqzzaglcJFCshQajib59mCFHgmT6fyXpqqbzVnD CeFtNiNdBTpR99JclNYKl8lTKuczK9eVDK4vYvg4rx99IT/sVqhx+nqQ8jJNu/QUP/Hb 2zcd2Zf5uqeF2jtPCO8rIXBuFOoQcVJCi8KjiI/PwCm6YhbOYS9SLfhJ5KO0Woh3+Apx bLei5BKMNqX9eW6DBSwDKNg5bwtcRubbHhBsFzPaydPlqCNsNKKS8X/e8/6jNOM7sLE7 lRGg== 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 k33-v6si12797585pld.269.2018.07.02.04.05.02; Mon, 02 Jul 2018 04:05:02 -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 S1030395AbeGBLE7 (ORCPT + 31 others); Mon, 2 Jul 2018 07:04:59 -0400 Received: from foss.arm.com ([217.140.101.70]:57556 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030288AbeGBLEu (ORCPT ); Mon, 2 Jul 2018 07:04:50 -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 CE9D215AD; Mon, 2 Jul 2018 04:04:49 -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 B4BDD3F5BA; Mon, 2 Jul 2018 04:04:47 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 10/19] arm64: don't restore GPRs when context tracking Date: Mon, 2 Jul 2018 12:04:06 +0100 Message-Id: <20180702110415.10465-11-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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 Mon Jul 2 11:04:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140737 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3857220ljj; Mon, 2 Jul 2018 04:07:27 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIXqKDeTlRUgvrekEQt56YgD0MQtY0bRLOMFuxSTMsDS0FgSGBpFOQX04kGzgG0tU4EvmJI X-Received: by 2002:a63:27c1:: with SMTP id n184-v6mr20685613pgn.29.1530529647119; Mon, 02 Jul 2018 04:07:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529647; cv=none; d=google.com; s=arc-20160816; b=hIfmfcHw6Vw2NHMhaWBVdvl6ECFmwGsT4EZowRZCe9VVOhL/48jbuA6OCA8LxWwIte hwjB5SB9NgN4ye1xNIs2SaRH8oUeNQrHgga/9I7+u8aPTVaceL4+kmhqiHqfBE8adnBN D1gB5pSYbPq5aXVfL59J0xXn3iEc95wgFvBPYyf/1Ckg/pE+YP5K0WDN4lyIPbn36TYG YH2DQf1sHwpSHgBFxKMiPeiZ43FmOgeod8iGduNRsvvQEkA2xycmF2oyCNvgALlgqNBf OtHi1Dr6spuPmcyA1e7jd4HhwTRbq5MelV1xwDrCvmA0O3XAZAEpslx2MiFFBdNb2P2n 8Jzg== 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=TWrS2x9BEGelaAuf0VWaOjgvkGy/0PjLgtSFucQDHjY=; b=P/MmeuVj7/WgTK66JrZuOZD8GKuHDbm9fFzcZjGjWKmvoPcCkYogepEsn03WqXKnS1 8mZ99v9KAycE6Pv1m+ti5e/6TWKxf4EjEJuRVn5X/R2p3Y847A+1jx9abBZhwMdD6hnm JP1dP0Y++zu+XsxqsVvJhxkdaTI5WYmgaAgLjW17oznh1y0DCWVabp+puMPJhj8EUf+m bR3/MhrrK2w8iHPkK775b542cyeHtT7diyz4xmvlotspsJclgORVOdZlW3eLQcZ29Jkl WI+Gj+5WMzS2TbRJwutvnwc5JxqV7OeWzE9fjMUgnNNjI20vDpIhWnjYCwM82iYP89Fg 9KxA== 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 b3-v6si16683530pfa.333.2018.07.02.04.07.26; Mon, 02 Jul 2018 04:07: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 S1030415AbeGBLFB (ORCPT + 31 others); Mon, 2 Jul 2018 07:05:01 -0400 Received: from foss.arm.com ([217.140.101.70]:57566 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030372AbeGBLEx (ORCPT ); Mon, 2 Jul 2018 07:04:53 -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 D6F581650; Mon, 2 Jul 2018 04:04:52 -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 C65983F5BA; Mon, 2 Jul 2018 04:04:50 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 11/19] arm64: don't reload GPRs after apply_ssbd Date: Mon, 2 Jul 2018 12:04:07 +0100 Message-Id: <20180702110415.10465-12-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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..728bc7cc5bbb 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 skip_apply_ssbd\@ alternative_cb_end ldr_this_cpu \tmp2, arm64_ssbd_callback_required, \tmp1 - cbz \tmp2, \targ + cbz \tmp2, skip_apply_ssbd\@ ldr \tmp2, [tsk, #TSK_TI_FLAGS] - tbnz \tmp2, #TIF_SSBD, \targ + tbnz \tmp2, #TIF_SSBD, skip_apply_ssbd\@ 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 +skip_apply_ssbd\@: #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 Mon Jul 2 11:04:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140734 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3856391ljj; Mon, 2 Jul 2018 04:06:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLLSyB+dToG3lqlIyRl/UjZPNCmgwkWZ9vW8cBVmDYum03rngOgRzY3uPA0PerISX/5/4ot X-Received: by 2002:a65:6008:: with SMTP id m8-v6mr21589427pgu.134.1530529597322; Mon, 02 Jul 2018 04:06:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529597; cv=none; d=google.com; s=arc-20160816; b=CACLgj/str65XdEdoY3FjDXWpVwEdl/6ne44r9xdzr8oOUw9ygopEoz77YRKiP09jN g6IrEnl1txzht67dv7ggNEB5ekMP6PSWZut+eRmwYcRgHtrihGTDyaDDCLwVDi1eoMP4 gpZKORyPFTVWtlhgpxJyWwmgt65SyTNnzTtEKKinu54gOyjgBcYWm3IpwXA9lzAK4nao H6soeq77qnV/o6+9xq4zPMNgVMsjuEczsR96qABEDC6SZIX8x3tDNnUFTDI0drDpKLyl m900NjMULopGY8JiZcE1MRmEqFvUzqw/DzWoVXd/Xc3LcvPWL0aBW9mU6yT5XHzDJlpI Snww== 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=ISMX0F+EbSwiQFliuirnYHux0bFPkYQXrw6z7Hiil/4=; b=FCJZoIN5lMtyYy1Iuaj54j+pqoOHYyoQo8EUElCk1zoQdjIjFvLugcDrjkx3rFdpZC QIw1gibi+R3HWMy/gWUGu1KeqC20BXB5Sm/uKXvUvAKaooVKIRxmhPBB5lcti08nxygt xYl9RZ7bOxlew6y9VcO8q+lPL8gQaGFAIpucmOf3afTpyiJQjbrjVimaidTnDZqVPvRY RpC6NVYdxKhv9wpT5pcMBevCRRueJamN6Dul+OZBu1dofY5LXi315omdHO/kfKxE+upI pFdnJZBkSll+dpCEqbumE6bjkKlFsUYdakEgfUcvFeEEme3RB9CcN7Td6EFism4CGFUU fcMg== 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 p10-v6si12849379pgn.555.2018.07.02.04.06.36; Mon, 02 Jul 2018 04:06:37 -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 S1030460AbeGBLFI (ORCPT + 31 others); Mon, 2 Jul 2018 07:05:08 -0400 Received: from foss.arm.com ([217.140.101.70]:57584 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030373AbeGBLE4 (ORCPT ); Mon, 2 Jul 2018 07:04:56 -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 B58F61682; Mon, 2 Jul 2018 04:04:55 -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 A512C3F5BA; Mon, 2 Jul 2018 04:04:53 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 12/19] arm64: zero GPRs upon entry from EL0 Date: Mon, 2 Jul 2018 12:04:08 +0100 Message-Id: <20180702110415.10465-13-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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 728bc7cc5bbb..6b7789d72064 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 @@ skip_apply_ssbd\@: 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 @@ skip_apply_ssbd\@: 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 Mon Jul 2 11:04:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140738 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3857500ljj; Mon, 2 Jul 2018 04:07:44 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdL1VgDg96v8aLafmgFqxdIi98Fsuvt8VQHrQrrrQ9veIuz+cZM06P9D67gNuPqlNH2OV2s X-Received: by 2002:a62:9c17:: with SMTP id f23-v6mr15130280pfe.209.1530529664026; Mon, 02 Jul 2018 04:07:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529664; cv=none; d=google.com; s=arc-20160816; b=weCU7O5hSSFgAA8xaTcZUsxFztMcpMTppZzMdJSG/bRtkd9TRGO6/JQLlm6D+XLPCS 2lVx0OCrblPLtvU+6UWVFT1EKXBWTkZqtlo2PgUhNOV3O/JxjyzoFaT+2h3FTWC4FMLi lJKQt9mR0C+qoSOAgdinoj2M1qjFlH8ruJ74k3QadIHHuBAIlYc18c4qS7e6cs0rwtFi bOQKerJgZOu+lB2otYZvw6llJHexR6PnxSz4qrFC/NHQjHrtGMFf3Hn8mHD/phwXn3p4 KC2dpVT7abhUJPRJirWogN77XnziPX+rUsb+RF0ccpyM8OsPDrlE/YU1384f8MNzo/tR 7RBw== 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=r4kz2XTfAWilnhIQ4PbLXyMLsAYhHzSo7tQLyC4G9kmEFKLCGNDPaiWmDznkS56chi 4m/Zl/3k8IB5QfTjQWJI2GIAEmcXOUxEcx6T8c/vjpA7bcYP5pzN5ZiLYU2FxE3pwmP8 H26XsSpiryXm+jnH/QUF0pVArSpgGo/rToAs07r7Yzm9JFFFnWfzawCB+gsIhF0eHzFO rlZflpsIy7xaATgEu6xLCzQqGr1pYwsQ9EbKdcgNS3CvKEjsy5w9Hc1iDBkHU60A2XJ7 lzKTjlhtq3cSDJkW074fpCvxKAf2tWj/Wog+q3T7l/5ex2+/tUFDoj70cW1vs4b8Lhbk n2Jw== 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 a10-v6si15858487pls.480.2018.07.02.04.07.43; Mon, 02 Jul 2018 04:07:44 -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 S965631AbeGBLHm (ORCPT + 31 others); Mon, 2 Jul 2018 07:07:42 -0400 Received: from foss.arm.com ([217.140.101.70]:57600 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030389AbeGBLE7 (ORCPT ); Mon, 2 Jul 2018 07:04: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 F21A01529; Mon, 2 Jul 2018 04:04:58 -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 E1A3A3F5BA; Mon, 2 Jul 2018 04:04:56 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 13/19] kernel: add ksys_personality() Date: Mon, 2 Jul 2018 12:04:09 +0100 Message-Id: <20180702110415.10465-14-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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 Mon Jul 2 11:04:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140730 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3854731ljj; Mon, 2 Jul 2018 04:05:13 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ0Q72mZhAwY0nKuVPgM9xP+jn8QkWDi83NfjYtiRSdq2Cnal84IZEkoFfG378Cfisj4ZqX X-Received: by 2002:a63:2c94:: with SMTP id s142-v6mr20854877pgs.39.1530529512891; Mon, 02 Jul 2018 04:05:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529512; cv=none; d=google.com; s=arc-20160816; b=Te2EQVZryiBFx/y8cllWYZHtJBBL20+Tm+Wm8xYhsjj3CwI+KaSEwlOtIHMg7Isn9D MHhq4ZxQDujjjHs8RRsVF2JbzaAX0e3M/TydzVGnOzTcJAkay4GqzNGiGxoWtjDCDjqj t/r40BVmtFqVolJskUP+0CvGfjB3ZdXS7jVHiAWuIRcODUQiqRpajZ4u8DHDboNKng0z 6G9qaatNeoZ5/zY0Po8Qj+jkInJOv38u9WAniY0mkrINpnXp0qeX7vo2Ql0K3V6nLdkF EoGpnK+IyFRNidqZI65JUt6VSTrpfToVw43CLjrtKV98EopbProQfVm3B4TD0+BQhq+f 67Kg== 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=POh8w0qCvrr8FFfG7ow38R7TZLJDxmfwRlXSNPrb9+R7uEsTi3esEHwqcvzJjD3cmP 8LDUQGz9rraFbyIuqq6HEDxboksKimTGLy7vtR8xLWaf5XOFbm44/uKNmZd2qxG2b22D MpBasQcFI6pNK2sJvvVwwxHwD9vj0EP0lELFROsuAQBKTtS8VgOHfENv36bBeTE/t7fw sD6C/viBR81hWGAzjiIomaiChr2duKjwBXGmwu/iOjnkK8Ut0EgIlbG8kuke1kateqgC kPfHBvckRvLPd6W2U+8GU/IdkLqSAmIZ6EzCq2vBxaALP670QDwelAGmt/3M3Ma+RYZq fS7w== 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 k33-v6si12797585pld.269.2018.07.02.04.05.12; Mon, 02 Jul 2018 04:05:12 -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 S1030475AbeGBLFL (ORCPT + 31 others); Mon, 2 Jul 2018 07:05:11 -0400 Received: from foss.arm.com ([217.140.101.70]:57608 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030417AbeGBLFC (ORCPT ); Mon, 2 Jul 2018 07:05: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 5A06E19F6; Mon, 2 Jul 2018 04:05: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 495D73F5BA; Mon, 2 Jul 2018 04:05:00 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 14/19] kernel: add kcompat_sys_{f,}statfs64() Date: Mon, 2 Jul 2018 12:04:10 +0100 Message-Id: <20180702110415.10465-15-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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 Mon Jul 2 11:04:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140736 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3856821ljj; Mon, 2 Jul 2018 04:07:01 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeFbjdRboUeLSRajsr1rdXYZE2WQh2GB1QuwH46lkSY8ST2Y+X21/WiwAUiTw8I3TNxCdaE X-Received: by 2002:a62:858c:: with SMTP id m12-v6mr361582pfk.173.1530529621728; Mon, 02 Jul 2018 04:07:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529621; cv=none; d=google.com; s=arc-20160816; b=ru97CZnMYihcg4fdPOXZFRYiB1ocnMKc/ZRN2wCgv1ciTcclUakzp6LmVOCD4XEwQV 4Vo9V5IpHNu/bqRERFC1sJipYeYrm6IK+lsANKq/nZ3vpnTDdj8HG3APfaZWKHItIaF5 +lmvq5fQo3XMfiBHEnTFE9KtYMrym8JabgB92euI+viEd9prPX6uPk/khFZbGks661iv bOyBhHgK9DVWPKXwkkm105gq81eTTwGW94+KEPQWfuSfpC3TtOsRi6ioR3Jl2C/1jbZv //QpiN0senFju0nC8nFMgaP5HIL+mAlXiEVbd5Sc5sZW3X/M6nwDF4GSJ4p6Tv8BDrhR wyFQ== 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=Q9Av5dEuw8v8Rup5pOqBRzZBd0A2r1YI7em15Gfj4gs=; b=TM0lE76Ult+DHNTeoPYp9LiweNxY1kbeEqOiKYnjL4IfaMv1NiF3pDA7VFcR5fYBhf kEtZIHKF7BB03fndvbJqI5kqQm+rsE0mJ0LoVBQ1aWtGYsVTvXyxrE8EtFSqR0WdYjTL ati4EUZnZzggXavBAPpyG+IGWKcYvFOD+4dOEvCYgb7MF80hiP+AXhTq957B+BPQp2ua bJBP/rALvcOJ01iViHy5fUcdTVVVAgvP4biwSBgUm2dqiBVRqD2Zij/REP/qkLqrx5bO bjnkYS6kfvq9xUCkKu90/aD+35mCjqVEW1HTLuRZVwa17PeZyAyKFLhmp0XPcZDOofX+ 52ww== 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 n68-v6si14165152pga.662.2018.07.02.04.07.01; Mon, 02 Jul 2018 04:07: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 S965510AbeGBLHA (ORCPT + 31 others); Mon, 2 Jul 2018 07:07:00 -0400 Received: from foss.arm.com ([217.140.101.70]:57618 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030441AbeGBLFF (ORCPT ); Mon, 2 Jul 2018 07:05:05 -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 5D4BB1AC1; Mon, 2 Jul 2018 04:05: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 437D13F5BA; Mon, 2 Jul 2018 04:05:03 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 15/19] arm64: remove in-kernel call to sys_personality() Date: Mon, 2 Jul 2018 12:04:11 +0100 Message-Id: <20180702110415.10465-16-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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 31045f3fed92..a82c3f7a9a90 100644 --- a/arch/arm64/kernel/sys.c +++ b/arch/arm64/kernel/sys.c @@ -42,7 +42,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 Mon Jul 2 11:04:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140735 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3856510ljj; Mon, 2 Jul 2018 04:06:44 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJjfHnzyBgTqKmD5rQ30N+7Xhz80lTd6GC5VH0sUNarj9tm6pwHaAihCFOf+8DCyj4QPdWI X-Received: by 2002:a17:902:758e:: with SMTP id j14-v6mr24838616pll.160.1530529603894; Mon, 02 Jul 2018 04:06:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529603; cv=none; d=google.com; s=arc-20160816; b=PtId8Fe4kK0iYaZSEy3PecsoQSqhh/aDCC7Lv0ouZpjG8ks+AtfN1iplwoYsP/ZV2+ PVoSLevSA7nzT/L5ABdMTihafcv7f5Kf3lLzKzF2ozP4v4PHeJ7gD9EGlTKd9Go+5gDE d4MCLPgPoC2NWID4pH4uxNlTiPiM7bXGgPri2Gc0Y27t/xPowfSVIeBYZzR7soupeu2e oS7mKAmtVID9ZKUMRdndqNIFyRvoKcwUSPxpmtKXS+wNmMOpger53gFOdM0XRkUpZJod I1thtuDHhBTv7nio+TFunq9Hn1oGz/dwZAy7uGLQWlcqDk4Jj6ObYoubcUIwzzV0KBu0 gRZw== 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=TY3hjp9EKT0YUMwhLRq2aHVlBpztNiLR0mVGuuzQ1xM8GDQYlSv0HJO1CYvHMPHFO0 Cg2jAvN3sa5i0CM2TTbnRRdeR+E5nT8iZTgbC9N4jQTBTcbyw8vyZep5lCqiaWKzq55+ elat3gJUKQe8WK48VrCKuYEYp/5z9nme7UsuNOMzG/KBakBDqPGrF5fAE3yZD+JsxjS6 rfBVUBPbvOuwi+LZZKux405xxWJEqm7SaSgnT/kjtrJ+OT0X54w/1liNdkvgekXv85GZ GhWy1r/ARLTJQvsc2wl6yi+z1Bu89wZ7sNnZIsEViXukFz9Oj9gAa9JrH7cQj7vCrPM0 O5iQ== 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 n68-v6si14165152pga.662.2018.07.02.04.06.43; Mon, 02 Jul 2018 04:06:43 -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 S1030348AbeGBLGk (ORCPT + 31 others); Mon, 2 Jul 2018 07:06:40 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:57632 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030458AbeGBLFI (ORCPT ); Mon, 2 Jul 2018 07:05:08 -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 463FC1688; Mon, 2 Jul 2018 04:05: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 35CC63F5BA; Mon, 2 Jul 2018 04:05:06 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 16/19] arm64: use {COMPAT,}SYSCALL_DEFINE0 for sigreturn Date: Mon, 2 Jul 2018 12:04:12 +0100 Message-Id: <20180702110415.10465-17-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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 Mon Jul 2 11:04:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140731 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3854847ljj; Mon, 2 Jul 2018 04:05:18 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK6Os8CpOuQGYao4a3+mZSCBFRk57tXi57RwZ2vzIAWZ4ZJjpsId6+DJg8dlGcF5KaOjCJY X-Received: by 2002:a65:4bcd:: with SMTP id p13-v6mr21495675pgr.114.1530529518525; Mon, 02 Jul 2018 04:05:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529518; cv=none; d=google.com; s=arc-20160816; b=UgxGZQCBrT4NAZK4xOnd2Ps2sSRphbHklXm35fA1NxcfxQy7Pi42+ZnXKXRivnNurY 3MornyKfRIV36kcCC3PnVl0Fwk/exwTsPOduJgvWMUAzj73qdHj5u62JFg7pA3nFOnq5 vvsMX7vXuJcxYHeHI+gH07CtbM4ke+InJuMG/2IA0rUKkeiSswiAUiaSBuxSFb5aY71M z+m8e0aNC92f8fkNo6MaaIC70dKuqJcBFTPzNaWbWOHDzykwMlAb06GRgxHMSZWfFMHI mmOPEWy669xTnrZvxPv4fXfT0ITh7Cg9sgTiAkgztM5JhdipS/GPfwtIRNZI7KJ7L9gD 5VxQ== 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=qsWkevCwNE07DTdRejk7DTpOb3+GGNmbt0qAN0qcE+A=; b=lwc5Dgo0Xsrz8G5bB19JdEDqznit4mQtI4Oe2CiINuWwcBSrT6J5728uM9PhFoXKJC KVTwdlW0xa+Z72NJ0HlSHSF6aCYg59AC2VdKObl9Fn8zoZgiHiEUtI9f/YPzhIzvU+8b Wqkt1mtf8ljDI8vhTKmyAGI1rhbwXErbQIa8447JuV7DWCEz20tttotV050igP+21ugK G7D73QPj5FfOZxH8IEDXVO3N5/6hCH2Qdrl1u3hXMToE6Dx/TLkTrZRiunUmQcL3PnA2 u+Crl+Vbhi4PpgJjMHjOU8RgoEmquM4kwRIX0X3cPhmgJQkiQhRrqTE1V0a7gasqOhjD 23yw== 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 t70-v6si14202698pgc.481.2018.07.02.04.05.18; Mon, 02 Jul 2018 04:05: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 S1030496AbeGBLFP (ORCPT + 31 others); Mon, 2 Jul 2018 07:05:15 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:57646 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030474AbeGBLFL (ORCPT ); Mon, 2 Jul 2018 07:05: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 45CAB1BB2; Mon, 2 Jul 2018 04:05: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 2C0693F5BA; Mon, 2 Jul 2018 04:05:09 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 17/19] arm64: use SYSCALL_DEFINE6() for mmap Date: Mon, 2 Jul 2018 12:04:13 +0100 Message-Id: <20180702110415.10465-18-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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 a82c3f7a9a90..2ad1497a184e 100644 --- a/arch/arm64/kernel/sys.c +++ b/arch/arm64/kernel/sys.c @@ -27,9 +27,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 Mon Jul 2 11:04:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140733 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3855937ljj; Mon, 2 Jul 2018 04:06:13 -0700 (PDT) X-Google-Smtp-Source: ADUXVKILVCkrPiWrnRDQlFw4ni8PIdTnqoRnllG4cnrwXbe0xB6Y4ZJxf2lkpVNFqQvQ3qq6ijIm X-Received: by 2002:a17:902:6903:: with SMTP id j3-v6mr24953086plk.313.1530529573553; Mon, 02 Jul 2018 04:06:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529573; cv=none; d=google.com; s=arc-20160816; b=bqpppJ+tiDgN8qrWuRgE3kh4u0MLfVZhp5vLADvFY0WyGpCMaHg8B34cVUWDkDoGme TdbhsoEqwYreORufYuKLyOxbMjfOO4foMrJUwEiZ7V/lTIlkDJX0fUELTFGplT37ZYvM fIZkNHzjmPSX5Ev5/1gkSIdCT9CNi2iMk7CElYXscGwW1iWnJFGN4c0SInisa7gyt23X sxLL+dqybDRuSLOVxv0+FsUQa9DL2GGwGmY7wNPKCztVXDFScRd4xTLtJ1n9CAuwzhNd F1P1R6Ds0DvfR2pHOlXB9at/+P5eOeUFWqFP2UiSpjjAG79rnydD9xguvvRxhFGKpGqp GUrg== 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=K4JRn2EGnS4j3kMJv6gl7KnzQfEqT+8K5r8fEsY3cKI=; b=aTdZHCEGwNAfasak6qnoSVLOa2TOPkhDq3uXJCx7hTeo+oc+zrrAOUHm+EcelfMAvu lM0pNgyZm2GcA5YZAsuZ8ZFjK4Y5kkSKSdNQVU6gThSV+fv4bcS7t65SQuA6u/+Yl01E H8zL34EfWNleioCBied81oFlWQy16PGI1DWJ1eK0cYRs7gpRm1pLiBDosI7U0q5H6wZ3 ZEMqjbAyesEmT2mt+MluUMK9VFHDfw7Uf/K8Un1yfZyxtEyGmS2UXWervGWfkA35ZQPv xMIMycOqKrgcOIAn54vZT4AHUyV0Q7VT+hYOEGQOkuBXXP2Wq2QJX8s6+MUIjrZ/ONQn SF9g== 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 t1-v6si877025pfm.7.2018.07.02.04.06.13; Mon, 02 Jul 2018 04:06:13 -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 S1753964AbeGBLGM (ORCPT + 31 others); Mon, 2 Jul 2018 07:06:12 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:57656 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030478AbeGBLFO (ORCPT ); Mon, 2 Jul 2018 07:05:14 -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 49F7518A; Mon, 2 Jul 2018 04:05: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 39B103F5BA; Mon, 2 Jul 2018 04:05:12 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 18/19] arm64: convert compat wrappers to C Date: Mon, 2 Jul 2018 12:04:14 +0100 Message-Id: <20180702110415.10465-19-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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 1ef103c95410..793bd0952ee0 100644 --- a/arch/arm64/kernel/sys32.c +++ b/arch/arm64/kernel/sys32.c @@ -22,22 +22,114 @@ */ #define __COMPAT_SYSCALL_NR +#include #include #include 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] = sym, From patchwork Mon Jul 2 11:04:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 140732 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3855014ljj; Mon, 2 Jul 2018 04:05:26 -0700 (PDT) X-Google-Smtp-Source: AAOMgpezl45XVMhwH0IlwdKeKyIWNLWs+XowgB8HIgsZquAwNSRs3mNQvkB9TGBKylcEWRCCJeOa X-Received: by 2002:a63:ad46:: with SMTP id y6-v6mr13969456pgo.144.1530529526245; Mon, 02 Jul 2018 04:05:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530529526; cv=none; d=google.com; s=arc-20160816; b=b7rBju70U4F0paMkUVZ8hVPgLNL4umrGOd0n0ELW4jgr2YyM40/xgzdffOPkxItLKl kGQ85J27XCYDgEzzyFyYyNDiOKpJfpQuXOfWHfGGZjJKGcfZNHGcXSO0bZ2KfuWBMruh 5iyDtjXK0ed9nqNatHiUpR01aygj9cfTVof+qKWHwRGy4Df4Rynztoq9pkO4uPBmk/aE f2PiO/FyqmAsokviDPGjluwFEN7omQ8+XmzkF8ozZSvdCDsX+OJpqBXNIILXHCkJRRjT TTspSnl+4vi3Ki1sjRw3HCOYFK9XQiEDnUFJPNlBRqOxmw+XggI+NdJAXC6j87viXz40 e3tw== 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=EYV/MuJUP2XuSLEuBdCAM3KYDOBgzi7PzlqfQxwxtOQ=; b=p6PnRXC5+sNWwfRDnbiutuLhuIs9RfpcjFPAhUFX/kjqySmRRFhTV9A8lbAds4X/ey ZWyxrOBi88bERSe09xsGKjpzhvrhtfppmEhUhGz14I3m5KIi3fX7CWKvnnh3rsTdGA6d ZgvkhFItVjPOe4x/zHzt+1H2sjt/KzbNLlp7+zhKE1pWZEESaW4aZysKAaauFiYRZpTn Sx1yeexBI5+PhS2C9jUt6q58Nsj1W7mWn95KCysmoGwwTk1NsqvjNEUdM1WeZOIuro6W Nr9P6XSevLzYavgxUY6ASFZCEricIzbgg5ihbOqtj/ixaQPF6jurBvCsBemsH1y+DfY+ 6N5w== 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 v127-v6si11789096pgb.200.2018.07.02.04.05.25; Mon, 02 Jul 2018 04:05:26 -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 S1030517AbeGBLFX (ORCPT + 31 others); Mon, 2 Jul 2018 07:05:23 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:57662 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030474AbeGBLFR (ORCPT ); Mon, 2 Jul 2018 07:05:17 -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 672691650; Mon, 2 Jul 2018 04:05: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 56F783F5BA; Mon, 2 Jul 2018 04:05:15 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com Cc: linux-kernel@vger.kernel.org, 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: [PATCHv4 19/19] arm64: implement syscall wrappers Date: Mon, 2 Jul 2018 12:04:15 +0100 Message-Id: <20180702110415.10465-20-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180702110415.10465-1-mark.rutland@arm.com> References: <20180702110415.10465-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_wrapper.h | 80 ++++++++++++++++++++++++++++++++ arch/arm64/kernel/sys.c | 10 +++- arch/arm64/kernel/sys32.c | 9 +++- arch/arm64/kernel/syscall.c | 9 ++-- 5 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_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 2ad1497a184e..ee93bf789f0a 100644 --- a/arch/arm64/kernel/sys.c +++ b/arch/arm64/kernel/sys.c @@ -48,11 +48,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] = sym, +#define __SYSCALL(nr, sym) [nr] = __arm64_##sym, /* * The sys_call_table array must be 4K aligned to be accessible from diff --git a/arch/arm64/kernel/sys32.c b/arch/arm64/kernel/sys32.c index 793bd0952ee0..533c97c5c232 100644 --- a/arch/arm64/kernel/sys32.c +++ b/arch/arm64/kernel/sys32.c @@ -131,8 +131,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] = sym, +#define __SYSCALL(nr, sym) [nr] = __arm64_##sym, /* * The sys_call_table array must be 4K aligned to be accessible from diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index ea4fc5eea182..edd822629ce4 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -14,6 +14,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 @@ -28,14 +30,11 @@ asmlinkage long do_ni_syscall(struct pt_regs *regs) return sys_ni_syscall(); } -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); 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,