All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mark Brown" <broonie@kernel.org>
Cc: kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>,
	"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH v22 10/16] KVM: arm64: Allow GCS to be enabled for guests
Date: Mon, 30 Nov 2026 17:16:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-241680@kernel.org> (raw)
In-Reply-To: <20261130-arm64-gcs-v22-10-80454edf47ea@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] KVM: arm64: mismatched GCSPR_EL2 gating in
  __sysreg_save_vel2_state()
--

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

KVM: arm64: Allow GCS to be enabled for guests

This commit exposes ID_AA64PFR1_EL1.GCS to guests, including nested
virtualization guests, and registers its dependency on FEAT_S1PIE.

> diff --git a/arch/arm64/kvm/config.c b/arch/arm64/kvm/config.c
> index 6f668148ccc11..4e9c4cbba9af2 100644
> --- a/arch/arm64/kvm/config.c
> +++ b/arch/arm64/kvm/config.c
> @@ -330,6 +330,12 @@ static bool feat_s1poe(struct kvm *kvm)
>  		kvm_has_feat(kvm, FEAT_HPDS));
>  }
>  
> +static bool feat_gcs(struct kvm *kvm)
> +{
> +	return (kvm_has_feat(kvm, FEAT_GCS) &&
> +		kvm_has_feat(kvm, FEAT_S1PIE));
> +}

[Severity: High]
Can a userspace VMM leak another guest VM's physical SYS_GCSPR_EL1 value into
vcpu->arch.ctxt.sys_regs[GCSPR_EL2] before ID register dependencies are
finalized on first KVM_RUN?

feat_gcs() is only enforced by kvm_idregs_enforce_dependencies() during
kvm_vm_finalize_sys_regs() on the first KVM_RUN, while ctxt_has_gcs() checks
only ID_AA64PFR1_EL1.GCS.  In arch/arm64/kvm/hyp/vhe/sysreg-sr.c, the
save and restore paths for GCSPR_EL2 use different conditions:

arch/arm64/kvm/hyp/vhe/sysreg-sr.c:__sysreg_save_vel2_state() {
	...
	if (ctxt_has_gcs(&vcpu->arch.ctxt))
		__vcpu_assign_sys_reg(vcpu, GCSPR_EL2, read_sysreg_el1(SYS_GCSPR));
}

arch/arm64/kvm/hyp/vhe/sysreg-sr.c:__sysreg_restore_vel2_state() {
	...
	if (ctxt_has_tcrx(&vcpu->arch.ctxt)) {
		write_sysreg_el1(__vcpu_sys_reg(vcpu, TCR2_EL2), SYS_TCR2);

		if (ctxt_has_s1pie(&vcpu->arch.ctxt)) {
			write_sysreg_el1(__vcpu_sys_reg(vcpu, PIR_EL2), SYS_PIR);
			write_sysreg_el1(__vcpu_sys_reg(vcpu, PIRE0_EL2), SYS_PIRE0);

			if (ctxt_has_gcs(&vcpu->arch.ctxt))
				write_sysreg_el1(__vcpu_sys_reg(vcpu, GCSPR_EL2), SYS_GCSPR);
		}
}

If userspace initializes a vCPU with KVM_ARM_VCPU_HAS_EL2, clears
ID_AA64MMFR3_EL1.S1PIE or ID_AA64MMFR3_EL1.TCRX via KVM_SET_ONE_REG while
leaving ID_AA64PFR1_EL1.GCS enabled, and calls KVM_SET_VCPU_EVENTS before
KVM_RUN, vcpu_load() skips writing SYS_GCSPR in __sysreg_restore_vel2_state()
and leaves the previous guest's value in the hardware register.  The paired
vcpu_put() then executes __sysreg_save_vel2_state(), which saves that stale
hardware SYS_GCSPR value into GCSPR_EL2 where userspace can read it via
KVM_GET_ONE_REG.

Should __sysreg_save_vel2_state() also gate saving GCSPR_EL2 on
ctxt_has_tcrx() and ctxt_has_s1pie() (or kvm_has_gcs() check kvm_has_s1pie())
to match __sysreg_restore_vel2_state()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-arm64-gcs-v22-0-80454edf47ea@kernel.org?part=10

  reply	other threads:[~2026-11-30 17:17 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 16:35 [PATCH v22 00/16] KVM: arm64: Provide guest support for GCS Mark Brown
2026-11-30 16:35 ` [PATCH v22 01/16] arm64/gcs: Ensure FGTs for EL1 GCS instructions are disabled Mark Brown
2026-11-30 16:35 ` [PATCH v22 02/16] KVM: arm64: Drop the SPSR_EL1 and ELR_EL1 trap accessors Mark Brown
2026-11-30 16:35 ` [PATCH v22 03/16] KVM: arm64: Manage GCS access and registers for guests Mark Brown
2026-11-30 16:49   ` Leonardo Bras
2026-11-30 16:59     ` Mark Brown
2026-11-30 16:35 ` [PATCH v22 04/16] KVM: arm64: Ensure GCS memory effects are visible Mark Brown
2026-11-30 17:03   ` sashiko-bot
2026-11-30 16:35 ` [PATCH v22 05/16] KVM: arm64: Set PSTATE.EXLOCK when entering an exception Mark Brown
2026-11-30 16:35 ` [PATCH v22 06/16] KVM: arm64: Validate GCS exception lock when emulating ERET Mark Brown
2026-11-30 16:35 ` [PATCH v22 07/16] KVM: arm64: Forward GCS exceptions to nested guests Mark Brown
2026-11-30 17:05   ` sashiko-bot
2026-11-30 16:35 ` [PATCH v22 08/16] KVM: arm64: Preserve ISS2.GCS when injecting a Data Abort Mark Brown
2026-11-30 16:35 ` [PATCH v22 09/16] KVM: arm64: Fully implement GCS in the stage-1 walker Mark Brown
2026-11-30 16:35 ` [PATCH v22 10/16] KVM: arm64: Allow GCS to be enabled for guests Mark Brown
2026-11-30 17:16   ` sashiko-bot [this message]
2026-11-30 16:35 ` [PATCH v22 11/16] KVM: selftests: arm64: Check invalid feature combination handling Mark Brown
2026-11-30 16:35 ` [PATCH v22 12/16] KVM: selftests: arm64: Add GCS registers to get-reg-list Mark Brown
2026-11-30 16:35 ` [PATCH v22 13/16] KVM: selftests: arm64: Add GCS to set_id_regs Mark Brown
2026-11-30 16:35 ` [PATCH v22 14/16] KVM: selftests: arm64: Only restore SPSR_EL1 and ELR_EL1 if they change Mark Brown
2026-11-30 16:35 ` [PATCH v22 15/16] tools: Synchronise the kernel esr.h Mark Brown
2026-11-30 16:35 ` [PATCH v22 16/16] KVM: selftests: arm64: Add GCS EXLOCK exception emulation test Mark Brown

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=sashiko-outbox-241680@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.