powerpc/64s: Get LPID bit width from device tree

Allow the LPID bit width and partition table size to be set at runtime
from the device tree.

Move the PID bit width detection into the same place.

KVM does not support using the extra bits yet, this is mainly required
to get the PTCR register values correct (so KVM will run but it will
not allocate > 4096 LPIDs).

OPAL firmware provides this property for POWER10 CPUs since skiboot
commit 9b85f7d961f2 ("hdata: add mmu-pid-bits and mmu-lpid-bits for
POWER10 CPUs").

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Fabiano Rosas <farosas@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20211129030915.1888332-1-npiggin@gmail.com
This commit is contained in:
Nicholas Piggin 2021-11-29 13:09:15 +10:00 committed by Michael Ellerman
parent 2c9ac51b85
commit 5402e239d0
4 changed files with 51 additions and 22 deletions

View File

@ -62,6 +62,9 @@ extern struct patb_entry *partition_tb;
#define PRTS_MASK 0x1f /* process table size field */ #define PRTS_MASK 0x1f /* process table size field */
#define PRTB_MASK 0x0ffffffffffff000UL #define PRTB_MASK 0x0ffffffffffff000UL
/* Number of supported LPID bits */
extern unsigned int mmu_lpid_bits;
/* Number of supported PID bits */ /* Number of supported PID bits */
extern unsigned int mmu_pid_bits; extern unsigned int mmu_pid_bits;
@ -76,10 +79,8 @@ extern unsigned long __ro_after_init radix_mem_block_size;
#define PRTB_SIZE_SHIFT (mmu_pid_bits + 4) #define PRTB_SIZE_SHIFT (mmu_pid_bits + 4)
#define PRTB_ENTRIES (1ul << mmu_pid_bits) #define PRTB_ENTRIES (1ul << mmu_pid_bits)
/* #define PATB_SIZE_SHIFT (mmu_lpid_bits + 4)
* Power9 currently only support 64K partition table size. #define PATB_ENTRIES (1ul << mmu_lpid_bits)
*/
#define PATB_SIZE_SHIFT 16
typedef unsigned long mm_context_id_t; typedef unsigned long mm_context_id_t;
struct spinlock; struct spinlock;

View File

@ -207,17 +207,12 @@ void __init mmu_partition_table_init(void)
unsigned long patb_size = 1UL << PATB_SIZE_SHIFT; unsigned long patb_size = 1UL << PATB_SIZE_SHIFT;
unsigned long ptcr; unsigned long ptcr;
BUILD_BUG_ON_MSG((PATB_SIZE_SHIFT > 36), "Partition table size too large.");
/* Initialize the Partition Table with no entries */ /* Initialize the Partition Table with no entries */
partition_tb = memblock_alloc(patb_size, patb_size); partition_tb = memblock_alloc(patb_size, patb_size);
if (!partition_tb) if (!partition_tb)
panic("%s: Failed to allocate %lu bytes align=0x%lx\n", panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
__func__, patb_size, patb_size); __func__, patb_size, patb_size);
/*
* update partition table control register,
* 64 K size.
*/
ptcr = __pa(partition_tb) | (PATB_SIZE_SHIFT - 12); ptcr = __pa(partition_tb) | (PATB_SIZE_SHIFT - 12);
set_ptcr_when_no_uv(ptcr); set_ptcr_when_no_uv(ptcr);
powernv_set_nmmu_ptcr(ptcr); powernv_set_nmmu_ptcr(ptcr);

View File

@ -33,7 +33,6 @@
#include <trace/events/thp.h> #include <trace/events/thp.h>
unsigned int mmu_pid_bits;
unsigned int mmu_base_pid; unsigned int mmu_base_pid;
unsigned long radix_mem_block_size __ro_after_init; unsigned long radix_mem_block_size __ro_after_init;
@ -357,18 +356,13 @@ static void __init radix_init_pgtable(void)
-1, PAGE_KERNEL)); -1, PAGE_KERNEL));
} }
/* Find out how many PID bits are supported */
if (!cpu_has_feature(CPU_FTR_HVMODE) && if (!cpu_has_feature(CPU_FTR_HVMODE) &&
cpu_has_feature(CPU_FTR_P9_RADIX_PREFETCH_BUG)) { cpu_has_feature(CPU_FTR_P9_RADIX_PREFETCH_BUG)) {
/* /*
* Older versions of KVM on these machines perfer if the * Older versions of KVM on these machines perfer if the
* guest only uses the low 19 PID bits. * guest only uses the low 19 PID bits.
*/ */
if (!mmu_pid_bits)
mmu_pid_bits = 19; mmu_pid_bits = 19;
} else {
if (!mmu_pid_bits)
mmu_pid_bits = 20;
} }
mmu_base_pid = 1; mmu_base_pid = 1;
@ -449,11 +443,6 @@ static int __init radix_dt_scan_page_sizes(unsigned long node,
if (type == NULL || strcmp(type, "cpu") != 0) if (type == NULL || strcmp(type, "cpu") != 0)
return 0; return 0;
/* Find MMU PID size */
prop = of_get_flat_dt_prop(node, "ibm,mmu-pid-bits", &size);
if (prop && size == 4)
mmu_pid_bits = be32_to_cpup(prop);
/* Grab page size encodings */ /* Grab page size encodings */
prop = of_get_flat_dt_prop(node, "ibm,processor-radix-AP-encodings", &size); prop = of_get_flat_dt_prop(node, "ibm,processor-radix-AP-encodings", &size);
if (!prop) if (!prop)

View File

@ -370,6 +370,9 @@ void register_page_bootmem_memmap(unsigned long section_nr,
#endif /* CONFIG_SPARSEMEM_VMEMMAP */ #endif /* CONFIG_SPARSEMEM_VMEMMAP */
#ifdef CONFIG_PPC_BOOK3S_64 #ifdef CONFIG_PPC_BOOK3S_64
unsigned int mmu_lpid_bits;
unsigned int mmu_pid_bits;
static bool disable_radix = !IS_ENABLED(CONFIG_PPC_RADIX_MMU_DEFAULT); static bool disable_radix = !IS_ENABLED(CONFIG_PPC_RADIX_MMU_DEFAULT);
static int __init parse_disable_radix(char *p) static int __init parse_disable_radix(char *p)
@ -437,19 +440,60 @@ static void __init early_check_vec5(void)
} }
} }
static int __init dt_scan_mmu_pid_width(unsigned long node,
const char *uname, int depth,
void *data)
{
int size = 0;
const __be32 *prop;
const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
/* We are scanning "cpu" nodes only */
if (type == NULL || strcmp(type, "cpu") != 0)
return 0;
/* Find MMU LPID, PID register size */
prop = of_get_flat_dt_prop(node, "ibm,mmu-lpid-bits", &size);
if (prop && size == 4)
mmu_lpid_bits = be32_to_cpup(prop);
prop = of_get_flat_dt_prop(node, "ibm,mmu-pid-bits", &size);
if (prop && size == 4)
mmu_pid_bits = be32_to_cpup(prop);
if (!mmu_pid_bits && !mmu_lpid_bits)
return 0;
return 1;
}
void __init mmu_early_init_devtree(void) void __init mmu_early_init_devtree(void)
{ {
bool hvmode = !!(mfmsr() & MSR_HV);
/* Disable radix mode based on kernel command line. */ /* Disable radix mode based on kernel command line. */
if (disable_radix) if (disable_radix)
cur_cpu_spec->mmu_features &= ~MMU_FTR_TYPE_RADIX; cur_cpu_spec->mmu_features &= ~MMU_FTR_TYPE_RADIX;
of_scan_flat_dt(dt_scan_mmu_pid_width, NULL);
if (hvmode && !mmu_lpid_bits) {
if (early_cpu_has_feature(CPU_FTR_ARCH_207S))
mmu_lpid_bits = 12; /* POWER8-10 */
else
mmu_lpid_bits = 10; /* POWER7 */
}
if (!mmu_pid_bits) {
if (early_cpu_has_feature(CPU_FTR_ARCH_300))
mmu_pid_bits = 20; /* POWER9-10 */
}
/* /*
* Check /chosen/ibm,architecture-vec-5 if running as a guest. * Check /chosen/ibm,architecture-vec-5 if running as a guest.
* When running bare-metal, we can use radix if we like * When running bare-metal, we can use radix if we like
* even though the ibm,architecture-vec-5 property created by * even though the ibm,architecture-vec-5 property created by
* skiboot doesn't have the necessary bits set. * skiboot doesn't have the necessary bits set.
*/ */
if (!(mfmsr() & MSR_HV)) if (!hvmode)
early_check_vec5(); early_check_vec5();
if (early_radix_enabled()) { if (early_radix_enabled()) {