[PATCH] LoongArch: Use __pmd() helper for __swp_entry_to_pmd()

WangYuli posted 1 patch 2 weeks, 2 days ago
arch/loongarch/include/asm/pgtable.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] LoongArch: Use __pmd() helper for __swp_entry_to_pmd()
Posted by WangYuli 2 weeks, 2 days ago
From: WangYuli <wangyl5933@chinaunicom.cn>

The __pmd() helper macro provides the correct initialization syntax
and abstraction for the pmd_t type.

Fix follow warning on gcc-15 under specific configs [1] :

  In file included from ./include/linux/pgtable.h:6,
                   from ./include/linux/mm.h:31,
                   from ./include/linux/pagemap.h:8,
                   from arch/loongarch/mm/init.c:14:
  ./include/linux/swapops.h: In function ‘swp_entry_to_pmd’:
  ./arch/loongarch/include/asm/pgtable.h:302:34: error: missing braces around initializer [-Werror=missing-braces]
    302 | #define __swp_entry_to_pmd(x)   ((pmd_t) { (x).val | _PAGE_HUGE })
        |                                  ^
  ./include/linux/swapops.h:559:16: note: in expansion of macro ‘__swp_entry_to_pmd’
    559 |         return __swp_entry_to_pmd(arch_entry);
        |                ^~~~~~~~~~~~~~~~~~
  cc1: all warnings being treated as errors

[1]. https://download.01.org/0day-ci/archive/20251119/202511190316.luI90kAo-lkp@intel.com/config

Signed-off-by: WangYuli <wangyl5933@chinaunicom.cn>
---
 arch/loongarch/include/asm/pgtable.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h
index 03fb60432fde..4e09f7e8bbec 100644
--- a/arch/loongarch/include/asm/pgtable.h
+++ b/arch/loongarch/include/asm/pgtable.h
@@ -299,7 +299,7 @@ static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
 #define __swp_entry_to_pte(x)	((pte_t) { (x).val })
 #define __pmd_to_swp_entry(pmd) ((swp_entry_t) { pmd_val(pmd) })
-#define __swp_entry_to_pmd(x)	((pmd_t) { (x).val | _PAGE_HUGE })
+#define __swp_entry_to_pmd(x)	__pmd((x).val | _PAGE_HUGE)
 
 static inline bool pte_swp_exclusive(pte_t pte)
 {
-- 
2.51.0

Re: [PATCH] LoongArch: Use __pmd() helper for __swp_entry_to_pmd()
Posted by WangYuli 2 weeks, 2 days ago
Hi Huacai,

On 2025/12/3 17:46, Huacai Chen wrote:
>> diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h
>> index 03fb60432fde..4e09f7e8bbec 100644
>> --- a/arch/loongarch/include/asm/pgtable.h
>> +++ b/arch/loongarch/include/asm/pgtable.h
>> @@ -299,7 +299,7 @@ static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
>>   #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
>>   #define __swp_entry_to_pte(x)  ((pte_t) { (x).val })
> Why not change __swp_entry_to_pte() together with __pte()?
>
> Huacai

I haven't investigated this closely, but it's odd that changing just 
this one spot was enough to get it to compile — there doesn't seem to be 
an error at __swp_entry_to_pte.

But you're right that changing both together looks neater.

If you think it's necessary, I'm happy to submit a patch v2.

Thanks,

--

WangYuli

Re: [PATCH] LoongArch: Use __pmd() helper for __swp_entry_to_pmd()
Posted by Huacai Chen 2 weeks, 2 days ago
On Wed, Dec 3, 2025 at 6:05 PM WangYuli <wangyuli@aosc.io> wrote:
>
> Hi Huacai,
>
> On 2025/12/3 17:46, Huacai Chen wrote:
> >> diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h
> >> index 03fb60432fde..4e09f7e8bbec 100644
> >> --- a/arch/loongarch/include/asm/pgtable.h
> >> +++ b/arch/loongarch/include/asm/pgtable.h
> >> @@ -299,7 +299,7 @@ static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
> >>   #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
> >>   #define __swp_entry_to_pte(x)  ((pte_t) { (x).val })
> > Why not change __swp_entry_to_pte() together with __pte()?
> >
> > Huacai
>
> I haven't investigated this closely, but it's odd that changing just
> this one spot was enough to get it to compile — there doesn't seem to be
> an error at __swp_entry_to_pte.
>
> But you're right that changing both together looks neater.
>
> If you think it's necessary, I'm happy to submit a patch v2.
Yes, please!

Huacai
>
> Thanks,
>
> --
>
> WangYuli
>
Re: [PATCH] LoongArch: Use __pmd() helper for __swp_entry_to_pmd()
Posted by Huacai Chen 2 weeks, 2 days ago
Hi, Yuli,

On Wed, Dec 3, 2025 at 5:29 PM WangYuli <wangyuli@aosc.io> wrote:
>
> From: WangYuli <wangyl5933@chinaunicom.cn>
>
> The __pmd() helper macro provides the correct initialization syntax
> and abstraction for the pmd_t type.
>
> Fix follow warning on gcc-15 under specific configs [1] :
>
>   In file included from ./include/linux/pgtable.h:6,
>                    from ./include/linux/mm.h:31,
>                    from ./include/linux/pagemap.h:8,
>                    from arch/loongarch/mm/init.c:14:
>   ./include/linux/swapops.h: In function ‘swp_entry_to_pmd’:
>   ./arch/loongarch/include/asm/pgtable.h:302:34: error: missing braces around initializer [-Werror=missing-braces]
>     302 | #define __swp_entry_to_pmd(x)   ((pmd_t) { (x).val | _PAGE_HUGE })
>         |                                  ^
>   ./include/linux/swapops.h:559:16: note: in expansion of macro ‘__swp_entry_to_pmd’
>     559 |         return __swp_entry_to_pmd(arch_entry);
>         |                ^~~~~~~~~~~~~~~~~~
>   cc1: all warnings being treated as errors
>
> [1]. https://download.01.org/0day-ci/archive/20251119/202511190316.luI90kAo-lkp@intel.com/config
>
> Signed-off-by: WangYuli <wangyl5933@chinaunicom.cn>
> ---
>  arch/loongarch/include/asm/pgtable.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h
> index 03fb60432fde..4e09f7e8bbec 100644
> --- a/arch/loongarch/include/asm/pgtable.h
> +++ b/arch/loongarch/include/asm/pgtable.h
> @@ -299,7 +299,7 @@ static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
>  #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
>  #define __swp_entry_to_pte(x)  ((pte_t) { (x).val })
Why not change __swp_entry_to_pte() together with __pte()?

Huacai

>  #define __pmd_to_swp_entry(pmd) ((swp_entry_t) { pmd_val(pmd) })
> -#define __swp_entry_to_pmd(x)  ((pmd_t) { (x).val | _PAGE_HUGE })
> +#define __swp_entry_to_pmd(x)  __pmd((x).val | _PAGE_HUGE)
>
>  static inline bool pte_swp_exclusive(pte_t pte)
>  {
> --
> 2.51.0
>