public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: x86: kvm_fpu_get() is fpregs_lock_and_load()
@ 2025-12-22 21:33 Paolo Bonzini
  2025-12-22 22:18 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Paolo Bonzini @ 2025-12-22 21:33 UTC (permalink / raw)
  To: linux-kernel, kvm

The only difference is usage of switch_fpu_return() vs.
fpregs_restore_userregs().  In turn, these are only different
if there is no FPU at all, but KVM requires one.  Therefore use the
pre-made export---the code is simpler and there is no functional change.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/kernel/fpu/core.c | 2 +-
 arch/x86/kvm/fpu.h         | 6 +-----
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 3ab27fb86618..8ded41b023a2 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -858,7 +858,6 @@ void switch_fpu_return(void)
 
 	fpregs_restore_userregs();
 }
-EXPORT_SYMBOL_FOR_KVM(switch_fpu_return);
 
 void fpregs_lock_and_load(void)
 {
@@ -877,6 +876,7 @@ void fpregs_lock_and_load(void)
 
 	fpregs_assert_state_consistent();
 }
+EXPORT_SYMBOL_FOR_KVM(fpregs_lock_and_load);
 
 #ifdef CONFIG_X86_DEBUG_FPU
 /*
diff --git a/arch/x86/kvm/fpu.h b/arch/x86/kvm/fpu.h
index f898781b6a06..b6a03d8fa8af 100644
--- a/arch/x86/kvm/fpu.h
+++ b/arch/x86/kvm/fpu.h
@@ -149,11 +149,7 @@ static inline void _kvm_write_mmx_reg(int reg, const u64 *data)
 
 static inline void kvm_fpu_get(void)
 {
-	fpregs_lock();
-
-	fpregs_assert_state_consistent();
-	if (test_thread_flag(TIF_NEED_FPU_LOAD))
-		switch_fpu_return();
+	fpregs_lock_and_load();
 }
 
 static inline void kvm_fpu_put(void)
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] KVM: x86: kvm_fpu_get() is fpregs_lock_and_load()
  2025-12-22 21:33 [PATCH] KVM: x86: kvm_fpu_get() is fpregs_lock_and_load() Paolo Bonzini
@ 2025-12-22 22:18 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2025-12-22 22:18 UTC (permalink / raw)
  To: linux-kernel, kvm

On 12/22/25 22:33, Paolo Bonzini wrote:
> The only difference is usage of switch_fpu_return() vs.
> fpregs_restore_userregs().  In turn, these are only different
> if there is no FPU at all, but KVM requires one.  Therefore use the
> pre-made export---the code is simpler and there is no functional change.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   arch/x86/kernel/fpu/core.c | 2 +-
>   arch/x86/kvm/fpu.h         | 6 +-----
>   2 files changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
> index 3ab27fb86618..8ded41b023a2 100644
> --- a/arch/x86/kernel/fpu/core.c
> +++ b/arch/x86/kernel/fpu/core.c
> @@ -858,7 +858,6 @@ void switch_fpu_return(void)
>   
>   	fpregs_restore_userregs();
>   }
> -EXPORT_SYMBOL_FOR_KVM(switch_fpu_return);

Oops, unlike in my tree (patch to be sent tomorrow after I write a 
testcase) there's still an occurrence of switch_fpu_return() in 
vcpu_enter_guest().

Paolo

>   void fpregs_lock_and_load(void)
>   {
> @@ -877,6 +876,7 @@ void fpregs_lock_and_load(void)
>   
>   	fpregs_assert_state_consistent();
>   }
> +EXPORT_SYMBOL_FOR_KVM(fpregs_lock_and_load);
>   
>   #ifdef CONFIG_X86_DEBUG_FPU
>   /*
> diff --git a/arch/x86/kvm/fpu.h b/arch/x86/kvm/fpu.h
> index f898781b6a06..b6a03d8fa8af 100644
> --- a/arch/x86/kvm/fpu.h
> +++ b/arch/x86/kvm/fpu.h
> @@ -149,11 +149,7 @@ static inline void _kvm_write_mmx_reg(int reg, const u64 *data)
>   
>   static inline void kvm_fpu_get(void)
>   {
> -	fpregs_lock();
> -
> -	fpregs_assert_state_consistent();
> -	if (test_thread_flag(TIF_NEED_FPU_LOAD))
> -		switch_fpu_return();
> +	fpregs_lock_and_load();
>   }
>   
>   static inline void kvm_fpu_put(void)


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-12-22 22:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-22 21:33 [PATCH] KVM: x86: kvm_fpu_get() is fpregs_lock_and_load() Paolo Bonzini
2025-12-22 22:18 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox