| From 49fd0bc0c1a598ece68d7f1e77da4835652690e8 Mon Sep 17 00:00:00 2001 |
| From: Julien Grall <julien.grall@arm.com> |
| Date: Tue, 21 May 2019 18:21:38 +0100 |
| Subject: [PATCH] arm64/fpsimd: Introduce fpsimd_save_and_flush_cpu_state() and |
| use it |
| |
| commit 54b8c7cbc57c1ce21f4e35101f2609092c4af49a upstream. |
| |
| The only external user of fpsimd_save() and fpsimd_flush_cpu_state() is |
| the KVM FPSIMD code. |
| |
| A following patch will introduce a mechanism to acquire owernship of the |
| FPSIMD/SVE context for performing context management operations. Rather |
| than having to export the new helpers to get/put the context, we can just |
| introduce a new function to combine fpsimd_save() and |
| fpsimd_flush_cpu_state(). |
| |
| This has also the advantage to remove any external call of fpsimd_save() |
| and fpsimd_flush_cpu_state(), so they can be turned static. |
| |
| Lastly, the new function can also be used in the PM notifier. |
| |
| Reviewed-by: Dave Martin <Dave.Martin@arm.com> |
| Acked-by: Marc Zyngier <marc.zyngier@arm.com> |
| Signed-off-by: Julien Grall <julien.grall@arm.com> |
| Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> |
| Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> |
| |
| diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h |
| index 5b34cff5151b..b6a2c352f4c3 100644 |
| --- a/arch/arm64/include/asm/fpsimd.h |
| +++ b/arch/arm64/include/asm/fpsimd.h |
| @@ -37,8 +37,6 @@ struct task_struct; |
| extern void fpsimd_save_state(struct user_fpsimd_state *state); |
| extern void fpsimd_load_state(struct user_fpsimd_state *state); |
| |
| -extern void fpsimd_save(void); |
| - |
| extern void fpsimd_thread_switch(struct task_struct *next); |
| extern void fpsimd_flush_thread(void); |
| |
| @@ -52,7 +50,7 @@ extern void fpsimd_bind_state_to_cpu(struct user_fpsimd_state *state, |
| void *sve_state, unsigned int sve_vl); |
| |
| extern void fpsimd_flush_task_state(struct task_struct *target); |
| -extern void fpsimd_flush_cpu_state(void); |
| +extern void fpsimd_save_and_flush_cpu_state(void); |
| |
| /* Maximum VL that SVE VL-agnostic software can transparently support */ |
| #define SVE_VL_ARCH_MAX 0x100 |
| diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c |
| index 0cfcf5c237c5..1041c6a8f072 100644 |
| --- a/arch/arm64/kernel/fpsimd.c |
| +++ b/arch/arm64/kernel/fpsimd.c |
| @@ -236,7 +236,7 @@ static void task_fpsimd_load(void) |
| * |
| * Softirqs (and preemption) must be disabled. |
| */ |
| -void fpsimd_save(void) |
| +static void fpsimd_save(void) |
| { |
| struct fpsimd_last_state_struct const *last = |
| this_cpu_ptr(&fpsimd_last_state); |
| @@ -1135,12 +1135,22 @@ void fpsimd_flush_task_state(struct task_struct *t) |
| * Invalidate any task's FPSIMD state that is present on this cpu. |
| * This function must be called with softirqs disabled. |
| */ |
| -void fpsimd_flush_cpu_state(void) |
| +static void fpsimd_flush_cpu_state(void) |
| { |
| __this_cpu_write(fpsimd_last_state.st, NULL); |
| set_thread_flag(TIF_FOREIGN_FPSTATE); |
| } |
| |
| +/* |
| + * Save the FPSIMD state to memory and invalidate cpu view. |
| + * This function must be called with softirqs (and preemption) disabled. |
| + */ |
| +void fpsimd_save_and_flush_cpu_state(void) |
| +{ |
| + fpsimd_save(); |
| + fpsimd_flush_cpu_state(); |
| +} |
| + |
| #ifdef CONFIG_KERNEL_MODE_NEON |
| |
| DEFINE_PER_CPU(bool, kernel_neon_busy); |
| @@ -1297,8 +1307,7 @@ static int fpsimd_cpu_pm_notifier(struct notifier_block *self, |
| { |
| switch (cmd) { |
| case CPU_PM_ENTER: |
| - fpsimd_save(); |
| - fpsimd_flush_cpu_state(); |
| + fpsimd_save_and_flush_cpu_state(); |
| break; |
| case CPU_PM_EXIT: |
| break; |
| diff --git a/arch/arm64/kvm/fpsimd.c b/arch/arm64/kvm/fpsimd.c |
| index 6e3c9c8b2df9..525010504f9d 100644 |
| --- a/arch/arm64/kvm/fpsimd.c |
| +++ b/arch/arm64/kvm/fpsimd.c |
| @@ -112,9 +112,7 @@ void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu) |
| if (vcpu->arch.flags & KVM_ARM64_FP_ENABLED) { |
| u64 *guest_zcr = &vcpu->arch.ctxt.sys_regs[ZCR_EL1]; |
| |
| - /* Clean guest FP state to memory and invalidate cpu view */ |
| - fpsimd_save(); |
| - fpsimd_flush_cpu_state(); |
| + fpsimd_save_and_flush_cpu_state(); |
| |
| if (guest_has_sve) |
| *guest_zcr = read_sysreg_s(SYS_ZCR_EL12); |
| -- |
| 2.7.4 |
| |