Skip to content

Commit 17601bf

Browse files
author
Marc Zyngier
committed
KVM: Add KVM_CAP_DIRTY_LOG_RING_ACQ_REL capability and config option
In order to differenciate between architectures that require no extra synchronisation when accessing the dirty ring and those who do, add a new capability (KVM_CAP_DIRTY_LOG_RING_ACQ_REL) that identify the latter sort. TSO architectures can obviously advertise both, while relaxed architectures must only advertise the ACQ_REL version. This requires some configuration symbol rejigging, with HAVE_KVM_DIRTY_RING being only indirectly selected by two top-level config symbols: - HAVE_KVM_DIRTY_RING_TSO for strongly ordered architectures (x86) - HAVE_KVM_DIRTY_RING_ACQ_REL for weakly ordered architectures (arm64) Suggested-by: Paolo Bonzini <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Gavin Shan <[email protected]> Reviewed-by: Peter Xu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8929bc9 commit 17601bf

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

arch/x86/kvm/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ config KVM
2828
select HAVE_KVM_IRQCHIP
2929
select HAVE_KVM_PFNCACHE
3030
select HAVE_KVM_IRQFD
31-
select HAVE_KVM_DIRTY_RING
31+
select HAVE_KVM_DIRTY_RING_TSO
3232
select IRQ_BYPASS_MANAGER
3333
select HAVE_KVM_IRQ_BYPASS
3434
select HAVE_KVM_IRQ_ROUTING

include/uapi/linux/kvm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ struct kvm_ppc_resize_hpt {
11771177
#define KVM_CAP_VM_DISABLE_NX_HUGE_PAGES 220
11781178
#define KVM_CAP_S390_ZPCI_OP 221
11791179
#define KVM_CAP_S390_CPU_TOPOLOGY 222
1180+
#define KVM_CAP_DIRTY_LOG_RING_ACQ_REL 223
11801181

11811182
#ifdef KVM_CAP_IRQ_ROUTING
11821183

virt/kvm/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ config HAVE_KVM_IRQ_ROUTING
1919
config HAVE_KVM_DIRTY_RING
2020
bool
2121

22+
# Only strongly ordered architectures can select this, as it doesn't
23+
# put any explicit constraint on userspace ordering. They can also
24+
# select the _ACQ_REL version.
25+
config HAVE_KVM_DIRTY_RING_TSO
26+
bool
27+
select HAVE_KVM_DIRTY_RING
28+
depends on X86
29+
30+
# Weakly ordered architectures can only select this, advertising
31+
# to userspace the additional ordering requirements.
32+
config HAVE_KVM_DIRTY_RING_ACQ_REL
33+
bool
34+
select HAVE_KVM_DIRTY_RING
35+
2236
config HAVE_KVM_EVENTFD
2337
bool
2438
select EVENTFD

virt/kvm/kvm_main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4475,7 +4475,13 @@ static long kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)
44754475
case KVM_CAP_NR_MEMSLOTS:
44764476
return KVM_USER_MEM_SLOTS;
44774477
case KVM_CAP_DIRTY_LOG_RING:
4478-
#ifdef CONFIG_HAVE_KVM_DIRTY_RING
4478+
#ifdef CONFIG_HAVE_KVM_DIRTY_RING_TSO
4479+
return KVM_DIRTY_RING_MAX_ENTRIES * sizeof(struct kvm_dirty_gfn);
4480+
#else
4481+
return 0;
4482+
#endif
4483+
case KVM_CAP_DIRTY_LOG_RING_ACQ_REL:
4484+
#ifdef CONFIG_HAVE_KVM_DIRTY_RING_ACQ_REL
44794485
return KVM_DIRTY_RING_MAX_ENTRIES * sizeof(struct kvm_dirty_gfn);
44804486
#else
44814487
return 0;
@@ -4580,6 +4586,7 @@ static int kvm_vm_ioctl_enable_cap_generic(struct kvm *kvm,
45804586
return 0;
45814587
}
45824588
case KVM_CAP_DIRTY_LOG_RING:
4589+
case KVM_CAP_DIRTY_LOG_RING_ACQ_REL:
45834590
return kvm_vm_ioctl_enable_dirty_log_ring(kvm, cap->args[0]);
45844591
default:
45854592
return kvm_vm_ioctl_enable_cap(kvm, cap);

0 commit comments

Comments
 (0)