From patchwork Fri Jun 1 11:24:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137508 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp805073lji; Fri, 1 Jun 2018 04:24:58 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL7JpNkf7ruw6onmqw3njCxrCxpKcm8F4zDOMtloeZuDIZbLv30juvYwrAJPqjNAxU5XQ/V X-Received: by 2002:a63:ad4a:: with SMTP id y10-v6mr8570388pgo.330.1527852298711; Fri, 01 Jun 2018 04:24:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852298; cv=none; d=google.com; s=arc-20160816; b=nJK17+zvC3+GJ+M1SafiSEZkVicRK1H58NaALnivB0l/dfGbYwHHvsw9V5fJAKHA5Q e5GkoCuhBko7FsNPqm/yqjExgtfafy/31RQLPW6p/5wwgMaJCu3RsIwXDtBmyn/QKj+N vAoOhnpLaecc6DErX4amQCyN3p3q+/AiRBhxmy3DGakpt4+xFG1mmiK/0qjvEeFbJxkN dV0BsljjZZodc5FmZshM90PUmNwKatrAgoC1PNwCInz0s94NXvxo1UTpgdYx9FY5uqdN fkx3azyn9yNQ6Mmg5JTphvvE2ig1pDveynym6qMnzFi0iPFzuwpJB5ci+MjOet7RYv7s W2zg== 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=TWEeKYTzV0e3mlfA8TWBsF+N4cvfB+5pArjCyNx6Cm8=; b=vMkDViHenSThnol4GoZbxL69RCMbOPu9qdIqjFYAyB7q86FOmmfaDHebHJMQr2IkW2 Kx5nrp79i9YFAP7KA4aRSAuYX+ElGP/kbR+ukDbNDoqzNTQ2G1J6UvMebDGu0diuwT9a n41aBOf/ebwndmcC0rleDeDKJe5USj1Z8hoGbBkMqIvDnXkoeQ1pSWiklMdjU+KjcqBP VzQdYsFybS3g4oI7jmiYIAXjWN5UNZagflacboRJd80bcPg5PFbuJiZSdSOxMpECERX3 29HwpRV6LpRbuKelbp2irpS+5Y4jfN+wnLWTfH3OjN70ux36S6VeZzBLNgI44vyFAu02 j8tw== 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 w2-v6si31554323pgs.676.2018.06.01.04.24.58; Fri, 01 Jun 2018 04:24:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751889AbeFALY5 (ORCPT + 30 others); Fri, 1 Jun 2018 07:24:57 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50272 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751836AbeFALYw (ORCPT ); Fri, 1 Jun 2018 07:24:52 -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 7D7C715AB; Fri, 1 Jun 2018 04:24: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 6758B3F25D; Fri, 1 Jun 2018 04:24:51 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland Subject: [PATCHv2 01/19] arm64: consistently use unsigned long for thread flags Date: Fri, 1 Jun 2018 12:24:23 +0100 Message-Id: <20180601112441.37810-2-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 Cc: 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 154b7d30145d..8e624fec4707 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -896,7 +896,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 Fri Jun 1 11:24:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137526 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp809807lji; Fri, 1 Jun 2018 04:29:55 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKPQHsTpXCkyKXbHWi6Gpu7aDCY9iqZfZelxxw4wDJ+eCQXOowV8GTTDTULAw/jsk2fJgzi X-Received: by 2002:a63:931c:: with SMTP id b28-v6mr8332825pge.167.1527852595786; Fri, 01 Jun 2018 04:29:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852595; cv=none; d=google.com; s=arc-20160816; b=xENnr3FamWVim+pWswG9oRCuwTR/AWorESwfP21aLQrEsfpKurGPm98zZznVly8EWX /JUbrEV7ab8Cx7NMXwxfEVR7i/zNfFBWdlOhRN+i8ETtJAU0v7mpXFyzy3yAvYnXQWbY 9G+Ncar4J6KVdzOXtFNeYbEytl5aRJQO0dvxsP0leTpCRikyPd1wGvR795y8qfrZ1YdD 8RKanMAH11cKMr8MoyQ72d6qRNED6HnLyhymEz7VkrfhrS1y8Vr1ssV+W4dgSbpJe8US AmHLeFFXl/V9H31na2fe8kH6hC2b9a5AYJmf3lHUqa/j4ipELKCCJRGdgOHoSa2JVsGa bZUw== 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=RatNHbu2MgMqHitpfdf4XscP2rWSRjytuc3v3+/I3h4=; b=s0VaqX1hf/xR8TA9tRSKooXqTkvK7uDESluqp+bzkRW0im66HJz8p6UoU31eTipOe0 HDj1cMlrKQku+CnW79Eu3vPLyJj1CFcSDFne3Re11l8lZSmm6BoekP8ZLQs1J1sM+xdx cpo3+S2aAGXNuFztN3l+9rUNqgTTrIgqnc67yxmkc96n+QIIEmnzmoVPrxNRSz/ZmmWM EuSe7UivAYda/9F8s9E9xbZdcXOoT8hgvq3RhiZccK+01fHcteUtVtxexsOWmuYWB9mA JClWLZGLxlYW1PsCXqmIPHNBaK32pssos42Q1v19UHXO7OCQyGMY5rpyHUQ2ZcEEb9FZ XxVQ== 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 l61-v6si38726423plb.507.2018.06.01.04.29.55; Fri, 01 Jun 2018 04:29:55 -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 S1752048AbeFAL3x (ORCPT + 30 others); Fri, 1 Jun 2018 07:29:53 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50276 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751092AbeFALYz (ORCPT ); Fri, 1 Jun 2018 07:24:55 -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 6534215BE; Fri, 1 Jun 2018 04:24:54 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 348AD3F25D; Fri, 1 Jun 2018 04:24:53 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland , James Morse Subject: [PATCHv2 02/19] arm64: move SCTLR_EL{1, 2} assertions to Date: Fri, 1 Jun 2018 12:24:24 +0100 Message-Id: <20180601112441.37810-3-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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. The preprocessor handles literals differently than regular C, e.g. ~0 is equivalent to ~(intmax_t)0 rather than ~(int)0. Therefore, instead of ~0 we use 0xffffffff, which is unambiguous. Signed-off-by: Mark Rutland Reviewed-by: Dave Martin Cc: Catalin Marinas Cc: James Morse Cc: Will Deacon --- arch/arm64/include/asm/sysreg.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) -- 2.11.0 diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index 6171178075dc..bd1d1194a5e7 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -452,9 +452,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) != 0xffffffff +#error "Inconsistent SCTLR_EL2 set/clear bits" +#endif /* SCTLR_EL1 specific flags. */ #define SCTLR_EL1_UCI (1 << 26) @@ -492,8 +492,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) != 0xffffffff +#error "Inconsistent SCTLR_EL1 set/clear bits" +#endif /* id_aa64isar0 */ #define ID_AA64ISAR0_TS_SHIFT 52 @@ -732,9 +733,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 Fri Jun 1 11:24:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137511 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp805273lji; Fri, 1 Jun 2018 04:25:10 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLydraGOtQbgYIJrgU3swuOgOnSam14eJTX3orkRKrQ9C/7dhqsMQB40wagqcAvURTO4Q4h X-Received: by 2002:a62:6a0a:: with SMTP id f10-v6mr10355746pfc.99.1527852310299; Fri, 01 Jun 2018 04:25:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852310; cv=none; d=google.com; s=arc-20160816; b=YITmZh7IF96T2G0qO8N2y/5qAueInwl4TpNI6wC/jDwtuG+3+POslXK+mNhxUbnAX7 eKrg4X/ltQaG/PbkBNTYp1kveOgUXguoZGQfhxp9mhGsCCmyfygz1/dHAGtrReW6Rzz+ DCg1unjW9nCt2C/QhOAdolAUTYAZUI7U/oZBgYJfCFbQqDfmgdZea5lcf8qwIhvKc4+S d8YTAIN+kNw3DntvBmJP6Fy+oKvcYzqHPEDMYA5siFHxPQ79Vk+ouUJxflEru3om2nP/ zU+H8D9ZDT6cECh8PCq7qJihgfvZOdG67LU9tEx7BELaMOB8ubSCj9CKFrRVc8nAL0RE 0D5A== 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=KhSuPTejIwL3fzpLs2g94019El0zpSTFUIDSdspDH5U=; b=r67ehaZuw39/Wamwei4j3G7MafCF9fDfql+4HmbQ6PFWSlv0SElcghLGN60YUtR0KY 38xsnMJg8D7F6N4WDYWAbeqk0/mqNSCNlWMc2ip+0QLAS073TRGLTwwrUoHoDoIUaqeR RXxGLKekcF3wfZSUuVDuiIWwETimrzsDlYUve87ZRwQDU0RwfLhpN5OUTGVYFx61Pj2s fc48WjzVGw6xMRmnUkMi28+/9ZbWZL5xdnhkzWK1ISi+EYzkFCpGn365Szff0T023Qmm N/VpvKyYo77iByDZwkK6t3NN31nV2Vg7USNTBA+ynmsXp0GLYIRICm3TN7+S8gUX/f7D ysnw== 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 x6-v6si13773302pll.24.2018.06.01.04.25.09; Fri, 01 Jun 2018 04:25:10 -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 S1751981AbeFALZH (ORCPT + 30 others); Fri, 1 Jun 2018 07:25:07 -0400 Received: from foss.arm.com ([217.140.101.70]:50284 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751849AbeFALY4 (ORCPT ); Fri, 1 Jun 2018 07:24: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 55B76164F; Fri, 1 Jun 2018 04:24:56 -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 24EA13F25D; Fri, 1 Jun 2018 04:24:55 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland , Marc Zyngier Subject: [PATCHv2 03/19] arm64: introduce sysreg_clear_set() Date: Fri, 1 Jun 2018 12:24:25 +0100 Message-Id: <20180601112441.37810-4-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 have a couple of helpers to manipulate bits in particular sysregs: * config_sctlr_el1(u32 clear, u32 set) * change_cpacr(u64 val, u64 mask) The parameters of these differ in naming convention, order, and size, which is unfortunate. They also differ slightly in behaviour, as change_cpacr() skips the sysreg write if the bits are unchanged, which is a useful optimization when sysreg writes are expensive. Before we gain more yet another sysreg manipulation function, let's unify these with a common helper, providing a consistent order for clear/set operands, and the write skipping behaviour from change_cpacr(). Code will be migrated to the new helper in subsequent patches. Signed-off-by: Mark Rutland Reviewed-by: Dave Martin Cc: Catalin Marinas Cc: Marc Zyngier --- arch/arm64/include/asm/sysreg.h | 11 +++++++++++ 1 file changed, 11 insertions(+) -- 2.11.0 diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index bd1d1194a5e7..b52762769329 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -729,6 +729,17 @@ asm( asm volatile("msr_s " __stringify(r) ", %x0" : : "rZ" (__val)); \ } while (0) +/* + * Modify bits in a sysreg. Bits in the clear mask are zeroed, then bits in the + * set mask are set. Other bits are left as-is. + */ +#define sysreg_clear_set(sysreg, clear, set) do { \ + u64 __scs_val = read_sysreg(sysreg); \ + u64 __scs_new = (__scs_val & ~(u64)(clear)) | (set); \ + if (__scs_new != __scs_val) \ + write_sysreg(__scs_new, sysreg); \ +} while (0) + static inline void config_sctlr_el1(u32 clear, u32 set) { u32 val; From patchwork Fri Jun 1 11:24:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137509 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp805193lji; Fri, 1 Jun 2018 04:25:05 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL3pWD5vwBGJF+3UMdD4CL0fBOSDE8Sgn8el1sWZCNJ+DbHtpv1qK8dMrFPFcvQodgLCZ0c X-Received: by 2002:a63:3c4c:: with SMTP id i12-v6mr8605864pgn.309.1527852305641; Fri, 01 Jun 2018 04:25:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852305; cv=none; d=google.com; s=arc-20160816; b=mkf1V7H7i/a8fUr/IkH6LtvZPo3sDsWvgEe7JXWuh9nw3iX7P1z+948ELFpJDSyrKQ Srkku9ykq2z+ewUgj8j3Fy3XNzCIqZi7GqMnIAgtRZ6wBkPdui/pF5shSf4jLd1QN5Je hbPfpZH+9n/WYF8pLAsNhx+NCfK4IC+Z21ZIQdYuZsRTq+bFeQBmssBONPrdsLfyiKBN 0k6HyIXfxz6jP14hJPNjiRSXbIFx/OYQG+uN8muCCKW2MkGSPE09oPfQmeaKqH84xPXJ vx12Y6IbKngJM4fbNgU/q5sAQsOXHy2TvyXZBX3T8cadLszD6J9pSRQdfBy8D6urIGa9 8MVg== 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=CmW6WQdAI+cU9pjjgCxtIvQJv3vmDp4YbZlBVkPx55g=; b=qvp4iOBtcbYVFVdBVzU7Qdw4Xz2keVx3HIU3oJNUl9SPZ3rMynX94v+vZn/kdqPLCh 6RK4AW1wdcMjHrkg4nCUdM6SkL2gJaUwRrNsk1ZOEZkhczwpZLy0RuAQlA3ZX0HEd2KC m3SfSLkOZeKqUzgahvnkJD4Sm10LiTDEU3Xu5+zSQ183XpTXHMePZFcXpGkrcfBR9yLh j2G3xTfNRjiN7I+wG4Sq37piYJkiZD0gjVflvoVtKNjm1xI2/4KUjmmX7wJgUoR8HK8v wycnXiz3I4HtG3b+as56xgv6qeJyAO5AZAtfVjl8t5D0Ne7WOUQ92wKKtmFEa1x75GTb EAlw== 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 d16-v6si18499554pll.197.2018.06.01.04.25.05; Fri, 01 Jun 2018 04:25: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 S1751923AbeFALZD (ORCPT + 30 others); Fri, 1 Jun 2018 07:25:03 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50288 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751599AbeFALY6 (ORCPT ); Fri, 1 Jun 2018 07:24:58 -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 367BD1650; Fri, 1 Jun 2018 04:24: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 05A7D3F25D; Fri, 1 Jun 2018 04:24:56 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland , James Morse Subject: [PATCHv2 04/19] arm64: kill config_sctlr_el1() Date: Fri, 1 Jun 2018 12:24:26 +0100 Message-Id: <20180601112441.37810-5-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 Cc: 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 b52762769329..3493c7048994 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -740,16 +740,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 97d45d5151d4..c15847521394 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 cf37ca6fa5f2..b99e492c44b5 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -74,8 +74,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 8bbdc17e49df..b8d3e0d8c616 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 27cbe0b38960..07926ee00053 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -822,7 +822,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 Fri Jun 1 11:24:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137510 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp805225lji; Fri, 1 Jun 2018 04:25:08 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK0e5zG+pYtUB6Pg9slhpS3JsqR+BwGYFFyf+KDX7OAwToZtbL3iU1Vc5CopbBHTHb8lGZt X-Received: by 2002:a62:968f:: with SMTP id s15-v6mr2531892pfk.191.1527852307858; Fri, 01 Jun 2018 04:25:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852307; cv=none; d=google.com; s=arc-20160816; b=xVhrz6UhFF3OP5IcJTRXEz7mu7rIsAwqJL8pk1toj3D7pT4th1HU9aN1b2j9u+uYdZ wY1T2qm3nCEEsY6BWlO4Wk2FXJ2cGpmHWVsZftWxqJGztvsh47wHpEWtHcYnwDytlOx6 lJs0+APeLmHZbLjs6rGtEZAAla4Y/p0tgHhSq4k8n5qbTnA2LLCVy9WXJl4BrUJ8FgE7 b+RaU8O71mW5d6yZV2OIfJQND8Zzycg4QCGaPO547+GeVwmcBofax8w1SGbzncGxft9m g6UdJhixGUhTZ4JjsHSNHOUUuOrCrx45ix1ORBLJnDjjcXh8XlN4HQF/yjesJtMpLmBi Ms9w== 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=vXe67gi0/Xn5bgoHOQowhB59VCeWEhCCYHNAfoMPk0A=; b=nnVWoYcc8VwJ7VBuoI4d43pyKVLNk+nBz/lMW7UrdrUW2s3zejXWDSCk0A9w33qNcR 92J9YytYYJfglu5D7WrPXgeT4Mbyi31uhTCM+lr2G5OXKth6Zkmw8eWpIscd3FsWkI+o eMYvuC30nIpe2C3MxskM+DLXGvmjjNOLSCZP0xPcUxflrpzU+IwyZLeYPwKKuKwbkQmH RENemzRNtdwscX6y3GWHh7tfX0pfCYzCYKzFMGpCdn+WUPeFfyfRR+Fn2FKDrVCASMnF 2pSD31XmPqJINvfLdEotGvj+LDR8Mgkzle3X0JucKLMipFNYbK2GEP1GMk1f53fHQMDR kgIQ== 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 d16-v6si18499554pll.197.2018.06.01.04.25.07; Fri, 01 Jun 2018 04:25:07 -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 S1751948AbeFALZG (ORCPT + 30 others); Fri, 1 Jun 2018 07:25:06 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50294 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751890AbeFALZA (ORCPT ); Fri, 1 Jun 2018 07:25:00 -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 16F4D15AB; Fri, 1 Jun 2018 04:25:00 -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 DA86F3F25D; Fri, 1 Jun 2018 04:24:58 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland , James Morse Subject: [PATCHv2 05/19] arm64: kill change_cpacr() Date: Fri, 1 Jun 2018 12:24:27 +0100 Message-Id: <20180601112441.37810-6-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 Cc: 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 3db8ed530e56..c135cff8f882 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -171,23 +171,14 @@ static void *sve_pffr(struct task_struct *task) sve_ffr_offset(task->thread.sve_vl); } -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 Fri Jun 1 11:24:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137525 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp809505lji; Fri, 1 Jun 2018 04:29:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIlLHMb0NNZk2hDoPOVNxzARdzYuKVCV17jIuwQTsS+1jc7lTBxqUZYCNz+KjGAt2gjB7bU X-Received: by 2002:a62:d1a:: with SMTP id v26-v6mr10631917pfi.90.1527852577356; Fri, 01 Jun 2018 04:29:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852577; cv=none; d=google.com; s=arc-20160816; b=MP3XaQ/CmnTKumrG+6sLvUZL5TOaxtbUL5Sjk21iZ4wcAJko67gDmj0kAZM8xoe1Un iD+t25mbskQx10nOXuTpz780aB7EG4D7IwG6FZD2y9FLFWZW6dYaffcdkSxq+E876QhJ B8HdYYOhp7I6MV5SRIFOGBfJqbCsZXRBCks9fqw+AS9X4JJXZCihKbppa/bDL3ylcXMJ vu6t0XqOwefpBcokqPbExf9f5KDaIweH2j037mhYsNuOePCl9713CVJxM6m2f5H1nPNz bVubDPMCpsE4aycRS+A3Fqe9Xz7AljBDdZ288XBvr9BXMMc2o+Au42YcCo74HfInnhqZ Vasg== 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=pAych2jz+ukQvzoxRHKQ6tZmUbp1nac25vFeKRGFesw=; b=arkpRw1td72KYbbzjSLSk0OuQgBItWUMXbb1Pwt84VFagZocn9XAsIKmSKs/mUyiB1 K2Sy4fftu2E10sp+K+PAU2Igth6n1osv2Pa+GN4x6xgs0b67ZElm8zhKmh0Y1bBzF1Y/ ABzfGAa6TU5eIleifCFXOfgeyw1LAGbv94i4G8kCeJ5xx5xwfJG8DI9GYuJ2iwT/lJZE APidBDPzpUdVoTlRRyF0Kz3nrs0rQQa4+WyvUCAvmwCD8W8jdyXt/neolm5RaUFXTtig VFzAaT1F9qCrnKpf27iXAeAd6MpDb89Jitw/jsUUmdXbwuxA6i7B4Wxw8wr+oOm1coNM QgqA== 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 m27-v6si38408617pfj.192.2018.06.01.04.29.37; Fri, 01 Jun 2018 04:29: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 S1752126AbeFAL3f (ORCPT + 30 others); Fri, 1 Jun 2018 07:29:35 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50300 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751788AbeFALZC (ORCPT ); Fri, 1 Jun 2018 07:25: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 F3CF6164F; Fri, 1 Jun 2018 04:25:01 -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 C31EF3F25D; Fri, 1 Jun 2018 04:25:00 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland , Dave Martin Subject: [PATCHv2 06/19] arm64: move sve_user_{enable, disable} to Date: Fri, 1 Jun 2018 12:24:28 +0100 Message-Id: <20180601112441.37810-7-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 Cc: Catalin Marinas Cc: 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 aa7162ae93e3..c9acc6ad9b75 100644 --- a/arch/arm64/include/asm/fpsimd.h +++ b/arch/arm64/include/asm/fpsimd.h @@ -16,11 +16,13 @@ #ifndef __ASM_FP_H #define __ASM_FP_H -#include #include +#include +#include #ifndef __ASSEMBLY__ +#include #include #include #include @@ -81,6 +83,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. @@ -107,6 +119,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 c135cff8f882..86f2eef428e0 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -171,16 +171,6 @@ static void *sve_pffr(struct task_struct *task) sve_ffr_offset(task->thread.sve_vl); } -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 Fri Jun 1 11:24:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137524 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp809208lji; Fri, 1 Jun 2018 04:29:19 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKCjI6e01o+pSFz5RgySmJZmGqrTvJJdty5mdRHsXt4x0Z+O8AZ+vadCbRVfeAYUKQfOl3Y X-Received: by 2002:a17:902:868b:: with SMTP id g11-v6mr10495303plo.305.1527852559591; Fri, 01 Jun 2018 04:29:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852559; cv=none; d=google.com; s=arc-20160816; b=QuX8LKKkry+HXWVVMkAJwlb5eaYkrYx59qLevVLRdbjdnkTGFxbEZcgrhgMRGFg+9u +bNIDdKeNw0az2Xw+T2CabWCWrFCzmPxTh5alVqO0qVlSUaTM+L24z2hsp9s5k50jpIh a4QpILpkKw/tTiV/BxVmBO1VueaaQjiQhAXwqWaFiXVT6C7UVkRS7bsou6KcAZ6qvvY1 9n2wgZhOe2X4+IBaskoYlCxELWN58c7KklXIlEo/+gqwgx4WEFoWeYZrFDh/HxNgZysJ fx/okBqD98kM7OfcfjQ+EWNpEfKFi4B5UcO3VuU/QoHF6dBZokZagJEapggER/JKN/b8 rrsA== 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=gry78QWOdxXugY3oX6b9fPaUDsoLTfxpEqswEXTM60k=; b=WhMOo/qRougmBBy95fOG5KEjT65dQLA2lLRDJjzsxc5qvreCaCAohiNgBgxGe5EdQ4 SdA3mTUd7dj6dZRwcHDHjULQADvLasE6fygr36CVziASK1OB1ntG3GwpS2h2gandSoLy TpqJlDiojSa0lBQ53MTanX2uswtf/wei8ZMt5jobF0k/zRWvWZ3iF6UlK2vRrWATcMIj qXDoNHp8PMx+7sdEF+31gU5pUvaDQZrLYtDsmWd2GlPy7BYIwK9hdBfOasebIePf0HAN PXt5YEZ0ivRQ8A11uNzc4hTDJ6jlP96hnIvMc2wzNXwF+0CrUQLIzzyuHkA4B+qFAiOo Eg9g== 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 m27-v6si38408617pfj.192.2018.06.01.04.29.19; Fri, 01 Jun 2018 04:29:19 -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 S1752107AbeFAL3R (ORCPT + 30 others); Fri, 1 Jun 2018 07:29:17 -0400 Received: from foss.arm.com ([217.140.101.70]:50306 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751599AbeFALZD (ORCPT ); Fri, 1 Jun 2018 07:25:03 -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 AD33615BE; Fri, 1 Jun 2018 04:25:03 -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 9FF2C3F25D; Fri, 1 Jun 2018 04:25:02 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland Subject: [PATCHv2 07/19] arm64: remove sigreturn wrappers Date: Fri, 1 Jun 2018 12:24:29 +0100 Message-Id: <20180601112441.37810-8-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 Cc: 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 8e624fec4707..caa7a68cf2d2 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -538,8 +538,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 Fri Jun 1 11:24:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137523 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp808638lji; Fri, 1 Jun 2018 04:28:44 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJR27icy+ZVksX+xoIbM4j3XjGPVdSVMsaanabNP6npaFsWAaLl1wiqKeEbVd1mEPQwtSfF X-Received: by 2002:a62:7002:: with SMTP id l2-v6mr10584593pfc.40.1527852524139; Fri, 01 Jun 2018 04:28:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852524; cv=none; d=google.com; s=arc-20160816; b=IBg1BvGA/iakDwc0O02Fw0uQrCtiY6Js7hiNx/mRWDKPjrWbniQEKA9FJwjBzLOQYp M8S2k06wsOSpvaMrx6hvow+dzsR40WDeUFOdkHc2No5E9VSRHb8gWZTMzrgbZ0QWtx1v Xd/zlKXBa/eCdaSXZxpyBAKt+gbwfZFUQibO42YbP+TdT8cw8J59SmCf3bJommPVaGaS smZ9jw0ZemTwBrpF/HdQT2/O2sFdKiT/uT7cf8Ho3Q40YwqCXpZktNJ7Quxrz0sQrs12 YtPuPsiuN3jedszpun5b1iKB/7zCj0jUgC8DdqNRbAToyodOojr8d7NjGSEhu6qj+5R2 Uq8Q== 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=UTpi8NEWpmi6EFSDxdnqEfECO5z5xFrLIIT14P6puXs=; b=KxhlczKs1bhuA6FjdWdIzTH8RxxB8ItEzd1Xtx2KS/+oL/fUCzmE0quHCAMrVv7exT np9rf2Te8k0PT0uwx3/YYYm2mYizxizYYyI3Qoi2hjkIwwtE71xAarclfnadv6KcnaR/ FpvToBXrHAOyZKW411kxWuxn4jaqGt5jsuiOVucj0eBzYOrU51u1GhFMccV5OTfJfDTY bstBjFWFBGGKfK9LNftcIy25axzwz0U+kU+goMqX+DUdAmIfpVwXcPM1RI0m5/i7xZZY YL25oiMw+D4IKhd9JlfnrJhASaf1Duz3tBUZX9evVqnX4/0NOGLisMWvGTgqjMlLJmgU Wmtg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b4-v6si31564672pgc.190.2018.06.01.04.28.43; Fri, 01 Jun 2018 04:28: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 S1752132AbeFAL2m (ORCPT + 30 others); Fri, 1 Jun 2018 07:28:42 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50312 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751942AbeFALZF (ORCPT ); Fri, 1 Jun 2018 07:25: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 6AA991650; Fri, 1 Jun 2018 04:25: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 5D87B3F25D; Fri, 1 Jun 2018 04:25:04 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland Subject: [PATCHv2 08/19] arm64: convert raw syscall invocation to C Date: Fri, 1 Jun 2018 12:24:30 +0100 Message-Id: <20180601112441.37810-9-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 simplfiied 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 Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/Makefile | 3 ++- arch/arm64/kernel/entry.S | 36 ++++++++++-------------------------- arch/arm64/kernel/syscall.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 27 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..46543f34b9dc 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..b463b962d597 --- /dev/null +++ b/arch/arm64/kernel/syscall.c @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include + +long do_ni_syscall(struct pt_regs *regs); + +typedef long (*syscall_fn_t)(unsigned long, unsigned long, + unsigned long, unsigned long, + unsigned long, unsigned long); + +static void __invoke_syscall(struct pt_regs *regs, syscall_fn_t syscall_fn) +{ + regs->regs[0] = 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[]) +{ + if (scno < sc_nr) { + syscall_fn_t syscall_fn; + syscall_fn = syscall_table[array_index_nospec(scno, sc_nr)]; + __invoke_syscall(regs, syscall_fn); + } else { + regs->regs[0] = do_ni_syscall(regs); + } +} From patchwork Fri Jun 1 11:24:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137512 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp805335lji; Fri, 1 Jun 2018 04:25:15 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJEqP5YZ+iNwoAOwRJMJCgAGgsy6AY5BPwSh/4RJOpCMuluIF8iklkdqZQecvmniMaFF0HV X-Received: by 2002:a62:830e:: with SMTP id h14-v6mr5463812pfe.64.1527852315105; Fri, 01 Jun 2018 04:25:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852315; cv=none; d=google.com; s=arc-20160816; b=JUkoX1Ios8AmNMsn+Th/g33pDjrmLywZKZ2J6MOabd5HXMtbYR+/rGZiAHiBTA/amr ynJ30ptqVuX9cCRjSlORrr9TT4KEYSREAJw09ZQuQEUz4wDy6N+BBHJEDT0XRHKzlI9J /xLB3cTzwiN6D9c9hMD1kQ9GB90wdQ6SKAXbdIUE+DowDLi20Cm54jsT7GNx3Do87nl1 KSF0RTbtx6JGd22aU3Ud3iryluTLZ3UXCM67PSPEI65xx1CnNPqfJK1CmRbGRptFir5L nm60eTwq0gmp1H0nx+O8rYhxp3of+SrgijqgPMPVxuTqhgHNOQ0H6fvpd4/KXTKJCN5m lLLA== 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=+sv0/wTlO2NSBtZ+1NtOJQKPKJt9hEqpEfpEP8b3qxw=; b=DibjvJtkkcZYgzVTImJbF/bcyhXPDVKsRbJgacuASEIKeyZ0cGmadoiPHeWN50ZlTF PdCyLhT2tiypRVRBohXb4K469QyhyV/oQVRpj5kC8yFTraXGK3JF7pplCOzq0TNNWXHH wh/SQoxb6SHLW1fFl9Fc8w9dRAyK+hhCrh3c+r/IamkQUPDaQ4R/+SiacvOMyF1Qg00O ILC3SZZ/FGtiHhLsStn+02ib1WLx6dwP6452ShPSTO4E35OC+JIAhW8Giewey02vxkAi dOojXZZXGp57ZuJdT1PNcTnUeqgykbsUJ9ofhIly+sXhUv5jeBKo1Q1jwnBjG8cCysbx 22uQ== 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 x6-v6si13773302pll.24.2018.06.01.04.25.14; Fri, 01 Jun 2018 04:25:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752005AbeFALZN (ORCPT + 30 others); Fri, 1 Jun 2018 07:25:13 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50318 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751968AbeFALZH (ORCPT ); Fri, 1 Jun 2018 07:25:07 -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 1927C165D; Fri, 1 Jun 2018 04:25:07 -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 0B8403F25D; Fri, 1 Jun 2018 04:25:05 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland Subject: [PATCHv2 09/19] arm64: convert syscall trace logic to C Date: Fri, 1 Jun 2018 12:24:31 +0100 Message-Id: <20180601112441.37810-10-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 Cc: 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 46543f34b9dc..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 b463b962d597..2adf1a073398 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -1,8 +1,13 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include #include #include +#include +#include + long do_ni_syscall(struct pt_regs *regs); typedef long (*syscall_fn_t)(unsigned long, unsigned long, @@ -16,9 +21,9 @@ static void __invoke_syscall(struct pt_regs *regs, syscall_fn_t syscall_fn) 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[]) { if (scno < sc_nr) { syscall_fn_t syscall_fn; @@ -28,3 +33,50 @@ asmlinkage void invoke_syscall(struct pt_regs *regs, unsigned int scno, regs->regs[0] = do_ni_syscall(regs); } } + +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 Fri Jun 1 11:24:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137522 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp808211lji; Fri, 1 Jun 2018 04:28:16 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKwUiHTFI11mXxIfJ7X36VmplpY0yrH9FB1dZR6j6aTHwLZRwSBSUnwVWiZDu8WktDbiZlb X-Received: by 2002:a17:902:28ab:: with SMTP id f40-v6mr10807128plb.208.1527852496734; Fri, 01 Jun 2018 04:28:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852496; cv=none; d=google.com; s=arc-20160816; b=IyG3JRrdKXSwMIDOwZYO7YtkIEcss51L9BUwkmo5n4dnNGb6Ashp/xF1MEC0ZTqf8T Wa1r3/XUqlEiFuZHilz2mNydp/iT3zGYO7Xc/AMSDD/T+XQmLla3c+xvCEcAZGhRsoVJ CfvloAoM6r/dFRY7qeVW4gO1Gy50RzOIlU6Yop2nf1hA80Phzm4QcUF3QUT9mbcBnhwV VJp4Le/6ptNt1PQKDbesqIGtM6B5MCBqtu+4OVz4+B9v2EiLwFffHCtZetKLRdahnaPf HdVAOLMIGn0kkPzgms87wYiN/iyRdl7c2fbuqaYLS7IoKXMqjdR4rB+rfUdq0pjT2GGV +G1A== 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=E3GVxjFVU62NWU41Dil8Uhv6Kpdom8eOukOUL7ZWQHI=; b=Qsf7N4QiV+S9doKwpDTNRS6sbuF0VXvOpHJ8S/eD69/APkhV4RHUT13p5qHsr9+Roq B18VRdXeL+q3yHxyN/RSIqOkWA+Fau5yqOyRDvLEqxkw/fpHgo2qQYJVERG2ZdV5040K E+u1pV0Y0zvjwjorNnQJTEKhiiSc4NPCQjenRDMlf/uTDjj3az/Opec2rYT3uBpBnNHY iOnecoNznI3c5dOx3lbtUMqqo6AIjzpXuS7iW5iTFp8SWOEyAxUBGvowdzPwy7TxHPik 07phj8fq0qz7f69nlj+o2mdurTQXtTfGlblWYq6DBr4wKBF12e/L9tFdWm0FRXlpsOx7 B1SQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b4-v6si31564672pgc.190.2018.06.01.04.28.16; Fri, 01 Jun 2018 04:28:16 -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 S1752323AbeFAL2O (ORCPT + 30 others); Fri, 1 Jun 2018 07:28:14 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50324 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751782AbeFALZJ (ORCPT ); Fri, 1 Jun 2018 07:25:09 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BEA921688; Fri, 1 Jun 2018 04:25: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 B18443F25D; Fri, 1 Jun 2018 04:25:07 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland Subject: [PATCHv2 10/19] arm64: convert native/compat syscall entry to C Date: Fri, 1 Jun 2018 12:24:32 +0100 Message-Id: <20180601112441.37810-11-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/kernel/entry.S | 42 ++++-------------------------------------- arch/arm64/kernel/syscall.c | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 42 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 2adf1a073398..6a31bb2a382b 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -6,7 +6,9 @@ #include #include +#include #include +#include long do_ni_syscall(struct pt_regs *regs); @@ -42,8 +44,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; @@ -80,3 +82,37 @@ 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_reset(void) +{ + if (!system_supports_sve()) + return; + + /* + * 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. + */ + clear_thread_flag(TIF_SVE); + sve_user_disable(); +} + +extern syscall_fn_t sys_call_table[]; + +asmlinkage void el0_svc_handler(struct pt_regs *regs) +{ + sve_user_reset(); + 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 Fri Jun 1 11:24:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137521 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp808162lji; Fri, 1 Jun 2018 04:28:13 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI9AJQej/1pZuVJqssdEFnd7vYNVp3N1yyk3ENq6BXvFwGOk0jr4IIUfl2r8ZKh4m3oBkgS X-Received: by 2002:a62:a09c:: with SMTP id p28-v6mr10559814pfl.9.1527852493510; Fri, 01 Jun 2018 04:28:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852493; cv=none; d=google.com; s=arc-20160816; b=lj//BdbVa70EYFQQKrGOYySQoETKQqtKkayRrkh4aTt+ZdPysYH0zzIs2JeElTE42X Zlt9y0xLfmgiivTgKPskE9PtwGXB3jPjObhoiBpLh0Hqz8u4fGTbX58weQC3CJ0JyJ98 qUPgz+GEIVqZaco3pmFM31LIjIwj4lUTGJ1gVGBo1uSH50N7Qv0gEgyO2qbF+b3OUZyi Rskdn7MguPi1GdMuTnDUgykxhw1hi3MeQgB1iSfJ8E72CYjuULXAcL33CcoLELPmSGSW TUjc/vkC5EzfaPamAR+OL3xraOmVRzp/PDa+NqDwFEuO7T8a+Oha1z6d/so/JFoxbAgI wBSQ== 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=SrjDVMaNJ3DhDE0LCMAdreUevpNi5gCnwygZDBQeRls=; b=paaYe61d10TH7uI5iB4uJ3rV2CAvKcOKsKLlf0DYAzqyILIHqFV9zT1JA+9c+Wu+BX 6oOKDtl3OylnpxPwHDqMYpeIzlqixrOkCXSTz0olUZTx+qtJSImbrMgS0E9fMzjPi0X1 JkuyLuBSkSPV/FiBVYle0Yk+7euCdmlIUDWGc0TJhKLrTKGFBo7DkBZAdPhKvUYhGYeK cyy1bqcVFCGLtXCFyOhGXu0ANHbzX80BiyRZPNCqQgBPD9FNHSKvkvlQxMJPZ8HNCMxH H4XrPine6GHEVhcc0Zc7dQag1rKHqX9flsW06SDBnO2+g219AAPzGw9u5zIXhyj9cORg MpSg== 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 u12-v6si18671407plz.392.2018.06.01.04.28.13; Fri, 01 Jun 2018 04:28: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 S1752062AbeFAL2L (ORCPT + 30 others); Fri, 1 Jun 2018 07:28:11 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50334 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751984AbeFALZK (ORCPT ); Fri, 1 Jun 2018 07:25:10 -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 845EC169F; Fri, 1 Jun 2018 04:25:10 -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 53B583F25D; Fri, 1 Jun 2018 04:25:09 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland , Marc Zyngier Subject: [PATCHv2 11/19] arm64: don't reload GPRs after apply_ssbd Date: Fri, 1 Jun 2018 12:24:33 +0100 Message-Id: <20180601112441.37810-12-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 remotve 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 Cc: Catalin Marinas Cc: Marc Zyngier Cc: Will Deacon --- arch/arm64/kernel/entry.S | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) -- 2.11.0 Acked-by: Marc Zyngier diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 156c4e3fd1a4..22c58e7dfc0f 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -140,20 +140,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 @@ -183,13 +184,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 @@ -331,8 +326,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 Fri Jun 1 11:24:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137520 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp807649lji; Fri, 1 Jun 2018 04:27:44 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIJtbFvAXA5tpgfDF4GAsmr4zPcFCqphymyJ/WIpBsHhYfiVQyIU3gpgJm62ysfjJZb/VBH X-Received: by 2002:a17:902:205:: with SMTP id 5-v6mr10540475plc.301.1527852464672; Fri, 01 Jun 2018 04:27:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852464; cv=none; d=google.com; s=arc-20160816; b=IAmHljHUi36UukOI7W0DQlyHyi8D3IeCT68ybfg0/s9eCx8wn9itSb99Hqo/9lfvJ3 P/JXbdDJ5OeDn4nBVuJ4O/sbkDBUPlRYgbJan3f5zbdim/33g6arnmETp7qFFxMrExBU rJFcU8nXgPPcDBqqsYTxj2Lq9k7Lw4xikLXjXS/3xPa1vNUtit+4Wyuxb52oKvVliEk1 OcgocydcNn8Gmh9JXLiZoQydV+AKqhjHKs8cdrEW+aSjQRiGaAiJF1jhiuovWF0yH6UI QN1+rQsDYE5Jn6MUB02+HncvkxrcQFP5KJ5IAt23C7gHacc9DGJHfBNyzvABYwfCf+zW 0xBg== 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=0qbh9YyYk2Fu8//V3v595cYA4CFBraDa4yvmMcEnuA0=; b=SgRDT3+SVkapmgeoMGfuDU448SbX26wv+Lpaitc/jYWqKcQLg5NudciV/sRmjCmffQ oRuF5YwrkReg9MD9j0uyXWOC3HEgJjgprSBE9PAWtftqzOTPjl0PlsLLjowNRiN04QrO 8ZGOr+1KUssRYjBQ/Ee9A6m545YHCBiexGEz9WCfBvXTcxlO1Y7XhKzTTTTgNe3N21l6 9MlGpMBk1msF9V0odPorMAemsANpqGhWXceVeZLWo1ZzLcd7meDCj2zIkX8W86RkWkaI vNBcaHDPGtodasiO1GTiH4P07xznyDfIQC1Lvu8TWMo6zBwBlihA1+BQVcGE02G1n5gl W7fw== 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 h4-v6si678978pgs.201.2018.06.01.04.27.44; Fri, 01 Jun 2018 04:27: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 S1752190AbeFAL1m (ORCPT + 30 others); Fri, 1 Jun 2018 07:27:42 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50344 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751807AbeFALZM (ORCPT ); Fri, 1 Jun 2018 07:25:12 -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 375AB1529; Fri, 1 Jun 2018 04:25:12 -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 20F203F25D; Fri, 1 Jun 2018 04:25:10 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland Subject: [PATCHv2 12/19] arm64: zero GPRs upon entry from EL0 Date: Fri, 1 Jun 2018 12:24:34 +0100 Message-Id: <20180601112441.37810-13-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 Cc: 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 22c58e7dfc0f..39440c2ee66d 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -63,6 +63,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 *----------------- @@ -179,6 +185,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 @@ -186,7 +193,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 Fri Jun 1 11:24:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137517 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp806910lji; Fri, 1 Jun 2018 04:27:01 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIRFJRXs6wuus7FFU/SY6PVSKzjGxDE0e+LRwBpqD982GtPmKMHQE0mMpx1CjhAv5IwfBwd X-Received: by 2002:a62:5c06:: with SMTP id q6-v6mr10548912pfb.118.1527852421704; Fri, 01 Jun 2018 04:27:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852421; cv=none; d=google.com; s=arc-20160816; b=lZ4uWktJ+dgiDlMmzznxBsy3S+laLY2Wz+zFelhW9ZZmlq6gqnjKIvzQPoFzrfuBsf Nx3rF+E0PIeZeWmkLiHIxlCqKsDKgEU3aVw5Wg99cgBmIKWQLngdq/tjfihDwE9gOtAZ j5GnsY9jsEcHJTrhSbOEt7PsDN0PZXl2qg+ae4eFoawaacRJ9L0FP/q5PjFeaC2/GGPl OMUL2kt/tpXTfaC0j4RG9Cz+1SoO2GHpEI9oabSojLXCdghV0hnN5gtxhUmRqwAmoYlm XvtdBA5r1J/ftg39ueBNgi71sCWa4RW69XG7Oe4Biu/YRKMsFTMt//wmY+Lsh4B+JLz+ jAhQ== 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=dp8RxSY3pxFhNh2uOnT85B8C1J+zrWhFUVvCYt5IMEQ=; b=T9OdIrwa/3CZpDdYMcnMWO/FLiFUZBNya7ny4/a9sS2s+ec2v2JWolLLxbnz7nWyd4 HjMoQBBKnW9MD5KDVfy9trDXswOxMjSzl/FHm5d5G4IvaINf1D5YFR27XrYBS+l7vlWA 6QGPxupixYzTeNBvQFgmEeJGKvrNEoduhuxwHnA+GlXZ3fAbv5Rm2dXijR0By+JlESrC XKSob21M/NbVI0dpkFCnkeOZvCNb1geG/AHN1fe4tXSRzPl+etUqvDOq0/0WymvOd6za wag9h45beyu06zfbkVSIAQ+79MGRbPHg1z4hGkzjnaW/4vrAEeaKwMjh5mXQFB79a9tU m2uA== 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 m9-v6si39397641pfc.9.2018.06.01.04.27.01; Fri, 01 Jun 2018 04:27: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 S1752035AbeFALZV (ORCPT + 30 others); Fri, 1 Jun 2018 07:25:21 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50334 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751968AbeFALZO (ORCPT ); Fri, 1 Jun 2018 07:25: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 88D401684; Fri, 1 Jun 2018 04:25: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 E25313F25D; Fri, 1 Jun 2018 04:25:12 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland , Al Viro , Christoph Hellwig , Dave Martin , Dominik Brodowski Subject: [PATCHv2 13/19] kernel: add ksys_personality() Date: Fri, 1 Jun 2018 12:24:35 +0100 Message-Id: <20180601112441.37810-14-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 Cc: Al Viro Cc: Christoph Hellwig Cc: Dave Martin Cc: Dominik Brodowski --- 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 70fcda1a9049..652e166deb64 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -79,6 +79,7 @@ union bpf_attr; #include #include #include +#include #include #ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER @@ -1268,4 +1269,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 Fri Jun 1 11:24:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137513 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp805503lji; Fri, 1 Jun 2018 04:25:25 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLJEfeJUmxuGteErDh98lOhC8HJqTfeyuWfw2CMpw0yN9wHV6hfKI+pQgAF0N4GGxTodBDO X-Received: by 2002:a63:720f:: with SMTP id n15-v6mr8799882pgc.12.1527852325805; Fri, 01 Jun 2018 04:25:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852325; cv=none; d=google.com; s=arc-20160816; b=fN/PINQS21rBwuIwIga2TKQsMD6SkElAi7gaKNQrj2RGWka033YPzMdqItazeeT6QU CmvU90SluY/jXVngVcGo7qUFZJuts5hOsED95jSXKQx9pyWGWSbouB9VxlgtHySIZQ6G dzySJ9us7CSz5z/sWjrvcxoJMZN69MfXV6i9BDBEK8h4XmsVreu1AxINKyaVn1dRtubg YjiDfwlLgeOUSmFF+X1Fx5rnGEwBrGKslqdp1fqgZRYg2mCWh9WyM4zk0Gk1bAH9VxFS +kGEuQFtDi8lSb8aGrsxNUq8g7nZ5nO3vS93L1xfFH9ZyZgH9UBgrx2FNxy3emdmxaZV 2KUQ== 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=5esnfEHpxG6UbSVuzA3aJDrMybAxCpMjqaMHPcJ6UCM=; b=mtIcnvF7klCSUi5YdXxMmvQlnTTJe7E3P7KKluH5RdkEVlcEV/CFtXfl2Nminn7h4A RemqXe7bPQOIwFVKeMn9yci/l5aVfNqA8Mkv5A8+tL52R1hg5yVHpZADLkYVkCseyiT5 xEY1JC+R43byLCB6nHxskDKgRY2w+W2O8wW7vjO6OHE/T3TdG9smttlmq9UABgEJh6xH 9PWGuL+p28pA/tMbyV8Hcfy8ezMXu56NJqbYsOfEuXiSs5sSZn0L8zMOgpoLVPoH59j1 TjeGcy94eBpsciVVuvb6IkDj6U9VITOjogEevBGLpXoN254PYGjyhCtkhhsUy44GUiL9 lETA== 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 b67-v6si38762507pfa.71.2018.06.01.04.25.25; Fri, 01 Jun 2018 04:25:25 -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 S1752058AbeFALZX (ORCPT + 30 others); Fri, 1 Jun 2018 07:25:23 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50344 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752006AbeFALZQ (ORCPT ); Fri, 1 Jun 2018 07:25:16 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2ABA216A0; Fri, 1 Jun 2018 04:25:16 -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 CAEC43F25D; Fri, 1 Jun 2018 04:25:14 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland , Al Viro , linux-fsdevel@vger.kernel.org Subject: [PATCHv2 14/19] kernel: add kcompat_sys_{f,}statfs64() Date: Fri, 1 Jun 2018 12:24:36 +0100 Message-Id: <20180601112441.37810-15-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 081281ad5772..6cecf9f11d6b 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -1013,6 +1013,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 Fri Jun 1 11:24:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137515 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp805936lji; Fri, 1 Jun 2018 04:25:53 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJmqjSPcLqoClb23QzuXvQWG0FEdxeBcg6k/Eq9sAKa/KjlsazwHk007IG4CdqMChMytHjg X-Received: by 2002:a17:902:bb8a:: with SMTP id m10-v6mr2494074pls.236.1527852353539; Fri, 01 Jun 2018 04:25:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852353; cv=none; d=google.com; s=arc-20160816; b=nMRpmnBjUo5hafQXbhorN2R60KMxyvY/Mm2p6roEMNBBwXjaCNOnIEB3AxYTJ03tei XCuxuixcvHDoTlJqYyVgblsX58GaTp8bUqwX4cdWRI6c3wcnYDPXjwNMCeSZ9gH7mrmv YXOp+lyl2UvZ5LVKcbsUdoAjLiH3G3sefSGOgo+dq+8PLN7PcVvHSOaji2WMeEA036A6 UWUo8Eow5IgcUle9VAEKYYI1ca5qp8mx0yTb7Y0Ujr+BnPa4so3vrMyL7bxv4jigwxe9 D9ISXSQZ0adbe8KJZ3yMEL6Y1d4/QxA9i7Q0QqufLmXcTx7gZkOc3aWmhRfvp3uwf4QP raaQ== 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=iemocDnVJQ7xzC5SIlxQ40unDLGqIdXL/TCmoRVQiao=; b=S+FbMaRihFub7Xmf0eq/6WffuivEnHmaeZSA4v767YR80fTFt9kwutFFVQKQMoc+wB c68mazFhDOXZqdLraeJE/4mase1+H68G8vLsHtjs2LPumkV73UD8NavOGouRjgSLfpcg n7d8cyajiujGSe52v2fkU6d3aSI3v5HlXnX8fkExyis2sRPXOo49X3gZJsBgT0HspwaU u+FhHX3WVnqxzTWUYP6eGj0/um/1KXAL2dfvuaMIAxi58jYbrZev4KBeKs7dGr9gyNRA YpwweLoo20KOtrOdvAikQXmzpgfvLbDNPYImLASvGxtoCbN1bLpqqltS+lPSrar/Eq9m 9nYA== 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 s3-v6si39385756plb.394.2018.06.01.04.25.53; Fri, 01 Jun 2018 04:25:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752096AbeFALZ1 (ORCPT + 30 others); Fri, 1 Jun 2018 07:25:27 -0400 Received: from foss.arm.com ([217.140.101.70]:50366 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751989AbeFALZS (ORCPT ); Fri, 1 Jun 2018 07:25:18 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1BC7416A3; Fri, 1 Jun 2018 04:25:18 -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 059EE3F25D; Fri, 1 Jun 2018 04:25:16 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland Subject: [PATCHv2 15/19] arm64: remove in-kernel call to sys_personality() Date: Fri, 1 Jun 2018 12:24:37 +0100 Message-Id: <20180601112441.37810-16-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 Cc: 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 Fri Jun 1 11:24:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137519 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp807276lji; Fri, 1 Jun 2018 04:27:25 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKC1FCsYbbuUOGwnhCFk7U9uNuCIARgjTbzQpV3WFw+WpmL99aOxuP+U0GvDHO/l44nga6P X-Received: by 2002:a62:1fd6:: with SMTP id l83-v6mr10674628pfj.182.1527852444969; Fri, 01 Jun 2018 04:27:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852444; cv=none; d=google.com; s=arc-20160816; b=b3php2FcorFNsSg7tJNTDU0bkJi3yEsFqlXk7ulwHrxs1iPqK+QaRU6hfUsgySfXf8 4uJPCgLkbMfsToWSRdGqfTSIqjC5JclnGiGUmQbdiD9SURjqgooNJPci3UcNLZRm87Wy Q9s2/nC4X657HgmkFg+gE9U41DhJY+kC0bs8xK4w45P2E2hcE4D/rYZ0IPprOYyrOO4u toppQa4OmjGw6vdPtZkyGMe73brOSaRWjS62mfT3N0B9IasfgHnpDbvzKzv4lrCKgVTz Zg4SbtuLHrN9s5j0y6CMZOsxOaQiDG+VzqN0bq5WQW+5qOzqbPjHj54/QdDPbdak1RLz wE1Q== 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=hBjJuyDd1pK2W0iK9C6UkQAUr59FhFQAPEcgIlSDjfo=; b=uOJ7Ptb4cCb9ggQVaOEuISJjZIQvWSPkc/ZgQkVkUK3uzh7z1GDNkjD6i58ryJc4Lz 7CSJLXtPd3Cwwfc+dkfdGnzEOTIuhv+h2u61/YzPI0v9iQ7ON5c+BoUet+DMcCH8iUBf eXWONU98J1/Gp7P1CCEnoZETlX0w9Ut8mi9RbDZIRieddxmwmgkvwrohDV7qBEewo8SO UyeZd2zAcycVZVe6NoknlEyD+8CvWS5Jp8jKRpHcyPvB1Z+08bPOPVzDd9u5jnBIfAHv ePAwNO5Jw1mUqvmmpDokMjF6rfS50BOEBfg+LUWfTC6953Z2U2P0lkReM0h/5NjRGw/v Zijg== 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 h4-v6si678978pgs.201.2018.06.01.04.27.24; Fri, 01 Jun 2018 04:27:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752141AbeFAL1W (ORCPT + 30 others); Fri, 1 Jun 2018 07:27:22 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50368 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751775AbeFALZU (ORCPT ); Fri, 1 Jun 2018 07:25:20 -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 DC3A516EA; Fri, 1 Jun 2018 04:25:19 -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 CEC793F25D; Fri, 1 Jun 2018 04:25:18 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland Subject: [PATCHv2 16/19] arm64: use {COMPAT,}SYSCALL_DEFINE0 for sigreturn Date: Fri, 1 Jun 2018 12:24:38 +0100 Message-Id: <20180601112441.37810-17-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 Cc: 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 caa7a68cf2d2..04a26dcbea32 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -538,7 +538,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 Fri Jun 1 11:24:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137518 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp806942lji; Fri, 1 Jun 2018 04:27:04 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLUZWblilItIrE7/Z8UXwh4wYoMCbq1s4tvzyEhTZshUVyhbPNy7jKjckwfge6asy+ZC4Xa X-Received: by 2002:a62:c6d8:: with SMTP id x85-v6mr113803pfk.249.1527852423909; Fri, 01 Jun 2018 04:27:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852423; cv=none; d=google.com; s=arc-20160816; b=XR+02/SmYRYUtnLTnuvNir4lw2L9dREv+wTRcBRvReqo5WbPYo4QM2MXBCBThmtmFR Q+sFuuav3YvTCUthr3Kmj/oAa4uFORtXlGxWrmllq9HnsQ6qDKQiDFHvG7s3GtvT43Zw bi/vJT02/Gat7IQ+UpPpNgMStGz7ZwI0M5owoNM+dJaUixr2s9U3OtHNIqJvWanAqwMY teaSNvq+wakePGXziFcN8z18RLfKch8cHZPFtTCH6kzj1QAx+4EJTS7CjiRiTUeYUimO P+ssksIVPO7faTwziOtpO6A2pnMHLjzb8g3tcz43Qny357E3wd0QLqm+2B+TgDVUbMg3 yQtQ== 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=tpwknUO5hW4xd9o9VI1aWSsObL7O/6tJQbYg+VGdd9Q=; b=Pw27M1ua4iUbWpcy4G+yJi9QQnW5Tjq3NEtn0xRv+M9DMRCiP1H40zeW1gll6lOGiG ZmdMA6Ut3pI8vjfxYKn5+/WqI597St2Jl9zq73uLzkFoq85pVGGY/+U6CylqClGxhzb/ D1pzyOauVA+WpRJnj6z7FNk9iwmqYnxiZXy13YL/hBidpP9QfFY5lSu23gjjet1C+uTz 8MqucNbpaT+C9S0LlJrKa14d0qi6gWKdeD7JlhFyS9O6z1YXtveQtAt7nGc1nZWxjawc kcahbfB2gKtd9BIyCkyVeIor7xbkbnG55tekKDI3DdD0WctB/BGeXXT8iWTeuUsntgnk jBNw== 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 m9-v6si39397641pfc.9.2018.06.01.04.27.03; Fri, 01 Jun 2018 04:27:03 -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 S1751988AbeFAL1B (ORCPT + 30 others); Fri, 1 Jun 2018 07:27:01 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50376 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751968AbeFALZV (ORCPT ); Fri, 1 Jun 2018 07:25:21 -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 B9E4D1713; Fri, 1 Jun 2018 04:25:21 -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 A3D453F25D; Fri, 1 Jun 2018 04:25:20 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland Subject: [PATCHv2 17/19] arm64: use SYSCALL_DEFINE6() for mmap Date: Fri, 1 Jun 2018 12:24:39 +0100 Message-Id: <20180601112441.37810-18-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 Cc: 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 Fri Jun 1 11:24:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137514 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp805611lji; Fri, 1 Jun 2018 04:25:31 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIhNOTRKI1pgJEbf+F6bK/gSv5QGeinHfc7djt0uLGvUT36bbrgjoouM5IZJUbw0GV74zQe X-Received: by 2002:a17:902:8217:: with SMTP id x23-v6mr10647080pln.380.1527852331364; Fri, 01 Jun 2018 04:25:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852331; cv=none; d=google.com; s=arc-20160816; b=Vvx6CP/v9DpwYXl6UT6fR5yE8Xn6TYD/IVe8ne0sfBWUGjiZcX2nszlgFbgC7lIpV9 BhWzCcJCU0FUL3qAvD2VHWEz3a0gykciYCe0U4l5fzCiGxv02eRbfoDoirG5vul35biT f2QJe9mnHOaoKuiFcR3nGm/5aCJyaxgRPpw3OeXetNvE3LR8decYNJ8ZtdoKXg8TX9Wz j052cgyVb81j8h8WVloFB8u9dJSZvkI5YZSv/XxC6oem4eo5rB+FGnpSjiEzio+Zk/Bv PvLDchz8UG9CS/sgVb2LP3JD3ICpnxuUYlEu8mhZ/Yuzd/ZcKpTpjbd3zm2DCuszwukI nl1Q== 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=8s1Ekf3dbxENn/mI9W8GE/xNNVh9H/ymdP5WnIVmw2A=; b=Qet1OON7gyZEiECL+iba/29Z734LzgURuKP9QuzY2vaNQ7e3eP/v/O2MasUo5+lVVN IxIFa9LL0PsAC2hQjz/GxtdkGheRCEILp0O89cpx/BUewHTZgN7Oj/LzwD+4OOg0vgNO Nh5v4N8fNBdMWvTvF7d7HjblfEdQp0cpjQ+A37hAOVK7GAKDm3UuOSExRdM9JwOEHra2 iMN4Y1b3vtz2ydZxLIMvmI6L3GyV2w77BlP/flEl3owWbV+GFPS9FcY7xqaeRKiNrAmb h/j8t1Jqx/svRUfyPYh6NGQKrMiHUh76teiat9DgNMBIeAsRsWR4g6wokdBllAUc/aUM FL4w== 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 b67-v6si38762507pfa.71.2018.06.01.04.25.30; Fri, 01 Jun 2018 04:25:31 -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 S1752123AbeFALZ2 (ORCPT + 30 others); Fri, 1 Jun 2018 07:25:28 -0400 Received: from foss.arm.com ([217.140.101.70]:50384 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752006AbeFALZX (ORCPT ); Fri, 1 Jun 2018 07:25:23 -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 7A586164F; Fri, 1 Jun 2018 04:25:23 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6D2253F25D; Fri, 1 Jun 2018 04:25:22 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland Subject: [PATCHv2 18/19] arm64: convert compat wrappers to C Date: Fri, 1 Jun 2018 12:24:40 +0100 Message-Id: <20180601112441.37810-19-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 Cc: 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 Fri Jun 1 11:24:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 137516 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp806046lji; Fri, 1 Jun 2018 04:26:00 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIstHt4tIBmF9VGXKC/5o73DFaADWl+dzy2AUKYLVsTEbmt6qcTyn5pQiVzNcdl9RPXKSmZ X-Received: by 2002:a62:d508:: with SMTP id d8-v6mr5238215pfg.128.1527852360632; Fri, 01 Jun 2018 04:26:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527852360; cv=none; d=google.com; s=arc-20160816; b=GghEJ+eUsjOKTuWJMITQcQY1IefEBDcDYkwIrHZlP4JMR7jMauP/2P+SD742uaIUjK ASEPE5eKde77gXq0SjY+03I9D3uSR9HkqJk4epEMhaIC6kGsN4gHZ1wUVNk/XRuRTNDg VGw3zVfRrLLLHdLpDXFTkJMYPMUxM1LZBkjIK5szmlnv9Gr5OR/Y05TzbkNVC2Yn7Alv QmDhqHkMrOUAHhGZw/h50ze/bpK6lzMrL94aDX/hzbAiY+LKYH6pyK/Ava0PzGdpqugY cuzeRsYvhdacucKX+i/ThY5PWTx9dYF+4AKSja2hR9B+j45iNzE2aFvdCcYDgbyF5hc9 1S7Q== 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=9VdWUWqKRHKXzvzX8VqZ4W1u/q3Oe9UulYCJZidClQI=; b=QHm1zag5qnd7yGKebxbST6KJOVHz8xTHILpS179nFOcZjzMMQqrdlXBm+F9XQVbv+a 7b2gr8EcT6vha8fdcZgu9PkjK0fkzisIxYXSuBR5VeDu3IK5MNG4NxcCf/KpmnSWWYms qN7+cHlBJGltu/IXzvpi4hE58ty3hYZPPVeQEvIJyxkscOXKG/Zdx4rEDqCclrvTkBUE e67YAApG1zoWLRkRSlTHhg765odqle0f4ZcZpVN75jHZnhR7f8F10K9GS7WzJfTff3js +s+cUg8/Ges1SlIjQ8m/3ALf3+B+M2ZvLLHDquQQ7YjppS3uh7vCiVjlDE2GRnzg08p/ xouQ== 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 s3-v6si39385756plb.394.2018.06.01.04.26.00; Fri, 01 Jun 2018 04:26:00 -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 S1752154AbeFALZ6 (ORCPT + 30 others); Fri, 1 Jun 2018 07:25:58 -0400 Received: from foss.arm.com ([217.140.101.70]:50394 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752067AbeFALZ0 (ORCPT ); Fri, 1 Jun 2018 07:25:26 -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 381AF165D; Fri, 1 Jun 2018 04:25:25 -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 2AB433F25D; Fri, 1 Jun 2018 04:25:24 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com Cc: Mark Rutland Subject: [PATCHv2 19/19] arm64: implement syscall wrappers Date: Fri, 1 Jun 2018 12:24:41 +0100 Message-Id: <20180601112441.37810-20-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180601112441.37810-1-mark.rutland@arm.com> References: <20180601112441.37810-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 define 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 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 | 8 +--- arch/arm64/kernel/traps.c | 2 + 6 files changed, 101 insertions(+), 9 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 0b98a6c42454..4c18c6b3c915 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -23,6 +23,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 6a31bb2a382b..e5985924f57e 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -12,15 +12,11 @@ long do_ni_syscall(struct pt_regs *regs); -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 void __invoke_syscall(struct pt_regs *regs, syscall_fn_t syscall_fn) { - regs->regs[0] = syscall_fn(regs->regs[0], regs->regs[1], - regs->regs[2], regs->regs[3], - regs->regs[4], regs->regs[5]); + regs->regs[0] = syscall_fn(regs); } static void invoke_syscall(struct pt_regs *regs, unsigned int scno, diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index b8d3e0d8c616..8bfcc37cbc65 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -549,6 +549,8 @@ asmlinkage void __exception do_sysinstr(unsigned int esr, struct pt_regs *regs) 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