Linux KVM/arm64 development list
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Oliver Upton <oliver.upton@linux.dev>
Cc: kvmarm@lists.linux.dev, Joey Gouly <joey.gouly@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Jinqian Yang <yangjinqian1@huawei.com>
Subject: Re: [PATCH] KVM: arm64: nv: Exclude guest's TWED configuration when TWE isn't set
Date: Tue, 09 Sep 2025 10:07:21 +0100	[thread overview]
Message-ID: <86ms74c7ue.wl-maz@kernel.org> (raw)
In-Reply-To: <20250909071602.294783-1-oliver.upton@linux.dev>

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.

  reply	other threads:[~2025-09-09  9:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2025-09-09 21:28   ` Oliver Upton

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=86ms74c7ue.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=oliver.upton@linux.dev \
    --cc=suzuki.poulose@arm.com \
    --cc=yangjinqian1@huawei.com \
    --cc=yuzenghui@huawei.com \
    /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