* [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping
@ 2024-06-28 20:52 Ashish Kalra
2024-06-28 20:58 ` Edgecombe, Rick P
2024-06-29 10:20 ` Jürgen Groß
0 siblings, 2 replies; 15+ messages in thread
From: Ashish Kalra @ 2024-06-28 20:52 UTC (permalink / raw)
To: dave.hansen, luto, peterz, tglx, mingo, bp
Cc: x86, hpa, kirill.shutemov, rick.p.edgecombe, mhklinux, peterx,
jgross, linux-kernel, thomas.lendacky, linux-coco, jroedel
From: Ashish Kalra <ashish.kalra@amd.com>
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.
Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
---
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;
}
/*
--
2.34.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping
2024-06-28 20:52 [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping Ashish Kalra
@ 2024-06-28 20:58 ` Edgecombe, Rick P
2024-06-28 21:22 ` Kalra, Ashish
2024-06-28 21:31 ` Tom Lendacky
2024-06-29 10:20 ` Jürgen Groß
1 sibling, 2 replies; 15+ messages in thread
From: Edgecombe, Rick P @ 2024-06-28 20:58 UTC (permalink / raw)
To: tglx@linutronix.de, Ashish.Kalra@amd.com, peterz@infradead.org,
mingo@redhat.com, luto@kernel.org, dave.hansen@linux.intel.com,
bp@alien8.de
Cc: jgross@suse.com, x86@kernel.org, mhklinux@outlook.com,
Rodel, Jorg, hpa@zytor.com, linux-kernel@vger.kernel.org,
thomas.lendacky@amd.com, kirill.shutemov@linux.intel.com,
peterx@redhat.com, linux-coco@lists.linux.dev
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.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping
2024-06-28 20:58 ` Edgecombe, Rick P
@ 2024-06-28 21:22 ` Kalra, Ashish
2024-06-28 21:33 ` Edgecombe, Rick P
2024-06-28 21:31 ` Tom Lendacky
1 sibling, 1 reply; 15+ messages in thread
From: Kalra, Ashish @ 2024-06-28 21:22 UTC (permalink / raw)
To: Edgecombe, Rick P, tglx@linutronix.de, peterz@infradead.org,
mingo@redhat.com, luto@kernel.org, dave.hansen@linux.intel.com,
bp@alien8.de
Cc: jgross@suse.com, x86@kernel.org, mhklinux@outlook.com,
Rodel, Jorg, hpa@zytor.com, linux-kernel@vger.kernel.org,
thomas.lendacky@amd.com, kirill.shutemov@linux.intel.com,
peterx@redhat.com, linux-coco@lists.linux.dev
On 6/28/2024 3:58 PM, 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.
If we are returning NULL, why should adjusting *level matter.
Thanks, Ashish
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping
2024-06-28 20:58 ` Edgecombe, Rick P
2024-06-28 21:22 ` Kalra, Ashish
@ 2024-06-28 21:31 ` Tom Lendacky
1 sibling, 0 replies; 15+ messages in thread
From: Tom Lendacky @ 2024-06-28 21:31 UTC (permalink / raw)
To: Edgecombe, Rick P, tglx@linutronix.de, Ashish.Kalra@amd.com,
peterz@infradead.org, mingo@redhat.com, luto@kernel.org,
dave.hansen@linux.intel.com, bp@alien8.de
Cc: jgross@suse.com, x86@kernel.org, mhklinux@outlook.com,
Rodel, Jorg, hpa@zytor.com, linux-kernel@vger.kernel.org,
kirill.shutemov@linux.intel.com, peterx@redhat.com,
linux-coco@lists.linux.dev
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
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping
2024-06-28 21:22 ` Kalra, Ashish
@ 2024-06-28 21:33 ` Edgecombe, Rick P
2024-06-28 21:36 ` Tom Lendacky
0 siblings, 1 reply; 15+ messages in thread
From: Edgecombe, Rick P @ 2024-06-28 21:33 UTC (permalink / raw)
To: tglx@linutronix.de, ashish.kalra@amd.com, peterz@infradead.org,
mingo@redhat.com, luto@kernel.org, dave.hansen@linux.intel.com,
bp@alien8.de
Cc: jgross@suse.com, x86@kernel.org, Rodel, Jorg,
mhklinux@outlook.com, hpa@zytor.com, linux-kernel@vger.kernel.org,
thomas.lendacky@amd.com, kirill.shutemov@linux.intel.com,
peterx@redhat.com, linux-coco@lists.linux.dev
On Fri, 2024-06-28 at 16:22 -0500, Kalra, Ashish wrote:
> > > @@ -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.
>
> If we are returning NULL, why should adjusting *level matter.
Well, I think symmetry is enough of a reason, but actually it should be ok.
I was looking at this diff compared to my working tree, but this tip commit
(which is about that scenario) makes it set *level before checking none for all
of them:
https://lore.kernel.org/lkml/171871930159.10875.16081839197437299007.tip-bot2@tip-bot2/
So sorry, nevermind.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping
2024-06-28 21:33 ` Edgecombe, Rick P
@ 2024-06-28 21:36 ` Tom Lendacky
0 siblings, 0 replies; 15+ messages in thread
From: Tom Lendacky @ 2024-06-28 21:36 UTC (permalink / raw)
To: Edgecombe, Rick P, tglx@linutronix.de, ashish.kalra@amd.com,
peterz@infradead.org, mingo@redhat.com, luto@kernel.org,
dave.hansen@linux.intel.com, bp@alien8.de
Cc: jgross@suse.com, x86@kernel.org, Rodel, Jorg,
mhklinux@outlook.com, hpa@zytor.com, linux-kernel@vger.kernel.org,
kirill.shutemov@linux.intel.com, peterx@redhat.com,
linux-coco@lists.linux.dev
On 6/28/24 16:33, Edgecombe, Rick P wrote:
> On Fri, 2024-06-28 at 16:22 -0500, Kalra, Ashish wrote:
>>>> @@ -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.
>>
>> If we are returning NULL, why should adjusting *level matter.
>
> Well, I think symmetry is enough of a reason, but actually it should be ok.
>
> I was looking at this diff compared to my working tree, but this tip commit
Ditto for me.
Thanks,
Tom
> (which is about that scenario) makes it set *level before checking none for all
> of them:
> https://lore.kernel.org/lkml/171871930159.10875.16081839197437299007.tip-bot2@tip-bot2/
>
> So sorry, nevermind.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping
2024-06-28 20:52 [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping Ashish Kalra
2024-06-28 20:58 ` Edgecombe, Rick P
@ 2024-06-29 10:20 ` Jürgen Groß
2024-06-29 15:16 ` Tom Lendacky
2024-07-01 17:57 ` Kalra, Ashish
1 sibling, 2 replies; 15+ messages in thread
From: Jürgen Groß @ 2024-06-29 10:20 UTC (permalink / raw)
To: Ashish Kalra, dave.hansen, luto, peterz, tglx, mingo, bp
Cc: x86, hpa, kirill.shutemov, rick.p.edgecombe, mhklinux, peterx,
linux-kernel, thomas.lendacky, linux-coco, jroedel
On 28.06.24 22:52, Ashish Kalra wrote:
> From: Ashish Kalra <ashish.kalra@amd.com>
>
> 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.
Juergen
>
> Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
> ---
> 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;
> }
>
> /*
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping
2024-06-29 10:20 ` Jürgen Groß
@ 2024-06-29 15:16 ` Tom Lendacky
2024-06-29 16:50 ` Jürgen Groß
2024-07-01 17:57 ` Kalra, Ashish
1 sibling, 1 reply; 15+ messages in thread
From: Tom Lendacky @ 2024-06-29 15:16 UTC (permalink / raw)
To: Jürgen Groß, Ashish Kalra, dave.hansen, luto, peterz,
tglx, mingo, bp
Cc: x86, hpa, kirill.shutemov, rick.p.edgecombe, mhklinux, peterx,
linux-kernel, linux-coco, jroedel
On 6/29/24 05:20, Jürgen Groß wrote:
> On 28.06.24 22:52, Ashish Kalra wrote:
>> From: Ashish Kalra <ashish.kalra@amd.com>
>>
>> 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.
This brings up a point from my other reply. The comment says that it
returns "the effective NX and RW bits of all page table levels", but in
fact NX and RW are not updated for the PTE. Since the comment says all
page table levels, shouldn't they be updated with the PTE values, too?
Thanks,
Tom
>
>
> Juergen
>
>>
>> Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
>> ---
>> 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;
>> }
>> /*
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping
2024-06-29 15:16 ` Tom Lendacky
@ 2024-06-29 16:50 ` Jürgen Groß
0 siblings, 0 replies; 15+ messages in thread
From: Jürgen Groß @ 2024-06-29 16:50 UTC (permalink / raw)
To: Tom Lendacky, Ashish Kalra, dave.hansen, luto, peterz, tglx,
mingo, bp
Cc: x86, hpa, kirill.shutemov, rick.p.edgecombe, mhklinux, peterx,
linux-kernel, linux-coco, jroedel
On 29.06.24 17:16, Tom Lendacky wrote:
> On 6/29/24 05:20, Jürgen Groß wrote:
>> On 28.06.24 22:52, Ashish Kalra wrote:
>>> From: Ashish Kalra <ashish.kalra@amd.com>
>>>
>>> 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.
>
> This brings up a point from my other reply. The comment says that it
> returns "the effective NX and RW bits of all page table levels", but in
> fact NX and RW are not updated for the PTE. Since the comment says all
> page table levels, shouldn't they be updated with the PTE values, too?
Hmm, the comment could need some clarifications.
It returns the effective NX and RW bits of the levels above the PTE. Reason is
that the function is used in case the NX/RW bits of a PTE are updated, so the
PTE settings are not always really important.
Juergen
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping
2024-06-29 10:20 ` Jürgen Groß
2024-06-29 15:16 ` Tom Lendacky
@ 2024-07-01 17:57 ` Kalra, Ashish
2024-07-01 18:38 ` Jürgen Groß
1 sibling, 1 reply; 15+ messages in thread
From: Kalra, Ashish @ 2024-07-01 17:57 UTC (permalink / raw)
To: Jürgen Groß, dave.hansen, luto, peterz, tglx, mingo, bp
Cc: x86, hpa, kirill.shutemov, rick.p.edgecombe, mhklinux, peterx,
linux-kernel, thomas.lendacky, linux-coco, jroedel
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@amd.com>
>>
>> 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@amd.com>
>> ---
>> 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;
>> }
>> /*
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping
2024-07-01 17:57 ` Kalra, Ashish
@ 2024-07-01 18:38 ` Jürgen Groß
2024-07-01 18:59 ` Kalra, Ashish
0 siblings, 1 reply; 15+ messages in thread
From: Jürgen Groß @ 2024-07-01 18:38 UTC (permalink / raw)
To: Kalra, Ashish, dave.hansen, luto, peterz, tglx, mingo, bp
Cc: x86, hpa, kirill.shutemov, rick.p.edgecombe, mhklinux, peterx,
linux-kernel, thomas.lendacky, linux-coco, jroedel
On 01.07.24 19:57, Kalra, Ashish wrote:
>
> 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@amd.com>
>>>
>>> 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.
There is a PTE, but it is all 0.
There is no _valid_ PTE. No PTE would mean that the related PMD entry (or any
other higher level entry) is invalid.
Remember that the W^X checking needs to be performed _before_ a new PTE is
written.
Juergen
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping
2024-07-01 18:38 ` Jürgen Groß
@ 2024-07-01 18:59 ` Kalra, Ashish
2024-07-01 19:13 ` Edgecombe, Rick P
0 siblings, 1 reply; 15+ messages in thread
From: Kalra, Ashish @ 2024-07-01 18:59 UTC (permalink / raw)
To: Jürgen Groß, dave.hansen, luto, peterz, tglx, mingo, bp
Cc: x86, hpa, kirill.shutemov, rick.p.edgecombe, mhklinux, peterx,
linux-kernel, thomas.lendacky, linux-coco, jroedel
On 7/1/2024 1:38 PM, Jürgen Groß wrote:
> On 01.07.24 19:57, Kalra, Ashish wrote:
>>
>> 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@amd.com>
>>>>
>>>> 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.
>
> There is a PTE, but it is all 0.
>
> There is no _valid_ PTE. No PTE would mean that the related PMD entry (or any
> other higher level entry) is invalid.
Then what is the caller supposed to do in this case ?
As the return from lookup_address() is non-NULL in this case, accessing it causes a fatal #PF.
Is the caller supposed to add the check for a valid PTE using pte_none(*pte) ?
Thanks, Ashish
>
> Remember that the W^X checking needs to be performed _before_ a new PTE is
> written.
>
>
> Juergen
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping
2024-07-01 18:59 ` Kalra, Ashish
@ 2024-07-01 19:13 ` Edgecombe, Rick P
2024-07-01 19:39 ` Kalra, Ashish
0 siblings, 1 reply; 15+ messages in thread
From: Edgecombe, Rick P @ 2024-07-01 19:13 UTC (permalink / raw)
To: jgross@suse.com, luto@kernel.org, bp@alien8.de,
dave.hansen@linux.intel.com, peterz@infradead.org,
mingo@redhat.com, tglx@linutronix.de, ashish.kalra@amd.com
Cc: x86@kernel.org, mhklinux@outlook.com, Rodel, Jorg, hpa@zytor.com,
linux-kernel@vger.kernel.org, thomas.lendacky@amd.com,
kirill.shutemov@linux.intel.com, peterx@redhat.com,
linux-coco@lists.linux.dev
On Mon, 2024-07-01 at 13:59 -0500, Kalra, Ashish wrote:
>
> Then what is the caller supposed to do in this case ?
>
> As the return from lookup_address() is non-NULL in this case, accessing it
> causes a fatal #PF.
>
> Is the caller supposed to add the check for a valid PTE using pte_none(*pte) ?
I did a quick look at the callers, and some do their own check for pte_none().
But some don't. Some also assume the return can't be NULL.
Can you elaborate on your goal for this change? Just a cleanup?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping
2024-07-01 19:13 ` Edgecombe, Rick P
@ 2024-07-01 19:39 ` Kalra, Ashish
2024-07-02 5:29 ` Jürgen Groß
0 siblings, 1 reply; 15+ messages in thread
From: Kalra, Ashish @ 2024-07-01 19:39 UTC (permalink / raw)
To: Edgecombe, Rick P, jgross@suse.com, luto@kernel.org, bp@alien8.de,
dave.hansen@linux.intel.com, peterz@infradead.org,
mingo@redhat.com, tglx@linutronix.de
Cc: x86@kernel.org, mhklinux@outlook.com, Rodel, Jorg, hpa@zytor.com,
linux-kernel@vger.kernel.org, thomas.lendacky@amd.com,
kirill.shutemov@linux.intel.com, peterx@redhat.com,
linux-coco@lists.linux.dev
On 7/1/2024 2:13 PM, Edgecombe, Rick P wrote:
> On Mon, 2024-07-01 at 13:59 -0500, Kalra, Ashish wrote:
>> Then what is the caller supposed to do in this case ?
>>
>> As the return from lookup_address() is non-NULL in this case, accessing it
>> causes a fatal #PF.
>>
>> Is the caller supposed to add the check for a valid PTE using pte_none(*pte) ?
> I did a quick look at the callers, and some do their own check for pte_none().
> But some don't. Some also assume the return can't be NULL.
>
> Can you elaborate on your goal for this change? Just a cleanup?
Hit this issue while implementing and testing SNP guest kexec.
So trying to understand if need a generic fix for this issue or do i need to add my own check for pte_none() ?
Thanks, Ashish
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping
2024-07-01 19:39 ` Kalra, Ashish
@ 2024-07-02 5:29 ` Jürgen Groß
0 siblings, 0 replies; 15+ messages in thread
From: Jürgen Groß @ 2024-07-02 5:29 UTC (permalink / raw)
To: Kalra, Ashish, Edgecombe, Rick P, luto@kernel.org, bp@alien8.de,
dave.hansen@linux.intel.com, peterz@infradead.org,
mingo@redhat.com, tglx@linutronix.de
Cc: x86@kernel.org, mhklinux@outlook.com, Rodel, Jorg, hpa@zytor.com,
linux-kernel@vger.kernel.org, thomas.lendacky@amd.com,
kirill.shutemov@linux.intel.com, peterx@redhat.com,
linux-coco@lists.linux.dev
On 01.07.24 21:39, Kalra, Ashish wrote:
>
> On 7/1/2024 2:13 PM, Edgecombe, Rick P wrote:
>> On Mon, 2024-07-01 at 13:59 -0500, Kalra, Ashish wrote:
>>> Then what is the caller supposed to do in this case ?
>>>
>>> As the return from lookup_address() is non-NULL in this case, accessing it
>>> causes a fatal #PF.
>>>
>>> Is the caller supposed to add the check for a valid PTE using pte_none(*pte) ?
>> I did a quick look at the callers, and some do their own check for pte_none().
>> But some don't. Some also assume the return can't be NULL.
>>
>> Can you elaborate on your goal for this change? Just a cleanup?
>
> Hit this issue while implementing and testing SNP guest kexec.
>
> So trying to understand if need a generic fix for this issue or do i need to add my own check for pte_none() ?
Please add a check for pte_none() after calling lookup_address().
Juergen
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2024-07-02 5:29 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-28 20:52 [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping Ashish Kalra
2024-06-28 20:58 ` Edgecombe, Rick P
2024-06-28 21:22 ` Kalra, Ashish
2024-06-28 21:33 ` Edgecombe, Rick P
2024-06-28 21:36 ` Tom Lendacky
2024-06-28 21:31 ` Tom Lendacky
2024-06-29 10:20 ` Jürgen Groß
2024-06-29 15:16 ` Tom Lendacky
2024-06-29 16:50 ` Jürgen Groß
2024-07-01 17:57 ` Kalra, Ashish
2024-07-01 18:38 ` Jürgen Groß
2024-07-01 18:59 ` Kalra, Ashish
2024-07-01 19:13 ` Edgecombe, Rick P
2024-07-01 19:39 ` Kalra, Ashish
2024-07-02 5:29 ` Jürgen Groß
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).