Re: [PATCH v4 10/12] x86,tlb: do targeted broadcast flushing from tlbbatch code
From: Rik van Riel
Date: Mon Jan 13 2025 - 16:18:43 EST
On Mon, 2025-01-13 at 18:05 +0100, Jann Horn wrote:
> On Sun, Jan 12, 2025 at 4:55 PM Rik van Riel <riel@xxxxxxxxxxx>
> wrote:
>
> >
> > +void arch_tlbbatch_add_pending(struct arch_tlbflush_unmap_batch
> > *batch,
> > + struct mm_struct *mm,
> > + unsigned long uaddr)
> > +{
> > + if (static_cpu_has(X86_FEATURE_INVLPGB) &&
> > mm_global_asid(mm)) {
> > + u16 asid = mm_global_asid(mm);
> > + /*
> > + * Queue up an asynchronous invalidation. The
> > corresponding
> > + * TLBSYNC is done in arch_tlbbatch_flush(), and
> > must be done
> > + * on the same CPU.
> > + */
> > + if (!batch->used_invlpgb) {
> > + batch->used_invlpgb = true;
> > + migrate_disable();
> > + }
> > + invlpgb_flush_user_nr_nosync(kern_pcid(asid),
> > uaddr, 1, false);
> > + /* Do any CPUs supporting INVLPGB need PTI? */
> > + if (static_cpu_has(X86_FEATURE_PTI))
> > +
> > invlpgb_flush_user_nr_nosync(user_pcid(asid), uaddr, 1, false);
> > + } else {
> > + inc_mm_tlb_gen(mm);
> > + cpumask_or(&batch->cpumask, &batch->cpumask,
> > mm_cpumask(mm));
> > + }
> > + mmu_notifier_arch_invalidate_secondary_tlbs(mm, 0, -1UL);
> > +}
>
> How does this work if the MM is currently transitioning to a global
> ASID? Should the "mm_global_asid(mm)" check maybe be replaced with
> something that checks if the MM has fully transitioned to a global
> ASID, so that we keep using the classic path if there might be
> holdout
> CPUs?
>
You are right!
If the mm is still transitioning, we should send a
TLB flush IPI, in addition to doing the broadcast shootdown.
Worst case the CPU is already using a global ASID, and
the TLB flush IPI ends up being a noop.
--
All Rights Reversed.