[PATCH] mm/swapops: make is_pmd_migration_entry more strict

Hongchen Zhang posted 1 patch 4 years ago
include/linux/swapops.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] mm/swapops: make is_pmd_migration_entry more strict
Posted by Hongchen Zhang 4 years ago
a pmd migration entry should first be a swap pmd,so
use is_swap_pmd(pmd) instead of !pmd_present(pmd).

On the other hand, some architecture (MIPS for example)
may misjudge a pmd_none entry as a pmd migration entry.

Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
---
 include/linux/swapops.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/swapops.h b/include/linux/swapops.h
index d356ab4..1d16569 100644
--- a/include/linux/swapops.h
+++ b/include/linux/swapops.h
@@ -304,7 +304,7 @@ static inline pmd_t swp_entry_to_pmd(swp_entry_t entry)
 
 static inline int is_pmd_migration_entry(pmd_t pmd)
 {
-	return !pmd_present(pmd) && is_migration_entry(pmd_to_swp_entry(pmd));
+	return is_swap_pmd(pmd) && is_migration_entry(pmd_to_swp_entry(pmd));
 }
 #else
 static inline void set_pmd_migration_entry(struct page_vma_mapped_walk *pvmw,
-- 
1.8.3.1
Re: [PATCH] mm/swapops: make is_pmd_migration_entry more strict
Posted by Peter Xu 4 years ago
On Thu, Apr 28, 2022 at 03:35:33PM +0800, Hongchen Zhang wrote:
> a pmd migration entry should first be a swap pmd,so
> use is_swap_pmd(pmd) instead of !pmd_present(pmd).
> 
> On the other hand, some architecture (MIPS for example)
> may misjudge a pmd_none entry as a pmd migration entry.
> 
> Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>

The change looks reasonable,

Acked-by: Peter Xu <peterx@redhat.com>

Two more pure questions..

  (1) is there a real issue to be fixed with it?  Asked because I see most
      calls to is_pmd_migration_entry() should already make sure it's not
      none, and,

  (2) why it matters with MIPS?  Firstly this function is not used in arch
      specific code, and iiuc thp migration is not enabled at all for mips.

Thanks,

> ---
>  include/linux/swapops.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/swapops.h b/include/linux/swapops.h
> index d356ab4..1d16569 100644
> --- a/include/linux/swapops.h
> +++ b/include/linux/swapops.h
> @@ -304,7 +304,7 @@ static inline pmd_t swp_entry_to_pmd(swp_entry_t entry)
>  
>  static inline int is_pmd_migration_entry(pmd_t pmd)
>  {
> -	return !pmd_present(pmd) && is_migration_entry(pmd_to_swp_entry(pmd));
> +	return is_swap_pmd(pmd) && is_migration_entry(pmd_to_swp_entry(pmd));
>  }
>  #else
>  static inline void set_pmd_migration_entry(struct page_vma_mapped_walk *pvmw,
> -- 
> 1.8.3.1
> 

-- 
Peter Xu
Re: [PATCH] mm/swapops: make is_pmd_migration_entry more strict
Posted by Hongchen Zhang 4 years ago
On 2022/4/29 上午2:41, Peter Xu wrote:
> On Thu, Apr 28, 2022 at 03:35:33PM +0800, Hongchen Zhang wrote:
>> a pmd migration entry should first be a swap pmd,so
>> use is_swap_pmd(pmd) instead of !pmd_present(pmd).
>>
>> On the other hand, some architecture (MIPS for example)
>> may misjudge a pmd_none entry as a pmd migration entry.
>>
>> Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
> 
> The change looks reasonable,
> 
> Acked-by: Peter Xu <peterx@redhat.com>
> 
> Two more pure questions..
> 
>    (1) is there a real issue to be fixed with it?  Asked because I see most
>        calls to is_pmd_migration_entry() should already make sure it's not
>        none, and,
> 
>    (2) why it matters with MIPS?  Firstly this function is not used in arch
>        specific code, and iiuc thp migration is not enabled at all for mips.
> 
> Thanks,
> 
>> ---
>>   include/linux/swapops.h | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/linux/swapops.h b/include/linux/swapops.h
>> index d356ab4..1d16569 100644
>> --- a/include/linux/swapops.h
>> +++ b/include/linux/swapops.h
>> @@ -304,7 +304,7 @@ static inline pmd_t swp_entry_to_pmd(swp_entry_t entry)
>>   
>>   static inline int is_pmd_migration_entry(pmd_t pmd)
>>   {
>> -	return !pmd_present(pmd) && is_migration_entry(pmd_to_swp_entry(pmd));
>> +	return is_swap_pmd(pmd) && is_migration_entry(pmd_to_swp_entry(pmd));
>>   }
>>   #else
>>   static inline void set_pmd_migration_entry(struct page_vma_mapped_walk *pvmw,
>> -- 
>> 1.8.3.1
>>
> 
Hello Peter,
   (1) the pmd passed to __split_huge_pmd_locked may be a none pmd,so it 
may be wrongly treated as a pmd migration entry.
   (2) we are preparing to support thp migration on MIPS.

Thanks.

Re: [PATCH] mm/swapops: make is_pmd_migration_entry more strict
Posted by Peter Xu 4 years ago
On Fri, Apr 29, 2022 at 10:23:08AM +0800, Hongchen Zhang wrote:
> Hello Peter,

Hi, Hongchen,

>   (1) the pmd passed to __split_huge_pmd_locked may be a none pmd,so it may
> be wrongly treated as a pmd migration entry.

With !ARCH_ENABLE_THP_MIGRATION is_pmd_migration_entry() returns 0
constantly.

>   (2) we are preparing to support thp migration on MIPS.

Makes sense (to not have Fixes then).  It'll be great if the objective of
the patch will be mentioned in the future.

Thanks for answering!

-- 
Peter Xu