linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shah, Amit" <Amit.Shah@amd.com>
To: "seanjc@google.com" <seanjc@google.com>
Cc: "corbet@lwn.net" <corbet@lwn.net>,
	"pawan.kumar.gupta@linux.intel.com"
	<pawan.kumar.gupta@linux.intel.com>,
	"kai.huang@intel.com" <kai.huang@intel.com>,
	"jpoimboe@kernel.org" <jpoimboe@kernel.org>,
	"andrew.cooper3@citrix.com" <andrew.cooper3@citrix.com>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
	"daniel.sneddon@linux.intel.com" <daniel.sneddon@linux.intel.com>,
	"Lendacky, Thomas" <Thomas.Lendacky@amd.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"dwmw@amazon.co.uk" <dwmw@amazon.co.uk>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"Moger, Babu" <Babu.Moger@amd.com>,
	"Das1, Sandipan" <Sandipan.Das@amd.com>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"bp@alien8.de" <bp@alien8.de>,
	"boris.ostrovsky@oracle.com" <boris.ostrovsky@oracle.com>,
	"Kaplan, David" <David.Kaplan@amd.com>,
	"x86@kernel.org" <x86@kernel.org>
Subject: Re: [PATCH v6 1/1] x86: kvm: svm: set up ERAPS support for guests
Date: Mon, 24 Nov 2025 16:15:47 +0000	[thread overview]
Message-ID: <db6a57eb67620d1b41d702baf16142669cc26e5c.camel@amd.com> (raw)
In-Reply-To: <aR913X8EqO6meCqa@google.com>

On Thu, 2025-11-20 at 12:11 -0800, Sean Christopherson wrote:
> 

> > 2. Hosts that disable NPT: the ERAPS feature flushes the RSB
> > entries on
> >    several conditions, including CR3 updates.  Emulating hardware
> >    behaviour on RSB flushes is not worth the effort for NPT=off
> > case,
> >    nor is it worthwhile to enumerate and emulate every trigger the
> >    hardware uses to flush RSB entries.  Instead of identifying and
> >    replicating RSB flushes that hardware would have performed had
> > NPT
> >    been ON, do not let NPT=off VMs use the ERAPS features.
> 
> The emulation requirements are not limited to shadow paging.  From
> the APM:
> 
>   The ERAPS feature eliminates the need to execute CALL instructions
> to clear
>   the return address predictor in most cases. On processors that
> support ERAPS,
>   return addresses from CALL instructions executed in host mode are
> not used in
>   guest mode, and vice versa. Additionally, the return address
> predictor is
>   cleared in all cases when the TLB is implicitly invalidated (see
> Section 5.5.3 “TLB
>   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   Management,” on page 159) and in the following cases:
> 
>   • MOV CR3 instruction
>   • INVPCID other than single address invalidation (operation type 0)
> 
> Yes, KVM only intercepts MOV CR3 and INVPCID when NPT is disabled (or
> INVPCID is
> unsupported per guest CPUID), but that is an implementation detail,
> the instructions
> are still reachable via emulator, and KVM needs to emulate implicit
> TLB flush
> behavior.
> 
> So punting on emulating RAP clearing because it's too hard is not an
> option.  And
> AFAICT, it's not even that hard.

I didn't mean on punting it in the "it's too hard" sense, but in the
sense that we don't know all the details of when hardware decides to do
a flush; and even if triggers are mentioned in this APM today, future
changes to microcode or APM docs might reveal more triggers that we
need to emulate and account for.  There's no way to track such changes,
so my thinking is that we should be conservative and not assume
anything.

> The changelog also needs to include the architectural behavior,
> otherwise "is not
> worth the effort" is even more subjective since there's no
> documentation of what
> the effort would actually be.

> As for emulating the RAP clears, a clever idea is to piggyback and
> alias dirty
> tracking for VCPU_EXREG_CR3, as VCPU_EXREG_ERAPS.  I.e. mark the vCPU
> as needing
> a RAP clear if CR3 is written to, and then let common x86 also set
> VCPU_EXREG_ERAPS
> as needed, e.g. when handling INVPCID.

> Compile tested only at this point, but this?

I'll run this on my hardware and check for anything obvious.

Since you're also saying the npt=on and npt=off cases aren't very
different, I'll check with the hardware architects to confirm we can
indeed go with the RAP clearing triggers as presented.

		Amit

  parent reply	other threads:[~2025-11-24 16:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-07  9:32 [PATCH v6 0/1] KVM: Add support for the ERAPS feature Amit Shah
2025-11-07  9:32 ` [PATCH v6 1/1] x86: kvm: svm: set up ERAPS support for guests Amit Shah
2025-11-20 20:11   ` Sean Christopherson
2025-11-21  2:40     ` Andrew Cooper
2025-11-21 14:58       ` Sean Christopherson
2025-11-21 15:21         ` Andrew Cooper
2025-11-24 16:15     ` Shah, Amit [this message]
2025-11-24 16:40       ` Andrew Cooper
2025-11-25 14:41         ` Shah, Amit
2025-11-25 14:54           ` Sean Christopherson
2025-12-11 16:09         ` Shah, Amit

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=db6a57eb67620d1b41d702baf16142669cc26e5c.camel@amd.com \
    --to=amit.shah@amd.com \
    --cc=Babu.Moger@amd.com \
    --cc=David.Kaplan@amd.com \
    --cc=Sandipan.Das@amd.com \
    --cc=Thomas.Lendacky@amd.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=bp@alien8.de \
    --cc=corbet@lwn.net \
    --cc=daniel.sneddon@linux.intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dwmw@amazon.co.uk \
    --cc=hpa@zytor.com \
    --cc=jpoimboe@kernel.org \
    --cc=kai.huang@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pawan.kumar.gupta@linux.intel.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).