kvm: arm64: correctly align nVHE percpu data
PATCH 1/1 kvm: arm64: correctly align nVHE percpu data
The nVHE percpu data is partially linked but the nVHE linker script did not align the percpu section. The PERCPU_INPUT macro would then align the data to a page boundary:
#define PERCPU_INPUT(cacheline) \ __per_cpu_start = .; \ *(.data..percpu..first) \ . = ALIGN(PAGE_SIZE); \ *(.data..percpu..page_aligned) \ . = ALIGN(cacheline); \ *(.data..percpu..read_mostly) \ . = ALIGN(cacheline); \ *(.data..percpu) \ *(.data..percpu..shared_aligned) \ PERCPU_DECRYPTED_SECTION \ __per_cpu_end = .;
but then when the final vmlinux linking happens the hypervisor percpu data is included after page alignment and so the offsets potentially don't match. This manifests as one of the CPUs getting lost when running kvm-unit-tests on EL2 entry and subsequent soft lockup.
--- arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 1 + 1 file changed, 1 insertion(+)
arch/arm64/kvm/hyp/nvhe/hyp.lds.S +1 -0
@@ -13,6 +13,7 @@ SECTIONS { HYP_SECTION(.text) + . = ALIGN(PAGE_SIZE); HYP_SECTION_NAME(.data..percpu) : { PERCPU_INPUT(L1_CACHE_BYTES) }
Signature · 7 lines
2.27.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hi Jamie,
Quoted 17 lines · Jamie Iles
The nVHE percpu data is partially linked but the nVHE linker script did not align the percpu section. The
PERCPU_INPUTmacro would then align the data to a page boundary:#define PERCPU_INPUT(cacheline) \ __per_cpu_start = .; \ *(.data..percpu..first) \ . = ALIGN(PAGE_SIZE); \ *(.data..percpu..page_aligned) \ . = ALIGN(cacheline); \ *(.data..percpu..read_mostly) \ . = ALIGN(cacheline); \ *(.data..percpu) \ *(.data..percpu..shared_aligned) \ PERCPU_DECRYPTED_SECTION \ __per_cpu_end = .;
Quoted 4 lines
but then when the final vmlinux linking happens the hypervisor percpu data is included after page alignment and so the offsets potentially don't match. This manifests as one of the CPUs getting lost when running kvm-unit-tests on EL2 entry and subsequent soft lockup.
You're right - the internal alignment of these subsections can be off after linking into vmlinux. Could you just elaborate on how you managed to trigger this? Which offsets don't match?
Quoted 15 lines
Fixes 30c953911c43 ("kvm: arm64: Set up hyp percpu data for nVHE")Cc David Brazdil <[email protected]>Cc Marc Zyngier <[email protected]>Cc Will Deacon <[email protected]>Signed-off-by Jamie Iles <[email protected]>--- arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 1 + 1 file changed, 1 insertion(+)arch/arm64/kvm/hyp/nvhe/hyp.lds.S +0
-0
arch/arm64/kvm/hyp/nvhe/hyp.lds.S line 16
Quoted 4 lines
arch/arm64/kvm/hyp/nvhe/hyp.lds.S +1
-0@@ -13,6 +13,7 @@ SECTIONS { HYP_SECTION(.text) + . = ALIGN(PAGE_SIZE);
Could you add a comment so that we don't forget why it was needed?
Thanks,
David
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 1/1 kvm: arm64: correctly align nVHE percpu data
The nVHE percpu data is partially linked but the nVHE linker script did not align the percpu section. The PERCPU_INPUT macro would then align the data to a page boundary:
#define PERCPU_INPUT(cacheline) \ __per_cpu_start = .; \ *(.data..percpu..first) \ . = ALIGN(PAGE_SIZE); \ *(.data..percpu..page_aligned) \ . = ALIGN(cacheline); \ *(.data..percpu..read_mostly) \ . = ALIGN(cacheline); \ *(.data..percpu) \ *(.data..percpu..shared_aligned) \ PERCPU_DECRYPTED_SECTION \ __per_cpu_end = .;
but then when the final vmlinux linking happens the hypervisor percpu data is included after page alignment and so the offsets potentially don't match. On my build I saw that the .hyp.data..percpu section was at address 0x20 and then the percpu data would begin at 0x1000 (because of the page alignment in PERCPU_INPUT), but when linked into vmlinux, everything would be shifted down by 0x20 bytes.
This manifests as one of the CPUs getting lost when running kvm-unit-tests or starting any VM and subsequent soft lockup on a Cortex A72 device.
---
v2: add clarifying commentary
arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm64/kvm/hyp/nvhe/hyp.lds.S +5 -0
@@ -13,6 +13,11 @@ SECTIONS { HYP_SECTION(.text) + /* + * .hyp..data..percpu needs to be page aligned to maintain the same + * alignment for when linking into vmlinux. + */ + . = ALIGN(PAGE_SIZE); HYP_SECTION_NAME(.data..percpu) : { PERCPU_INPUT(L1_CACHE_BYTES) }
Signature · 7 lines
2.27.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Thanks Jamie
Quoted 24 lines · Jamie Iles
The nVHE percpu data is partially linked but the nVHE linker script did not align the percpu section. The
PERCPU_INPUTmacro would then align the data to a page boundary:#define PERCPU_INPUT(cacheline) \ __per_cpu_start = .; \ *(.data..percpu..first) \ . = ALIGN(PAGE_SIZE); \ *(.data..percpu..page_aligned) \ . = ALIGN(cacheline); \ *(.data..percpu..read_mostly) \ . = ALIGN(cacheline); \ *(.data..percpu) \ *(.data..percpu..shared_aligned) \ PERCPU_DECRYPTED_SECTION \ __per_cpu_end = .;but then when the final vmlinux linking happens the hypervisor percpu data is included after page alignment and so the offsets potentially don't match. On my build I saw that the .hyp.data..percpu section was at address
0x20and then the percpu data would begin at0x1000(because of the page alignment inPERCPU_INPUT), but when linked into vmlinux, everything would be shifted down by0x20bytes.
Quoted 8 lines
This manifests as one of the CPUs getting lost when running kvm-unit-tests or starting any VM and subsequent soft lockup on a Cortex A72 device.
Fixes 30c953911c43 ("kvm: arm64: Set up hyp percpu data for nVHE")Cc David Brazdil <[email protected]>Cc Marc Zyngier <[email protected]>Cc Will Deacon <[email protected]>
Quoted 26 lines
Signed-off-by Jamie Iles <[email protected]>---
v2: add clarifying commentaryarch/arm64/kvm/hyp/nvhe/hyp.lds.S | 5 +++++ 1 file changed, 5 insertions(+)arch/arm64/kvm/hyp/nvhe/hyp.lds.S +5
-0@@ -13,6 +13,11 @@ SECTIONS { HYP_SECTION(.text) + /* + * .hyp..data..percpu needs to be page aligned to maintain the same + * alignment for when linking into vmlinux. + */ + . = ALIGN(PAGE_SIZE); HYP_SECTION_NAME(.data..percpu) : { PERCPU_INPUT(L1_CACHE_BYTES) }Signature · 1 line
2.27.0
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 17 lines · Jamie Iles
The nVHE percpu data is partially linked but the nVHE linker script did not align the percpu section. The
PERCPU_INPUTmacro would then align the data to a page boundary:#define PERCPU_INPUT(cacheline) \ __per_cpu_start = .; \ *(.data..percpu..first) \ . = ALIGN(PAGE_SIZE); \ *(.data..percpu..page_aligned) \ . = ALIGN(cacheline); \ *(.data..percpu..read_mostly) \ . = ALIGN(cacheline); \ *(.data..percpu) \ *(.data..percpu..shared_aligned) \ PERCPU_DECRYPTED_SECTION \ __per_cpu_end = .;
Quoted 1 line
[...]
Applied to kvm-arm64/fixes-5.10, thanks!
[1/1] KVM: arm64: Correctly align nVHE percpu data
commit: 7bab16a6075b7b94999666355ab532c3dabb94f9
Cheers,
M.
Signature · 8 lines
Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel