diff mbox series

[RFC,1/4] riscv: Optimize satp_mode data type

Message ID 20220705100523.1204595-2-guoren@kernel.org (mailing list archive)
State New, archived
Headers show
Series Proof of concept for rv32 svpbmt support | expand

Commit Message

Guo Ren July 5, 2022, 10:05 a.m. UTC
From: Guo Ren <guoren@linux.alibaba.com>

Fixup satp_mode data type. Use ulong instead of u64 for rv32
compatibility. Because the u64 type didn't cause any real problem, make
it as optimized.

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
---
 arch/riscv/include/asm/pgtable.h | 2 +-
 arch/riscv/mm/init.c             | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

Comments

Christoph Hellwig July 5, 2022, 5:26 p.m. UTC | #1
On Tue, Jul 05, 2022 at 06:05:20AM -0400, guoren@kernel.org wrote:
> From: Guo Ren <guoren@linux.alibaba.com>
> 
> Fixup satp_mode data type. Use ulong instead of u64 for rv32
> compatibility. Because the u64 type didn't cause any real problem, make
> it as optimized.

The changelog loooks odd, but given that CSR are Xlen sized this
is the right thing to do even without further justification.

> -extern u64 satp_mode;
> +extern ulong satp_mode;

.. but please spell out unsigned long.

>  #ifdef CONFIG_64BIT
> -u64 satp_mode __ro_after_init = !IS_ENABLED(CONFIG_XIP_KERNEL) ? SATP_MODE_57 : SATP_MODE_39;
> +ulong satp_mode __ro_after_init = !IS_ENABLED(CONFIG_XIP_KERNEL) ? SATP_MODE_57 : SATP_MODE_39;
>  #else
> -u64 satp_mode __ro_after_init = SATP_MODE_32;
> +ulong satp_mode __ro_after_init = SATP_MODE_32;
>  #endif

And maybe make this less of a mess while we're at it:

#ifdef CONFIG_32BIT
#define SATP_DEFAULT	SATP_MODE_32
#elif defined(CONFIG_XIP_KERNEL)
#define SATP_DEFAULT	SATP_MODE_39
#else
#define SATP_DEFAULT	SATP_MODE_57
#endif

unsigned long satp_mode __ro_after_init = SATP_DEFAULT;
Guo Ren July 5, 2022, 11:45 p.m. UTC | #2
On Wed, Jul 6, 2022 at 1:26 AM Christoph Hellwig <hch@infradead.org> wrote:
>
> On Tue, Jul 05, 2022 at 06:05:20AM -0400, guoren@kernel.org wrote:
> > From: Guo Ren <guoren@linux.alibaba.com>
> >
> > Fixup satp_mode data type. Use ulong instead of u64 for rv32
> > compatibility. Because the u64 type didn't cause any real problem, make
> > it as optimized.
>
> The changelog loooks odd, but given that CSR are Xlen sized this
> is the right thing to do even without further justification.
The last sentence is the reason not to add Fixes: tag.

>
> > -extern u64 satp_mode;
> > +extern ulong satp_mode;
>
> .. but please spell out unsigned long.
>
> >  #ifdef CONFIG_64BIT
> > -u64 satp_mode __ro_after_init = !IS_ENABLED(CONFIG_XIP_KERNEL) ? SATP_MODE_57 : SATP_MODE_39;
> > +ulong satp_mode __ro_after_init = !IS_ENABLED(CONFIG_XIP_KERNEL) ? SATP_MODE_57 : SATP_MODE_39;
> >  #else
> > -u64 satp_mode __ro_after_init = SATP_MODE_32;
> > +ulong satp_mode __ro_after_init = SATP_MODE_32;
> >  #endif
>
> And maybe make this less of a mess while we're at it:
>
> #ifdef CONFIG_32BIT
> #define SATP_DEFAULT    SATP_MODE_32
> #elif defined(CONFIG_XIP_KERNEL)
> #define SATP_DEFAULT    SATP_MODE_39
> #else
> #define SATP_DEFAULT    SATP_MODE_57
> #endif
>
> unsigned long satp_mode __ro_after_init = SATP_DEFAULT;
It a little involves the other coding convention work.

ulong satp_mode __ro_after_init = !IS_ENABLED(CONFIG_XIP_KERNEL) ?
SATP_MODE_57 : SATP_MODE_39;B
The above seems readable & clear to me.
diff mbox series

Patch

diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 1d1be9d9419c..edc68759b69d 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -833,7 +833,7 @@  extern uintptr_t _dtb_early_pa;
 #define dtb_early_va	_dtb_early_va
 #define dtb_early_pa	_dtb_early_pa
 #endif /* CONFIG_XIP_KERNEL */
-extern u64 satp_mode;
+extern ulong satp_mode;
 extern bool pgtable_l4_enabled;
 
 void paging_init(void);
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index d466ec670e1f..eea147b1a617 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -38,9 +38,9 @@  EXPORT_SYMBOL(kernel_map);
 #endif
 
 #ifdef CONFIG_64BIT
-u64 satp_mode __ro_after_init = !IS_ENABLED(CONFIG_XIP_KERNEL) ? SATP_MODE_57 : SATP_MODE_39;
+ulong satp_mode __ro_after_init = !IS_ENABLED(CONFIG_XIP_KERNEL) ? SATP_MODE_57 : SATP_MODE_39;
 #else
-u64 satp_mode __ro_after_init = SATP_MODE_32;
+ulong satp_mode __ro_after_init = SATP_MODE_32;
 #endif
 EXPORT_SYMBOL(satp_mode);