All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Oliver Upton <oliver.upton@linux.dev>
Cc: Marc Zyngier <maz@kernel.org>,
	linux-arm-kernel@lists.infradead.org,  kvmarm@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	 James Houghton <jthoughton@google.com>
Subject: Re: [RFC PATCH 05/16] KVM: arm64: Introduce "struct kvm_page_fault" for tracking abort state
Date: Tue, 26 Aug 2025 14:29:59 -0700	[thread overview]
Message-ID: <aK4nVyoEd3hgmxaD@google.com> (raw)
In-Reply-To: <aK4LIj-OZsP_35wc@linux.dev>

On Tue, Aug 26, 2025, Oliver Upton wrote:
> On Tue, Aug 26, 2025 at 11:58:10AM -0700, Sean Christopherson wrote:
> > On Thu, Aug 21, 2025, Oliver Upton wrote:
> > > > +struct kvm_page_fault {
> > > > +	const u64 esr;
> > > > +	const bool exec;
> > > > +	const bool write;
> > > > +	const bool is_perm;
> > > 
> > > Hmm... these might be better represented as predicates that take a
> > > pointer to this struct and we just compute it based on ESR. That'd have
> > > the benefit in the arch-neutral code where 'struct kvm_page_fault' is an
> > > opaque type and we don't need to align field names/types.
> > 
> > We'd need to align function names/types though, so to some extent it's six of one,
> > half dozen of the other.  My slight preference would be to require kvm_page_fault
> > to have certain fields, but I'm ok with making kvm_page_fault opaque to generic
> > code and instead adding arch APIs.  Having a handful of wrappers in x86 isn't the
> > end of the world, and it would be more familiar for pretty much everyone.
> 
> To clarify my earlier point, my actual interest is in using ESR as the
> source of truth from the arch POV, interface to the arch-neutral code
> isn't that big of a deal either way.

Ya, but that would mean having something like

  static bool kvm_is_exec_fault(struct kvm_page_fault *fault)
  {
	return esr_trap_is_iabt(fault->esr) && !esr_abt_iss1tw(fault->esr);
  }

and

  if (kvm_is_exec_fault(fault))

in arm64 code and then

  if (fault->exec)

in arch-neutral code, which, eww.

I like the idea of having a single source of truth, but that's going to be a
massive amount of work to do it "right", e.g. O(weeks) if not O(months).  E.g. to
replace fault->exec with kvm_is_exec_fault(), AFAICT it would require duplicating
all of kvm_is_write_fault().  Rinse and repeat for 20+ APIs in kvm_emulate.h that
take a vCPU and pull ESR from vcpu->arch.fault.esr_el2.

As an intermediate state, having that many duplicate APIs is tolerable, but I
wouldn't want to leave that as the "end" state for any kernel release, and ideally
not for any given series.  That means adding a pile of esr-based APIs, converting
_all_ users, then dropping the vcpu-based APIs.  That's a lot of code and patches.

E.g. even if we convert all of kvm_handle_guest_abort(), which itself is a big task,
there will still be usage of many of the APIs in at least kvm_translate_vncr(),
io_mem_abort(), and kvm_handle_mmio_return().  Converting all of those is totally
doable, e.g. through a combination of using kvm_page_fault and local snapshots of
esr, but it will be a lot of work and churn.

The work+churn itself doesn't bother me, but I would prefer not to block arch-neutral
usage of kvm_page_fault for months on end, nor do I want to leave KVM arm64 in
a half-baked state, i.e. I wouldn't feel comfortable converting just
__kvm_handle_guest_abort() and walking away.

What if we keep the exec, write, and is_perm fields for now, but add proper APIs
to access kvm_page_fault from common code?  The APIs would be largely duplicate
code between x86 and arm64 (though I think kvm_get_fault_gpa() would be different,
so yay), but that's not a big deal.  That way common KVM can start building out
functionality based on kvm_page_fault, and arm64 can independently convert to
making fault->esr the single source of truth, without having to worry about
perturbing common code.

  reply	other threads:[~2025-08-26 21:30 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-21 21:00 [RFC PATCH 00/16] KVM: arm64: Add "struct kvm_page_fault" Sean Christopherson
2025-08-21 21:00 ` [RFC PATCH 01/16] KVM: arm64: Drop nested "esr" to eliminate variable shadowing Sean Christopherson
2025-08-21 21:00 ` [RFC PATCH 02/16] KVM: arm64: Get iabt status on-demand Sean Christopherson
2025-08-21 21:00 ` [RFC PATCH 03/16] KVM: arm64: Move SRCU-protected region of kvm_handle_guest_abort() to helper Sean Christopherson
2025-08-21 21:00 ` [RFC PATCH 04/16] KVM: arm64: Use guard(srcu) in kvm_handle_guest_abort() Sean Christopherson
2025-08-21 21:00 ` [RFC PATCH 05/16] KVM: arm64: Introduce "struct kvm_page_fault" for tracking abort state Sean Christopherson
2025-08-21 22:31   ` Oliver Upton
2025-08-26 18:58     ` Sean Christopherson
2025-08-26 19:29       ` Oliver Upton
2025-08-26 21:29         ` Sean Christopherson [this message]
2025-08-21 21:00 ` [RFC PATCH 06/16] KVM: arm64: Pass kvm_page_fault pointer to transparent_hugepage_adjust() Sean Christopherson
2025-08-21 21:00 ` [RFC PATCH 07/16] KVM: arm64: Pass @fault to fault_supports_stage2_huge_mapping() Sean Christopherson
2025-08-21 21:00 ` [RFC PATCH 08/16] KVM: arm64: Add helper to get permission fault granule from ESR Sean Christopherson
2025-08-21 21:00 ` [RFC PATCH 09/16] KVM: arm64: Track perm fault granule in "struct kvm_page_fault" Sean Christopherson
2025-08-21 21:00 ` [RFC PATCH 10/16] KVM: arm64: Drop local vfio_allow_any_uc, use vm_flags snapshot Sean Christopherson
2025-08-21 21:00 ` [RFC PATCH 11/16] KVM: arm64: Drop local mte_allowed, " Sean Christopherson
2025-08-21 21:00 ` [RFC PATCH 12/16] KVM: arm64: Move VMA-related information into "struct kvm_page_fault" Sean Christopherson
2025-08-21 21:00 ` [RFC PATCH 13/16] KVM: arm64: Stash "mmu_seq" in " Sean Christopherson
2025-08-21 21:00 ` [RFC PATCH 14/16] KVM: arm64: Track "forced" information " Sean Christopherson
2025-08-21 21:00 ` [RFC PATCH 15/16] KVM: arm64: Extract mmap_lock-protected code to helper for user mem aborts Sean Christopherson
2025-08-21 21:00 ` [RFC PATCH 16/16] KVM: arm64: Don't bother nullifying "vma" in mem abort path Sean Christopherson
2025-08-21 22:39 ` [RFC PATCH 00/16] KVM: arm64: Add "struct kvm_page_fault" Oliver Upton

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=aK4nVyoEd3hgmxaD@google.com \
    --to=seanjc@google.com \
    --cc=jthoughton@google.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=oliver.upton@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.