From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Shivank Garg <shivankg@amd.com>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
Jan Kara <jack@suse.cz>,
Andrew Morton <akpm@linux-foundation.org>,
Vlastimil Babka <vbabka@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
Brendan Jackman <jackmanb@google.com>,
Johannes Weiner <hannes@cmpxchg.org>, Zi Yan <ziy@nvidia.com>,
Matthew Brost <matthew.brost@intel.com>,
Joshua Hahn <joshua.hahnjy@gmail.com>,
Rakie Kim <rakie.kim@sk.com>, Byungchul Park <byungchul@sk.com>,
Gregory Price <gourry@gourry.net>,
Ying Huang <ying.huang@linux.alibaba.com>,
Alistair Popple <apopple@nvidia.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Shuah Khan <shuah@kernel.org>,
Chao Peng <chao.p.peng@linux.intel.com>,
Nikunj A Dadhania <nikunj@amd.com>,
Michael Roth <michael.roth@amd.com>,
Pankaj Gupta <pankaj.gupta@amd.com>,
Ackerley Tng <ackerleytng@google.com>,
Sean Christopherson <seanjc@google.com>,
Vishal Annapurve <vannapurve@google.com>,
Nikita Kalyazin <nikita.kalyazin@linux.dev>,
Patrick Roy <patrick.roy@linux.dev>,
Pratik Sampat <prsampat@amd.com>,
Ashish Kalra <Ashish.Kalra@amd.com>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Peter Shier <pshier@google.com>,
Jim Mattson <jmattson@google.com>,
Ricardo Koller <ricarkol@google.com>,
Ira Weiny <iweiny@kernel.org>, Fuad Tabba <fuad.tabba@linux.dev>
Cc: linux-fsdevel@vger.kernel.org, linux-coco@lists.linux.dev,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-doc@vger.kernel.org, Sashiko <sashiko-bot@kernel.org>
Subject: Re: [PATCH v3 0/9] KVM: guest_memfd: folio migration for non-confidential VMs
Date: Thu, 10 Sep 2026 11:58:09 +0200 [thread overview]
Message-ID: <0b8c746e-544b-4ec0-91dd-d5e10e1920dd@kernel.org> (raw)
In-Reply-To: <20260805-shivank-gmem-migrate-v3-0-00d8bdec4e1d@amd.com>
On 8/5/26 08:40, Shivank Garg wrote:
> guest_memfd folios are currently always marked unmovable, so the kernel cannot
> perform memory compaction, offlining, etc. This is unavoidable for
> confidential VMs (SEV-SNP, TDX), since memory is encrypted and copying it
> needs firmware assistance. However, for non-confidential VMs (like
> Firecracker), we can migrate the folios.
Yes.
>
> This series enables folio migration for non-confidential guest_memfd and
> also lays the groundwork for migrating confidential guest_memfd later.
> Once firmware-assisted copying support is available, those VMs can be
> made movable, the confidential folio content can be copied separately,
> and the destination folio marked with FOLIO_CONTENT_COPIED[4] so
> __migrate_folio() skips the host-side folio_mc_copy().
>
> Testing
> -------
> Host: 7.2-rc6+(c21bb419386) + this, AMD EPYC ZEN 3, 2 NUMA nodes
>
> - KVM selftest: allocate folios on node 0, migrate them to node 1 and
> back and verify resulting NUMA node and the folio contents at each
> step.
>
> - Firecracker [1]: booted a microVM backed by guest_memfd. While the
> guest was running, forced host-side migration of its folios via
> migratepages(8) and explicit move_pages(2) of guest_memfd
> pages. Verify with /proc/firecracker_pid/numa_maps.
>
> Notes
> -----
> - Sashiko pointed out a pre-existing ABBA deadlock between
> kvm_gmem_error_folio() and truncation. It's being addressed separately
> by Hao Zhang. [2][3]
>
> [1] https://github.com/firecracker-microvm/firecracker/tree/feature/secret-hiding
> In builder.rs, add GUEST_MEMFD_FLAG_MIGRATABLE to bit-2 and pass it instead
> of GUEST_MEMFD_FLAG_NO_DIRECT_MAP to vm.create_guest_memfd().
> [2] https://lore.kernel.org/all/ambEdSPjerZIVN0b@192.168.1.215/
> [3] https://sashiko.dev/#/patchset/20260611-shivank-gmem-migrate-v1-0-2d266bfc6f95%40amd.com
> [4] https://lore.kernel.org/all/20260630-shivank-batch-migrate-offload-v6-1-da95d7e8b8a2@amd.com
>
> Signed-off-by: Shivank Garg <shivankg@amd.com>
> ---
> Changes in v3:
> - Fix unbalanced mmu_invalidate_in_progress count unbinding dying guest_memfd. (Sashiko)
> - Fix maxnode handling in xapic_ipi_test selftest.
> - Add GUEST_MEMFD_FLAG_MIGRATABLE documentation
> - Replace open-coded sizeof() * 8 calculation with BITS_PER_TYPE()
> - Add get_numa_mem_nodes() and use MPOL_F_MEMS_ALLOWED for allowed NUMA ndoes
> instead of hardcoded NUMA node IDs. (Sashiko)
> - Extend migration selftest to verify rejection without MIGRATABLE flag and
> move repeated checks into common helpers.
> - Drop RFC tag.
> - Link to v2: https://lore.kernel.org/r/20260728-shivank-gmem-migrate-v2-0-269ac1f84e2b@amd.com
>
> Changes in v2:
> - Make folio migration opt-in through GUEST_MEMFD_FLAG_MIGRATABLE,
> preserving unmovable behavior if userspace don't explictly ask. (Alexandru, David, Sean)
> - Add kvm_arch_supports_gmem_migration() so arch can control whether
> GUEST_MEMFD_FLAG_MIGRATABLE is advertised.
> - Allocate movable folios with GFP_HIGHUSER_MOVABLE. (David)
> - Keep guest_memfd unevictable. (David, Sashiko, Sean)
> - Split migrate_folio() implementation and enablement as separate patches.
> - Update selftest with new flag.
> - Link to v1: https://lore.kernel.org/r/20260611-shivank-gmem-migrate-v1-0-2d266bfc6f95@amd.com
>
> ---
> Shivank Garg (9):
> KVM: guest_memfd: take the invalidate lock when unbinding a dying file
> mm: split AS_UNMOVABLE back out of AS_INACCESSIBLE
> KVM: guest_memfd: implement folio migration for non-confidential VMs
> KVM: guest_memfd: add GUEST_MEMFD_FLAG_MIGRATABLE
As discussed, we should for now just always enable it and not expose such a
flag. The hope is that use cases that need migration disabled can just find a
way for kvm to tell guest_memfd about that internally ... or we'll add a
GUEST_MEMFD_FLAG_UNMIGRATABLE or whatever later.
With migration in place, as also discussed, it would be interesting to
investigate what it would take for these shared-only (no conversion) and
migratable guest_memfd instances to support THPs.
I'd assume we might have to teach
1) guest_memfd / KVM parts about this, although I recall that most of it should
be there
2) Unlock guest_memfd in khugeapged
We disallowed khugepaged entirely in commit
commit dd085fe9a8ebfc5d10314c60452db38d2b75e609
Author: Deepanshu Kartikey <kartikey406@gmail.com>
Date: Sat Feb 14 05:45:35 2026 +0530
mm: thp: deny THP for files on anonymous inodes
file_thp_enabled() incorrectly allows THP for files on anonymous inodes
(e.g. guest_memfd and secretmem). These files are created via
alloc_file_pseudo(), which does not call get_write_access() and leaves
inode->i_writecount at 0. Combined with S_ISREG(inode->i_mode) being
true, they appear as read-only regular files when
CONFIG_READ_ONLY_THP_FOR_FS is enabled, making them eligible for THP
collapse.
It will also be interesting to figure out how well khugepaged would collapse
guest_memfd when most folios are not actually faulted into the user page tables.
collapse_scan_file() does not seem to worry about whether folios are actually
mapped, just if they are present in the page cache.
Which might mean that as long as guestmemfd is mmap'ed, it might just work.
--
Cheers,
David
next prev parent reply other threads:[~2026-09-10 9:58 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 6:40 [PATCH v3 0/9] KVM: guest_memfd: folio migration for non-confidential VMs Shivank Garg
2026-08-05 6:40 ` [PATCH v3 1/9] KVM: guest_memfd: take the invalidate lock when unbinding a dying file Shivank Garg
2026-09-10 9:58 ` David Hildenbrand (Arm)
2026-09-11 6:40 ` Garg, Shivank
2026-08-05 6:40 ` [PATCH v3 2/9] mm: split AS_UNMOVABLE back out of AS_INACCESSIBLE Shivank Garg
2026-09-10 10:03 ` David Hildenbrand (Arm)
2026-09-11 13:22 ` Garg, Shivank
2026-08-05 6:40 ` [PATCH v3 3/9] KVM: guest_memfd: implement folio migration for non-confidential VMs Shivank Garg
2026-09-10 10:05 ` David Hildenbrand (Arm)
2026-09-11 11:42 ` Garg, Shivank
2026-08-05 6:40 ` [PATCH v3 4/9] KVM: guest_memfd: add GUEST_MEMFD_FLAG_MIGRATABLE Shivank Garg
2026-08-05 6:40 ` [PATCH v3 5/9] KVM: selftests: fix maxnode arguments in xapic_ipi_test Shivank Garg
2026-08-05 6:40 ` [PATCH v3 6/9] KVM: selftests: use BITS_PER_TYPE() for NUMA masks Shivank Garg
2026-08-05 6:40 ` [PATCH v3 7/9] KVM: selftests: add get_numa_mem_nodes() Shivank Garg
2026-08-05 6:40 ` [PATCH v3 8/9] KVM: selftests: use allowed NUMA nodes in guest_memfd_test Shivank Garg
2026-08-05 6:40 ` [PATCH v3 9/9] KVM: selftests: exercise guest_memfd folio migration Shivank Garg
2026-08-21 12:34 ` [PATCH v3 0/9] KVM: guest_memfd: folio migration for non-confidential VMs Garg, Shivank
2026-08-21 13:39 ` David Hildenbrand (Arm)
2026-09-10 9:58 ` David Hildenbrand (Arm) [this message]
2026-09-11 11:37 ` Garg, Shivank
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=0b8c746e-544b-4ec0-91dd-d5e10e1920dd@kernel.org \
--to=david@kernel.org \
--cc=Ashish.Kalra@amd.com \
--cc=ackerleytng@google.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=bp@alien8.de \
--cc=byungchul@sk.com \
--cc=chao.p.peng@linux.intel.com \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=fuad.tabba@linux.dev \
--cc=gourry@gourry.net \
--cc=hannes@cmpxchg.org \
--cc=hpa@zytor.com \
--cc=iweiny@kernel.org \
--cc=jack@suse.cz \
--cc=jackmanb@google.com \
--cc=jmattson@google.com \
--cc=joshua.hahnjy@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=matthew.brost@intel.com \
--cc=mhocko@suse.com \
--cc=michael.roth@amd.com \
--cc=mingo@redhat.com \
--cc=nikita.kalyazin@linux.dev \
--cc=nikunj@amd.com \
--cc=pankaj.gupta@amd.com \
--cc=patrick.roy@linux.dev \
--cc=pbonzini@redhat.com \
--cc=prsampat@amd.com \
--cc=pshier@google.com \
--cc=rakie.kim@sk.com \
--cc=ricarkol@google.com \
--cc=sashiko-bot@kernel.org \
--cc=seanjc@google.com \
--cc=shivankg@amd.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=surenb@google.com \
--cc=tglx@kernel.org \
--cc=vannapurve@google.com \
--cc=vbabka@kernel.org \
--cc=willy@infradead.org \
--cc=x86@kernel.org \
--cc=ying.huang@linux.alibaba.com \
--cc=ziy@nvidia.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