Re: [PATCH v1 09/11] powerpc/64s: Make hash MMU code build configurable

2021-10-19 Thread Nicholas Piggin
Excerpts from Christophe Leroy's message of October 19, 2021 6:05 pm:
> 
> 
> Le 15/10/2021 à 17:46, Nicholas Piggin a écrit :
>> Introduce a new option CONFIG_PPC_64S_HASH_MMU which allows the 64s hash
>> MMU code to be compiled out if radix is selected and the minimum
>> supported CPU type is POWER9 or higher, and KVM is not selected.
>> 
>> This saves 128kB kernel image size (90kB text) on powernv_defconfig
>> minus KVM, 350kB on pseries_defconfig minus KVM, 40kB on a tiny config.
> 
> This patch is huge, it could be split in several smaller patches ?
> 
> I'm sure at least the Kconfig stuff can be do as a second step. In first 
> step just make CONFIG_PPC_64S_HASH_MMU always y.

I can do that.

> 
> I'm wondering if we could also reduce the amount of #ifdefs in C files, 
> by using IS_ENABLED() and/or stubs defined in H files.

I didn't see a lot of low hanging things there. A lot of it is struct
members and globals and things. E.g., something like this -

@@ -175,7 +181,9 @@ static int radix__init_new_context(struct mm_struct *mm)
 */
asm volatile("ptesync;isync" : : : "memory");
 
+#ifdef CONFIG_PPC_64S_HASH_MMU
mm->context.hash_context = NULL;
+#endif
 
return index;
 }

In theory we could add a mm_set_hash_context(mm, NULL) function to do 
this for us, but if it is only required in this one bit of radix init
code then I would say the new function actually adds a reading burden
on all the rest of the code that uses it (or if we only use it in
this one place then it's pretty pointless).

> 
>> 
>> Signed-off-by: Nicholas Piggin 
>> ---
>>   arch/powerpc/Kconfig  |  1 +
>>   arch/powerpc/include/asm/book3s/64/mmu.h  | 22 ++-
>>   .../include/asm/book3s/64/tlbflush-hash.h |  7 ++
>>   arch/powerpc/include/asm/book3s/pgtable.h |  4 
>>   arch/powerpc/include/asm/mmu.h| 14 +---
>>   arch/powerpc/include/asm/mmu_context.h|  2 ++
>>   arch/powerpc/include/asm/paca.h   |  8 +++
>>   arch/powerpc/kernel/asm-offsets.c |  2 ++
>>   arch/powerpc/kernel/dt_cpu_ftrs.c |  8 ++-
>>   arch/powerpc/kernel/entry_64.S|  4 ++--
>>   arch/powerpc/kernel/exceptions-64s.S  | 16 ++
>>   arch/powerpc/kernel/mce.c |  2 +-
>>   arch/powerpc/kernel/mce_power.c   | 10 ++---
>>   arch/powerpc/kernel/paca.c| 18 ++-
>>   arch/powerpc/kernel/process.c | 13 ++-
>>   arch/powerpc/kernel/prom.c|  2 ++
>>   arch/powerpc/kernel/setup_64.c|  4 
>>   arch/powerpc/kexec/core_64.c  |  4 ++--
>>   arch/powerpc/kexec/ranges.c   |  4 
>>   arch/powerpc/kvm/Kconfig  |  1 +
>>   arch/powerpc/mm/book3s64/Makefile | 17 --
>>   arch/powerpc/mm/book3s64/hash_utils.c | 10 -
>>   .../{hash_hugetlbpage.c => hugetlbpage.c} |  6 +
>>   arch/powerpc/mm/book3s64/mmu_context.c| 16 ++
>>   arch/powerpc/mm/book3s64/pgtable.c| 12 ++
>>   arch/powerpc/mm/book3s64/radix_pgtable.c  |  4 
>>   arch/powerpc/mm/copro_fault.c |  2 ++
>>   arch/powerpc/mm/pgtable.c | 10 ++---
>>   arch/powerpc/platforms/Kconfig.cputype| 21 +-
>>   arch/powerpc/platforms/cell/Kconfig   |  1 +
>>   arch/powerpc/platforms/maple/Kconfig  |  1 +
>>   arch/powerpc/platforms/microwatt/Kconfig  |  2 +-
>>   arch/powerpc/platforms/pasemi/Kconfig |  1 +
>>   arch/powerpc/platforms/powermac/Kconfig   |  1 +
>>   arch/powerpc/platforms/powernv/Kconfig|  2 +-
>>   arch/powerpc/platforms/powernv/idle.c |  2 ++
>>   arch/powerpc/platforms/powernv/setup.c|  2 ++
>>   arch/powerpc/platforms/pseries/lpar.c | 11 --
>>   arch/powerpc/platforms/pseries/lparcfg.c  |  2 +-
>>   arch/powerpc/platforms/pseries/mobility.c |  6 +
>>   arch/powerpc/platforms/pseries/ras.c  |  2 ++
>>   arch/powerpc/platforms/pseries/reconfig.c |  2 ++
>>   arch/powerpc/platforms/pseries/setup.c|  6 +++--
>>   arch/powerpc/xmon/xmon.c  |  8 +--
>>   44 files changed, 233 insertions(+), 60 deletions(-)
>>   rename arch/powerpc/mm/book3s64/{hash_hugetlbpage.c => hugetlbpage.c} (95%)
>> 
> 
>> diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h
>> index 8abe8e42e045..0f89fcab834d 100644
>> --- a/arch/powerpc/include/asm/mmu.h
>> +++ b/arch/powerpc/include/asm/mmu.h
>> @@ -157,7 +157,7 @@ DECLARE_PER_CPU(int, next_tlbcam_idx);
>>   
>>   enum {
>>  MMU_FTRS_POSSIBLE =
>> -#if defined(CONFIG_PPC_BOOK3S_64) || defined(CONFIG_PPC_BOOK3S_604)
>> +#if defined(CONFIG_PPC_BOOK3S_604)
>>  MMU_FTR_HPTE_TABLE |
>>   #endif
>>   #ifdef CO

Re: [PATCH v1 09/11] powerpc/64s: Make hash MMU code build configurable

2021-10-19 Thread Christophe Leroy




Le 15/10/2021 à 17:46, Nicholas Piggin a écrit :

Introduce a new option CONFIG_PPC_64S_HASH_MMU which allows the 64s hash
MMU code to be compiled out if radix is selected and the minimum
supported CPU type is POWER9 or higher, and KVM is not selected.

This saves 128kB kernel image size (90kB text) on powernv_defconfig
minus KVM, 350kB on pseries_defconfig minus KVM, 40kB on a tiny config.


This patch is huge, it could be split in several smaller patches ?

I'm sure at least the Kconfig stuff can be do as a second step. In first 
step just make CONFIG_PPC_64S_HASH_MMU always y.


I'm wondering if we could also reduce the amount of #ifdefs in C files, 
by using IS_ENABLED() and/or stubs defined in H files.




Signed-off-by: Nicholas Piggin 
---
  arch/powerpc/Kconfig  |  1 +
  arch/powerpc/include/asm/book3s/64/mmu.h  | 22 ++-
  .../include/asm/book3s/64/tlbflush-hash.h |  7 ++
  arch/powerpc/include/asm/book3s/pgtable.h |  4 
  arch/powerpc/include/asm/mmu.h| 14 +---
  arch/powerpc/include/asm/mmu_context.h|  2 ++
  arch/powerpc/include/asm/paca.h   |  8 +++
  arch/powerpc/kernel/asm-offsets.c |  2 ++
  arch/powerpc/kernel/dt_cpu_ftrs.c |  8 ++-
  arch/powerpc/kernel/entry_64.S|  4 ++--
  arch/powerpc/kernel/exceptions-64s.S  | 16 ++
  arch/powerpc/kernel/mce.c |  2 +-
  arch/powerpc/kernel/mce_power.c   | 10 ++---
  arch/powerpc/kernel/paca.c| 18 ++-
  arch/powerpc/kernel/process.c | 13 ++-
  arch/powerpc/kernel/prom.c|  2 ++
  arch/powerpc/kernel/setup_64.c|  4 
  arch/powerpc/kexec/core_64.c  |  4 ++--
  arch/powerpc/kexec/ranges.c   |  4 
  arch/powerpc/kvm/Kconfig  |  1 +
  arch/powerpc/mm/book3s64/Makefile | 17 --
  arch/powerpc/mm/book3s64/hash_utils.c | 10 -
  .../{hash_hugetlbpage.c => hugetlbpage.c} |  6 +
  arch/powerpc/mm/book3s64/mmu_context.c| 16 ++
  arch/powerpc/mm/book3s64/pgtable.c| 12 ++
  arch/powerpc/mm/book3s64/radix_pgtable.c  |  4 
  arch/powerpc/mm/copro_fault.c |  2 ++
  arch/powerpc/mm/pgtable.c | 10 ++---
  arch/powerpc/platforms/Kconfig.cputype| 21 +-
  arch/powerpc/platforms/cell/Kconfig   |  1 +
  arch/powerpc/platforms/maple/Kconfig  |  1 +
  arch/powerpc/platforms/microwatt/Kconfig  |  2 +-
  arch/powerpc/platforms/pasemi/Kconfig |  1 +
  arch/powerpc/platforms/powermac/Kconfig   |  1 +
  arch/powerpc/platforms/powernv/Kconfig|  2 +-
  arch/powerpc/platforms/powernv/idle.c |  2 ++
  arch/powerpc/platforms/powernv/setup.c|  2 ++
  arch/powerpc/platforms/pseries/lpar.c | 11 --
  arch/powerpc/platforms/pseries/lparcfg.c  |  2 +-
  arch/powerpc/platforms/pseries/mobility.c |  6 +
  arch/powerpc/platforms/pseries/ras.c  |  2 ++
  arch/powerpc/platforms/pseries/reconfig.c |  2 ++
  arch/powerpc/platforms/pseries/setup.c|  6 +++--
  arch/powerpc/xmon/xmon.c  |  8 +--
  44 files changed, 233 insertions(+), 60 deletions(-)
  rename arch/powerpc/mm/book3s64/{hash_hugetlbpage.c => hugetlbpage.c} (95%)




diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h
index 8abe8e42e045..0f89fcab834d 100644
--- a/arch/powerpc/include/asm/mmu.h
+++ b/arch/powerpc/include/asm/mmu.h
@@ -157,7 +157,7 @@ DECLARE_PER_CPU(int, next_tlbcam_idx);
  
  enum {

MMU_FTRS_POSSIBLE =
-#if defined(CONFIG_PPC_BOOK3S_64) || defined(CONFIG_PPC_BOOK3S_604)
+#if defined(CONFIG_PPC_BOOK3S_604)
MMU_FTR_HPTE_TABLE |
  #endif
  #ifdef CONFIG_PPC_8xx
@@ -184,15 +184,18 @@ enum {
MMU_FTR_USE_TLBRSRV | MMU_FTR_USE_PAIRED_MAS |
  #endif
  #ifdef CONFIG_PPC_BOOK3S_64
+   MMU_FTR_KERNEL_RO |
+#ifdef CONFIG_PPC_64S_HASH_MMU
MMU_FTR_NO_SLBIE_B | MMU_FTR_16M_PAGE | MMU_FTR_TLBIEL |
MMU_FTR_LOCKLESS_TLBIE | MMU_FTR_CI_LARGE_PAGE |
MMU_FTR_1T_SEGMENT | MMU_FTR_TLBIE_CROP_VA |
-   MMU_FTR_KERNEL_RO | MMU_FTR_68_BIT_VA |
+   MMU_FTR_68_BIT_VA | MMU_FTR_HPTE_TABLE |
  #endif
  #ifdef CONFIG_PPC_RADIX_MMU
MMU_FTR_TYPE_RADIX |
MMU_FTR_GTSE |
  #endif /* CONFIG_PPC_RADIX_MMU */
+#endif
  #ifdef CONFIG_PPC_KUAP
MMU_FTR_BOOK3S_KUAP |
  #endif /* CONFIG_PPC_KUAP */
@@ -223,6 +226,11 @@ enum {
  #ifdef CONFIG_E500
  #define MMU_FTRS_ALWAYS   MMU_FTR_TYPE_FSL_E
  #endif
+#ifdef CONFIG_PPC_BOOK3S_64
+#if defined(CONFIG_PPC_RADIX_MMU) && !defined(CONFIG_PPC_64S_HASH_MMU)
+#define MMU_FTRS_ALWAYS 

[PATCH v1 09/11] powerpc/64s: Make hash MMU code build configurable

2021-10-15 Thread Nicholas Piggin
Introduce a new option CONFIG_PPC_64S_HASH_MMU which allows the 64s hash
MMU code to be compiled out if radix is selected and the minimum
supported CPU type is POWER9 or higher, and KVM is not selected.

This saves 128kB kernel image size (90kB text) on powernv_defconfig
minus KVM, 350kB on pseries_defconfig minus KVM, 40kB on a tiny config.

Signed-off-by: Nicholas Piggin 
---
 arch/powerpc/Kconfig  |  1 +
 arch/powerpc/include/asm/book3s/64/mmu.h  | 22 ++-
 .../include/asm/book3s/64/tlbflush-hash.h |  7 ++
 arch/powerpc/include/asm/book3s/pgtable.h |  4 
 arch/powerpc/include/asm/mmu.h| 14 +---
 arch/powerpc/include/asm/mmu_context.h|  2 ++
 arch/powerpc/include/asm/paca.h   |  8 +++
 arch/powerpc/kernel/asm-offsets.c |  2 ++
 arch/powerpc/kernel/dt_cpu_ftrs.c |  8 ++-
 arch/powerpc/kernel/entry_64.S|  4 ++--
 arch/powerpc/kernel/exceptions-64s.S  | 16 ++
 arch/powerpc/kernel/mce.c |  2 +-
 arch/powerpc/kernel/mce_power.c   | 10 ++---
 arch/powerpc/kernel/paca.c| 18 ++-
 arch/powerpc/kernel/process.c | 13 ++-
 arch/powerpc/kernel/prom.c|  2 ++
 arch/powerpc/kernel/setup_64.c|  4 
 arch/powerpc/kexec/core_64.c  |  4 ++--
 arch/powerpc/kexec/ranges.c   |  4 
 arch/powerpc/kvm/Kconfig  |  1 +
 arch/powerpc/mm/book3s64/Makefile | 17 --
 arch/powerpc/mm/book3s64/hash_utils.c | 10 -
 .../{hash_hugetlbpage.c => hugetlbpage.c} |  6 +
 arch/powerpc/mm/book3s64/mmu_context.c| 16 ++
 arch/powerpc/mm/book3s64/pgtable.c| 12 ++
 arch/powerpc/mm/book3s64/radix_pgtable.c  |  4 
 arch/powerpc/mm/copro_fault.c |  2 ++
 arch/powerpc/mm/pgtable.c | 10 ++---
 arch/powerpc/platforms/Kconfig.cputype| 21 +-
 arch/powerpc/platforms/cell/Kconfig   |  1 +
 arch/powerpc/platforms/maple/Kconfig  |  1 +
 arch/powerpc/platforms/microwatt/Kconfig  |  2 +-
 arch/powerpc/platforms/pasemi/Kconfig |  1 +
 arch/powerpc/platforms/powermac/Kconfig   |  1 +
 arch/powerpc/platforms/powernv/Kconfig|  2 +-
 arch/powerpc/platforms/powernv/idle.c |  2 ++
 arch/powerpc/platforms/powernv/setup.c|  2 ++
 arch/powerpc/platforms/pseries/lpar.c | 11 --
 arch/powerpc/platforms/pseries/lparcfg.c  |  2 +-
 arch/powerpc/platforms/pseries/mobility.c |  6 +
 arch/powerpc/platforms/pseries/ras.c  |  2 ++
 arch/powerpc/platforms/pseries/reconfig.c |  2 ++
 arch/powerpc/platforms/pseries/setup.c|  6 +++--
 arch/powerpc/xmon/xmon.c  |  8 +--
 44 files changed, 233 insertions(+), 60 deletions(-)
 rename arch/powerpc/mm/book3s64/{hash_hugetlbpage.c => hugetlbpage.c} (95%)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index ba5b66189358..3c36511e6133 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -936,6 +936,7 @@ config PPC_MEM_KEYS
prompt "PowerPC Memory Protection Keys"
def_bool y
depends on PPC_BOOK3S_64
+   depends on PPC_64S_HASH_MMU
select ARCH_USES_HIGH_VMA_FLAGS
select ARCH_HAS_PKEYS
help
diff --git a/arch/powerpc/include/asm/book3s/64/mmu.h 
b/arch/powerpc/include/asm/book3s/64/mmu.h
index c02f42d1031e..857dc88b0043 100644
--- a/arch/powerpc/include/asm/book3s/64/mmu.h
+++ b/arch/powerpc/include/asm/book3s/64/mmu.h
@@ -98,7 +98,9 @@ typedef struct {
 * from EA and new context ids to build the new VAs.
 */
mm_context_id_t id;
+#ifdef CONFIG_PPC_64S_HASH_MMU
mm_context_id_t extended_id[TASK_SIZE_USER64/TASK_CONTEXT_SIZE];
+#endif
};
 
/* Number of bits in the mm_cpumask */
@@ -110,7 +112,9 @@ typedef struct {
/* Number of user space windows opened in process mm_context */
atomic_t vas_windows;
 
+#ifdef CONFIG_PPC_64S_HASH_MMU
struct hash_mm_context *hash_context;
+#endif
 
void __user *vdso;
/*
@@ -133,6 +137,7 @@ typedef struct {
 #endif
 } mm_context_t;
 
+#ifdef CONFIG_PPC_64S_HASH_MMU
 static inline u16 mm_ctx_user_psize(mm_context_t *ctx)
 {
return ctx->hash_context->user_psize;
@@ -187,11 +192,22 @@ static inline struct subpage_prot_table 
*mm_ctx_subpage_prot(mm_context_t *ctx)
 }
 #endif
 
+#endif
+
 /*
  * The current system page and segment sizes
  */
-extern int mmu_linear_psize;
+#if defined(CONFIG_PPC_RADIX_MMU) && !defined(CONFIG_PPC_64S_HASH_MMU)
+#ifdef CONFIG_PPC_64K_PAGES
+#define mmu_virtual_psize MMU_PAGE_64K
+#else
+#define mmu_virtual_psize MMU_PAGE_4K
+#endif
+#else
 extern int mmu_virtual_psize;