KVM Archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: isaku.yamahata@intel.com, xiaoyao.li@intel.com,
	binbin.wu@linux.intel.com, seanjc@google.com,
	rick.p.edgecombe@intel.com
Subject: [PATCH v4 0/6] KVM: Guest Memory Pre-Population API
Date: Fri, 19 Apr 2024 04:59:21 -0400	[thread overview]
Message-ID: <20240419085927.3648704-1-pbonzini@redhat.com> (raw)

Pre-population has been requested several times to mitigate KVM page faults
during guest boot or after live migration.  It is also required by TDX
before filling in the initial guest memory with measured contents; while
I am not yet sure that userspace will use this ioctl, if not the code
will be used by a TDX-specific ioctl---to pre-populate the SEPT before
invoking TDH.MEM.PAGE.ADD or TDH.MR.EXTEND.

This patch series depends on the other pieces that have been applied
to the kvm-coco-queue branch (and is present on the branch).

Paolo

v3->v4:
- renamed everything to KVM_PRE_FAULT_MEMORY, KVM_CAP_PRE_FAULT_MEMORY,
  struct kvm_pre_fault_memory.
- renamed base_address field to gpa
- merged introduction of kvm_tdp_map_page() and kvm_arch_vcpu_map_memory()
  in a single patch, moving the latter to mmu.c; did *not* merge them
  in a single function though
- removed EINVAL return code for RET_PF_RETRY, do it in KVM and exit
  on signal_pending()
- return ENOENT for RET_PF_EMULATE
- do not document the possibility that different VMs can have different
  results for KVM_CHECK_EXTENSION(KVM_CAP_PRE_FAULT_MEMORY)
- return long from kvm_arch_vcpu_map_memory(), update size and gpa in
  kvm_vcpu_map_memory()
- cover remaining range.size more thoroughly in the selftest

v2->v3:
- no vendor-specific hooks
- just fail if pre-population is invoked while nested virt is access
- just populate page tables for the SMM address space if invoked while
  SMM is active
- struct name changed to `kvm_map_memory`
- common code has supports for KVM_CHECK_EXTENSION(KVM_MAP_MEMORY)
  on the VM file descriptor, which allows to make this ioctl supported
  only on a subset of VM types
- if EINTR or EAGAIN happens on the first page, it is returned.  Otherwise,
  the ioctl *succeeds* but mapping->size is left nonzero.  While this
  drops the detail as to why the system call was interrupted, it is
  consistent with other interruptible system calls such as read().
- the test is not x86-specific anymore (though for now only compiled
  on x86 because no other architectures supports the feature)
- instead of using __weak symbols, the code is conditional on a new
  Kconfig CONFIG_KVM_GENERIC_MAP_MEMORY.


Isaku Yamahata (6):
  KVM: Document KVM_PRE_FAULT_MEMORY ioctl
  KVM: Add KVM_PRE_FAULT_MEMORY vcpu ioctl to pre-populate guest memory
  KVM: x86/mmu: Extract __kvm_mmu_do_page_fault()
  KVM: x86/mmu: Make __kvm_mmu_do_page_fault() return mapped level
  KVM: x86: Implement kvm_arch_vcpu_pre_fault_memory()
  KVM: selftests: x86: Add test for KVM_PRE_FAULT_MEMORY

 Documentation/virt/kvm/api.rst                |  50 ++++++
 arch/x86/kvm/Kconfig                          |   1 +
 arch/x86/kvm/mmu/mmu.c                        |  72 +++++++++
 arch/x86/kvm/mmu/mmu_internal.h               |  42 +++--
 arch/x86/kvm/x86.c                            |   3 +
 include/linux/kvm_host.h                      |   5 +
 include/uapi/linux/kvm.h                      |  10 ++
 tools/include/uapi/linux/kvm.h                |   8 +
 tools/testing/selftests/kvm/Makefile          |   1 +
 .../selftests/kvm/pre_fault_memory_test.c     | 146 ++++++++++++++++++
 virt/kvm/Kconfig                              |   3 +
 virt/kvm/kvm_main.c                           |  63 ++++++++
 12 files changed, 390 insertions(+), 14 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/pre_fault_memory_test.c

-- 
2.43.0


             reply	other threads:[~2024-04-19  8:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-19  8:59 Paolo Bonzini [this message]
2024-04-19  8:59 ` [PATCH 1/6] KVM: Document KVM_PRE_FAULT_MEMORY ioctl Paolo Bonzini
2024-04-22 17:55   ` Isaku Yamahata
2024-04-19  8:59 ` [PATCH 2/6] KVM: Add KVM_PRE_FAULT_MEMORY vcpu ioctl to pre-populate guest memory Paolo Bonzini
2024-04-22  5:39   ` Binbin Wu
2024-04-24 16:05     ` Paolo Bonzini
2024-04-22  7:19   ` Binbin Wu
2024-04-22 18:00   ` Isaku Yamahata
2024-04-19  8:59 ` [PATCH 3/6] KVM: x86/mmu: Extract __kvm_mmu_do_page_fault() Paolo Bonzini
2024-04-22  8:46   ` Xiaoyao Li
2024-04-19  8:59 ` [PATCH 4/6] KVM: x86/mmu: Make __kvm_mmu_do_page_fault() return mapped level Paolo Bonzini
2024-04-19  8:59 ` [PATCH 5/6] KVM: x86: Implement kvm_arch_vcpu_pre_fault_memory() Paolo Bonzini
2024-04-22 15:37   ` Xiaoyao Li
2024-04-19  8:59 ` [PATCH 6/6] KVM: selftests: x86: Add test for KVM_PRE_FAULT_MEMORY Paolo Bonzini
2024-04-22 17:50   ` Isaku Yamahata
2024-04-23 15:18   ` Xiaoyao Li
2024-04-24  1:59     ` Xiaoyao Li

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=20240419085927.3648704-1-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=binbin.wu@linux.intel.com \
    --cc=isaku.yamahata@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rick.p.edgecombe@intel.com \
    --cc=seanjc@google.com \
    --cc=xiaoyao.li@intel.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).