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>,
	Sebastian Ott <sebott@redhat.com>
Subject: Re: [PATCH 1/3] KVM: arm64: Copy guest CTR_EL0 into hyp VM
Date: Thu, 06 Mar 2025 00:25:30 +0000	[thread overview]
Message-ID: <86cyevovid.wl-maz@kernel.org> (raw)
In-Reply-To: <20250305230825.484091-2-oliver.upton@linux.dev>

On Wed, 05 Mar 2025 23:08:23 +0000,
Oliver Upton <oliver.upton@linux.dev> wrote:
> 
> Since commit 2843cae26644 ("KVM: arm64: Treat CTR_EL0 as a VM feature
> ID register") KVM has allowed userspace to configure the VM-wide view of
> CTR_EL0, falling back to trap-n-emulate if the value doesn't match
> hardware. It appears that this has worked by chance in protected-mode
> for some time, and on systems with FEAT_EVT protected-mode
> unconditionally sets TID4 (i.e. TID2 traps sans CTR_EL0).
> 
> Forward the guest CTR_EL0 value through to the hyp VM and align the
> TID2/TID4 configuration with the non-protected setup.
> 
> Fixes: 2843cae26644 ("KVM: arm64: Treat CTR_EL0 as a VM feature ID register")
> Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
> ---
>  arch/arm64/kvm/hyp/nvhe/pkvm.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> index 3927fe52a3dd..2e2975248cd3 100644
> --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c
> +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> @@ -46,7 +46,8 @@ static void pkvm_vcpu_reset_hcr(struct kvm_vcpu *vcpu)
>  		vcpu->arch.hcr_el2 |= HCR_FWB;
>  
>  	if (cpus_have_final_cap(ARM64_HAS_EVT) &&
> -	    !cpus_have_final_cap(ARM64_MISMATCHED_CACHE_TYPE))
> +	    !cpus_have_final_cap(ARM64_MISMATCHED_CACHE_TYPE) &&
> +	    kvm_read_vm_id_reg(vcpu->kvm, SYS_CTR_EL0) == read_cpuid(CTR_EL0))
>  		vcpu->arch.hcr_el2 |= HCR_TID4;
>  	else
>  		vcpu->arch.hcr_el2 |= HCR_TID2;
> @@ -374,6 +375,7 @@ static void init_pkvm_hyp_vm(struct kvm *host_kvm, struct pkvm_hyp_vm *hyp_vm,
>  	hyp_vm->kvm.arch.pkvm.enabled = READ_ONCE(host_kvm->arch.pkvm.enabled);
>  	hyp_vm->kvm.arch.flags = 0;
>  	pkvm_init_features_from_host(hyp_vm, host_kvm);
> +	hyp_vm->kvm.arch.ctr_el0 = host_kvm->arch.ctr_el0;

Maybe it'd be better to stick this into pkvm_init_features_from_host()
in order to keep all the "inherit stuff from host" together?

Same thing for the following patch.

Thanks,

	M.

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

  reply	other threads:[~2025-03-06  0:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-05 23:08 [PATCH 0/3] KVM: arm64: Fixes for 'writable' ID registers in protected mode Oliver Upton
2025-03-05 23:08 ` [PATCH 1/3] KVM: arm64: Copy guest CTR_EL0 into hyp VM Oliver Upton
2025-03-06  0:25   ` Marc Zyngier [this message]
2025-03-05 23:08 ` [PATCH 2/3] KVM: arm64: Copy MIDR_EL1 into hyp VM when it is writable Oliver Upton
2025-03-06 10:52   ` Sebastian Ott
2025-03-05 23:08 ` [PATCH 3/3] KVM: arm64: Fix documentation for KVM_CAP_ARM_WRITABLE_IMP_ID_REGS Oliver Upton
2025-03-06  0:26 ` [PATCH 0/3] KVM: arm64: Fixes for 'writable' ID registers in protected mode Marc Zyngier
2025-03-06  1:01 ` 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=86cyevovid.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=oliver.upton@linux.dev \
    --cc=sebott@redhat.com \
    --cc=suzuki.poulose@arm.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