lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230123173748.1734238-6-shr@devkernel.io>
Date:   Mon, 23 Jan 2023 09:37:33 -0800
From:   Stefan Roesch <shr@...kernel.io>
To:     linux-mm@...ck.org
Cc:     shr@...kernel.io, linux-doc@...r.kernel.org,
        linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
        linux-kselftest@...r.kernel.org, linux-trace-kernel@...r.kernel.org
Subject: [RESEND RFC PATCH v1 05/20] mm: support disabling of ksm for a process

This adds the ability to disable ksm for a process if ksm has been
enabled for the process.

Signed-off-by: Stefan Roesch <shr@...kernel.io>
---
 mm/ksm.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/mm/ksm.c b/mm/ksm.c
index 967eda719fab..5fa6b46dfa3b 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -2588,6 +2588,27 @@ int __ksm_enter(struct mm_struct *mm, int flag)
 	return 0;
 }
 
+static void unmerge_vmas(struct mm_struct *mm)
+{
+	struct vm_area_struct *vma;
+	struct vma_iterator vmi;
+
+	vma_iter_init(&vmi, mm, 0);
+
+	mmap_read_lock(mm);
+	for_each_vma(vmi, vma) {
+		if (vma->vm_flags & VM_MERGEABLE) {
+			unsigned long flags = vma->vm_flags;
+
+			if (ksm_madvise(vma, vma->vm_start, vma->vm_end, MADV_UNMERGEABLE, &flags))
+				continue;
+
+			vma->vm_flags = flags;
+		}
+	}
+	mmap_read_unlock(mm);
+}
+
 void __ksm_exit(struct mm_struct *mm, int flag)
 {
 	struct ksm_mm_slot *mm_slot;
@@ -2595,8 +2616,10 @@ void __ksm_exit(struct mm_struct *mm, int flag)
 	int easy_to_free = 0;
 
 	if (!(current->flags & PF_EXITING) && flag == MMF_VM_MERGE_ANY &&
-	    test_bit(MMF_VM_MERGE_ANY, &mm->flags))
+		test_bit(MMF_VM_MERGE_ANY, &mm->flags)) {
 		clear_bit(MMF_VM_MERGE_ANY, &mm->flags);
+		unmerge_vmas(mm);
+	}
 
 	/*
 	 * This process is exiting: if it's straightforward (as is the
-- 
2.30.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