| 1 |
.. SPDX-License-Identifier: GPL-2.0 |
| 2 |
|
| 3 |
.. include:: <isonum.txt> |
| 4 |
|
| 5 |
=============================== |
| 6 |
Bus lock detection and handling |
| 7 |
=============================== |
| 8 |
|
| 9 |
:Copyright: |copy| 2021 Intel Corporation |
| 10 |
:Authors: - Fenghua Yu <[email protected]> |
| 11 |
- Tony Luck <[email protected]> |
| 12 |
|
| 13 |
Problem |
| 14 |
======= |
| 15 |
|
| 16 |
A split lock is any atomic operation whose operand crosses two cache lines. |
| 17 |
Since the operand spans two cache lines and the operation must be atomic, |
| 18 |
the system locks the bus while the CPU accesses the two cache lines. |
| 19 |
|
| 20 |
A bus lock is acquired through either split locked access to writeback (WB) |
| 21 |
memory or any locked access to non-WB memory. This is typically thousands of |
| 22 |
cycles slower than an atomic operation within a cache line. It also disrupts |
| 23 |
performance on other cores and brings the whole system to its knees. |
| 24 |
|
| 25 |
Detection |
| 26 |
========= |
| 27 |
|
| 28 |
Intel processors may support either or both of the following hardware |
| 29 |
mechanisms to detect split locks and bus locks. Some AMD processors also |
| 30 |
support bus lock detect. |
| 31 |
|
| 32 |
#AC exception for split lock detection |
| 33 |
-------------------------------------- |
| 34 |
|
| 35 |
Beginning with the Tremont Atom CPU split lock operations may raise an |
| 36 |
Alignment Check (#AC) exception when a split lock operation is attempted. |
| 37 |
|
| 38 |
#DB exception for bus lock detection |
| 39 |
------------------------------------ |
| 40 |
|
| 41 |
Some CPUs have the ability to notify the kernel by an #DB trap after a user |
| 42 |
instruction acquires a bus lock and is executed. This allows the kernel to |
| 43 |
terminate the application or to enforce throttling. |
| 44 |
|
| 45 |
Software handling |
| 46 |
================= |
| 47 |
|
| 48 |
The kernel #AC and #DB handlers handle bus lock based on the kernel |
| 49 |
parameter "split_lock_detect". Here is a summary of different options: |
| 50 |
|
| 51 |
+------------------+----------------------------+-----------------------+ |
| 52 |
|split_lock_detect=|#AC for split lock |#DB for bus lock | |
| 53 |
+------------------+----------------------------+-----------------------+ |
| 54 |
|off |Do nothing |Do nothing | |
| 55 |
+------------------+----------------------------+-----------------------+ |
| 56 |
|warn |Kernel OOPs |Warn once per task and | |
| 57 |
|(default) |Warn once per task, add a |and continues to run. | |
| 58 |
| |delay, add synchronization | | |
| 59 |
| |to prevent more than one | | |
| 60 |
| |core from executing a | | |
| 61 |
| |split lock in parallel. | | |
| 62 |
| |sysctl split_lock_mitigate | | |
| 63 |
| |can be used to avoid the | | |
| 64 |
| |delay and synchronization | | |
| 65 |
| |When both features are | | |
| 66 |
| |supported, warn in #AC | | |
| 67 |
+------------------+----------------------------+-----------------------+ |
| 68 |
|fatal |Kernel OOPs |Send SIGBUS to user. | |
| 69 |
| |Send SIGBUS to user | | |
| 70 |
| |When both features are | | |
| 71 |
| |supported, fatal in #AC | | |
| 72 |
+------------------+----------------------------+-----------------------+ |
| 73 |
|ratelimit:N |Do nothing |Limit bus lock rate to | |
| 74 |
|(0 < N <= 1000) | |N bus locks per second | |
| 75 |
| | |system wide and warn on| |
| 76 |
| | |bus locks. | |
| 77 |
+------------------+----------------------------+-----------------------+ |
| 78 |
|
| 79 |
Usages |
| 80 |
====== |
| 81 |
|
| 82 |
Detecting and handling bus lock may find usages in various areas: |
| 83 |
|
| 84 |
It is critical for real time system designers who build consolidated real |
| 85 |
time systems. These systems run hard real time code on some cores and run |
| 86 |
"untrusted" user processes on other cores. The hard real time cannot afford |
| 87 |
to have any bus lock from the untrusted processes to hurt real time |
| 88 |
performance. To date the designers have been unable to deploy these |
| 89 |
solutions as they have no way to prevent the "untrusted" user code from |
| 90 |
generating split lock and bus lock to block the hard real time code to |
| 91 |
access memory during bus locking. |
| 92 |
|
| 93 |
It's also useful for general computing to prevent guests or user |
| 94 |
applications from slowing down the overall system by executing instructions |
| 95 |
with bus lock. |
| 96 |
|
| 97 |
|
| 98 |
Guidance |
| 99 |
======== |
| 100 |
off |
| 101 |
--- |
| 102 |
|
| 103 |
Disable checking for split lock and bus lock. This option can be useful if |
| 104 |
there are legacy applications that trigger these events at a low rate so |
| 105 |
that mitigation is not needed. |
| 106 |
|
| 107 |
warn |
| 108 |
---- |
| 109 |
|
| 110 |
A warning is emitted when a bus lock is detected which allows to identify |
| 111 |
the offending application. This is the default behavior. |
| 112 |
|
| 113 |
fatal |
| 114 |
----- |
| 115 |
|
| 116 |
In this case, the bus lock is not tolerated and the process is killed. |
| 117 |
|
| 118 |
ratelimit |
| 119 |
--------- |
| 120 |
|
| 121 |
A system wide bus lock rate limit N is specified where 0 < N <= 1000. This |
| 122 |
allows a bus lock rate up to N bus locks per second. When the bus lock rate |
| 123 |
is exceeded then any task which is caught via the buslock #DB exception is |
| 124 |
throttled by enforced sleeps until the rate goes under the limit again. |
| 125 |
|
| 126 |
This is an effective mitigation in cases where a minimal impact can be |
| 127 |
tolerated, but an eventual Denial of Service attack has to be prevented. It |
| 128 |
allows to identify the offending processes and analyze whether they are |
| 129 |
malicious or just badly written. |
| 130 |
|
| 131 |
Selecting a rate limit of 1000 allows the bus to be locked for up to about |
| 132 |
seven million cycles each second (assuming 7000 cycles for each bus |
| 133 |
lock). On a 2 GHz processor that would be about 0.35% system slowdown. |