Skip to content

Commit dbaee83

Browse files
samitolvanenMarc Zyngier
authored andcommitted
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 >>> 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 >>> 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. Link: ClangBuiltLinux#1317 Reported-by: Nathan Chancellor <nathan@kernel.org> Suggested-by: Marc Zyngier <maz@kernel.org> Suggested-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Sami Tolvanen <samitolvanen@google.com> Reviewed-by: Kees Cook <keescook@chromium.org> Acked-by: Will Deacon <will@kernel.org> Tested-by: Nathan Chancellor <nathan@kernel.org> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20210305202124.3768527-1-samitolvanen@google.com
1 parent 357ad20 commit dbaee83

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

arch/arm64/kvm/hyp/entry.S

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,18 @@ SYM_INNER_LABEL(__guest_exit_panic, SYM_L_GLOBAL)
8585

8686
// If the hyp context is loaded, go straight to hyp_panic
8787
get_loaded_vcpu x0, x1
88-
cbz x0, hyp_panic
88+
cbnz x0, 1f
89+
b hyp_panic
8990

91+
1:
9092
// The hyp context is saved so make sure it is restored to allow
9193
// hyp_panic to run at hyp and, subsequently, panic to run in the host.
9294
// This makes use of __guest_exit to avoid duplication but sets the
9395
// return address to tail call into hyp_panic. As a side effect, the
9496
// current state is saved to the guest context but it will only be
9597
// accurate if the guest had been completely restored.
9698
adr_this_cpu x0, kvm_hyp_ctxt, x1
97-
adr x1, hyp_panic
99+
adr_l x1, hyp_panic
98100
str x1, [x0, #CPU_XREG_OFFSET(30)]
99101

100102
get_vcpu_ptr x1, x0

0 commit comments

Comments
 (0)