Re: [RFC PATCH 4/6] x86/mm/tlb: Refactor common code into flush_tlb_on_cpus()

From: Nadav Amit
Date: Mon May 27 2019 - 15:04:33 EST


> On May 27, 2019, at 2:24 AM, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Sat, May 25, 2019 at 01:22:01AM -0700, Nadav Amit wrote:
>
>> There is one functional change, which should not affect correctness:
>> flush_tlb_mm_range compared loaded_mm and the mm to figure out if local
>> flush is needed. Instead, the common code would look at the mm_cpumask()
>> which should give the same result.
>
>> @@ -786,18 +804,9 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
>> info = get_flush_tlb_info(mm, start, end, stride_shift, freed_tables,
>> new_tlb_gen);
>>
>> - if (mm == this_cpu_read(cpu_tlbstate.loaded_mm)) {
>> - lockdep_assert_irqs_enabled();
>> - local_irq_disable();
>> - flush_tlb_func_local(info, TLB_LOCAL_MM_SHOOTDOWN);
>> - local_irq_enable();
>> - }
>> -
>> - if (cpumask_any_but(mm_cpumask(mm), cpu) < nr_cpu_ids)
>> - flush_tlb_others(mm_cpumask(mm), info);
>
> So if we want to double check that; we'd add:
>
> WARN_ON_ONCE(cpumask_test_cpu(smp_processor_id(), mm_cpumask(mm)) ==
> (mm == this_cpu_read(cpu_tlbstate.loaded_mm)));
>
> right?

Yes, except the condition should be inverted (â!=â instead of â==â), and I
would prefer to use VM_WARN_ON_ONCE().

Unfortunately, this condition does fire when copy_init_mm() calls dup_mm().
I donât think there is a correctness issue, and I am tempted just check,
before warning, that (mm != init_mm) .

What do you say?