All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/2] KVM: arm64: Additional documentation of the FP code
@ 2022-01-24 15:57 ` Mark Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2022-01-24 15:57 UTC (permalink / raw)
  To: Marc Zyngier; +Cc: Mark Brown, kvmarm, linux-arm-kernel

These couple of patches add a few more comments to the floating point
code which will hopefully help the next person who comes along and tries
to figure out what is going on.

Mark Brown (2):
  KVM: arm64: Add comments for context flush and sync callbacks
  KVM: arm64: Add some more comments in kvm_hyp_handle_fpsimd()

 arch/arm64/kvm/fpsimd.c                 | 14 ++++++++++----
 arch/arm64/kvm/hyp/include/hyp/switch.h |  4 ++++
 2 files changed, 14 insertions(+), 4 deletions(-)


base-commit: e783362eb54cd99b2cac8b3a9aeac942e6f6ac07
-- 
2.30.2

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

* [PATCH v1 0/2] KVM: arm64: Additional documentation of the FP code
@ 2022-01-24 15:57 ` Mark Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2022-01-24 15:57 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: James Morse, Alexandru Elisei, Suzuki K Poulose,
	linux-arm-kernel, kvmarm, Mark Brown

These couple of patches add a few more comments to the floating point
code which will hopefully help the next person who comes along and tries
to figure out what is going on.

Mark Brown (2):
  KVM: arm64: Add comments for context flush and sync callbacks
  KVM: arm64: Add some more comments in kvm_hyp_handle_fpsimd()

 arch/arm64/kvm/fpsimd.c                 | 14 ++++++++++----
 arch/arm64/kvm/hyp/include/hyp/switch.h |  4 ++++
 2 files changed, 14 insertions(+), 4 deletions(-)


base-commit: e783362eb54cd99b2cac8b3a9aeac942e6f6ac07
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v1 1/2] KVM: arm64: Add comments for context flush and sync callbacks
  2022-01-24 15:57 ` Mark Brown
@ 2022-01-24 15:57   ` Mark Brown
  -1 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2022-01-24 15:57 UTC (permalink / raw)
  To: Marc Zyngier; +Cc: Mark Brown, kvmarm, linux-arm-kernel

Add a little bit of information on where _ctxflush_fp() and _ctxsync_fp()
are called to help people unfamiliar with the code get up to speed.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 arch/arm64/kvm/fpsimd.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/kvm/fpsimd.c b/arch/arm64/kvm/fpsimd.c
index 2f48fd362a8c..397fdac75cb1 100644
--- a/arch/arm64/kvm/fpsimd.c
+++ b/arch/arm64/kvm/fpsimd.c
@@ -84,6 +84,11 @@ void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu)
 		vcpu->arch.flags |= KVM_ARM64_HOST_SVE_ENABLED;
 }
 
