From patchwork Wed Jan 17 11:54:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Thierry X-Patchwork-Id: 124804 Delivered-To: patch@linaro.org Received: by 10.46.62.1 with SMTP id l1csp11724lja; Wed, 17 Jan 2018 03:56:29 -0800 (PST) X-Google-Smtp-Source: ACJfBoudI/oSPVccuB0COtb6pEBOxEzUS852oDJc3YVgBrB0WO8W5Kd7BI4bpam7MKNE0H/o40T9 X-Received: by 10.99.165.87 with SMTP id r23mr12428815pgu.93.1516190189218; Wed, 17 Jan 2018 03:56:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516190189; cv=none; d=google.com; s=arc-20160816; b=V58p3KGGVI7P6K/cCpcpptXS+WHldmu8aaW1vN6+0BdSll+0tIXEUtxFfheJYR8FNX 7E3oby3D/DlX4R+UUN9W/PpH3i70HQhS2fWKWbxKR4t11IQKU2LbERHe/9zGj2ln5fHS x6npa/qe61mVpbyzKeLoLr08xZCTjQOqv80NrkFowIDKJjzg/z7KCZ/jb7kPre7K8aMW ERAl3vYv6C/2OfOM4qs5yqnL0zrz8QLiBE1f5CNdscib/6QzTvDD11kDSmnAlQppKBTO gOcblCeUOsVUORaSurAT77vGUAYKc/Ndtap/wpWCHFfPleI4hlC9HCHev38DN5Nl+Qel Ejsg== 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=JBaDJUY/aBUFpCEhsd0a5rur5UCWwAfixcIuIfZWQOQ=; b=bLIRj6Z/1Zi5CSleI+EgnX1ZmIayVweVHdFLMLTFBlAVtnY8ECoNdK1b03eMXdg/cf SiKkRiiYb/yuHfUKR+T5EeB3WOrj7vsE7xQ9DVOGpcpjjViCA7Mh8+BMiVwmPEUiabP8 GASTqv2q6Xmay8zloCKGAmfCfyERvGusHYyShJvV5Z4FVSiv2P6rRuZOz1kcXuB8vKU4 29BLZYTt1ExAJdgRcQ0x6xBozrRmH5OwBI2QmLSXtkAp2otZ5ByITJxgC6Y0767P805Q AMRUXSDtPZq9XPpsRYyu/2/AJ7PFBPPTOvs2s499prDSj+VZyt62Y5hTpr+DQnrHZFdq jLoQ== 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 z6si3773894plo.200.2018.01.17.03.56.28; Wed, 17 Jan 2018 03:56:29 -0800 (PST) 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 S1753238AbeAQL40 (ORCPT + 28 others); Wed, 17 Jan 2018 06:56:26 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:39142 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753009AbeAQLzP (ORCPT ); Wed, 17 Jan 2018 06:55:15 -0500 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 E515215AD; Wed, 17 Jan 2018 03:55:14 -0800 (PST) Received: from e112298-lin.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 6BD653F53D; Wed, 17 Jan 2018 03:55:13 -0800 (PST) From: Julien Thierry To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: mark.rutland@arm.com, marc.zyngier@arm.com, james.morse@arm.com, daniel.thompson@linaro.org, Julien Thierry , Catalin Marinas , Will Deacon Subject: [PATCH v2 2/6] arm64: alternative: Apply alternatives early in boot process Date: Wed, 17 Jan 2018 11:54:40 +0000 Message-Id: <1516190084-18978-3-git-send-email-julien.thierry@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1516190084-18978-1-git-send-email-julien.thierry@arm.com> References: <1516190084-18978-1-git-send-email-julien.thierry@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Thompson Currently alternatives are applied very late in the boot process (and a long time after we enable scheduling). Some alternative sequences, such as those that alter the way CPU context is stored, must be applied much earlier in the boot sequence. Introduce apply_alternatives_early() to allow some alternatives to be applied immediately after we detect the CPU features of the boot CPU. Signed-off-by: Daniel Thompson Signed-off-by: Julien Thierry Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/include/asm/alternative.h | 1 + arch/arm64/kernel/alternative.c | 39 +++++++++++++++++++++++++++++++++--- arch/arm64/kernel/smp.c | 6 ++++++ 3 files changed, 43 insertions(+), 3 deletions(-) -- 1.9.1 diff --git a/arch/arm64/include/asm/alternative.h b/arch/arm64/include/asm/alternative.h index 4a85c69..1fc1cdb 100644 --- a/arch/arm64/include/asm/alternative.h +++ b/arch/arm64/include/asm/alternative.h @@ -20,6 +20,7 @@ struct alt_instr { u8 alt_len; /* size of new instruction(s), <= orig_len */ }; +void __init apply_alternatives_early(void); void __init apply_alternatives_all(void); void apply_alternatives(void *start, size_t length); diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c index 6dd0a3a3..78051d4 100644 --- a/arch/arm64/kernel/alternative.c +++ b/arch/arm64/kernel/alternative.c @@ -28,6 +28,18 @@ #include #include +/* + * early-apply features are detected using only the boot CPU and checked on + * secondary CPUs startup, even then, + * These early-apply features should only include features where we must + * patch the kernel very early in the boot process. + * + * Note that the cpufeature logic *must* be made aware of early-apply + * features to ensure they are reported as enabled without waiting + * for other CPUs to boot. + */ +#define EARLY_APPLY_FEATURE_MASK BIT(ARM64_HAS_SYSREG_GIC_CPUIF) + #define __ALT_PTR(a,f) ((void *)&(a)->f + (a)->f) #define ALT_ORIG_PTR(a) __ALT_PTR(a, orig_offset) #define ALT_REPL_PTR(a) __ALT_PTR(a, alt_offset) @@ -105,7 +117,8 @@ static u32 get_alt_insn(struct alt_instr *alt, __le32 *insnptr, __le32 *altinsnp return insn; } -static void __apply_alternatives(void *alt_region, bool use_linear_alias) +static void __apply_alternatives(void *alt_region, bool use_linear_alias, + unsigned long feature_mask) { struct alt_instr *alt; struct alt_region *region = alt_region; @@ -115,6 +128,9 @@ static void __apply_alternatives(void *alt_region, bool use_linear_alias) u32 insn; int i, nr_inst; + if ((BIT(alt->cpufeature) & feature_mask) == 0) + continue; + if (!cpus_have_cap(alt->cpufeature)) continue; @@ -138,6 +154,21 @@ static void __apply_alternatives(void *alt_region, bool use_linear_alias) } /* + * This is called very early in the boot process (directly after we run + * a feature detect on the boot CPU). No need to worry about other CPUs + * here. + */ +void apply_alternatives_early(void) +{ + struct alt_region region = { + .begin = (struct alt_instr *)__alt_instructions, + .end = (struct alt_instr *)__alt_instructions_end, + }; + + __apply_alternatives(®ion, true, EARLY_APPLY_FEATURE_MASK); +} + +/* * We might be patching the stop_machine state machine, so implement a * really simple polling protocol here. */ @@ -156,7 +187,9 @@ static int __apply_alternatives_multi_stop(void *unused) isb(); } else { BUG_ON(patched); - __apply_alternatives(®ion, true); + + __apply_alternatives(®ion, true, ~EARLY_APPLY_FEATURE_MASK); + /* Barriers provided by the cache flushing */ WRITE_ONCE(patched, 1); } @@ -177,5 +210,5 @@ void apply_alternatives(void *start, size_t length) .end = start + length, }; - __apply_alternatives(®ion, false); + __apply_alternatives(®ion, false, -1); } diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 551eb07..37361b5 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -453,6 +453,12 @@ void __init smp_prepare_boot_cpu(void) * cpuinfo_store_boot_cpu() above. */ update_cpu_errata_workarounds(); + /* + * We now know enough about the boot CPU to apply the + * alternatives that cannot wait until interrupt handling + * and/or scheduling is enabled. + */ + apply_alternatives_early(); } static u64 __init of_get_cpu_mpidr(struct device_node *dn)