Re: [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping

From: Tom Lendacky
Date: Fri Jun 28 2024 - 17:32:09 EST




On 6/28/24 15:58, Edgecombe, Rick P wrote:
> On Fri, 2024-06-28 at 20:52 +0000, Ashish Kalra wrote:
>> diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
>> index 443a97e515c0..be8b5bf3bc3f 100644
>> --- a/arch/x86/mm/pat/set_memory.c
>> +++ b/arch/x86/mm/pat/set_memory.c
>> @@ -672,6 +672,7 @@ pte_t *lookup_address_in_pgd_attr(pgd_t *pgd, unsigned
>> long address,
>>         p4d_t *p4d;
>>         pud_t *pud;
>>         pmd_t *pmd;
>> +       pte_t *pte;
>>  
>>         *level = PG_LEVEL_256T;
>>         *nx = false;
>> @@ -717,7 +718,11 @@ pte_t *lookup_address_in_pgd_attr(pgd_t *pgd, unsigned
>> long address,
>>         *nx |= pmd_flags(*pmd) & _PAGE_NX;
>>         *rw &= pmd_flags(*pmd) & _PAGE_RW;
>>  
>> -       return pte_offset_kernel(pmd, address);
>> +       pte = pte_offset_kernel(pmd, address);
>> +       if (pte_none(*pte))
>> +               return NULL;
>> +
>> +       return pte;
>
> The other levels check for pXX_none() before adjusting *level. Not sure what the
> effect would be, but I think it should be the same behavior for all.

Agreed. It should follow the same logic as the previous checks.

It looks like the *nx and *rw should be updated, too, right? That seems to
be missing from the change that added them.

Thanks,
Tom