xen/arm: arm64: Widen register access to mpidr to 64-bits
v3 cover xen/arm: arm64: Widen register access to mpidr to 64-bits
In ARM64 the MPIDR register is mapped to MPIDR_EL1, and the register bits are expanded to 64-bits. But Xen 64-bit ARM code treats this it as 32-bit register.
We have to provide correct accessing to this register to avoid unexpected issues that is caused by incorrect MPIDR value.
Wei Chen (4):
xen/arm: Change the variable type of cpu_logical_map to register_t xen/arm: Make AFFINITY_MASK generate correct mask for level3 xen:arm: arm64: Add correct MPIDR_HWID_MASK value for ARM64 xen/arm: arm64: Remove MPIDR multiprocessing extensions check
xen/arch/arm/arm64/head.S | 3 +-- xen/arch/arm/gic-v3.c | 2 +- xen/arch/arm/smpboot.c | 13 +++++++------ xen/include/asm-arm/processor.h | 9 +++++++-- 4 files changed, 16 insertions(+), 11 deletions(-)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v3 1/4 xen/arm: Change the variable type of cpu_logical_map to register_t
The cpu_logical_map is used to store CPU hardware ID from MPIDR_EL1 or from CPU node of DT. Currently, the cpu_logical_map is using the u32 as its variable type. It can work properly while Xen is running on ARM32, because the hardware ID is 32-bits. While Xen is running on ARM64, the hardware ID expands to 64-bits and then the cpu_logical_map will overflow.
Change the variable type of cpu_logical_map to register_t will make cpu_logical_map to store hardware IDs correctly on ARM32 and ARM64.
---
v2-->v3:
1. Update verion number.
v1-->v2:
1. Fix typos in commit messages that were commented by Julien.
2. Add Julien's Acked-by.
--- xen/arch/arm/gic-v3.c | 2 +- xen/arch/arm/smpboot.c | 13 +++++++------ xen/include/asm-arm/processor.h | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-)
xen/arch/arm/gic-v3.c +1 -1
@@ -674,7 +674,7 @@ static int __init gicv3_populate_rdist(void) }while ( !(typer &GICR_TYPER_LAST ) ); } -dprintk (XENLOG_ERR ,"GICv3: CPU%d: mpidr 0x%x has no re-distributor!\n" , +dprintk (XENLOG_ERR ,"GICv3: CPU%d: mpidr 0x%" PRIregister" has no re-distributor!\n" ,smp_processor_id (),cpu_logical_map (smp_processor_id ()));return -ENODEV ;
xen/arch/arm/smpboot.c +7 -6
@@ -40,7 +40,7 @@ cpumask_t cpu_possible_map;struct cpuinfo_arm cpu_data[NR_CPUS ];/* CPU logical map: map xen cpuid to an MPIDR */ -u32 __cpu_logical_map[NR_CPUS ] = { [0 ...NR_CPUS -1 ] =MPIDR_INVALID }; +register_t __cpu_logical_map[NR_CPUS ] = { [0 ...NR_CPUS -1 ] =MPIDR_INVALID };/* Fake one node for now. See also include/asm-arm/numa.h */ nodemask_t __read_mostly node_online_map = { { [0 ] =1UL } };
@@ -100,7 +100,7 @@ static void __init dt_smp_init_cpus(void)struct dt_device_node *cpu;unsigned int i, j;unsigned int cpuidx =1 ; -static u32 tmp_map[NR_CPUS ]__initdata = +static register_t tmp_map[NR_CPUS ]__initdata = { [0 ...NR_CPUS -1 ] =MPIDR_INVALID };
@@ -120,7 +120,8 @@ static void __init dt_smp_init_cpus(void) {const __be32 *prop;u64 addr; -u32 reg_len, hwid; +u32 reg_len; +register_t hwid;if ( !dt_device_type_is_equal (cpu,"cpu" ) )continue ;
@@ -160,7 +161,7 @@ static void __init dt_smp_init_cpus(void)*/ if ( hwid & ~MPIDR_HWID_MASK ) { -printk (XENLOG_WARNING "cpu node `%s`: invalid hwid value (0x%x)\n" , +printk (XENLOG_WARNING "cpu node `%s`: invalid hwid value (0x%" PRIregister")\n" ,dt_node_full_name (cpu), hwid);continue ; }
@@ -176,7 +177,7 @@ static void __init dt_smp_init_cpus(void)if ( tmp_map[j] == hwid ) {printk (XENLOG_WARNING -"cpu node `%s`: duplicate /cpu reg properties %" PRIx32" in the DT\n" , +"cpu node `%s`: duplicate /cpu reg properties %" PRIregister" in the DT\n" ,dt_node_full_name (cpu), hwid);break ; }
@@ -211,7 +212,7 @@ static void __init dt_smp_init_cpus(void)if ( (rc =arch_cpu_init (i, cpu)) <0 ) { -printk ("cpu%d init failed (hwid %x): %d\n" , i, hwid, rc); +printk ("cpu%d init failed (hwid %" PRIregister"): %d\n" , i, hwid, rc); tmp_map[i] =MPIDR_INVALID ; }else
xen/include/asm-arm/processor.h +1 -1
@@ -348,7 +348,7 @@ extern void identify_cpu(struct cpuinfo_arm *);extern struct cpuinfo_arm cpu_data[];#define current_cpu_data cpu_data[smp_processor_id()] -extern u32 __cpu_logical_map[]; +extern register_t __cpu_logical_map[];#define cpu_logical_map (cpu) __cpu_logical_map[cpu]/* HSR data abort size definition */
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v3 2/4 xen/arm: Make AFFINITY_MASK generate correct mask for level3
In reply to Wei ChenThe original affinity shift bits algorithm in AFFINITY_MASK is buggy, it could not generate correct affinity shift bits of level3. The macro MPIDR_LEVEL_SHIFT can calculate level3 affinity shift bits correctly. We use this macro in AFFINITY_MASK to generate correct mask for level3.
---
v2-->v3:
Update version numnber.
v1-->v2:
Add Julien's reviewed-by.
--- xen/include/asm-arm/processor.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
xen/include/asm-arm/processor.h +2 -1
@@ -21,7 +21,6 @@#define MPIDR_HWID_MASK _AC(0xffffff,U)#define MPIDR_INVALID (~MPIDR_HWID_MASK)#define MPIDR_LEVEL_BITS (8) -#define AFFINITY_MASK (level) ~((_AC(0x1,U) << ((level) * MPIDR_LEVEL_BITS)) - 1)/*
@@ -37,6 +36,8 @@#define MPIDR_AFFINITY_LEVEL (mpidr, level) \ ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK) +#define AFFINITY_MASK (level) ~((_AC(0x1,UL) << MPIDR_LEVEL_SHIFT(level)) - 1) +/* TTBCR Translation Table Base Control Register */ #define TTBCR_EAE _AC(0x80000000,U)#define TTBCR_N_MASK _AC(0x07,U)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v3 3/4 xen:arm: arm64: Add correct MPIDR_HWID_MASK value for ARM64
In reply to Wei ChenCurrently, MPIDR_HWID_MASK is using the bit definition of AArch32 MPIDR register. But from D7.2.67 of ARM ARM (DDI 0487A.i) we can see there are 4 levels of affinity on AArch64 whilst AArch32 has only 3. So, this value is not correct when Xen is running on AArch64.
Now, we use the value 0xff00ffffff for this macro on AArch64. But neither of this value and its bitwise invert value can be used in mov instruction with the encoding of {imm16:shift} or {imms:immr}. So we have to use ldr to load the bitwise invert value to register.
The details of mov immediate encoding are listed in C4.2.5 of ARM ARM (DDI 0487A.i).
---
v2-->v3:
1. Add version information of mentioned ARM ARM.
v1-->v2: Address Julien's comments
1. Fix typos in commit messages.
2. Explain valid MPIDR_HWID_MASK value in AArch64.
3. Simply explain mov immediate encoding.
--- xen/arch/arm/arm64/head.S | 2 +- xen/include/asm-arm/processor.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-)
xen/arch/arm/arm64/head.S +1 -1
@@ -270,7 +270,7 @@ common_start: tbz x0, _MPIDR_SMP, 1f /* Multiprocessor extension not supported? */ tbnz x0, _MPIDR_UP, 1f /* Uniprocessor system? */ - mov x13, #(~MPIDR_HWID_MASK) + ldr x13, =(~MPIDR_HWID_MASK) bic x24, x0, x13 /* Mask out flags to get CPU ID */ 1:
xen/include/asm-arm/processor.h +4 -0
@@ -18,7 +18,11 @@#define MPIDR_SMP (_AC(1,U) << _MPIDR_SMP)#define MPIDR_AFF0_SHIFT (0)#define MPIDR_AFF0_MASK (_AC(0xff,U) << MPIDR_AFF0_SHIFT) +#ifdef CONFIG_ARM_64 +#define MPIDR_HWID_MASK _AC(0xff00ffffff,UL) +#else #define MPIDR_HWID_MASK _AC(0xffffff,U) +#endif #define MPIDR_INVALID (~MPIDR_HWID_MASK)#define MPIDR_LEVEL_BITS (8)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v3 4/4 xen/arm: arm64: Remove MPIDR multiprocessing extensions check
In reply to Wei ChenIn AArch32, MPIDR bit 31 is defined as multiprocessing extensions bit. But in AArch64, this bit is always RES1. So the value check for this bit is no longer necessary in AArch64.
---
v2--v3:
1. Fix a typo in commit messages.
2. Add Julien's Reviewed-by.
v1-->v2:
Make clear the status of MPIDR.SMP bit in AArch32 and AArch64.
--- xen/arch/arm/arm64/head.S | 1 - 1 file changed, 1 deletion(-)
xen/arch/arm/arm64/head.S +0 -1
@@ -267,7 +267,6 @@ common_start: * find that multiprocessor extensions are * present and the system is SMP */ mrs x0, mpidr_el1 - tbz x0, _MPIDR_SMP, 1f /* Multiprocessor extension not supported? */ tbnz x0, _MPIDR_UP, 1f /* Uniprocessor system? */ ldr x13, =(~MPIDR_HWID_MASK)
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 5 lines · Wei Chen
In ARM64 the MPIDR register is mapped to
MPIDR_EL1, and the register bits are expanded to 64-bits. But Xen 64-bit ARM code treats this it as 32-bit register.
We have to provide correct accessing to this register to avoid unexpected issues that is caused by incorrect MPIDR value.
Please don't drop acked-by and reviewed-by tags in the future (unless you make significant changes to the patches).
Quoted 6 lines
Wei Chen (4):
xen/arm: Change the variable type ofcpu_logical_maptoregister_txen/arm: MakeAFFINITY_MASKgenerate correct mask for level3 xen:arm: arm64: Add correctMPIDR_HWID_MASKvalue for ARM64 xen/arm: arm64: Remove MPIDR multiprocessing extensions check
Quoted 9 lines
xen/arch/arm/arm64/head.S | 3 +-- xen/arch/arm/gic-v3.c | 2 +- xen/arch/arm/smpboot.c | 13 +++++++------ xen/include/asm-arm/processor.h | 9 +++++++-- 4 files changed, 16 insertions(+), 11 deletions(-)Signature · 1 line
2.7.4
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Hi Stefano,
Quoted 10 lines · Stefano Stabellini
Quoted 5 lines · Wei Chen
In ARM64 the MPIDR register is mapped to
MPIDR_EL1, and the register bits are expanded to 64-bits. But Xen 64-bit ARM code treats this it as 32-bit register.
We have to provide correct accessing to this register to avoid unexpected issues that is caused by incorrect MPIDR value.Please don't drop acked-by and reviewed-by tags in the future (unless you make significant changes to the patches).
Thanks for your kindly reminder!
Quoted 13 lines
Quoted 13 lines
Wei Chen (4):
xen/arm: Change the variable type ofcpu_logical_maptoregister_txen/arm: MakeAFFINITY_MASKgenerate correct mask for level3 xen:arm: arm64: Add correctMPIDR_HWID_MASKvalue for ARM64 xen/arm: arm64: Remove MPIDR multiprocessing extensions checkxen/arch/arm/arm64/head.S | 3 +-- xen/arch/arm/gic-v3.c | 2 +- xen/arch/arm/smpboot.c | 13 +++++++------ xen/include/asm-arm/processor.h | 9 +++++++-- 4 files changed, 16 insertions(+), 11 deletions(-)
Quoted 3 lines
Quoted 3 lines
--
2.7.4
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel