[12/31] mm/vmalloc: vmalloc_to_page() use pte_offset_kernel()

Message ID fc3c7ca1-6c9c-b6c-f4df-36f24b56139@google.com
State New
Headers
Series mm: allow pte_offset_map[_lock]() to fail |

Commit Message

Hugh Dickins May 22, 2023, 5:04 a.m. UTC
  vmalloc_to_page() was using pte_offset_map() (followed by pte_unmap()),
but it's intended for userspace page tables: prefer pte_offset_kernel().

Signed-off-by: Hugh Dickins <hughd@google.com>
---
 mm/vmalloc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
  

Comments

Lorenzo Stoakes May 22, 2023, 7:27 a.m. UTC | #1
On Sun, May 21, 2023 at 10:04:07PM -0700, Hugh Dickins wrote:
> vmalloc_to_page() was using pte_offset_map() (followed by pte_unmap()),
> but it's intended for userspace page tables: prefer pte_offset_kernel().
>
> Signed-off-by: Hugh Dickins <hughd@google.com>
> ---
>  mm/vmalloc.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 9683573f1225..741722d247d5 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -703,11 +703,10 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
>  	if (WARN_ON_ONCE(pmd_bad(*pmd)))
>  		return NULL;
>
> -	ptep = pte_offset_map(pmd, addr);
> +	ptep = pte_offset_kernel(pmd, addr);
>  	pte = *ptep;
>  	if (pte_present(pte))
>  		page = pte_page(pte);
> -	pte_unmap(ptep);
>
>  	return page;
>  }
> --
> 2.35.3
>

Looks good to me,

Reviewed-by: Lorenzo Stoakes <lstoakes@gmail.com>
  

Patch

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 9683573f1225..741722d247d5 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -703,11 +703,10 @@  struct page *vmalloc_to_page(const void *vmalloc_addr)
 	if (WARN_ON_ONCE(pmd_bad(*pmd)))
 		return NULL;
 
-	ptep = pte_offset_map(pmd, addr);
+	ptep = pte_offset_kernel(pmd, addr);
 	pte = *ptep;
 	if (pte_present(pte))
 		page = pte_page(pte);
-	pte_unmap(ptep);
 
 	return page;
 }