mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Yosry Ahmed <yosry@kernel.org>
Cc: Jim Mattson <jmattson@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	 Maxim Levitsky <mlevitsk@redhat.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	 Tom Lendacky <thomas.lendacky@amd.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 00/27] KVM: nSVM: Optimize nSVM TLB flushes
Date: Wed, 4 Nov 2026 14:15:55 -0800	[thread overview]
Message-ID: <auuum7Dq0w-swARW@google.com> (raw)
In-Reply-To: <CAO9r8zOa315UTmR4fbGzyHMtKDfUjW=6ehTrdA9js+JOAb3d7w@mail.gmail.com>

On Wed, Oct 14, 2026, Yosry Ahmed wrote:
> On Wed, Oct 14, 2026 at 6:23 AM Jim Mattson <jmattson@google.com> wrote:
> >
> > On Mon, Oct 12, 2026 at 4:36 PM Yosry Ahmed <yosry@kernel.org> wrote:
> > >
> > > This series optimizes TLB flushes for nested SVM by using and maintaining
> > > a separate ASID for L2 for each vCPU (similar to VMX's handling of VPIDs),
> > > rather than sharing the same ASID and flushing everything on every nested
> > > transition.
> > >
> > > The series also drops the dynamic ASID allocation scheme and uses a
> > > static ASID per vCPU (or two if using nested), bringing it closer to how
> > > VMX handles VPIDs. Modern CPUs (Rome, Milan, Genoa, Turin) advertise 32K
> > > ASIDs, so there is no need for dynamic allocation.
> >
> > I'm not convinced that this is the right direction. It's almost always
> > better to do things locally when possible. Why not keep the per-CPU
> > generational allocation, but allocate two ASIDs per vCPU—one for each
> > VMCB?
> 
> This is what a much older version of this series did:
> https://lore.kernel.org/lkml/20250205182402.2147495-1-yosry.ahmed@linux.dev/
> 
> Then we moved on to per-VM fixed ASIDs to align with SEV, but the
> tracking of "which vCPU used this ASID last" was annoying, so we
> settled on per-vCPU fixed ASIDs, similar to VPIDs, with the caveat of
> not being able to disable ASID (Hence the fallback ASID thing).
> 
> Other than alignment, dynamic allocation of ASIDs means that we need
> to handle the possibility of ASID reuse, which imo introduces more
> complexity than the fallback ASID logic, patch 10 lists three very
> recent fixups that we need to handle corner cases with dynamic ASID
> allocations:
> https://lore.kernel.org/kvm/20261012233638.2546339-11-yosry@kernel.org/
> 
> There is a 4th one that was sent after patch 10.
> 
> Also, the dynamic ASID allocations give the VMs more noisy neighbor
> power, I think the ASID is reallocated on INIT, so a VM can trigger
> running out of ASIDs on a pCPU and flushing the ASIDs of all other
> VMs. Yes, we can handle this in INIT, but the problem is completely
> side-stepped by using static ASIDs.
> 
> > This would eliminate the need for a fallback ASID and remove any
> > possible concerns about contention for a global bitmap.
> 
> The fallback ASID logic is annoying, yes, but it's only in a few
> places. I don't think there's a risk of real contention in most
> practical use cases, we can run 32k vCPUs per pCPU before we run into
> issues. I think we will hit other scalability limits before the
> fallback ASID becomes a problem.
> 
> > Moreover, it would be much simpler to implement.
> 
> The delta is smaller and simpler, yes. But I think the static ASIDs
> code ends up being simpler to reason about.

+1.  The per-pCPU tracking might require less code, but OMG is it hard to reason
about.  I also hate having completely different schemes for VMX vs. SVM, it makes
it extra difficult to reason about TLB stuff when looking at KVM x86 as a whole.

The other big argument for per-vCPU ASIDs is that it will allow us to elide TLB
flushes on task migration[*], which might not be a major performance win for bare
metal, but it can be a significant win when running nested.

https://lore.kernel.org/all/aHWjPSIdp5B-2UBl@google.com

      reply	other threads:[~2026-11-04 22:15 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 23:36 Yosry Ahmed
2026-10-12 23:36 ` [PATCH v3 01/27] KVM: nSVM: Flush the TLB after forcefully leaving nested Yosry Ahmed
2026-10-14 15:02   ` Jim Mattson
2026-10-14 15:18     ` Yosry Ahmed
2026-10-16 19:32       ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 02/27] KVM: SVM: Document number of ASIDs CPUID setting Yosry Ahmed
2026-10-14 15:07   ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 03/27] KVM: VMX: Generalize VPID allocation to be vendor-neutral Yosry Ahmed
2026-10-14 18:22   ` Jim Mattson
2026-10-14 20:38     ` Yosry Ahmed
2026-10-16 19:34       ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 04/27] KVM: x86/mmu: Support specifying reserved TLB tags Yosry Ahmed
2026-10-14 21:49   ` Jim Mattson
2026-10-14 22:07     ` Yosry Ahmed
2026-10-12 23:36 ` [PATCH v3 05/27] KVM: SVM: Add helpers to set/clear ASID flush in VMCB Yosry Ahmed
2026-10-14 22:00   ` Jim Mattson
2026-10-14 22:03     ` Yosry Ahmed
2026-10-14 22:22       ` Jim Mattson
2026-10-14 22:25         ` Yosry Ahmed
2026-10-14 22:32           ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 06/27] KVM: SVM: Fallback to flush everything if FLUSHBYASID is not available Yosry Ahmed
2026-10-14 22:45   ` Jim Mattson
2026-10-14 22:50     ` Yosry Ahmed
2026-10-14 23:27       ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 07/27] KVM: SEV: Do ASID initialization at VMCB initialization Yosry Ahmed
2026-10-14 23:31   ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 08/27] KVM: SEV: Expose sev_get_asid() outside of sev.c Yosry Ahmed
2026-10-14 23:33   ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 09/27] KVM: SEV: Explicitly initialize the per vCPU ASID on SEV VM migration Yosry Ahmed
2026-10-14 23:35   ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 10/27] KVM: SVM: Use a static ASID per vCPU Yosry Ahmed
2026-10-12 23:36 ` [PATCH v3 11/27] KVM: SVM: Only flush the fallback ASID when used by a different vCPU Yosry Ahmed
2026-10-15 21:44   ` Jim Mattson
2026-10-15 22:03     ` Yosry Ahmed
2026-10-16 19:36       ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 12/27] KVM: nSVM: Drop svm->nested.initialized Yosry Ahmed
2026-10-15 21:48   ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 13/27] KVM: nSVM: Add a placeholder ASID for L2 Yosry Ahmed
2026-10-15 21:55   ` Jim Mattson
2026-10-15 22:10     ` Yosry Ahmed
2026-10-15 22:21       ` Jim Mattson
2026-10-15 22:27         ` Yosry Ahmed
2026-10-12 23:36 ` [PATCH v3 14/27] KVM: x86: hyper-v: Rename kvm_hv_vcpu_purge_flush_tlb() Yosry Ahmed
2026-10-15 21:58   ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 15/27] KVM: x86: hyper-v: Allow purging all TLB flush FIFOs Yosry Ahmed
2026-10-15 22:02   ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 16/27] KVM: nSVM: Flush both L1 and L2 ASIDs on KVM_REQ_TLB_FLUSH Yosry Ahmed
2026-10-15 22:05   ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 17/27] KVM: nSVM: Always switch VMCB before leaving guest mode Yosry Ahmed
2026-10-15 22:08   ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 18/27] KVM: nSVM: Split nested_svm_transition_tlb_flush() into entry/exit fns Yosry Ahmed
2026-10-15 22:10   ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 19/27] KVM: nSVM: Service local TLB flushes before nested transitions Yosry Ahmed
2026-10-15 22:19   ` Jim Mattson
2026-10-15 22:34     ` Yosry Ahmed
2026-10-16 19:39       ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 20/27] KVM: x86: Add KVM_REQ_MMU_SYNC_ALL_ROOTS Yosry Ahmed
2026-10-15 22:24   ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 21/27] KVM: nSVM: Handle nested TLB flush requests through TLB_CONTROL Yosry Ahmed
2026-10-15 22:33   ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 22/27] KVM: nSVM: Flush the TLB if L1 changes L2's ASID in vmcb12 Yosry Ahmed
2026-10-15 23:09   ` Jim Mattson
2026-10-15 23:20     ` Yosry Ahmed
2026-10-15 23:50       ` Jim Mattson
2026-10-15 23:56         ` Yosry Ahmed
2026-10-16 19:24           ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 23/27] KVM: nSVM: Do not reset TLB_CONTROL in vmcb02 on nested VM-Enter Yosry Ahmed
2026-10-15 23:16   ` Jim Mattson
2026-10-15 23:22     ` Yosry Ahmed
2026-10-12 23:36 ` [PATCH v3 24/27] KVM: nSVM: Flush L2's ASID when emulating INVLPGA Yosry Ahmed
2026-10-15 23:37   ` Jim Mattson
2026-10-15 23:42     ` Yosry Ahmed
2026-10-16  0:53       ` Sean Christopherson
2026-10-16 19:41         ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 25/27] KVM: nSVM: Flush the ASID on nested transitions if shared by L1 and L2 Yosry Ahmed
2026-10-15 23:42   ` Jim Mattson
2026-10-12 23:36 ` [PATCH v3 26/27] KVM: nSVM: Use different ASIDs for " Yosry Ahmed
2026-10-16 21:17   ` Jim Mattson
2026-10-17  0:25     ` Yosry Ahmed
2026-10-19 18:49       ` Jim Mattson
2026-10-19 19:51         ` Yosry Ahmed
2026-10-26 17:33           ` Sean Christopherson
2026-10-22 22:44     ` Sean Christopherson
2026-10-22 22:45       ` Yosry Ahmed
2026-10-26 17:33         ` Sean Christopherson
2026-10-26 18:06           ` Yosry Ahmed
2026-10-27 17:50             ` Sean Christopherson
2026-10-27 17:56               ` Yosry Ahmed
2026-10-28 19:55                 ` Sean Christopherson
2026-10-28 20:00                   ` Yosry Ahmed
2026-10-28 20:21                     ` Sean Christopherson
2026-10-12 23:36 ` [PATCH v3 27/27] KVM: selftests: Add a test for nested TLB flushes Yosry Ahmed
2026-10-14 13:23 ` [PATCH v3 00/27] KVM: nSVM: Optimize nSVM " Jim Mattson
2026-10-14 14:37   ` Yosry Ahmed
2026-11-04 22:15     ` 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=auuum7Dq0w-swARW@google.com \
    --to=seanjc@google.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mlevitsk@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=thomas.lendacky@amd.com \
    --cc=vkuznets@redhat.com \
    --cc=yosry@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

all inboxes | Powered by JetHome®