crosvm/kvm
Zhang Yiming 59f6611a74 Add bus lock detect support in CROSVM
A bus lock is acquired through either split locked access to writeback
(WB) memory or any locked access to non-WB memory. It is typically >1000
cycles slower than an atomic operation within a cache and can also
disrupts performance on other cores.

Virtual Machines can exploit bus locks to degrade the performance of
system. To address this kind of performance DOS attack coming from the
VMs, bus lock VM exit is introduced in KVM and it can report the bus
locks detected in guest. If enabled in KVM, it would exit to the
userspace to let the user enforce throttling policies once bus locks
acquired in VMs.

The availability of bus lock VM exit can be detected through the
KVM_CAP_X86_BUS_LOCK_EXIT. The returned bitmap contains the potential
policies supported by KVM. The field KVM_BUS_LOCK_DETECTION_EXIT in
bitmap is the only supported strategy at present. It indicates that KVM
will exit to userspace to handle the bus locks.

This patch adds a ratelimit on the bus locks acquired in guest as a
mitigation policy.

Introduce a new field "bus_lock_ratelimit" to record the limited speed
of bus locks in the target VM. The user can specify it through
"bus-lock-ratelimit". In current implementation,
the default value of the speed is 0 per second, which means no
restrictions on the bus locks.

As for ratelimit on detected bus locks, simply set the ratelimit
interval to 1s and restrict the quota of bus lock occurence to the value
of "bus_lock_ratelimit". A potential alternative is to introduce the
time slice as a property which can help the user achieve more precise
control.

Change-Id: I60708cfd056062281d6384a2a3aa9acfe0326af2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3969352
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zhenyu Z Wang <zhenyuw@linux.intel.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-12-07 18:43:41 +00:00
..
src Add bus lock detect support in CROSVM 2022-12-07 18:43:41 +00:00
tests kvm: Extract integration tests 2022-11-09 18:39:33 +00:00
Cargo.toml Refactoring: Move common/base into base 2022-03-17 00:01:27 +00:00