From: SeongJae Park <sj@kernel.org>
To: Jianhui Zhou <jianhuizzzzz@gmail.com>
Cc: SeongJae Park <sj@kernel.org>,
Muchun Song <muchun.song@linux.dev>,
Oscar Salvador <osalvador@suse.de>,
Andrew Morton <akpm@linux-foundation.org>,
Mike Rapoport <rppt@kernel.org>,
David Hildenbrand <david@kernel.org>,
Peter Xu <peterx@redhat.com>,
Andrea Arcangeli <aarcange@redhat.com>,
Mike Kravetz <mike.kravetz@oracle.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Jonas Zhou <jonaszhou@zhaoxin.com>,
syzbot+f525fd79634858f478e7@syzkaller.appspotmail.com,
stable@vger.kernel.org
Subject: Re: [PATCH] mm/userfaultfd: fix hugetlb fault mutex hash calculation
Date: Fri, 6 Mar 2026 19:27:57 -0800 [thread overview]
Message-ID: <20260307032759.100915-1-sj@kernel.org> (raw)
In-Reply-To: <20260306140332.171078-1-jianhuizzzzz@gmail.com>
Hello Jianhui,
On Fri, 6 Mar 2026 22:03:32 +0800 Jianhui Zhou <jianhuizzzzz@gmail.com> wrote:
> In mfill_atomic_hugetlb(), linear_page_index() is used to calculate the
> page index for hugetlb_fault_mutex_hash(). However, linear_page_index()
> returns the index in PAGE_SIZE units, while hugetlb_fault_mutex_hash()
> expects the index in huge page units (as calculated by
> vma_hugecache_offset()). This mismatch means that different addresses
> within the same huge page can produce different hash values, leading to
> the use of different mutexes for the same huge page. This can cause
> races between faulting threads, which can corrupt the reservation map
> and trigger the BUG_ON in resv_map_release().
>
> Fix this by replacing linear_page_index() with vma_hugecache_offset()
> and applying huge_page_mask() to align the address properly. To make
> vma_hugecache_offset() available outside of mm/hugetlb.c, move it to
> include/linux/hugetlb.h as a static inline function.
>
> Fixes: 60d4d2d2b40e ("userfaultfd: hugetlbfs: add __mcopy_atomic_hugetlb for huge page UFFDIO_COPY")
> Reported-by: syzbot+f525fd79634858f478e7@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=f525fd79634858f478e7
> Cc: stable@vger.kernel.org
> Signed-off-by: Jianhui Zhou <jianhuizzzzz@gmail.com>
> ---
[...]
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
[...]
> +static inline pgoff_t vma_hugecache_offset(struct hstate *h,
> + struct vm_area_struct *vma, unsigned long address)
> +{
> + return linear_page_index(vma, address);
> +}
> +
I just found this patch makes UML build fails as below.
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=8
ERROR:root:In file included from ../io_uring/rsrc.c:9:
../include/linux/hugetlb.h: In function ‘vma_hugecache_offset’:
../include/linux/hugetlb.h:1214:16: error: implicit declaration of function ‘linear_page_index’ [-Wimplicit-function-declaration]
1214 | return linear_page_index(vma, address);
| ^~~~~~~~~~~~~~~~~
Maybe we need to include pagemap.h? I confirmed below attaching patch fix the
error on my setup.
Thanks,
SJ
[...]
=== >8 ===
From f55581ba154d6c8aaaf1f1d33cc317b5bf463147 Mon Sep 17 00:00:00 2001
From: SeongJae Park <sj@kernel.org>
Date: Fri, 6 Mar 2026 19:23:28 -0800
Subject: [PATCH] mm/hugetlb: include pagemap.h to fix build error
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Without this, UML build fails as below:
$ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=8
ERROR:root:In file included from ../io_uring/rsrc.c:9:
../include/linux/hugetlb.h: In function ‘vma_hugecache_offset’:
../include/linux/hugetlb.h:1214:16: error: implicit declaration of function ‘linear_page_index’ [-Wimplicit-function-declaration]
1214 | return linear_page_index(vma, address);
| ^~~~~~~~~~~~~~~~~
Signed-off-by: SeongJae Park <sj@kernel.org>
---
include/linux/hugetlb.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 3f994f3e839cf..63426bd716839 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -15,6 +15,7 @@
#include <linux/gfp.h>
#include <linux/userfaultfd_k.h>
#include <linux/nodemask.h>
+#include <linux/pagemap.h>
struct mmu_gather;
struct node;
--
2.47.3
next prev parent reply other threads:[~2026-03-07 3:28 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-06 14:03 [PATCH] mm/userfaultfd: fix hugetlb fault mutex hash calculation Jianhui Zhou
2026-03-06 16:53 ` Peter Xu
2026-03-07 13:37 ` 周建辉
2026-03-07 13:59 ` Jianhui Zhou
2026-03-07 3:27 ` SeongJae Park [this message]
2026-03-08 13:41 ` Jianhui Zhou
2026-03-08 22:57 ` SeongJae Park
2026-03-07 14:35 ` [PATCH v2] " Jianhui Zhou
2026-03-09 2:08 ` Hugh Dickins
2026-03-09 3:08 ` Jianhui Zhou
2026-03-09 16:47 ` David Hildenbrand (Arm)
2026-03-10 10:24 ` Jianhui Zhou
2026-03-09 3:30 ` [PATCH v3] " Jianhui Zhou
2026-03-10 11:05 ` [PATCH v4] " Jianhui Zhou
2026-03-10 19:47 ` jane.chu
2026-03-11 10:54 ` Jianhui Zhou
2026-03-25 0:03 ` Andrew Morton
2026-03-25 1:06 ` SeongJae Park
2026-03-25 6:07 ` Jianhui Zhou
2026-03-25 8:49 ` David Hildenbrand (Arm)
2026-03-25 19:08 ` Mike Rapoport
2026-03-25 8:49 ` David Hildenbrand (Arm)
2026-03-25 19:02 ` Mike Rapoport
2026-03-25 23:46 ` jane.chu
2026-03-26 9:18 ` David Hildenbrand (Arm)
2026-03-25 19:10 ` Mike Rapoport
-- strict thread matches above, loose matches on Subject: below --
2026-03-06 13:59 [PATCH] " Jianhui Zhou
2026-03-06 13:51 Jianhui Zhou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260307032759.100915-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=jianhuizzzzz@gmail.com \
--cc=jonaszhou@zhaoxin.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=peterx@redhat.com \
--cc=rppt@kernel.org \
--cc=stable@vger.kernel.org \
--cc=syzbot+f525fd79634858f478e7@syzkaller.appspotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.