From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B835834252C for ; Mon, 20 Apr 2026 14:59:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776697141; cv=none; b=JS2SnL/YuhI0fqPM7eIE9lUK2ydJj1SvnAHCKmoslY+hABJpQnnUqzp9l2SA1NnPdw5xx5tAtUE7z4jOcYQggCyTmfNzwWZxTl+s5GqJ2KKVEtrX89guzh1O0qX4IghB5qrJXuvsUaqy0C9XY42ZI66+NdGy5tFBRGl12qyU7bU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776697141; c=relaxed/simple; bh=qwH2y8AOpJCUqW/8zoInSHYPzg/EdBpkgUTr/amh8Ko=; h=Subject:To:Cc:From:Date:Message-ID:MIME-Version:Content-Type; b=aESxvYzKFUiRTi9WEJyKy5ztvrtRbjdbiwzN7KPCYuT0AW6i/tTfsr3hJDw+UjXhFJ2sr7nDE26ircrbVeRmvoSJNV2qgmBJdK2v2E42daCg+AVRDvWDYqh1yCtDmtnObs0Clu6NhZfh4HoM4u2J9m5UTZG7lvHk7HTSNnN8FWc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=VBlNqObr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="VBlNqObr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D27FC19425; Mon, 20 Apr 2026 14:59:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1776697141; bh=qwH2y8AOpJCUqW/8zoInSHYPzg/EdBpkgUTr/amh8Ko=; h=Subject:To:Cc:From:Date:From; b=VBlNqObr8kEXeJPdSRa0NYkNg9KIQaQxdturQgiCGy1mLP1UucLKvt8IhT+iZ/8pz 1i8Ch0m/tzGN8BhlVBdP8fkrnXs+Ky2HTdcPScnvzd4YarsJ+32kGR9Mdqk6awFg1c dOtQ/S5/iw587eMf77uKmLc7dhTiHqhMSJFVQr+o= Subject: FAILED: patch "[PATCH] mm/userfaultfd: fix hugetlb fault mutex hash calculation" failed to apply to 6.12-stable tree To: jianhuizzzzz@gmail.com,JonasZhou@zhaoxin.com,aarcange@redhat.com,akpm@linux-foundation.org,david@kernel.org,hughd@google.com,jane.chu@oracle.com,muchun.song@linux.dev,osalvador@suse.de,peterx@redhat.com,rppt@kernel.org,sidhartha.kumar@oracle.com,sj@kernel.org,stable@vger.kernel.org Cc: From: Date: Mon, 20 Apr 2026 16:58:07 +0200 Message-ID: <2026042007-casually-unaligned-fc88@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.12-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y git checkout FETCH_HEAD git cherry-pick -x 0217c7fb4de4a40cee667eb21901f3204effe5ac # git commit -s git send-email --to '' --in-reply-to '2026042007-casually-unaligned-fc88@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^.. Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 0217c7fb4de4a40cee667eb21901f3204effe5ac Mon Sep 17 00:00:00 2001 From: Jianhui Zhou Date: Tue, 10 Mar 2026 19:05:26 +0800 Subject: [PATCH] mm/userfaultfd: fix hugetlb fault mutex hash calculation 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. 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 introducing hugetlb_linear_page_index(), which returns the page index in huge page granularity, and using it in place of linear_page_index(). Link: https://lkml.kernel.org/r/20260310110526.335749-1-jianhuizzzzz@gmail.com Fixes: a08c7193e4f1 ("mm/filemap: remove hugetlb special casing in filemap.c") Signed-off-by: Jianhui Zhou Reported-by: syzbot+f525fd79634858f478e7@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=f525fd79634858f478e7 Acked-by: SeongJae Park Reviewed-by: David Hildenbrand (Arm) Acked-by: Mike Rapoport (Microsoft) Cc: Jane Chu Cc: Andrea Arcangeli Cc: Hugh Dickins Cc: JonasZhou Cc: Muchun Song Cc: Oscar Salvador Cc: Peter Xu Cc: SeongJae Park Cc: Sidhartha Kumar Cc: Signed-off-by: Andrew Morton diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index aaf3d472e6b5..9c098a02a09e 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -792,6 +792,23 @@ static inline unsigned huge_page_shift(struct hstate *h) return h->order + PAGE_SHIFT; } +/** + * hugetlb_linear_page_index() - linear_page_index() but in hugetlb + * page size granularity. + * @vma: the hugetlb VMA + * @address: the virtual address within the VMA + * + * Return: the page offset within the mapping in huge page units. + */ +static inline pgoff_t hugetlb_linear_page_index(struct vm_area_struct *vma, + unsigned long address) +{ + struct hstate *h = hstate_vma(vma); + + return ((address - vma->vm_start) >> huge_page_shift(h)) + + (vma->vm_pgoff >> huge_page_order(h)); +} + static inline bool order_is_gigantic(unsigned int order) { return order > MAX_PAGE_ORDER; diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index e19872e51878..2c565c7134b6 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -573,7 +573,7 @@ static __always_inline ssize_t mfill_atomic_hugetlb( * in the case of shared pmds. fault mutex prevents * races with other faulting threads. */ - idx = linear_page_index(dst_vma, dst_addr); + idx = hugetlb_linear_page_index(dst_vma, dst_addr); mapping = dst_vma->vm_file->f_mapping; hash = hugetlb_fault_mutex_hash(mapping, idx); mutex_lock(&hugetlb_fault_mutex_table[hash]);