mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Garg, Shivank" <shivankg@amd.com>
To: "Gupta, Pankaj" <Pankaj.Gupta@amd.com>,
	"Sampat, Pratik Rajesh" <PratikRajesh.Sampat@amd.com>,
	"nikita.kalyazin@linux.dev" <nikita.kalyazin@linux.dev>,
	"ying.huang@linux.alibaba.com" <ying.huang@linux.alibaba.com>,
	"patrick.roy@linux.dev" <patrick.roy@linux.dev>,
	"joshua.hahnjy@gmail.com" <joshua.hahnjy@gmail.com>,
	"david@kernel.org" <david@kernel.org>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"jmattson@google.com" <jmattson@google.com>,
	"hannes@cmpxchg.org" <hannes@cmpxchg.org>,
	"jack@suse.cz" <jack@suse.cz>,
	"tglx@kernel.org" <tglx@kernel.org>,
	"Dadhania, Nikunj" <nikunj.dadhania@amd.com>,
	"Roth, Michael" <Michael.Roth@amd.com>,
	"corbet@lwn.net" <corbet@lwn.net>,
	"mhocko@suse.com" <mhocko@suse.com>,
	"gourry@gourry.net" <gourry@gourry.net>,
	"iweiny@kernel.org" <iweiny@kernel.org>,
	"chao.p.peng@linux.intel.com" <chao.p.peng@linux.intel.com>,
	"byungchul@sk.com" <byungchul@sk.com>,
	"x86@kernel.org" <x86@kernel.org>, "bp@alien8.de" <bp@alien8.de>,
	"ricarkol@google.com" <ricarkol@google.com>,
	"vannapurve@google.com" <vannapurve@google.com>,
	"shuah@kernel.org" <shuah@kernel.org>,
	"seanjc@google.com" <seanjc@google.com>,
	"jackmanb@google.com" <jackmanb@google.com>,
	"Kalra, Ashish" <Ashish.Kalra@amd.com>,
	"willy@infradead.org" <willy@infradead.org>,
	"surenb@google.com" <surenb@google.com>,
	"pshier@google.com" <pshier@google.com>,
	"matthew.brost@intel.com" <matthew.brost@intel.com>,
	"fuad.tabba@linux.dev" <fuad.tabba@linux.dev>,
	"skhan@linuxfoundation.org" <skhan@linuxfoundation.org>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"rakie.kim@sk.com" <rakie.kim@sk.com>,
	"ackerleytng@google.com" <ackerleytng@google.com>,
	"apopple@nvidia.com" <apopple@nvidia.com>,
	"ziy@nvidia.com" <ziy@nvidia.com>,
	"vbabka@kernel.org" <vbabka@kernel.org>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>
Cc: "linux-kselftest@vger.kernel.org"
	<linux-kselftest@vger.kernel.org>,
	"sashiko-bot@kernel.org" <sashiko-bot@kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-coco@lists.linux.dev" <linux-coco@lists.linux.dev>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH v3 0/9] KVM: guest_memfd: folio migration for non-confidential VMs
Date: Fri, 11 Sep 2026 11:37:28 +0000	[thread overview]
Message-ID: <4f190c4bfd90ce93b6ebf898fc39371f8aa8e6ea.camel@amd.com> (raw)
In-Reply-To: <0b8c746e-544b-4ec0-91dd-d5e10e1920dd@kernel.org>

On Thu, 2026-09-10 at 11:58 +0200, David Hildenbrand (Arm) wrote:
> 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.
> 

Sure, makes sense.
I'll drop GUEST_MEMFD_FLAG_UNMIGRATABLE.

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

Thanks for the pointers.
I'll think about khugepaged implementation for this.

Best regards,
Shivank


      reply	other threads:[~2026-09-11 11:37 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05  6:40 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)
2026-09-11 11:37   ` Garg, Shivank [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=4f190c4bfd90ce93b6ebf898fc39371f8aa8e6ea.camel@amd.com \
    --to=shivankg@amd.com \
    --cc=Ashish.Kalra@amd.com \
    --cc=Michael.Roth@amd.com \
    --cc=Pankaj.Gupta@amd.com \
    --cc=PratikRajesh.Sampat@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=david@kernel.org \
    --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=mingo@redhat.com \
    --cc=nikita.kalyazin@linux.dev \
    --cc=nikunj.dadhania@amd.com \
    --cc=patrick.roy@linux.dev \
    --cc=pbonzini@redhat.com \
    --cc=pshier@google.com \
    --cc=rakie.kim@sk.com \
    --cc=ricarkol@google.com \
    --cc=sashiko-bot@kernel.org \
    --cc=seanjc@google.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

all inboxes | Powered by JetHome®