Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v12 00/45] guest_memfd: In-place conversion support
@ 2026-08-31  0:25 Ackerley Tng via B4 Relay
  2026-08-31  0:25 ` [PATCH v12 01/45] KVM: guest_memfd: Optimize away conversion overheads via dead-code elimination Ackerley Tng via B4 Relay
                   ` (44 more replies)
  0 siblings, 45 replies; 71+ messages in thread
From: Ackerley Tng via B4 Relay @ 2026-08-31  0:25 UTC (permalink / raw)
  To: aik, andrew.jones, binbin.wu, brauner, chao.p.peng, david,
	jmattson, jthoughton, michael.roth, oupton, pankaj.gupta, qperret,
	rick.p.edgecombe, rientjes, shivankg, steven.price, willy, wyihan,
	yan.y.zhao, forkloop, pratyush, suzuki.poulose, aneesh.kumar,
	liam, Paolo Bonzini, Sean Christopherson, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers,
	Jonathan Corbet, Shuah Khan, Shuah Khan, Vishal Annapurve,
	Andrew Morton, Chris Li, Kairui Song, Kemeng Shi, Nhat Pham,
	Barry Song, Axel Rasmussen, Yuanchu Xie, Wei Xu, Youngjun Park,
	Qi Zheng, Shakeel Butt, Kiryl Shutsemau, Baoquan He,
	Jason Gunthorpe, John Hubbard, Peter Xu, tarunsahu, Randy Dunlap,
	Lorenzo Stoakes, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, Jason Gunthorpe, Fuad Tabba,
	Vlastimil Babka, Baoquan He
  Cc: kvm, linux-kernel, linux-trace-kernel, linux-doc, linux-kselftest,
	linux-mm, linux-coco, Ackerley Tng, Xiaoyao Li, Fuad Tabba

Here's v12. Thanks everyone for the comments and fast responses!  We're now
at ~4 weeks to soft-close at 7.3-rc5.

v12 is based on 7.3-rc1 (contains the mm/ bugfixes). Like v11, v12 is also
dependent on another series [3], which makes kvm_gmem_get_pfn() NOT return
a refcounted page to KVM.

Here's everything stitched together for your convenience:

https://github.com/googleprodkernel/linux-cc/commits/guest_memfd-inplace-conversion-v12

This revision resolves the issue on v10/v11 to do with over-zapping of
non-gmem memory because of the requested filters. [1]

The resolution is in a new patch "KVM: guest_memfd: Always fault from
guest_memfd if in-place conversion is enabled". I also updated the
documentation as requested.

Documentation updates are in these patches:

+ KVM: guest_memfd: Stub in ability to enable in-place shared<=>private conversion
+ KVM: guest_memfd: Always fault from guest_memfd if in-place conversion is enabled
+ KVM: guest_memfd: Add base support for KVM_SET_MEMORY_ATTRIBUTES2

The documentation update in v10's "KVM: Let userspace disable per-VM mem
attributes, enable per-gmem attributes" was misplaced imo so I folded it
conceptually into the patches above.

private_mem_conversions_test was updated in v11 to test dual backing, and
that's meaningless now since with gmem_in_place_conversions, we're now
always faulting from guest_memfd, and the userspace_addr not being from the
gmem associated with the memslot is considered a user error.

I now only have 1 patch "KVM: selftests: Update
private_mem_conversions_test for in-place conversions" instead of 2 in v11.

Resolves discussion at [2].

Here's v12 with tests:

https://github.com/googleprodkernel/linux-cc/commits/guest_memfd-inplace-conversion-coco-selftests-v12

Tested with both CONFIG_KVM_VM_MEMORY_ATTRIBUTES enabled and disabled:

+ tools/testing/selftests/kvm/guest_memfd_test.c
+ tools/testing/selftests/kvm/pre_fault_memory_test.c
+ tools/testing/selftests/kvm/x86/guest_memfd_conversions_test.c
+ tools/testing/selftests/kvm/x86/private_mem_conversions_test.c
+ tools/testing/selftests/kvm/x86/private_mem_kvm_exits_test.c

[1] https://lore.kernel.org/all/apCLFSbj8sq2biJp@google.com/
[2] https://lore.kernel.org/all/apCj6gz8x24Dkle8@google.com/
[3] https://lore.kernel.org/all/20260826-gmem-no-return-page-v4-0-3bb9c1ddb4e3@google.com/

