From: Lilit Janpoladyan <lilitj@amazon.com>
To: <kvm@vger.kernel.org>, <maz@kernel.org>, <oliver.upton@linux.dev>,
<james.morse@arm.com>, <suzuki.poulose@arm.com>,
<yuzenghui@huawei.com>, <nh-open-source@amazon.com>,
<lilitj@amazon.com>
Subject: [PATCH 2/8] KVM: arm64: add page tracking device as a capability
Date: Wed, 18 Sep 2024 15:28:01 +0000 [thread overview]
Message-ID: <20240918152807.25135-3-lilitj@amazon.com> (raw)
In-Reply-To: <20240918152807.25135-1-lilitj@amazon.com>
Add new capability KVM_CAP_ARM_PAGE_TRACKING_DEVICE to use page tracking
device for dirty logging. The capability can be used only if platform
supports such a device i.e. when KVM_CAP_ARM_PAGE_TRACKING_DEVICE
extension is supported. Until there is dirty ring support, make new
capability incompatible with the use of dirty ring.
When page tracking device is in use, instead of logging dirty pages on
faults KVM will collect a list of dirty pages from the device when
userspace reads dirty bitmap.
Signed-off-by: Lilit Janpoladyan <lilitj@amazon.com>
---
Documentation/virt/kvm/api.rst | 17 +++++++++++++++++
arch/arm64/include/asm/kvm_host.h | 2 ++
arch/arm64/kvm/arm.c | 17 +++++++++++++++++
include/uapi/linux/kvm.h | 1 +
4 files changed, 37 insertions(+)
diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index b3be87489108..989d5dd886fb 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -8950,6 +8950,23 @@ Do not use KVM_X86_SW_PROTECTED_VM for "real" VMs, and especially not in
production. The behavior and effective ABI for software-protected VMs is
unstable.
+8.42 KVM_CAP_ARM_PAGE_TRACKING_DEVICE
+_____________________________________
+
+:Capability: KVM_CAP_ARM_PAGE_TRACKING_DEVICE
+:Architecture: arm64
+:Type: vm
+:Parameters: arg[0] whether feature should be enabled or not
+:Returns 0 on success, -errno on failure
+
+This capability enables or disables hardware assistance for dirty page logging.
+
+In case page tracking device is available (i.e. if the host supports the
+KVM_CAP_ARM_PAGE_TRACKING_DEVICE extension), the device can be used to accelerate
+dirty logging. This capability turns the acceleration on and off.
+
+Not compatible with KVM_CAP_DIRTY_LOG_RING/KVM_CAP_DIRTY_LOG_RING_ACQ_REL.
+
9. Known KVM API problems
=========================
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index a33f5996ca9f..5b5e3647fbda 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -326,6 +326,8 @@ struct kvm_arch {
#define KVM_ARCH_FLAG_ID_REGS_INITIALIZED 7
/* Fine-Grained UNDEF initialised */
#define KVM_ARCH_FLAG_FGU_INITIALIZED 8
+ /* Page tracking device enabled */
+#define KVM_ARCH_FLAG_PAGE_TRACKING_DEVICE_ENABLED 9
unsigned long flags;
/* VM-wide vCPU feature set */
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index 9bef7638342e..aea56df8ac04 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -40,6 +40,7 @@
#include <asm/kvm_nested.h>
#include <asm/kvm_pkvm.h>
#include <asm/kvm_ptrauth.h>
+#include <asm/page_tracking.h>
#include <asm/sections.h>
#include <kvm/arm_hypercalls.h>
@@ -149,6 +150,19 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
}
mutex_unlock(&kvm->slots_lock);
break;
+ case KVM_CAP_ARM_PAGE_TRACKING_DEVICE:
+ if (page_tracking_device_registered() &&
+ !kvm->dirty_ring_size /* Does not support dirty ring yet */) {
+
+ r = 0;
+ if (cap->args[0])
+ set_bit(KVM_ARCH_FLAG_PAGE_TRACKING_DEVICE_ENABLED,
+ &kvm->arch.flags);
+ else
+ clear_bit(KVM_ARCH_FLAG_PAGE_TRACKING_DEVICE_ENABLED,
+ &kvm->arch.flags);
+ }
+ break;
default:
break;
}
@@ -416,6 +430,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
case KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES:
r = BIT(0);
break;
+ case KVM_CAP_ARM_PAGE_TRACKING_DEVICE:
+ r = page_tracking_device_registered();
+ break;
default:
r = 0;
}
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 637efc055145..552ebede3f9d 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -933,6 +933,7 @@ struct kvm_enable_cap {
#define KVM_CAP_PRE_FAULT_MEMORY 236
#define KVM_CAP_X86_APIC_BUS_CYCLES_NS 237
#define KVM_CAP_X86_GUEST_MODE 238
+#define KVM_CAP_ARM_PAGE_TRACKING_DEVICE 239
struct kvm_irq_routing_irqchip {
__u32 irqchip;
--
2.40.1
next prev parent reply other threads:[~2024-09-18 15:28 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-18 15:27 [PATCH 0/8] *** RFC: ARM KVM dirty tracking device *** Lilit Janpoladyan
2024-09-18 15:28 ` [PATCH 1/8] arm64: add an interface for stage-2 page tracking Lilit Janpoladyan
2024-09-18 15:28 ` Lilit Janpoladyan [this message]
2024-09-18 15:28 ` [PATCH 3/8] KVM: arm64: use page tracking interface to enable dirty logging Lilit Janpoladyan
2024-09-22 7:31 ` Sean Christopherson
2024-09-18 15:28 ` [PATCH 4/8] KVM: return value from kvm_arch_sync_dirty_log Lilit Janpoladyan
2024-09-19 1:50 ` kernel test robot
2024-09-19 2:32 ` kernel test robot
2024-09-18 15:28 ` [PATCH 5/8] KVM: arm64: get dirty pages from the page tracking device Lilit Janpoladyan
2024-09-18 15:28 ` [PATCH 6/8] KVM: arm64: flush dirty logging data Lilit Janpoladyan
2024-09-18 15:28 ` [PATCH 7/8] KVM: arm64: enable hardware dirty state management for stage-2 Lilit Janpoladyan
2024-09-18 15:28 ` [PATCH 8/8] KVM: arm64: make hardware manage dirty state after write faults Lilit Janpoladyan
2024-09-19 9:11 ` [PATCH 0/8] *** RFC: ARM KVM dirty tracking device *** Oliver Upton
2024-09-20 10:12 ` Janpoladyan, Lilit
2024-09-26 10:00 ` David Woodhouse
2024-09-30 17:33 ` Oliver Upton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240918152807.25135-3-lilitj@amazon.com \
--to=lilitj@amazon.com \
--cc=james.morse@arm.com \
--cc=kvm@vger.kernel.org \
--cc=maz@kernel.org \
--cc=nh-open-source@amazon.com \
--cc=oliver.upton@linux.dev \
--cc=suzuki.poulose@arm.com \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox