* [PATCH] KVM: arm64: nv: Exclude guest's TWED configuration when TWE isn't set
@ 2025-09-09 7:16 Oliver Upton
2025-09-09 9:07 ` Marc Zyngier
0 siblings, 1 reply; 3+ messages in thread
From: Oliver Upton @ 2025-09-09 7:16 UTC (permalink / raw)
To: kvmarm
Cc: Marc Zyngier, Joey Gouly, Suzuki K Poulose, Zenghui Yu,
Jinqian Yang, Oliver Upton
KVM blindly OR's the guest values for TWEDEL and TWEDEn into the
programmed value even if the guest has WFE traps disabled. Exclude these
fields from the final value when TWE isn't set to avoid potentially
delaying a trap desired by the host.
Note that KVM doesn't use FEAT_TWED currently so there's no need to
empty out these fields the other way around (i.e. host TWE=0, guest
TWE=1).
Fixes: 04ab519bb86d ("KVM: arm64: nv: Configure HCR_EL2 for FEAT_NV2")
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
---
arch/arm64/kvm/hyp/vhe/switch.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c
index 0998ad4a2552..e4955b49c0d2 100644
--- a/arch/arm64/kvm/hyp/vhe/switch.c
+++ b/arch/arm64/kvm/hyp/vhe/switch.c
@@ -95,6 +95,13 @@ static u64 __compute_hcr(struct kvm_vcpu *vcpu)
/* Force NV2 in case the guest is forgetful... */
guest_hcr |= HCR_NV2;
}
+
+ /*
+ * Exclude the guest's TWED configuration if it hasn't set TWE
+ * to avoid potentially delaying traps for the host.
+ */
+ if (!(guest_hcr & HCR_TWE))
+ guest_hcr &= (HCR_EL2_TWEDEn | HCR_EL2_TWEDEL);
}
BUG_ON(host_data_test_flag(VCPU_IN_HYP_CONTEXT) &&
base-commit: b320789d6883cc00ac78ce83bccbfe7ed58afcf0
--
2.39.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: arm64: nv: Exclude guest's TWED configuration when TWE isn't set
2025-09-09 7:16 [PATCH] KVM: arm64: nv: Exclude guest's TWED configuration when TWE isn't set Oliver Upton
@ 2025-09-09 9:07 ` Marc Zyngier
2025-09-09 21:28 ` Oliver Upton
0 siblings, 1 reply; 3+ messages in thread
From: Marc Zyngier @ 2025-09-09 9:07 UTC (permalink / raw)
To: Oliver Upton
Cc: kvmarm, Joey Gouly, Suzuki K Poulose, Zenghui Yu, Jinqian Yang
On Tue, 09 Sep 2025 08:16:02 +0100,
Oliver Upton <oliver.upton@linux.dev> wrote:
>
> KVM blindly OR's the guest values for TWEDEL and TWEDEn into the
> programmed value even if the guest has WFE traps disabled. Exclude these
> fields from the final value when TWE isn't set to avoid potentially
> delaying a trap desired by the host.
>
> Note that KVM doesn't use FEAT_TWED currently so there's no need to
> empty out these fields the other way around (i.e. host TWE=0, guest
> TWE=1).
>
> Fixes: 04ab519bb86d ("KVM: arm64: nv: Configure HCR_EL2 for FEAT_NV2")
> Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
> ---
> arch/arm64/kvm/hyp/vhe/switch.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c
> index 0998ad4a2552..e4955b49c0d2 100644
> --- a/arch/arm64/kvm/hyp/vhe/switch.c
> +++ b/arch/arm64/kvm/hyp/vhe/switch.c
> @@ -95,6 +95,13 @@ static u64 __compute_hcr(struct kvm_vcpu *vcpu)
> /* Force NV2 in case the guest is forgetful... */
> guest_hcr |= HCR_NV2;
> }
> +
> + /*
> + * Exclude the guest's TWED configuration if it hasn't set TWE
> + * to avoid potentially delaying traps for the host.
> + */
> + if (!(guest_hcr & HCR_TWE))
> + guest_hcr &= (HCR_EL2_TWEDEn | HCR_EL2_TWEDEL);
> }
>
> BUG_ON(host_data_test_flag(VCPU_IN_HYP_CONTEXT) &&
>
> base-commit: b320789d6883cc00ac78ce83bccbfe7ed58afcf0
I'm a bit lost here.
We seem to sanitise ID_AA64MMFR1_EL1 in a way that totally removes
TWED from the feature set (see limit_nv_id_reg()). Therefore,
HCR_EL2.(TWEDEn,TWEDEL} should be RES0, no matter what.
Is there another way the guest can set these bits?
M.
--
Without deviation from the norm, progress is not possible.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: arm64: nv: Exclude guest's TWED configuration when TWE isn't set
2025-09-09 9:07 ` Marc Zyngier
@ 2025-09-09 21:28 ` Oliver Upton
0 siblings, 0 replies; 3+ messages in thread
From: Oliver Upton @ 2025-09-09 21:28 UTC (permalink / raw)
To: Marc Zyngier
Cc: kvmarm, Joey Gouly, Suzuki K Poulose, Zenghui Yu, Jinqian Yang
On Tue, Sep 09, 2025 at 10:07:21AM +0100, Marc Zyngier wrote:
> On Tue, 09 Sep 2025 08:16:02 +0100,
> Oliver Upton <oliver.upton@linux.dev> wrote:
> >
> > KVM blindly OR's the guest values for TWEDEL and TWEDEn into the
> > programmed value even if the guest has WFE traps disabled. Exclude these
> > fields from the final value when TWE isn't set to avoid potentially
> > delaying a trap desired by the host.
> >
> > Note that KVM doesn't use FEAT_TWED currently so there's no need to
> > empty out these fields the other way around (i.e. host TWE=0, guest
> > TWE=1).
> >
> > Fixes: 04ab519bb86d ("KVM: arm64: nv: Configure HCR_EL2 for FEAT_NV2")
> > Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
> > ---
> > arch/arm64/kvm/hyp/vhe/switch.c | 7 +++++++
> > 1 file changed, 7 insertions(+)
> >
> > diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c
> > index 0998ad4a2552..e4955b49c0d2 100644
> > --- a/arch/arm64/kvm/hyp/vhe/switch.c
> > +++ b/arch/arm64/kvm/hyp/vhe/switch.c
> > @@ -95,6 +95,13 @@ static u64 __compute_hcr(struct kvm_vcpu *vcpu)
> > /* Force NV2 in case the guest is forgetful... */
> > guest_hcr |= HCR_NV2;
> > }
> > +
> > + /*
> > + * Exclude the guest's TWED configuration if it hasn't set TWE
> > + * to avoid potentially delaying traps for the host.
> > + */
> > + if (!(guest_hcr & HCR_TWE))
> > + guest_hcr &= (HCR_EL2_TWEDEn | HCR_EL2_TWEDEL);
> > }
> >
> > BUG_ON(host_data_test_flag(VCPU_IN_HYP_CONTEXT) &&
> >
> > base-commit: b320789d6883cc00ac78ce83bccbfe7ed58afcf0
>
> I'm a bit lost here.
No more than I was, apparently...
> We seem to sanitise ID_AA64MMFR1_EL1 in a way that totally removes
> TWED from the feature set (see limit_nv_id_reg()). Therefore,
> HCR_EL2.(TWEDEn,TWEDEL} should be RES0, no matter what.
>
> Is there another way the guest can set these bits?
No, I just saw Jinqian's changes making this field writable and failed
to check the limit. I'd like to reduce the amount of NV limitations we
have, I'll just send this with the relaxation as a v2.
Thanks,
Oliver
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-09 21:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-09 7:16 [PATCH] KVM: arm64: nv: Exclude guest's TWED configuration when TWE isn't set Oliver Upton
2025-09-09 9:07 ` Marc Zyngier
2025-09-09 21:28 ` Oliver Upton
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.