Re: [PATCH v3 05/27] KVM: SVM: Add helpers to set/clear ASID flush in VMCB
From: Jim Mattson
Date: Wed Oct 14 2026 - 18:28:36 EST
On Wed, Oct 14, 2026 at 3:03 PM Yosry Ahmed <yosry@xxxxxxxxxx> wrote:
>
> On Wed, Oct 14, 2026 at 3:00 PM Jim Mattson <jmattson@xxxxxxxxxx> wrote:
> >
> > On Mon, Oct 12, 2026 at 4:36 PM Yosry Ahmed <yosry@xxxxxxxxxx> wrote:
> > >
> > > Introduce set/clear helpers to set tlb_ctl to
> > > TLB_CONTROL_FLUSH_ASID or TLB_CONTROL_DO_NOTHING. Incoming changes will
> > > eliminate the use of TLB_CONTROL_FLUSH_ALL_ASID except as a fallback
> > > when FLUSHBYASID is not available, so the helpers will create a common
> > > path for this.
> >
> > No functional change intended? :)
> >
> > >
> > > Signed-off-by: Yosry Ahmed <yosry@xxxxxxxxxx>
> > > ---
> > > arch/x86/kvm/svm/nested.c | 2 +-
> > > arch/x86/kvm/svm/sev.c | 2 +-
> > > arch/x86/kvm/svm/svm.c | 4 ++--
> > > arch/x86/kvm/svm/svm.h | 10 ++++++++++
> > > 4 files changed, 14 insertions(+), 4 deletions(-)
> > >
> > [ ... ]
> > > diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
> > > index 6d0242966dc87..ba5077b9838c0 100644
> > > --- a/arch/x86/kvm/svm/svm.h
> > > +++ b/arch/x86/kvm/svm/svm.h
> > > @@ -480,6 +480,16 @@ static inline void vmcb_set_gpat(struct vmcb *vmcb, u64 data)
> > > vmcb_mark_dirty(vmcb, VMCB_NPT);
> > > }
> > >
> > > +static inline void vmcb_set_flush_asid(struct vmcb *vmcb)
> > > +{
> > > + vmcb->control.tlb_ctl = TLB_CONTROL_FLUSH_ASID;
> > > +}
> > > +
> > > +static inline void vmcb_clr_flush_asid(struct vmcb *vmcb)
> >
> > The name of this function makes it sound like the inverse of
> > vmcb_set_flush_asid(), which it isn't. Maybe vmcb_clr_tlb_ctl()?
>
> Why not? vmcb_set_flush_asid() sets FLUSH_ASID and
> vmcb_clr_flush_asid() clears it, right?
Not exactly. The tlb_ctl field is not a boolean.
vmcb_set_flush_asid() sets tlb_ctl to 3 (flush current ASID).
vmcb_clr_flush_asid() sets tlb_ctl to 0 (do not flush).
Other legal values are 1 (flush entire TLB) and 7 (flush non-global
entries of current ASID).
And, in fact, these values were chosen so that older hardware would
see both 3 and 7 as "flush entire TLB."
So, it's a little more nuanced than set and clear "flush by ASID."
Maybe vmcb_set_flush_asid() and vmcb_set_flush_nothing()?