From: Nikita Kalyazin <kalyazin@amazon.com>
To: "Kalyazin, Nikita" <kalyazin@amazon.co.uk>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"shuah@kernel.org" <shuah@kernel.org>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-kselftest@vger.kernel.org"
<linux-kselftest@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"seanjc@google.com" <seanjc@google.com>,
"david@kernel.org" <david@kernel.org>,
"jthoughton@google.com" <jthoughton@google.com>,
"ackerleytng@google.com" <ackerleytng@google.com>,
"vannapurve@google.com" <vannapurve@google.com>,
"jackmanb@google.com" <jackmanb@google.com>,
"patrick.roy@linux.dev" <patrick.roy@linux.dev>,
"Thomson, Jack" <jackabt@amazon.co.uk>,
"Itazuri, Takahiro" <itazur@amazon.co.uk>,
"Manwaring, Derek" <derekmn@amazon.com>,
"Cali, Marco" <xmarcalx@amazon.co.uk>
Subject: Re: [PATCH v7 0/2] KVM: guest_memfd: use write for population
Date: Fri, 14 Nov 2025 15:23:22 +0000 [thread overview]
Message-ID: <6b79711c-ee0f-47aa-b42f-51f13ac0bd5c@amazon.com> (raw)
In-Reply-To: <20251114151828.98165-1-kalyazin@amazon.com>
On 14/11/2025 15:18, Kalyazin, Nikita wrote:
> On systems that support shared guest memory, write() is useful, for
> example, for population of the initial image. 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 user 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%)
>
> Only PAGE_ALIGNED offset and len are allowed. Even though non-aligned
> writes are technically possible, when in-place conversion support is
> implemented [1], the restriction makes handling of mixed shared/private
> huge pages simpler. write() will only be allowed to populate shared
> pages.
>
> When direct map removal is implemented [2]
> - write() will not be allowed to access pages that have already
> been removed from direct map
> - on completion, write() will remove the populated pages from
> direct map
>
> While it is technically possible to implement read() syscall on systems
> with shared guest memory, it is not supported as there is currently no
> use case for it.
>
> [1]
> https://lore.kernel.org/kvm/cover.1760731772.git.ackerleytng@google.com
> [2]
> https://lore.kernel.org/kvm/20250924151101.2225820-1-patrick.roy@campus.lmu.de
I failed to include links to previous versions:
v7:
- Sean: add GUEST_MEMFD_FLAG_WRITE and documentation for it
- Ackerley: only allow PAGE_ALIGNED offset and len
- Sean/Ackerley: formatting fixes
v6:
- https://lore.kernel.org/kvm/20251020161352.69257-1-kalyazin@amazon.com
- 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 dependencies 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
>
> Documentation/virt/kvm/api.rst | 2 +
> include/linux/kvm_host.h | 2 +-
> include/uapi/linux/kvm.h | 1 +
> .../testing/selftests/kvm/guest_memfd_test.c | 58 +++++++++++++++++--
> virt/kvm/guest_memfd.c | 52 +++++++++++++++++
> 5 files changed, 108 insertions(+), 7 deletions(-)
>
>
> base-commit: 8a4821412cf2c1429fffa07c012dd150f2edf78c
> --
> 2.50.1
>
prev parent reply other threads:[~2025-11-14 15:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 15:18 [PATCH v7 0/2] KVM: guest_memfd: use write for population Kalyazin, Nikita
2025-11-14 15:18 ` [PATCH v7 1/2] KVM: guest_memfd: add generic population via write Kalyazin, Nikita
2026-03-12 0:46 ` Sean Christopherson
2025-11-14 15:18 ` [PATCH v7 2/2] KVM: selftests: update guest_memfd write tests Kalyazin, Nikita
2026-03-12 0:55 ` Sean Christopherson
2025-11-14 15:23 ` Nikita Kalyazin [this message]
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=6b79711c-ee0f-47aa-b42f-51f13ac0bd5c@amazon.com \
--to=kalyazin@amazon.com \
--cc=ackerleytng@google.com \
--cc=david@kernel.org \
--cc=derekmn@amazon.com \
--cc=itazur@amazon.co.uk \
--cc=jackabt@amazon.co.uk \
--cc=jackmanb@google.com \
--cc=jthoughton@google.com \
--cc=kalyazin@amazon.co.uk \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=patrick.roy@linux.dev \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=vannapurve@google.com \
--cc=xmarcalx@amazon.co.uk \
/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