All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fuad Tabba" <tabba@google.com>
Cc: "Marc Zyngier" <maz@kernel.org>,
	kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>
Subject: Re: [PATCH] KVM: arm64: nv: Fix PSTATE construction on illegal exception return
Date: Wed, 17 Jun 2026 15:04:38 +0000	[thread overview]
Message-ID: <20260617150438.66E3A1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260617144907.2972095-1-tabba@google.com>

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

Pre-existing issues:
- [High] Incomplete PSTATE allowlist on illegal exception return causes guest state corruption
--

commit 93d5c5c2769fe9f58076ca66eb01cbe04fd87921
Author: Fuad Tabba <tabba@google.com>

KVM: arm64: nv: Fix PSTATE construction on illegal exception return

This commit updates PSTATE construction during an illegal exception return
to correctly source flags and masks from the SPSR being returned to, as
per ARM rule R_VWJHB. It constructs the PSTATE by taking these fields from
the SPSR while preserving EL, SP, nRW, and EXLOCK from the current PSTATE.

Link: https://lore.kernel.org/all/86wlvxs5r0.wl-maz@kernel.org/

> diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nested.c
> index dba7ced74ca5e..ace2b40cf8756 100644
> --- a/arch/arm64/kvm/emulate-nested.c
> +++ b/arch/arm64/kvm/emulate-nested.c
> @@ -2738,17 +2738,30 @@ static u64 kvm_check_illegal_exception_return(struct kvm_vcpu *vcpu, u64 spsr)

[ ... ]

> +		mask = PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT |
> +		       PSR_N_BIT | PSR_Z_BIT | PSR_C_BIT | PSR_V_BIT;
> +
> +		if (kvm_has_feat(vcpu->kvm, ID_AA64MMFR1_EL1, PAN, IMP))
> +			mask |= PSR_PAN_BIT;
> +		if (kvm_has_feat(vcpu->kvm, ID_AA64PFR1_EL1, NMI, IMP))
> +			mask |= ALLINT_ALLINT;
> +		/* FEAT_SPE_EXC and FEAT_TRBE_EXC also gate PSTATE.PM one day... */
> +		if (kvm_has_feat(vcpu->kvm, ID_AA64DFR1_EL1, EBEP, IMP))
> +			mask |= BIT_ULL(32);	/* PSTATE.PM */
> +
> +		spsr &= mask;

[Severity: High]
This is a pre-existing issue, but this explicit allowlist approach seems to
omit several architecturally defined and KVM-supported PSTATE fields.

For example, PSR_SSBS_BIT, PSR_DIT_BIT, PSR_UAO_BIT, PSR_TCO_BIT, and
PSR_BTYPE_MASK are not included in the mask. Because spsr is masked with
this incomplete allowlist, won't these valid bits be silently zeroed out
instead of being preserved?

When the guest takes the resulting Illegal State Exception, its SPSR_ELx
will have lost these bits, which could corrupt the guest's architectural
state and break guest exception handlers that rely on them.

Would a denylist approach (masking out only the mode bits and EXLOCK from
SPSR and taking them from CPSR) be safer to ensure all relevant bits are
retained?

> +		spsr |= cpsr & (PSR_MODE_MASK | PSR_MODE32_BIT);
> +		if (kvm_has_feat(vcpu->kvm, ID_AA64PFR1_EL1, GCS, IMP))
> +			spsr |= cpsr & BIT_ULL(34);	/* PSTATE.EXLOCK */
>  		spsr |= PSR_IL_BIT;
>  	}

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

  reply	other threads:[~2026-06-17 15:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-17 14:49 [PATCH] KVM: arm64: nv: Fix PSTATE construction on illegal exception return Fuad Tabba
2026-06-17 15:04 ` sashiko-bot [this message]
2026-06-17 15:29   ` Fuad Tabba
2026-06-17 16:23     ` Marc Zyngier
2026-06-17 16:45 ` Marc Zyngier
2026-06-17 17:19   ` Fuad Tabba
2026-06-17 17:32     ` Marc Zyngier
2026-06-17 17:36 ` Marc Zyngier

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=20260617150438.66E3A1F000E9@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=tabba@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 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.