v11: https://patch.msgid.link/20260826-gmem-inplace-conversion-v11-0-0a15d8a799aa@google.com
v10: https://lore.kernel.org/r/20260807-gmem-inplace-conversion-v10-0-2fc18ee6d3ba@google.com
v9: https://lore.kernel.org/r/20260728-gmem-inplace-conversion-v9-0-35f9aec2aed2@google.com
v8: https://lore.kernel.org/r/20260618-gmem-inplace-conversion-v8-0-9d2959357853@google.com
v7: https://lore.kernel.org/r/20260522-gmem-inplace-conversion-v7-0-2f0fae496530@google.com
v6: https://lore.kernel.org/r/20260507-gmem-inplace-conversion-v6-0-91ab5a8b19a4@google.com
RFC v5: https://lore.kernel.org/r/20260428-gmem-inplace-conversion-v5-0-d8608ccfca22@google.com
RFC v4: https://lore.kernel.org/all/20260326-gmem-inplace-conversion-v4-0-e202fe950ffd@google.com/T/
RFC v3: https://lore.kernel.org/r/20260313-gmem-inplace-conversion-v3-0-5fc12a70ec89@google.com/T/
RFC v2: https://lore.kernel.org/all/cover.1770071243.git.ackerleytng@google.com/T/
RFC v1: https://lore.kernel.org/all/cover.1760731772.git.ackerleytng@google.com/T/

Previous versions of this feature, part of other series, are available at:

+ https://lore.kernel.org/all/bd163de3118b626d1005aa88e71ef2fb72f0be0f.1726009989.git.ackerleytng@google.com/
+ https://lore.kernel.org/all/20250117163001.2326672-6-tabba@google.com/
+ https://lore.kernel.org/all/b784326e9ccae6a08388f1bf39db70a2204bdc51.1747264138.git.ackerleytng@google.com/

Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
Ackerley Tng (23):
      KVM: Rename kvm_mem_is_private() to kvm_is_private_gfn()
      KVM: guest_memfd: Always fault from guest_memfd if in-place conversion is enabled
      KVM: guest_memfd: Pass mapping type filter to invalidation helper
      KVM: guest_memfd: Add base support for KVM_SET_MEMORY_ATTRIBUTES2
      KVM: guest_memfd: Ensure pages are not in use before conversion
      KVM: guest_memfd: Call arch make_shared callback for to-shared conversion
      KVM: guest_memfd: Return early if range already has requested attributes
      KVM: guest_memfd: Handle lru_add fbatch refcounts during conversion safety check
      KVM: guest_memfd: Zero page while getting pfn
      KVM: TDX: Make source page optional for KVM_TDX_INIT_MEM_REGION
      KVM: selftests: Test basic single-page conversion flow
      KVM: selftests: Test conversion flow when INIT_SHARED
      KVM: selftests: Test conversion precision in guest_memfd
      KVM: selftests: Test conversion before allocation
      KVM: selftests: Convert with allocated folios in different layouts
      KVM: selftests: Test that truncation does not change shared/private status
      KVM: selftests: Add helpers to pin pages with CONFIG_GUP_TEST
      KVM: selftests: Test conversion with elevated page refcount
      KVM: selftests: Reset shared memory after hole-punching
      KVM: selftests: Provide function to look up guest_memfd details from gpa
      KVM: selftests: Make TEST_EXPECT_SIGBUS thread-safe
      KVM: selftests: Set up page size and alignment independently for guest_memfd
      KVM: selftests: Update private_mem_conversions_test for in-place conversions

Michael Roth (1):
      KVM: SEV: Make 'uaddr' parameter optional for KVM_SEV_SNP_LAUNCH_UPDATE

