Move __hyp_text code under no-asan Makefiles
Subsystems (3)
cover Move __hyp_text code under no-asan Makefiles
The fancy new pmu code added its __hyp_text code in part of the tree that doesn't get covered by the no-asan/no-kcov kconfig decorations. This shows up as a hyp-panic on v8.0 hardware when the host kernel is built with debug options like kasan.
This same bug has been living happily in the aarch32 emulation code since v4.9. (commit 8cebe750c4d9a "arm64: KVM: Make kvm_skip_instr32 available to HYP"). Patch 2 has the two relevant fixes tag, but won't apply cleanly before v4.19 due to the churn.
Fix them both by shuffling the code around.
Thanks,
James Morse (2):
KVM: arm64: Move pmu hyp code under hyp's Makefile to avoid
instrumentation
KVM: arm/arm64: Move cc/it checks under hyp's Makefile to avoid
instrumentation
arch/arm/kvm/hyp/Makefile | 1 + arch/arm64/kvm/hyp/Makefile | 1 + arch/arm64/kvm/hyp/switch.c | 39 +++++++++++ arch/arm64/kvm/pmu.c | 38 ---------- virt/kvm/arm/aarch32.c | 121 -------------------------------- virt/kvm/arm/hyp/aarch32.c | 136 ++++++++++++++++++++++++++++++++++++ 6 files changed, 177 insertions(+), 159 deletions(-) create mode 100644 virt/kvm/arm/hyp/aarch32.c
Signature · 6 lines
2.20.1 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH 1/2 KVM: arm64: Move pmu hyp code under hyp's Makefile to avoid instrumentation
KVM's pmu.c contains the __hyp_text needed to switch the pmu registers between host and guest. Because this isn't covered by the 'hyp' Makefile, it can be built with kasan and friends when these are enabled in Kconfig.
When starting a guest, this results in:
| Kernel panic - not syncing: HYP panic: | PS:a00003c9 PC:000083000028ada0 ESR:86000007 | FAR:000083000028ada0 HPFAR:0000000029df5300 PAR:0000000000000000 | VCPU:000000004e10b7d6 | CPU: 0 PID: 3088 Comm: qemu-system-aar Not tainted 5.2.0-rc1 #11026 | Hardware name: ARM LTD ARM Juno Development Platform/ARM Juno Development Plat | Call trace: | dump_backtrace+0x0/0x200 | show_stack+0x20/0x30 | dump_stack+0xec/0x158 | panic+0x1ec/0x420 | panic+0x0/0x420 | SMP: stopping secondary CPUs | Kernel Offset: disabled | CPU features: 0x002,25006082 | Memory Limit: none | ---[ end Kernel panic - not syncing: HYP panic:
This is caused by functions in pmu.c calling the instrumented code, which isn't mapped to hyp. From objdump -r:
| RELOCATION RECORDS FOR [.hyp.text]: | OFFSET TYPE VALUE | 0000000000000010 R_AARCH64_CALL26 __sanitizer_cov_trace_pc | 0000000000000018 R_AARCH64_CALL26 __asan_load4_noabort | 0000000000000024 R_AARCH64_CALL26 __asan_load4_noabort
Move the affected code to a new file under 'hyp's Makefile.
--- arch/arm64/kvm/hyp/switch.c | 39 +++++++++++++++++++++++++++++++++++++ arch/arm64/kvm/pmu.c | 38 ------------------------------------ 2 files changed, 39 insertions(+), 38 deletions(-)
arch/arm64/kvm/hyp/switch.c +39 -0
@@ -16,6 +16,7 @@*/ #include <linux/arm-smccc.h> +#include <linux/kvm_host.h> #include <linux/types.h> #include <linux/jump_label.h> #include <uapi/linux/psci.h>
@@ -703,3 +704,41 @@ void __hyp_text __noreturn hyp_panic(struct kvm_cpu_context *host_ctxt)unreachable (); } + +/** +* Disable host events, enable guest events +*/ +bool __hyp_text __pmu_switch_to_guest(struct kvm_cpu_context *host_ctxt) +{ +struct kvm_host_data *host; +struct kvm_pmu_events *pmu; + + host = container_of(host_ctxt, struct kvm_host_data, host_ctxt); + pmu = &host->pmu_events; + +if (pmu->events_host) +write_sysreg (pmu->events_host, pmcntenclr_el0); + +if (pmu->events_guest) +write_sysreg (pmu->events_guest, pmcntenset_el0); + +return (pmu->events_host || pmu->events_guest); +} + +/** +* Disable guest events, enable host events +*/ +void __hyp_text __pmu_switch_to_host(struct kvm_cpu_context *host_ctxt) +{ +struct kvm_host_data *host; +struct kvm_pmu_events *pmu; + + host = container_of(host_ctxt, struct kvm_host_data, host_ctxt); + pmu = &host->pmu_events; + +if (pmu->events_guest) +write_sysreg (pmu->events_guest, pmcntenclr_el0); + +if (pmu->events_host) +write_sysreg (pmu->events_host, pmcntenset_el0); +}
arch/arm64/kvm/pmu.c +0 -38
@@ -53,44 +53,6 @@ void kvm_clr_pmu_events(u32 clr) ctx->pmu_events.events_guest &= ~clr; } -/** -* Disable host events, enable guest events -*/ -bool __hyp_text __pmu_switch_to_guest(struct kvm_cpu_context *host_ctxt) -{ -struct kvm_host_data *host; -struct kvm_pmu_events *pmu; - - host = container_of(host_ctxt, struct kvm_host_data, host_ctxt); - pmu = &host->pmu_events; - -if (pmu->events_host) -write_sysreg (pmu->events_host, pmcntenclr_el0); - -if (pmu->events_guest) -write_sysreg (pmu->events_guest, pmcntenset_el0); - -return (pmu->events_host || pmu->events_guest); -} - -/** -* Disable guest events, enable host events -*/ -void __hyp_text __pmu_switch_to_host(struct kvm_cpu_context *host_ctxt) -{ -struct kvm_host_data *host; -struct kvm_pmu_events *pmu; - - host = container_of(host_ctxt, struct kvm_host_data, host_ctxt); - pmu = &host->pmu_events; - -if (pmu->events_guest) -write_sysreg (pmu->events_guest, pmcntenclr_el0); - -if (pmu->events_host) -write_sysreg (pmu->events_host, pmcntenset_el0); -} -#define PMEVTYPER_READ_CASE (idx) \ case idx: \ return read_sysreg(pmevtyper##idx##_el0)
Signature · 6 lines
2.20.1 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH 1/2] KVM: arm64: Move pmu hyp code under hyp's Makefile to avoid instrumentation
Hi James,
Quoted 54 lines · James Morse
KVM's
pmu.ccontains the__hyp_textneeded to switch the pmu registers between host and guest. Because this isn't covered by the 'hyp'Makefile, it can be built with kasan and friends when these are enabled inKconfig.When starting a guest, this results in:
| Kernel panic - not syncing: HYP panic: | PS:a00003c9 PC:000083000028ada0 ESR:86000007 | FAR:000083000028ada0 HPFAR:0000000029df5300 PAR:0000000000000000 | VCPU:000000004e10b7d6 | CPU: 0 PID: 3088 Comm: qemu-system-aar Not tainted 5.2.0-rc1 #11026 | Hardware name: ARM LTD ARM Juno Development Platform/ARM Juno Development Plat | Call trace: | dump_backtrace+0x0/0x200 | show_stack+0x20/0x30 | dump_stack+0xec/0x158 | panic+0x1ec/0x420 | panic+0x0/0x420 | SMP: stopping secondary CPUs | Kernel Offset: disabled | CPU features: 0x002,25006082 | Memory Limit: none | ---[ end Kernel panic - not syncing: HYP panic:This is caused by functions in
pmu.ccalling the instrumented code, which isn't mapped to hyp. From objdump -r:| RELOCATION RECORDS FOR [.hyp.text]: | OFFSET TYPE VALUE | 0000000000000010 R_AARCH64_CALL26 __sanitizer_cov_trace_pc | 0000000000000018 R_AARCH64_CALL26 __asan_load4_noabort | 0000000000000024 R_AARCH64_CALL26 __asan_load4_noabortMove the affected code to a new file under 'hyp's
Makefile.Fixes 3d91befbb3a0 ("arm64: KVM: Enable !VHE support for :G/:H perf event modifiers")Cc Andrew Murray <[email protected]>Signed-off-by James Morse <[email protected]>--- arch/arm64/kvm/hyp/switch.c | 39 +++++++++++++++++++++++++++++++++++++ arch/arm64/kvm/pmu.c | 38 ------------------------------------ 2 files changed, 39 insertions(+), 38 deletions(-)arch/arm64/kvm/hyp/switch.c +1
-0@@ -16,6 +16,7 @@*/ #include <linux/arm-smccc.h> +#include <linux/kvm_host.h> #include <linux/types.h> #include <linux/jump_label.h> #include <uapi/linux/psci.h>
arch/arm64/kvm/hyp/switch.c void __hyp_text __noreturn hyp_panic(struct kvm_cpu_context *host_ctxt) · line 711
Quoted 8 lines
arch/arm64/kvm/hyp/switch.c +5
-0@@ -703,3 +704,41 @@ void __hyp_text __noreturn hyp_panic(struct kvm_cpu_context *host_ctxt)unreachable (); } + +/** +* Disable host events, enable guest events +*/ +bool __hyp_text __pmu_switch_to_guest(struct kvm_cpu_context *host_ctxt)
I think this could now be made static, and the declarations removed from asm/kvm_host.h.
Thanks,
M.
Signature · 5 lines
Jazz is not dead. It just smells funny... _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH 2/2 KVM: arm/arm64: Move cc/it checks under hyp's Makefile to avoid instrumentation
In reply to James MorseKVM has helpers to handle the condition codes of trapped aarch32 instructions. These are marked __hyp_text and used from HYP, but they aren't built by the 'hyp' Makefile, which has all the runes to avoid ASAN and KCOV instrumentation, used when debugging.
Move this code to a new hyp/aarch32.c to avoid a hyp-panic when starting an aarch32 guest on a host built with the ASAN/KCOV debug options.
--- arch/arm/kvm/hyp/Makefile | 1 + arch/arm64/kvm/hyp/Makefile | 1 + virt/kvm/arm/aarch32.c | 121 -------------------------------- virt/kvm/arm/hyp/aarch32.c | 136 ++++++++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+), 121 deletions(-) create mode 100644 virt/kvm/arm/hyp/aarch32.c
arch/arm/kvm/hyp/Makefile +1 -0
@@ -11,6 +11,7 @@ CFLAGS_ARMV7VE :=$(call cc-option, -march=armv7ve) obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/vgic-v3-sr.o obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/timer-sr.o +obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/aarch32.o obj-$(CONFIG_KVM_ARM_HOST) += tlb.o obj-$(CONFIG_KVM_ARM_HOST) += cp15-sr.o
arch/arm64/kvm/hyp/Makefile +1 -0
@@ -10,6 +10,7 @@ KVM=../../../../virt/kvm obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/vgic-v3-sr.o obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/timer-sr.o +obj-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/hyp/aarch32.o obj-$(CONFIG_KVM_ARM_HOST) += vgic-v2-cpuif-proxy.o obj-$(CONFIG_KVM_ARM_HOST) += sysreg-sr.o
virt/kvm/arm/aarch32.c +0 -121
127 lines not on this page · raw message
virt/kvm/arm/hyp/aarch32.c new file +136 -0
136 lines not on this page · raw message
Signature · 6 lines
2.20.1 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm