From 818d44dd844f11b3494bdb1273e5d2d3dfb179cf Mon Sep 17 00:00:00 2001 From: Vincent Donnefort Date: Fri, 27 Jan 2023 18:09:24 +0000 Subject: [PATCH] ANDROID: KVM: arm64: Move hyp event enable into ro data section It is expected for hyp events to be used in hot paths. We then need to reduce the overhead of having the events placed even when they are disabled. Moving the variable enabling event tracing into a read-only section increase the chance of sharing a cache line with immutable objects and as a consequence making it less likely to get a cache miss. A RW mapping alias must then be made with the fixmap to turn on and off events. Bug: 229972309 Change-Id: Ib15bb3fd16b3adb9a889a730b701fd26171c9d37 Signed-off-by: Vincent Donnefort --- arch/arm64/kvm/hyp/nvhe/events.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/events.c b/arch/arm64/kvm/hyp/nvhe/events.c index 21c8d7b04e5a..9deb2c31db5e 100644 --- a/arch/arm64/kvm/hyp/nvhe/events.c +++ b/arch/arm64/kvm/hyp/nvhe/events.c @@ -4,13 +4,14 @@ */ #include +#include extern struct hyp_event_id __hyp_event_ids_start[]; extern struct hyp_event_id __hyp_event_ids_end[]; #undef HYP_EVENT #define HYP_EVENT(__name, __proto, __struct, __assign, __printk) \ - atomic_t __name##_enabled = ATOMIC_INIT(0); \ + atomic_t __ro_after_init __name##_enabled = ATOMIC_INIT(0); \ struct hyp_event_id hyp_event_id_##__name __section("_hyp_event_ids") = { \ .data = (void *)&__name##_enabled, \ } @@ -28,11 +29,11 @@ int __pkvm_enable_event(unsigned short id, bool enable) continue; enable_key = (atomic_t *)event_id->data; + enable_key = hyp_fixmap_map(__hyp_pa(enable_key)); - if (enable) - atomic_set(enable_key, 1); - else - atomic_set(enable_key, 0); + atomic_set(enable_key, enable); + + hyp_fixmap_unmap(); return 0; }