Sean Christopherson (21):
      KVM: guest_memfd: Optimize away conversion overheads via dead-code elimination
      KVM: guest_memfd: Use kvm_mem_is_private() when populating guest_memfd memory
      KVM: guest_memfd: Introduce per-gmem attributes, use to guard user mappings
      KVM: Rename KVM_GENERIC_MEMORY_ATTRIBUTES to KVM_VM_MEMORY_ATTRIBUTES
      KVM: Enumerate support for PRIVATE memory iff kvm_arch_has_private_mem is defined
      KVM: Rename memory attribute APIs to prepare for in-place gmem conversion
      KVM: Provide generic interface for checking memory private/shared status
      KVM: guest_memfd: Stub in ability to enable in-place shared<=>private conversion
      KVM: Consolidate private memory and guest_memfd ifdeffery in kvm_host.h
      KVM: guest_memfd: Invalidate both SHARED and PRIVATE mappings for in-place conversions
      KVM: Move KVM_VM_MEMORY_ATTRIBUTES config definition to x86
      KVM: Let userspace disable per-VM mem attributes, enable per-gmem attributes
      KVM: guest_memfd: Enable INIT_SHARED on guest_memfd for x86 Coco VMs
      KVM: selftests: Create gmem fd before "regular" fd when adding memslot
      KVM: selftests: Rename guest_memfd{,_offset} to gmem_{fd,offset}
      KVM: selftests: Add support for mmap() on guest_memfd in core library
      KVM: selftests: Add selftests global for guest memory attributes capability
      KVM: selftests: Add helpers for calling ioctls on guest_memfd
      KVM: selftests: Test that shared/private status is consistent across processes
      KVM: selftests: Provide common function to set memory attributes
      KVM: selftests: Update private memory exits test to work with per-gmem attributes

 Documentation/admin-guide/kernel-parameters.txt    |  25 +
 Documentation/virt/kvm/api.rst                     | 107 ++++-
 .../virt/kvm/x86/amd-memory-encryption.rst         |  14 +-
 Documentation/virt/kvm/x86/intel-tdx.rst           |   4 +
 arch/x86/include/asm/kvm-x86-ops.h                 |   2 +-
 arch/x86/include/asm/kvm_host.h                    |   9 +-
 arch/x86/kvm/Kconfig                               |  15 +-
 arch/x86/kvm/mmu/mmu.c                             |  28 +-
 arch/x86/kvm/svm/sev.c                             |  13 +-
 arch/x86/kvm/vmx/tdx.c                             |   8 +-
 arch/x86/kvm/x86.c                                 |  20 +-
 include/linux/kvm_host.h                           |  83 ++--
 include/trace/events/kvm.h                         |   6 +-
 include/uapi/linux/kvm.h                           |  16 +
 mm/folio.c                                         |   2 +
 tools/testing/selftests/kvm/Makefile.kvm           |   1 +
 tools/testing/selftests/kvm/include/kvm_util.h     | 139 +++++-
 tools/testing/selftests/kvm/include/test_util.h    |  34 +-
 tools/testing/selftests/kvm/lib/kvm_util.c         | 222 +++++----
 tools/testing/selftests/kvm/lib/test_util.c        |   7 -
 .../kvm/x86/guest_memfd_conversions_test.c         | 512 +++++++++++++++++++++
 .../kvm/x86/private_mem_conversions_test.c         |  66 ++-
 .../selftests/kvm/x86/private_mem_kvm_exits_test.c |  36 +-
 virt/kvm/Kconfig                                   |   3 -
 virt/kvm/guest_memfd.c                             | 469 +++++++++++++++++--
 virt/kvm/kvm_main.c                                |  92 ++--
 26 files changed, 1646 insertions(+), 287 deletions(-)
---
base-commit: a0c789941a3d705d00c018b3c9348b4b930c0c74
change-id: 20260225-gmem-inplace-conversion-bd0dbd39753a

Best regards,
--
Ackerley Tng <ackerleytng@google.com>




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

end of thread, other threads:[~2026-09-02 13:30 UTC | newest]

Thread overview: 71+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-31  0:25 [PATCH v12 00/45] guest_memfd: In-place conversion support Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 01/45] KVM: guest_memfd: Optimize away conversion overheads via dead-code elimination Ackerley Tng via B4 Relay
2026-09-01  8:39   ` Fuad Tabba
2026-09-01  9:13   ` Binbin Wu
2026-08-31  0:25 ` [PATCH v12 02/45] KVM: guest_memfd: Use kvm_mem_is_private() when populating guest_memfd memory Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 03/45] KVM: guest_memfd: Introduce per-gmem attributes, use to guard user mappings Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 04/45] KVM: Rename KVM_GENERIC_MEMORY_ATTRIBUTES to KVM_VM_MEMORY_ATTRIBUTES Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 05/45] KVM: Enumerate support for PRIVATE memory iff kvm_arch_has_private_mem is defined Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 06/45] KVM: Rename memory attribute APIs to prepare for in-place gmem conversion Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 07/45] KVM: Rename kvm_mem_is_private() to kvm_is_private_gfn() Ackerley Tng via B4 Relay
2026-09-01  8:42   ` Fuad Tabba
2026-09-01  9:18   ` Binbin Wu
2026-08-31  0:25 ` [PATCH v12 08/45] KVM: Provide generic interface for checking memory private/shared status Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 09/45] KVM: guest_memfd: Stub in ability to enable in-place shared<=>private conversion Ackerley Tng via B4 Relay
2026-09-01  9:10   ` Fuad Tabba
2026-09-01  9:47   ` Binbin Wu
2026-08-31  0:25 ` [PATCH v12 10/45] KVM: Consolidate private memory and guest_memfd ifdeffery in kvm_host.h Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 11/45] KVM: guest_memfd: Invalidate both SHARED and PRIVATE mappings for in-place conversions Ackerley Tng via B4 Relay
2026-09-01  9:44   ` Fuad Tabba
2026-09-02  3:27   ` Binbin Wu
2026-08-31  0:25 ` [PATCH v12 12/45] KVM: guest_memfd: Always fault from guest_memfd if in-place conversion is enabled Ackerley Tng via B4 Relay
2026-09-01 10:13   ` Fuad Tabba
2026-09-02  5:01   ` Yan Zhao
2026-09-02  6:00   ` Binbin Wu
2026-08-31  0:25 ` [PATCH v12 13/45] KVM: guest_memfd: Pass mapping type filter to invalidation helper Ackerley Tng via B4 Relay
2026-09-01 10:33   ` Fuad Tabba
2026-09-02  6:02   ` Binbin Wu
2026-08-31  0:25 ` [PATCH v12 14/45] KVM: guest_memfd: Add base support for KVM_SET_MEMORY_ATTRIBUTES2 Ackerley Tng via B4 Relay
2026-09-01  8:00   ` Fuad Tabba
2026-08-31  0:25 ` [PATCH v12 15/45] KVM: guest_memfd: Ensure pages are not in use before conversion Ackerley Tng via B4 Relay
2026-09-01  7:45   ` Fuad Tabba
2026-09-01 18:35     ` Sean Christopherson
2026-09-01 18:41       ` Sean Christopherson
2026-08-31  0:25 ` [PATCH v12 16/45] KVM: guest_memfd: Call arch make_shared callback for to-shared conversion Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 17/45] KVM: guest_memfd: Return early if range already has requested attributes Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 18/45] KVM: guest_memfd: Handle lru_add fbatch refcounts during conversion safety check Ackerley Tng via B4 Relay
2026-09-02  2:21   ` Hugh Dickins
2026-08-31  0:25 ` [PATCH v12 19/45] KVM: guest_memfd: Zero page while getting pfn Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 20/45] KVM: SEV: Make 'uaddr' parameter optional for KVM_SEV_SNP_LAUNCH_UPDATE Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 21/45] KVM: TDX: Make source page optional for KVM_TDX_INIT_MEM_REGION Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 22/45] KVM: Move KVM_VM_MEMORY_ATTRIBUTES config definition to x86 Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 23/45] KVM: Let userspace disable per-VM mem attributes, enable per-gmem attributes Ackerley Tng via B4 Relay
2026-09-01  8:19   ` Fuad Tabba
2026-09-01 18:26     ` Sean Christopherson
2026-09-01 22:22       ` Fuad Tabba
2026-09-02  5:56       ` Binbin Wu
2026-09-02 13:30         ` Sean Christopherson
2026-08-31  0:25 ` [PATCH v12 24/45] KVM: guest_memfd: Enable INIT_SHARED on guest_memfd for x86 Coco VMs Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 25/45] KVM: selftests: Create gmem fd before "regular" fd when adding memslot Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 26/45] KVM: selftests: Rename guest_memfd{,_offset} to gmem_{fd,offset} Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 27/45] KVM: selftests: Add support for mmap() on guest_memfd in core library Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 28/45] KVM: selftests: Add selftests global for guest memory attributes capability Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 29/45] KVM: selftests: Add helpers for calling ioctls on guest_memfd Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 30/45] KVM: selftests: Test basic single-page conversion flow Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 31/45] KVM: selftests: Test conversion flow when INIT_SHARED Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 32/45] KVM: selftests: Test conversion precision in guest_memfd Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 33/45] KVM: selftests: Test conversion before allocation Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 34/45] KVM: selftests: Convert with allocated folios in different layouts Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 35/45] KVM: selftests: Test that truncation does not change shared/private status Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 36/45] KVM: selftests: Test that shared/private status is consistent across processes Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 37/45] KVM: selftests: Add helpers to pin pages with CONFIG_GUP_TEST Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 38/45] KVM: selftests: Test conversion with elevated page refcount Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 39/45] KVM: selftests: Reset shared memory after hole-punching Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 40/45] KVM: selftests: Provide function to look up guest_memfd details from gpa Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 41/45] KVM: selftests: Provide common function to set memory attributes Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 42/45] KVM: selftests: Make TEST_EXPECT_SIGBUS thread-safe Ackerley Tng via B4 Relay
2026-08-31  0:25 ` [PATCH v12 43/45] KVM: selftests: Set up page size and alignment independently for guest_memfd Ackerley Tng via B4 Relay
2026-09-01 11:03   ` Fuad Tabba
2026-08-31  0:25 ` [PATCH v12 44/45] KVM: selftests: Update private_mem_conversions_test for in-place conversions Ackerley Tng via B4 Relay
2026-09-01 11:11   ` Fuad Tabba
2026-08-31  0:25 ` [PATCH v12 45/45] KVM: selftests: Update private memory exits test to work with per-gmem attributes Ackerley Tng via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox