Skip to contentSkip to conversation

mm: don't overwrite mm->def_flags in do_mlockall()

PATCH In review Gerald Schaefer 2 participants 3 messages Feb 6, 2013 – Feb 7, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: don't overwrite mm->def_flags in do_mlockall()

With commit 8e72033 "thp: make MADV_HUGEPAGE check for mm->def_flags" the VM_NOHUGEPAGE flag may be set on s390 in mm->def_flags for certain processes, to prevent future thp mappings. This would be overwritten by do_mlockall(), which sets it back to 0 with an optional VM_LOCKED flag set.

To fix this, instead of overwriting mm->def_flags in do_mlockall(), only the VM_LOCKED flag should be set or cleared.

---
 mm/mlock.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
mm/mlock.c +3 -3
index f0b9ce5..c9bd528 100644
@@ -517,11 +517,11 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
 static int do_mlockall(int flags)
 {
 	struct vm_area_struct * vma, * prev = NULL;
-	unsigned int def_flags = 0;
 
 	if (flags & MCL_FUTURE)
-		def_flags = VM_LOCKED;
-	current->mm->def_flags = def_flags;
+		current->mm->def_flags |= VM_LOCKED;
+	else
+		current->mm->def_flags &= ~VM_LOCKED;
 	if (flags == MCL_FUTURE)
 		goto out;
 
Signature · 7 lines
1.7.12.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#1 lore raw
Quoted 8 lines · On Wed, 6 Feb 2013 16:49:34 +0100 Gerald Schaefer…

With commit 8e72033 "thp: make MADV_HUGEPAGE check for mm->def_flags" the VM_NOHUGEPAGE flag may be set on s390 in mm->def_flags for certain processes, to prevent future thp mappings. This would be overwritten by do_mlockall(), which sets it back to 0 with an optional VM_LOCKED flag set.

To fix this, instead of overwriting mm->def_flags in do_mlockall(), only the VM_LOCKED flag should be set or cleared.

What are the user-visible effects here? Looking at the 274023da1e8 changelog, I'm guessing that it might be pretty nasty - kvm breakage?

Quoted 6 lines
mm/mlock.c +0 -0
@@ -517,11 +517,11 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
 static int do_mlockall(int flags)
 {
 	struct vm_area_struct * vma, * prev = NULL;

mm/mlock.c SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len) · line 526

Quoted 10 lines
mm/mlock.c +3 -3
-	unsigned int def_flags = 0;
 
 	if (flags & MCL_FUTURE)
-		def_flags = VM_LOCKED;
-	current->mm->def_flags = def_flags;
+		current->mm->def_flags |= VM_LOCKED;
+	else
+		current->mm->def_flags &= ~VM_LOCKED;
 	if (flags == MCL_FUTURE)
 		goto out;

Michal sent an equivalent patch last month:
http://ozlabs.org/~akpm/mmotm/broken-out/mm-make-mlockall-preserve-flags-other-than-vm_locked-in-def_flags.patch.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 9 lines · On Wed, 6 Feb 2013 12:51:03 -0800 Andrew Morton <[email protected]>…
Quoted 6 lines · On Wed, 6 Feb 2013 16:49:34 +0100 Gerald Schaefer…

With commit 8e72033 "thp: make MADV_HUGEPAGE check for mm->def_flags" the VM_NOHUGEPAGE flag may be set on s390 in mm->def_flags for certain processes, to prevent future thp mappings. This would be overwritten by do_mlockall(), which sets it back to 0 with an optional VM_LOCKED flag set.

Quoted 5 lines
Quoted 2 lines

To fix this, instead of overwriting mm->def_flags in do_mlockall(), only the VM_LOCKED flag should be set or cleared.

What are the user-visible effects here? Looking at the 274023da1e8 changelog, I'm guessing that it might be pretty nasty - kvm breakage?

Yes, though at the moment there should be no mlockall()/munlockall() involved with kvm/qemu. So currently no user-visible effects, Vivek found this while reading the do_mlockall() code, but it might be a good idea to add this to stable.
Could you add a "Cc: [email protected] # v3.7+"?

Thanks,
Gerald

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>