All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mark Brown" <broonie@kernel.org>
Cc: "Marc Zyngier" <maz@kernel.org>,
	kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>
Subject: Re: [PATCH v20 08/14] KVM: arm64: Enforce EXLOCK for SPSR and ELR
Date: Tue, 01 Sep 2026 22:15:20 +0000	[thread overview]
Message-ID: <20260901221520.B0CB01F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260901-arm64-gcs-v20-8-f31750bdfadb@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] KVM incorrectly injects spurious EXLOCK exceptions for ELR_EL1 and SPSR_EL1 writes when executed from guest EL2.
--

commit 9a420a46393dc947b55c66f63966668a4f79d12b
Author: Mark Brown <broonie@kernel.org>

KVM: arm64: Enforce EXLOCK for SPSR and ELR

This commit adds enforcement of the EXLOCK rules for attempts to write to
SPSR_ELx and ELR_ELx from a guest. It injects an EXLOCK exception if both
GCSCR_ELx.EXLOCKEN and PSTATE.EXLOCK are set.

[ ... ]

> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> index c5ce18b3f7d8d..1f80c26a98393 100644
> --- a/arch/arm64/kvm/sys_regs.c
> +++ b/arch/arm64/kvm/sys_regs.c
> @@ -2866,14 +2866,42 @@ static bool access_sp_el1(struct kvm_vcpu *vcpu,
>  	return true;
>  }
>  
> +static inline bool sysregs_exlocked(struct kvm_vcpu *vcpu)
> +{
> +	u64 gcscr;
> +
> +	if (!kvm_has_gcs(vcpu->kvm))
> +		return false;
> +
> +	if (!(vcpu->arch.ctxt.regs.pstate & PSR_EXLOCK_BIT))
> +		return false;
> +
> +	/*
> +	 * Note that the EXLOCKEN for the running EL is checked
> +	 * regardless of the register written to.
> +	 */
> +	if (is_hyp_ctxt(vcpu))
> +		gcscr = vcpu_read_sys_reg(vcpu, GCSCR_EL2);
> +	else
> +		gcscr = vcpu_read_sys_reg(vcpu, GCSCR_EL1);

[Severity: High]
Does this logic correctly follow the architectural requirements for EXLOCK
exceptions?

According to the ARM Architecture Reference Manual, the pseudocode for
AArch64.CheckEXLOCK(target_el) restricts EXLOCK exception generation to cases
where PSTATE.EL == target_el.

When a guest running at vEL2 accesses ELR_EL1 or SPSR_EL1, the target_el is 1,
but the PSTATE.EL is 2. Since 2 != 1, the hardware would not generate an
exception here. However, by checking the running EL's EXLOCKEN (GCSCR_EL2)
and ignoring the target EL of the register written to, KVM will inject a
spurious EXLOCK exception into the nested EL2 guest.

Can we update this to skip the check when target_el != PSTATE.EL to prevent
spurious exceptions during guest context switching?

> +
> +	return gcscr & GCSCR_ELx_EXLOCKEN;
> +}
> +
>  static bool access_elr(struct kvm_vcpu *vcpu,
>  		       struct sys_reg_params *p,
>  		       const struct sys_reg_desc *r)
>  {
> -	if (p->is_write)
> +	if (p->is_write) {
> +		if (sysregs_exlocked(vcpu)) {
> +			kvm_inject_exlock(vcpu);
> +			return false;
> +		}
> +

[Severity: High]
Can this cause spurious exceptions for vEL2 guests?

When a guest hypervisor writes to ELR_EL1 (which is architecturally valid and
necessary for nested virtualization), this check applies the flawed EXLOCK
logic from sysregs_exlocked() and triggers an incorrect exception injection.

>  		vcpu_write_sys_reg(vcpu, p->regval, ELR_EL1);
> -	else
> +	} else {
>  		p->regval = vcpu_read_sys_reg(vcpu, ELR_EL1);
> +	}
>  
>  	return true;
>  }
> @@ -2882,10 +2910,16 @@ static bool access_spsr(struct kvm_vcpu *vcpu,
>  			struct sys_reg_params *p,
>  			const struct sys_reg_desc *r)
>  {
> -	if (p->is_write)
> +	if (p->is_write) {
> +		if (sysregs_exlocked(vcpu)) {
> +			kvm_inject_exlock(vcpu);
> +			return false;
> +		}
> +

[Severity: High]
Similarly, can this lead to an incorrect exception injection when a guest
hypervisor accesses SPSR_EL1 from vEL2?

>  		__vcpu_assign_sys_reg(vcpu, SPSR_EL1, p->regval);
> -	else
> +	} else {
>  		p->regval = __vcpu_sys_reg(vcpu, SPSR_EL1);
> +	}
>  
>  	return true;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260901-arm64-gcs-v20-0-f31750bdfadb@kernel.org?part=8

  reply	other threads:[~2026-09-01 22:15 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01 21:46 [PATCH v20 00/14] KVM: arm64: Provide guest support for GCS Mark Brown
2026-09-01 21:46 ` [PATCH v20 01/14] arm64/gcs: Ensure FGTs for EL1 GCS instructions are disabled Mark Brown
2026-09-03 16:10   ` Lorenzo Stoakes (ARM)
2026-09-01 21:47 ` [PATCH v20 02/14] KVM: arm64: Fix FGT mapping for HFGITR_EL2.nGCSEPP Mark Brown
2026-09-03 16:23   ` Lorenzo Stoakes (ARM)
2026-09-03 19:29     ` Mark Brown
2026-09-01 21:47 ` [PATCH v20 03/14] KVM: arm64: Manage GCS access and registers for guests Mark Brown
2026-09-01 22:00   ` sashiko-bot
2026-09-02 16:44   ` Leonardo Bras
2026-09-03 20:52     ` Mark Brown
2026-09-03 18:13   ` Lorenzo Stoakes (ARM)
2026-09-03 20:41     ` Mark Brown
2026-09-04  8:54       ` Lorenzo Stoakes (ARM)
2026-09-04 21:07         ` Mark Brown
2026-09-07 14:14           ` Lorenzo Stoakes (ARM)
2026-09-07 14:55             ` Mark Brown
2026-09-09 11:34               ` Lorenzo Stoakes (ARM)
2026-09-01 21:47 ` [PATCH v20 04/14] KVM: arm64: Ensure GCS memory effects are visible Mark Brown
2026-09-01 22:06   ` sashiko-bot
2026-09-02 16:30   ` Leonardo Bras
2026-09-04 12:16   ` Lorenzo Stoakes (ARM)
2026-09-01 21:47 ` [PATCH v20 05/14] KVM: arm64: Set PSTATE.EXLOCK when entering an exception Mark Brown
2026-09-01 22:06   ` sashiko-bot
2026-09-03 14:25   ` Leonardo Bras
2026-09-03 16:20     ` Mark Brown
2026-09-03 16:40       ` Leonardo Bras
2026-09-04 13:04   ` Lorenzo Stoakes (ARM)
2026-09-01 21:47 ` [PATCH v20 06/14] KVM: arm64: Validate GCS exception lock when emulating ERET Mark Brown
2026-09-03 15:37   ` Leonardo Bras
2026-09-03 19:22     ` Mark Brown
2026-09-04 13:16       ` Leonardo Bras
2026-09-04 21:56         ` Mark Brown
2026-09-07 10:55           ` Leonardo Bras
2026-09-01 21:47 ` [PATCH v20 07/14] KVM: arm64: Forward GCS exceptions to nested guests Mark Brown
2026-09-01 22:09   ` sashiko-bot
2026-09-09 13:00   ` Leonardo Bras
2026-09-01 21:47 ` [PATCH v20 08/14] KVM: arm64: Enforce EXLOCK for SPSR and ELR Mark Brown
2026-09-01 22:15   ` sashiko-bot [this message]
2026-09-01 22:48     ` Mark Brown
2026-09-09 14:35   ` Leonardo Bras
2026-09-01 21:47 ` [PATCH v20 09/14] KVM: arm64: Allow GCS to be enabled for guests Mark Brown
2026-09-09 16:34   ` Leonardo Bras
2026-09-09 16:45     ` Mark Brown
2026-09-01 21:47 ` [PATCH v20 10/14] KVM: selftests: arm64: Add GCS registers to get-reg-list Mark Brown
2026-09-01 22:05   ` sashiko-bot
2026-09-09 16:46   ` Leonardo Bras
2026-09-01 21:47 ` [PATCH v20 11/14] KVM: selftests: arm64: Add GCS to set_id_regs Mark Brown
2026-09-09 16:55   ` Leonardo Bras
2026-09-01 21:47 ` [PATCH v20 12/14] KVM: selftests: arm64: Only restore SPSR_EL1 and ELR_EL1 if they change Mark Brown
2026-09-09 17:03   ` Leonardo Bras
2026-09-01 21:47 ` [PATCH v20 13/14] tools: Synchronise the kernel esr.h Mark Brown
2026-09-01 22:08   ` sashiko-bot
2026-09-10 11:10   ` Leonardo Bras
2026-09-01 21:47 ` [PATCH v20 14/14] KVM: selftests: arm64: Add GCS EXLOCK exception emulation test Mark Brown
2026-09-01 22:16   ` sashiko-bot
2026-09-10 17:20   ` Leonardo Bras
2026-09-10 18:26     ` Mark Brown
2026-09-11 11:02       ` Leonardo Bras

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=20260901221520.B0CB01F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=broonie@kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 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.