Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6362092imu; Mon, 21 Jan 2019 07:38:09 -0800 (PST) X-Google-Smtp-Source: ALg8bN4xBf19Fr7MiKfhA6AZzjoXyhH8cXrlRiEOkFmLIYMWPAqnSy6sn9namm18+fyK5Ss+9hus X-Received: by 2002:a62:104a:: with SMTP id y71mr11091614pfi.34.1548085089498; Mon, 21 Jan 2019 07:38:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548085089; cv=none; d=google.com; s=arc-20160816; b=vYPUPMer1h/4dnvYfyLAsKxswNrT3LxMosUO4tU7DIZ5Fms6mcU2D0ILfO4BfVGN/5 0FDutgNupUrJg5UnZbIXwujQnuKj+NwPgznVGtB/6WpXJ6Jw8edIna4PNZVAh2M19E5T 6vZvpW5r6xBUn/Y35TfID9SIlay80oqlIh0E1BHz+CBpfGV+YVUJUvwtABaa3aNrWO/n 6bbCK4Veerj+CAFE1edaqlM8f8XXfMKXn+xhtRq5mQngBW3NTMyZOBlQkORghkI6dy+t Ultje4K6Pf9g6MPqVeZPV9xSqK77G1rAHaZVo5Bwi8N9487zB9dnJc2az+m0I2YJWBJw 53PA== 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; bh=jv/hahUg6/g/kZOVmDl/RCOr6qGP/yyeuvEX9LJPxgo=; b=X3/DdqhRvtmWiUShNOW2QpU4AUTt54i5FzoSc4krdFcjinR+5U9/InhAogPzamb59o CV638CaEC/GXxkk4sAZSADxl6oL7c8TPevjfjZ1ISux50PAzQlzLzrPOwWZztx6OSqms dH+tSrCUPVHq1XgMfQj/oRdpSUXB4mJMSxrbkw/girPgkmGKh15KblUT3jGTVIGGpJ8b SM9UMJGIusbLYw7QsO3WrIikJMqjZ7s9P9IA8Jyh7mH4VOLoaSn1t20dRYPgnMPAwbu9 FjnQshTYE4KPxRsr8K6GcAe6sWm+6diPrYvTxDPFXdCDPfeCnI0xsY64uyYUiRvkd7H6 6jOg== 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 y12si12614306plk.174.2019.01.21.07.37.54; Mon, 21 Jan 2019 07:38:09 -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 S1730108AbfAUPgJ (ORCPT + 99 others); Mon, 21 Jan 2019 10:36:09 -0500 Received: from foss.arm.com ([217.140.101.70]:36534 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730242AbfAUPee (ORCPT ); Mon, 21 Jan 2019 10:34:34 -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 10738EBD; Mon, 21 Jan 2019 07:34:34 -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 A7CBC3F5C1; Mon, 21 Jan 2019 07:34:31 -0800 (PST) From: Julien Thierry To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, daniel.thompson@linaro.org, joel@joelfernandes.org, marc.zyngier@arm.com, christoffer.dall@arm.com, james.morse@arm.com, catalin.marinas@arm.com, will.deacon@arm.com, mark.rutland@arm.com, Julien Thierry , Suzuki K Poulose , Marc Zyngier , Christoffer Dall Subject: [PATCH v9 14/26] arm64: alternative: Allow alternative status checking per cpufeature Date: Mon, 21 Jan 2019 15:33:33 +0000 Message-Id: <1548084825-8803-15-git-send-email-julien.thierry@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1548084825-8803-1-git-send-email-julien.thierry@arm.com> References: <1548084825-8803-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 In preparation for the application of alternatives at different points during the boot process, provide the possibility to check whether alternatives for a feature of interest was already applied instead of having a global boolean for all alternatives. Make VHE enablement code check for the VHE feature instead of considering all alternatives. Signed-off-by: Julien Thierry Cc: Catalin Marinas Cc: Will Deacon Cc: Suzuki K Poulose Cc: Marc Zyngier Cc: Christoffer Dall --- arch/arm64/include/asm/alternative.h | 3 +-- arch/arm64/kernel/alternative.c | 21 +++++++++++++++++---- arch/arm64/kernel/cpufeature.c | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/alternative.h b/arch/arm64/include/asm/alternative.h index 4b650ec..9806a23 100644 --- a/arch/arm64/include/asm/alternative.h +++ b/arch/arm64/include/asm/alternative.h @@ -14,8 +14,6 @@ #include #include -extern int alternatives_applied; - struct alt_instr { s32 orig_offset; /* offset to original instruction */ s32 alt_offset; /* offset to replacement instruction */ @@ -28,6 +26,7 @@ typedef void (*alternative_cb_t)(struct alt_instr *alt, __le32 *origptr, __le32 *updptr, int nr_inst); void __init apply_alternatives_all(void); +bool alternative_is_applied(u16 cpufeature); #ifdef CONFIG_MODULES void apply_alternatives_module(void *start, size_t length); diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c index b5d6039..c947d22 100644 --- a/arch/arm64/kernel/alternative.c +++ b/arch/arm64/kernel/alternative.c @@ -32,13 +32,23 @@ #define ALT_ORIG_PTR(a) __ALT_PTR(a, orig_offset) #define ALT_REPL_PTR(a) __ALT_PTR(a, alt_offset) -int alternatives_applied; +static int all_alternatives_applied; + +static DECLARE_BITMAP(applied_alternatives, ARM64_NCAPS); struct alt_region { struct alt_instr *begin; struct alt_instr *end; }; +bool alternative_is_applied(u16 cpufeature) +{ + if (WARN_ON(cpufeature >= ARM64_NCAPS)) + return false; + + return test_bit(cpufeature, applied_alternatives); +} + /* * Check if the target PC is within an alternative block. */ @@ -192,6 +202,9 @@ static void __apply_alternatives(void *alt_region, bool is_module) dsb(ish); __flush_icache_all(); isb(); + + /* We applied all that was available */ + bitmap_copy(applied_alternatives, cpu_hwcaps, ARM64_NCAPS); } } @@ -208,14 +221,14 @@ static int __apply_alternatives_multi_stop(void *unused) /* We always have a CPU 0 at this point (__init) */ if (smp_processor_id()) { - while (!READ_ONCE(alternatives_applied)) + while (!READ_ONCE(all_alternatives_applied)) cpu_relax(); isb(); } else { - BUG_ON(alternatives_applied); + BUG_ON(all_alternatives_applied); __apply_alternatives(®ion, false); /* Barriers provided by the cache flushing */ - WRITE_ONCE(alternatives_applied, 1); + WRITE_ONCE(all_alternatives_applied, 1); } return 0; diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 6f56e0a..d607ea3 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -1118,7 +1118,7 @@ static void cpu_copy_el2regs(const struct arm64_cpu_capabilities *__unused) * that, freshly-onlined CPUs will set tpidr_el2, so we don't need to * do anything here. */ - if (!alternatives_applied) + if (!alternative_is_applied(ARM64_HAS_VIRT_HOST_EXTN)) write_sysreg(read_sysreg(tpidr_el1), tpidr_el2); } #endif -- 1.9.1