@@ -95,6 +95,13 @@ struct kvm_arch {
* supported.
*/
bool return_nisv_io_abort_to_user;
+
+ /*
+ * Use hardware management of dirty status (DBM) to log dirty pages.
+ * Userspace can enable this feature if KVM_CAP_ARM_HW_DIRTY_LOG is
+ * supported.
+ */
+ bool hw_dirty_log;
};
#define KVM_NR_MEM_OBJS 40
@@ -87,6 +87,16 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
r = 0;
kvm->arch.return_nisv_io_abort_to_user = true;
break;
+#ifdef CONFIG_ARM64_HW_AFDBM
+ case KVM_CAP_ARM_HW_DIRTY_LOG:
+ if ((cap->args[0] & ~1) || !kvm_hw_dbm_enabled()) {
+ r = -EINVAL;
+ } else {
+ r = 0;
+ kvm->arch.hw_dirty_log = cap->args[0];
+ }
+ break;
+#endif
default:
r = -EINVAL;
break;
@@ -83,6 +83,11 @@ int kvm_arch_vm_ioctl_check_extension(struct kvm *kvm, long ext)
r = has_vhe() && system_supports_address_auth() &&
system_supports_generic_auth();
break;
+#ifdef CONFIG_ARM64_HW_AFDBM
+ case KVM_CAP_ARM_HW_DIRTY_LOG:
+ r = kvm_hw_dbm_enabled();
+ break;
+#endif /* CONFIG_ARM64_HW_AFDBM */
default:
r = 0;
}
@@ -1031,6 +1031,7 @@ struct kvm_ppc_resize_hpt {
#define KVM_CAP_PPC_SECURE_GUEST 181
#define KVM_CAP_HALT_POLL 182
#define KVM_CAP_ASYNC_PF_INT 183
+#define KVM_CAP_ARM_HW_DIRTY_LOG 184
#ifdef KVM_CAP_IRQ_ROUTING
@@ -1017,6 +1017,7 @@ struct kvm_ppc_resize_hpt {
#define KVM_CAP_S390_VCPU_RESETS 179
#define KVM_CAP_S390_PROTECTED 180
#define KVM_CAP_PPC_SECURE_GUEST 181
+#define KVM_CAP_ARM_HW_DIRTY_LOG 184
#ifdef KVM_CAP_IRQ_ROUTING
For that using arm64 DBM to log dirty pages has the side effect of long time dirty log sync, we should give userspace opportunity to enable or disable this feature, to realize some policy. Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com> --- arch/arm64/include/asm/kvm_host.h | 7 +++++++ arch/arm64/kvm/arm.c | 10 ++++++++++ arch/arm64/kvm/reset.c | 5 +++++ include/uapi/linux/kvm.h | 1 + tools/include/uapi/linux/kvm.h | 1 + 5 files changed, 24 insertions(+)