kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6 0/2] KVM: guest_memfd: use write for population
@ 2025-10-20 16:13 Kalyazin, Nikita
  2025-10-20 16:14 ` [PATCH v6 1/2] KVM: guest_memfd: add generic population via write Kalyazin, Nikita
  2025-10-20 16:14 ` [PATCH v6 2/2] KVM: selftests: update guest_memfd write tests Kalyazin, Nikita
  0 siblings, 2 replies; 9+ messages in thread
From: Kalyazin, Nikita @ 2025-10-20 16:13 UTC (permalink / raw)
  To: pbonzini@redhat.com, shuah@kernel.org
  Cc: kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org, seanjc@google.com, david@redhat.com,
	jthoughton@google.com, patrick.roy@linux.dev, Thomson, Jack,
	Manwaring, Derek, Cali, Marco, Kalyazin, Nikita

[ based on kvm/next ]

Implement guest_memfd population via the write syscall.
This is useful in non-CoCo use cases where the host can access guest
memory.  Even though the same can also be achieved via userspace mapping
and memcpying from userspace, write provides a more performant option
because it does not need to set page tables and it does not cause a page
fault for every page like memcpy would.  Note that memcpy cannot be
accelerated via MADV_POPULATE_WRITE as it is not supported by
guest_memfd and relies on GUP.

Populating 512MiB of guest_memfd on a x86 machine:
 - via memcpy: 436 ms
 - via write:  202 ms (-54%)

The write syscall support is conditional on kvm_gmem_supports_mmap.
When in-place shared/private conversion is supported, write should only
be allowed on shared pages.

v6:
 - Make write support conditional on mmap support instead of relying on
   the up-to-date flag to decide whether writing to a page is allowed
 - James: Remove depenendencies on folio_test_large
 - James: Remove page alignment restriction
 - James: Formatting fixes

v5:
 - https://lore.kernel.org/kvm/20250902111951.58315-1-kalyazin@amazon.com/
 - Replace the call to the unexported filemap_remove_folio with
   zeroing the bytes that could not be copied
 - Fix checkpatch findings

v4:
 - https://lore.kernel.org/kvm/20250828153049.3922-1-kalyazin@amazon.com
 - Switch from implementing the write callback to write_iter
 - Remove conditional compilation

v3:
 - https://lore.kernel.org/kvm/20250303130838.28812-1-kalyazin@amazon.com
 - David/Mike D: Only compile support for the write syscall if
   CONFIG_KVM_GMEM_SHARED_MEM (now gone) is enabled.
v2:
 - https://lore.kernel.org/kvm/20241129123929.64790-1-kalyazin@amazon.com
 - Switch from an ioctl to the write syscall to implement population

v1:
 - https://lore.kernel.org/kvm/20241024095429.54052-1-kalyazin@amazon.com

Nikita Kalyazin (2):
  KVM: guest_memfd: add generic population via write
  KVM: selftests: update guest_memfd write tests

 .../testing/selftests/kvm/guest_memfd_test.c  | 51 ++++++++++++++++---
 virt/kvm/guest_memfd.c                        | 49 ++++++++++++++++++
 2 files changed, 94 insertions(+), 6 deletions(-)


base-commit: 6b36119b94d0b2bb8cea9d512017efafd461d6ac
-- 
2.50.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-11-07 17:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-20 16:13 [PATCH v6 0/2] KVM: guest_memfd: use write for population Kalyazin, Nikita
2025-10-20 16:14 ` [PATCH v6 1/2] KVM: guest_memfd: add generic population via write Kalyazin, Nikita
2025-10-23 16:07   ` Sean Christopherson
2025-10-24 14:35     ` Nikita Kalyazin
2025-10-30 21:37       ` Sean Christopherson
2025-11-03 16:55         ` Nikita Kalyazin
2025-11-07 15:42           ` Ackerley Tng
2025-11-07 17:23             ` Nikita Kalyazin
2025-10-20 16:14 ` [PATCH v6 2/2] KVM: selftests: update guest_memfd write tests Kalyazin, Nikita

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).