Skip to content

Commit d7547c5

Browse files
xzpeterbonzini
authored andcommitted
KVM: Introduce KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2
The previous KVM_CAP_MANUAL_DIRTY_LOG_PROTECT has some problem which blocks the correct usage from userspace. Obsolete the old one and introduce a new capability bit for it. Suggested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Peter Xu <peterx@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 53eac7a commit d7547c5

4 files changed

Lines changed: 17 additions & 11 deletions

File tree

‎Documentation/virtual/kvm/api.txt‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ They must be less than the value that KVM_CHECK_EXTENSION returns for
330330
the KVM_CAP_MULTI_ADDRESS_SPACE capability.
331331

332332
The bits in the dirty bitmap are cleared before the ioctl returns, unless
333-
KVM_CAP_MANUAL_DIRTY_LOG_PROTECT is enabled. For more information,
333+
KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is enabled. For more information,
334334
see the description of the capability.
335335

336336
4.9 KVM_SET_MEMORY_ALIAS
@@ -3791,7 +3791,7 @@ to I/O ports.
37913791

37923792
4.117 KVM_CLEAR_DIRTY_LOG (vm ioctl)
37933793

3794-
Capability: KVM_CAP_MANUAL_DIRTY_LOG_PROTECT
3794+
Capability: KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2
37953795
Architectures: x86
37963796
Type: vm ioctl
37973797
Parameters: struct kvm_dirty_log (in)
@@ -3824,10 +3824,10 @@ the address space for which you want to return the dirty bitmap.
38243824
They must be less than the value that KVM_CHECK_EXTENSION returns for
38253825
the KVM_CAP_MULTI_ADDRESS_SPACE capability.
38263826

3827-
This ioctl is mostly useful when KVM_CAP_MANUAL_DIRTY_LOG_PROTECT
3827+
This ioctl is mostly useful when KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2
38283828
is enabled; for more information, see the description of the capability.
38293829
However, it can always be used as long as KVM_CHECK_EXTENSION confirms
3830-
that KVM_CAP_MANUAL_DIRTY_LOG_PROTECT is present.
3830+
that KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is present.
38313831

38323832
4.118 KVM_GET_SUPPORTED_HV_CPUID
38333833

@@ -4780,7 +4780,7 @@ and injected exceptions.
47804780
* For the new DR6 bits, note that bit 16 is set iff the #DB exception
47814781
will clear DR6.RTM.
47824782

4783-
7.18 KVM_CAP_MANUAL_DIRTY_LOG_PROTECT
4783+
7.18 KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2
47844784

47854785
Architectures: all
47864786
Parameters: args[0] whether feature should be enabled or not
@@ -4803,6 +4803,11 @@ while userspace can see false reports of dirty pages. Manual reprotection
48034803
helps reducing this time, improving guest performance and reducing the
48044804
number of dirty log false positives.
48054805

4806+
KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 was previously available under the name
4807+
KVM_CAP_MANUAL_DIRTY_LOG_PROTECT, but the implementation had bugs that make
4808+
it hard or impossible to use it correctly. The availability of
4809+
KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 signals that those bugs are fixed.
4810+
Userspace should not try to use KVM_CAP_MANUAL_DIRTY_LOG_PROTECT.
48064811

48074812
8. Other capabilities.
48084813
----------------------

‎include/uapi/linux/kvm.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,8 +986,9 @@ struct kvm_ppc_resize_hpt {
986986
#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS 163
987987
#define KVM_CAP_EXCEPTION_PAYLOAD 164
988988
#define KVM_CAP_ARM_VM_IPA_SIZE 165
989-
#define KVM_CAP_MANUAL_DIRTY_LOG_PROTECT 166
989+
#define KVM_CAP_MANUAL_DIRTY_LOG_PROTECT 166 /* Obsolete */
990990
#define KVM_CAP_HYPERV_CPUID 167
991+
#define KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 168
991992

992993
#ifdef KVM_CAP_IRQ_ROUTING
993994

@@ -1434,7 +1435,7 @@ struct kvm_enc_region {
14341435
#define KVM_GET_NESTED_STATE _IOWR(KVMIO, 0xbe, struct kvm_nested_state)
14351436
#define KVM_SET_NESTED_STATE _IOW(KVMIO, 0xbf, struct kvm_nested_state)
14361437

1437-
/* Available with KVM_CAP_MANUAL_DIRTY_LOG_PROTECT */
1438+
/* Available with KVM_CAP_MANUAL_DIRTY_LOG_PROTECT_2 */
14381439
#define KVM_CLEAR_DIRTY_LOG _IOWR(KVMIO, 0xc0, struct kvm_clear_dirty_log)
14391440

14401441
/* Available with KVM_CAP_HYPERV_CPUID */

‎tools/testing/selftests/kvm/dirty_log_test.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
311311
#ifdef USE_CLEAR_DIRTY_LOG
312312
struct kvm_enable_cap cap = {};
313313

314-
cap.cap = KVM_CAP_MANUAL_DIRTY_LOG_PROTECT;
314+
cap.cap = KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2;
315315
cap.args[0] = 1;
316316
vm_enable_cap(vm, &cap);
317317
#endif
@@ -427,7 +427,7 @@ int main(int argc, char *argv[])
427427
int opt, i;
428428

429429
#ifdef USE_CLEAR_DIRTY_LOG
430-
if (!kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT)) {
430+
if (!kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2)) {
431431
fprintf(stderr, "KVM_CLEAR_DIRTY_LOG not available, skipping tests\n");
432432
exit(KSFT_SKIP);
433433
}

‎virt/kvm/kvm_main.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3110,7 +3110,7 @@ static long kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)
31103110
case KVM_CAP_CHECK_EXTENSION_VM:
31113111
case KVM_CAP_ENABLE_CAP_VM:
31123112
#ifdef CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT
3113-
case KVM_CAP_MANUAL_DIRTY_LOG_PROTECT:
3113+
case KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2:
31143114
#endif
31153115
return 1;
31163116
#ifdef CONFIG_KVM_MMIO
@@ -3148,7 +3148,7 @@ static int kvm_vm_ioctl_enable_cap_generic(struct kvm *kvm,
31483148
{
31493149
switch (cap->cap) {
31503150
#ifdef CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT
3151-
case KVM_CAP_MANUAL_DIRTY_LOG_PROTECT:
3151+
case KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2:
31523152
if (cap->flags || (cap->args[0] & ~1))
31533153
return -EINVAL;
31543154
kvm->manual_dirty_log_protect = cap->args[0];

0 commit comments

Comments
 (0)