Linux KVM/arm64 development list
 help / color / mirror / Atom feed
From: Oliver Upton <oupton@kernel.org>
To: Marc Zyngier <maz@kernel.org>
Cc: sashiko-reviews@lists.linux.dev, kvmarm@lists.linux.dev
Subject: Re: [PATCH] KVM: arm64: nv: Check RW permissions for insn abort due to S1PTW
Date: Wed, 24 Jun 2026 02:39:43 -0700	[thread overview]
Message-ID: <ajul3_7XpTeDn57I@kernel.org> (raw)
In-Reply-To: <86mrwkqqix.wl-maz@kernel.org>

On Wed, Jun 24, 2026 at 09:41:26AM +0100, Marc Zyngier wrote:
> > diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
> > index 5bf3d7e1d92c..d5c61e0027c8 100644
> > --- a/arch/arm64/include/asm/kvm_emulate.h
> > +++ b/arch/arm64/include/asm/kvm_emulate.h
> > @@ -479,21 +479,12 @@ static __always_inline int kvm_vcpu_sys_get_rt(struct kvm_vcpu *vcpu)
> >  
> >  static inline bool kvm_is_write_fault(struct kvm_vcpu *vcpu)
> >  {
> > -	if (kvm_vcpu_abt_iss1tw(vcpu)) {
> > -		/*
> > -		 * Only a permission fault on a S1PTW should be
> > -		 * considered as a write. Otherwise, page tables baked
> > -		 * in a read-only memslot will result in an exception
> > -		 * being delivered in the guest.
> > -		 *
> > -		 * The drawback is that we end-up faulting twice if the
> > -		 * guest is using any of HW AF/DB: a translation fault
> > -		 * to map the page containing the PT (read only at
> > -		 * first), then a permission fault to allow the flags
> > -		 * to be set.
> > -		 */
> > -		return kvm_vcpu_trap_is_permission_fault(vcpu);
> > -	}
> > +	/*
> > +	 * The architecture sucks; assume that the S1PTW fetched for write if
> > +	 * HA is enabled at stage-1.
> > +	 */
> > +	if (kvm_vcpu_abt_iss1tw(vcpu))
> > +		return effective_tcr_ha(vcpu);
> 
> OK, so you're trading the implicit state machine (translation fault ->
> RO, permission fault -> RW) for a direct TCR.HA lookup, because the
> only reason you'd get a S1PTW fault for write is if you were updating
> the descriptor. This is cute, and I wish I had thought of that, as it
> saves us a round trip.
> 
> But why can't that happen with HD? Surely this results in a similar
> fault, and I think we should also evaluate that bit.

The effective value of both HAFT and HD is 0 if TCR_ELx.HA is 0. So
evaluating HA covers them all :)

Thanks,
Oliver

  reply	other threads:[~2026-06-24  9:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-23 21:13 [PATCH] KVM: arm64: nv: Check RW permissions for insn abort due to S1PTW Oliver Upton
2026-06-23 21:32 ` sashiko-bot
2026-06-24  0:07   ` Oliver Upton
2026-06-24  8:41     ` Marc Zyngier
2026-06-24  9:39       ` Oliver Upton [this message]
2026-06-24  9:57         ` 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=ajul3_7XpTeDn57I@kernel.org \
    --to=oupton@kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox