mm/gup: Minor fix, cleanup and improvements
Subsystems (9)
v2 cover mm/gup: Minor fix, cleanup and improvements
These are made when I explore codes in mm/gup.c.
v1->v2:
- In patch 1, I carelessly copied the fault_in_readable() as fault_in_writeable(). Thanks to Yanjun for pointing it out.
- In patch 2, I copied the code in follow_page_pte() to __get_user_pages() directly w/o adjustment which is done but not merged to patch. That failed testing taken by lkp test robot, thanks for reporting.
Baoquan He (7):
mm/gup: fix wrongly calculated returned value in
fault_in_safe_writeable()
mm/gup: check if both GUP_GET and GUP_PIN are set in
__get_user_pages() earlier
mm/gup: Fix the outdated code comments above get_user_pages_unlocked() mm/gup: remove gup_fast_pgd_leaf() and clean up the relevant codes x86/mm: remove pgd_leaf definition in arch
x86/mm: remove p4d_leaf definition
mm/pgtable: remove unneeded pgd_devmap()
arch/arm64/include/asm/pgtable.h | 5 -- arch/loongarch/include/asm/pgtable.h | 1 - arch/powerpc/include/asm/book3s/64/pgtable.h | 5 -- arch/riscv/include/asm/pgtable-64.h | 5 -- arch/x86/include/asm/pgtable.h | 15 ---- arch/x86/mm/pti.c | 4 +- include/linux/pgtable.h | 4 - mm/gup.c | 79 ++++---------------- 8 files changed, 15 insertions(+), 103 deletions(-)
Signature · 1 line
2.41.0
PATCH v2 1/7 mm/gup: fix wrongly calculated returned value in fault_in_safe_writeable()
Not like fault_in_readable() or fault_in_writeable(), in fault_in_safe_writeable() local variable 'start' is increased page by page to loop till the whole address range is handled. However, it mistakenly calcalates the size of handled range with 'uaddr - start'.
Fix it here.
---v1->v2:
- Fix a patch log typo caused by copy-and-paste error. Thanks to Yanjun.
mm/gup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/gup.c +2 -2
@@ -2207,8 +2207,8 @@ size_t fault_in_safe_writeable(const char __user *uaddr, size_t size) }while (start != end);mmap_read_unlock (mm); -if (size > (unsigned long )uaddr - start) -return size - ((unsigned long )uaddr - start); +if (size > start - (unsigned long )uaddr) +return size - (start - (unsigned long )uaddr);return 0 ; }EXPORT_SYMBOL (fault_in_safe_writeable);
Signature · 1 line
2.41.0
Re: [PATCH v2 1/7] mm/gup: fix wrongly calculated returned value in fault_in_safe_writeable()
Quoted 6 lines · Baoquan He
Not like
fault_in_readable()orfault_in_writeable(), infault_in_safe_writeable()local variable 'start' is increased page by page to loop till the whole address range is handled. However, it mistakenly calcalates the size of handled range with 'uaddr - start'.Fix it here.
Quoted 15 lines
Signed-off-by Baoquan He <[email protected]>---
v1->v2:
- Fix a patch log typo caused by copy-and-paste error. Thanks to Yanjun.mm/gup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/gup.c +0
-0
mm/gup.c size_t fault_in_safe_writeable(const char __user *uaddr, size_t size) · line 2214
Quoted 10 lines
mm/gup.c +2
-2@@ -2207,8 +2207,8 @@ size_t fault_in_safe_writeable(const char __user *uaddr, size_t size) }while (start != end);mmap_read_unlock (mm); -if (size > (unsigned long )uaddr - start) -return size - ((unsigned long )uaddr - start); +if (size > start - (unsigned long )uaddr) +return size - (start - (unsigned long )uaddr);return 0 ; }EXPORT_SYMBOL (fault_in_safe_writeable);
Can we instead just use the uaddr and start variables like in fault_in_readable?
That is, turn "start" into a const and adjust uaddr instead.
(maybe we should also handle the types of these variables similar to as in fault_in_readable)
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v2 1/7] mm/gup: fix wrongly calculated returned value in fault_in_safe_writeable()
Quoted 17 lines · David Hildenbrand
mm/gup.c size_t fault_in_safe_writeable(const char __user *uaddr, size_t size) · line 2213
Quoted 12 lines · Baoquan He
mm/gup.c +2
-2@@ -2207,8 +2207,8 @@ size_t fault_in_safe_writeable(const char __user *uaddr, size_t size) }while (start != end);mmap_read_unlock (mm); -if (size > (unsigned long )uaddr - start) -return size - ((unsigned long )uaddr - start); +if (size > start - (unsigned long )uaddr) +return size - (start - (unsigned long )uaddr);return 0 ; }EXPORT_SYMBOL (fault_in_safe_writeable);Can we instead just use the uaddr and start variables like in
fault_in_readable?
Quoted 1 line
That is, turn "start" into a const and adjust uaddr instead.
Yes, I think that would be much cleaner.
Otherwise, this looks good to me.
Signature · 2 lines
Oscar Salvador SUSE Labs
Re: [PATCH v2 1/7] mm/gup: fix wrongly calculated returned value in fault_in_safe_writeable()
Quoted 18 lines · Oscar Salvador
Quoted 17 lines · David Hildenbrand
mm/gup.c size_t fault_in_safe_writeable(const char __user *uaddr, size_t size) · line 2213
Quoted 12 lines · Baoquan He
mm/gup.c +2
-2@@ -2207,8 +2207,8 @@ size_t fault_in_safe_writeable(const char __user *uaddr, size_t size) }while (start != end);mmap_read_unlock (mm); -if (size > (unsigned long )uaddr - start) -return size - ((unsigned long )uaddr - start); +if (size > start - (unsigned long )uaddr) +return size - (start - (unsigned long )uaddr);return 0 ; }EXPORT_SYMBOL (fault_in_safe_writeable);Can we instead just use the uaddr and start variables like in
fault_in_readable?
Quoted 5 lines
Quoted 1 line
That is, turn "start" into a const and adjust uaddr instead.
Yes, I think that would be much cleaner.
Otherwise, this looks good to me.
Will change in v3 as both of you suggested, thanks for reviewing this v2 series.
Re: [PATCH v2 1/7] mm/gup: fix wrongly calculated returned value in fault_in_safe_writeable()
In reply to David HildenbrandQuoted 9 lines · David Hildenbrand
Quoted 6 lines · Baoquan He
Not like
fault_in_readable()orfault_in_writeable(), infault_in_safe_writeable()local variable 'start' is increased page by page to loop till the whole address range is handled. However, it mistakenly calcalates the size of handled range with 'uaddr - start'.Fix it here.
Fixes ? Do we know of user-visible effects?
I believe it should impact, while I didn't hear of any complaint. Yeah, it's worth to have one Fixes.
Quoted 29 lines
Quoted 16 lines
Signed-off-by Baoquan He <[email protected]>---
v1->v2:
- Fix a patch log typo caused by copy-and-paste error. Thanks to Yanjun.mm/gup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)mm/gup.c +0
-0mm/gup.c size_t fault_in_safe_writeable(const char __user *uaddr, size_t size) · line 2213
Quoted 9 lines
mm/gup.c +2
-2@@ -2207,8 +2207,8 @@ size_t fault_in_safe_writeable(const char __user *uaddr, size_t size) }while (start != end);mmap_read_unlock (mm); -if (size > (unsigned long )uaddr - start) -return size - ((unsigned long )uaddr - start); +if (size > start - (unsigned long )uaddr) +return size - (start - (unsigned long )uaddr);return 0 ; }EXPORT_SYMBOL (fault_in_safe_writeable);Can we instead just use the uaddr and start variables like in
fault_in_readable?
Quoted 1 line
That is, turn "start" into a const and adjust uaddr instead.
Sounds good to me, that makes these similar blocks own consistent code style. Will change in v3. Thanks for reviewing.
Quoted 9 lines
(maybe we should also handle the types of these variables similar to as in
fault_in_readable)Signature · 3 lines
Cheers, David / dhildenb
PATCH v2 2/7 mm/gup: check if both GUP_GET and GUP_PIN are set in __get_user_pages() earlier
In reply to Baoquan HeIn __get_user_pages(), it will traverse page table and take a reference to the page the given user address corresponds to if GUP_GET or GUP_PIN is et. However, it's not supported both GUP_GET and GUP_PIN are set. This check should be done earlier, but not doing it till entering into follow_page_pte() and failed.
Here move the checking to the beginning of __get_user_pages().
---v1->v2:
- Fix code bug caused by copy-and-paste error, this is reported by lkp test robot.
mm/gup.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
mm/gup.c +5 -5
@@ -847,11 +847,6 @@ static struct page *follow_page_pte(struct vm_area_struct *vma,pte_t *ptep, pte;int ret; -/* FOLL_GET and FOLL_PIN are mutually exclusive. */ -if (WARN_ON_ONCE ((flags & (FOLL_PIN |FOLL_GET )) == - (FOLL_PIN |FOLL_GET ))) -return ERR_PTR (-EINVAL ); - ptep =pte_offset_map_lock (mm, pmd, address, &ptl);if (!ptep)return no_page_table (vma, flags, address);
@@ -1434,6 +1429,11 @@ static long __get_user_pages(struct mm_struct *mm,VM_BUG_ON (!!pages != !!(gup_flags & (FOLL_GET |FOLL_PIN ))); +/* FOLL_GET and FOLL_PIN are mutually exclusive. */ +if (WARN_ON_ONCE ((gup_flags & (FOLL_PIN |FOLL_GET )) == + (FOLL_PIN |FOLL_GET ))) +return -EINVAL ; + do { struct page *page; unsigned int page_increm;
Signature · 1 line
2.41.0
Re: [PATCH v2 2/7] mm/gup: check if both GUP_GET and GUP_PIN are set in __get_user_pages() earlier
Quoted 34 lines · Baoquan He
In
__get_user_pages(), it will traverse page table and take a reference to the page the given user address corresponds to ifGUP_GETorGUP_PINis et. However, it's not supported bothGUP_GETandGUP_PINare set. This check should be done earlier, but not doing it till entering intofollow_page_pte()and failed.Here move the checking to the beginning of
__get_user_pages().Signed-off-by Baoquan He <[email protected]>---
v1->v2:
- Fix code bug caused by copy-and-paste error, this is reported by lkp test robot.mm/gup.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)mm/gup.c +0
-5@@ -847,11 +847,6 @@ static struct page *follow_page_pte(struct vm_area_struct *vma,pte_t *ptep, pte;int ret; -/* FOLL_GET and FOLL_PIN are mutually exclusive. */ -if (WARN_ON_ONCE ((flags & (FOLL_PIN |FOLL_GET )) == - (FOLL_PIN |FOLL_GET ))) -return ERR_PTR (-EINVAL ); - ptep =pte_offset_map_lock (mm, pmd, address, &ptl);if (!ptep)return no_page_table (vma, flags, address);
mm/gup.c static long __get_user_pages(struct mm_struct *mm, · line 1436
Quoted 8 lines
mm/gup.c +5
-0@@ -1434,6 +1429,11 @@ static long __get_user_pages(struct mm_struct *mm,VM_BUG_ON (!!pages != !!(gup_flags & (FOLL_GET |FOLL_PIN ))); +/* FOLL_GET and FOLL_PIN are mutually exclusive. */ +if (WARN_ON_ONCE ((gup_flags & (FOLL_PIN |FOLL_GET )) == + (FOLL_PIN |FOLL_GET ))) +return -EINVAL ; +
We already have that check in is_valid_gup_args(), that catches all external users that could possibly mess this up.
So we can just convert that into a VM_WARN_ON_ONCE(), and while doing that, we should convert the VM_BUG_ON() above to a VM_WARN_ON_ONCE() as well.
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v2 2/7] mm/gup: check if both GUP_GET and GUP_PIN are set in __get_user_pages() earlier
Quoted 35 lines · David Hildenbrand
Quoted 34 lines · Baoquan He
In
__get_user_pages(), it will traverse page table and take a reference to the page the given user address corresponds to ifGUP_GETorGUP_PINis et. However, it's not supported bothGUP_GETandGUP_PINare set. This check should be done earlier, but not doing it till entering intofollow_page_pte()and failed.Here move the checking to the beginning of
__get_user_pages().Signed-off-by Baoquan He <[email protected]>---
v1->v2:
- Fix code bug caused by copy-and-paste error, this is reported by lkp test robot.mm/gup.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)mm/gup.c +0
-5@@ -847,11 +847,6 @@ static struct page *follow_page_pte(struct vm_area_struct *vma,pte_t *ptep, pte;int ret; -/* FOLL_GET and FOLL_PIN are mutually exclusive. */ -if (WARN_ON_ONCE ((flags & (FOLL_PIN |FOLL_GET )) == - (FOLL_PIN |FOLL_GET ))) -return ERR_PTR (-EINVAL ); - ptep =pte_offset_map_lock (mm, pmd, address, &ptl);if (!ptep)return no_page_table (vma, flags, address);@@ -1434,6 +1429,11 @@ static long __get_user_pages(struct mm_struct *mm,VM_BUG_ON (!!pages != !!(gup_flags & (FOLL_GET |FOLL_PIN )));
Quoted 8 lines
mm/gup.c static long __get_user_pages(struct mm_struct *mm, · line 1434
Quoted 5 lines
mm/gup.c +5
-0+/* FOLL_GET and FOLL_PIN are mutually exclusive. */ +if (WARN_ON_ONCE ((gup_flags & (FOLL_PIN |FOLL_GET )) == + (FOLL_PIN |FOLL_GET ))) +return -EINVAL ; +We already have that check in
is_valid_gup_args(), that catches all external users that could possibly mess this up.
Right.
Quoted 3 lines
So we can just convert that into a
VM_WARN_ON_ONCE(), and while doing that, we should convert theVM_BUG_ON()above to aVM_WARN_ON_ONCE()as well.
Sounds great to me, will put below change into this patch of v3 as suggested. Thanks.
mm/gup.c +2 -2
@@ -1427,10 +1427,10 @@ static long __get_user_pages(struct mm_struct *mm, start =untagged_addr_remote (mm, start); -VM_BUG_ON (!!pages != !!(gup_flags & (FOLL_GET |FOLL_PIN ))); +VM_WARN_ON_ONCE (!!pages != !!(gup_flags & (FOLL_GET |FOLL_PIN )));/* FOLL_GET and FOLL_PIN are mutually exclusive. */ -if (WARN_ON_ONCE ((gup_flags & (FOLL_PIN |FOLL_GET )) == +if (VM_WARN_ON_ONCE ((gup_flags & (FOLL_PIN |FOLL_GET )) == (FOLL_PIN |FOLL_GET )))return -EINVAL ;
Re: [PATCH v2 2/7] mm/gup: check if both GUP_GET and GUP_PIN are set in __get_user_pages() earlier
Quoted 59 lines · Baoquan He
Quoted 35 lines · David Hildenbrand
Quoted 34 lines · Baoquan He
In
__get_user_pages(), it will traverse page table and take a reference to the page the given user address corresponds to ifGUP_GETorGUP_PINis et. However, it's not supported bothGUP_GETandGUP_PINare set. This check should be done earlier, but not doing it till entering intofollow_page_pte()and failed.Here move the checking to the beginning of
__get_user_pages().Signed-off-by Baoquan He <[email protected]>---
v1->v2:
- Fix code bug caused by copy-and-paste error, this is reported by lkp test robot.mm/gup.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)mm/gup.c +0
-5@@ -847,11 +847,6 @@ static struct page *follow_page_pte(struct vm_area_struct *vma,pte_t *ptep, pte;int ret; -/* FOLL_GET and FOLL_PIN are mutually exclusive. */ -if (WARN_ON_ONCE ((flags & (FOLL_PIN |FOLL_GET )) == - (FOLL_PIN |FOLL_GET ))) -return ERR_PTR (-EINVAL ); - ptep =pte_offset_map_lock (mm, pmd, address, &ptl);if (!ptep)return no_page_table (vma, flags, address);@@ -1434,6 +1429,11 @@ static long __get_user_pages(struct mm_struct *mm,VM_BUG_ON (!!pages != !!(gup_flags & (FOLL_GET |FOLL_PIN )));Quoted 8 lines
mm/gup.c static long __get_user_pages(struct mm_struct *mm, · line 1434
Quoted 5 lines
mm/gup.c +5
-0+/* FOLL_GET and FOLL_PIN are mutually exclusive. */ +if (WARN_ON_ONCE ((gup_flags & (FOLL_PIN |FOLL_GET )) == + (FOLL_PIN |FOLL_GET ))) +return -EINVAL ; +We already have that check in
is_valid_gup_args(), that catches all external users that could possibly mess this up.Right.
Quoted 3 lines
So we can just convert that into a
VM_WARN_ON_ONCE(), and while doing that, we should convert theVM_BUG_ON()above to aVM_WARN_ON_ONCE()as well.Sounds great to me, will put below change into this patch of v3 as suggested. Thanks.
mm/gup.c +0
-0
mm/gup.c static long __get_user_pages(struct mm_struct *mm, · line 1434
Quoted 10 lines
mm/gup.c +2
-2@@ -1427,10 +1427,10 @@ static long __get_user_pages(struct mm_struct *mm, start =untagged_addr_remote (mm, start); -VM_BUG_ON (!!pages != !!(gup_flags & (FOLL_GET |FOLL_PIN ))); +VM_WARN_ON_ONCE (!!pages != !!(gup_flags & (FOLL_GET |FOLL_PIN )));/* FOLL_GET and FOLL_PIN are mutually exclusive. */ -if (WARN_ON_ONCE ((gup_flags & (FOLL_PIN |FOLL_GET )) == +if (VM_WARN_ON_ONCE ((gup_flags & (FOLL_PIN |FOLL_GET )) == (FOLL_PIN |FOLL_GET )))
That won't work (or shouldn't work :) ). Just drop the handling, it's a sanity check we don't expect to ever trigger, just like the old VM_BUG_ON above.
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v2 2/7] mm/gup: check if both GUP_GET and GUP_PIN are set in __get_user_pages() earlier
Quoted 3 lines · David Hildenbrand
Quoted 2 lines · Baoquan He
Quoted 1 line · David Hildenbrand
On 31.03.25 10:13, Baoquan He wrote:
...snip...
Quoted 12 lines
Quoted 12 lines
Quoted 2 lines
We already have that check in
is_valid_gup_args(), that catches all external users that could possibly mess this up.Right.
Quoted 3 lines
So we can just convert that into a
VM_WARN_ON_ONCE(), and while doing that, we should convert theVM_BUG_ON()above to aVM_WARN_ON_ONCE()as well.Sounds great to me, will put below change into this patch of v3 as suggested. Thanks.
Quoted 16 lines
mm/gup.c static long __get_user_pages(struct mm_struct *mm, · line 1431
Quoted 12 lines
mm/gup.c +2
-2@@ -1427,10 +1427,10 @@ static long __get_user_pages(struct mm_struct *mm, start =untagged_addr_remote (mm, start); -VM_BUG_ON (!!pages != !!(gup_flags & (FOLL_GET |FOLL_PIN ))); +VM_WARN_ON_ONCE (!!pages != !!(gup_flags & (FOLL_GET |FOLL_PIN )));/* FOLL_GET and FOLL_PIN are mutually exclusive. */ -if (WARN_ON_ONCE ((gup_flags & (FOLL_PIN |FOLL_GET )) == +if (VM_WARN_ON_ONCE ((gup_flags & (FOLL_PIN |FOLL_GET )) == (FOLL_PIN |FOLL_GET )))That won't work (or shouldn't work :) ). Just drop the handling, it's a sanity check we don't expect to ever trigger, just like the old
VM_BUG_ONabove.
Ah, I misunderstood it. Will add below change into this patch of v3.
mm/gup.c +3 -6
@@ -1427,12 +1427,9 @@ static long __get_user_pages(struct mm_struct *mm, start =untagged_addr_remote (mm, start); -VM_BUG_ON (!!pages != !!(gup_flags & (FOLL_GET |FOLL_PIN ))); - -/* FOLL_GET and FOLL_PIN are mutually exclusive. */ -if (WARN_ON_ONCE ((gup_flags & (FOLL_PIN |FOLL_GET )) == - (FOLL_PIN |FOLL_GET ))) -return -EINVAL ; +VM_WARN_ON_ONCE (!!pages != !!(gup_flags & (FOLL_GET |FOLL_PIN ))); +VM_WARN_ON_ONCE ((gup_flags & (FOLL_PIN |FOLL_GET )) == + (FOLL_PIN |FOLL_GET )); do { struct page *page;
PATCH v2 3/7 mm/gup: Fix the outdated code comments above get_user_pages_unlocked()
In reply to Baoquan HeSince commit f0818f472d8d ("mm: gup: add get_user_pages_locked and get_user_pages_unlocked"), get_user_pages() doesn't need to have mmap_lock held anymore. It calls __get_user_pages_locked() which can acquire and drop the mmap_lock internaly.
Hence remove the incorrect code comments now.
--- mm/gup.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
mm/gup.c +3 -13
@@ -2702,19 +2702,9 @@ long get_user_pages(unsigned long start, unsigned long nr_pages,EXPORT_SYMBOL (get_user_pages);/* -* get_user_pages_unlocked() is suitable to replace the form: -* -* mmap_read_lock(mm); -* get_user_pages(mm, ..., pages, NULL); -* mmap_read_unlock(mm); -* -* with: -* -* get_user_pages_unlocked(mm, ..., pages); -* -* It is functionally equivalent to get_user_pages_fast so -* get_user_pages_fast should be used instead if specific gup_flags -* (e.g. FOLL_FORCE) are not required. +* get_user_pages_unlocked() is functionally equivalent to +* get_user_pages_fast so get_user_pages_fast should be used instead +* if specific gup_flags (e.g. FOLL_FORCE) are not required. */ long get_user_pages_unlocked (unsigned long start,unsigned long nr_pages,struct page **pages,unsigned int gup_flags)
Signature · 1 line
2.41.0
Re: [PATCH v2 3/7] mm/gup: Fix the outdated code comments above get_user_pages_unlocked()
Quoted 4 lines · Baoquan He
Since commit
f0818f472d8d("mm: gup: addget_user_pages_lockedandget_user_pages_unlocked"),get_user_pages()doesn't need to havemmap_lockheld anymore. It calls__get_user_pages_locked()which can acquire and drop themmap_lockinternaly.
s/internaly/internally/
But your statement is wrong. get_user_pages() must be called with the mmap_lock held, because it sets "int locked = 1;" when calling __get_user_pages_locked().
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v2 3/7] mm/gup: Fix the outdated code comments above get_user_pages_unlocked()
Quoted 11 lines · David Hildenbrand
Quoted 4 lines · Baoquan He
Since commit
f0818f472d8d("mm: gup: addget_user_pages_lockedandget_user_pages_unlocked"),get_user_pages()doesn't need to havemmap_lockheld anymore. It calls__get_user_pages_locked()which can acquire and drop themmap_lockinternaly.s/internaly/internally/
But your statement is wrong.
get_user_pages()must be called with themmap_lockheld, because it sets "int locked = 1;" when calling__get_user_pages_locked().
You are right. I missed that line. Oscar pointed that out in v1 thread. I will drop this patch. Thanks.
Re: [PATCH v2 3/7] mm/gup: Fix the outdated code comments above get_user_pages_unlocked()
In reply to Baoquan HeQuoted 6 lines · Baoquan He
Since commit
f0818f472d8d("mm: gup: addget_user_pages_lockedandget_user_pages_unlocked"),get_user_pages()doesn't need to havemmap_lockheld anymore. It calls__get_user_pages_locked()which can acquire and drop themmap_lockinternaly.Hence remove the incorrect code comments now.
Uhm, I think this one should be dropped according to
https://lore.kernel.org/linux-mm/[email protected]/T/#m1aa161016ab98a6d85bcb657a729e01cb98763ec
?
Signature · 2 lines
Oscar Salvador SUSE Labs
Re: [PATCH v2 3/7] mm/gup: Fix the outdated code comments above get_user_pages_unlocked()
Quoted 9 lines · Oscar Salvador
Quoted 6 lines · Baoquan He
Since commit
f0818f472d8d("mm: gup: addget_user_pages_lockedandget_user_pages_unlocked"),get_user_pages()doesn't need to havemmap_lockheld anymore. It calls__get_user_pages_locked()which can acquire and drop themmap_lockinternaly.Hence remove the incorrect code comments now.
Uhm, I think this one should be dropped according to
Yeah, this v2 series was sent earlier than your comment in v1. Sorry about the mess.
Quoted 10 lines
https://lore.kernel.org/linux-mm/[email protected]/T/#m1aa161016ab98a6d85bcb657a729e01cb98763ec
?
Signature · 2 lines
Oscar Salvador SUSE Labs
PATCH v2 4/7 mm/gup: remove gup_fast_pgd_leaf() and clean up the relevant codes
In reply to Baoquan HeIn the current kernel, only pud huge page is supported in some architectures. P4d and pgd huge pages haven't been supported yet. And in mm/gup.c, there's no pgd huge page handling in the follow_page_mask() code path. Hence it doesn't make sense to have gup_fast_pgd_leaf() in gup_fast code path.
Here remove gup_fast_pgd_leaf() and clean up the relevant codes.
--- mm/gup.c | 49 +++---------------------------------------------- 1 file changed, 3 insertions(+), 46 deletions(-)
mm/gup.c +3 -46
@@ -3168,46 +3168,6 @@ static int gup_fast_pud_leaf(pud_t orig, pud_t *pudp, unsigned long addr,return 1 ; } -static int gup_fast_pgd_leaf (pgd_t orig,pgd_t *pgdp,unsigned long addr, -unsigned long end,unsigned int flags,struct page **pages, -int *nr) -{ -int refs; -struct page *page; -struct folio *folio; - -if (!pgd_access_permitted (orig, flags &FOLL_WRITE )) -return 0 ; - -BUILD_BUG_ON (pgd_devmap (orig)); - - page =pgd_page (orig); - refs =record_subpages (page,PGDIR_SIZE , addr, end, pages + *nr); - - folio =try_grab_folio_fast (page, refs, flags); -if (!folio) -return 0 ; - -if (unlikely (pgd_val (orig) !=pgd_val (*pgdp))) { -gup_put_folio (folio, refs, flags); -return 0 ; - } - -if (!pgd_write (orig) &&gup_must_unshare (NULL , flags, &folio->page)) { -gup_put_folio (folio, refs, flags); -return 0 ; - } - -if (!gup_fast_folio_allowed (folio, flags)) { -gup_put_folio (folio, refs, flags); -return 0 ; - } - - *nr += refs; -folio_set_referenced (folio); -return 1 ; -} -static int gup_fast_pmd_range (pud_t *pudp,pud_t pud,unsigned long addr,unsigned long end,unsigned int flags,struct page **pages,int *nr)
@@ -3302,12 +3262,9 @@ static void gup_fast_pgd_range(unsigned long addr, unsigned long end, next =pgd_addr_end (addr, end);if (pgd_none (pgd))return ; -if (unlikely (pgd_leaf (pgd))) { -if (!gup_fast_pgd_leaf (pgd, pgdp, addr, next, flags, - pages, nr)) -return ; - }else if (!gup_fast_p4d_range (pgdp, pgd, addr, next, flags, - pages, nr)) +BUILD_BUG_ON (pgd_leaf (pgd)); +if (!gup_fast_p4d_range (pgdp, pgd, addr, next, flags, + pages, nr))return ; }while (pgdp++, addr = next, addr != end); }
Signature · 1 line
2.41.0
Re: [PATCH v2 4/7] mm/gup: remove gup_fast_pgd_leaf() and clean up the relevant codes
Quoted 5 lines · Baoquan He
In the current kernel, only pud huge page is supported in some architectures. P4d and pgd huge pages haven't been supported yet. And in
mm/gup.c, there's no pgd huge page handling in thefollow_page_mask()code path. Hence it doesn't make sense to havegup_fast_pgd_leaf()ingup_fastcode path.
I wonder if that was in place to handle (prepare for) very large hugetlb folios. Until a while ago, follow_page_mask() did not have to handle these hugetlb folios.
But I assume it never got used.
Quoted 75 lines
Here remove
gup_fast_pgd_leaf()and clean up the relevant codes.Signed-off-by Baoquan He <[email protected]>--- mm/gup.c | 49 +++---------------------------------------------- 1 file changed, 3 insertions(+), 46 deletions(-)mm/gup.c +3
-46@@ -3168,46 +3168,6 @@ static int gup_fast_pud_leaf(pud_t orig, pud_t *pudp, unsigned long addr,return 1 ; } -static int gup_fast_pgd_leaf (pgd_t orig,pgd_t *pgdp,unsigned long addr, -unsigned long end,unsigned int flags,struct page **pages, -int *nr) -{ -int refs; -struct page *page; -struct folio *folio; - -if (!pgd_access_permitted (orig, flags &FOLL_WRITE )) -return 0 ; - -BUILD_BUG_ON (pgd_devmap (orig)); - - page =pgd_page (orig); - refs =record_subpages (page,PGDIR_SIZE , addr, end, pages + *nr); - - folio =try_grab_folio_fast (page, refs, flags); -if (!folio) -return 0 ; - -if (unlikely (pgd_val (orig) !=pgd_val (*pgdp))) { -gup_put_folio (folio, refs, flags); -return 0 ; - } - -if (!pgd_write (orig) &&gup_must_unshare (NULL , flags, &folio->page)) { -gup_put_folio (folio, refs, flags); -return 0 ; - } - -if (!gup_fast_folio_allowed (folio, flags)) { -gup_put_folio (folio, refs, flags); -return 0 ; - } - - *nr += refs; -folio_set_referenced (folio); -return 1 ; -} -static int gup_fast_pmd_range (pud_t *pudp,pud_t pud,unsigned long addr,unsigned long end,unsigned int flags,struct page **pages,int *nr)@@ -3302,12 +3262,9 @@ static void gup_fast_pgd_range(unsigned long addr, unsigned long end, next =pgd_addr_end (addr, end);if (pgd_none (pgd))return ; -if (unlikely (pgd_leaf (pgd))) { -if (!gup_fast_pgd_leaf (pgd, pgdp, addr, next, flags, - pages, nr)) -return ; - }else if (!gup_fast_p4d_range (pgdp, pgd, addr, next, flags, - pages, nr)) +BUILD_BUG_ON (pgd_leaf (pgd)); +if (!gup_fast_p4d_range (pgdp, pgd, addr, next, flags, + pages, nr))return ; }while (pgdp++, addr = next, addr != end); }
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v2 4/7] mm/gup: remove gup_fast_pgd_leaf() and clean up the relevant codes
In reply to Baoquan HeQuoted 9 lines · Baoquan He
In the current kernel, only pud huge page is supported in some architectures. P4d and pgd huge pages haven't been supported yet. And in
mm/gup.c, there's no pgd huge page handling in thefollow_page_mask()code path. Hence it doesn't make sense to havegup_fast_pgd_leaf()ingup_fastcode path.Here remove
gup_fast_pgd_leaf()and clean up the relevant codes.Signed-off-by Baoquan He <[email protected]>
Signature · 2 lines
Oscar Salvador SUSE Labs
PATCH v2 5/7 x86/mm: remove pgd_leaf definition in arch
In reply to Baoquan Hepgd huge page is not supported yet, let's use the generic definition in linux/pgtable.h.
And also update the BUILD_BUG_ON() checking for pgd_leaf() in pti_user_pagetable_walk_p4d() because pgd_leaf() returns boolean value.
--- arch/x86/include/asm/pgtable.h | 3 --- arch/x86/mm/pti.c | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-)
arch/x86/include/asm/pgtable.h +0 -3
@@ -1472,9 +1472,6 @@ static inline bool pgdp_maps_userspace(void *__ptr)return (((ptr & ~PAGE_MASK ) /sizeof (pgd_t)) <PGD_KERNEL_START ); } -#define pgd_leaf pgd_leaf -static inline bool pgd_leaf (pgd_t pgd) {return false; } -#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION /* * All top-level MITIGATION_PAGE_TABLE_ISOLATION page tables are order-1 pages
arch/x86/mm/pti.c +1 -1
@@ -185,7 +185,7 @@ static p4d_t *pti_user_pagetable_walk_p4d(unsigned long address)set_pgd (pgd,__pgd (_KERNPG_TABLE |__pa (new_p4d_page))); } -BUILD_BUG_ON (pgd_leaf (*pgd) !=0 ); +BUILD_BUG_ON (pgd_leaf (*pgd));return p4d_offset (pgd, address); }
Signature · 1 line
2.41.0
[tip: x86/mm] x86/mm: Simplify the pgd_leaf() and p4d_leaf() checks a bit
The following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: e62c7a4bd1d1e99e1ddd947cb526f833992c5bd4 Gitweb: https://git.kernel.org/tip/e62c7a4bd1d1e99e1ddd947cb526f833992c5bd4 Author: Baoquan He <[email protected]> AuthorDate: Mon, 31 Mar 2025 16:13:25 +08:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Mon, 31 Mar 2025 12:08:17 +02:00
x86/mm: Simplify the pgd_leaf() and p4d_leaf() checks a bit
The functions return bool, simplify the checks.
[ mingo: Split off from two other patches. ]
--- arch/x86/mm/pti.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/mm/pti.c +2 -2
@@ -185,7 +185,7 @@ static p4d_t *pti_user_pagetable_walk_p4d(unsigned long address)set_pgd (pgd,__pgd (_KERNPG_TABLE |__pa (new_p4d_page))); } -BUILD_BUG_ON (pgd_leaf (*pgd) !=0 ); +BUILD_BUG_ON (pgd_leaf (*pgd));return p4d_offset (pgd, address); }
@@ -206,7 +206,7 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long address)if (!p4d)return NULL ; -BUILD_BUG_ON (p4d_leaf (*p4d) !=0 ); +BUILD_BUG_ON (p4d_leaf (*p4d));if (p4d_none (*p4d)) {unsigned long new_pud_page =__get_free_page (gfp);if (WARN_ON_ONCE (!new_pud_page))
[tip: x86/mm] x86/mm: Remove the arch-specific pgd_leaf() definition
In reply to Baoquan HeThe following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: 65525a3787ff082575fe29381d4dc8fd535634f2 Gitweb: https://git.kernel.org/tip/65525a3787ff082575fe29381d4dc8fd535634f2 Author: Baoquan He <[email protected]> AuthorDate: Mon, 31 Mar 2025 16:13:25 +08:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Mon, 31 Mar 2025 12:08:17 +02:00
x86/mm: Remove the arch-specific pgd_leaf() definition
PGD huge pages are not supported yet, let's use the generic definition in <linux/pgtable.h>.
[ mingo: Cleaned up the changelog. ]
--- arch/x86/include/asm/pgtable.h | 3 --- 1 file changed, 3 deletions(-)
arch/x86/include/asm/pgtable.h +0 -3
@@ -1472,9 +1472,6 @@ static inline bool pgdp_maps_userspace(void *__ptr)return (((ptr & ~PAGE_MASK ) /sizeof (pgd_t)) <PGD_KERNEL_START ); } -#define pgd_leaf pgd_leaf -static inline bool pgd_leaf (pgd_t pgd) {return false; } -#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION /* * All top-level MITIGATION_PAGE_TABLE_ISOLATION page tables are order-1 pages
Re: [PATCH v2 5/7] x86/mm: remove pgd_leaf definition in arch
In reply to Baoquan HeQuoted 9 lines · Baoquan He
pgd huge page is not supported yet, let's use the generic definition in
linux/pgtable.h.And also update the
BUILD_BUG_ON()checking forpgd_leaf()inpti_user_pagetable_walk_p4d()becausepgd_leaf()returns boolean value.Signed-off-by Baoquan He <[email protected]>---
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v2 5/7] x86/mm: remove pgd_leaf definition in arch
In reply to Baoquan HeQuoted 8 lines · Baoquan He
pgd huge page is not supported yet, let's use the generic definition in
linux/pgtable.h.And also update the
BUILD_BUG_ON()checking forpgd_leaf()inpti_user_pagetable_walk_p4d()becausepgd_leaf()returns boolean value.Signed-off-by Baoquan He <[email protected]>
I have been carrying a sort of this patch in my tree as well for quite some time now, and I think that Christophe also sent it some time ago, so glad someone finally pushed it
https://patchwork.kernel.org/project/linux-mm/patch/[email protected]/
Signature · 2 lines
Oscar Salvador SUSE Labs
Re: [PATCH v2 5/7] x86/mm: remove pgd_leaf definition in arch
Quoted 7 lines · Oscar Salvador
Quoted 6 lines · Baoquan He
pgd huge page is not supported yet, let's use the generic definition in
linux/pgtable.h.And also update the
BUILD_BUG_ON()checking forpgd_leaf()inpti_user_pagetable_walk_p4d()becausepgd_leaf()returns boolean value.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Baoquan He <[email protected]>I have been carrying a sort of this patch in my tree as well for quite some time now, and I think that Christophe also sent it some time ago, so glad someone finally pushed it
https://patchwork.kernel.org/project/linux-mm/patch/[email protected]/
Oops, I even commented in Christophe's patch thread to ask why the patchset hasn't been merged yet. Later when I focused on mm/gup.c code reading, I forgot that posting completely. Hope you don't mind I grab you and Christophe's credit since Ingo has picked it into x86/tip tree.
[PATCH v3 1/5] arch/x86: Drop own definition of pgd,p4d_leaf
Quoted 8 lines
Reviewed-by Oscar Salvador <[email protected]>Signature · 2 lines
Oscar Salvador SUSE Labs
[tip: x86/mm] x86/mm: Simplify the pgd_leaf() and p4d_leaf() checks a bit
In reply to Baoquan HeThe following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: 4a490be3cb59c71dc84a363a251d466e2886ecd2 Gitweb: https://git.kernel.org/tip/4a490be3cb59c71dc84a363a251d466e2886ecd2 Author: Baoquan He <[email protected]> AuthorDate: Mon, 31 Mar 2025 16:13:25 +08:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Tue, 01 Apr 2025 22:47:02 +02:00
x86/mm: Simplify the pgd_leaf() and p4d_leaf() checks a bit
The functions return bool, simplify the checks.
[ mingo: Split off from two other patches. ]
--- arch/x86/mm/pti.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/mm/pti.c +2 -2
@@ -185,7 +185,7 @@ static p4d_t *pti_user_pagetable_walk_p4d(unsigned long address)set_pgd (pgd,__pgd (_KERNPG_TABLE |__pa (new_p4d_page))); } -BUILD_BUG_ON (pgd_leaf (*pgd) !=0 ); +BUILD_BUG_ON (pgd_leaf (*pgd));return p4d_offset (pgd, address); }
@@ -206,7 +206,7 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long address)if (!p4d)return NULL ; -BUILD_BUG_ON (p4d_leaf (*p4d) !=0 ); +BUILD_BUG_ON (p4d_leaf (*p4d));if (p4d_none (*p4d)) {unsigned long new_pud_page =__get_free_page (gfp);if (WARN_ON_ONCE (!new_pud_page))
[tip: x86/mm] x86/mm: Remove the arch-specific pgd_leaf() definition
In reply to Baoquan HeThe following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: b0510ac74e189442dde8799c1b212bd106f2300c Gitweb: https://git.kernel.org/tip/b0510ac74e189442dde8799c1b212bd106f2300c Author: Baoquan He <[email protected]> AuthorDate: Mon, 31 Mar 2025 16:13:25 +08:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Tue, 01 Apr 2025 22:46:51 +02:00
x86/mm: Remove the arch-specific pgd_leaf() definition
PGD huge pages are not supported yet, let's use the generic definition in <linux/pgtable.h>.
[ mingo: Cleaned up the changelog. ]
--- arch/x86/include/asm/pgtable.h | 3 --- 1 file changed, 3 deletions(-)
arch/x86/include/asm/pgtable.h +0 -3
@@ -1472,9 +1472,6 @@ static inline bool pgdp_maps_userspace(void *__ptr)return (((ptr & ~PAGE_MASK ) /sizeof (pgd_t)) <PGD_KERNEL_START ); } -#define pgd_leaf pgd_leaf -static inline bool pgd_leaf (pgd_t pgd) {return false; } -#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION /* * All top-level MITIGATION_PAGE_TABLE_ISOLATION page tables are order-1 pages
[tip: x86/mm] x86/mm: Simplify the pgd_leaf() and p4d_leaf() checks a bit
In reply to Baoquan HeThe following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: 2b00d9031e42eabc8d32847d231ef48b8be0373d Gitweb: https://git.kernel.org/tip/2b00d9031e42eabc8d32847d231ef48b8be0373d Author: Baoquan He <[email protected]> AuthorDate: Mon, 31 Mar 2025 16:13:25 +08:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Tue, 01 Apr 2025 22:48:56 +02:00
x86/mm: Simplify the pgd_leaf() and p4d_leaf() checks a bit
The functions return bool, simplify the checks.
[ mingo: Split off from two other patches. ]
--- arch/x86/mm/pti.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/mm/pti.c +2 -2
@@ -185,7 +185,7 @@ static p4d_t *pti_user_pagetable_walk_p4d(unsigned long address)set_pgd (pgd,__pgd (_KERNPG_TABLE |__pa (new_p4d_page))); } -BUILD_BUG_ON (pgd_leaf (*pgd) !=0 ); +BUILD_BUG_ON (pgd_leaf (*pgd));return p4d_offset (pgd, address); }
@@ -206,7 +206,7 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long address)if (!p4d)return NULL ; -BUILD_BUG_ON (p4d_leaf (*p4d) !=0 ); +BUILD_BUG_ON (p4d_leaf (*p4d));if (p4d_none (*p4d)) {unsigned long new_pud_page =__get_free_page (gfp);if (WARN_ON_ONCE (!new_pud_page))
PATCH v2 6/7 x86/mm: remove p4d_leaf definition
In reply to Baoquan HeThere's no p4d huge page support yet, let's use the generic definition.
And also update the BUILD_BUG_ON() in pti_user_pagetable_walk_pmd() because p4d_leaf() returns boolean value.
--- arch/x86/include/asm/pgtable.h | 7 ------- arch/x86/mm/pti.c | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-)
arch/x86/include/asm/pgtable.h +0 -7
@@ -292,13 +292,6 @@ static inline unsigned long pgd_pfn(pgd_t pgd)return (pgd_val (pgd) &PTE_PFN_MASK ) >>PAGE_SHIFT ; } -#define p4d_leaf p4d_leaf -static inline bool p4d_leaf (p4d_t p4d) -{ -/* No 512 GiB pages yet */ -return 0 ; -} -#define pte_page (pte) pfn_to_page(pte_pfn(pte))#define pmd_leaf pmd_leaf
arch/x86/mm/pti.c +1 -1
@@ -206,7 +206,7 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long address)if (!p4d)return NULL ; -BUILD_BUG_ON (p4d_leaf (*p4d) !=0 ); +BUILD_BUG_ON (p4d_leaf (*p4d));if (p4d_none (*p4d)) {unsigned long new_pud_page =__get_free_page (gfp);if (WARN_ON_ONCE (!new_pud_page))
Signature · 1 line
2.41.0
Re: [PATCH v2 6/7] x86/mm: remove p4d_leaf definition
arch/x86/include/asm/pgtable.h static inline unsigned long pgd_pfn(pgd_t pgd) · line 300
Quoted 12 lines · Baoquan He
There's no p4d huge page support yet, let's use the generic definition.
And also update the
BUILD_BUG_ON()inpti_user_pagetable_walk_pmd()becausep4d_leaf()returns boolean value.arch/x86/include/asm/pgtable.h +0
-6-#define p4d_leaf p4d_leaf -static inline bool p4d_leaf (p4d_t p4d) -{ -/* No 512 GiB pages yet */ -return 0 ; -}
This comment was also incorrect I believe:
1 PTE entry on x86-64 covers 4K virtual memory, 512 PTE entries make up a 4K pagetable page, and each level of paging adds another level of 512 pagetable entries:
- level 0: 4K pages
- level 1: 512x 4K = 2MB 'large' pages
- level 2: 512x 2MB = 1GB 'huge' pages
- level 3: 512x 1GB = 512GB 'PGD' pages
- level 4: 512x 512GB = 256TB 'P4D' pages
So the above comment should have said '256 TB' pages, unless there's some naming weirdness I missed.
Thanks,
Ingo
Re: [PATCH v2 6/7] x86/mm: remove p4d_leaf definition
Quoted 7 lines · Ingo Molnar
Quoted 4 lines · Baoquan He
There's no p4d huge page support yet, let's use the generic definition.
And also update the
BUILD_BUG_ON()inpti_user_pagetable_walk_pmd()becausep4d_leaf()returns boolean value.
Thanks a lot for cleaning up the patch logs and rearranging x86 patches into tip tree.
Quoted 15 lines
arch/x86/include/asm/pgtable.h static inline unsigned long pgd_pfn(pgd_t pgd) · line 300
Quoted 8 lines
arch/x86/include/asm/pgtable.h +0
-6-#define p4d_leaf p4d_leaf -static inline bool p4d_leaf (p4d_t p4d) -{ -/* No 512 GiB pages yet */ -return 0 ; -}This comment was also incorrect I believe:
1 PTE entry on x86-64 covers 4K virtual memory, 512 PTE entries make up a 4K pagetable page, and each level of paging adds another level of 512 pagetable entries:
Quoted 8 lines
- level 0: 4K pages
- level 1: 512x 4K = 2MB 'large' pages
- level 2: 512x 2MB = 1GB 'huge' pages
- level 3: 512x 1GB = 512GB 'PGD' pages
- level 4: 512x 512GB = 256TB 'P4D' pagesSo the above comment should have said '256 TB' pages, unless there's some naming weirdness I missed.
Hmm, there could be misunderstanding here. In 5-level paging, PGD is the highest level, P4D is the next level of PGD. You may have reversed their order. So one P4D entry maps one PUD table which is 512 x 1GB. Then the mentioned comment seems correct to me.
Re: [PATCH v2 6/7] x86/mm: remove p4d_leaf definition
Quoted 6 lines · Baoquan He
Quoted 2 lines
So the above comment should have said '256 TB' pages, unless there's some naming weirdness I missed.
Hmm, there could be misunderstanding here. In 5-level paging, PGD is the highest level, P4D is the next level of PGD. You may have reversed their order.
Erm, yes indeed I flipped those two, so the correct table should be:
- level 0: 4K pages
- level 1: 512x 4K = 2MB 'large' pages
- level 2: 512x 2MB = 1GB 'huge' pages
- level 3: 512x 1GB = 512GB 'P4D' pages
- level 4: 512x 512GB = 256TB 'PGD' pages
I'm wondering whether 512GB pages will be called 'terapages'. ;-)
Thanks,
Ingo
Re: [PATCH v2 6/7] x86/mm: remove p4d_leaf definition
Quoted 12 lines · Ingo Molnar
Quoted 6 lines · Baoquan He
Quoted 2 lines
So the above comment should have said '256 TB' pages, unless there's some naming weirdness I missed.
Hmm, there could be misunderstanding here. In 5-level paging, PGD is the highest level, P4D is the next level of PGD. You may have reversed their order.
Erm, yes indeed I flipped those two, so the correct table should be:
Quoted 7 lines
- level 0: 4K pages
- level 1: 512x 4K = 2MB 'large' pages
- level 2: 512x 2MB = 1GB 'huge' pages
- level 3: 512x 1GB = 512GB 'P4D' pages
- level 4: 512x 512GB = 256TB 'PGD' pagesI'm wondering whether 512GB pages will be called 'terapages'. ;-)
Forgot replying to this one.
With my understanding, MM usually don't name large page of different size a specific name, just call them hugepage + size, e.g 2M huge page, or 1G huge page. Sometime when we build mapping for them, we will call them PMD hugepage or PUD hugepage.
I remember in x86 ARCH direct mapping is built with invocation of init_mem_mapping(), and the mapping to 2M or 1G directly is called large page mapping or PMD/PUD huge page mapping. They are similar.
Hope other MM people can correct me if I am wrong.
[tip: x86/mm] x86/mm: Remove the arch-specific p4d_leaf() definition
In reply to Baoquan HeThe following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: 3532c1f79ffcc57d14b8387a67b01797cc0e8be0 Gitweb: https://git.kernel.org/tip/3532c1f79ffcc57d14b8387a67b01797cc0e8be0 Author: Baoquan He <[email protected]> AuthorDate: Mon, 31 Mar 2025 16:13:26 +08:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Mon, 31 Mar 2025 12:08:17 +02:00
x86/mm: Remove the arch-specific p4d_leaf() definition
P4D huge pages are not supported yet, let's use the generic definition in <linux/pgtable.h>.
[ mingo: Cleaned up the changelog. ]
--- arch/x86/include/asm/pgtable.h | 7 ------- 1 file changed, 7 deletions(-)
arch/x86/include/asm/pgtable.h +0 -7
@@ -292,13 +292,6 @@ static inline unsigned long pgd_pfn(pgd_t pgd)return (pgd_val (pgd) &PTE_PFN_MASK ) >>PAGE_SHIFT ; } -#define p4d_leaf p4d_leaf -static inline bool p4d_leaf (p4d_t p4d) -{ -/* No 512 GiB pages yet */ -return 0 ; -} -#define pte_page (pte) pfn_to_page(pte_pfn(pte))#define pmd_leaf pmd_leaf
Re: [PATCH v2 6/7] x86/mm: remove p4d_leaf definition
In reply to Baoquan HeQuoted 7 lines · Baoquan He
There's no p4d huge page support yet, let's use the generic definition.
And also update the
BUILD_BUG_ON()inpti_user_pagetable_walk_pmd()becausep4d_leaf()returns boolean value.Signed-off-by Baoquan He <[email protected]>
Signature · 2 lines
Oscar Salvador SUSE Labs
[tip: x86/mm] x86/mm: Remove the arch-specific p4d_leaf() definition
In reply to Baoquan HeThe following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: 06e6e99da66cfca1ebac52c09c3a025ef5ccf959 Gitweb: https://git.kernel.org/tip/06e6e99da66cfca1ebac52c09c3a025ef5ccf959 Author: Baoquan He <[email protected]> AuthorDate: Mon, 31 Mar 2025 16:13:26 +08:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Tue, 01 Apr 2025 22:47:02 +02:00
x86/mm: Remove the arch-specific p4d_leaf() definition
P4D huge pages are not supported yet, let's use the generic definition in <linux/pgtable.h>.
[ mingo: Cleaned up the changelog. ]
--- arch/x86/include/asm/pgtable.h | 7 ------- 1 file changed, 7 deletions(-)
arch/x86/include/asm/pgtable.h +0 -7
@@ -292,13 +292,6 @@ static inline unsigned long pgd_pfn(pgd_t pgd)return (pgd_val (pgd) &PTE_PFN_MASK ) >>PAGE_SHIFT ; } -#define p4d_leaf p4d_leaf -static inline bool p4d_leaf (p4d_t p4d) -{ -/* No 512 GiB pages yet */ -return 0 ; -} -#define pte_page (pte) pfn_to_page(pte_pfn(pte))#define pmd_leaf pmd_leaf
[tip: x86/mm] x86/mm: Remove the arch-specific p4d_leaf() definition
In reply to Baoquan HeThe following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: c083eff324edd73eb23f4bd3f40f388a3e7c2cd2 Gitweb: https://git.kernel.org/tip/c083eff324edd73eb23f4bd3f40f388a3e7c2cd2 Author: Baoquan He <[email protected]> AuthorDate: Mon, 31 Mar 2025 16:13:26 +08:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Tue, 01 Apr 2025 22:48:51 +02:00
x86/mm: Remove the arch-specific p4d_leaf() definition
P4D huge pages are not supported yet, let's use the generic definition in <linux/pgtable.h>.
[ mingo: Cleaned up the changelog. ]
--- arch/x86/include/asm/pgtable.h | 7 ------- 1 file changed, 7 deletions(-)
arch/x86/include/asm/pgtable.h +0 -7
@@ -292,13 +292,6 @@ static inline unsigned long pgd_pfn(pgd_t pgd)return (pgd_val (pgd) &PTE_PFN_MASK ) >>PAGE_SHIFT ; } -#define p4d_leaf p4d_leaf -static inline bool p4d_leaf (p4d_t p4d) -{ -/* No 512 GiB pages yet */ -return 0 ; -} -#define pte_page (pte) pfn_to_page(pte_pfn(pte))#define pmd_leaf pmd_leaf
PATCH v2 7/7 mm/pgtable: remove unneeded pgd_devmap()
In reply to Baoquan HeThere's no user of pgd_devmap() now, remove it from all ARCH-es and linux/pgtable.h.
--- arch/arm64/include/asm/pgtable.h | 5 ----- arch/loongarch/include/asm/pgtable.h | 1 - arch/powerpc/include/asm/book3s/64/pgtable.h | 5 ----- arch/riscv/include/asm/pgtable-64.h | 5 ----- arch/x86/include/asm/pgtable.h | 5 ----- include/linux/pgtable.h | 4 ---- 6 files changed, 25 deletions(-)
arch/arm64/include/asm/pgtable.h +0 -5
@@ -1230,11 +1230,6 @@ static inline int pud_devmap(pud_t pud) {return 0 ; } - -static inline int pgd_devmap (pgd_t pgd) -{ -return 0 ; -}#endif #ifdef CONFIG_PAGE_TABLE_CHECK
arch/loongarch/include/asm/pgtable.h +0 -1
@@ -615,7 +615,6 @@ static inline long pmd_protnone(pmd_t pmd)#ifdef CONFIG_TRANSPARENT_HUGEPAGE #define pud_devmap (pud) (0) -#define pgd_devmap (pgd) (0)#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ /*
arch/powerpc/include/asm/book3s/64/pgtable.h +0 -5
@@ -1405,11 +1405,6 @@ static inline int pud_devmap(pud_t pud) {return pte_devmap (pud_pte (pud)); } - -static inline int pgd_devmap (pgd_t pgd) -{ -return 0 ; -}#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ #define __HAVE_ARCH_PTEP_MODIFY_PROT_TRANSACTION
arch/riscv/include/asm/pgtable-64.h +0 -5
@@ -411,11 +411,6 @@ static inline int pud_devmap(pud_t pud) {return 0 ; } - -static inline int pgd_devmap (pgd_t pgd) -{ -return 0 ; -}#endif #endif /* _ASM_RISCV_PGTABLE_64_H */
arch/x86/include/asm/pgtable.h +0 -5
@@ -361,11 +361,6 @@ static inline pud_t pud_mkspecial(pud_t pud)return pud_set_flags (pud, _PAGE_SPECIAL); }#endif /* CONFIG_ARCH_SUPPORTS_PUD_PFNMAP */ - -static inline int pgd_devmap (pgd_t pgd) -{ -return 0 ; -}#endif #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
include/linux/pgtable.h +0 -4
@@ -1615,10 +1615,6 @@ static inline int pud_devmap(pud_t pud) {return 0 ; } -static inline int pgd_devmap (pgd_t pgd) -{ -return 0 ; -}#endif #if !defined(CONFIG_TRANSPARENT_HUGEPAGE) || \
Signature · 1 line
2.41.0
Re: [PATCH v2 7/7] mm/pgtable: remove unneeded pgd_devmap()
Quoted 2 lines · Baoquan He
There's no user of
pgd_devmap()now, remove it from all ARCH-es andlinux/pgtable.h.
Drop this patch, Alistair will remove all that devmap stuff soon.
Signature · 3 lines
Cheers, David / dhildenb
Re: [PATCH v2 7/7] mm/pgtable: remove unneeded pgd_devmap()
Quoted 7 lines · David Hildenbrand
Quoted 2 lines · Baoquan He
There's no user of
pgd_devmap()now, remove it from all ARCH-es andlinux/pgtable.h.Drop this patch, Alistair will remove all that devmap stuff soon.
Thanks for telling, will drop it.
Quoted 6 lines
Signature · 4 lines
-- Cheers, David / dhildenb