Linux KVM/arm64 development list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mostafa Saleh" <smostafa@google.com>
Cc: kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>,
	"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH] KVM: arm64: Fix hvhe and broken CNTVOFF_EL2
Date: Thu, 06 Aug 2026 15:31:34 +0000	[thread overview]
Message-ID: <20260806153135.02E851F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806150105.4010701-1-smostafa@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] Virtual timer traps are inadvertently disabled for non-protected guests under pKVM on hardware with broken CNTVOFF_EL2, breaking their configured timer offsets.

Pre-existing issues:
- [High] `__timer_enable_traps()` uses the global `is_protected_kvm_enabled()` check and an unsynced `poffset`, unconditionally disabling physical timer traps for non-protected VMs under pKVM.
--

--- Patch [1]: [PATCH] KVM: arm64: Fix hvhe and broken CNTVOFF_EL2 ---
commit d5e405a74fba9d73744f97970471012a4473ce3c
Author: Mostafa Saleh <smostafa@google.com>
Subject: KVM: arm64: Fix hvhe and broken CNTVOFF_EL2

The commit fixes a guest kernel panic when launching a protected VM with
protected hvhe mode on hardware with a broken CNTVOFF_EL2. It achieves
this by conditionally enabling virtual timer traps only when the guest
actually has a non-zero virtual timer offset.

> diff --git a/arch/arm64/kvm/hyp/nvhe/timer-sr.c b/arch/arm64/kvm/hyp/nvhe/timer-sr.c
> index ff176f4ce7deb..98b6e37ee8fa4 100644
> --- a/arch/arm64/kvm/hyp/nvhe/timer-sr.c
> +++ b/arch/arm64/kvm/hyp/nvhe/timer-sr.c
[ ... ]

[Severity: High]
This is a pre-existing issue, but does the physical timer trap logic earlier
in __timer_enable_traps() improperly grant all guests under pKVM access to
the physical timer?

Looking at the physical timer access check in this function:

	if (is_protected_kvm_enabled() ||
	    !kern_hyp_va(vcpu->kvm)->arch.timer_data.poffset)
		set |= CNTHCTL_EL1PCTEN;

The is_protected_kvm_enabled() static key reflects host pKVM support and
applies to all guests. Additionally, the fallback poffset check evaluates to
true under pKVM because the EL2-private hyp_vm->kvm is never populated with
the host's poffset during init_pkvm_hyp_vm().

Can this cause non-protected VMs on older hardware without CNTPOFF_EL2 to
bypass physical timer offset emulation and read the raw physical timer
directly?

> @@ -63,7 +64,7 @@ void __timer_enable_traps(struct kvm_vcpu *vcpu)
>  	 * Trap the virtual counter/timer if we have a broken cntvoff
>  	 * implementation.
>  	 */
> -	if (has_broken_cntvoff())
> +	if (has_broken_cntvoff() && hyp_timer_get_offset(vcpu_vtimer(vcpu)))

[Severity: High]
Could this condition inadvertently disable virtual timer traps for
non-protected guests under pKVM?

The new check evaluates hyp_timer_get_offset(vcpu_vtimer(vcpu)). However,
under pKVM (nVHE), the EL2-private pkvm_hyp_vcpu structure's timer_cpu state
is never synchronized from the host vCPU during init_pkvm_hyp_vcpu() or
flush_hyp_vcpu().

Since ctxt->offset.vm_offset remains NULL, hyp_timer_get_offset() will
unconditionally return 0. Will this allow any non-protected guest with a
configured virtual timer offset to bypass the trap and incorrectly observe an
offset of 0?

>  		set |= CNTHCTL_EL1TVT | CNTHCTL_EL1TVCT;
>  
>  	sysreg_clear_set(cnthctl_el2, clr, set);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260806150105.4010701-1-smostafa@google.com?part=1

  reply	other threads:[~2026-08-06 15:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06 15:01 [PATCH] KVM: arm64: Fix hvhe and broken CNTVOFF_EL2 Mostafa Saleh
2026-08-06 15:31 ` sashiko-bot [this message]
2026-08-06 16:20   ` Fuad Tabba
2026-08-06 16:55 ` Fuad Tabba
2026-08-07  1:37 ` Yao Yuan
2026-08-07 10:50 ` Marc Zyngier
2026-08-07 15:27   ` Mostafa Saleh

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=20260806153135.02E851F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=smostafa@google.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