* [PATCH v2] mm/hugetlb: fix copy_hugetlb_page_range() to use ->pt_share_count
@ 2025-09-10 19:27 Jane Chu
2025-09-11 8:17 ` David Hildenbrand
0 siblings, 1 reply; 5+ messages in thread
From: Jane Chu @ 2025-09-10 19:27 UTC (permalink / raw)
To: harry.yoo, osalvador, liushixin2, muchun.song, david, akpm,
jannh, linux-mm, linux-kernel
commit 59d9094df3d79 ("mm: hugetlb: independent PMD page table shared count")
introduced ->pt_share_count dedicated to hugetlb PMD share count tracking,
but omitted fixing copy_hugetlb_page_range(), leaving the function relying on
page_count() for tracking that no longer works.
When lazy page table copy for hugetlb is disabled, that is, revert
commit bcd51a3c679d ("hugetlb: lazy page table copies in fork()")
fork()'ing with hugetlb PMD sharing quickly lockup -
[ 239.446559] watchdog: BUG: soft lockup - CPU#75 stuck for 27s!
[ 239.446611] RIP: 0010:native_queued_spin_lock_slowpath+0x7e/0x2e0
[ 239.446631] Call Trace:
[ 239.446633] <TASK>
[ 239.446636] _raw_spin_lock+0x3f/0x60
[ 239.446639] copy_hugetlb_page_range+0x258/0xb50
[ 239.446645] copy_page_range+0x22b/0x2c0
[ 239.446651] dup_mmap+0x3e2/0x770
[ 239.446654] dup_mm.constprop.0+0x5e/0x230
[ 239.446657] copy_process+0xd17/0x1760
[ 239.446660] kernel_clone+0xc0/0x3e0
[ 239.446661] __do_sys_clone+0x65/0xa0
[ 239.446664] do_syscall_64+0x82/0x930
[ 239.446668] ? count_memcg_events+0xd2/0x190
[ 239.446671] ? syscall_trace_enter+0x14e/0x1f0
[ 239.446676] ? syscall_exit_work+0x118/0x150
[ 239.446677] ? arch_exit_to_user_mode_prepare.constprop.0+0x9/0xb0
[ 239.446681] ? clear_bhb_loop+0x30/0x80
[ 239.446684] ? clear_bhb_loop+0x30/0x80
[ 239.446686] entry_SYSCALL_64_after_hwframe+0x76/0x7e
There are two options to resolve the potential latent issue:
1. warn against PMD sharing in copy_hugetlb_page_range(),
2. fix it.
This patch opts for the second option.
Fixes: 59d9094df3d79 ("mm: hugetlb: independent PMD page table shared count")
Signed-off-by: Jane Chu <jane.chu@oracle.com>
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
---
mm/hugetlb.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 753f99b4c718..8ca5b4f7805f 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5594,18 +5594,13 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
break;
}
- /*
- * If the pagetables are shared don't copy or take references.
- *
- * dst_pte == src_pte is the common case of src/dest sharing.
- * However, src could have 'unshared' and dst shares with
- * another vma. So page_count of ptep page is checked instead
- * to reliably determine whether pte is shared.
- */
- if (page_count(virt_to_page(dst_pte)) > 1) {
+#ifdef CONFIG_HUGETLB_PMD_PAGE_TABLE_SHARING
+ /* If the pagetables are shared don't copy or take references. */
+ if (ptdesc_pmd_pts_count(virt_to_ptdesc(dst_pte)) > 0) {
addr |= last_addr_mask;
continue;
}
+#endif
dst_ptl = huge_pte_lock(h, dst, dst_pte);
src_ptl = huge_pte_lockptr(h, src, src_pte);
--
2.43.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] mm/hugetlb: fix copy_hugetlb_page_range() to use ->pt_share_count
2025-09-10 19:27 [PATCH v2] mm/hugetlb: fix copy_hugetlb_page_range() to use ->pt_share_count Jane Chu
@ 2025-09-11 8:17 ` David Hildenbrand
2025-09-11 19:58 ` jane.chu
0 siblings, 1 reply; 5+ messages in thread
From: David Hildenbrand @ 2025-09-11 8:17 UTC (permalink / raw)
To: Jane Chu, harry.yoo, osalvador, liushixin2, muchun.song, akpm,
jannh, linux-mm, linux-kernel
On 10.09.25 21:27, Jane Chu wrote:
> commit 59d9094df3d79 ("mm: hugetlb: independent PMD page table shared count")
> introduced ->pt_share_count dedicated to hugetlb PMD share count tracking,
> but omitted fixing copy_hugetlb_page_range(), leaving the function relying on
> page_count() for tracking that no longer works.
>
> When lazy page table copy for hugetlb is disabled, that is, revert
> commit bcd51a3c679d ("hugetlb: lazy page table copies in fork()")
> fork()'ing with hugetlb PMD sharing quickly lockup -
>
> [ 239.446559] watchdog: BUG: soft lockup - CPU#75 stuck for 27s!
> [ 239.446611] RIP: 0010:native_queued_spin_lock_slowpath+0x7e/0x2e0
> [ 239.446631] Call Trace:
> [ 239.446633] <TASK>
> [ 239.446636] _raw_spin_lock+0x3f/0x60
> [ 239.446639] copy_hugetlb_page_range+0x258/0xb50
> [ 239.446645] copy_page_range+0x22b/0x2c0
> [ 239.446651] dup_mmap+0x3e2/0x770
> [ 239.446654] dup_mm.constprop.0+0x5e/0x230
> [ 239.446657] copy_process+0xd17/0x1760
> [ 239.446660] kernel_clone+0xc0/0x3e0
> [ 239.446661] __do_sys_clone+0x65/0xa0
> [ 239.446664] do_syscall_64+0x82/0x930
> [ 239.446668] ? count_memcg_events+0xd2/0x190
> [ 239.446671] ? syscall_trace_enter+0x14e/0x1f0
> [ 239.446676] ? syscall_exit_work+0x118/0x150
> [ 239.446677] ? arch_exit_to_user_mode_prepare.constprop.0+0x9/0xb0
> [ 239.446681] ? clear_bhb_loop+0x30/0x80
> [ 239.446684] ? clear_bhb_loop+0x30/0x80
> [ 239.446686] entry_SYSCALL_64_after_hwframe+0x76/0x7e
>
> There are two options to resolve the potential latent issue:
> 1. warn against PMD sharing in copy_hugetlb_page_range(),
> 2. fix it.
> This patch opts for the second option.
>
> Fixes: 59d9094df3d79 ("mm: hugetlb: independent PMD page table shared count")
> Signed-off-by: Jane Chu <jane.chu@oracle.com>
> Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
> ---
> mm/hugetlb.c | 13 ++++---------
> 1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 753f99b4c718..8ca5b4f7805f 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -5594,18 +5594,13 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
> break;
> }
>
> - /*
> - * If the pagetables are shared don't copy or take references.
> - *
> - * dst_pte == src_pte is the common case of src/dest sharing.
> - * However, src could have 'unshared' and dst shares with
> - * another vma. So page_count of ptep page is checked instead
> - * to reliably determine whether pte is shared.
> - */
I think you ignored my question to v1 regarding the change of comment.
--
Cheers
David / dhildenb
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] mm/hugetlb: fix copy_hugetlb_page_range() to use ->pt_share_count
2025-09-11 8:17 ` David Hildenbrand
@ 2025-09-11 19:58 ` jane.chu
2025-09-12 7:32 ` David Hildenbrand
0 siblings, 1 reply; 5+ messages in thread
From: jane.chu @ 2025-09-11 19:58 UTC (permalink / raw)
To: David Hildenbrand, harry.yoo, osalvador, liushixin2, muchun.song,
akpm, jannh, linux-mm, linux-kernel
On 9/11/2025 1:17 AM, David Hildenbrand wrote:
[..]
>>
>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
>> index 753f99b4c718..8ca5b4f7805f 100644
>> --- a/mm/hugetlb.c
>> +++ b/mm/hugetlb.c
>> @@ -5594,18 +5594,13 @@ int copy_hugetlb_page_range(struct mm_struct
>> *dst, struct mm_struct *src,
>> break;
>> }
>> - /*
>> - * If the pagetables are shared don't copy or take references.
>> - *
>> - * dst_pte == src_pte is the common case of src/dest sharing.
>> - * However, src could have 'unshared' and dst shares with
>> - * another vma. So page_count of ptep page is checked instead
>> - * to reliably determine whether pte is shared.
>> - */
>
> I think you ignored my question to v1 regarding the change of comment.
>
Sorry David, didn't mean disrespect, I missed your earlier comments.
I just replied.
Thanks,
-jane
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] mm/hugetlb: fix copy_hugetlb_page_range() to use ->pt_share_count
2025-09-11 19:58 ` jane.chu
@ 2025-09-12 7:32 ` David Hildenbrand
2025-09-15 16:52 ` jane.chu
0 siblings, 1 reply; 5+ messages in thread
From: David Hildenbrand @ 2025-09-12 7:32 UTC (permalink / raw)
To: jane.chu, harry.yoo, osalvador, liushixin2, muchun.song, akpm,
jannh, linux-mm, linux-kernel
On 11.09.25 21:58, jane.chu@oracle.com wrote:
>
>
> On 9/11/2025 1:17 AM, David Hildenbrand wrote:
> [..]
>>>
>>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
>>> index 753f99b4c718..8ca5b4f7805f 100644
>>> --- a/mm/hugetlb.c
>>> +++ b/mm/hugetlb.c
>>> @@ -5594,18 +5594,13 @@ int copy_hugetlb_page_range(struct mm_struct
>>> *dst, struct mm_struct *src,
>>> break;
>>> }
>>> - /*
>>> - * If the pagetables are shared don't copy or take references.
>>> - *
>>> - * dst_pte == src_pte is the common case of src/dest sharing.
>>> - * However, src could have 'unshared' and dst shares with
>>> - * another vma. So page_count of ptep page is checked instead
>>> - * to reliably determine whether pte is shared.
>>> - */
>>
>> I think you ignored my question to v1 regarding the change of comment.
>>
>
> Sorry David, didn't mean disrespect, I missed your earlier comments.
No worries. Replied there about possibly simplifying the comment further.
BTW, I think the code would be even clearer if we would have
ptdesc_pmd_is_shared()
that is simply a wrapper around the ptdesc_pmd_pts_count() check.
--
Cheers
David / dhildenb
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] mm/hugetlb: fix copy_hugetlb_page_range() to use ->pt_share_count
2025-09-12 7:32 ` David Hildenbrand
@ 2025-09-15 16:52 ` jane.chu
0 siblings, 0 replies; 5+ messages in thread
From: jane.chu @ 2025-09-15 16:52 UTC (permalink / raw)
To: David Hildenbrand, harry.yoo, osalvador, liushixin2, muchun.song,
akpm, jannh, linux-mm, linux-kernel
On 9/12/2025 12:32 AM, David Hildenbrand wrote:
> On 11.09.25 21:58, jane.chu@oracle.com wrote:
>>
>>
>> On 9/11/2025 1:17 AM, David Hildenbrand wrote:
>> [..]
>>>>
>>>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
>>>> index 753f99b4c718..8ca5b4f7805f 100644
>>>> --- a/mm/hugetlb.c
>>>> +++ b/mm/hugetlb.c
>>>> @@ -5594,18 +5594,13 @@ int copy_hugetlb_page_range(struct mm_struct
>>>> *dst, struct mm_struct *src,
>>>> break;
>>>> }
>>>> - /*
>>>> - * If the pagetables are shared don't copy or take references.
>>>> - *
>>>> - * dst_pte == src_pte is the common case of src/dest sharing.
>>>> - * However, src could have 'unshared' and dst shares with
>>>> - * another vma. So page_count of ptep page is checked instead
>>>> - * to reliably determine whether pte is shared.
>>>> - */
>>>
>>> I think you ignored my question to v1 regarding the change of comment.
>>>
>>
>> Sorry David, didn't mean disrespect, I missed your earlier comments.
>
> No worries. Replied there about possibly simplifying the comment further.
>
> BTW, I think the code would be even clearer if we would have
>
> ptdesc_pmd_is_shared()
>
> that is simply a wrapper around the ptdesc_pmd_pts_count() check.
Agreed, will add ptdesc_pmd_is_shared().
thanks a lot!
-jane>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-09-15 16:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-10 19:27 [PATCH v2] mm/hugetlb: fix copy_hugetlb_page_range() to use ->pt_share_count Jane Chu
2025-09-11 8:17 ` David Hildenbrand
2025-09-11 19:58 ` jane.chu
2025-09-12 7:32 ` David Hildenbrand
2025-09-15 16:52 ` jane.chu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox