Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4534839ybl; Mon, 13 Jan 2020 15:38:55 -0800 (PST) X-Google-Smtp-Source: APXvYqxWwRZYfsTaW1Ob8hEILmc3b9Rvx6gB9TGSNAeRiR5R8VMCMi7oCtJ0lDhXUggzYtFR3tRg X-Received: by 2002:a9d:7a97:: with SMTP id l23mr15444612otn.34.1578958735323; Mon, 13 Jan 2020 15:38:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578958735; cv=none; d=google.com; s=arc-20160816; b=uYddzyN+2jyi33m7fxC84GyLmIaKX7al+ggMq3HEc7/po9HGPk1L+okOXywb3n4xSQ l0yo2+kjAgOt06wcW6CewG2ZmOiBIN9bHk1m04EjJzm+3LrzqdLCNVSTmC8uKqycU3VG jMqLDI4Q8C4xij5v7pb6xIDFypUF64PSP88Kxrwh7Rmq3EQWsUupIl/fFqtnxNY3jlIL sQ7RHqMsgwplepNH6ddwlEM8fjLmCyz2qeWg/RsgNawWYfnzkyoRWW09F9NMm33O0K2o pnTIUnajwyUdeVHMlDBVXVxwMWIlfZbf9FtGw0FbO2eQhW/Z9d/Ar1tv517N9bqD+JB+ k2kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jJMEEjsbq4j2yKDBqk5ZQ3oc96bNkEIfgUBGbX7O/YQ=; b=CLgnfUZANTdY9cdm8IFZT50c7VTEGoPeNIdTvXvZvxeObDzR4rbGBNgazQ+mkskl0E OwshZqVOfsEaPh6yGTkCNLq0Grl5zoxZIjyO/XFCvlItZ+sKDBEm9W5ivir0IIULSnyG AiRRUkGMWaHN4R7uHrOKosbCxJdxsqXUNJwRs3Fgctd7bqmXn4Ub7XaAWrfn7twJyjOf IXLuW+rOLFGwpHQqWuRWce75D9jLTJZKN7EGC3HxRMfiaDwBHsUd62rKoOuztdjuXNvn zlafbzWNx2rP2I+Y9LxbhqVX7txbBidVfHShHtCf6tj0lDCbXYAJATuQvaYtWPOnxoPm LOqg== 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 m17si7837525otr.17.2020.01.13.15.38.43; Mon, 13 Jan 2020 15:38:55 -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 S1728977AbgAMXbC (ORCPT + 99 others); Mon, 13 Jan 2020 18:31:02 -0500 Received: from foss.arm.com ([217.140.110.172]:45634 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727282AbgAMXbC (ORCPT ); Mon, 13 Jan 2020 18:31:02 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A42FF11B3; Mon, 13 Jan 2020 15:31:01 -0800 (PST) Received: from ewhatever.cambridge.arm.com (ewhatever.cambridge.arm.com [10.1.197.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8A6403F68E; Mon, 13 Jan 2020 15:31:00 -0800 (PST) From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, will@kernel.org, maz@kernel.org, catalin.marinas@arm.com, ard.biesheuvel@linaro.org, mark.rutland@arm.com, Suzuki K Poulose Subject: [PATCH v3 1/7] arm64: Introduce system_capabilities_finalized() marker Date: Mon, 13 Jan 2020 23:30:17 +0000 Message-Id: <20200113233023.928028-2-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200113233023.928028-1-suzuki.poulose@arm.com> References: <20200113233023.928028-1-suzuki.poulose@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We finalize the system wide capabilities after the SMP CPUs are booted by the kernel. This is used as a marker for deciding various checks in the kernel. e.g, sanity check the hotplugged CPUs for missing mandatory features. However there is no explicit helper available for this in the kernel. There is sys_caps_initialised, which is not exposed. The other closest one we have is the jump_label arm64_const_caps_ready which denotes that the capabilities are set and the capability checks could use the individual jump_labels for fast path. This is performed before setting the ELF Hwcaps, which must be checked against the new CPUs. We also perform some of the other initialization e.g, SVE setup, which is important for the use of FP/SIMD where SVE is supported. Normally userspace doesn't get to run before we finish this. However the in-kernel users may potentially start using the neon mode. So, we need to reject uses of neon mode before we are set. Instead of defining a new marker for the completion of SVE setup, we could simply reuse the arm64_const_caps_ready and enable it once we have finished all the setup. Also we could expose this to the various users as "system_capabilities_finalized()" to make it more meaningful than "const_caps_ready". Cc: Ard Biesheuvel Cc: Will Deacon Cc: Mark Rutland Reviewed-by: Catalin Marinas Signed-off-by: Suzuki K Poulose --- arch/arm64/include/asm/cpufeature.h | 5 +++++ arch/arm64/include/asm/kvm_host.h | 2 +- arch/arm64/kernel/cpufeature.c | 28 ++++++++++------------------ arch/arm64/kernel/process.c | 2 +- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 4261d55e8506..92ef9539874a 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -613,6 +613,11 @@ static inline bool system_has_prio_mask_debugging(void) system_uses_irq_prio_masking(); } +static inline bool system_capabilities_finalized(void) +{ + return static_branch_likely(&arm64_const_caps_ready); +} + #define ARM64_BP_HARDEN_UNKNOWN -1 #define ARM64_BP_HARDEN_WA_NEEDED 0 #define ARM64_BP_HARDEN_NOT_REQUIRED 1 diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index c61260cf63c5..48ce54639eb5 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -547,7 +547,7 @@ static inline void __cpu_init_hyp_mode(phys_addr_t pgd_ptr, * wrong, and hyp will crash and burn when it uses any * cpus_have_const_cap() wrapper. */ - BUG_ON(!static_branch_likely(&arm64_const_caps_ready)); + BUG_ON(!system_capabilities_finalized()); __kvm_call_hyp((void *)pgd_ptr, hyp_stack_ptr, vector_ptr, tpidr_el2); /* diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index fa907b13dd55..1154f2d47b4b 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -56,13 +56,14 @@ EXPORT_SYMBOL(arm64_use_ng_mappings); * will be used to determine if a new booting CPU should * go through the verification process to make sure that it * supports the system capabilities, without using a hotplug - * notifier. + * notifier. This is also used to decide if we could use + * the fast path for checking constant CPU caps. */ -static bool sys_caps_initialised; - -static inline void set_sys_caps_initialised(void) +DEFINE_STATIC_KEY_FALSE(arm64_const_caps_ready); +EXPORT_SYMBOL(arm64_const_caps_ready); +static inline void finalize_system_capabilities(void) { - sys_caps_initialised = true; + static_branch_enable(&arm64_const_caps_ready); } static int dump_cpu_hwcaps(struct notifier_block *self, unsigned long v, void *p) @@ -789,7 +790,7 @@ void update_cpu_features(int cpu, /* Probe vector lengths, unless we already gave up on SVE */ if (id_aa64pfr0_sve(read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1)) && - !sys_caps_initialised) + !system_capabilities_finalized()) sve_update_vq_map(); } @@ -1002,7 +1003,7 @@ bool kaslr_requires_kpti(void) */ if (!IS_ENABLED(CONFIG_CAVIUM_ERRATUM_27456)) { tx1_bug = false; - } else if (!static_branch_likely(&arm64_const_caps_ready)) { + } else if (!system_capabilities_finalized()) { extern const struct midr_range cavium_erratum_27456_cpus[]; tx1_bug = is_midr_in_range_list(read_cpuid_id(), @@ -2046,7 +2047,7 @@ void check_local_cpu_capabilities(void) * Otherwise, this CPU should verify that it has all the system * advertised capabilities. */ - if (!sys_caps_initialised) + if (!system_capabilities_finalized()) update_cpu_capabilities(SCOPE_LOCAL_CPU); else verify_local_cpu_capabilities(); @@ -2060,14 +2061,6 @@ static void __init setup_boot_cpu_capabilities(void) enable_cpu_capabilities(SCOPE_BOOT_CPU); } -DEFINE_STATIC_KEY_FALSE(arm64_const_caps_ready); -EXPORT_SYMBOL(arm64_const_caps_ready); - -static void __init mark_const_caps_ready(void) -{ - static_branch_enable(&arm64_const_caps_ready); -} - bool this_cpu_has_cap(unsigned int n) { if (!WARN_ON(preemptible()) && n < ARM64_NCAPS) { @@ -2126,7 +2119,6 @@ void __init setup_cpu_features(void) u32 cwg; setup_system_capabilities(); - mark_const_caps_ready(); setup_elf_hwcaps(arm64_elf_hwcaps); if (system_supports_32bit_el0()) @@ -2139,7 +2131,7 @@ void __init setup_cpu_features(void) minsigstksz_setup(); /* Advertise that we have computed the system capabilities */ - set_sys_caps_initialised(); + finalize_system_capabilities(); /* * Check for sane CTR_EL0.CWG value. diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 71f788cd2b18..48a38144ea7b 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -646,6 +646,6 @@ asmlinkage void __sched arm64_preempt_schedule_irq(void) * Only allow a task to be preempted once cpufeatures have been * enabled. */ - if (static_branch_likely(&arm64_const_caps_ready)) + if (system_capabilities_finalized()) preempt_schedule_irq(); } -- 2.24.1