public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
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 0/8] *** RFC: ARM KVM dirty tracking device ***
Date: Wed, 18 Sep 2024 15:27:59 +0000	[thread overview]
Message-ID: <20240918152807.25135-1-lilitj@amazon.com> (raw)

This patch series adds an ARM KVM interface for platform specific stage-2
page tracking devices and makes use of this interface for dirty tracking.

The page_tracking_device interface will be implemented by a device driver and
used by KVM. A device driver will register/deregister its implementation via
page_tracking_device_register()/page_tracking_device_unregister() functions;
KVM can use the device when page_tracking_device_registered() is true.

The page_tracking_device interface provides the following functionality:
- enabling\disabling dirty tracking for a VMID (+ optionally for a CPU id),
- reading GPAs dirtied by either any CPU (to populate dirty bitmaps) or
  by a specific CPU (to populate dirty rings)
- flushing not yet logged data.

KVM support for the page tracking device is added as a new extension and a
capability with the same name - KVM_CAP_ARM_PAGE_TRACKING_DEVICE. The 
capability is available when extension is supported (page_tracking_device_registered()
is true). When a device is available, new capability toggles device use for
dirty tracking. The capability is currently not compatible with the dirty ring
interface. At this moment only dirty bitmaps are supported as they allow userspace
to sync dirty pages from the hardware (e.g. PML) via kvm_arch_sync_dirty_log()
function. We have yet to add support for the dirty ring interface; which can sync
dirty pages into dirty rings either from userspace via a new ioctl or from KVM
on timer events.

For the page tracking device to be able to log guest write accesses this patch
series enables hardware management of the dirty state for stage-2 translations
by 1) setting VTCR_EL2.HD flag and 2) setting DBM (51) flag for the tracked
stage-2 descriptors. Currently KVM sets the DBM flag only when faulting in pages,
thus the first write to a page is logged by KVM as usual - on write fault, 
subsequent writes to the same page will be logged by a page tracking device.
We will optimize this by setting DBM flag when eagerly splitting huge pages.

An example of a device that tracks accesses to stage-2 translations and will
implement page_tracking_device interface is AWS Graviton Page Tracking Agent
(PTA). We'll be posting code for the Graviton PTA device driver in a separate
series of patches.

When ARM architectural solution (FEAT_HDBSS feature) is available, we intend to
use it via the same interface most likely with adaptations.


Lilit Janpoladyan (8):
  arm64: add an interface for stage-2 page tracking
  KVM: arm64: add page tracking device as a capability
  KVM: arm64: use page tracking interface to enable dirty logging
  KVM: return value from kvm_arch_sync_dirty_log
  KVM: arm64: get dirty pages from the page tracking device
  KVM: arm64: flush dirty logging data
  KVM: arm64: enable hardware dirty state management for stage-2
  KVM: arm64: make hardware manage dirty state after write faults

 Documentation/virt/kvm/api.rst         |  17 +++
 arch/arm64/include/asm/kvm_host.h      |   8 ++
 arch/arm64/include/asm/kvm_pgtable.h   |   1 +
 arch/arm64/include/asm/page_tracking.h |  79 +++++++++++++
 arch/arm64/kvm/Kconfig                 |  12 ++
 arch/arm64/kvm/Makefile                |   1 +
 arch/arm64/kvm/arm.c                   | 121 ++++++++++++++++++-
 arch/arm64/kvm/hyp/pgtable.c           |  29 ++++-
 arch/arm64/kvm/mmu.c                   |   8 ++
 arch/arm64/kvm/page_tracking.c         | 158 +++++++++++++++++++++++++
 arch/loongarch/kvm/mmu.c               |   3 +-
 arch/mips/kvm/mips.c                   |  12 +-
 arch/powerpc/kvm/book3s.c              |  12 +-
 arch/powerpc/kvm/booke.c               |  12 +-
 arch/riscv/kvm/mmu.c                   |   3 +-
 arch/s390/kvm/kvm-s390.c               |  13 +-
 arch/x86/kvm/x86.c                     |  21 +++-
 include/linux/kvm_host.h               |   4 +-
 include/uapi/linux/kvm.h               |   1 +
 virt/kvm/kvm_main.c                    |  34 ++++--
 20 files changed, 521 insertions(+), 28 deletions(-)
 create mode 100644 arch/arm64/include/asm/page_tracking.h
 create mode 100644 arch/arm64/kvm/page_tracking.c

-- 
2.40.1


             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 Lilit Janpoladyan [this message]
2024-09-18 15:28 ` [PATCH 1/8] arm64: add an interface for stage-2 page tracking Lilit Janpoladyan
2024-09-18 15:28 ` [PATCH 2/8] KVM: arm64: add page tracking device as a capability Lilit Janpoladyan
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-1-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