[PATCH v4 4/5] mm,hugetlb: drop obsolete comment about non-present pte and second faults

Oscar Salvador posted 5 patches 3 months, 1 week ago
[PATCH v4 4/5] mm,hugetlb: drop obsolete comment about non-present pte and second faults
Posted by Oscar Salvador 3 months, 1 week ago
There is a comment in hugetlb_fault() that does not hold anymore.  This
one:

 /*
  * vmf.orig_pte could be a migration/hwpoison vmf.orig_pte at this
  * point, so this check prevents the kernel from going below assuming
  * that we have an active hugepage in pagecache. This goto expects
  * the 2nd page fault, and is_hugetlb_entry_(migration|hwpoisoned)
  * check will properly handle it.
  */

This was written because back in the day we used to do:

 hugetlb_fault () {
  ptep = huge_pte_offset(...)
  if (ptep) {
    entry = huge_ptep_get(ptep)
    if (unlikely(is_hugetlb_entry_migration(entry))
        ...
    else if (unlikely(is_hugetlb_entry_hwpoisoned(entry)))
        ...
  }

  ...
  ...

  /*
   * entry could be a migration/hwpoison entry at this point, so this
   * check prevents the kernel from going below assuming that we have
   * a active hugepage in pagecache. This goto expects the 2nd page fault,
   * and is_hugetlb_entry_(migration|hwpoisoned) check will properly
   * handle it.
   */
  if (!pte_present(entry))
          goto out_mutex;
  ...
 }

The code was designed to check for hwpoisoned/migration entries upfront,
and then bail out if further down the pte was not present anymore, relying
on the second fault to properly handle migration/hwpoison entries that
time around.

The way we handle this is different nowadays, so drop the misleading
comment.

Link: https://lkml.kernel.org/r/20250627102904.107202-5-osalvador@suse.de
Signed-off-by: Oscar Salvador <osalvador@suse.de>
Cc: David Hildenbrand <david@redhat.com>
Cc: Gavin Guo <gavinguo@igalia.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Peter Xu <peterx@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
 mm/hugetlb.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 67f3c9c16348..ba078aa1cb96 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -6745,13 +6745,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
 
 	ret = 0;
 
-	/*
-	 * vmf.orig_pte could be a migration/hwpoison vmf.orig_pte at this
-	 * point, so this check prevents the kernel from going below assuming
-	 * that we have an active hugepage in pagecache. This goto expects
-	 * the 2nd page fault, and is_hugetlb_entry_(migration|hwpoisoned)
-	 * check will properly handle it.
-	 */
+	/* Not present, either a migration or a hwpoisoned entry */
 	if (!pte_present(vmf.orig_pte)) {
 		if (unlikely(is_hugetlb_entry_migration(vmf.orig_pte))) {
 			/*
-- 
2.50.0
Re: [PATCH v4 4/5] mm,hugetlb: drop obsolete comment about non-present pte and second faults
Posted by David Hildenbrand 3 months ago
On 30.06.25 16:42, Oscar Salvador wrote:
> There is a comment in hugetlb_fault() that does not hold anymore.  This
> one:
> 
>   /*
>    * vmf.orig_pte could be a migration/hwpoison vmf.orig_pte at this
>    * point, so this check prevents the kernel from going below assuming
>    * that we have an active hugepage in pagecache. This goto expects
>    * the 2nd page fault, and is_hugetlb_entry_(migration|hwpoisoned)
>    * check will properly handle it.
>    */
> 
> This was written because back in the day we used to do:
> 
>   hugetlb_fault () {
>    ptep = huge_pte_offset(...)
>    if (ptep) {
>      entry = huge_ptep_get(ptep)
>      if (unlikely(is_hugetlb_entry_migration(entry))
>          ...
>      else if (unlikely(is_hugetlb_entry_hwpoisoned(entry)))
>          ...
>    }
> 
>    ...
>    ...
> 
>    /*
>     * entry could be a migration/hwpoison entry at this point, so this
>     * check prevents the kernel from going below assuming that we have
>     * a active hugepage in pagecache. This goto expects the 2nd page fault,
>     * and is_hugetlb_entry_(migration|hwpoisoned) check will properly
>     * handle it.
>     */
>    if (!pte_present(entry))
>            goto out_mutex;
>    ...
>   }
> 
> The code was designed to check for hwpoisoned/migration entries upfront,
> and then bail out if further down the pte was not present anymore, relying
> on the second fault to properly handle migration/hwpoison entries that
> time around.
> 
> The way we handle this is different nowadays, so drop the misleading
> comment.
> 
> Link: https://lkml.kernel.org/r/20250627102904.107202-5-osalvador@suse.de
> Signed-off-by: Oscar Salvador <osalvador@suse.de>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Gavin Guo <gavinguo@igalia.com>
> Cc: Muchun Song <muchun.song@linux.dev>
> Cc: Peter Xu <peterx@redhat.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb