Re: [PATCH RFC 3/3] powerpc/64: Enable use of radix MMU under hypervisor on POWER9

2016-12-05 Thread Paul Mackerras
On Mon, Dec 05, 2016 at 07:55:32PM +1100, Benjamin Herrenschmidt wrote:
> On Mon, 2016-12-05 at 19:04 +1100, Paul Mackerras wrote:
> > +   vec5 = of_get_flat_dt_prop(chosen, "ibm,architecture-vec-5", &size);
> > +   if (!vec5 || size <= OV5_INDX(OV5_MMU_RADIX_300))
> > +   return;
> 
> Could be bike shedding but shouldn't we first check if
> we are in an LPAR and bail out of we are not, then
> if we *are* and the above size is too small to contain
> the ARCH 3.00 options, also disable radix as obviously
> the hypervisor doesn't know about it ?

This is *very* early on, so early that we haven't yet decided what
platform we're on.  If we're not in an LPAR then we won't have a
/chosen/ibm-architecture-vec-5 property.  Any hypervisor that is too
old to have that property will also be too old to set the radix
bit in the ibm,pa-features property, so we won't use radix.

If we do have the property but it's short then yes that's a good
indication that the hypervisor can't do radix, though in that case
it's strange that it set the radix bit in the ibm,pa-features property
(which must have been set otherwise we wouldn't have got here).

I'll do a new patch.

> > +   if (!(vec5[OV5_INDX(OV5_MMU_RADIX_300)] & 
> > OV5_FEAT(OV5_MMU_RADIX_300)))
> > +   /* Hypervisor doesn't support radix */
> > +   cur_cpu_spec->mmu_features &= ~MMU_FTR_TYPE_RADIX;
> > +}
> > +

Paul.


Re: [PATCH RFC 3/3] powerpc/64: Enable use of radix MMU under hypervisor on POWER9

2016-12-05 Thread Benjamin Herrenschmidt
On Mon, 2016-12-05 at 19:04 +1100, Paul Mackerras wrote:
> +   vec5 = of_get_flat_dt_prop(chosen, "ibm,architecture-vec-5", &size);
> +   if (!vec5 || size <= OV5_INDX(OV5_MMU_RADIX_300))
> +   return;

Could be bike shedding but shouldn't we first check if
we are in an LPAR and bail out of we are not, then
if we *are* and the above size is too small to contain
the ARCH 3.00 options, also disable radix as obviously
the hypervisor doesn't know about it ?

> +   if (!(vec5[OV5_INDX(OV5_MMU_RADIX_300)] & 
> OV5_FEAT(OV5_MMU_RADIX_300)))
> +   /* Hypervisor doesn't support radix */
> +   cur_cpu_spec->mmu_features &= ~MMU_FTR_TYPE_RADIX;
> +}
> +



[PATCH RFC 3/3] powerpc/64: Enable use of radix MMU under hypervisor on POWER9

2016-12-05 Thread Paul Mackerras
To use radix as a guest, we first need to tell the hypervisor via
the ibm,client-architecture call first that we support POWER9 and
architecture v3.00, and that we can do either radix or hash and
that we would like to choose later using an hcall (the
H_REGISTER_PROC_TBL hcall).

Then we need to check whether the hypervisor agreed to us using
radix.  We need to do this very early on in the kernel boot process
before any of the MMU initialization is done.  If the hypervisor
doesn't agree, we can't use radix and therefore clear the radix
MMU feature bit.

Later, when we have set up our process table, which points to the
radix tree for each process, we need to install that using the
H_REGISTER_PROC_TBL hcall.

Signed-off-by: Paul Mackerras 
---
 arch/powerpc/include/asm/book3s/64/mmu.h |  2 ++
 arch/powerpc/include/asm/hvcall.h| 11 +++
 arch/powerpc/include/asm/prom.h  |  9 +
 arch/powerpc/kernel/prom_init.c  | 18 +-
 arch/powerpc/mm/init_64.c| 28 
 arch/powerpc/mm/pgtable-radix.c  |  2 ++
 arch/powerpc/platforms/pseries/lpar.c| 29 +
 7 files changed, 98 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/book3s/64/mmu.h 
b/arch/powerpc/include/asm/book3s/64/mmu.h
index 8afb0e0..e8cbdc0 100644
--- a/arch/powerpc/include/asm/book3s/64/mmu.h
+++ b/arch/powerpc/include/asm/book3s/64/mmu.h
@@ -138,5 +138,7 @@ static inline void setup_initial_memory_limit(phys_addr_t 
first_memblock_base,
 extern int (*register_process_table)(unsigned long base, unsigned long 
page_size,
 unsigned long tbl_size);
 
+extern void radix_init_pseries(void);
+
 #endif /* __ASSEMBLY__ */
 #endif /* _ASM_POWERPC_BOOK3S_64_MMU_H_ */
diff --git a/arch/powerpc/include/asm/hvcall.h 
b/arch/powerpc/include/asm/hvcall.h
index 77ff1ba..54d11b3 100644
--- a/arch/powerpc/include/asm/hvcall.h
+++ b/arch/powerpc/include/asm/hvcall.h
@@ -276,6 +276,7 @@
 #define H_GET_MPP_X0x314
 #define H_SET_MODE 0x31C
 #define H_CLEAR_HPT0x358
+#define H_REGISTER_PROC_TBL0x37C
 #define H_SIGNAL_SYS_RESET 0x380
 #define MAX_HCALL_OPCODE   H_SIGNAL_SYS_RESET
 
@@ -313,6 +314,16 @@
 #define H_SIGNAL_SYS_RESET_ALL_OTHERS  -2
 /* >= 0 values are CPU number */
 
+/* Flag values used in H_REGISTER_PROC_TBL hcall */
+#define PROC_TABLE_OP_MASK 0x18
+#define PROC_TABLE_DEREG   0x10
+#define PROC_TABLE_NEW 0x18
+#define PROC_TABLE_TYPE_MASK   0x06
+#define PROC_TABLE_HPT_SLB 0x00
+#define PROC_TABLE_HPT_PT  0x02
+#define PROC_TABLE_RADIX   0x04
+#define PROC_TABLE_GTSE0x01
+
 #ifndef __ASSEMBLY__
 
 /**
diff --git a/arch/powerpc/include/asm/prom.h b/arch/powerpc/include/asm/prom.h
index e6d83d0..8af2546 100644
--- a/arch/powerpc/include/asm/prom.h
+++ b/arch/powerpc/include/asm/prom.h
@@ -121,6 +121,8 @@ struct of_drconf_cell {
 #define OV1_PPC_2_06   0x02/* set if we support PowerPC 2.06 */
 #define OV1_PPC_2_07   0x01/* set if we support PowerPC 2.07 */
 
+#define OV1_PPC_3_00   0x80/* set if we support PowerPC 3.00 */
+
 /* Option vector 2: Open Firmware options supported */
 #define OV2_REAL_MODE  0x20/* set if we want OF in real mode */
 
@@ -155,6 +157,13 @@ struct of_drconf_cell {
 #define OV5_PFO_HW_842 0x1140  /* PFO Compression Accelerator */
 #define OV5_PFO_HW_ENCR0x1120  /* PFO Encryption Accelerator */
 #define OV5_SUB_PROCESSORS 0x1501  /* 1,2,or 4 Sub-Processors supported */
+#define OV5_XIVE_EXPLOIT   0x1701  /* XIVE exploitation supported */
+#define OV5_MMU_RADIX_300  0x1880  /* ISA v3.00 radix MMU supported */
+#define OV5_MMU_HASH_300   0x1840  /* ISA v3.00 hash MMU supported */
+#define OV5_MMU_SEGM_RADIX 0x1820  /* radix mode (no segmentation) */
+#define OV5_MMU_PROC_TBL   0x1810  /* hcall selects SLB or proc table */
+#define OV5_MMU_SLB0x1800  /* always use SLB */
+#define OV5_MMU_GTSE   0x1808  /* Guest translation shootdown */
 
 /* Option Vector 6: IBM PAPR hints */
 #define OV6_LINUX  0x02/* Linux is our OS */
diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index ec47a93..358d43f 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -649,6 +649,7 @@ static void __init early_cmdline_parse(void)
 struct option_vector1 {
u8 byte1;
u8 arch_versions;
+   u8 arch_versions3;
 } __packed;
 
 struct option_vector2 {
@@ -691,6 +692,9 @@ struct option_vector5 {
u8 reserved2;
__be16 reserved3;
u8 subprocessors;
+   u8 byte22;
+   u8 intarch;
+   u8 mmu;
 } __packed;
 
 struct option_vector6 {
@@ -700,7 +704,7 @@ struct option_vector6 {
 } __packed;
 
 struct ibm_arch_vec {
-   struct { u32 mask, val; } pvrs[10];
+