Skip to contentSkip to conversation

revert-mm-init_mlocked_on_free_v3.patch removed from -mm tree

merged mm-hotfixes-stable Andrew Morton 1 participant 1 message Jun 15, 2024

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: Revert "mm: init_mlocked_on_free_v3"
has been removed from the -mm tree. Its filename was
revert-mm-init_mlocked_on_free_v3.patch

This patch was dropped because it was merged into the mm-hotfixes-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: David Hildenbrand <[email protected]>
Subject: Revert "mm: init_mlocked_on_free_v3"
Date: Wed, 5 Jun 2024 11:17:10 +0200

There was insufficient review and no agreement that this is the right approach.

There are serious flaws with the implementation that make processes using mlock() not even work with simple fork() [1] and we get reliable crashes when rebooting.

Further, simply because we might be unmapping a single PTE of a large mlocked folio, we shouldn't zero out the whole folio.

... especially because the code can also *corrupt* urelated memory because

	kernel_init_pages(page, folio_nr_pages(folio));

Could end up writing outside of the actual folio if we work with a tail page.

Let's revert it. Once there is agreement that this is the right approach, the issues were fixed and there was reasonable review and proper testing, we can consider it again.

[1] https://lkml.kernel.org/r/[email protected]

---

 Documentation/admin-guide/kernel-parameters.txt |    6 -
 include/linux/mm.h                              |    9 --
 mm/internal.h                                   |    1 
 mm/memory.c                                     |    6 -
 mm/mm_init.c                                    |   43 ++------------
 mm/page_alloc.c                                 |    2 
 security/Kconfig.hardening                      |   15 ----
 7 files changed, 9 insertions(+), 73 deletions(-)
Documentation/admin-guide/kernel-parameters.txt renamed from Documentation/admin-guide/kernel-parameters.txt~revert-mm-init_mlocked_on_free_v3 +0 -6
@@ -2192,12 +2192,6 @@
 			Format: 0 | 1
 			Default set by CONFIG_INIT_ON_FREE_DEFAULT_ON.
 
-	init_mlocked_on_free=	[MM] Fill freed userspace memory with zeroes if
-				it was mlock'ed and not explicitly munlock'ed
-				afterwards.
-				Format: 0 | 1
-				Default set by CONFIG_INIT_MLOCKED_ON_FREE_DEFAULT_ON
-
 	init_pkru=	[X86] Specify the default memory protection keys rights
 			register contents for all processes.  0x55555554 by
 			default (disallow access to all but pkey 0).  Can
include/linux/mm.h renamed from include/linux/mm.h~revert-mm-init_mlocked_on_free_v3 +1 -8
@@ -3776,14 +3776,7 @@ DECLARE_STATIC_KEY_MAYBE(CONFIG_INIT_ON_
 static inline bool want_init_on_free(void)
 {
 	return static_branch_maybe(CONFIG_INIT_ON_FREE_DEFAULT_ON,
-				&init_on_free);
-}
-
-DECLARE_STATIC_KEY_MAYBE(CONFIG_INIT_MLOCKED_ON_FREE_DEFAULT_ON, init_mlocked_on_free);
-static inline bool want_init_mlocked_on_free(void)
-{
-	return static_branch_maybe(CONFIG_INIT_MLOCKED_ON_FREE_DEFAULT_ON,
-				&init_mlocked_on_free);
+				   &init_on_free);
 }
 
 extern bool _debug_pagealloc_enabled_early;
mm/internal.h renamed from mm/internal.h~revert-mm-init_mlocked_on_free_v3 +0 -1
@@ -588,7 +588,6 @@ extern void __putback_isolated_page(stru
 extern void memblock_free_pages(struct page *page, unsigned long pfn,
 					unsigned int order);
 extern void __free_pages_core(struct page *page, unsigned int order);
-extern void kernel_init_pages(struct page *page, int numpages);
 
 /*
  * This will have no effect, other than possibly generating a warning, if the
mm/memory.c renamed from mm/memory.c~revert-mm-init_mlocked_on_free_v3 +0 -6
@@ -1507,12 +1507,6 @@ static __always_inline void zap_present_
 		if (unlikely(folio_mapcount(folio) < 0))
 			print_bad_pte(vma, addr, ptent, page);
 	}
-
-	if (want_init_mlocked_on_free() && folio_test_mlocked(folio) &&
-	    !delay_rmap && folio_test_anon(folio)) {
-		kernel_init_pages(page, folio_nr_pages(folio));
-	}
-
 	if (unlikely(__tlb_remove_folio_pages(tlb, page, nr, delay_rmap))) {
 		*force_flush = true;
 		*force_break = true;
mm/mm_init.c renamed from mm/mm_init.c~revert-mm-init_mlocked_on_free_v3 +7 -36

78 lines not on this page · raw message

mm/page_alloc.c renamed from mm/page_alloc.c~revert-mm-init_mlocked_on_free_v3 +1 -1
@@ -1016,7 +1016,7 @@ static inline bool should_skip_kasan_poi
 	return page_kasan_tag(page) == KASAN_TAG_KERNEL;
 }
 
-void kernel_init_pages(struct page *page, int numpages)
+static void kernel_init_pages(struct page *page, int numpages)
 {
 	int i;
 
security/Kconfig.hardening renamed from security/Kconfig.hardening~revert-mm-init_mlocked_on_free_v3 +0 -15
@@ -255,21 +255,6 @@ config INIT_ON_FREE_DEFAULT_ON
 	  touching "cold" memory areas. Most cases see 3-5% impact. Some
 	  synthetic workloads have measured as high as 8%.
 
-config INIT_MLOCKED_ON_FREE_DEFAULT_ON
-	bool "Enable mlocked memory zeroing on free"
-	depends on !KMSAN
-	help
-	  This config has the effect of setting "init_mlocked_on_free=1"
-	  on the kernel command line. If it is enabled, all mlocked process
-	  memory is zeroed when freed. This restriction to mlocked memory
-	  improves performance over "init_on_free" but can still be used to
-	  protect confidential data like key material from content exposures
-	  to other processes, as well as live forensics and cold boot attacks.
-	  Any non-mlocked memory is not cleared before it is reassigned. This
-	  configuration can be overwritten by setting "init_mlocked_on_free=0"
-	  on the command line. The "init_on_free" boot option takes
-	  precedence over "init_mlocked_on_free".
-
 config CC_HAS_ZERO_CALL_USED_REGS
 	def_bool $(cc-option,-fzero-call-used-regs=used-gpr)
 	# https://github.com/ClangBuiltLinux/linux/issues/1766

_

Patches currently in -mm which might be from [email protected] are

mm-memory-move-page_count-check-into-validate_page_before_insert.patch mm-memory-cleanly-support-zeropage-in-vm_insert_page-vm_map_pages-and-vmf_insert_mixed.patch mm-rmap-sanity-check-that-zeropages-are-not-passed-to-rmap.patch mm-update-_mapcount-and-page_type-documentation.patch mm-allow-reuse-of-the-lower-16-bit-of-the-page-type-with-an-actual-type.patch mm-zsmalloc-use-a-proper-page-type.patch mm-page_alloc-clear-pagebuddy-using-__clearpagebuddy-for-bad-pages.patch mm-filemap-reinitialize-folio-_mapcount-directly.patch mm-mm_init-initialize-page-_mapcount-directly-in-__init_single_page.patch fs-proc-task_mmu-indicate-pm_file-for-pmd-mapped-file-thp.patch fs-proc-task_mmu-dont-indicate-pm_mmap_exclusive-without-pm_present.patch fs-proc-task_mmu-properly-detect-pm_mmap_exclusive-per-page-of-pmd-mapped-thps.patch fs-proc-task_mmu-account-non-present-entries-as-maybe-shared-but-no-idea-how-often.patch fs-proc-move-page_mapcount-to-fs-proc-internalh.patch documentation-admin-guide-mm-pagemaprst-drop-using-pagemap-to-do-something-useful.patch mm-pass-meminit_context-to-__free_pages_core.patch mm-pass-meminit_context-to-__free_pages_core-fix.patch mm-pass-meminit_context-to-__free_pages_core-fix-2.patch mm-pass-meminit_context-to-__free_pages_core-fix-3.patch mm-memory_hotplug-initialize-memmap-of-zone_device-with-pageoffline-instead-of-pagereserved.patch mm-memory_hotplug-skip-adjust_managed_page_count-for-pageoffline-pages-when-offlining.patch mm-highmem-reimplement-totalhigh_pages-by-walking-zones.patch mm-highmem-reimplement-totalhigh_pages-by-walking-zones-fix.patch mm-highmem-make-nr_free_highpages-return-unsigned-long.patch