From b556e0c960be85c09dc2145fd8f7ccc15f1027b2 Mon Sep 17 00:00:00 2001 From: Vincent Donnefort Date: Tue, 1 Oct 2024 10:24:59 +0100 Subject: [PATCH] ANDROID: KVM: arm64: Fix hyp events ELF section order It is not possible to assume the compiler will order events in the sections _hyp_events and .hyp.event_ids the same way. So force that order using the linker script SORT. Somehow this worked on previous Android version until ftrace shuffled things out. Bug: 357781595 Bug: 268495982 Bug: 273748186 Change-Id: I21ca85b7aa321367f0c126bf6b74d56db87eb19d Signed-off-by: Vincent Donnefort --- arch/arm64/include/asm/kvm_define_hypevents.h | 2 +- arch/arm64/include/asm/module.lds.h | 7 +++++++ arch/arm64/kernel/vmlinux.lds.S | 2 +- arch/arm64/kvm/hyp/include/nvhe/trace/define_events.h | 2 +- arch/arm64/kvm/hyp/nvhe/hyp.lds.S | 4 +++- arch/arm64/kvm/hyp/nvhe/module.lds.S | 2 +- 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/kvm_define_hypevents.h b/arch/arm64/include/asm/kvm_define_hypevents.h index 39e5963e0c2a..095acc8df477 100644 --- a/arch/arm64/include/asm/kvm_define_hypevents.h +++ b/arch/arm64/include/asm/kvm_define_hypevents.h @@ -50,7 +50,7 @@ #define HYP_EVENT(__name, __proto, __struct, __assign, __printk) \ static char hyp_event_print_fmt_##__name[] = __printk; \ static bool hyp_event_enabled_##__name; \ - struct hyp_event __section("_hyp_events") hyp_event_##__name = {\ + struct hyp_event __section("_hyp_events."#__name) hyp_event_##__name = {\ .name = #__name, \ .enabled = &hyp_event_enabled_##__name, \ .fields = hyp_event_fields_##__name, \ diff --git a/arch/arm64/include/asm/module.lds.h b/arch/arm64/include/asm/module.lds.h index eeaa96938a6c..608bd1cb3dbb 100644 --- a/arch/arm64/include/asm/module.lds.h +++ b/arch/arm64/include/asm/module.lds.h @@ -41,7 +41,13 @@ SECTIONS { . = ALIGN(PAGE_SIZE); } .hyp.event_ids : ALIGN(PAGE_SIZE) { + /* + * Yet empty, without that *(.hyp.event_ids) input section + * (named after the output section), the location counter + * page-alignment below is ignored. + */ *(.hyp.event_ids) + *(SORT(.hyp.event_ids.*)) *(.hyp.printk_fmt_offset) . = ALIGN(PAGE_SIZE); } @@ -50,5 +56,6 @@ SECTIONS { . = ALIGN(PAGE_SIZE); } .hyp.reloc : ALIGN(4) { *(.hyp.reloc) } + _hyp_events : { *(SORT(_hyp_events.*)) } #endif } diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 407a1a3cb950..481e88afb747 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -224,7 +224,7 @@ SECTIONS #ifdef CONFIG_TRACING .rodata.hyp_events : { __hyp_events_start = .; - *(_hyp_events) + *(SORT(_hyp_events.*)) __hyp_events_end = .; } .rodata.hyp_printk_fmts : { diff --git a/arch/arm64/kvm/hyp/include/nvhe/trace/define_events.h b/arch/arm64/kvm/hyp/include/nvhe/trace/define_events.h index 3947c1e47ef4..869971d471e2 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/trace/define_events.h +++ b/arch/arm64/kvm/hyp/include/nvhe/trace/define_events.h @@ -10,7 +10,7 @@ #define HYP_EVENT(__name, __proto, __struct, __assign, __printk) \ atomic_t __ro_after_init __name##_enabled = ATOMIC_INIT(0); \ struct hyp_event_id hyp_event_id_##__name \ - __section(".hyp.event_ids") = { \ + __section(".hyp.event_ids." # __name) = { \ .data = (void *)&__name##_enabled, \ } diff --git a/arch/arm64/kvm/hyp/nvhe/hyp.lds.S b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S index b9ad9e662c32..f588c284bd25 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp.lds.S +++ b/arch/arm64/kvm/hyp/nvhe/hyp.lds.S @@ -18,7 +18,9 @@ SECTIONS { HYP_SECTION(.rodata) #ifdef CONFIG_TRACING . = ALIGN(PAGE_SIZE); - HYP_SECTION(.event_ids) + BEGIN_HYP_SECTION(.event_ids) + *(SORT(.hyp.event_ids.*)) + END_HYP_SECTION #endif /* diff --git a/arch/arm64/kvm/hyp/nvhe/module.lds.S b/arch/arm64/kvm/hyp/nvhe/module.lds.S index 26e13e8568fe..945dd1b334a5 100644 --- a/arch/arm64/kvm/hyp/nvhe/module.lds.S +++ b/arch/arm64/kvm/hyp/nvhe/module.lds.S @@ -21,7 +21,7 @@ SECTIONS { .hyp.event_ids : { HYP_SECTION_SYMBOL_NAME(.event_ids) = .; - *(HYP_SECTION_NAME(.event_ids)) + *(SORT(HYP_SECTION_NAME(.event_ids.*))) *(HYP_SECTION_NAME(.printk_fmt_offset)) }