Re: [PATCH] MIPS: mm: tlb-r4k: Uniquify TLB entries on init

From: Jiaxun Yang
Date: Sat Jun 07 2025 - 06:37:24 EST




在2025年6月7日周六 上午3:48,Maciej W. Rozycki写道:
> On Thu, 5 Jun 2025, Jiaxun Yang wrote:
>
>> +static unsigned long r4k_safe_entryhi(void)
>> +{
>> + int entry = current_cpu_data.tlbsize;
>> + int old_index;
>> +
>> + old_index = read_c0_index();
>> + while (entry >= 0) {
> [...]
>> + entry++;
>> + }
>
> Hmm, how is it supposed to work: you start from say 48 and then iterate
> until 0x80000000 before giving up? Also a signed overflow condition is UB
> pre-C23, so the compiler may well optimise the loop control away.

Ah sorry I didn't realise it's a UB. However, this loop is likely to be
terminated very early as it should be fairly easily to find a free EntryHi
value with TLBP.

>
> How did you verify this code?

Boot tested on Boston as well as M5150 simulation. I tried to manually setup a
TLB entry collision situation with Boot-MIPS.

>
> Maciej

Thanks

--
- Jiaxun