linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: James Houghton <jthoughton@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	 Oliver Upton <oliver.upton@linux.dev>
Cc: Jonathan Corbet <corbet@lwn.net>, Marc Zyngier <maz@kernel.org>,
	Yan Zhao <yan.y.zhao@intel.com>,
	 James Houghton <jthoughton@google.com>,
	Nikita Kalyazin <kalyazin@amazon.com>,
	 Anish Moorthy <amoorthy@google.com>,
	Peter Gonda <pgonda@google.com>, Peter Xu <peterx@redhat.com>,
	 David Matlack <dmatlack@google.com>,
	wei.w.wang@intel.com, kvm@vger.kernel.org,
	 linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
	 Bagas Sanjaya <bagasdotme@gmail.com>
Subject: [PATCH v3 15/15] KVM: Documentation: Add KVM_CAP_USERFAULT and KVM_MEM_USERFAULT details
Date: Wed, 18 Jun 2025 04:24:24 +0000	[thread overview]
Message-ID: <20250618042424.330664-16-jthoughton@google.com> (raw)
In-Reply-To: <20250618042424.330664-1-jthoughton@google.com>

Include the note about memory ordering when clearing bits in
userfault_bitmap, as it may not be obvious for users.

Signed-off-by: James Houghton <jthoughton@google.com>
Reviewed-by: Bagas Sanjaya <bagasdotme@gmail.com>
---
 Documentation/virt/kvm/api.rst | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index ff0aa9eb91efe..25668206a5d80 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -6308,7 +6308,8 @@ bounds checks apply (use common sense).
 	__u64 guest_memfd_offset;
 	__u32 guest_memfd;
 	__u32 pad1;
-	__u64 pad2[14];
+	__u64 userfault_bitmap;
+	__u64 pad2[13];
   };
 
 A KVM_MEM_GUEST_MEMFD region _must_ have a valid guest_memfd (private memory) and
@@ -6324,6 +6325,25 @@ state.  At VM creation time, all memory is shared, i.e. the PRIVATE attribute
 is '0' for all gfns.  Userspace can control whether memory is shared/private by
 toggling KVM_MEMORY_ATTRIBUTE_PRIVATE via KVM_SET_MEMORY_ATTRIBUTES as needed.
 
+When the KVM_MEM_USERFAULT flag is set, userfault_bitmap points to the starting
+address for the bitmap that controls if vCPU memory faults should immediately
+exit to userspace. If an invalid pointer is provided, at fault time, KVM_RUN
+will return -EFAULT. KVM_MEM_USERFAULT is only supported when
+KVM_CAP_USERFAULT is supported.
+
+userfault_bitmap should point to an array of longs where each bit in the array
+linearly corresponds to a single gfn. Bit 0 in userfault_bitmap corresponds to
+guest_phys_addr, bit 1 corresponds to guest_phys_addr + PAGE_SIZE, etc. If the
+bit for a page is set, any vCPU access to that page will exit to userspace with
+KVM_MEMORY_EXIT_FLAG_USERFAULT.
+
+Setting bits in userfault_bitmap has no effect on pages that have already been
+mapped by KVM until KVM_MEM_USERFAULT is disabled and re-enabled again.
+
+Clearing bits in userfault_bitmap should usually be done with a store-release
+if changes to guest memory are being made available to the guest via
+userfault_bitmap.
+
 S390:
 ^^^^^
 
@@ -8557,6 +8577,17 @@ given VM.
 When this capability is enabled, KVM resets the VCPU when setting
 MP_STATE_INIT_RECEIVED through IOCTL.  The original MP_STATE is preserved.
 
+7.44 KVM_CAP_USERFAULT
+----------------------
+
+:Architectures: x86, arm64
+:Returns: Informational only, -EINVAL on direct KVM_ENABLE_CAP.
+
+The presence of this capability indicates that KVM_SET_USER_MEMORY_REGION2 will
+accept KVM_MEM_USERFAULT as a valid memslot flag.
+
+See KVM_SET_USER_MEMORY_REGION2 for more details.
+
 8. Other capabilities.
 ======================
 
-- 
2.50.0.rc2.692.g299adb8693-goog



  parent reply	other threads:[~2025-06-18  5:01 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-18  4:24 [PATCH v3 00/15] KVM: Introduce KVM Userfault James Houghton
2025-06-18  4:24 ` [PATCH v3 01/15] KVM: x86/mmu: Move "struct kvm_page_fault" definition to asm/kvm_host.h James Houghton
2025-06-18  4:24 ` [PATCH v3 02/15] KVM: arm64: Add "struct kvm_page_fault" to gather common fault variables James Houghton
2025-06-18 19:26   ` Oliver Upton
2025-06-18 21:17     ` Sean Christopherson
2025-06-18  4:24 ` [PATCH v3 03/15] KVM: arm64: x86: Require "struct kvm_page_fault" for memory fault exits James Houghton
2025-06-18 20:00   ` Oliver Upton
2025-06-18 20:47     ` Sean Christopherson
2025-06-18 23:14       ` Oliver Upton
2025-06-19  1:22         ` Sean Christopherson
2025-06-18  4:24 ` [PATCH v3 04/15] KVM: Add common infrastructure for KVM Userfaults James Houghton
2025-06-18 19:40   ` Oliver Upton
2025-06-18 20:33     ` Sean Christopherson
2025-06-18 20:41       ` James Houghton
2025-06-18 22:43       ` Oliver Upton
2025-06-19  1:27         ` Sean Christopherson
2025-06-18 20:38     ` James Houghton
2025-06-18  4:24 ` [PATCH v3 05/15] KVM: x86: Add support for KVM userfault exits James Houghton
2025-07-30 21:11   ` James Houghton
2025-06-18  4:24 ` [PATCH v3 06/15] KVM: arm64: " James Houghton
2025-06-18  4:24 ` [PATCH v3 07/15] KVM: Enable and advertise " James Houghton
2025-06-18  4:24 ` [PATCH v3 08/15] KVM: selftests: Fix vm_mem_region_set_flags docstring James Houghton
2025-06-18  4:24 ` [PATCH v3 09/15] KVM: selftests: Fix prefault_mem logic James Houghton
2025-06-18  4:24 ` [PATCH v3 10/15] KVM: selftests: Add va_start/end into uffd_desc James Houghton
2025-06-18  4:24 ` [PATCH v3 11/15] KVM: selftests: Add KVM Userfault mode to demand_paging_test James Houghton
2025-06-18  4:24 ` [PATCH v3 12/15] KVM: selftests: Inform set_memory_region_test of KVM_MEM_USERFAULT James Houghton
2025-06-18  4:24 ` [PATCH v3 13/15] KVM: selftests: Add KVM_MEM_USERFAULT + guest_memfd toggle tests James Houghton
2025-06-18  4:24 ` [PATCH v3 14/15] KVM: Documentation: Fix section number for KVM_CAP_ARM_WRITABLE_IMP_ID_REGS James Houghton
2025-06-18  4:24 ` James Houghton [this message]
2025-06-18 23:24 ` [PATCH v3 00/15] KVM: Introduce KVM Userfault 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=20250618042424.330664-16-jthoughton@google.com \
    --to=jthoughton@google.com \
    --cc=amoorthy@google.com \
    --cc=bagasdotme@gmail.com \
    --cc=corbet@lwn.net \
    --cc=dmatlack@google.com \
    --cc=kalyazin@amazon.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=pgonda@google.com \
    --cc=seanjc@google.com \
    --cc=wei.w.wang@intel.com \
    --cc=yan.y.zhao@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 NNTP newsgroup(s).