+/*
+ * Called just before entering the guest once we are no longer
+ * preemptable. Syncs the host's TIF_FOREIGN_FPSTATE with the KVM
+ * mirror of the flag used by the hypervisor.
+ */
 void kvm_arch_vcpu_ctxflush_fp(struct kvm_vcpu *vcpu)
 {
 	if (test_thread_flag(TIF_FOREIGN_FPSTATE))
@@ -93,10 +98,11 @@ void kvm_arch_vcpu_ctxflush_fp(struct kvm_vcpu *vcpu)
 }
 
 /*
- * If the guest FPSIMD state was loaded, update the host's context
- * tracking data mark the CPU FPSIMD regs as dirty and belonging to vcpu
- * so that they will be written back if the kernel clobbers them due to
- * kernel-mode NEON before re-entry into the guest.
+ * Called just after exiting the guest. If the guest FPSIMD state
+ * was loaded, update the host's context tracking data mark the CPU
+ * FPSIMD regs as dirty and belonging to vcpu so that they will be
+ * written back if the kernel clobbers them due to kernel-mode NEON
+ * before re-entry into the guest.
  */
 void kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu)
 {
-- 
2.30.2

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

* [PATCH v1 1/2] KVM: arm64: Add comments for context flush and sync callbacks
@ 2022-01-24 15:57   ` Mark Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2022-01-24 15:57 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: James Morse, Alexandru Elisei, Suzuki K Poulose,
	linux-arm-kernel, kvmarm, Mark Brown

Add a little bit of information on where _ctxflush_fp() and _ctxsync_fp()
are called to help people unfamiliar with the code get up to speed.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 arch/arm64/kvm/fpsimd.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/kvm/fpsimd.c b/arch/arm64/kvm/fpsimd.c
index 2f48fd362a8c..397fdac75cb1 100644
--- a/arch/arm64/kvm/fpsimd.c
+++ b/arch/arm64/kvm/fpsimd.c
@@ -84,6 +84,11 @@ void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu)
 		vcpu->arch.flags |= KVM_ARM64_HOST_SVE_ENABLED;
 }
 
+/*
+ * Called just before entering the guest once we are no longer
+ * preemptable. Syncs the host's TIF_FOREIGN_FPSTATE with the KVM
+ * mirror of the flag used by the hypervisor.
+ */
 void kvm_arch_vcpu_ctxflush_fp(struct kvm_vcpu *vcpu)
 {
 	if (test_thread_flag(TIF_FOREIGN_FPSTATE))
@@ -93,10 +98,11 @@ void kvm_arch_vcpu_ctxflush_fp(struct kvm_vcpu *vcpu)
 }
 
 /*
- * If the guest FPSIMD state was loaded, update the host's context
- * tracking data mark the CPU FPSIMD regs as dirty and belonging to vcpu
- * so that they will be written back if the kernel clobbers them due to
- * kernel-mode NEON before re-entry into the guest.
+ * Called just after exiting the guest. If the guest FPSIMD state
+ * was loaded, update the host's context tracking data mark the CPU
+ * FPSIMD regs as dirty and belonging to vcpu so that they will be
+ * written back if the kernel clobbers them due to kernel-mode NEON
+ * before re-entry into the guest.
  */
 void kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu)
 {
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v1 2/2] KVM: arm64: Add some more comments in kvm_hyp_handle_fpsimd()
  2022-01-24 15:57 ` Mark Brown
@ 2022-01-24 15:57   ` Mark Brown
  -1 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2022-01-24 15:57 UTC (permalink / raw)
  To: Marc Zyngier; +Cc: Mark Brown, kvmarm, linux-arm-kernel

The handling for FPSIMD/SVE traps is multi stage and involves some trap
manipulation which isn't quite so immediately obvious as might be desired
so add a few more comments.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 arch/arm64/kvm/hyp/include/hyp/switch.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h
index 58e14f8ead23..1995808d8766 100644
--- a/arch/arm64/kvm/hyp/include/hyp/switch.h
+++ b/arch/arm64/kvm/hyp/include/hyp/switch.h
@@ -173,6 +173,8 @@ static bool kvm_hyp_handle_fpsimd(struct kvm_vcpu *vcpu, u64 *exit_code)
 		return false;
 
 	/* Valid trap.  Switch the context: */
+
+	/* First disable enough traps to allow us to update the registers */
 	if (has_vhe()) {
 		reg = CPACR_EL1_FPEN;
 		if (sve_guest)
@@ -188,11 +190,13 @@ static bool kvm_hyp_handle_fpsimd(struct kvm_vcpu *vcpu, u64 *exit_code)
 	}
 	isb();
 
+	/* Write out the host state if it's in the registers */
 	if (vcpu->arch.flags & KVM_ARM64_FP_HOST) {
 		__fpsimd_save_state(vcpu->arch.host_fpsimd_state);
 		vcpu->arch.flags &= ~KVM_ARM64_FP_HOST;
 	}
 
+	/* Restore the guest state */
 	if (sve_guest)
 		__hyp_sve_restore_guest(vcpu);
 	else
-- 
2.30.2

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

* [PATCH v1 2/2] KVM: arm64: Add some more comments in kvm_hyp_handle_fpsimd()
@ 2022-01-24 15:57   ` Mark Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2022-01-24 15:57 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: James Morse, Alexandru Elisei, Suzuki K Poulose,
	linux-arm-kernel, kvmarm, Mark Brown

The handling for FPSIMD/SVE traps is multi stage and involves some trap
manipulation which isn't quite so immediately obvious as might be desired
so add a few more comments.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 arch/arm64/kvm/hyp/include/hyp/switch.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h
index 58e14f8ead23..1995808d8766 100644
--- a/arch/arm64/kvm/hyp/include/hyp/switch.h
+++ b/arch/arm64/kvm/hyp/include/hyp/switch.h
@@ -173,6 +173,8 @@ static bool kvm_hyp_handle_fpsimd(struct kvm_vcpu *vcpu, u64 *exit_code)
 		return false;
 
 	/* Valid trap.  Switch the context: */
+
+	/* First disable enough traps to allow us to update the registers */
 	if (has_vhe()) {
 		reg = CPACR_EL1_FPEN;
 		if (sve_guest)
@@ -188,11 +190,13 @@ static bool kvm_hyp_handle_fpsimd(struct kvm_vcpu *vcpu, u64 *exit_code)
 	}
 	isb();
 
+	/* Write out the host state if it's in the registers */
 	if (vcpu->arch.flags & KVM_ARM64_FP_HOST) {
 		__fpsimd_save_state(vcpu->arch.host_fpsimd_state);
 		vcpu->arch.flags &= ~KVM_ARM64_FP_HOST;
 	}
 
+	/* Restore the guest state */
 	if (sve_guest)
 		__hyp_sve_restore_guest(vcpu);
 	else
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 0/2] KVM: arm64: Additional documentation of the FP code
  2022-01-24 15:57 ` Mark Brown
@ 2022-02-08 17:37   ` Marc Zyngier
  -1 siblings, 0 replies; 8+ messages in thread
