diff mbox series

mm/gup.c: stricter check on THP migration entry during follow_pmd_mask

Message ID 20211208133930.599253-1-lixinhai.lxh@gmail.com (mailing list archive)
State New
Headers show
Series mm/gup.c: stricter check on THP migration entry during follow_pmd_mask | expand

Commit Message

Li Xinhai Dec. 8, 2021, 1:39 p.m. UTC
When BUG_ON check for THP migration entry, we need also consider
!thp_migration_supported() case, becaouse it is invalid at the code
context. Now, make this check been covered without adding extra cost.

Because pmdval instead of *pmd is read, so just call
pmd_migration_entry_wait().

Signed-off-by: Li Xinhai <lixinhai.lxh@gmail.com>
---
 mm/gup.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Andrew Morton Dec. 8, 2021, 11:35 p.m. UTC | #1
On Wed,  8 Dec 2021 21:39:30 +0800 Li Xinhai <lixinhai.lxh@gmail.com> wrote:

> When BUG_ON check for THP migration entry, we need also consider
> !thp_migration_supported() case, becaouse it is invalid at the code
> context. Now, make this check been covered without adding extra cost.
> 
> Because pmdval instead of *pmd is read, so just call
> pmd_migration_entry_wait().
> 
> Signed-off-by: Li Xinhai <lixinhai.lxh@gmail.com>
> ---
>  mm/gup.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/gup.c b/mm/gup.c
> index 2c51e9748a6a..49f490bae030 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -644,10 +644,9 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma,
>  	if (!pmd_present(pmdval)) {
>  		if (likely(!(flags & FOLL_MIGRATION)))
>  			return no_page_table(vma, flags);
> -		VM_BUG_ON(thp_migration_supported() &&
> +		VM_BUG_ON(!thp_migration_supported() ||

I don't get this.  thp_migration_supported() evaluates to a
compile-time constant.  What is the point in doing a runtime BUG based
on a thing which is known at compile-time?

>  				  !is_pmd_migration_entry(pmdval));
> -		if (is_pmd_migration_entry(pmdval))
> -			pmd_migration_entry_wait(mm, pmd);
> +		pmd_migration_entry_wait(mm, pmd);
>  		pmdval = READ_ONCE(*pmd);
>  		/*
>  		 * MADV_DONTNEED may convert the pmd to null because
Li Xinhai Dec. 9, 2021, 1:40 a.m. UTC | #2
On 12/9/21 7:35 AM, Andrew Morton wrote:
> On Wed,  8 Dec 2021 21:39:30 +0800 Li Xinhai <lixinhai.lxh@gmail.com> wrote:
> 
>> When BUG_ON check for THP migration entry, we need also consider
>> !thp_migration_supported() case, becaouse it is invalid at the code
>> context. Now, make this check been covered without adding extra cost.
>>
>> Because pmdval instead of *pmd is read, so just call
>> pmd_migration_entry_wait().
>>
>> Signed-off-by: Li Xinhai <lixinhai.lxh@gmail.com>
>> ---
>>   mm/gup.c | 5 ++---
>>   1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/mm/gup.c b/mm/gup.c
>> index 2c51e9748a6a..49f490bae030 100644
>> --- a/mm/gup.c
>> +++ b/mm/gup.c
>> @@ -644,10 +644,9 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma,
>>   	if (!pmd_present(pmdval)) {
>>   		if (likely(!(flags & FOLL_MIGRATION)))
>>   			return no_page_table(vma, flags);
>> -		VM_BUG_ON(thp_migration_supported() &&
>> +		VM_BUG_ON(!thp_migration_supported() ||
> 
> I don't get this.  thp_migration_supported() evaluates to a
> compile-time constant.  What is the point in doing a runtime BUG based
> on a thing which is known at compile-time?
> 
Yes, support thp migration is compile-time known. The exsiting VM_BUG_ON will
be nothing if thp_migration_supported() equal to false, so pmdval other than
migration entry will not be caught.

Now, with the patch, if thp_migration_supported() equal to false, we will have
VM_BUG_ON(1) so to catch above error case.


>>   				  !is_pmd_migration_entry(pmdval));
>> -		if (is_pmd_migration_entry(pmdval))
>> -			pmd_migration_entry_wait(mm, pmd);
>> +		pmd_migration_entry_wait(mm, pmd);
>>   		pmdval = READ_ONCE(*pmd);
>>   		/*
>>   		 * MADV_DONTNEED may convert the pmd to null because
>
diff mbox series

Patch

diff --git a/mm/gup.c b/mm/gup.c
index 2c51e9748a6a..49f490bae030 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -644,10 +644,9 @@  static struct page *follow_pmd_mask(struct vm_area_struct *vma,
 	if (!pmd_present(pmdval)) {
 		if (likely(!(flags & FOLL_MIGRATION)))
 			return no_page_table(vma, flags);
-		VM_BUG_ON(thp_migration_supported() &&
+		VM_BUG_ON(!thp_migration_supported() ||
 				  !is_pmd_migration_entry(pmdval));
-		if (is_pmd_migration_entry(pmdval))
-			pmd_migration_entry_wait(mm, pmd);
+		pmd_migration_entry_wait(mm, pmd);
 		pmdval = READ_ONCE(*pmd);
 		/*
 		 * MADV_DONTNEED may convert the pmd to null because