linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Dave.Martin@arm.com (Dave Martin)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH v2 39/41] arm64/sve: Migrate to cpucap based detection for runtime SVE code
Date: Wed, 22 Mar 2017 14:51:09 +0000	[thread overview]
Message-ID: <1490194274-30569-40-git-send-email-Dave.Martin@arm.com> (raw)
In-Reply-To: <1490194274-30569-1-git-send-email-Dave.Martin@arm.com>

Checking elf_hwcap multiple times on the context switch path is an
unnecessary cost.

Because the cpufeature framework allows for more efficient
decisions by branch patching, it will be more efficient to test for
the ARM64_SVE CPU capability using cpus_have_const_cap() instead.

The test is guarded with IS_ENABLED() so that SVE-dependent code
can still be optimised out if CONFIG_ARM64_SVE is not set.

Signed-off-by: Dave Martin <Dave.Martin@arm.com>
---
 arch/arm64/include/asm/cpufeature.h |  3 ++-
 arch/arm64/kernel/fpsimd.c          | 26 ++++++++++++--------------
 arch/arm64/kernel/ptrace.c          |  5 +++--
 arch/arm64/kernel/signal.c          | 14 +++++---------
 4 files changed, 22 insertions(+), 26 deletions(-)

diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
index 90e4b79..e8d4857 100644
--- a/arch/arm64/include/asm/cpufeature.h
+++ b/arch/arm64/include/asm/cpufeature.h
@@ -263,7 +263,8 @@ static inline bool system_uses_ttbr0_pan(void)
 
 static inline bool system_supports_sve(void)
 {
-	return cpus_have_const_cap(ARM64_SVE);
+	return IS_ENABLED(CONFIG_ARM64_SVE) &&
+		cpus_have_const_cap(ARM64_SVE);
 }
 
 #endif /* __ASSEMBLY__ */
diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c
index 34ec75e..2b9def0 100644
--- a/arch/arm64/kernel/fpsimd.c
+++ b/arch/arm64/kernel/fpsimd.c
@@ -148,7 +148,7 @@ static void fpsimd_to_sve(struct task_struct *task)
 {
 	unsigned int vl = task->thread.sve_vl;
 
-	if (!(elf_hwcap & HWCAP_SVE))
+	if (!system_supports_sve())
 		return;
 
 	BUG_ON(!sve_vl_valid(vl));
@@ -169,7 +169,7 @@ static void sve_to_fpsimd(struct task_struct *task)
 {
 	unsigned int vl = task->thread.sve_vl;
 
-	if (!(elf_hwcap & HWCAP_SVE))
+	if (!system_supports_sve())
 		return;
 
 	BUG_ON(!sve_vl_valid(vl));
@@ -316,7 +316,7 @@ int sve_set_task_vl(struct task_struct *task,
 {
 	int ret;
 
-	if (!(elf_hwcap & HWCAP_SVE))
+	if (!system_supports_sve())
 		return -EINVAL;
 
 	BUG_ON(task != current);
@@ -334,7 +334,7 @@ int sve_set_task_vl(struct task_struct *task,
 /* PR_SVE_GET_VL */
 int sve_get_task_vl(struct task_struct *task)
 {
-	if (!(elf_hwcap & HWCAP_SVE))
+	if (!system_supports_sve())
 		return -EINVAL;
 
 	return sve_prctl_status(task);
@@ -552,8 +552,7 @@ void do_fpsimd_exc(unsigned int esr, struct pt_regs *regs)
 
 static void task_fpsimd_load(struct task_struct *task)
 {
-	if (IS_ENABLED(CONFIG_ARM64_SVE) &&
-	    test_tsk_thread_flag(task, TIF_SVE)) {
+	if (system_supports_sve() && test_tsk_thread_flag(task, TIF_SVE)) {
 		unsigned int vl = task->thread.sve_vl;
 
 		BUG_ON(!sve_vl_valid(vl));
@@ -567,7 +566,7 @@ static void task_fpsimd_load(struct task_struct *task)
 	 * Flip SVE enable for userspace if it doesn't match the
 	 * current_task.
 	 */
-	if (IS_ENABLED(CONFIG_ARM64_SVE) && (elf_hwcap & HWCAP_SVE)) {
+	if (system_supports_sve()) {
 		unsigned int tmp, flags;
 
 		asm ("mrs %0, cpacr_el1" : "=r" (tmp));
@@ -586,7 +585,7 @@ static void task_fpsimd_save(struct task_struct *task)
 	/* FIXME: remove task argument? */
 	BUG_ON(task != current);
 
-	if (IS_ENABLED(CONFIG_ARM64_SVE) &&
+	if (system_supports_sve() &&
 	    task_pt_regs(task)->syscallno != ~0UL &&
 	    test_tsk_thread_flag(task, TIF_SVE)) {
 		unsigned long tmp;
@@ -603,8 +602,7 @@ static void task_fpsimd_save(struct task_struct *task)
 		);
 	}
 
-	if (IS_ENABLED(CONFIG_ARM64_SVE) &&
-	    test_tsk_thread_flag(task, TIF_SVE))
+	if (system_supports_sve() && test_tsk_thread_flag(task, TIF_SVE))
 		sve_save_state(sve_pffr(task),
 			       &task->thread.fpsimd_state.fpsr);
 	else
@@ -652,7 +650,7 @@ void fpsimd_flush_thread(void)
 
 	memset(&current->thread.fpsimd_state, 0, sizeof(struct fpsimd_state));
 
-	if (IS_ENABLED(CONFIG_ARM64_SVE) && (elf_hwcap & HWCAP_SVE)) {
+	if (system_supports_sve()) {
 		clear_sve_regs(current);
 
 		current->thread.sve_vl = current->thread.sve_vl_onexec ?
@@ -733,7 +731,7 @@ void fpsimd_update_current_state(struct fpsimd_state *state)
 		return;
 	preempt_disable();
 
-	if (IS_ENABLED(CONFIG_ARM64_SVE) && test_thread_flag(TIF_SVE)) {
+	if (system_supports_sve() && test_thread_flag(TIF_SVE)) {
 		current->thread.fpsimd_state = *state;
 		fpsimd_to_sve(current);
 	}
@@ -777,7 +775,7 @@ void kernel_neon_begin_partial(u32 num_regs)
 	 * interrupt context, so always save the userland SVE state
 	 * if there is any, even for interrupts.
 	 */
-	if (IS_ENABLED(CONFIG_ARM64_SVE) &&
+	if (system_supports_sve() &&
 	    test_thread_flag(TIF_SVE) && current->mm &&
 	    !test_and_set_thread_flag(TIF_FOREIGN_FPSTATE)) {
 		fpsimd_save_state(&current->thread.fpsimd_state);
@@ -918,7 +916,7 @@ static int __init fpsimd_init(void)
 	if (!(elf_hwcap & HWCAP_ASIMD))
 		pr_notice("Advanced SIMD is not implemented\n");
 
-	if (IS_ENABLED(CONFIG_ARM64_SVE) && (elf_hwcap & HWCAP_SVE))
+	if (system_supports_sve())
 		return sve_procfs_init();
 
 	return 0;
diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
index 02d3265..bbb8e38 100644
--- a/arch/arm64/kernel/ptrace.c
+++ b/arch/arm64/kernel/ptrace.c
@@ -42,6 +42,7 @@
 #include <linux/elf.h>
 
 #include <asm/compat.h>
+#include <asm/cpufeature.h>
 #include <asm/debug-monitors.h>
 #include <asm/pgtable.h>
 #include <asm/syscall.h>
@@ -740,7 +741,7 @@ static int sve_get(struct task_struct *target,
 	unsigned int vq;
 	unsigned long start, end;
 
-	if (!(elf_hwcap & HWCAP_SVE))
+	if (!system_supports_sve())
 		return -EINVAL;
 
 	/* Header */
@@ -835,7 +836,7 @@ static int sve_set(struct task_struct *target,
 	unsigned int vq;
 	unsigned long start, end;
 
-	if (!(elf_hwcap & HWCAP_SVE))
+	if (!system_supports_sve())
 		return -EINVAL;
 
 	/* Header */
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 45f0c2c..e3810e2 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -378,10 +378,7 @@ static int parse_user_sigframe(struct user_ctxs *user,
 			break;
 
 		case SVE_MAGIC:
-			if (!IS_ENABLED(CONFIG_ARM64_SVE))
-				goto invalid;
-
-			if (!(elf_hwcap & HWCAP_SVE))
+			if (!system_supports_sve())
 				goto invalid;
 
 			if (user->sve)
@@ -481,8 +478,7 @@ static int restore_sigframe(struct pt_regs *regs,
 			return -EINVAL;
 
 		if (user.sve) {
-			if (!IS_ENABLED(CONFIG_ARM64_SVE) ||
-			    !(elf_hwcap & HWCAP_SVE))
+			if (!system_supports_sve())
 				return -EINVAL;
 
 			err = restore_sve_fpsimd_context(&user);
@@ -547,14 +543,14 @@ static int setup_sigframe_layout(struct rt_sigframe_user_layout *user)
 			return err;
 	}
 
-	if (IS_ENABLED(CONFIG_ARM64_SVE) && test_thread_flag(TIF_SVE)) {
+	if (system_supports_sve() && test_thread_flag(TIF_SVE)) {
 		unsigned int vl = current->thread.sve_vl;
 		unsigned int vq;
 
 		BUG_ON(!sve_vl_valid(vl));
 		vq = sve_vq_from_vl(vl);
 
-		BUG_ON(!(elf_hwcap & HWCAP_SVE));
+		BUG_ON(!system_supports_sve());
 
 		err = sigframe_alloc(user, &user->sve_offset,
 				     SVE_SIG_CONTEXT_SIZE(vq));
@@ -604,7 +600,7 @@ static int setup_sigframe(struct rt_sigframe_user_layout *user,
 	}
 
 	/* Scalable Vector Extension state, if present */
-	if (IS_ENABLED(CONFIG_ARM64_SVE) && err == 0 && user->sve_offset) {
+	if (system_supports_sve() && err == 0 && user->sve_offset) {
 		struct sve_context __user *sve_ctx =
 			apply_user_offset(user, user->sve_offset);
 		err |= preserve_sve_context(sve_ctx);
-- 
2.1.4

  parent reply	other threads:[~2017-03-22 14:51 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-22 14:50 [RFC PATCH v2 00/41] Scalable Vector Extension (SVE) core support Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 01/41] arm64: signal: Refactor sigcontext parsing in rt_sigreturn Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 02/41] arm64: signal: factor frame layout and population into separate passes Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 03/41] arm64: signal: factor out signal frame record allocation Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 04/41] arm64: signal: Allocate extra sigcontext space as needed Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 05/41] arm64: signal: Parse extra_context during sigreturn Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 06/41] arm64: efi: Add missing Kconfig dependency on KERNEL_MODE_NEON Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 07/41] arm64/sve: Allow kernel-mode NEON to be disabled in Kconfig Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 08/41] arm64/sve: Low-level save/restore code Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 09/41] arm64/sve: Boot-time feature detection and reporting Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 10/41] arm64/sve: Boot-time feature enablement Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 11/41] arm64/sve: Expand task_struct for Scalable Vector Extension state Dave Martin
2017-03-22 16:20   ` Mark Rutland
2017-03-23 10:49     ` Dave Martin
2017-03-23 11:26       ` Mark Rutland
2017-03-22 14:50 ` [RFC PATCH v2 12/41] arm64/sve: Save/restore SVE state on context switch paths Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 13/41] arm64/sve: [BROKEN] Basic support for KERNEL_MODE_NEON Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 14/41] Revert "arm64/sve: Allow kernel-mode NEON to be disabled in Kconfig" Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 15/41] arm64/sve: Restore working FPSIMD save/restore around signals Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 16/41] arm64/sve: signal: Add SVE state record to sigcontext Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 17/41] arm64/sve: signal: Dump Scalable Vector Extension registers to user stack Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 18/41] arm64/sve: signal: Restore FPSIMD/SVE state in rt_sigreturn Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 19/41] arm64/sve: Avoid corruption when replacing the SVE state Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 20/41] arm64/sve: traps: Add descriptive string for SVE exceptions Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 21/41] arm64/sve: Enable SVE on demand for userspace Dave Martin
2017-03-22 16:48   ` Mark Rutland
2017-03-23 11:24     ` Dave Martin
2017-03-23 11:30       ` Suzuki K Poulose
2017-03-23 11:52         ` Mark Rutland
2017-03-23 12:07           ` Dave Martin
2017-03-23 13:40             ` Mark Rutland
2017-03-23 13:45               ` Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 22/41] arm64/sve: Implement FPSIMD-only context for tasks not using SVE Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 23/41] arm64/sve: Move ZEN handling to the common task_fpsimd_load() path Dave Martin
2017-03-22 16:55   ` Mark Rutland
2017-03-23 11:52     ` Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 24/41] arm64/sve: Discard SVE state on system call Dave Martin
2017-03-22 17:03   ` Mark Rutland
2017-03-23 11:59     ` Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 25/41] arm64/sve: Avoid preempt_disable() during sigreturn Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 26/41] arm64/sve: Avoid stale user register state after SVE access exception Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 27/41] arm64/sve: ptrace support Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 28/41] arm64: KVM: Treat SVE use by guests as undefined instruction execution Dave Martin
2017-03-22 17:06   ` Mark Rutland
2017-03-23 12:10     ` Dave Martin
2017-03-22 14:50 ` [RFC PATCH v2 29/41] prctl: Add skeleton for PR_SVE_{SET, GET}_VL controls Dave Martin
2017-03-22 14:51 ` [RFC PATCH v2 30/41] arm64/sve: Track vector length for each task Dave Martin
2017-03-22 14:51 ` [RFC PATCH v2 31/41] arm64/sve: Set CPU vector length to match current task Dave Martin
2017-03-22 14:51 ` [RFC PATCH v2 32/41] arm64/sve: Factor out clearing of tasks' SVE regs Dave Martin
2017-03-22 14:51 ` [RFC PATCH v2 33/41] arm64/sve: Wire up vector length control prctl() calls Dave Martin
2017-03-22 14:51 ` [RFC PATCH v2 34/41] arm64/sve: Disallow VL setting for individual threads by default Dave Martin
2017-03-22 14:51 ` [RFC PATCH v2 35/41] arm64/sve: Add vector length inheritance control Dave Martin
2017-03-22 14:51 ` [RFC PATCH v2 36/41] arm64/sve: ptrace: Wire up vector length control and reporting Dave Martin
2017-03-22 14:51 ` [RFC PATCH v2 37/41] arm64/sve: Enable default vector length control via procfs Dave Martin
2017-03-22 14:51 ` [RFC PATCH v2 38/41] arm64/sve: Detect SVE via the cpufeature framework Dave Martin
2017-03-23 14:11   ` Suzuki K Poulose
2017-03-23 14:37     ` Dave Martin
2017-03-23 14:43       ` Dave Martin
2017-03-22 14:51 ` Dave Martin [this message]
2017-03-22 14:51 ` [RFC PATCH v2 40/41] arm64/sve: Allocate task SVE context storage dynamically Dave Martin
2017-03-22 14:51 ` [RFC PATCH v2 41/41] arm64/sve: Documentation: Add overview of the SVE userspace ABI Dave Martin
2017-03-31 15:28 ` [RFC PATCH v2 00/41] Scalable Vector Extension (SVE) core support Ard Biesheuvel
2017-04-03  9:45   ` Dave Martin
2017-04-03 10:01     ` Ard Biesheuvel
2017-04-03 10:51       ` Dave Martin
2017-04-03 10:55         ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1490194274-30569-40-git-send-email-Dave.Martin@arm.com \
    --to=dave.martin@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).