From: Marc Zyngier @ 2022-02-08 17:37 UTC (permalink / raw)
  To: Mark Brown; +Cc: kvmarm, linux-arm-kernel

On Mon, 24 Jan 2022 15:57:18 +0000, Mark Brown wrote:
> These couple of patches add a few more comments to the floating point
> code which will hopefully help the next person who comes along and tries
> to figure out what is going on.
> 
> Mark Brown (2):
>   KVM: arm64: Add comments for context flush and sync callbacks
>   KVM: arm64: Add some more comments in kvm_hyp_handle_fpsimd()
> 
> [...]

Applied to next, thanks!

[1/2] KVM: arm64: Add comments for context flush and sync callbacks
      commit: 23afc82539cfcce105bf18c5c835c75e463ca349
[2/2] KVM: arm64: Add some more comments in kvm_hyp_handle_fpsimd()
      commit: 01a244decc760b1ae2caa045647d79ff431bf37b

Cheers,

	M.
-- 
Without deviation from the norm, progress is not possible.


_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

* Re: [PATCH v1 0/2] KVM: arm64: Additional documentation of the FP code
@ 2022-02-08 17:37   ` Marc Zyngier
  0 siblings, 0 replies; 8+ messages in thread
From: Marc Zyngier @ 2022-02-08 17:37 UTC (permalink / raw)
  To: Mark Brown; +Cc: kvmarm, linux-arm-kernel

On Mon, 24 Jan 2022 15:57:18 +0000, Mark Brown wrote:
> These couple of patches add a few more comments to the floating point
> code which will hopefully help the next person who comes along and tries
> to figure out what is going on.
> 
> Mark Brown (2):
>   KVM: arm64: Add comments for context flush and sync callbacks
>   KVM: arm64: Add some more comments in kvm_hyp_handle_fpsimd()
> 
> [...]

Applied to next, thanks!

[1/2] KVM: arm64: Add comments for context flush and sync callbacks
      commit: 23afc82539cfcce105bf18c5c835c75e463ca349
[2/2] KVM: arm64: Add some more comments in kvm_hyp_handle_fpsimd()
      commit: 01a244decc760b1ae2caa045647d79ff431bf37b

Cheers,

	M.
-- 
Without deviation from the norm, progress is not possible.



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2022-02-08 17:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24 15:57 [PATCH v1 0/2] KVM: arm64: Additional documentation of the FP code Mark Brown
2022-01-24 15:57 ` Mark Brown
2022-01-24 15:57 ` [PATCH v1 1/2] KVM: arm64: Add comments for context flush and sync callbacks Mark Brown
2022-01-24 15:57   ` Mark Brown
2022-01-24 15:57 ` [PATCH v1 2/2] KVM: arm64: Add some more comments in kvm_hyp_handle_fpsimd() Mark Brown
2022-01-24 15:57   ` Mark Brown
2022-02-08 17:37 ` [PATCH v1 0/2] KVM: arm64: Additional documentation of the FP code Marc Zyngier
2022-02-08 17:37   ` Marc Zyngier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.