Skip to content

Direct Map Removal Support for guest_memfd

Kalyazin, Nikita bpf kvm kvmarm linux-doc linux-fsdevel linux-kselftest linux-mm linux-pm linux-riscv linux-s390 lkml loongarch 5 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v12 Latest16 patches 26 repliesIn review
  2. v1116 patches 23 repliesSuperseded
  3. v1015 patches 19 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v913 patches48 repliesSuperseded
v813 patches12 repliesSuperseded

Changes in v12 from the cover letter

- Ackerley/Sashiko: fix previously missed __set_pages_* argument update in __kernel_map_pages (patch 1)
- David: disallow large folios in folio_zap_direct_map (patch 2)
- David/Sashiko: check for folio_is_zone_device if mapping is NULL in gup_fast_folio_allowed (patch 4)
- Ackerley/Sashiko: kvm_arch_gmem_supports_no_direct_map to return false for SEV-SNP (patch 8).
- David: replace a redundant check for GUEST_MEMFD_FLAG_NO_DIRECT_MAP with a WARN_ON_ONCE (patch 10)
- David: assert the folio is locked when zapping direct map (patch 10)
- Ackerley/Sashiko: reorder operations to "zap then prepare" and "invalidate then restore" (patch 10)

Patches in v12 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/16set_memory: set_direct_map_* to take addressarch/arm64/include/asm/set_memory.h arch/arm64/mm/pageattr.c arch/loongarch/include/asm/set_memory.h +12 more+91 -816 replies
2/16set_memory: add folio_{zap,restore}_direct_map helpersinclude/linux/set_memory.h mm/memory.c+58 -03 replies
3/16mm/secretmem: make use of folio_{zap,restore}_direct_mapmm/secretmem.c+2 -60 replies
4/16mm/gup: drop secretmem optimization from gup_fast_folio_allowedmm/gup.c+6 -110 replies
5/16mm/gup: drop local variable in gup_fast_folio_allowedmm/gup.c+12 -110 replies
6/16mm: introduce AS_NO_DIRECT_MAPinclude/linux/pagemap.h include/linux/secretmem.h lib/buildid.c +3 more+29 -320 replies
7/16KVM: guest_memfd: Add stub for kvm_arch_gmem_invalidateinclude/linux/kvm_host.h virt/kvm/guest_memfd.c+2 -40 replies
8/16KVM: x86: define kvm_arch_gmem_supports_no_direct_map()arch/x86/include/asm/kvm_host.h arch/x86/kvm/x86.c include/linux/kvm_host.h+22 -00 replies
9/16KVM: arm64: define kvm_arch_gmem_supports_no_direct_map()arch/arm64/include/asm/kvm_host.h+13 -03 replies
10/16KVM: guest_memfd: Add flag to remove from direct mapDocumentation/virt/kvm/api.rst include/linux/kvm_host.h include/uapi/linux/kvm.h +1 more+83 -138 replies
11/16KVM: selftests: load elf via bounce buffertools/testing/selftests/kvm/include/test_util.h tools/testing/selftests/kvm/lib/elf.c tools/testing/selftests/kvm/lib/io.c+28 -40 replies
12/16KVM: selftests: set KVM_MEM_GUEST_MEMFD in vm_mem_add() if guest_memfd != -1tools/testing/selftests/kvm/lib/kvm_util.c+14 -100 replies
13/16KVM: selftests: Add guest_memfd based vm_mem_backing_src_typestools/testing/selftests/kvm/include/kvm_util.h tools/testing/selftests/kvm/include/test_util.h tools/testing/selftests/kvm/lib/kvm_util.c +1 more+65 -291 reply
14/16KVM: selftests: cover GUEST_MEMFD_FLAG_NO_DIRECT_MAP in existing selfteststools/testing/selftests/kvm/guest_memfd_test.c tools/testing/selftests/kvm/x86/private_mem_conversions_test.c+20 -40 replies
15/16KVM: selftests: stuff vm_mem_backing_src_type into vm_shapetools/testing/selftests/kvm/include/kvm_util.h tools/testing/selftests/kvm/lib/kvm_util.c tools/testing/selftests/kvm/lib/x86/sev.c +1 more+13 -100 replies
16/16KVM: selftests: Test guest execution from direct map removed gmemtools/testing/selftests/kvm/set_memory_region_test.c+48 -40 replies

Reviews trailers per patch

9 of 16 patches have a Reviewed-by or Acked-by.

PatchDavid Hildenbrand (Arm)Ackerley TngVlastimil BabkaMike Rapoport (Microsoft)
1/16A-b
2/16A-b
3/16A-b R-b
4/16A-b A-b
5/16A-b
6/16A-b R-b A-b A-b
7/16A-b R-b A-b
8/16R-b R-b
9/16R-b
10/16
11/16
12/16
13/16
14/16
15/16
16/16

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v12 thread

Cover letter [PATCH v12 00/16] Direct Map Removal Support for guest_memfd

From: Nikita Kalyazin <[email protected]>

[ based on kvm/next ]

Unmapping virtual machine guest memory from the host kernel's direct map is a successful mitigation against Spectre-style transient execution
issues: if the kernel page tables do not contain entries pointing to guest memory, then any attempted speculative read through the direct map will necessarily be blocked by the MMU before any observable microarchitectural side-effects happen. This means that Spectre-gadgets and similar cannot be used to target virtual machine memory. Roughly 60% of speculative execution issues fall into this category [1, Table 1].

This patch series extends guest_memfd with the ability to remove its memory from the host kernel's direct map, to be able to attain the above protection for KVM guests running inside guest_memfd.

Additionally, a Firecracker branch with support for these VMs can be found on GitHub [2].

For more details, please refer to the v5 cover letter. No substantial changes in design have taken place since.

See also related write() syscall support in guest_memfd [3] where the interoperation between the two features is described.

Changes since v11:
- Ackerley/Sashiko: fix previously missed __set_pages_* argument update in __kernel_map_pages (patch 1)
- David: disallow large folios in folio_zap_direct_map (patch 2)
- David/Sashiko: check for folio_is_zone_device if mapping is NULL in gup_fast_folio_allowed (patch 4)
- Ackerley/Sashiko: kvm_arch_gmem_supports_no_direct_map to return false for SEV-SNP (patch 8).
- David: replace a redundant check for GUEST_MEMFD_FLAG_NO_DIRECT_MAP with a WARN_ON_ONCE (patch 10)
- David: assert the folio is locked when zapping direct map (patch 10)
- Ackerley/Sashiko: reorder operations to "zap then prepare" and "invalidate then restore" (patch 10)

v11: https://lore.kernel.org/kvm/[email protected]
v10: https://lore.kernel.org/kvm/[email protected]
v9: https://lore.kernel.org/kvm/[email protected]
v8: https://lore.kernel.org/kvm/[email protected]
v7: https://lore.kernel.org/kvm/[email protected]
v6: https://lore.kernel.org/kvm/[email protected]
v5: https://lore.kernel.org/kvm/[email protected]
v4: https://lore.kernel.org/kvm/[email protected]
RFCv3: https://lore.kernel.org/kvm/[email protected]
RFCv2: https://lore.kernel.org/kvm/[email protected]
RFCv1: https://lore.kernel.org/kvm/[email protected]

[1] https://download.vusec.net/papers/quarantine_raid23.pdf
[2] https://github.com/firecracker-microvm/firecracker/tree/feature/secret-hiding
[3] https://lore.kernel.org/kvm/[email protected]

Nikita Kalyazin (4):
set_memory: set_direct_map_* to take address
set_memory: add folio_{zap,restore}_direct_map helpers mm/secretmem: make use of folio_{zap,restore}_direct_map mm/gup: drop local variable in gup_fast_folio_allowed

Patrick Roy (12):
mm/gup: drop secretmem optimization from gup_fast_folio_allowed
mm: introduce AS_NO_DIRECT_MAP
KVM: guest_memfd: Add stub for kvm_arch_gmem_invalidate
KVM: x86: define kvm_arch_gmem_supports_no_direct_map()
KVM: arm64: define kvm_arch_gmem_supports_no_direct_map()
KVM: guest_memfd: Add flag to remove from direct map
KVM: selftests: load elf via bounce buffer
KVM: selftests: set KVM_MEM_GUEST_MEMFD in vm_mem_add() if guest_memfd

    != -1

KVM: selftests: Add guest_memfd based vm_mem_backing_src_types
KVM: selftests: cover GUEST_MEMFD_FLAG_NO_DIRECT_MAP in existing
selftests
KVM: selftests: stuff vm_mem_backing_src_type into vm_shape
KVM: selftests: Test guest execution from direct map removed gmem

 Documentation/virt/kvm/api.rst                | 21 +++---
 arch/arm64/include/asm/kvm_host.h             | 13 ++++
 arch/arm64/include/asm/set_memory.h           |  7 +-
 arch/arm64/mm/pageattr.c                      | 19 +++--
 arch/loongarch/include/asm/set_memory.h       |  7 +-
 arch/loongarch/mm/pageattr.c                  | 25 +++----
 arch/riscv/include/asm/set_memory.h           |  7 +-
 arch/riscv/mm/pageattr.c                      | 17 +++--
 arch/s390/include/asm/set_memory.h            |  7 +-
 arch/s390/mm/pageattr.c                       | 13 ++--
 arch/x86/include/asm/kvm_host.h               |  6 ++
 arch/x86/include/asm/set_memory.h             |  7 +-
 arch/x86/kvm/x86.c                            |  7 ++
 arch/x86/mm/pat/set_memory.c                  | 27 +++----
 include/linux/kvm_host.h                      | 14 ++++
 include/linux/pagemap.h                       | 16 ++++
 include/linux/secretmem.h                     | 18 -----
 include/linux/set_memory.h                    | 22 +++++-
 include/uapi/linux/kvm.h                      |  1 +
 kernel/power/snapshot.c                       |  4 +-
 lib/buildid.c                                 |  8 +-
 mm/execmem.c                                  |  6 +-
 mm/gup.c                                      | 47 ++++++------
 mm/memory.c                                   | 45 +++++++++++
 mm/mlock.c                                    |  2 +-
 mm/secretmem.c                                | 18 ++---
 mm/vmalloc.c                                  | 11 ++-
 .../testing/selftests/kvm/guest_memfd_test.c  | 17 ++++-
 .../testing/selftests/kvm/include/kvm_util.h  | 37 ++++++---
 .../testing/selftests/kvm/include/test_util.h |  8 ++
 tools/testing/selftests/kvm/lib/elf.c         |  8 +-
 tools/testing/selftests/kvm/lib/io.c          | 23 ++++++
 tools/testing/selftests/kvm/lib/kvm_util.c    | 59 ++++++++-------
 tools/testing/selftests/kvm/lib/test_util.c   |  8 ++
 tools/testing/selftests/kvm/lib/x86/sev.c     |  1 +
 .../selftests/kvm/pre_fault_memory_test.c     |  1 +
 .../selftests/kvm/set_memory_region_test.c    | 52 ++++++++++++-
 .../kvm/x86/private_mem_conversions_test.c    |  7 +-
 virt/kvm/guest_memfd.c                        | 75 +++++++++++++++++--
 39 files changed, 489 insertions(+), 202 deletions(-)

base-commit: 24f9515de8778410e4b84c85b196c9850d2c1e18

Signature · 1 line
2.50.1