[PATCH 10/10] kvm: x86: mmu: Add IOCTLs to allow userspace to switch dirty logging mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add 3 new IOCTLs to get/set the dirty logging mode and to get a mask
representing the set of supported modes.

Signed-off-by: Junaid Shahid <junaids@xxxxxxxxxx>
---
 Documentation/virtual/kvm/api.txt | 39 +++++++++++++++++++++++++++++++
 arch/x86/kvm/x86.c                | 13 +++++++++++
 include/uapi/linux/kvm.h          |  3 +++
 3 files changed, 55 insertions(+)

diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index cd209f7730af..4eaf8201b9b9 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -3753,6 +3753,45 @@ Coalesced pio is based on coalesced mmio. There is little difference
 between coalesced mmio and pio except that coalesced pio records accesses
 to I/O ports.
 
+4.117 KVM_GET_DIRTY_LOG_MODE
+
+Capability: none
+Architectures: x86
+Type: vm ioctl
+Parameters: none
+Returns: Current dirty log mode on success, < 0 on error
+
+kvm supports 3 different mechanisms for dirty logging on x86 architectures. This
+returns the mode currently configured for this VM, which can be one of:
+
+- KVM_DIRTY_LOG_MODE_WRPROT: Uses write-protection to track dirty pages
+- KVM_DIRTY_LOG_MODE_DBIT: Uses PTE Dirty bits to track dirty pages
+- KVM_DIRTY_LOG_MODE_PML: Uses Page Modification Logging to track dirty pages
+
+4.118 KVM_GET_SUPPORTED_DIRTY_LOG_MODES
+
+Capability: none
+Architectures: x86
+Type: system ioctl
+Parameters: none
+Returns: Bitmask of dirty log modes on success, < 0 on error
+
+This returns the possible set of dirty logging modes that can be configured for
+a VM. This will be a bitmask consisting of a combination of the 3 modes listed
+above.
+
+4.119 KVM_SET_DIRTY_LOG_MODE
+
+Capability: none
+Architectures: x86
+Type: vm ioctl
+Parameters: u8
+Returns: 0 on success, < 0 on error
+
+This configures the VM's dirty logging mode according to the given parameter,
+which can be one of the 3 modes listed above, or KVM_DIRTY_LOG_MODE_DEFAULT, in
+which case kvm will choose the mode depending on enabled hardware capabilities.
+
 5. The kvm_run structure
 ------------------------
 
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 9d22d4eeb5dc..4630973b2eba 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3164,6 +3164,11 @@ long kvm_arch_dev_ioctl(struct file *filp,
 		r = msr_io(NULL, argp, do_get_msr_feature, 1);
 		break;
 	}
+	case KVM_GET_SUPPORTED_DIRTY_LOG_MODES:
+	{
+		r = kvm_supported_dirty_log_modes;
+		break;
+	}
 	default:
 		r = -EINVAL;
 	}
@@ -4824,6 +4829,14 @@ long kvm_arch_vm_ioctl(struct file *filp,
 		r = kvm_vm_ioctl_hv_eventfd(kvm, &hvevfd);
 		break;
 	}
+	case KVM_SET_DIRTY_LOG_MODE: {
+		r = kvm_mmu_switch_dirty_log_mode(kvm, arg);
+		break;
+	}
+	case KVM_GET_DIRTY_LOG_MODE: {
+		r = kvm->arch.dirty_logging_mode;
+		break;
+	}
 	default:
 		r = -ENOTTY;
 	}
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 2b7a652c9fa4..79289b93028a 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -1224,6 +1224,9 @@ struct kvm_vfio_spapr_tce {
 					struct kvm_userspace_memory_region)
 #define KVM_SET_TSS_ADDR          _IO(KVMIO,   0x47)
 #define KVM_SET_IDENTITY_MAP_ADDR _IOW(KVMIO,  0x48, __u64)
+#define KVM_SET_DIRTY_LOG_MODE    _IO(KVMIO,   0x49)
+#define KVM_GET_DIRTY_LOG_MODE    _IO(KVMIO,   0x4a)
+#define KVM_GET_SUPPORTED_DIRTY_LOG_MODES _IO(KVMIO, 0x4b)
 
 /* enable ucontrol for s390 */
 struct kvm_s390_ucas_mapping {
-- 
2.19.1.568.g152ad8e336-goog




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux