ANDROID: KVM: arm64: Nop padding for ftrace support in the pKVM hyp

When built with CONFIG_PROTECTED_NVHE_FTRACE, add 3 nops after each
function entry. This intends to make room for the upcoming ftrace
support in the pKVM hypervisor.

Each modified function address is added to the ELF section
__patchable_function_entries.

Tracing related functions are not covered to avoid infinite calls when
ftrace will be wired with tracing.

Bug: 357781595
Change-Id: I7128b459f03470815d975cdc349f6de6846695c0
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
This commit is contained in:
Vincent Donnefort
2024-10-01 13:51:52 +01:00
parent 3a1ca167bb
commit e77aff6717
6 changed files with 21 additions and 2 deletions
+4
View File
@@ -140,6 +140,10 @@ KVM_NVHE_ALIAS(__hyp_rodata_end);
KVM_NVHE_ALIAS(__hyp_event_ids_start);
KVM_NVHE_ALIAS(__hyp_event_ids_end);
KVM_NVHE_ALIAS(__hyp_printk_fmts_start);
#ifdef CONFIG_PROTECTED_NVHE_FTRACE
KVM_NVHE_ALIAS(__hyp_patchable_function_entries_start);
KVM_NVHE_ALIAS(__hyp_patchable_function_entries_end);
#endif
#endif
/* pKVM static key */
+5 -1
View File
@@ -18,7 +18,11 @@
. = ALIGN(PAGE_SIZE); \
__hyp_event_ids_start = .; \
*(HYP_SECTION_NAME(.event_ids)) \
__hyp_event_ids_end = .;
__hyp_event_ids_end = .; \
__hyp_patchable_function_entries_start = .; \
*(HYP_SECTION_NAME(__patchable_function_entries)) \
__hyp_patchable_function_entries_end = .;
#else
#define HYPERVISOR_EVENT_IDS
#endif
+6
View File
@@ -29,4 +29,10 @@ $(obj)/hyp.lds: $(src)/hyp.lds.S FORCE
$(call if_changed_dep,cpp_lds_S)
include $(srctree)/arch/arm64/kvm/hyp/nvhe/Makefile.nvhe
CFLAGS_REMOVE_trace.nvhe.o := -fpatchable-function-entry=3
CFLAGS_REMOVE_events.nvhe.o := -fpatchable-function-entry=3
CFLAGS_REMOVE_ftrace.nvhe.o := -fpatchable-function-entry=3
CFLAGS_REMOVE_setup.nvhe.o := -fpatchable-function-entry=3
obj-y := kvm_nvhe.o
+4
View File
@@ -14,6 +14,10 @@ ccflags-y += -fno-stack-protector \
-DDISABLE_BRANCH_PROFILING \
$(DISABLE_STACKLEAK_PLUGIN)
ifeq ($(CONFIG_PROTECTED_NVHE_FTRACE), y)
ccflags-y += -fpatchable-function-entry=3
endif
HYPREL := arch/arm64/tools/gen-hyprel
##
+1 -1
View File
@@ -34,7 +34,7 @@ void trace_clock_update(u32 mult, u32 shift, u64 epoch_ns, u64 epoch_cyc)
}
/* Using host provided data. Do not use for anything else than debugging. */
u64 trace_clock(void)
u64 __attribute__((patchable_function_entry(0, 0))) trace_clock(void)
{
struct clock_data *clock = &trace_clock_data;
u64 bank = smp_load_acquire(&clock->cur);
+1
View File
@@ -21,6 +21,7 @@ SECTIONS {
BEGIN_HYP_SECTION(.event_ids)
*(SORT(.hyp.event_ids.*))
END_HYP_SECTION
HYP_SECTION(__patchable_function_entries)
#endif
/*