diff mbox series

[V2,1/7] m68k/mm: Change pmd_val()

Message ID 20240917073117.1531207-2-anshuman.khandual@arm.com (mailing list archive)
State New
Headers show
Series mm: Use pxdp_get() for accessing page table entries | expand

Commit Message

Anshuman Khandual Sept. 17, 2024, 7:31 a.m. UTC
This changes platform's pmd_val() to access the pmd_t element directly like
other architectures rather than current pointer address based dereferencing
that prevents transition into pmdp_get().

Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Guo Ren <guoren@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: linux-m68k@lists.linux-m68k.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/m68k/include/asm/page.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Ryan Roberts Sept. 17, 2024, 8:40 a.m. UTC | #1
On 17/09/2024 08:31, Anshuman Khandual wrote:
> This changes platform's pmd_val() to access the pmd_t element directly like
> other architectures rather than current pointer address based dereferencing
> that prevents transition into pmdp_get().
> 
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Guo Ren <guoren@kernel.org>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: linux-m68k@lists.linux-m68k.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>

I know very little about m68k, but for what it's worth:

Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>

> ---
>  arch/m68k/include/asm/page.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/m68k/include/asm/page.h b/arch/m68k/include/asm/page.h
> index 8cfb84b49975..be3f2c2a656c 100644
> --- a/arch/m68k/include/asm/page.h
> +++ b/arch/m68k/include/asm/page.h
> @@ -19,7 +19,7 @@
>   */
>  #if !defined(CONFIG_MMU) || CONFIG_PGTABLE_LEVELS == 3
>  typedef struct { unsigned long pmd; } pmd_t;
> -#define pmd_val(x)	((&x)->pmd)
> +#define pmd_val(x)	((x).pmd)
>  #define __pmd(x)	((pmd_t) { (x) } )
>  #endif
>
David Hildenbrand Sept. 17, 2024, 10:20 a.m. UTC | #2
On 17.09.24 09:31, Anshuman Khandual wrote:
> This changes platform's pmd_val() to access the pmd_t element directly like
> other architectures rather than current pointer address based dereferencing
> that prevents transition into pmdp_get().
> 
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Guo Ren <guoren@kernel.org>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: linux-m68k@lists.linux-m68k.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> ---
>   arch/m68k/include/asm/page.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/m68k/include/asm/page.h b/arch/m68k/include/asm/page.h
> index 8cfb84b49975..be3f2c2a656c 100644
> --- a/arch/m68k/include/asm/page.h
> +++ b/arch/m68k/include/asm/page.h
> @@ -19,7 +19,7 @@
>    */
>   #if !defined(CONFIG_MMU) || CONFIG_PGTABLE_LEVELS == 3
>   typedef struct { unsigned long pmd; } pmd_t;
> -#define pmd_val(x)	((&x)->pmd)
> +#define pmd_val(x)	((x).pmd)
>   #define __pmd(x)	((pmd_t) { (x) } )
>   #endif
>   

Trying to understand what's happening here, I stumbled over

commit ef22d8abd876e805b604e8f655127de2beee2869
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Fri Jan 31 13:45:36 2020 +0100

     m68k: mm: Restructure Motorola MMU page-table layout
     
     The Motorola 68xxx MMUs, 040 (and later) have a fixed 7,7,{5,6}
     page-table setup, where the last depends on the page-size selected (8k
     vs 4k resp.), and head.S selects 4K pages. For 030 (and earlier) we
     explicitly program 7,7,6 and 4K pages in %tc.
     
     However, the current code implements this mightily weird. What it does
     is group 16 of those (6 bit) pte tables into one 4k page to not waste
     space. The down-side is that that forces pmd_t to be a 16-tuple
     pointing to consecutive pte tables.
     
     This breaks the generic code which assumes READ_ONCE(*pmd) will be
     word sized.

Where we did

  #if !defined(CONFIG_MMU) || CONFIG_PGTABLE_LEVELS == 3
-typedef struct { unsigned long pmd[16]; } pmd_t;
-#define pmd_val(x)     ((&x)->pmd[0])
-#define __pmd(x)       ((pmd_t) { { (x) }, })
+typedef struct { unsigned long pmd; } pmd_t;
+#define pmd_val(x)     ((&x)->pmd)
+#define __pmd(x)       ((pmd_t) { (x) } )
  #endif

So I assume this should be fine

Acked-by: David Hildenbrand <david@redhat.com>
Ryan Roberts Sept. 17, 2024, 10:27 a.m. UTC | #3
On 17/09/2024 11:20, David Hildenbrand wrote:
> On 17.09.24 09:31, Anshuman Khandual wrote:
>> This changes platform's pmd_val() to access the pmd_t element directly like
>> other architectures rather than current pointer address based dereferencing
>> that prevents transition into pmdp_get().
>>
>> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
>> Cc: Guo Ren <guoren@kernel.org>
>> Cc: Arnd Bergmann <arnd@arndb.de>
>> Cc: linux-m68k@lists.linux-m68k.org
>> Cc: linux-kernel@vger.kernel.org
>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>> ---
>>   arch/m68k/include/asm/page.h | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/m68k/include/asm/page.h b/arch/m68k/include/asm/page.h
>> index 8cfb84b49975..be3f2c2a656c 100644
>> --- a/arch/m68k/include/asm/page.h
>> +++ b/arch/m68k/include/asm/page.h
>> @@ -19,7 +19,7 @@
>>    */
>>   #if !defined(CONFIG_MMU) || CONFIG_PGTABLE_LEVELS == 3
>>   typedef struct { unsigned long pmd; } pmd_t;
>> -#define pmd_val(x)    ((&x)->pmd)
>> +#define pmd_val(x)    ((x).pmd)
>>   #define __pmd(x)    ((pmd_t) { (x) } )
>>   #endif
>>   
> 
> Trying to understand what's happening here, I stumbled over
> 
> commit ef22d8abd876e805b604e8f655127de2beee2869
> Author: Peter Zijlstra <peterz@infradead.org>
> Date:   Fri Jan 31 13:45:36 2020 +0100
> 
>     m68k: mm: Restructure Motorola MMU page-table layout
>         The Motorola 68xxx MMUs, 040 (and later) have a fixed 7,7,{5,6}
>     page-table setup, where the last depends on the page-size selected (8k
>     vs 4k resp.), and head.S selects 4K pages. For 030 (and earlier) we
>     explicitly program 7,7,6 and 4K pages in %tc.
>         However, the current code implements this mightily weird. What it does
>     is group 16 of those (6 bit) pte tables into one 4k page to not waste
>     space. The down-side is that that forces pmd_t to be a 16-tuple
>     pointing to consecutive pte tables.
>         This breaks the generic code which assumes READ_ONCE(*pmd) will be
>     word sized.
> 
> Where we did
> 
>  #if !defined(CONFIG_MMU) || CONFIG_PGTABLE_LEVELS == 3
> -typedef struct { unsigned long pmd[16]; } pmd_t;
> -#define pmd_val(x)     ((&x)->pmd[0])
> -#define __pmd(x)       ((pmd_t) { { (x) }, })
> +typedef struct { unsigned long pmd; } pmd_t;
> +#define pmd_val(x)     ((&x)->pmd)
> +#define __pmd(x)       ((pmd_t) { (x) } )
>  #endif
> 
> So I assume this should be fine

I think you're implying that taking the address then using arrow operator was
needed when pmd was an array? I don't really understand that if so? Surely:

  ((x).pmd[0])

would have worked too? I traced back further, and a version of that macro exists
with the "address of" and arrow operator since the beginning of (git) time.

> 
> Acked-by: David Hildenbrand <david@redhat.com>
>
David Hildenbrand Sept. 17, 2024, 10:30 a.m. UTC | #4
>>   #if !defined(CONFIG_MMU) || CONFIG_PGTABLE_LEVELS == 3
>> -typedef struct { unsigned long pmd[16]; } pmd_t;
>> -#define pmd_val(x)     ((&x)->pmd[0])
>> -#define __pmd(x)       ((pmd_t) { { (x) }, })
>> +typedef struct { unsigned long pmd; } pmd_t;
>> +#define pmd_val(x)     ((&x)->pmd)
>> +#define __pmd(x)       ((pmd_t) { (x) } )
>>   #endif
>>
>> So I assume this should be fine
> 
> I think you're implying that taking the address then using arrow operator was
> needed when pmd was an array? I don't really understand that if so? Surely:
> 
>    ((x).pmd[0])
> 
> would have worked too?

I think your right, I guess one suspects that there is more magic to it 
than there actually is ... :)
diff mbox series

Patch

diff --git a/arch/m68k/include/asm/page.h b/arch/m68k/include/asm/page.h
index 8cfb84b49975..be3f2c2a656c 100644
--- a/arch/m68k/include/asm/page.h
+++ b/arch/m68k/include/asm/page.h
@@ -19,7 +19,7 @@ 
  */
 #if !defined(CONFIG_MMU) || CONFIG_PGTABLE_LEVELS == 3
 typedef struct { unsigned long pmd; } pmd_t;
-#define pmd_val(x)	((&x)->pmd)
+#define pmd_val(x)	((x).pmd)
 #define __pmd(x)	((pmd_t) { (x) } )
 #endif