xen/arm64: Rework the MMU-off code (idmap) so it is self-contained
cover xen/arm64: Rework the MMU-off code (idmap) so it is self-contained
From: Julien Grall <[email protected]>
Hi all,
Right now, the MMU-off code will access may access data that are either in .rodata or .data. With the enablement of cache coloring, Xen may not be physcally contiguous anymore when secondary CPUs are brought up.
There are multiple way to solve this problem. The first is to keep a copy of Xen physically contiguous in memory. The downside is this means we are using up to 8MB (maximum size of Xen) when only a few KBs is necessary.
This series is reworking the logic so all the MMU-off code is now self-contained for secondary boot CPUs on arm64.
On arm32, this is not yet possible because secondary CPUs needs to rebuild boot page-tables.
Cheers,
Julien Grall (4):
arm/mmu: Move init_ttbr to a new section .data.idmap arm/smpboot: Move smp_up_cpu to a new section .data.idmap xen/arm64: head: Use PRINT_ID() for secondary CPU MMU-off boot code [DO NOT COMMIT] xen/arm: Create a trampoline for secondary boot CPUs
xen/arch/arm/arm64/head.S | 14 +++---- xen/arch/arm/arm64/mmu/head.S | 2 +- xen/arch/arm/arm64/mmu/mm.c | 7 ++++ xen/arch/arm/include/asm/arm64/macros.h | 9 +++-- xen/arch/arm/mmu/smpboot.c | 36 +++++++++++++++--- xen/arch/arm/psci.c | 5 ++- xen/arch/arm/smpboot.c | 49 ++++++++++++++++++++++--- xen/arch/arm/xen.lds.S | 1 + 8 files changed, 101 insertions(+), 22 deletions(-)
Signature · 1 line
2.40.1
PATCH 1/4 arm/mmu: Move init_ttbr to a new section .data.idmap
From: Julien Grall <[email protected]>
With the upcoming work to color Xen, the binary will not be anymore physically contiguous. This will be a problem during boot as the assembly code will need to work out where each piece of Xen reside.
An easy way to solve the issue is to have all code/data accessed by the secondary CPUs while the MMU is off within a single page.
Right now, init_ttbr is used by secondary CPUs to find there page-tables before the MMU is on. Yet it is currently in .data which is unlikely to be within the same page as the rest of the idmap.
Create a new section .data.idmap that will be used for variables accessed by the early boot code. The first one is init_ttbr.
The idmap is currently part of the text section and therefore will be mapped read-only executable. This means that we need to temporarily remap init_ttbr in order to update it.
Introduce a new function set_init_ttbr() for this purpose so the code is not duplicated between arm64 and arm32.
--- xen/arch/arm/mmu/smpboot.c | 34 +++++++++++++++++++++++++++++----- xen/arch/arm/xen.lds.S | 1 + 2 files changed, 30 insertions(+), 5 deletions(-)
xen/arch/arm/mmu/smpboot.c +29 -5
@@ -9,6 +9,10 @@#include <asm/setup.h> +/* Override macros from asm/page.h to make them work with mfn_t */ +#undef virt_to_mfn +#define virt_to_mfn (va) _mfn(__virt_to_mfn(va)) +/* * Static start-of-day pagetables that we use before the allocators * are up. These are used by all CPUs during bringup before switching
@@ -44,7 +48,7 @@ DEFINE_BOOT_PAGE_TABLE(boot_second);DEFINE_BOOT_PAGE_TABLES (boot_third,XEN_NR_ENTRIES (2 ));/* Non-boot CPUs use this to find the correct pagetables. */ -uint64_t init_ttbr; +uint64_t __section(".data.idmap") init_ttbr;/* Clear a translation table and clean & invalidate the cache */ static void clear_table (void *table)
@@ -68,6 +72,27 @@ static void clear_boot_pagetables(void)clear_table (boot_third); } +static void set_init_ttbr (lpae_t *root) +{ +/* +* init_ttbr is part of the identity mapping which is read-only. So +* We need to re-map the region so it can be updated +*/ +void *ptr =map_domain_page (virt_to_mfn (&init_ttbr)); + + ptr +=PAGE_OFFSET (&init_ttbr); + + *(uint64_t *)ptr =virt_to_maddr (root); + +/* +* init_ttbr will be accessed with the MMU off, so ensure the update +* is visible by cleaning the cache. +*/ +clean_dcache (ptr); + +unmap_domain_page (ptr); +} +#ifdef CONFIG_ARM_64 int prepare_secondary_mm (int cpu) {
@@ -77,8 +102,8 @@ int prepare_secondary_mm(int cpu)* Set init_ttbr for this CPU coming up. All CPUs share a single setof * pagetables, but rewrite it each time for consistency with 32 bit. */ - init_ttbr =virt_to_maddr (xen_pgtable); -clean_dcache (init_ttbr); +set_init_ttbr (xen_pgtable); + return 0; }#else
@@ -109,8 +134,7 @@ int prepare_secondary_mm(int cpu)clear_boot_pagetables ();/* Set init_ttbr for this CPU coming up */ - init_ttbr =__pa (first); -clean_dcache (init_ttbr); +set_init_ttbr (first);return 0 ; }
xen/arch/arm/xen.lds.S +1 -0
@@ -36,6 +36,7 @@ SECTIONS *(.text.header) *(.text.idmap) *(.rodata.idmap) + *(.data.idmap) _idmap_end = .; *(.text.cold)
Signature · 1 line
2.40.1
Re: [PATCH v1 repost 1/4] arm/mmu: Move init_ttbr to a new section .data.idmap
Hi Julien,
Quoted 18 lines · Julien Grall
From: Julien Grall <[email protected]>
With the upcoming work to color Xen, the binary will not be anymore physically contiguous. This will be a problem during boot as the assembly code will need to work out where each piece of Xen reside.
An easy way to solve the issue is to have all code/data accessed by the secondary CPUs while the MMU is off within a single page.
Right now,
init_ttbris used by secondary CPUs to find there page-tables before the MMU is on. Yet it is currently in .data which is unlikely to be within the same page as the rest of the idmap.Create a new section .data.idmap that will be used for variables accessed by the early boot code. The first one is
init_ttbr.
Quoted 8 lines
The idmap is currently part of the text section and therefore will be mapped read-only executable. This means that we need to temporarily remap
init_ttbrin order to update it.Introduce a new function
set_init_ttbr()for this purpose so the code is not duplicated between arm64 and arm32.Signed-off-by Julien Grall <[email protected]>
with ...
Quoted 21 lines
--- xen/arch/arm/mmu/smpboot.c | 34 +++++++++++++++++++++++++++++----- xen/arch/arm/xen.lds.S | 1 + 2 files changed, 30 insertions(+), 5 deletions(-)xen/arch/arm/mmu/smpboot.c +4
-0@@ -9,6 +9,10 @@#include <asm/setup.h> +/* Override macros from asm/page.h to make them work with mfn_t */ +#undef virt_to_mfn +#define virt_to_mfn (va) _mfn(__virt_to_mfn(va)) +/* * Static start-of-day pagetables that we use before the allocators * are up. These are used by all CPUs during bringup before switching
xen/arch/arm/mmu/smpboot.c DEFINE_BOOT_PAGE_TABLE(boot_second); · line 51
Quoted 5 lines
xen/arch/arm/mmu/smpboot.c +1
-1@@ -44,7 +48,7 @@ DEFINE_BOOT_PAGE_TABLE(boot_second);DEFINE_BOOT_PAGE_TABLES (boot_third,XEN_NR_ENTRIES (2 ));/* Non-boot CPUs use this to find the correct pagetables. */ -uint64_t init_ttbr; +uint64_t __section(".data.idmap") init_ttbr;
Do we need to keep the declaration in mmu/mm.h? This variable is only used in this file and in assembly, so maybe better to drop declaration and use asmlinkage instead?
xen/arch/arm/mmu/smpboot.c static void clear_boot_pagetables(void) · line 79
Quoted 12 lines
xen/arch/arm/mmu/smpboot.c +5
-0/* Clear a translation table and clean & invalidate the cache */ static void clear_table (void *table)@@ -68,6 +72,27 @@ static void clear_boot_pagetables(void)clear_table (boot_third); } +static void set_init_ttbr (lpae_t *root) +{ +/* +* init_ttbr is part of the identity mapping which is read-only. So +* We need to re-map the region so it can be updated
Would you mind fixing s/So We/So we/ and add a full stop after last sentence?
Quoted 53 lines
xen/arch/arm/mmu/smpboot.c +19
-4+*/ +void *ptr =map_domain_page (virt_to_mfn (&init_ttbr)); + + ptr +=PAGE_OFFSET (&init_ttbr); + + *(uint64_t *)ptr =virt_to_maddr (root); + +/* +* init_ttbr will be accessed with the MMU off, so ensure the update +* is visible by cleaning the cache. +*/ +clean_dcache (ptr); + +unmap_domain_page (ptr); +} +#ifdef CONFIG_ARM_64 int prepare_secondary_mm (int cpu) {@@ -77,8 +102,8 @@ int prepare_secondary_mm(int cpu)* Set init_ttbr for this CPU coming up. All CPUs share a single setof * pagetables, but rewrite it each time for consistency with 32 bit. */ - init_ttbr =virt_to_maddr (xen_pgtable); -clean_dcache (init_ttbr); +set_init_ttbr (xen_pgtable); + return 0; }#else @@ -109,8 +134,7 @@ int prepare_secondary_mm(int cpu)clear_boot_pagetables ();/* Set init_ttbr for this CPU coming up */ - init_ttbr =__pa (first); -clean_dcache (init_ttbr); +set_init_ttbr (first);return 0 ; }xen/arch/arm/xen.lds.S +1
-1@@ -36,6 +36,7 @@ SECTIONS *(.text.header) *(.text.idmap) *(.rodata.idmap) + *(.data.idmap) _idmap_end = .; *(.text.cold) --
Quoted 2 lines
2.40.1
~Michal
Re: [PATCH v1 repost 1/4] arm/mmu: Move init_ttbr to a new section .data.idmap
Quoted 1 line · Michal Orzel
Hi Julien,
Hi Michal,
Quoted 54 lines · Julien Grall
Quoted 18 lines
From: Julien Grall <[email protected]>
With the upcoming work to color Xen, the binary will not be anymore physically contiguous. This will be a problem during boot as the assembly code will need to work out where each piece of Xen reside.
An easy way to solve the issue is to have all code/data accessed by the secondary CPUs while the MMU is off within a single page.
Right now,
init_ttbris used by secondary CPUs to find there page-tables before the MMU is on. Yet it is currently in .data which is unlikely to be within the same page as the rest of the idmap.Create a new section .data.idmap that will be used for variables accessed by the early boot code. The first one is
init_ttbr.Quoted 8 lines
The idmap is currently part of the text section and therefore will be mapped read-only executable. This means that we need to temporarily remap
init_ttbrin order to update it.Introduce a new function
set_init_ttbr()for this purpose so the code is not duplicated between arm64 and arm32.Signed-off-by Julien Grall <[email protected]>Reviewed-by Michal Orzel <[email protected]>with ...
Quoted 23 lines
--- xen/arch/arm/mmu/smpboot.c | 34 +++++++++++++++++++++++++++++----- xen/arch/arm/xen.lds.S | 1 + 2 files changed, 30 insertions(+), 5 deletions(-)xen/arch/arm/mmu/smpboot.c +4
-0@@ -9,6 +9,10 @@#include <asm/setup.h> +/* Override macros from asm/page.h to make them work with mfn_t */ +#undef virt_to_mfn +#define virt_to_mfn (va) _mfn(__virt_to_mfn(va)) +/* * Static start-of-day pagetables that we use before the allocators * are up. These are used by all CPUs during bringup before switching @@ -44,7 +48,7 @@ DEFINE_BOOT_PAGE_TABLE(boot_second);DEFINE_BOOT_PAGE_TABLES (boot_third,XEN_NR_ENTRIES (2 ));
Quoted 5 lines
xen/arch/arm/mmu/smpboot.c DEFINE_BOOT_PAGE_TABLE(boot_second); · line 51
Quoted 3 lines
xen/arch/arm/mmu/smpboot.c +1
-1/* Non-boot CPUs use this to find the correct pagetables. */ -uint64_t init_ttbr; +uint64_t __section(".data.idmap") init_ttbr;Do we need to keep the declaration in
mmu/mm.h? This variable is only used in this file and in assembly, so maybe better to drop declaration and use asmlinkage instead?
I don't see the problem of keeping the declaration in mmu/mm.h. In any case, this seems to be unrelated to this patch.
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/mmu/smpboot.c +0
-0/* Clear a translation table and clean & invalidate the cache */ static void clear_table (void *table)@@ -68,6 +72,27 @@ static void clear_boot_pagetables(void)clear_table (boot_third); }
Quoted 6 lines
xen/arch/arm/mmu/smpboot.c static void clear_boot_pagetables(void) · line 79
Quoted 5 lines
xen/arch/arm/mmu/smpboot.c +5
-0+static void set_init_ttbr (lpae_t *root) +{ +/* +* init_ttbr is part of the identity mapping which is read-only. So +* We need to re-map the region so it can be updated Would you mind fixing s/So We/So we/ and add a full stop after last sentence?
I can do that.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v1 repost 1/4] arm/mmu: Move init_ttbr to a new section .data.idmap
Quoted 61 lines · Julien Grall
Quoted 1 line · Michal Orzel
Hi Julien,
Hi Michal,
Quoted 54 lines · Julien Grall
Quoted 18 lines
From: Julien Grall <[email protected]>
With the upcoming work to color Xen, the binary will not be anymore physically contiguous. This will be a problem during boot as the assembly code will need to work out where each piece of Xen reside.
An easy way to solve the issue is to have all code/data accessed by the secondary CPUs while the MMU is off within a single page.
Right now,
init_ttbris used by secondary CPUs to find there page-tables before the MMU is on. Yet it is currently in .data which is unlikely to be within the same page as the rest of the idmap.Create a new section .data.idmap that will be used for variables accessed by the early boot code. The first one is
init_ttbr.Quoted 8 lines
The idmap is currently part of the text section and therefore will be mapped read-only executable. This means that we need to temporarily remap
init_ttbrin order to update it.Introduce a new function
set_init_ttbr()for this purpose so the code is not duplicated between arm64 and arm32.Signed-off-by Julien Grall <[email protected]>Reviewed-by Michal Orzel <[email protected]>with ...
Quoted 23 lines
--- xen/arch/arm/mmu/smpboot.c | 34 +++++++++++++++++++++++++++++----- xen/arch/arm/xen.lds.S | 1 + 2 files changed, 30 insertions(+), 5 deletions(-)xen/arch/arm/mmu/smpboot.c +4
-0@@ -9,6 +9,10 @@#include <asm/setup.h> +/* Override macros from asm/page.h to make them work with mfn_t */ +#undef virt_to_mfn +#define virt_to_mfn (va) _mfn(__virt_to_mfn(va)) +/* * Static start-of-day pagetables that we use before the allocators * are up. These are used by all CPUs during bringup before switching @@ -44,7 +48,7 @@ DEFINE_BOOT_PAGE_TABLE(boot_second);DEFINE_BOOT_PAGE_TABLES (boot_third,XEN_NR_ENTRIES (2 ));
Quoted 8 lines
Quoted 5 lines
xen/arch/arm/mmu/smpboot.c DEFINE_BOOT_PAGE_TABLE(boot_second); · line 51
Quoted 3 lines
xen/arch/arm/mmu/smpboot.c +1
-1/* Non-boot CPUs use this to find the correct pagetables. */ -uint64_t init_ttbr; +uint64_t __section(".data.idmap") init_ttbr;Do we need to keep the declaration in
mmu/mm.h? This variable is only used in this file and in assembly, so maybe better to drop declaration and use asmlinkage instead?I don't see the problem of keeping the declaration in
mmu/mm.h. In any case, this seems to be unrelated to this patch.
This was just a question about the sense of a declaration that is not used/needed at all. If you also thought so, it could be done in this patch given that it touches definition. Since you don't, no problem whatsoever.
~Michal
PATCH 2/4 arm/smpboot: Move smp_up_cpu to a new section .data.idmap
In reply to Julien GrallFrom: Julien Grall <[email protected]>
With the upcoming work to color Xen, the binary will not be anymore physically contiguous. This will be a problem during boot as the assembly code will need to work out where each piece of Xen reside.
An easy way to solve the issue is to have all code/data accessed by the secondary CPUs while the MMU is off within a single page.
Right now, smp_up_cpu is used by secondary CPUs to wait there turn for booting before the MMU is on. Yet it is currently in .data which is unlikely to be within the same page as the rest of the idmap.
Move smp_up_cpu to the recently create section .data.idmap. The idmap is currently part of the text section and therefore will be mapped read-onl executable. This means that we need to temporarily remap smp_up_cpu in order to update it.
Introduce a new function set_smp_up_cpu() for this purpose so the code is not duplicated between when opening and closing the gate.
--- xen/arch/arm/smpboot.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-)
xen/arch/arm/smpboot.c +31 -5
@@ -29,6 +29,10 @@#include <asm/psci.h> #include <asm/acpi.h> +/* Override macros from asm/page.h to make them work with mfn_t */ +#undef virt_to_mfn +#define virt_to_mfn (va) _mfn(__virt_to_mfn(va)) +cpumask_t cpu_online_map;cpumask_t cpu_present_map;cpumask_t cpu_possible_map;
@@ -56,7 +60,7 @@ struct init_info init_data = };/* Shared state for coordinating CPU bringup */ -unsigned long smp_up_cpu =MPIDR_INVALID ; +unsigned long __section(".data.idmap") smp_up_cpu = MPIDR_INVALID;/* Shared state for coordinating CPU teardown */ static bool cpu_is_dead;
@@ -429,6 +433,28 @@ void stop_cpu(void)wfi (); } +static void set_smp_up_cpu (unsigned long mpidr) +{ +/* +* smp_up_cpu is part of the identity mapping which is read-only. So +* We need to re-map the region so it can be updated. +*/ +void *ptr =map_domain_page (virt_to_mfn (&smp_up_cpu)); + + ptr +=PAGE_OFFSET (&smp_up_cpu); + + *(unsigned long *)ptr = mpidr; + +/* +* init_ttbr will be accessed with the MMU off, so ensure the update +* is visible by cleaning the cache. +*/ +clean_dcache (ptr); + +unmap_domain_page (ptr); + +} +int __init cpu_up_send_sgi (int cpu) {/* We don't know the GIC ID of the CPU until it has woken up, so just
@@ -460,8 +486,7 @@ int __cpu_up(unsigned int cpu) init_data.cpuid = cpu;/* Open the gate for this CPU */ - smp_up_cpu =cpu_logical_map (cpu); -clean_dcache (smp_up_cpu); +set_smp_up_cpu (cpu_logical_map (cpu)); rc =arch_cpu_up (cpu);
@@ -497,8 +522,9 @@ int __cpu_up(unsigned int cpu)*/ init_data.stack =NULL ; init_data.cpuid = ~0 ; - smp_up_cpu =MPIDR_INVALID ; -clean_dcache (smp_up_cpu); + +set_smp_up_cpu (MPIDR_INVALID ); +arch_cpu_up_finish ();if ( !cpu_online (cpu) )
Signature · 1 line
2.40.1
Re: [PATCH v1 repost 2/4] arm/smpboot: Move smp_up_cpu to a new section .data.idmap
Hi Julien,
Quoted 4 lines · Julien Grall
From: Julien Grall <[email protected]>
Quoted 8 lines
With the upcoming work to color Xen, the binary will not be anymore physically contiguous. This will be a problem during boot as the assembly code will need to work out where each piece of Xen reside.
An easy way to solve the issue is to have all code/data accessed by the secondary CPUs while the MMU is off within a single page.
Right now,
smp_up_cpuis used by secondary CPUs to wait there turn for
s/there/their ?
Quoted 4 lines
booting before the MMU is on. Yet it is currently in .data which is unlikely to be within the same page as the rest of the idmap.
Move
smp_up_cputo the recently create section .data.idmap. The idmap is
s/create/created
Quoted 1 line
currently part of the text section and therefore will be mapped read-onl
s/onl/only
Quoted 7 lines
executable. This means that we need to temporarily remap
smp_up_cpuin order to update it.Introduce a new function
set_smp_up_cpu()for this purpose so the code is not duplicated between when opening and closing the gate.Signed-off-by Julien Grall <[email protected]>
Quoted 36 lines
--- xen/arch/arm/smpboot.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-)xen/arch/arm/smpboot.c +9
-1@@ -29,6 +29,10 @@#include <asm/psci.h> #include <asm/acpi.h> +/* Override macros from asm/page.h to make them work with mfn_t */ +#undef virt_to_mfn +#define virt_to_mfn (va) _mfn(__virt_to_mfn(va)) +cpumask_t cpu_online_map;cpumask_t cpu_present_map;cpumask_t cpu_possible_map;@@ -56,7 +60,7 @@ struct init_info init_data = };/* Shared state for coordinating CPU bringup */ -unsigned long smp_up_cpu =MPIDR_INVALID ; +unsigned long __section(".data.idmap") smp_up_cpu = MPIDR_INVALID;/* Shared state for coordinating CPU teardown */ static bool cpu_is_dead;@@ -429,6 +433,28 @@ void stop_cpu(void)wfi (); } +static void set_smp_up_cpu (unsigned long mpidr) +{ +/* +* smp_up_cpu is part of the identity mapping which is read-only. So
xen/arch/arm/smpboot.c void stop_cpu(void) · line 449
Quoted 10 lines
xen/arch/arm/smpboot.c +10
-0+* We need to re-map the region so it can be updated. +*/ +void *ptr =map_domain_page (virt_to_mfn (&smp_up_cpu)); + + ptr +=PAGE_OFFSET (&smp_up_cpu); + + *(unsigned long *)ptr = mpidr; + +/* +* init_ttbr will be accessed with the MMU off, so ensure the update
smp_up_cpu instead of init_ttbr
Quoted 34 lines
xen/arch/arm/smpboot.c +12
-5+* is visible by cleaning the cache. +*/ +clean_dcache (ptr); + +unmap_domain_page (ptr); + +} +int __init cpu_up_send_sgi (int cpu) {/* We don't know the GIC ID of the CPU until it has woken up, so just @@ -460,8 +486,7 @@ int __cpu_up(unsigned int cpu) init_data.cpuid = cpu;/* Open the gate for this CPU */ - smp_up_cpu =cpu_logical_map (cpu); -clean_dcache (smp_up_cpu); +set_smp_up_cpu (cpu_logical_map (cpu)); rc =arch_cpu_up (cpu);@@ -497,8 +522,9 @@ int __cpu_up(unsigned int cpu)*/ init_data.stack =NULL ; init_data.cpuid = ~0 ; - smp_up_cpu =MPIDR_INVALID ; -clean_dcache (smp_up_cpu); + +set_smp_up_cpu (MPIDR_INVALID ); +arch_cpu_up_finish ();if ( !cpu_online (cpu) ) --
Quoted 2 lines
2.40.1
~Michal
Re: [PATCH v1 repost 2/4] arm/smpboot: Move smp_up_cpu to a new section .data.idmap
Quoted 1 line · Michal Orzel
Hi Julien,
Hi Michal,
Quoted 10 lines · Julien Grall
Quoted 8 lines
From: Julien Grall <[email protected]>
With the upcoming work to color Xen, the binary will not be anymore physically contiguous. This will be a problem during boot as the assembly code will need to work out where each piece of Xen reside.
Quoted 5 lines
Quoted 4 lines
An easy way to solve the issue is to have all code/data accessed by the secondary CPUs while the MMU is off within a single page.
Right now,
smp_up_cpuis used by secondary CPUs to wait there turn fors/there/their ?
Yes. I will fix it on commit.
Quoted 51 lines
Quoted 5 lines
booting before the MMU is on. Yet it is currently in .data which is unlikely to be within the same page as the rest of the idmap.
Move
smp_up_cputo the recently create section .data.idmap. The idmap iss/create/created
Quoted 1 line
currently part of the text section and therefore will be mapped read-onl
s/onl/only
Quoted 7 lines
executable. This means that we need to temporarily remap
smp_up_cpuin order to update it.Introduce a new function
set_smp_up_cpu()for this purpose so the code is not duplicated between when opening and closing the gate.Signed-off-by Julien Grall <[email protected]>Reviewed-by Michal Orzel <[email protected]>Quoted 32 lines
--- xen/arch/arm/smpboot.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-)xen/arch/arm/smpboot.c +5
-1@@ -29,6 +29,10 @@#include <asm/psci.h> #include <asm/acpi.h> +/* Override macros from asm/page.h to make them work with mfn_t */ +#undef virt_to_mfn +#define virt_to_mfn (va) _mfn(__virt_to_mfn(va)) +cpumask_t cpu_online_map;cpumask_t cpu_present_map;cpumask_t cpu_possible_map;@@ -56,7 +60,7 @@ struct init_info init_data = };/* Shared state for coordinating CPU bringup */ -unsigned long smp_up_cpu =MPIDR_INVALID ; +unsigned long __section(".data.idmap") smp_up_cpu = MPIDR_INVALID;/* Shared state for coordinating CPU teardown */ static bool cpu_is_dead;@@ -429,6 +433,28 @@ void stop_cpu(void)wfi (); }
Quoted 15 lines
Quoted 4 lines
xen/arch/arm/smpboot.c +4
-0+static void set_smp_up_cpu (unsigned long mpidr) +{ +/* +* smp_up_cpu is part of the identity mapping which is read-only. So xen/arch/arm/smpboot.c void stop_cpu(void) · line 449
Quoted 10 lines
xen/arch/arm/smpboot.c +10
-0+* We need to re-map the region so it can be updated. +*/ +void *ptr =map_domain_page (virt_to_mfn (&smp_up_cpu)); + + ptr +=PAGE_OFFSET (&smp_up_cpu); + + *(unsigned long *)ptr = mpidr; + +/* +* init_ttbr will be accessed with the MMU off, so ensure the update
smp_up_cpuinstead ofinit_ttbr
Doh. I just copied/pasted the code from init_ttbr. I will update it.
BTW, I thought about trying to consolidate the code between set_init_ttbr() and set_smp_up_cpu() but it didn't seem to be worth it.
Cheers,
Signature · 1 line
Julien Grall
PATCH 3/4 xen/arm64: head: Use PRINT_ID() for secondary CPU MMU-off boot code
In reply to Julien GrallFrom: Julien Grall <[email protected]>
With the upcoming work to color Xen, the binary will not be anymore physically contiguous. This will be a problem during boot as the assembly code will need to work out where each piece of Xen reside.
An easy way to solve the issue is to have all code/data accessed by the secondary CPUs while the MMU is off within a single page.
Right now, most of the early printk messages are using PRINT() which will add the message in .rodata. This is unlikely to be within the same page as the rest of the idmap.
So replace all the PRINT() that can be reachable by the secondary CPU with MMU-off with PRINT_ID().
--- xen/arch/arm/arm64/head.S | 14 +++++++------- xen/arch/arm/arm64/mmu/head.S | 2 +- xen/arch/arm/include/asm/arm64/macros.h | 9 ++++++--- 3 files changed, 14 insertions(+), 11 deletions(-)
xen/arch/arm/arm64/head.S +7 -7
@@ -289,9 +289,9 @@ GLOBAL(init_secondary) #ifdef CONFIG_EARLY_PRINTK ldr x23, =CONFIG_EARLY_UART_BASE_ADDRESS /* x23 := UART base address */ - PRINT("- CPU ") + PRINT_ID("- CPU ") print_reg x24 - PRINT(" booting -\r\n") + PRINT_ID(" booting -\r\n") #endif bl check_cpu_mode bl cpu_init
@@ -314,10 +314,10 @@ ENDPROC(init_secondary) * Clobbers x0 - x5 */ check_cpu_mode: - PRINT("- Current EL ") + PRINT_ID("- Current EL ") mrs x5, CurrentEL print_reg x5 - PRINT(" -\r\n") + PRINT_ID(" -\r\n") /* Are we in EL2 */ cmp x5, #PSR_MODE_EL2t
@@ -326,8 +326,8 @@ check_cpu_mode: ret 1: /* OK, we're boned. */ - PRINT("- Xen must be entered in NS EL2 mode -\r\n") - PRINT("- Please update the bootloader -\r\n") + PRINT_ID("- Xen must be entered in NS EL2 mode -\r\n") + PRINT_ID("- Please update the bootloader -\r\n") b fail ENDPROC(check_cpu_mode)
@@ -361,7 +361,7 @@ ENDPROC(zero_bss) * Clobbers x0 - x3 */ cpu_init: - PRINT("- Initialize CPU -\r\n") + PRINT_ID("- Initialize CPU -\r\n") /* Set up memory attribute type tables */ ldr x0, =MAIRVAL
xen/arch/arm/arm64/mmu/head.S +1 -1
@@ -276,7 +276,7 @@ ENDPROC(create_page_tables) enable_mmu: mov x4, x0 mov x5, x1 - PRINT("- Turning on paging -\r\n") + PRINT_ID("- Turning on paging -\r\n") /* * The state of the TLBs is unknown before turning on the MMU.
xen/arch/arm/include/asm/arm64/macros.h +6 -3
@@ -39,9 +39,12 @@* There are multiple flavors: * - PRINT_SECT(section, string): The @string will be located in @section * - PRINT(): The string will be located in .rodata.str. -* - PRINT_ID(): When Xen is running on the Identity Mapping, it is -* only possible to have a limited amount of Xen. This will create -* the string in .rodata.idmap which will always be mapped. +* - PRINT_ID(): This will create the string in .rodata.idmap which +* will always be accessible. This is used when: +* - Xen is running on the identity mapping because not all of Xen is mapped +* - Running with the MMU-off on secondary boots as Xen may not be +* physically contiguous in memory (e.g. in the case of cache +* coloring). * * Clobbers x0 - x3 */
Signature · 1 line
2.40.1
Re: [PATCH v1 repost 3/4] xen/arm64: head: Use PRINT_ID() for secondary CPU MMU-off boot code
Quoted 11 lines · Julien Grall
From: Julien Grall <[email protected]>
With the upcoming work to color Xen, the binary will not be anymore physically contiguous. This will be a problem during boot as the assembly code will need to work out where each piece of Xen reside.
An easy way to solve the issue is to have all code/data accessed by the secondary CPUs while the MMU is off within a single page.
Quoted 8 lines
Right now, most of the early printk messages are using
PRINT()which will add the message in .rodata. This is unlikely to be within the same page as the rest of the idmap.So replace all the
PRINT()that can be reachable by the secondary CPU with MMU-off withPRINT_ID().Signed-off-by Julien Grall <[email protected]>
with some remarks below
Quoted 36 lines
--- xen/arch/arm/arm64/head.S | 14 +++++++------- xen/arch/arm/arm64/mmu/head.S | 2 +- xen/arch/arm/include/asm/arm64/macros.h | 9 ++++++--- 3 files changed, 14 insertions(+), 11 deletions(-)xen/arch/arm/arm64/head.S +4
-4@@ -289,9 +289,9 @@ GLOBAL(init_secondary) #ifdef CONFIG_EARLY_PRINTK ldr x23, =CONFIG_EARLY_UART_BASE_ADDRESS /* x23 := UART base address */ - PRINT("- CPU ") + PRINT_ID("- CPU ") print_reg x24 - PRINT(" booting -\r\n") + PRINT_ID(" booting -\r\n") #endif bl check_cpu_mode bl cpu_init@@ -314,10 +314,10 @@ ENDPROC(init_secondary) * Clobbers x0 - x5 */ check_cpu_mode: - PRINT("- Current EL ") + PRINT_ID("- Current EL ") mrs x5, CurrentEL print_reg x5 - PRINT(" -\r\n") + PRINT_ID(" -\r\n") /* Are we in EL2 */ cmp x5, #PSR_MODE_EL2t
xen/arch/arm/arm64/head.S check_cpu_mode: · line 331
Quoted 8 lines
xen/arch/arm/arm64/head.S +2
-2@@ -326,8 +326,8 @@ check_cpu_mode: ret 1: /* OK, we're boned. */ - PRINT("- Xen must be entered in NS EL2 mode -\r\n") - PRINT("- Please update the bootloader -\r\n") + PRINT_ID("- Xen must be entered in NS EL2 mode -\r\n") + PRINT_ID("- Please update the bootloader -\r\n") b fail
What about the PRINT in fail?
Quoted 29 lines
xen/arch/arm/arm64/head.S +1
-1ENDPROC(check_cpu_mode)@@ -361,7 +361,7 @@ ENDPROC(zero_bss) * Clobbers x0 - x3 */ cpu_init: - PRINT("- Initialize CPU -\r\n") + PRINT_ID("- Initialize CPU -\r\n") /* Set up memory attribute type tables */ ldr x0, =MAIRVALxen/arch/arm/arm64/mmu/head.S +1
-1@@ -276,7 +276,7 @@ ENDPROC(create_page_tables) enable_mmu: mov x4, x0 mov x5, x1 - PRINT("- Turning on paging -\r\n") + PRINT_ID("- Turning on paging -\r\n") /* * The state of the TLBs is unknown before turning on the MMU.xen/arch/arm/include/asm/arm64/macros.h +0
-0
xen/arch/arm/include/asm/arm64/macros.h line 45
Quoted 10 lines
xen/arch/arm/include/asm/arm64/macros.h +4
-3@@ -39,9 +39,12 @@* There are multiple flavors: * - PRINT_SECT(section, string): The @string will be located in @section * - PRINT(): The string will be located in .rodata.str. -* - PRINT_ID(): When Xen is running on the Identity Mapping, it is -* only possible to have a limited amount of Xen. This will create -* the string in .rodata.idmap which will always be mapped. +* - PRINT_ID(): This will create the string in .rodata.idmap which +* will always be accessible. This is used when: +* - Xen is running on the identity mapping because not all of Xen is mapped +* - Running with the MMU-off on secondary boots as Xen may not be
s/boots/CPUs
Quoted 8 lines
xen/arch/arm/include/asm/arm64/macros.h +2
-1+* physically contiguous in memory (e.g. in the case of cache +* coloring). * * Clobbers x0 - x3 */ --2.40.1
~Michal
Re: [PATCH v1 repost 3/4] xen/arm64: head: Use PRINT_ID() for secondary CPU MMU-off boot code
Hi Michal,
Quoted 59 lines · Michal Orzel
Quoted 11 lines · Julien Grall
From: Julien Grall <[email protected]>
With the upcoming work to color Xen, the binary will not be anymore physically contiguous. This will be a problem during boot as the assembly code will need to work out where each piece of Xen reside.
An easy way to solve the issue is to have all code/data accessed by the secondary CPUs while the MMU is off within a single page.
Quoted 8 lines
Right now, most of the early printk messages are using
PRINT()which will add the message in .rodata. This is unlikely to be within the same page as the rest of the idmap.So replace all the
PRINT()that can be reachable by the secondary CPU with MMU-off withPRINT_ID().Signed-off-by Julien Grall <[email protected]>Reviewed-by Michal Orzel <[email protected]>with some remarks below
Quoted 33 lines
--- xen/arch/arm/arm64/head.S | 14 +++++++------- xen/arch/arm/arm64/mmu/head.S | 2 +- xen/arch/arm/include/asm/arm64/macros.h | 9 ++++++--- 3 files changed, 14 insertions(+), 11 deletions(-)xen/arch/arm/arm64/head.S +4
-4@@ -289,9 +289,9 @@ GLOBAL(init_secondary) #ifdef CONFIG_EARLY_PRINTK ldr x23, =CONFIG_EARLY_UART_BASE_ADDRESS /* x23 := UART base address */ - PRINT("- CPU ") + PRINT_ID("- CPU ") print_reg x24 - PRINT(" booting -\r\n") + PRINT_ID(" booting -\r\n") #endif bl check_cpu_mode bl cpu_init@@ -314,10 +314,10 @@ ENDPROC(init_secondary) * Clobbers x0 - x5 */ check_cpu_mode: - PRINT("- Current EL ") + PRINT_ID("- Current EL ") mrs x5, CurrentEL print_reg x5 - PRINT(" -\r\n") + PRINT_ID(" -\r\n")
Quoted 12 lines
xen/arch/arm/arm64/head.S check_cpu_mode: · line 331
Quoted 11 lines
xen/arch/arm/arm64/head.S +2
-2/* Are we in EL2 */ cmp x5, #PSR_MODE_EL2t@@ -326,8 +326,8 @@ check_cpu_mode: ret 1: /* OK, we're boned. */ - PRINT("- Xen must be entered in NS EL2 mode -\r\n") - PRINT("- Please update the bootloader -\r\n") + PRINT_ID("- Xen must be entered in NS EL2 mode -\r\n") + PRINT_ID("- Please update the bootloader -\r\n") b failWhat about the PRINT in fail?
It should be modified. I will update it on commit.
Quoted 33 lines
Quoted 33 lines
xen/arch/arm/arm64/head.S +1
-1ENDPROC(check_cpu_mode)@@ -361,7 +361,7 @@ ENDPROC(zero_bss) * Clobbers x0 - x3 */ cpu_init: - PRINT("- Initialize CPU -\r\n") + PRINT_ID("- Initialize CPU -\r\n") /* Set up memory attribute type tables */ ldr x0, =MAIRVALxen/arch/arm/arm64/mmu/head.S +1
-1@@ -276,7 +276,7 @@ ENDPROC(create_page_tables) enable_mmu: mov x4, x0 mov x5, x1 - PRINT("- Turning on paging -\r\n") + PRINT_ID("- Turning on paging -\r\n") /* * The state of the TLBs is unknown before turning on the MMU.xen/arch/arm/include/asm/arm64/macros.h +0
-0@@ -39,9 +39,12 @@* There are multiple flavors: * - PRINT_SECT(section, string): The @string will be located in @section * - PRINT(): The string will be located in .rodata.str.
Quoted 8 lines
xen/arch/arm/include/asm/arm64/macros.h line 45
Quoted 7 lines
xen/arch/arm/include/asm/arm64/macros.h +4
-3-* - PRINT_ID(): When Xen is running on the Identity Mapping, it is -* only possible to have a limited amount of Xen. This will create -* the string in .rodata.idmap which will always be mapped. +* - PRINT_ID(): This will create the string in .rodata.idmap which +* will always be accessible. This is used when: +* - Xen is running on the identity mapping because not all of Xen is mapped +* - Running with the MMU-off on secondary boots as Xen may not be s/boots/CPUs
I will fix it.
Quoted 11 lines
Quoted 9 lines
xen/arch/arm/include/asm/arm64/macros.h +2
-1+* physically contiguous in memory (e.g. in the case of cache +* coloring). * * Clobbers x0 - x3 */ --2.40.1
~Michal
Cheers,
Signature · 1 line
Julien Grall
PATCH 4/4 xen/arm: Create a trampoline for secondary boot CPUs
In reply to Julien GrallFrom: Julien Grall <[email protected]>
In order to confirm the early boot code is self-contained, allocate a separate trampoline region for secondary to boot from it.
--- xen/arch/arm/arm64/mmu/mm.c | 7 +++++++ xen/arch/arm/mmu/smpboot.c | 4 +++- xen/arch/arm/psci.c | 5 ++++- xen/arch/arm/smpboot.c | 15 ++++++++++++++- 4 files changed, 28 insertions(+), 3 deletions(-)
xen/arch/arm/arm64/mmu/mm.c +7 -0
@@ -110,11 +110,18 @@ void __init arch_setup_page_tables(void)prepare_runtime_identity_mapping (); } +extern mfn_t trampoline_start; +void update_identity_mapping (bool enable) {paddr_t id_addr =virt_to_maddr (_start);int rc; +if ( !mfn_eq (trampoline_start,INVALID_MFN ) ) + { + id_addr =mfn_to_maddr (trampoline_start); + } +if ( enable ) rc =map_pages_to_xen (id_addr,maddr_to_mfn (id_addr),1 ,PAGE_HYPERVISOR_RX );
xen/arch/arm/mmu/smpboot.c +3 -1
@@ -72,13 +72,15 @@ static void clear_boot_pagetables(void)clear_table (boot_third); } +extern mfn_t trampoline_start; +static void set_init_ttbr (lpae_t *root) {/* * init_ttbr is part of the identity mapping which is read-only. So * We need to re-map the region so it can be updated */ -void *ptr =map_domain_page (virt_to_mfn (&init_ttbr)); +void *ptr =map_domain_page (trampoline_start); ptr +=PAGE_OFFSET (&init_ttbr);
xen/arch/arm/psci.c +4 -1
@@ -36,11 +36,14 @@ static uint32_t psci_cpu_on_nr;#define PSCI_RET (res) ((int32_t)(res).a0) +extern mfn_t trampoline_start; +int call_psci_cpu_on (int cpu) {struct arm_smccc_res res; -arm_smccc_smc (psci_cpu_on_nr,cpu_logical_map (cpu),__pa (init_secondary), +arm_smccc_smc (psci_cpu_on_nr,cpu_logical_map (cpu), +mfn_to_maddr (trampoline_start) +PAGE_OFFSET (init_secondary), &res);return PSCI_RET (res);
xen/arch/arm/smpboot.c +14 -1
@@ -293,10 +293,13 @@ unsigned int __init smp_get_max_cpus(void)return cpus; } +mfn_t trampoline_start =INVALID_MFN_INITIALIZER ; +void __init smp_prepare_cpus (void ) {int rc; +void *trampoline;cpumask_copy (&cpu_present_map, &cpu_possible_map);
@@ -304,6 +307,16 @@ smp_prepare_cpus(void)if ( rc )panic ("Unable to allocate CPU sibling/core maps\n" ); +/* Create a trampoline to confirm early boot code is self-contained */ + trampoline =alloc_xenheap_page (); +BUG_ON (!trampoline); + +memcpy (trampoline, _start,PAGE_SIZE ); +clean_dcache_va_range (trampoline,PAGE_SIZE ); +invalidate_icache (); + +printk ("Trampoline 0x%lx\n" ,virt_to_maddr (trampoline)); + trampoline_start =virt_to_mfn (trampoline); }/* Boot the current CPU */
@@ -439,7 +452,7 @@ static void set_smp_up_cpu(unsigned long mpidr)* smp_up_cpu is part of the identity mapping which is read-only. So * We need to re-map the region so it can be updated. */ -void *ptr =map_domain_page (virt_to_mfn (&smp_up_cpu)); +void *ptr =map_domain_page (trampoline_start); ptr +=PAGE_OFFSET (&smp_up_cpu);
Signature · 1 line
2.40.1
Re: [PATCH v1 repost 4/4] [DO NOT COMMIT] xen/arm: Create a trampoline for secondary boot CPUs
Hi Julien
Quoted 99 lines · Julien Grall
From: Julien Grall <[email protected]>
In order to confirm the early boot code is self-contained, allocate a separate trampoline region for secondary to boot from it.
Signed-off-by Julien Grall <[email protected]>--- xen/arch/arm/arm64/mmu/mm.c | 7 +++++++ xen/arch/arm/mmu/smpboot.c | 4 +++- xen/arch/arm/psci.c | 5 ++++- xen/arch/arm/smpboot.c | 15 ++++++++++++++- 4 files changed, 28 insertions(+), 3 deletions(-)xen/arch/arm/arm64/mmu/mm.c +7
-0@@ -110,11 +110,18 @@ void __init arch_setup_page_tables(void)prepare_runtime_identity_mapping (); } +extern mfn_t trampoline_start; +void update_identity_mapping (bool enable) {paddr_t id_addr =virt_to_maddr (_start);int rc; +if ( !mfn_eq (trampoline_start,INVALID_MFN ) ) + { + id_addr =mfn_to_maddr (trampoline_start); + } +if ( enable ) rc =map_pages_to_xen (id_addr,maddr_to_mfn (id_addr),1 ,PAGE_HYPERVISOR_RX );xen/arch/arm/mmu/smpboot.c +3
-1@@ -72,13 +72,15 @@ static void clear_boot_pagetables(void)clear_table (boot_third); } +extern mfn_t trampoline_start; +static void set_init_ttbr (lpae_t *root) {/* * init_ttbr is part of the identity mapping which is read-only. So * We need to re-map the region so it can be updated */ -void *ptr =map_domain_page (virt_to_mfn (&init_ttbr)); +void *ptr =map_domain_page (trampoline_start); ptr +=PAGE_OFFSET (&init_ttbr);xen/arch/arm/psci.c +4
-1@@ -36,11 +36,14 @@ static uint32_t psci_cpu_on_nr;#define PSCI_RET (res) ((int32_t)(res).a0) +extern mfn_t trampoline_start; +int call_psci_cpu_on (int cpu) {struct arm_smccc_res res; -arm_smccc_smc (psci_cpu_on_nr,cpu_logical_map (cpu),__pa (init_secondary), +arm_smccc_smc (psci_cpu_on_nr,cpu_logical_map (cpu), +mfn_to_maddr (trampoline_start) +PAGE_OFFSET (init_secondary), &res);return PSCI_RET (res);xen/arch/arm/smpboot.c +3
-0@@ -293,10 +293,13 @@ unsigned int __init smp_get_max_cpus(void)return cpus; } +mfn_t trampoline_start =INVALID_MFN_INITIALIZER ; +void __init smp_prepare_cpus (void ) {int rc; +void *trampoline;cpumask_copy (&cpu_present_map, &cpu_possible_map);@@ -304,6 +307,16 @@ smp_prepare_cpus(void)if ( rc )panic ("Unable to allocate CPU sibling/core maps\n" );
xen/arch/arm/smpboot.c smp_prepare_cpus(void) · line 318
Quoted 10 lines
xen/arch/arm/smpboot.c +9
-0+/* Create a trampoline to confirm early boot code is self-contained */ + trampoline =alloc_xenheap_page (); +BUG_ON (!trampoline); + +memcpy (trampoline, _start,PAGE_SIZE ); +clean_dcache_va_range (trampoline,PAGE_SIZE ); +invalidate_icache (); + +printk ("Trampoline 0x%lx\n" ,virt_to_maddr (trampoline));
Here PRIx64 is needed for arm32.
Quoted 14 lines
xen/arch/arm/smpboot.c +2
-2+ trampoline_start =virt_to_mfn (trampoline); }/* Boot the current CPU */ @@ -439,7 +452,7 @@ static void set_smp_up_cpu(unsigned long mpidr)* smp_up_cpu is part of the identity mapping which is read-only. So * We need to re-map the region so it can be updated. */ -void *ptr =map_domain_page (virt_to_mfn (&smp_up_cpu)); +void *ptr =map_domain_page (trampoline_start); ptr +=PAGE_OFFSET (&smp_up_cpu); --
Quoted 2 lines
2.40.1
Thanks.
Re: [PATCH v1 repost 4/4] [DO NOT COMMIT] xen/arm: Create a trampoline for secondary boot CPUs
Quoted 1 line · Carlo Nonato
Hi Julien
Hi Carlo,
Quoted 6 lines · Julien Grall
Quoted 5 lines
From: Julien Grall <[email protected]>
In order to confirm the early boot code is self-contained, allocate a separate trampoline region for secondary to boot from it.
[...]
Quoted 4 lines
Quoted 4 lines
xen/arch/arm/smpboot.c +0
-0@@ -304,6 +307,16 @@ smp_prepare_cpus(void)if ( rc )panic ("Unable to allocate CPU sibling/core maps\n" );
Quoted 11 lines
xen/arch/arm/smpboot.c smp_prepare_cpus(void) · line 318
Quoted 9 lines
xen/arch/arm/smpboot.c +9
-0+/* Create a trampoline to confirm early boot code is self-contained */ + trampoline =alloc_xenheap_page (); +BUG_ON (!trampoline); + +memcpy (trampoline, _start,PAGE_SIZE ); +clean_dcache_va_range (trampoline,PAGE_SIZE ); +invalidate_icache (); + +printk ("Trampoline 0x%lx\n" ,virt_to_maddr (trampoline));Here PRIx64 is needed for arm32.
Just for clarification, none of this patch is meant to work on Arm32. In fact, this would break secondary CPUs bring up.
This is why I tagged with DO NOT COMMIT. It was only included to show I tested this code on arm32.
Cheers,
Signature · 1 line
Julien Grall
Hi,
Quoted 19 lines · Julien Grall
From: Julien Grall <[email protected]>
Hi all,
Right now, the MMU-off code will access may access data that are either in .rodata or .data. With the enablement of cache coloring, Xen may not be physcally contiguous anymore when secondary CPUs are brought up.
There are multiple way to solve this problem. The first is to keep a copy of Xen physically contiguous in memory. The downside is this means we are using up to 8MB (maximum size of Xen) when only a few KBs is necessary.
This series is reworking the logic so all the MMU-off code is now self-contained for secondary boot CPUs on arm64.
On arm32, this is not yet possible because secondary CPUs needs to rebuild boot page-tables.
Quoted 6 lines
Cheers,
Julien Grall (4):
arm/mmu: Moveinit_ttbrto a new section .data.idmap arm/smpboot: Movesmp_up_cputo a new section .data.idmap xen/arm64: head: UsePRINT_ID()for secondary CPU MMU-off boot code
The first 3 patches are now committed.
Cheers,
Signature · 1 line
Julien Grall