Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Oliver Upton <oupton@kernel.org>
To: Dan Carpenter <dan@pereq.eu>
Cc: "Marc Zyngier" <maz@kernel.org>,
	"Fuad Tabba" <fuad.tabba@linux.dev>,
	"Joey Gouly" <joey.gouly@arm.com>,
	"Steffen Eiden" <seiden@linux.ibm.com>,
	"Suzuki K Poulose" <suzuki.poulose@arm.com>,
	"Zenghui Yu" <yuzenghui@huawei.com>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Will Deacon" <will@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Christoffer Dall" <c.dall@virtualopensystems.com>,
	"Rusty Russell" <rusty@rustcorp.com.au>,
	"Marcelo Tosatti" <mtosatti@redhat.com>,
	"Sebastian Ott" <sebott@redhat.com>,
	"Eric Auger" <eric.auger@redhat.com>,
	"James Morse" <james.morse@arm.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Sean Christopherson" <seanjc@google.com>,
	"Shuah Khan" <shuah@kernel.org>,
	"Karthik Bhargavan" <karthik@pereq.eu>,
	"Clément Blaudeau" <clement@cryspen.com>,
	linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	linux-kselftest@vger.kernel.org, Sashiko <sashiko-bot@kernel.org>,
	stable@vger.kernel.org
Subject: Re: [PATCH v2 5/8] KVM: arm64: nv: Replace a pending SError when injecting a new one
Date: Wed, 25 Nov 2026 00:00:15 -0800	[thread overview]
Message-ID: <awaVj0Aa6dMSksxX@kernel.org> (raw)
In-Reply-To: <20261125-double_exception-v2-5-224689d8a764@pereq.eu>

Hi Dan,

On Wed, Nov 25, 2026 at 09:56:20AM +0300, Dan Carpenter wrote:
> The kvm_inject_serror_esr() function injects SErrors as the name
> implies.  The bug is that it doesn't handle already pending errors
> correctly in nested virtualization.
> 
> In vanilla KVM the kvm_inject_serror_esr() function always sets
> the SError to pending.  However with nested KVM, it might set it
> to pending or it might deliver the SError directly.  We can only
> have one pending error at a time.  Imagine we enter the function
> with an SError pending already.  In the current code if we decide
> to pend the new error that's fine, everything works.  However if
> we decide to deliver it directly then the pend flags should be
> cleared but they are not.  So we deliver the SError directly and
> then the SError that was pending on the next exit or entry.

I could use a bit more color on how we got here. From what I can tell
this state is only possible if userspace changed the routing / masking
of the SError outside the context of a KVM_RUN. Otherwise, if the SError
is deliverable on guest exit we perform the injection prior to exiting
to userspace.

Thanks,
Oliver

> Clear the pend flags unconditionally at the start of the function.
> 
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://lore.kernel.org/all/sashiko-outbox-229065@kernel.org/
> Fixes: ce66109cec86 ("KVM: arm64: nv: Take "masked" aborts to EL2 when HCRX_EL2.TMEA is set")
> Fixes: 77ee70a07357 ("KVM: arm64: nv: Honor SError exception routing / masking")
> Cc: stable@vger.kernel.org
> Signed-off-by: Dan Carpenter <dan@pereq.eu>
> ---
> v2: New patch
> ---
>  arch/arm64/kvm/inject_fault.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/arch/arm64/kvm/inject_fault.c b/arch/arm64/kvm/inject_fault.c
> index aa2011cc0d5a..0f6a89b65074 100644
> --- a/arch/arm64/kvm/inject_fault.c
> +++ b/arch/arm64/kvm/inject_fault.c
> @@ -361,6 +361,10 @@ int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr)
>  {
>  	lockdep_assert_held(&vcpu->mutex);
>  
> +	/* A new SError replaces any that is already pending. */
> +	vcpu_clear_flag(vcpu, NESTED_SERROR_PENDING);
> +	*vcpu_hcr(vcpu) &= ~HCR_EL2_VSE;
> +
>  	if (is_nested_ctxt(vcpu) && kvm_serror_target_is_el2(vcpu))
>  		return kvm_inject_nested_serror(vcpu, esr);
>  
> 
> -- 
> 2.53.0
> 
> 

  reply	other threads:[~2026-11-25  8:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  6:56 [PATCH v2 0/8] KVM: arm64: Fix kvm_reset_vcpu() and SError handling for nested virt Dan Carpenter
2026-11-25  6:56 ` [PATCH v2 1/8] KVM: arm64: Drop an incomplete MMIO access when resetting a vcpu Dan Carpenter
2026-11-25  6:56 ` [PATCH v2 2/8] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 " Dan Carpenter
2026-11-25  6:56 ` [PATCH v2 3/8] KVM: arm64: Discard a pending SError " Dan Carpenter
2026-11-25  6:56 ` [PATCH v2 4/8] KVM: arm64: nv: Discard nested SError in kvm_reset_vcpu() Dan Carpenter
2026-11-25  6:56 ` [PATCH v2 5/8] KVM: arm64: nv: Replace a pending SError when injecting a new one Dan Carpenter
2026-11-25  8:00   ` Oliver Upton [this message]
2026-11-25  6:56 ` [PATCH v2 6/8] KVM: arm64: nv: Don't deliver a pending SError to the wrong guest Dan Carpenter
2026-11-25  6:56 ` [PATCH v2 7/8] KVM: arm64: nv: Re-inject a stored SError after the exit is handled Dan Carpenter
2026-11-25  6:56 ` [PATCH v2 8/8] KVM: arm64: selftests: Test that a vcpu reset clears the vcpu's state Dan Carpenter

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=awaVj0Aa6dMSksxX@kernel.org \
    --to=oupton@kernel.org \
    --cc=c.dall@virtualopensystems.com \
    --cc=catalin.marinas@arm.com \
    --cc=clement@cryspen.com \
    --cc=dan@pereq.eu \
    --cc=eric.auger@redhat.com \
    --cc=fuad.tabba@linux.dev \
    --cc=james.morse@arm.com \
    --cc=joey.gouly@arm.com \
    --cc=karthik@pereq.eu \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rusty@rustcorp.com.au \
    --cc=sashiko-bot@kernel.org \
    --cc=seanjc@google.com \
    --cc=sebott@redhat.com \
    --cc=seiden@linux.ibm.com \
    --cc=shuah@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.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