Skip to contentSkip to conversation

KVM: arm64: Don't use cbz/adr with external symbols

PATCH Applied Sami Tolvanen 5 participants 5 messages Mar 5, 2021 – Mar 9, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: arm64: Don't use cbz/adr with external symbols

allmodconfig + CONFIG_LTO_CLANG_THIN=y fails to build due to following linker errors:

ld.lld: error: irqbypass.c:(function __guest_enter: .text+0x21CC):
relocation R_AARCH64_CONDBR19 out of range: 2031220 is not in [-1048576, 1048575]; references hyp_panic

Quoted 1 line
Quoted 1 line
Quoted 1 line

defined in vmlinux.o

ld.lld: error: irqbypass.c:(function __guest_enter: .text+0x21E0):
relocation R_AARCH64_ADR_PREL_LO21 out of range: 2031200 is not in [-1048576, 1048575]; references hyp_panic

Quoted 1 line
Quoted 1 line
Quoted 1 line

defined in vmlinux.o

This is because with LTO, the compiler ends up placing hyp_panic() more than 1MB away from __guest_enter(). Use an unconditional branch and adr_l instead to fix the issue.

---
 arch/arm64/kvm/hyp/entry.S | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/arm64/kvm/hyp/entry.S +4 -2
index b0afad7a99c6..c62265951467 100644
@@ -85,8 +85,10 @@ SYM_INNER_LABEL(__guest_exit_panic, SYM_L_GLOBAL)
 
 	// If the hyp context is loaded, go straight to hyp_panic
 	get_loaded_vcpu x0, x1
-	cbz	x0, hyp_panic
+	cbnz	x0, 1f
+	b	hyp_panic
 
+1:
 	// The hyp context is saved so make sure it is restored to allow
 	// hyp_panic to run at hyp and, subsequently, panic to run in the host.
 	// This makes use of __guest_exit to avoid duplication but sets the
@@ -94,7 +96,7 @@ SYM_INNER_LABEL(__guest_exit_panic, SYM_L_GLOBAL)
 	// current state is saved to the guest context but it will only be
 	// accurate if the guest had been completely restored.
 	adr_this_cpu x0, kvm_hyp_ctxt, x1
