Notes about bus lock detection.

  • fault vs trap

#AC for Split-locked Access is fault, #DB for bus lock detection is trap.

A bus lock is acquired through either split locked access to writeback (WB) memory or any locked access to non-WB memory. This is typically >1000 cycles slower than an atomic operation within a cache line. It also disrupts performance on other cores.

Although split lock can be detected by #AC fault, the fault is triggered before the instruction acquires bus lock. This makes it difficult to mitigate bus lock (e.g. throttle(限制) the user application).

How to explain it difficult to mitigate bus lock(e.g. throttle the user application)?
split_lock_detect default value is warn, that is the split lock state will be changed for one instruction. But this requires changing the split lock state using the test MSR for the complete core, impacting other threads. Keypoint: #AC fault: The return address for the fault handler points to the faulting instruction, rather than to the instruction following the faulting instruction. Think: What does #AC handler do when split_lock_detect value is warn?

ratelimit可以理解为throttle the user application!

Some CPUs have ability to notify the kernel by an #DB trap after a user instruction acquires a bus lock and is executed. This allows the kernel to enforce user application throttling or mitigations.

#DB for bus lock detect fixes issues in #AC for split lock detect:

  1. It’s architectural … just need to look at one CPUID bit to know it exists
  2. The IA32_DEBUGCTL MSR, which reports bus lock in #DB, is per-thread. So each process or guest can have different behavior.
  3. It has support for VMM/guests (new VMEXIT codes, etc).
  4. It detects not only split locks but also bus locks from non-WB.

Hardware only generates #DB for bus lock detect when CPL>0 to avoid nested #DB from multiple bus locks while the first #DB is being handled.

Use the existing kernel command line parameter “split_lock_detect=” to handle #DB for bus lock with an additional option “ratelimit=N” to set bus lock rate limit for a user.


参考资料:

  1. Intel Instruction Set Extension Chapter 9
  2. x86/bus_lock: Enable bus lock detection