Re: [PATCH 4/5] x86/mm: Decouple kernel TLB flushes from flush_tlb_info

From: Chuyi Zhou

Date: Wed Sep 23 2026 - 07:01:25 EST


On 2026-09-23 5:28 p.m., Sebastian Andrzej Siewior wrote:
> On 2026-09-21 17:53:58 [+0800], Chuyi Zhou wrote:
>> --- a/arch/x86/mm/tlb.c
>> +++ b/arch/x86/mm/tlb.c
>> @@ -1487,38 +1487,47 @@ static void invlpgb_kernel_range_flush(struct flush_tlb_info *info)
> …
>> void flush_tlb_kernel_range(unsigned long start, unsigned long end)
>> {
>> - struct flush_tlb_info info;
>> -
>> guard(preempt)();
>> - init_flush_tlb_info(&info, NULL, start, end, PAGE_SHIFT, false,
>> - TLB_GENERATION_INVALID);
>>
>> - if (info.end == TLB_FLUSH_ALL)
>> + if (end == TLB_FLUSH_ALL ||
>
> info.end might be TLB_FLUSH_ALL because init_flush_tlb_info() might set
> it so. But 'end', which is passed as an argument, should not be
> TLB_FLUSH_ALL or can it?
> And if so, wouldn't the check below cover it anyway?

I couldn't find any callers passing TLB_FLUSH_ALL as end.
flush_tlb_kernel_range(start, end) is used to flush actual address
ranges, and flush_tlb_all() is available for unconditional full flushes.
So I agree that we can drop the explicit check.

The ceiling check does not cover all possible inputs, though. For
example, with start = ULONG_MAX - PAGE_SIZE + 1 and end = TLB_FLUSH_ALL,
the expression (end - start) >> PAGE_SHIFT evaluates to zero. The
ceiling check would therefore select a range flush, whereas the explicit
check would select a full flush.

I added the explicit check to preserve that behavior of the old code,
but the current callers do not need it. I'll remove it.



>
>> + tlb_range_exceeds_ceiling(start, end, PAGE_SHIFT))
>> kernel_tlb_flush_all();
>> else
>> - kernel_tlb_flush_range(&info);
>> + kernel_tlb_flush_range(start, end);
>> }
>
> Sebastian