Skip to content

Commit 9aed7a6

Browse files
yamahatabonzini
authored andcommitted
KVM: Document KVM_PRE_FAULT_MEMORY ioctl
Adds documentation of KVM_PRE_FAULT_MEMORY ioctl. [1] It populates guest memory. It doesn't do extra operations on the underlying technology-specific initialization [2]. For example, CoCo-related operations won't be performed. Concretely for TDX, this API won't invoke TDH.MEM.PAGE.ADD() or TDH.MR.EXTEND(). Vendor-specific APIs are required for such operations. The key point is to adapt of vcpu ioctl instead of VM ioctl. First, populating guest memory requires vcpu. If it is VM ioctl, we need to pick one vcpu somehow. Secondly, vcpu ioctl allows each vcpu to invoke this ioctl in parallel. It helps to scale regarding guest memory size, e.g., hundreds of GB. [1] https://lore.kernel.org/kvm/[email protected]/ [2] https://lore.kernel.org/kvm/[email protected]/ Suggested-by: Sean Christopherson <[email protected]> Signed-off-by: Isaku Yamahata <[email protected]> Message-ID: <9a060293c9ad9a78f1d8994cfe1311e818e99257.1712785629.git.isaku.yamahata@intel.com> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 02b0d3b commit 9aed7a6

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

Documentation/virt/kvm/api.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6352,6 +6352,61 @@ a single guest_memfd file, but the bound ranges must not overlap).
63526352

63536353
See KVM_SET_USER_MEMORY_REGION2 for additional details.
63546354

6355+
4.143 KVM_PRE_FAULT_MEMORY
6356+
------------------------
6357+
6358+
:Capability: KVM_CAP_PRE_FAULT_MEMORY
6359+
:Architectures: none
6360+
:Type: vcpu ioctl
6361+
:Parameters: struct kvm_pre_fault_memory (in/out)
6362+
:Returns: 0 if at least one page is processed, < 0 on error
6363+
6364+
Errors:
6365+
6366+
========== ===============================================================
6367+
EINVAL The specified `gpa` and `size` were invalid (e.g. not
6368+
page aligned, causes an overflow, or size is zero).
6369+
ENOENT The specified `gpa` is outside defined memslots.
6370+
EINTR An unmasked signal is pending and no page was processed.
6371+
EFAULT The parameter address was invalid.
6372+
EOPNOTSUPP Mapping memory for a GPA is unsupported by the
6373+
hypervisor, and/or for the current vCPU state/mode.
6374+
EIO unexpected error conditions (also causes a WARN)
6375+
========== ===============================================================
6376+
6377+
::
6378+
6379+
struct kvm_pre_fault_memory {
6380+
/* in/out */
6381+
__u64 gpa;
6382+
__u64 size;
6383+
/* in */
6384+
__u64 flags;
6385+
__u64 padding[5];
6386+
};
6387+
6388+
KVM_PRE_FAULT_MEMORY populates KVM's stage-2 page tables used to map memory
6389+
for the current vCPU state. KVM maps memory as if the vCPU generated a
6390+
stage-2 read page fault, e.g. faults in memory as needed, but doesn't break
6391+
CoW. However, KVM does not mark any newly created stage-2 PTE as Accessed.
6392+
6393+
In some cases, multiple vCPUs might share the page tables. In this
6394+
case, the ioctl can be called in parallel.
6395+
6396+
When the ioctl returns, the input values are updated to point to the
6397+
remaining range. If `size` > 0 on return, the caller can just issue
6398+
the ioctl again with the same `struct kvm_map_memory` argument.
6399+
6400+
Shadow page tables cannot support this ioctl because they
6401+
are indexed by virtual address or nested guest physical address.
6402+
Calling this ioctl when the guest is using shadow page tables (for
6403+
example because it is running a nested guest with nested page tables)
6404+
will fail with `EOPNOTSUPP` even if `KVM_CHECK_EXTENSION` reports
6405+
the capability to be present.
6406+
6407+
`flags` must currently be zero.
6408+
6409+
63556410
5. The kvm_run structure
63566411
========================
63576412

0 commit comments

Comments
 (0)