Skip to content

x86/bus_lock: Enable bus lock detection

Fenghua Yu lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 2 repliesIn review

Change Log from the cover letter

- Check bus lock bit by its positive polarity (Xiaoyao).
- Fix a few wording issues in the documentation (Randy).
[RFC v3 can be found at: https://lore.kernel.org/patchwork/cover/1329943/]

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4x86/cpufeatures: Enumerate #DB for bus lock detectionarch/x86/include/asm/cpufeatures.h+1 -00 replies
2/4x86/bus_lock: Handle warn and fatal in #DB for bus lockarch/x86/include/asm/cpu.h arch/x86/include/asm/msr-index.h arch/x86/include/uapi/asm/debugreg.h +3 more+118 -232 replies
3/4x86/bus_lock: Set rate limit for bus lockarch/x86/kernel/cpu/intel.c include/linux/sched/user.h kernel/user.c+42 -60 replies
4/4Documentation/admin-guide: Change doc for split_lock_detect parameterDocumentation/admin-guide/kernel-parameters.txt+24 -60 replies

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by.

PatchTony Luck
1/4R-b
2/4R-b
3/4R-b
4/4R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/4] x86/bus_lock: Enable bus lock detection

A bus lock [1] is acquired either through split locked access to writeback (WB) memory or by using locks to uncacheable (UC) memory (e.g. direct device assignment). 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 trap, the trap is triggered before the instruction acquires bus lock. This makes it difficult to mitigate bus lock (e.g. 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).

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 option "split_lock_detect=" to handle #DB for bus lock:

split_lock_detect=
#AC for split lock #DB for bus lock

off Do nothing Do nothing

warn Kernel OOPs Warn once per task and
Warn once per task and and continues to run.
disable future checking When both features are
supported, warn in #DB

fatal Kernel OOPs Send SIGBUS to user
Send SIGBUS to user
When both features are
supported, fatal in #AC.

ratelimit:N Do nothing Limit bus lock rate to
N per second in the current non-root user.

Default split_lock_detect is "warn".

[1] Intel Instruction Set Extension Chapter 8: https://software.intel.com/sites/default/files/managed/c5/15/architecture-instruction-set-extensions-programming-reference.pdf

Change Log:
- Check bus lock bit by its positive polarity (Xiaoyao).
- Fix a few wording issues in the documentation (Randy).
[RFC v3 can be found at: https://lore.kernel.org/patchwork/cover/1329943/]

RFC v3:
- Remove DR6_RESERVED change (PeterZ).
- Simplify the documentation (Randy).

RFC v2:
- Architecture changed based on feedback from Thomas and PeterZ. #DB is
no longer generated for bus lock in ring0.
- Split the one single patch into four patches.
[RFC v1 can be found at: https://lore.kernel.org/lkml/[email protected]/]

Fenghua Yu (4):
x86/cpufeatures: Enumerate #DB for bus lock detection x86/bus_lock: Handle warn and fatal in #DB for bus lock x86/bus_lock: Set rate limit for bus lock Documentation/admin-guide: Change doc for split_lock_detect parameter

 .../admin-guide/kernel-parameters.txt         |  30 +++-
 arch/x86/include/asm/cpu.h                    |   9 +-
 arch/x86/include/asm/cpufeatures.h            |   1 +
 arch/x86/include/asm/msr-index.h              |   1 +
 arch/x86/include/uapi/asm/debugreg.h          |   1 +
 arch/x86/kernel/cpu/common.c                  |   2 +-
 arch/x86/kernel/cpu/intel.c                   | 152 +++++++++++++++---
 arch/x86/kernel/traps.c                       |   7 +
 include/linux/sched/user.h                    |   4 +-
 kernel/user.c                                 |   7 +
 10 files changed, 182 insertions(+), 32 deletions(-)
Signature · 1 line
2.29.2