Add support for monitoring guest TLB operations
Subsystems (5)
cover Add support for monitoring guest TLB operations
Hi,
ARMv8 supports trapping guest TLB maintenance operations to the hypervisor. This trapping mechanism can be used to monitor the use of guest TLB instructions.
As taking a trap for every TLB operation can have significant overhead, trapping should only be enabled -
* on user request
* for the VM of interest
This patchset adds support to listen to perf trace event state change notifications. The notifications and associated context are then used to enable trapping of guest TLB operations when requested by the user. The trap handling generates trace events (kvm_tlb_invalidate) which can already be counted using existing perf trace functionality.
Trapping of guest TLB operations is disabled when not being monitored (reducing profiling overhead).
I would appreciate feedback on the approach to tie the control of TLB monitoring with perf trace events (Patch 1) especially if there are any suggestions on avoiding (or reducing) the overhead of "perf trace" notifications.
I looked at using regfunc/unregfunc tracepoint hooks but they don't include the event context. But the bigger problem was that the callbacks are only called on the first instance of simultaneously executing perf stat invocations.
The patchset is based on v4.8-rc2 and adds support for monitoring guest TLB operations on 64bit hosts. If the approach taken in the patches is acceptable, I'll add 32bit host support as well.
With this patchset, 'perf' tool when attached to a VM process can be used to monitor the TLB operations. E.g., to monitor a VM with process id 4166 -
# perf stat -e "kvm:kvm_tlb_invalidate" -p 4166
Perform some operations in VM (running 'make -j 7' on the kernel sources in this instance). Breaking out of perf shows -
Performance counter stats for process id '4166':
7,471,974 kvm:kvm_tlb_invalidate
374.235405282 seconds time elapsedAll feedback welcome.
Thanks,
Punit
Mark Rutland (2):
arm64: tlbflush.h: add __tlbi() macro
arm64/kvm: hyp: tlb: use __tlbi() helper
Punit Agrawal (5):
perf/trace: Add notification for perf trace events
KVM: Track the pid of the VM process
KVM: arm/arm64: Register perf trace event notifier
arm64: KVM: Handle trappable TLB instructions
arm64: KVM: Enable selective trapping of TLB instructions
arch/arm/include/asm/kvm_host.h | 3 + arch/arm/kvm/arm.c | 2 + arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/include/asm/kvm_host.h | 8 ++ arch/arm64/include/asm/tlbflush.h | 31 ++++++-- arch/arm64/kvm/Kconfig | 4 + arch/arm64/kvm/Makefile | 1 + arch/arm64/kvm/hyp/tlb.c | 158 ++++++++++++++++++++++++++++++++++++-- arch/arm64/kvm/perf_trace.c | 154 +++++++++++++++++++++++++++++++++++++ arch/arm64/kvm/sys_regs.c | 81 +++++++++++++++++++ arch/arm64/kvm/trace.h | 16 ++++ include/linux/kvm_host.h | 1 + include/linux/trace_events.h | 3 + kernel/trace/trace_event_perf.c | 24 ++++++ virt/kvm/kvm_main.c | 2 + 15 files changed, 475 insertions(+), 14 deletions(-) create mode 100644 arch/arm64/kvm/perf_trace.c
Signature · 1 line
2.8.1
RFC PATCH 1/7 perf/trace: Add notification for perf trace events
Add a mechanism to notify listeners about perf trace event state changes. This enables listeners to take actions requiring the event context (e.g., attached process).
The notification mechanism can be used to reduce trace point based profiling overhead by enabling/disabling hardware traps for specific contexts (e.g., virtual machines).
--- include/linux/trace_events.h | 3 +++ kernel/trace/trace_event_perf.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
include/linux/trace_events.h +3 -0
@@ -505,6 +505,9 @@ perf_trace_buf_submit(void *raw_data, int size, int rctx, u16 type, {perf_tp_event (type, count, raw_data, size, regs, head, rctx, task); } + +extern int perf_trace_notifier_register (struct notifier_block *nb); +extern int perf_trace_notifier_unregister (struct notifier_block *nb);#endif #endif /* _LINUX_TRACE_EVENT_H */
kernel/trace/trace_event_perf.c +24 -0
@@ -6,10 +6,12 @@*/ #include <linux/module.h> +#include <linux/notifier.h> #include <linux/kprobes.h> #include "trace.h" static char __percpu *perf_trace_buf[PERF_NR_CONTEXTS ]; +static RAW_NOTIFIER_HEAD (perf_trace_notifier_list);/* * Force it to be aligned to unsigned long to avoid misaligned accesses
@@ -86,6 +88,26 @@ static int perf_trace_event_perm(struct trace_event_call *tp_event,return 0 ; } +int perf_trace_notifier_register (struct notifier_block *nb) +{ +return raw_notifier_chain_register (&perf_trace_notifier_list, nb); +} + +int perf_trace_notifier_unregister (struct notifier_block *nb) +{ +return raw_notifier_chain_unregister (&perf_trace_notifier_list, nb); +} + +static void perf_trace_notify (enum trace_reg event,struct perf_event *p_event) +{ +/* +* We use raw notifiers here as we are called with the +* event_mutex held. +*/ +raw_notifier_call_chain (&perf_trace_notifier_list, + event, p_event); +} +static int perf_trace_event_reg (struct trace_event_call *tp_event,struct perf_event *p_event) {
@@ -176,6 +198,7 @@ out:static int perf_trace_event_open (struct perf_event *p_event) {struct trace_event_call *tp_event = p_event->tp_event; +perf_trace_notify (TRACE_REG_PERF_OPEN , p_event);return tp_event->class->reg (tp_event,TRACE_REG_PERF_OPEN , p_event); }
@@ -183,6 +206,7 @@ static void perf_trace_event_close(struct perf_event *p_event) {struct trace_event_call *tp_event = p_event->tp_event; tp_event->class->reg (tp_event,TRACE_REG_PERF_CLOSE , p_event); +perf_trace_notify (TRACE_REG_PERF_CLOSE , p_event); } static int perf_trace_event_init(struct trace_event_call *tp_event,
Signature · 1 line
2.8.1
RFC PATCH 2/7 KVM: Track the pid of the VM process
In reply to Punit AgrawalUserspace tools such as perf can be used to profile individual processes.
Track the PID of the virtual machine process to match profiling requests targeted at it. This can be used to take appropriate action to enable the requested profiling operations for the VMs of interest.
--- include/linux/kvm_host.h | 1 + virt/kvm/kvm_main.c | 2 ++ 2 files changed, 3 insertions(+)
include/linux/kvm_host.h +1 -0
@@ -374,6 +374,7 @@ struct kvm_memslots {struct kvm {spinlock_t mmu_lock;struct mutex slots_lock; +struct pid *pid;struct mm_struct *mm;/* userspace tied to this vm */ struct kvm_memslots *memslots[KVM_ADDRESS_SPACE_NUM ];struct srcu_struct srcu;
virt/kvm/kvm_main.c +2 -0
@@ -613,6 +613,7 @@ static struct kvm *kvm_create_vm(unsigned long type)spin_lock_init (&kvm->mmu_lock);atomic_inc (¤t->mm->mm_count); kvm->mm = current->mm; + kvm->pid =get_task_pid (current,PIDTYPE_PID );kvm_eventfd_init (kvm);mutex_init (&kvm->lock);mutex_init (&kvm->irq_lock);
@@ -712,6 +713,7 @@ static void kvm_destroy_vm(struct kvm *kvm)int i;struct mm_struct *mm = kvm->mm; +put_pid (kvm->pid);kvm_destroy_vm_debugfs (kvm);kvm_arch_sync_events (kvm);spin_lock (&kvm_lock);
Signature · 1 line
2.8.1
RFC PATCH 3/7 KVM: arm/arm64: Register perf trace event notifier
In reply to Punit AgrawalRegister a notifier to track state changes of perf trace events.
The notifier will enable taking appropriate action for trace events targeting VM.
--- arch/arm/include/asm/kvm_host.h | 3 + arch/arm/kvm/arm.c | 2 + arch/arm64/include/asm/kvm_host.h | 8 +++ arch/arm64/kvm/Kconfig | 4 ++ arch/arm64/kvm/Makefile | 1 + arch/arm64/kvm/perf_trace.c | 122 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 140 insertions(+) create mode 100644 arch/arm64/kvm/perf_trace.c
arch/arm/include/asm/kvm_host.h +3 -0
@@ -280,6 +280,9 @@ static inline int kvm_arch_dev_ioctl_check_extension(struct kvm *kvm, long ext)int kvm_perf_init (void );int kvm_perf_teardown (void ); +static inline int kvm_perf_trace_init (void ) {return 0 ; } +static inline int kvm_perf_trace_teardown (void ) {return 0 ; } +void kvm_mmu_wp_memory_region (struct kvm *kvm,int slot);struct kvm_vcpu *kvm_mpidr_to_vcpu (struct kvm *kvm,unsigned long mpidr);
arch/arm/kvm/arm.c +2 -0
@@ -1220,6 +1220,7 @@ static int init_subsystems(void) goto out;kvm_perf_init (); +kvm_perf_trace_init ();kvm_coproc_table_init (); out:
@@ -1411,6 +1412,7 @@ out_err:void kvm_arch_exit (void ) {kvm_perf_teardown (); +kvm_perf_trace_teardown (); }static int arm_init (void )
arch/arm64/include/asm/kvm_host.h +8 -0
@@ -345,6 +345,14 @@ int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,int kvm_perf_init (void );int kvm_perf_teardown (void ); +#if !defined(CONFIG_KVM_PERF_TRACE ) +static inline int kvm_perf_trace_init (void ) {return 0 ; } +static inline int kvm_perf_trace_teardown (void ) {return 0 ; } +#else +int kvm_perf_trace_init (void ); +int kvm_perf_trace_teardown (void ); +#endif +struct kvm_vcpu *kvm_mpidr_to_vcpu (struct kvm *kvm,unsigned long mpidr); static inline void __cpu_init_hyp_mode(phys_addr_t pgd_ptr,
arch/arm64/kvm/Kconfig +4 -0
@@ -19,6 +19,9 @@ if VIRTUALIZATION config KVM_ARM_VGIC_V3 bool +config KVM_PERF_TRACE + bool + config KVM bool "Kernel-based Virtual Machine (KVM) support" depends on OF
@@ -39,6 +42,7 @@ config KVM select HAVE_KVM_MSI select HAVE_KVM_IRQCHIP select HAVE_KVM_IRQ_ROUTING + select KVM_PERF_TRACE if EVENT_TRACING && PERF_EVENTS ---help--- Support hosting virtualized guest machines. We don't support KVM with 16K page tables yet, due to the multiple
arch/arm64/kvm/Makefile +1 -0
@@ -19,6 +19,7 @@ kvm-$(CONFIG_KVM_ARM_HOST) += $(ARM)/psci.o $(ARM)/perf.o kvm-$(CONFIG_KVM_ARM_HOST) += emulate.o inject_fault.o regmap.o kvm-$(CONFIG_KVM_ARM_HOST) += hyp.o hyp-init.o handle_exit.o kvm-$(CONFIG_KVM_ARM_HOST) += guest.o debug.o reset.o sys_regs.o sys_regs_generic_v8.o +kvm-$(CONFIG_KVM_PERF_TRACE) += perf_trace.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-init.o
arch/arm64/kvm/perf_trace.c new file +122 -0
122 lines not on this page · raw message
Signature · 1 line
2.8.1
RFC PATCH 4/7 arm64: tlbflush.h: add __tlbi() macro
In reply to Punit AgrawalFrom: Mark Rutland <[email protected]>
As with dsb() and isb(), add a __tbli() helper so that we can avoid distracting asm boilerplate every time we want a TLBI. As some TLBI operations take an argument while others do not, some pre-processor is used to handle these two cases with different assembly blocks.
The existing tlbflush.h code is moved over to use the helper.
--- arch/arm64/include/asm/tlbflush.h | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)
arch/arm64/include/asm/tlbflush.h +23 -8
@@ -25,6 +25,21 @@#include <asm/cputype.h> /* +* Raw TLBI operations. Drivers and most kernel code should use the TLB +* management routines below in preference to these. Where necessary, these can +* be used to avoid asm() boilerplate. +* +* Can be used as __tlbi(op) or __tlbi(op, arg), depending on whether a +* particular TLBI op takes an argument or not. The macros below handle invoking +* the asm with or without the register argument as appropriate. +*/ +#define TLBI_0 (op, arg) asm ("tlbi " #op) +#define TLBI_1 (op, arg) asm ("tlbi " #op ", %0" : : "r" (arg)) +#define TLBI_N (op, arg, n, ...) TLBI_##n(op, arg) + +#define __tlbi (op, ...) TLBI_N(op, ##__VA_ARGS__, 1, 0) + +/* * TLB Management * ============== *
@@ -66,7 +81,7 @@static inline void local_flush_tlb_all (void ) {dsb (nshst); - asm("tlbi vmalle1" ); +__tlbi (vmalle1);dsb (nsh);isb (); }
@@ -74,7 +89,7 @@ static inline void local_flush_tlb_all(void)static inline void flush_tlb_all (void ) {dsb (ishst); - asm("tlbi vmalle1is" ); +__tlbi (vmalle1is);dsb (ish);isb (); }
@@ -84,7 +99,7 @@ static inline void flush_tlb_mm(struct mm_struct *mm)unsigned long asid =ASID (mm) <<48 ;dsb (ishst); - asm("tlbi aside1is, %0" : :"r" (asid)); +__tlbi (aside1is, asid);dsb (ish); }
@@ -94,7 +109,7 @@ static inline void flush_tlb_page(struct vm_area_struct *vma,unsigned long addr = uaddr >>12 | (ASID (vma->vm_mm) <<48 );dsb (ishst); - asm("tlbi vale1is, %0" : :"r" (addr)); +__tlbi (vale1is, addr);dsb (ish); }
@@ -122,9 +137,9 @@ static inline void __flush_tlb_range(struct vm_area_struct *vma,dsb (ishst);for (addr = start; addr < end; addr +=1 << (PAGE_SHIFT -12 )) {if (last_level) - asm("tlbi vale1is, %0" : :"r" (addr)); +__tlbi (vale1is, addr);else - asm("tlbi vae1is, %0" : :"r" (addr)); +__tlbi (vae1is, addr); }dsb (ish); }
@@ -149,7 +164,7 @@ static inline void flush_tlb_kernel_range(unsigned long start, unsigned long enddsb (ishst);for (addr = start; addr < end; addr +=1 << (PAGE_SHIFT -12 )) - asm("tlbi vaae1is, %0" : :"r" (addr)); +__tlbi (vaae1is, addr);dsb (ish);isb (); }
@@ -163,7 +178,7 @@ static inline void __flush_tlb_pgtable(struct mm_struct *mm, {unsigned long addr = uaddr >>12 | (ASID (mm) <<48 ); - asm("tlbi vae1is, %0" : :"r" (addr)); +__tlbi (vae1is, addr);dsb (ish); }
Signature · 1 line
2.8.1
RFC PATCH 5/7 arm64/kvm: hyp: tlb: use __tlbi() helper
In reply to Punit AgrawalFrom: Mark Rutland <[email protected]>
Now that we have a __tlbi() helper, make use of this in the arm64 KVM hyp code to get rid of asm() boilerplate. At the same time, we simplify __tlb_flush_vm_context by using __flush_icache_all(), as this has the appropriate instruction cache maintenance and barrier.
--- arch/arm64/kvm/hyp/tlb.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/arm64/kvm/hyp/tlb.c +6 -6
@@ -16,6 +16,7 @@*/ #include <asm/kvm_hyp.h> +#include <asm/tlbflush.h> static void __hyp_text __tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa) {
@@ -32,7 +33,7 @@ static void __hyp_text __tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)* whole of Stage-1. Weep... */ ipa >>=12 ; - asmvolatile ("tlbi ipas2e1is, %0" : :"r" (ipa)); +__tlbi (ipas2e1is, ipa);/* * We have to ensure completion of the invalidation at Stage-2,
@@ -41,7 +42,7 @@ static void __hyp_text __tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)* the Stage-1 invalidation happened first. */ dsb (ish); - asmvolatile ("tlbi vmalle1is" : : ); +__tlbi (vmalle1is);dsb (ish);isb ();
@@ -60,7 +61,7 @@ static void __hyp_text __tlb_flush_vmid(struct kvm *kvm)write_sysreg (kvm->arch.vttbr, vttbr_el2);isb (); - asmvolatile ("tlbi vmalls12e1is" : : ); +__tlbi (vmalls12e1is);dsb (ish);isb ();
@@ -72,9 +73,8 @@ __alias(__tlb_flush_vmid) void __kvm_tlb_flush_vmid(struct kvm *kvm); static void __hyp_text __tlb_flush_vm_context(void) {dsb (ishst); - asmvolatile ("tlbi alle1is \n" -"ic ialluis " : : ); -dsb (ish); +__tlbi (alle1is); +__flush_icache_all ();/* contains a dsb(ish) */ } __alias(__tlb_flush_vm_context) void __kvm_flush_vm_context(void);
Signature · 1 line
2.8.1
RFC PATCH 6/7 arm64: KVM: Handle trappable TLB instructions
In reply to Punit AgrawalThe ARMv8 architecture allows trapping of TLB maintenane instructions from EL0/EL1 to higher exception levels. On encountering a trappable TLB instruction in a guest, an exception is taken to EL2.
Add functionality to handle emulating the TLB instructions.
--- arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/kvm/hyp/tlb.c | 146 +++++++++++++++++++++++++++++++++++++++ arch/arm64/kvm/sys_regs.c | 81 ++++++++++++++++++++++ arch/arm64/kvm/trace.h | 16 +++++ 4 files changed, 244 insertions(+)
arch/arm64/include/asm/kvm_asm.h +1 -0
@@ -49,6 +49,7 @@ extern char __kvm_hyp_vector[];extern void __kvm_flush_vm_context (void );extern void __kvm_tlb_flush_vmid_ipa (struct kvm *kvm,phys_addr_t ipa);extern void __kvm_tlb_flush_vmid (struct kvm *kvm); +extern void __kvm_emulate_tlb_invalidate (struct kvm *kvm,u32 sysreg,u64 regval);extern int __kvm_vcpu_run (struct kvm_vcpu *vcpu);
arch/arm64/kvm/hyp/tlb.c +146 -0
149 lines not on this page · raw message
arch/arm64/kvm/sys_regs.c +81 -0
99 lines not on this page · raw message
arch/arm64/kvm/trace.h +16 -0
@@ -166,6 +166,22 @@ TRACE_EVENT(kvm_set_guest_debug,TP_printk ("vcpu: %p, flags: 0x%08x" , __entry->vcpu, __entry->guest_debug) ); +TRACE_EVENT (kvm_tlb_invalidate, + TP_PROTO(unsigned long vcpu_pc, u32 opcode), +TP_ARGS (vcpu_pc, opcode), + +TP_STRUCT__entry ( + __field(unsigned long, vcpu_pc) +__field (u32, opcode) + ), + +TP_fast_assign ( + __entry->vcpu_pc = vcpu_pc; + __entry->opcode = opcode; + ), + +TP_printk ("vcpu_pc=0x%16lx opcode=%08x" , __entry->vcpu_pc, __entry->opcode) +);#endif /* _TRACE_ARM64_KVM_H */
Signature · 1 line
2.8.1
RFC PATCH 7/7 arm64: KVM: Enable selective trapping of TLB instructions
In reply to Punit AgrawalThe TTLB bit of Hypervisor Control Register (HCR_EL2) controls the trapping of guest TLB maintenance instructions. Taking the trap requires a switch to the hypervisor and is an expensive operation.
Enable selective trapping of guest TLB instructions when the associated perf trace event is enabled for a specific virtual machine.
--- arch/arm64/kvm/perf_trace.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
arch/arm64/kvm/perf_trace.c +32 -0
@@ -17,6 +17,8 @@#include <linux/kvm_host.h> #include <linux/trace_events.h> +#include <asm/kvm_emulate.h> +typedef int (*perf_trace_callback_fn )(struct kvm *kvm,bool enable);struct kvm_trace_hook {
@@ -24,7 +26,37 @@ struct kvm_trace_hook {perf_trace_callback_fn setup_fn; }; +static int tlb_invalidate_trap (struct kvm *kvm,bool enable) +{ +int i; +struct kvm_vcpu *vcpu; + +/* +* Halt the VM to ensure atomic update across all vcpus (this +* avoids racy behaviour against other modifications of +* HCR_EL2 such as kvm_toggle_cache/kvm_set_way_flush). +*/ +kvm_arm_halt_guest (kvm); +kvm_for_each_vcpu (i, vcpu, kvm) { +unsigned long hcr =vcpu_get_hcr (vcpu); + +if (enable) + hcr |=HCR_TTLB ; +else + hcr &= ~HCR_TTLB ; + +vcpu_set_hcr (vcpu, hcr); + } +kvm_arm_resume_guest (kvm); + +return 0 ; +} +static struct kvm_trace_hook trace_hook[] = { + { + .key ="kvm_tlb_invalidate" , + .setup_fn = tlb_invalidate_trap, + }, { }, };
Signature · 1 line
2.8.1
Paolo Bonzini
maintainerQuoted 45 lines · Punit Agrawal
Hi,
ARMv8 supports trapping guest TLB maintenance operations to the hypervisor. This trapping mechanism can be used to monitor the use of guest TLB instructions.
As taking a trap for every TLB operation can have significant overhead, trapping should only be enabled -
* on user request
* for the VM of interestThis patchset adds support to listen to perf trace event state change notifications. The notifications and associated context are then used to enable trapping of guest TLB operations when requested by the user. The trap handling generates trace events (
kvm_tlb_invalidate) which can already be counted using existing perf trace functionality.Trapping of guest TLB operations is disabled when not being monitored (reducing profiling overhead).
I would appreciate feedback on the approach to tie the control of TLB monitoring with perf trace events (Patch 1) especially if there are any suggestions on avoiding (or reducing) the overhead of "perf trace" notifications.
I looked at using regfunc/unregfunc tracepoint hooks but they don't include the event context. But the bigger problem was that the callbacks are only called on the first instance of simultaneously executing perf stat invocations.
The patchset is based on v4.8-rc2 and adds support for monitoring guest TLB operations on 64bit hosts. If the approach taken in the patches is acceptable, I'll add 32bit host support as well.
With this patchset, 'perf' tool when attached to a VM process can be used to monitor the TLB operations. E.g., to monitor a VM with process id 4166 -
# perf stat -e "kvm:kvm_tlb_invalidate" -p 4166Perform some operations in VM (running 'make -j 7' on the kernel sources in this instance). Breaking out of perf shows -
Quoted 7 lines
Performance counter stats for process id '4166':
7,471,974 kvm:kvm_tlb_invalidate 374.235405282 seconds time elapsedAll feedback welcome.
Can you explain what this is used for? In other words, why would this be used instead of just running perf in the guest?
Thanks,
Paolo
Quoted 48 lines · Paolo Bonzini
Quoted 47 lines · Punit Agrawal
Hi,
ARMv8 supports trapping guest TLB maintenance operations to the hypervisor. This trapping mechanism can be used to monitor the use of guest TLB instructions.
As taking a trap for every TLB operation can have significant overhead, trapping should only be enabled -
* on user request
* for the VM of interestThis patchset adds support to listen to perf trace event state change notifications. The notifications and associated context are then used to enable trapping of guest TLB operations when requested by the user. The trap handling generates trace events (
kvm_tlb_invalidate) which can already be counted using existing perf trace functionality.Trapping of guest TLB operations is disabled when not being monitored (reducing profiling overhead).
I would appreciate feedback on the approach to tie the control of TLB monitoring with perf trace events (Patch 1) especially if there are any suggestions on avoiding (or reducing) the overhead of "perf trace" notifications.
I looked at using regfunc/unregfunc tracepoint hooks but they don't include the event context. But the bigger problem was that the callbacks are only called on the first instance of simultaneously executing perf stat invocations.
The patchset is based on v4.8-rc2 and adds support for monitoring guest TLB operations on 64bit hosts. If the approach taken in the patches is acceptable, I'll add 32bit host support as well.
With this patchset, 'perf' tool when attached to a VM process can be used to monitor the TLB operations. E.g., to monitor a VM with process id 4166 -
# perf stat -e "kvm:kvm_tlb_invalidate" -p 4166Perform some operations in VM (running 'make -j 7' on the kernel sources in this instance). Breaking out of perf shows -
Performance counter stats for process id '4166':
Quoted 8 lines
Quoted 5 lines
7,471,974 kvm:kvm_tlb_invalidate 374.235405282 seconds time elapsedAll feedback welcome.
Can you explain what this is used for? In other words, why would this be used instead of just running perf in the guest?
As TLB maintenance operations are synchronised in hardware, they can impact performance beyond the guest. The operations generate traffic on the interconnect and depending on the implementation, they can also affect the remote TLB's translation bandwidth.
These patches are useful on systems where the host and guest are controlled by different users - the guest could be running arbitrary software.
Having the ability to monitor the usage of guest TLB invalidations in the host can be useful to diagnose performance issues on such systems.
Quoted 8 lines
Thanks,
Paolo
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Paolo Bonzini
maintainerQuoted 8 lines · Punit Agrawal
Quoted 2 lines
Can you explain what this is used for? In other words, why would this be used instead of just running perf in the guest?
As TLB maintenance operations are synchronised in hardware, they can impact performance beyond the guest. The operations generate traffic on the interconnect and depending on the implementation, they can also affect the remote TLB's translation bandwidth.
Quoted 6 lines
These patches are useful on systems where the host and guest are controlled by different users - the guest could be running arbitrary software.
Having the ability to monitor the usage of guest TLB invalidations in the host can be useful to diagnose performance issues on such systems.
Are there hardware performance counters for these operations?
Paolo
Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Punit Agrawal
Quoted 2 lines
Can you explain what this is used for? In other words, why would this be used instead of just running perf in the guest?
As TLB maintenance operations are synchronised in hardware, they can impact performance beyond the guest. The operations generate traffic on the interconnect and depending on the implementation, they can also affect the remote TLB's translation bandwidth.
Quoted 8 lines
Quoted 6 lines
These patches are useful on systems where the host and guest are controlled by different users - the guest could be running arbitrary software.
Having the ability to monitor the usage of guest TLB invalidations in the host can be useful to diagnose performance issues on such systems.
Are there hardware performance counters for these operations?
That would have been ideal! There are PMU events defined for TLB accesses and refills but unhelpfully none of them track maintenance operations.
Quoted 6 lines
Paolo
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Paolo Bonzini
maintainerQuoted 8 lines · Punit Agrawal
Quoted 4 lines
Quoted 2 lines
Having the ability to monitor the usage of guest TLB invalidations in the host can be useful to diagnose performance issues on such systems.
Are there hardware performance counters for these operations?
That would have been ideal! There are PMU events defined for TLB accesses and refills but unhelpfully none of them track maintenance operations.
I guess the patches do make sense then. :)
Paolo
Re: [RFC PATCH 4/7] arm64: tlbflush.h: add __tlbi() macro
In reply to Punit AgrawalQuoted 3 lines · Punit Agrawal
From: Mark Rutland <[email protected]>
As with
dsb()andisb(), add a__tbli()helper so that we can avoid
Minor typo: s/__tbli/__tlbi/
Quoted 25 lines
distracting asm boilerplate every time we want a TLBI. As some TLBI operations take an argument while others do not, some pre-processor is used to handle these two cases with different assembly blocks.
The existing
tlbflush.hcode is moved over to use the helper.Signed-off-by Mark Rutland <[email protected]>Cc Catalin Marinas <[email protected]>Cc Marc Zyngier <[email protected]>Cc Will Deacon <[email protected]>[ rename helper to __tlbi, update commit log ]Signed-off-by Punit Agrawal <[email protected]>--- arch/arm64/include/asm/tlbflush.h | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)arch/arm64/include/asm/tlbflush.h +1
-0@@ -25,6 +25,21 @@#include <asm/cputype.h> /* +* Raw TLBI operations. Drivers and most kernel code should use the TLB
arch/arm64/include/asm/tlbflush.h line 38
Quoted 10 lines
arch/arm64/include/asm/tlbflush.h +10
-0+* management routines below in preference to these. Where necessary, these can +* be used to avoid asm() boilerplate. +* +* Can be used as __tlbi(op) or __tlbi(op, arg), depending on whether a +* particular TLBI op takes an argument or not. The macros below handle invoking +* the asm with or without the register argument as appropriate. +*/ +#define TLBI_0 (op, arg) asm ("tlbi " #op) +#define TLBI_1 (op, arg) asm ("tlbi " #op ", %0" : : "r" (arg)) +#define TLBI_N (op, arg, n, ...) TLBI_##n(op, arg)
Should this be prefixed with underscores, too?
Will
Re: [RFC PATCH 4/7] arm64: tlbflush.h: add __tlbi() macro
Quoted 6 lines · Will Deacon
Quoted 3 lines · Punit Agrawal
From: Mark Rutland <[email protected]>
As with
dsb()andisb(), add a__tbli()helper so that we can avoidMinor typo: s/__tbli/__tlbi/
Thanks for spotting. I've fixed this locally now.
Quoted 24 lines
Quoted 24 lines
distracting asm boilerplate every time we want a TLBI. As some TLBI operations take an argument while others do not, some pre-processor is used to handle these two cases with different assembly blocks.
The existing
tlbflush.hcode is moved over to use the helper.Signed-off-by Mark Rutland <[email protected]>Cc Catalin Marinas <[email protected]>Cc Marc Zyngier <[email protected]>Cc Will Deacon <[email protected]>[ rename helper to __tlbi, update commit log ]Signed-off-by Punit Agrawal <[email protected]>--- arch/arm64/include/asm/tlbflush.h | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)arch/arm64/include/asm/tlbflush.h +0
-0@@ -25,6 +25,21 @@#include <asm/cputype.h>
Quoted 14 lines
arch/arm64/include/asm/tlbflush.h line 38
Quoted 12 lines
arch/arm64/include/asm/tlbflush.h +11
-0/* +* Raw TLBI operations. Drivers and most kernel code should use the TLB +* management routines below in preference to these. Where necessary, these can +* be used to avoid asm() boilerplate. +* +* Can be used as __tlbi(op) or __tlbi(op, arg), depending on whether a +* particular TLBI op takes an argument or not. The macros below handle invoking +* the asm with or without the register argument as appropriate. +*/ +#define TLBI_0 (op, arg) asm ("tlbi " #op) +#define TLBI_1 (op, arg) asm ("tlbi " #op ", %0" : : "r" (arg)) +#define TLBI_N (op, arg, n, ...) TLBI_##n(op, arg)Should this be prefixed with underscores, too?
As these were only used in the definition of __tlbi() I didn't prefix them. I'll add them for the next posting.
Thanks for taking a look.
Punit
Quoted 6 lines
Will
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [RFC PATCH 6/7] arm64: KVM: Handle trappable TLB instructions
In reply to Punit AgrawalHi Punit,
Quoted 9 lines · Punit Agrawal
The ARMv8 architecture allows trapping of TLB maintenane instructions from EL0/EL1 to higher exception levels. On encountering a trappable TLB instruction in a guest, an exception is taken to EL2.
Add functionality to handle emulating the TLB instructions.
Signed-off-by Punit Agrawal <[email protected]>Cc Christoffer Dall <[email protected]>Cc Marc Zyngier <[email protected]>
[...]
Quoted 21 lines
arch/arm64/kvm/hyp/tlb.c +21
-0+void __hyp_text +__kvm_emulate_tlb_invalidate (struct kvm *kvm,u32 sys_op,u64 regval) +{ + kvm =kern_hyp_va (kvm); + +/* +* Switch to the guest before performing any TLB operations to +* target the appropriate VMID +*/ +__switch_to_guest_regime (kvm); + +/* +* TLB maintenance operations broadcast to inner-shareable +* domain when HCR_FB is set (default for KVM). +*/ +switch (sys_op) { +case TLBIALL : +case TLBIALLIS : +case ITLBIALL : +case DTLBIALL : +case TLBI_VMALLE1 :
arch/arm64/kvm/hyp/tlb.c static void __hyp_text __tlb_flush_vm_context(void) · line 194
Quoted 10 lines
arch/arm64/kvm/hyp/tlb.c +10
-0+case TLBI_VMALLE1IS : +__tlbi (vmalle1is); +break ; +case TLBIMVA : +case TLBIMVAIS : +case ITLBIMVA : +case DTLBIMVA : +case TLBI_VAE1 : +case TLBI_VAE1IS : +__tlbi (vae1is, regval);
I'm pretty nervous about this. Although you've switched in the guest stage-2 page table before the TLB maintenance, we're still running on a host stage-1 and it's not clear to me that the stage-1 context is completely ignored for the purposes of a stage-1 TLBI executed at EL2.
For example, if TCR_EL1.TBI0 is set in the guest but cleared in the host, my reading of the architecture is that it will be treated as zero when we perform this invalidation operation. I worry that we have similar problems with the granule size, where bits become RES0 in the TLBI VA ops.
Finally, we should probably be masking out the RES0 bits in the TLBI ops, just in case some future extension to the architecture defines them in such a way where they have different meanings when executed at EL2 or EL1.
The easiest thing to do is just TLBI VMALLE1IS for all trapped operations, but you might want to see how that performs.
Will
Re: [RFC PATCH 6/7] arm64: KVM: Handle trappable TLB instructions
Quoted 52 lines · Will Deacon
Hi Punit,
Quoted 9 lines · Punit Agrawal
The ARMv8 architecture allows trapping of TLB maintenane instructions from EL0/EL1 to higher exception levels. On encountering a trappable TLB instruction in a guest, an exception is taken to EL2.
Add functionality to handle emulating the TLB instructions.
Signed-off-by Punit Agrawal <[email protected]>Cc Christoffer Dall <[email protected]>Cc Marc Zyngier <[email protected]>[...]
Quoted 21 lines
arch/arm64/kvm/hyp/tlb.c +21
-0+void __hyp_text +__kvm_emulate_tlb_invalidate (struct kvm *kvm,u32 sys_op,u64 regval) +{ + kvm =kern_hyp_va (kvm); + +/* +* Switch to the guest before performing any TLB operations to +* target the appropriate VMID +*/ +__switch_to_guest_regime (kvm); + +/* +* TLB maintenance operations broadcast to inner-shareable +* domain when HCR_FB is set (default for KVM). +*/ +switch (sys_op) { +case TLBIALL : +case TLBIALLIS : +case ITLBIALL : +case DTLBIALL : +case TLBI_VMALLE1 :arch/arm64/kvm/hyp/tlb.c static void __hyp_text __tlb_flush_vm_context(void) · line 194
Quoted 10 lines
arch/arm64/kvm/hyp/tlb.c +10
-0+case TLBI_VMALLE1IS : +__tlbi (vmalle1is); +break ; +case TLBIMVA : +case TLBIMVAIS : +case ITLBIMVA : +case DTLBIMVA : +case TLBI_VAE1 : +case TLBI_VAE1IS : +__tlbi (vae1is, regval);I'm pretty nervous about this. Although you've switched in the guest stage-2 page table before the TLB maintenance, we're still running on a host stage-1 and it's not clear to me that the stage-1 context is completely ignored for the purposes of a stage-1 TLBI executed at EL2.
Quoted 5 lines
For example, if TCR_EL1.TBI0 is set in the guest but cleared in the host, my reading of the architecture is that it will be treated as zero when we perform this invalidation operation. I worry that we have similar problems with the granule size, where bits become RES0 in the TLBI VA ops.
Some control bits seem to be explicitly called out to not affect TLB maintenance operations[0] but I hadn't considered the ones you highlight.
[0] ARMv8 ARM DDI 0487A.j D4.7, Pg D4-1814
Quoted 5 lines
Finally, we should probably be masking out the RES0 bits in the TLBI ops, just in case some future extension to the architecture defines them in such a way where they have different meanings when executed at EL2 or EL1.
Although, the RES0 bits for TLBI VA ops are currently ignored, I agree that masking them out based on granule size protects against future incompatible changes.
Quoted 3 lines
The easiest thing to do is just TLBI VMALLE1IS for all trapped operations, but you might want to see how that performs.
That sounds reasonable for correctness. But I suspect we'll have to do more to claw back some performance. Let me run a few tests and come back on this.
Thanks for having a look.
Punit
Quoted 6 lines
Will
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [RFC PATCH 6/7] arm64: KVM: Handle trappable TLB instructions
Quoted 76 lines · Punit Agrawal
Quoted 52 lines · Will Deacon
Hi Punit,
Quoted 9 lines · Punit Agrawal
The ARMv8 architecture allows trapping of TLB maintenane instructions from EL0/EL1 to higher exception levels. On encountering a trappable TLB instruction in a guest, an exception is taken to EL2.
Add functionality to handle emulating the TLB instructions.
Signed-off-by Punit Agrawal <[email protected]>Cc Christoffer Dall <[email protected]>Cc Marc Zyngier <[email protected]>[...]
Quoted 21 lines
arch/arm64/kvm/hyp/tlb.c +21
-0+void __hyp_text +__kvm_emulate_tlb_invalidate (struct kvm *kvm,u32 sys_op,u64 regval) +{ + kvm =kern_hyp_va (kvm); + +/* +* Switch to the guest before performing any TLB operations to +* target the appropriate VMID +*/ +__switch_to_guest_regime (kvm); + +/* +* TLB maintenance operations broadcast to inner-shareable +* domain when HCR_FB is set (default for KVM). +*/ +switch (sys_op) { +case TLBIALL : +case TLBIALLIS : +case ITLBIALL : +case DTLBIALL : +case TLBI_VMALLE1 :arch/arm64/kvm/hyp/tlb.c static void __hyp_text __tlb_flush_vm_context(void) · line 194
Quoted 10 lines
arch/arm64/kvm/hyp/tlb.c +10
-0+case TLBI_VMALLE1IS : +__tlbi (vmalle1is); +break ; +case TLBIMVA : +case TLBIMVAIS : +case ITLBIMVA : +case DTLBIMVA : +case TLBI_VAE1 : +case TLBI_VAE1IS : +__tlbi (vae1is, regval);I'm pretty nervous about this. Although you've switched in the guest stage-2 page table before the TLB maintenance, we're still running on a host stage-1 and it's not clear to me that the stage-1 context is completely ignored for the purposes of a stage-1 TLBI executed at EL2.
Quoted 5 lines
For example, if TCR_EL1.TBI0 is set in the guest but cleared in the host, my reading of the architecture is that it will be treated as zero when we perform this invalidation operation. I worry that we have similar problems with the granule size, where bits become RES0 in the TLBI VA ops.
Some control bits seem to be explicitly called out to not affect TLB maintenance operations[0] but I hadn't considered the ones you highlight.
[0] ARMv8 ARM DDI 0487A.j D4.7, Pg D4-1814
Quoted 5 lines
Finally, we should probably be masking out the RES0 bits in the TLBI ops, just in case some future extension to the architecture defines them in such a way where they have different meanings when executed at EL2 or EL1.
Although, the RES0 bits for TLBI VA ops are currently ignored, I agree that masking them out based on granule size protects against future incompatible changes.
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
The easiest thing to do is just TLBI VMALLE1IS for all trapped operations, but you might want to see how that performs.
That sounds reasonable for correctness. But I suspect we'll have to do more to claw back some performance. Let me run a few tests and come back on this.
Assuming I've correctly switched in TCR and replacing the various TLB operations in this patch with TLBI VMALLE1IS, there is a drop in kernel build times of ~5% (384s vs 363s).
For the next version, I'll use this as a starting point and try clawing back the loss by using the appropriate TLB instructions albeit with additional sanity checking based on context.
Quoted 15 lines
Thanks for having a look.
Punit
Quoted 6 lines
Will
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [RFC PATCH 6/7] arm64: KVM: Handle trappable TLB instructions
Quoted 81 lines · On Fri, 26 Aug 2016 10:37:08 +0100 Punit Agrawal <[email protected]> wrote:
Quoted 79 lines · Punit Agrawal
Quoted 52 lines · Will Deacon
Hi Punit,
Quoted 9 lines · Punit Agrawal
The ARMv8 architecture allows trapping of TLB maintenane instructions from EL0/EL1 to higher exception levels. On encountering a trappable TLB instruction in a guest, an exception is taken to EL2.
Add functionality to handle emulating the TLB instructions.
Signed-off-by Punit Agrawal <[email protected]>Cc Christoffer Dall <[email protected]>Cc Marc Zyngier <[email protected]>[...]
Quoted 21 lines
arch/arm64/kvm/hyp/tlb.c +21
-0+void __hyp_text +__kvm_emulate_tlb_invalidate (struct kvm *kvm,u32 sys_op,u64 regval) +{ + kvm =kern_hyp_va (kvm); + +/* +* Switch to the guest before performing any TLB operations to +* target the appropriate VMID +*/ +__switch_to_guest_regime (kvm); + +/* +* TLB maintenance operations broadcast to inner-shareable +* domain when HCR_FB is set (default for KVM). +*/ +switch (sys_op) { +case TLBIALL : +case TLBIALLIS : +case ITLBIALL : +case DTLBIALL : +case TLBI_VMALLE1 :arch/arm64/kvm/hyp/tlb.c static void __hyp_text __tlb_flush_vm_context(void) · line 194
Quoted 10 lines
arch/arm64/kvm/hyp/tlb.c +10
-0+case TLBI_VMALLE1IS : +__tlbi (vmalle1is); +break ; +case TLBIMVA : +case TLBIMVAIS : +case ITLBIMVA : +case DTLBIMVA : +case TLBI_VAE1 : +case TLBI_VAE1IS : +__tlbi (vae1is, regval);I'm pretty nervous about this. Although you've switched in the guest stage-2 page table before the TLB maintenance, we're still running on a host stage-1 and it's not clear to me that the stage-1 context is completely ignored for the purposes of a stage-1 TLBI executed at EL2.
Quoted 5 lines
For example, if TCR_EL1.TBI0 is set in the guest but cleared in the host, my reading of the architecture is that it will be treated as zero when we perform this invalidation operation. I worry that we have similar problems with the granule size, where bits become RES0 in the TLBI VA ops.
Some control bits seem to be explicitly called out to not affect TLB maintenance operations[0] but I hadn't considered the ones you highlight.
[0] ARMv8 ARM DDI 0487A.j D4.7, Pg D4-1814
Quoted 5 lines
Finally, we should probably be masking out the RES0 bits in the TLBI ops, just in case some future extension to the architecture defines them in such a way where they have different meanings when executed at EL2 or EL1.
Although, the RES0 bits for TLBI VA ops are currently ignored, I agree that masking them out based on granule size protects against future incompatible changes.
Quoted 3 lines
The easiest thing to do is just TLBI VMALLE1IS for all trapped operations, but you might want to see how that performs.
Quoted 7 lines
Quoted 3 lines
That sounds reasonable for correctness. But I suspect we'll have to do more to claw back some performance. Let me run a few tests and come back on this.
Assuming I've correctly switched in TCR and replacing the various TLB operations in this patch with TLBI VMALLE1IS, there is a drop in kernel build times of ~5% (384s vs 363s).
Note that if all you're doing is a VMALLE1IS, switching TCR_EL1 should not be necessary, as all that is required for this invalidation is the VMID.
Quoted 3 lines
For the next version, I'll use this as a starting point and try clawing back the loss by using the appropriate TLB instructions albeit with additional sanity checking based on context.
Great, thanks!
M.
Signature · 1 line
Jazz is not dead. It just smells funny.
Re: [RFC PATCH 1/7] perf/trace: Add notification for perf trace events
In reply to Punit AgrawalQuoted 11 lines · Punit Agrawal
Add a mechanism to notify listeners about perf trace event state changes. This enables listeners to take actions requiring the event context (e.g., attached process).
The notification mechanism can be used to reduce trace point based profiling overhead by enabling/disabling hardware traps for specific contexts (e.g., virtual machines).
Signed-off-by Punit Agrawal <[email protected]>Cc Steven Rostedt <[email protected]>Cc Ingo Molnar <[email protected]>
While I respin the series addressing comments on the arm64 architectural bits, I'd appreciate any feedback on this patch as it forms the basis of the rest of the series.
Thanks,
Punit
Quoted 79 lines
--- include/linux/trace_events.h | 3 +++ kernel/trace/trace_event_perf.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+)include/linux/trace_events.h +3
-0@@ -505,6 +505,9 @@ perf_trace_buf_submit(void *raw_data, int size, int rctx, u16 type, {perf_tp_event (type, count, raw_data, size, regs, head, rctx, task); } + +extern int perf_trace_notifier_register (struct notifier_block *nb); +extern int perf_trace_notifier_unregister (struct notifier_block *nb);#endif #endif /* _LINUX_TRACE_EVENT_H */ kernel/trace/trace_event_perf.c +24
-0@@ -6,10 +6,12 @@*/ #include <linux/module.h> +#include <linux/notifier.h> #include <linux/kprobes.h> #include "trace.h" static char __percpu *perf_trace_buf[PERF_NR_CONTEXTS ]; +static RAW_NOTIFIER_HEAD (perf_trace_notifier_list);/* * Force it to be aligned to unsigned long to avoid misaligned accesses @@ -86,6 +88,26 @@ static int perf_trace_event_perm(struct trace_event_call *tp_event,return 0 ; } +int perf_trace_notifier_register (struct notifier_block *nb) +{ +return raw_notifier_chain_register (&perf_trace_notifier_list, nb); +} + +int perf_trace_notifier_unregister (struct notifier_block *nb) +{ +return raw_notifier_chain_unregister (&perf_trace_notifier_list, nb); +} + +static void perf_trace_notify (enum trace_reg event,struct perf_event *p_event) +{ +/* +* We use raw notifiers here as we are called with the +* event_mutex held. +*/ +raw_notifier_call_chain (&perf_trace_notifier_list, + event, p_event); +} +static int perf_trace_event_reg (struct trace_event_call *tp_event,struct perf_event *p_event) {@@ -176,6 +198,7 @@ out:static int perf_trace_event_open (struct perf_event *p_event) {struct trace_event_call *tp_event = p_event->tp_event; +perf_trace_notify (TRACE_REG_PERF_OPEN , p_event);return tp_event->class->reg (tp_event,TRACE_REG_PERF_OPEN , p_event); }@@ -183,6 +206,7 @@ static void perf_trace_event_close(struct perf_event *p_event) {struct trace_event_call *tp_event = p_event->tp_event; tp_event->class->reg (tp_event,TRACE_REG_PERF_CLOSE , p_event); +perf_trace_notify (TRACE_REG_PERF_CLOSE , p_event); } static int perf_trace_event_init(struct trace_event_call *tp_event,
Re: [RFC PATCH 6/7] arm64: KVM: Handle trappable TLB instructions
In reply to Punit AgrawalQuoted 11 lines · Punit Agrawal
Quoted 7 lines
Quoted 2 lines · Will Deacon
The easiest thing to do is just TLBI VMALLE1IS for all trapped operations, but you might want to see how that performs.
That sounds reasonable for correctness. But I suspect we'll have to do more to claw back some performance. Let me run a few tests and come back on this.
Assuming I've correctly switched in TCR and replacing the various TLB operations in this patch with TLBI VMALLE1IS, there is a drop in kernel build times of ~5% (384s vs 363s).
What do you mean by "switched in TCR"? Why is that necessary if you just nuke the whole thing? Is the ~5% relative to no trapping at all, or trapping, but being selective about the operation?
Will
Re: [RFC PATCH 6/7] arm64: KVM: Handle trappable TLB instructions
Quoted 9 lines · Will Deacon
Quoted 8 lines · Punit Agrawal
Quoted 7 lines
Quoted 2 lines · Will Deacon
The easiest thing to do is just TLBI VMALLE1IS for all trapped operations, but you might want to see how that performs.
That sounds reasonable for correctness. But I suspect we'll have to do more to claw back some performance. Let me run a few tests and come back on this.
Quoted 6 lines
Quoted 3 lines
Assuming I've correctly switched in TCR and replacing the various TLB operations in this patch with TLBI VMALLE1IS, there is a drop in kernel build times of ~5% (384s vs 363s).
What do you mean by "switched in TCR"? Why is that necessary if you just nuke the whole thing?
You're right. it's not necessary. I'd misunderstood how TCR affects things and was switching it in the above tests.
Quoted 2 lines
Is the ~5% relative to no trapping at all, or trapping, but being selective about the operation?
The reported number was relative to trapping and being selective about the operation. But I hadn't been careful in ensuring identical conditions (page caches, etc.) when running the numbers.
So I've done a fresh set of identical measurements by running "time make -j 7" in a VM booted with 7 vcpus and see the following results
1. no trapping ~ 365s
2. traps using selective tlb operations ~ 371s
3. traps that nuke all stage 1 (tlbi vmalle1is) ~ 393s
So based on these measurements there is ~1% and ~7.5% drop in comparison between 2. and 3. compared to the base case of no trapping at all.
Thanks,
Punit
Quoted 6 lines
Will
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm