x86/split_lock: Provide KVM helper to log guest bus lock exits
RFC PATCH 1/1 x86/split_lock: Provide KVM helper to log guest bus lock exits
Bus locks monopolize the memory bus for thousands of cycles, stalling all CPUs and degrading system performance for every workload on the system. Cloud providers running multiple VMs need a way to identify which guest is responsible, so the offending VM can be flagged.
Bus lock VMEXITs on AMD are fault-style, i.e. the vCPU's RIP points to the offending instruction at the time of the exit. Log guest's linear RIP and vCPU info to give operators the data needed to attribute the bus lock to a specific VM and instruction. Keep policy enforcement to userspace via KVM_EXIT_X86_BUS_LOCK and let userspace implement throttling or other mitigations.
Reuse current->reported_split_lock to limit the warning to the once per vCPU thread. Note that, current->reported_split_lock tracks the vCPU thread, not the individual guest process, i.e. the warning fires once per vCPU for the lifetime of thread regardless of how many distinct guest processes trigger bus locks on that vCPU.
----
The intent is purely observational — give hypervisor owners visibility into which guest is generating bus locks so they can act accordingly. No policy enforcement is done in the kernel. Suggestions on the approach are welcome.
--- arch/x86/include/asm/cpu.h | 2 ++ arch/x86/kernel/cpu/bus_lock.c | 19 +++++++++++++++++++ arch/x86/kvm/svm/svm.c | 1 + 3 files changed, 22 insertions(+)
arch/x86/include/asm/cpu.h +2 -0
@@ -29,6 +29,7 @@ unsigned int x86_stepping(unsigned int sig);extern void __init sld_setup (struct cpuinfo_x86 *c);extern bool handle_user_split_lock (struct pt_regs *regs,long error_code);extern bool handle_guest_split_lock (unsigned long ip); +extern void handle_guest_bus_lock (unsigned long ip);extern void handle_bus_lock (struct pt_regs *regs);void split_lock_init (void );void bus_lock_init (void );
@@ -44,6 +45,7 @@ static inline bool handle_guest_split_lock(unsigned long ip)return false; } +static inline void handle_guest_bus_lock (unsigned long ip) {}static inline void handle_bus_lock (struct pt_regs *regs) {}static inline void split_lock_init (void ) {}static inline void bus_lock_init (void ) {}
arch/x86/kernel/cpu/bus_lock.c +19 -0
@@ -292,6 +292,25 @@ bool handle_guest_split_lock(unsigned long ip) }EXPORT_SYMBOL_FOR_KVM (handle_guest_split_lock); +void handle_guest_bus_lock (unsigned long ip) +{ +/* +* Log bus lock exit when called from KVM exit handlers. Policy +* enforcement is delegated to userspace via KVM_EXIT_X86_BUS_LOCK. +* Let userspace implement throttling or other mitigations. +* +* Only log when split lock detection is active to respect system-wide +* bus lock detection policy. Use the reported_split_lock flag to +* prevent log spam from the same vCPU. +*/ +if (sld_state != sld_off && !current->reported_split_lock) { +pr_warn_ratelimited ("%s/%d buslock at rip: 0x%lx\n" , + current->comm, current->pid, ip); + current->reported_split_lock =1 ; + } +} +EXPORT_SYMBOL_FOR_KVM (handle_guest_bus_lock); +void bus_lock_init (void ) {u64 val;
arch/x86/kvm/svm/svm.c +1 -0
@@ -3258,6 +3258,7 @@ static int bus_lock_exit(struct kvm_vcpu *vcpu) vcpu->arch.cui_linear_rip =kvm_get_linear_rip (vcpu); vcpu->arch.complete_userspace_io = complete_userspace_buslock; +handle_guest_bus_lock (vcpu->arch.cui_linear_rip);if (is_guest_mode (vcpu)) svm->nested.last_bus_lock_rip = vcpu->arch.cui_linear_rip;
Signature · 1 line
2.43.0
Borislav Petkov
maintainerQuoted 5 lines · Manali Shukla
Bus locks monopolize the memory bus for thousands of cycles, stalling all CPUs and degrading system performance for every workload on the system. Cloud providers running multiple VMs need a way to identify which guest is responsible, so the offending VM can be flagged.
Quoted 8 lines
Bus lock VMEXITs on AMD are fault-style, i.e. the vCPU's RIP points to the offending instruction at the time of the exit. Log guest's linear RIP and vCPU info to give operators the data needed to attribute the bus lock to a specific VM and instruction. Keep policy enforcement to userspace via
KVM_EXIT_X86_BUS_LOCKand let userspace implement throttling or other mitigations.Reuse
current->reported_split_lockto limit the warning to the once per
s/ to the once/ to once/
Quoted 3 lines
vCPU thread. Note that,
current->reported_split_locktracks the vCPU thread, not the individual guest process, i.e. the warning fires once per vCPU for the lifetime of thread regardless of how many distinct
"... for the lifetime of the thread... "
Quoted 1 line
guest processes trigger bus locks on that vCPU.
I guess that's fine since you're ratelimited.
Quoted 2 lines
----
What's that "----" supposed to denote here?
Quoted 4 lines
The intent is purely observational — give hypervisor owners visibility into which guest is generating bus locks so they can act accordingly. No policy enforcement is done in the kernel. Suggestions on the approach are welcome.
Oh, sounds like you want this paragraph to be...
Quoted 4 lines
Suggested-by Nikunj A Dadhania <[email protected]>Signed-off-by Manali Shukla <[email protected]>---
<--- ... here, after the SOB block and above the diffstat.
Quoted 30 lines
arch/x86/include/asm/cpu.h | 2 ++ arch/x86/kernel/cpu/bus_lock.c | 19 +++++++++++++++++++ arch/x86/kvm/svm/svm.c | 1 + 3 files changed, 22 insertions(+)arch/x86/include/asm/cpu.h +2
-0@@ -29,6 +29,7 @@ unsigned int x86_stepping(unsigned int sig);extern void __init sld_setup (struct cpuinfo_x86 *c);extern bool handle_user_split_lock (struct pt_regs *regs,long error_code);extern bool handle_guest_split_lock (unsigned long ip); +extern void handle_guest_bus_lock (unsigned long ip);extern void handle_bus_lock (struct pt_regs *regs);void split_lock_init (void );void bus_lock_init (void );@@ -44,6 +45,7 @@ static inline bool handle_guest_split_lock(unsigned long ip)return false; } +static inline void handle_guest_bus_lock (unsigned long ip) {}static inline void handle_bus_lock (struct pt_regs *regs) {}static inline void split_lock_init (void ) {}static inline void bus_lock_init (void ) {}arch/x86/kernel/cpu/bus_lock.c +0
-0
arch/x86/kernel/cpu/bus_lock.c bool handle_guest_split_lock(unsigned long ip) · line 295
Quoted 4 lines
arch/x86/kernel/cpu/bus_lock.c +1
-0@@ -292,6 +292,25 @@ bool handle_guest_split_lock(unsigned long ip) }EXPORT_SYMBOL_FOR_KVM (handle_guest_split_lock); +void handle_guest_bus_lock (unsigned long ip)
Exported function better have a prefix:
bus_lock_guest_handle() or so.
But, the only reason this function is here is because you need sld_state.
So, instead of doing that, you can add a helper called
sld_enabled()
or so, which is exported and then you can put the guest-specific handling in svm.c in case you want to expand it in the future and there you use sld_enabled(), etc...
Quoted 7 lines
arch/x86/kernel/cpu/bus_lock.c +7
-0+{ +/* +* Log bus lock exit when called from KVM exit handlers. Policy +* enforcement is delegated to userspace via KVM_EXIT_X86_BUS_LOCK. +* Let userspace implement throttling or other mitigations. +* +* Only log when split lock detection is active to respect system-wide
arch/x86/kernel/cpu/bus_lock.c bool handle_guest_split_lock(unsigned long ip) · line 312
Quoted 10 lines
arch/x86/kernel/cpu/bus_lock.c +10
-0+* bus lock detection policy. Use the reported_split_lock flag to +* prevent log spam from the same vCPU. +*/ +if (sld_state != sld_off && !current->reported_split_lock) { +pr_warn_ratelimited ("%s/%d buslock at rip: 0x%lx\n" , + current->comm, current->pid, ip); + current->reported_split_lock =1 ; + } +} +EXPORT_SYMBOL_FOR_KVM (handle_guest_bus_lock);
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 37 lines · Borislav Petkov
Quoted 5 lines · Manali Shukla
Bus locks monopolize the memory bus for thousands of cycles, stalling all CPUs and degrading system performance for every workload on the system. Cloud providers running multiple VMs need a way to identify which guest is responsible, so the offending VM can be flagged.
Quoted 8 lines
Bus lock VMEXITs on AMD are fault-style, i.e. the vCPU's RIP points to the offending instruction at the time of the exit. Log guest's linear RIP and vCPU info to give operators the data needed to attribute the bus lock to a specific VM and instruction. Keep policy enforcement to userspace via
KVM_EXIT_X86_BUS_LOCKand let userspace implement throttling or other mitigations.Reuse
current->reported_split_lockto limit the warning to the once pers/ to the once/ to once/
Quoted 3 lines
vCPU thread. Note that,
current->reported_split_locktracks the vCPU thread, not the individual guest process, i.e. the warning fires once per vCPU for the lifetime of thread regardless of how many distinct"... for the lifetime of the thread... "
Quoted 1 line
guest processes trigger bus locks on that vCPU.
I guess that's fine since you're ratelimited.
Quoted 2 lines
----
What's that "----" supposed to denote here?
Quoted 4 lines
The intent is purely observational — give hypervisor owners visibility into which guest is generating bus locks so they can act accordingly. No policy enforcement is done in the kernel. Suggestions on the approach are welcome.
Quoted 8 lines
Oh, sounds like you want this paragraph to be...
Quoted 4 lines
Suggested-by Nikunj A Dadhania <[email protected]>Signed-off-by Manali Shukla <[email protected]>---
<--- ... here, after the SOB block and above the diffstat.
Oh, my bad. will correct in v2.
Quoted 42 lines
Quoted 31 lines
arch/x86/include/asm/cpu.h | 2 ++ arch/x86/kernel/cpu/bus_lock.c | 19 +++++++++++++++++++ arch/x86/kvm/svm/svm.c | 1 + 3 files changed, 22 insertions(+)arch/x86/include/asm/cpu.h +2
-0@@ -29,6 +29,7 @@ unsigned int x86_stepping(unsigned int sig);extern void __init sld_setup (struct cpuinfo_x86 *c);extern bool handle_user_split_lock (struct pt_regs *regs,long error_code);extern bool handle_guest_split_lock (unsigned long ip); +extern void handle_guest_bus_lock (unsigned long ip);extern void handle_bus_lock (struct pt_regs *regs);void split_lock_init (void );void bus_lock_init (void );@@ -44,6 +45,7 @@ static inline bool handle_guest_split_lock(unsigned long ip)return false; } +static inline void handle_guest_bus_lock (unsigned long ip) {}static inline void handle_bus_lock (struct pt_regs *regs) {}static inline void split_lock_init (void ) {}static inline void bus_lock_init (void ) {}arch/x86/kernel/cpu/bus_lock.c +0
-0arch/x86/kernel/cpu/bus_lock.c bool handle_guest_split_lock(unsigned long ip) · line 295
Quoted 4 lines
arch/x86/kernel/cpu/bus_lock.c +1
-0@@ -292,6 +292,25 @@ bool handle_guest_split_lock(unsigned long ip) }EXPORT_SYMBOL_FOR_KVM (handle_guest_split_lock); +void handle_guest_bus_lock (unsigned long ip)Exported function better have a prefix:
bus_lock_guest_handle()or so.But, the only reason this function is here is because you need
sld_state.
Quoted 8 lines
So, instead of doing that, you can add a helper called
sld_enabled()or so, which is exported and then you can put the guest-specific handling in
svm.cin case you want to expand it in the future and there you usesld_enabled(), etc...
Thank you for your suggestion, will fix the naming in v2. sld_enabled() could be added in bus_lock.c and called from bus_lock_exit() in svm.c. However, the other reason for keeping the function in bus_lock.c is the current->reported_split_lock usage - it is already used in split_lock_warn() and handle_guest_split_lock() in the same file, so keeping all reported_split_lock accesses in bus_lock.c seemed more maintainable. But happy to move it to svm.c, if you prefer that approach.
Quoted 11 lines
Quoted 11 lines
arch/x86/kernel/cpu/bus_lock.c +11
-0+{ +/* +* Log bus lock exit when called from KVM exit handlers. Policy +* enforcement is delegated to userspace via KVM_EXIT_X86_BUS_LOCK. +* Let userspace implement throttling or other mitigations. +* +* Only log when split lock detection is active to respect system-wide +* bus lock detection policy. Use the reported_split_lock flag to +* prevent log spam from the same vCPU. +*/ +if (sld_state != sld_off && !current->reported_split_lock) {
Quoted 9 lines
arch/x86/kernel/cpu/bus_lock.c bool handle_guest_split_lock(unsigned long ip) · line 312
Quoted 6 lines
arch/x86/kernel/cpu/bus_lock.c +6
-0+pr_warn_ratelimited ("%s/%d buslock at rip: 0x%lx\n" , + current->comm, current->pid, ip); + current->reported_split_lock =1 ; + } +} +EXPORT_SYMBOL_FOR_KVM (handle_guest_bus_lock);Thx.
-Manali
Borislav Petkov
maintainerQuoted 5 lines · Manali Shukla
However, the other reason for keeping the
function inbus_lock.cis thecurrent->reported_split_lockusage - it is already used insplit_lock_warn()andhandle_guest_split_lock()in the same file, so keeping allreported_split_lockaccesses inbus_lock.cseemed more maintainable.
Meh, it's not like C has member access rules. Besides we can all grep... I hope.
:)
Signature · 1 line
Small device. Typos and formatting crap
Sean Christopherson
maintainerQuoted 4 lines · Manali Shukla
The intent is purely observational — give hypervisor owners visibility into which guest is generating bus locks so they can act accordingly. No policy enforcement is done in the kernel. Suggestions on the approach are welcome.
This makes no sense. KVM is exiting to userspace, the hypervisor owner doesn't need to grep dmesg to understand *exactly* what vCPU is generating bus locks.
Quoted 8 lines · Sean Christopherson
Quoted 4 lines · Manali Shukla
The intent is purely observational — give hypervisor owners visibility into which guest is generating bus locks so they can act accordingly. No policy enforcement is done in the kernel. Suggestions on the approach are welcome.
This makes no sense. KVM is exiting to userspace, the hypervisor owner doesn't need to grep dmesg to understand *exactly* what vCPU is generating bus locks.
I agree that the VMM receives KVM_EXIT_X86_BUS_LOCK and knows which vCPU caused it, and I am fine with that approach. However, this request came from a customer who wanted to know which guest is causing bus locks at which RIP in dmesg, similar to how split lock detection on Intel does it. I am trying to address that use case.
-Manali
Sean Christopherson
maintainerQuoted 7 lines · Manali Shukla
Quoted 6 lines · Sean Christopherson
Quoted 4 lines · Manali Shukla
The intent is purely observational — give hypervisor owners visibility into which guest is generating bus locks so they can act accordingly. No policy enforcement is done in the kernel. Suggestions on the approach are welcome.
Quoted 7 lines
Quoted 2 lines
This makes no sense. KVM is exiting to userspace, the hypervisor owner doesn't need to grep dmesg to understand *exactly* what vCPU is generating bus locks.
I agree that the VMM receives
KVM_EXIT_X86_BUS_LOCKand knows which vCPU caused it, and I am fine with that approach. However, this request came from a customer who wanted to know which guest is causing bus locks at which RIP in dmesg,
Ratelimited printks are not features.
Quoted 1 line
similar to how split lock detection on Intel does it.
Split lock #AC is something entirely different. In that case, KVM intercepts an #AC and does NOT exit to userspace. The printk in that case is warranted because the host kernel is disabling a mitigation for the thread to allow forward progress.
The analogous Intel feature is BUS_LOCK_DETECTION, and KVM's implementation most definitely doesn't log anything to dmesg. That was very intentional, as the primary goal of the implementation was to give userspace full control over how to react to misbehaving guests.
Sorry, but this gets a very firm NAK from me.