Re: [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping
From: Kalra, Ashish
Date: Mon Jul 01 2024 - 13:58:11 EST
On 6/29/2024 5:20 AM, Jürgen Groß wrote:
> On 28.06.24 22:52, Ashish Kalra wrote:
>> From: Ashish Kalra <ashish.kalra@xxxxxxx>
>>
>> lookup_address_in_pgd_attr() at pte level it is simply returning
>> pte_offset_kernel() and there does not seem to be a check for
>> returning NULL if pte_none().
>>
>> Fix lookup_address_in_pgd_attr() to add check for pte_none()
>> after pte_offset_kernel() and return NULL if it is true.
>
> Please have a look at the comment above lookup_address(). You should not
> break the documented behavior without verifying that no caller is relying
> on the current behavior. If this is fine, please update the comment.
>
>
I don't get that, in this case the PTE does not exist, so as per the comments here lookup_address() should have returned NULL.
Thanks, Ashish
>
>>
>> Signed-off-by: Ashish Kalra <ashish.kalra@xxxxxxx>
>> ---
>> arch/x86/mm/pat/set_memory.c | 7 ++++++-
>> 1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> 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;
>> }
>> /*
>