-	adr	x1, hyp_panic
+	adr_l	x1, hyp_panic
 	str	x1, [x0, #CPU_XREG_OFFSET(30)]
 
 	get_vcpu_ptr	x1, x0

base-commit: 280d542f6ffac0e6d65dc267f92191d509b13b64

Signature · 1 line
2.30.1.766.gb4fecdf3b7-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Sami Tolvanen

allmodconfig + CONFIG_LTO_CLANG_THIN=y fails to build due to following linker errors:

ld.lld: error: irqbypass.c:(function __guest_enter: .text+0x21CC):
relocation R_AARCH64_CONDBR19 out of range: 2031220 is not in [-1048576, 1048575]; references hyp_panic

Quoted 1 line
Quoted 1 line
Quoted 1 line

defined in vmlinux.o

ld.lld: error: irqbypass.c:(function __guest_enter: .text+0x21E0):
relocation R_AARCH64_ADR_PREL_LO21 out of range: 2031200 is not in [-1048576, 1048575]; references hyp_panic

Quoted 1 line
Quoted 1 line
Quoted 1 line

defined in vmlinux.o

This is because with LTO, the compiler ends up placing hyp_panic() more than 1MB away from __guest_enter(). Use an unconditional branch and adr_l instead to fix the issue.

Quoted 5 lines
Signature · 5 lines
Kees Cook
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Tested-by on v1 1/1
#2 lore raw
In reply to Sami Tolvanen
Quoted 17 lines · Sami Tolvanen

allmodconfig + CONFIG_LTO_CLANG_THIN=y fails to build due to following linker errors:

ld.lld: error: irqbypass.c:(function __guest_enter: .text+0x21CC):
relocation R_AARCH64_CONDBR19 out of range: 2031220 is not in [-1048576, 1048575]; references hyp_panic

Quoted 1 line
Quoted 1 line
Quoted 1 line

defined in vmlinux.o

ld.lld: error: irqbypass.c:(function __guest_enter: .text+0x21E0):
relocation R_AARCH64_ADR_PREL_LO21 out of range: 2031200 is not in [-1048576, 1048575]; references hyp_panic

Quoted 1 line
Quoted 1 line
Quoted 1 line

defined in vmlinux.o

This is because with LTO, the compiler ends up placing hyp_panic() more than 1MB away from __guest_enter(). Use an unconditional branch and adr_l instead to fix the issue.

Quoted 5 lines

I booted an kernel with this patch in it on my Raspberry Pi 4 and booted a kernel under KVM without any issues.

Quoted 30 lines
---
 arch/arm64/kvm/hyp/entry.S | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/arm64/kvm/hyp/entry.S +4 -2
index b0afad7a99c6..c62265951467 100644
@@ -85,8 +85,10 @@ SYM_INNER_LABEL(__guest_exit_panic, SYM_L_GLOBAL)
 
 	// If the hyp context is loaded, go straight to hyp_panic
 	get_loaded_vcpu x0, x1
-	cbz	x0, hyp_panic
+	cbnz	x0, 1f
+	b	hyp_panic
 
+1:
 	// The hyp context is saved so make sure it is restored to allow
 	// hyp_panic to run at hyp and, subsequently, panic to run in the host.
 	// This makes use of __guest_exit to avoid duplication but sets the
@@ -94,7 +96,7 @@ SYM_INNER_LABEL(__guest_exit_panic, SYM_L_GLOBAL)
 	// current state is saved to the guest context but it will only be
 	// accurate if the guest had been completely restored.
 	adr_this_cpu x0, kvm_hyp_ctxt, x1
-	adr	x1, hyp_panic
+	adr_l	x1, hyp_panic
 	str	x1, [x0, #CPU_XREG_OFFSET(30)]
 
 	get_vcpu_ptr	x1, x0
Quoted 8 lines

base-commit: 280d542f6ffac0e6d65dc267f92191d509b13b64

Signature · 6 lines
2.30.1.766.gb4fecdf3b7-goog

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Sami Tolvanen
Quoted 17 lines · Sami Tolvanen

allmodconfig + CONFIG_LTO_CLANG_THIN=y fails to build due to following linker errors:

ld.lld: error: irqbypass.c:(function __guest_enter: .text+0x21CC):
relocation R_AARCH64_CONDBR19 out of range: 2031220 is not in [-1048576, 1048575]; references hyp_panic

Quoted 1 line
Quoted 1 line
Quoted 1 line

defined in vmlinux.o

ld.lld: error: irqbypass.c:(function __guest_enter: .text+0x21E0):
relocation R_AARCH64_ADR_PREL_LO21 out of range: 2031200 is not in [-1048576, 1048575]; references hyp_panic

Quoted 1 line
Quoted 1 line
Quoted 1 line

defined in vmlinux.o

This is because with LTO, the compiler ends up placing hyp_panic() more than 1MB away from __guest_enter(). Use an unconditional branch and adr_l instead to fix the issue.

Quoted 8 lines
---
 arch/arm64/kvm/hyp/entry.S | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Will
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer Applied
#4 lore raw
In reply to Sami Tolvanen
Quoted 9 lines · Sami Tolvanen

allmodconfig + CONFIG_LTO_CLANG_THIN=y fails to build due to following linker errors:

ld.lld: error: irqbypass.c:(function __guest_enter: .text+0x21CC):
relocation R_AARCH64_CONDBR19 out of range: 2031220 is not in [-1048576, 1048575]; references hyp_panic

Quoted 1 line
Quoted 1 line
Quoted 1 line

defined in vmlinux.o

[...]

Applied to next, thanks!

[1/1] KVM: arm64: Don't use cbz/adr with external symbols

      commit: dbaee836d60a8e1b03e7d53a37893235662ba124

Cheers,

	M.
Signature · 7 lines
Without deviation from the norm, progress is not possible.


_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm