Re: [PATCH 06/12] x86/mm: use INVLPGB for kernel TLB flushes

From: Rik van Riel
Date: Fri Jan 10 2025 - 15:29:35 EST


On Fri, 2025-01-10 at 12:53 -0600, Tom Lendacky wrote:
> On 12/30/24 11:53, Rik van Riel wrote:
> > Use broadcast TLB invalidation for kernel addresses when available.
> >
> > +static void broadcast_kernel_range_flush(unsigned long start,
> > unsigned long end)
> > +{
> > + unsigned long addr;
> > + unsigned long maxnr = invlpgb_count_max;
> > + unsigned long threshold = tlb_single_page_flush_ceiling *
> > maxnr;
> > +
> > + /*
> > + * TLBSYNC only waits for flushes originating on the same
> > CPU.
> > + * Disabling migration allows us to wait on all flushes.
> > + */
> > + guard(preempt)();
> > +
> > + if (end == TLB_FLUSH_ALL ||
> > +     (end - start) > threshold << PAGE_SHIFT) {
> > + invlpgb_flush_all();
> > + } else {
> > + unsigned long nr;
> > + for (addr = start; addr < end; addr += nr <<
> > PAGE_SHIFT) {
> > + nr = min((end - addr) >> PAGE_SHIFT,
> > maxnr);
> > + invlpgb_flush_addr(addr, nr);
> > + }
>
> Would it be better to put this loop in the actual invlpgb_flush*
> function(s)? Then callers don't have to worry about it, similar to
> what is
> done in clflush_cache_range() / clflush_cache_range_opt().

Maybe?

We only have one caller, though.


--
All Rights Reversed.