All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Amit Shah <amit@kernel.org>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	x86@kernel.org,  linux-doc@vger.kernel.org, amit.shah@amd.com,
	thomas.lendacky@amd.com,  bp@alien8.de, tglx@linutronix.de,
	peterz@infradead.org, jpoimboe@kernel.org,
	 pawan.kumar.gupta@linux.intel.com, corbet@lwn.net,
	mingo@redhat.com,  dave.hansen@linux.intel.com, hpa@zytor.com,
	pbonzini@redhat.com,  daniel.sneddon@linux.intel.com,
	kai.huang@intel.com, sandipan.das@amd.com,
	 boris.ostrovsky@oracle.com, Babu.Moger@amd.com,
	david.kaplan@amd.com,  dwmw@amazon.co.uk,
	andrew.cooper3@citrix.com
Subject: Re: [PATCH v6 1/1] x86: kvm: svm: set up ERAPS support for guests
Date: Mon, 12 Jan 2026 09:51:13 -0800	[thread overview]
Message-ID: <aWU0kWomCX0lrtf5@google.com> (raw)
In-Reply-To: <aR913X8EqO6meCqa@google.com>

n Thu, Nov 20, 2025, Sean Christopherson wrote:
> --
> From: Amit Shah <amit.shah@amd.com>
> Date: Fri, 7 Nov 2025 10:32:39 +0100
> Subject: [PATCH] KVM: SVM: Virtualize and advertise support for ERAPS
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
> 
> AMD CPUs with the Enhanced Return Address Predictor Security (ERAPS)
> feature (available on Zen5+) obviate the need for FILL_RETURN_BUFFER
> sequences right after VMEXITs.  ERAPS adds guest/host tags to entries in
> the RSB (a.k.a. RAP).  This helps with speculation protection across the
> VM boundary, and it also preserves host and guest entries in the RSB that
> can improve software performance (which would otherwise be flushed due to
> the FILL_RETURN_BUFFER sequences).
> 
> Importantly, ERAPS also improves cross-domain security by clearing the RAP
> in certain situations.  Specifically, the RAP is cleared in response to
> actions that are typically tied to software context switching between
> tasks.  Per 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 and in the following cases:
> 
>   • MOV CR3 instruction
>   • INVPCID other than single address invalidation (operation type 0)
> 
> ERAPS also allows CPUs to extends the size of the RSB/RAP from the older
> standard (of 32 entries) to a new size, enumerated in CPUID leaf
> 0x80000021:EBX bits 23:16 (64 entries in Zen5 CPUs).
> 
> In hardware, ERAPS is always-on, when running in host context, the CPU
> uses the full RSB/RAP size without any software changes necessary.
> However, when running in guest context, the CPU utilizes the full size of
> the RSB/RAP if and only if the new ALLOW_LARGER_RAP flag is set in the
> VMCB; if the flag is not set, the CPU limits itself to the historical size
> of 32 entires.
> 
> Requiring software to opt-in for guest usage of RAPs larger than 32 entries
> allows hypervisors, i.e. KVM, to emulate the aforementioned conditions in
> which the RAP is cleared as well as the guest/host split.  E.g. if the CPU
> unconditionally used the full RAP for guests, failure to clear the RAP on
> transitions between L1 or L2, or on emulated guest TLB flushes, would
> expose the guest to RAP-based attacks as a guest without support for ERAPS
> wouldn't know that its FILL_RETURN_BUFFER sequence is insufficient.
> 
> Address the ~two broad categories of ERAPS emulation, and advertise
> ERAPS support to userspace, along with the RAP size enumerated in CPUID.
> 
> 1. Architectural RAP clearing: as above, CPUs with ERAPS clear RAP entries
>    on several conditions, including CR3 updates.  To handle scenarios
>    where a relevant operation is handled in common code (emulation of
>    INVPCID and to a lesser extent MOV CR3), piggyback VCPU_EXREG_CR3 and
>    create an alias, VCPU_EXREG_ERAPS.  SVM doesn't utilize CR3 dirty
>    tracking, and so for all intents and purposes VCPU_EXREG_CR3 is unused.
>    Aliasing VCPU_EXREG_ERAPS ensures that any flow that writes CR3 will
>    also clear the guest's RAP, and allows common x86 to mark ERAPS vCPUs
>    as needing a RAP clear without having to add a new request (or other
>    mechanism).
> 
> 2. Nested guests: the ERAPS feature adds host/guest tagging to entries
>    in the RSB, but does not distinguish between the guest ASIDs.  To
>    prevent the case of an L2 guest poisoning the RSB to attack the L1
>    guest, the CPU exposes a new VMCB bit (CLEAR_RAP).  The next
>    VMRUN with a VMCB that has this bit set causes the CPU to flush the
>    RSB before entering the guest context.  Set the bit in VMCB01 after a
>    nested #VMEXIT to ensure the next time the L1 guest runs, its RSB
>    contents aren't polluted by the L2's contents.  Similarly, before
>    entry into a nested guest, set the bit for VMCB02, so that the L1
>    guest's RSB contents are not leaked/used in the L2 context.
> 
> Enable ALLOW_LARGER_RAP (and emulate RAP clears) if and only if ERAPS is
> exposed to the guest.  Enabling ALLOW_LARGER_RAP unconditionally wouldn't
> cause any functional issues, but ignoring userspace's (and L1's) desires
> would put KVM into a grey area, which is especially undesirable due to the
> potential security implications.  E.g. if a use case wants to have L1 do
> manual RAP clearing even when ERAPS is present in hardware, enabling
> ALLOW_LARGER_RAP could result in L1 leaving stale entries in the RAP.
> 
> ERAPS is documented in AMD APM Vol 2 (Pub 24593), in revisions 3.43 and
> later.
> 
> Signed-off-by: Amit Shah <amit.shah@amd.com>
> Co-developed-by: Sean Christopherson <seanjc@google.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---

Applied to kvm-x86 svm.

[1/1] KVM: SVM: Virtualize and advertise support for ERAPS
      https://github.com/kvm-x86/linux/commit/db5e82496492

--
https://github.com/kvm-x86/linux/tree/next

      parent reply	other threads:[~2026-01-12 17:51 UTC|newest]

Thread overview: 12+ 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
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
2026-01-12 17:51     ` Sean Christopherson [this message]

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=aWU0kWomCX0lrtf5@google.com \
    --to=seanjc@google.com \
    --cc=Babu.Moger@amd.com \
    --cc=amit.shah@amd.com \
    --cc=amit@kernel.org \
    --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=david.kaplan@amd.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=sandipan.das@amd.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --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 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.