All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/18] change mmap_sem taken for write killable
@ 2016-02-29 13:26 ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner

Hi,
this is a follow up work for oom_reaper [1]. As the async OOM killing
depends on oom_sem for read we would really appreciate if a holder for
write stood in the way. This patchset is changing many of down_write
calls to be killable to help those cases when the writer is blocked and
waiting for readers to release the lock and so help __oom_reap_task to
process the oom victim.

Most of the patches are really trivial because the lock is help from a
shallow syscall paths where we can return EINTR trivially. Others seem
to be easy as well as the callers are already handling fatal errors and
bail and return to userspace which should be sufficient to handle the
failure gracefully. I am not familiar with all those code paths so a
deeper review is really appreciated.

As this work is touching more areas which are not directly connected I
have tried to keep the CC list as small as possible and people who I
believed would be familiar are CCed only to the specific patches (all
should have received the cover though).

This patchset is based on linux-next and it depends on down_write_killable
for rw_semaphores posted recently [2].

I haven't covered all the mmap_write(mm->mmap_sem) instances here

$ git grep "down_write(.*\<mmap_sem\>)" next/master | wc -l
102
$ git grep "down_write(.*\<mmap_sem\>)" | wc -l
66

I have tried to cover those which should be relatively easy to review in
this series because this alone should be a nice improvement. Other places
can be changed on top.

Any feedback is highly appreciated.

---
[1] http://lkml.kernel.org/r/1452094975-551-1-git-send-email-mhocko@kernel.org
[2] http://lkml.kernel.org/r/1456750705-7141-1-git-send-email-mhocko@kernel.org

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

* [PATCH 0/18] change mmap_sem taken for write killable
@ 2016-02-29 13:26 ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

Hi,
this is a follow up work for oom_reaper [1]. As the async OOM killing
depends on oom_sem for read we would really appreciate if a holder for
write stood in the way. This patchset is changing many of down_write
calls to be killable to help those cases when the writer is blocked and
waiting for readers to release the lock and so help __oom_reap_task to
process the oom victim.

Most of the patches are really trivial because the lock is help from a
shallow syscall paths where we can return EINTR trivially. Others seem
to be easy as well as the callers are already handling fatal errors and
bail and return to userspace which should be sufficient to handle the
failure gracefully. I am not familiar with all those code paths so a
deeper review is really appreciated.

As this work is touching more areas which are not directly connected I
have tried to keep the CC list as small as possible and people who I
believed would be familiar are CCed only to the specific patches (all
should have received the cover though).

This patchset is based on linux-next and it depends on down_write_killable
for rw_semaphores posted recently [2].

I haven't covered all the mmap_write(mm->mmap_sem) instances here

$ git grep "down_write(.*\<mmap_sem\>)" next/master | wc -l
102
$ git grep "down_write(.*\<mmap_sem\>)" | wc -l
66

I have tried to cover those which should be relatively easy to review in
this series because this alone should be a nice improvement. Other places
can be changed on top.

Any feedback is highly appreciated.

---
[1] http://lkml.kernel.org/r/1452094975-551-1-git-send-email-mhocko@kernel.org
[2] http://lkml.kernel.org/r/1456750705-7141-1-git-send-email-mhocko@kernel.org

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

* [PATCH 0/18] change mmap_sem taken for write killable
@ 2016-02-29 13:26 ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner

Hi,
this is a follow up work for oom_reaper [1]. As the async OOM killing
depends on oom_sem for read we would really appreciate if a holder for
write stood in the way. This patchset is changing many of down_write
calls to be killable to help those cases when the writer is blocked and
waiting for readers to release the lock and so help __oom_reap_task to
process the oom victim.

Most of the patches are really trivial because the lock is help from a
shallow syscall paths where we can return EINTR trivially. Others seem
to be easy as well as the callers are already handling fatal errors and
bail and return to userspace which should be sufficient to handle the
failure gracefully. I am not familiar with all those code paths so a
deeper review is really appreciated.

As this work is touching more areas which are not directly connected I
have tried to keep the CC list as small as possible and people who I
believed would be familiar are CCed only to the specific patches (all
should have received the cover though).

This patchset is based on linux-next and it depends on down_write_killable
for rw_semaphores posted recently [2].

I haven't covered all the mmap_write(mm->mmap_sem) instances here

$ git grep "down_write(.*\<mmap_sem\>)" next/master | wc -l
102
$ git grep "down_write(.*\<mmap_sem\>)" | wc -l
66

I have tried to cover those which should be relatively easy to review in
this series because this alone should be a nice improvement. Other places
can be changed on top.

Any feedback is highly appreciated.

---
[1] http://lkml.kernel.org/r/1452094975-551-1-git-send-email-mhocko@kernel.org
[2] http://lkml.kernel.org/r/1456750705-7141-1-git-send-email-mhocko@kernel.org

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

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

* [PATCH 01/18] mm: Make mmap_sem for write waits killable for mm syscalls
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

This is the first step in making mmap_sem write holders killable. It
focuses on the trivial ones which are taking the lock early after
entering the syscall and they are not changing state before.

Therefore it is very easy to change them to use down_write_killable
and immediately return with -EINTR. This will allow the waiter to
pass away without blocking the mmap_sem which might be required to
make a forward progress. E.g. the oom reaper will need the lock for
reading to dismantle the OOM victim address space.

The only tricky function in this patch is vm_mmap_pgoff which has many
call sites via vm_mmap. To reduce the risk keep vm_mmap with the
original non-killable semantic for now.

vm_munmap callers do not bother checking the return value so open code
it into the munmap syscall path for now for simplicity.

Cc: Mel Gorman <mgorman@suse.de>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 mm/internal.h |  5 +++--
 mm/madvise.c  |  8 +++++---
 mm/mlock.c    | 16 ++++++++++------
 mm/mmap.c     | 27 +++++++++++++++++++++++----
 mm/mprotect.c |  3 ++-
 mm/mremap.c   |  3 ++-
 mm/nommu.c    |  2 +-
 mm/util.c     | 12 +++++++++---
 8 files changed, 55 insertions(+), 21 deletions(-)

diff --git a/mm/internal.h b/mm/internal.h
index 72bbce3efc36..26576cb3247e 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -444,9 +444,10 @@ extern u64 hwpoison_filter_flags_value;
 extern u64 hwpoison_filter_memcg;
 extern u32 hwpoison_filter_enable;
 
-extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
+extern unsigned long  __must_check vm_mmap_pgoff(struct file *, unsigned long,
         unsigned long, unsigned long,
-        unsigned long, unsigned long);
+        unsigned long, unsigned long,
+        bool);
 
 extern void set_pageblock_order(void);
 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
diff --git a/mm/madvise.c b/mm/madvise.c
index a50ac1885d09..b1809a409a77 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -764,10 +764,12 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
 		return error;
 
 	write = madvise_need_mmap_write(behavior);
-	if (write)
-		down_write(&current->mm->mmap_sem);
-	else
+	if (write) {
+		if (down_write_killable(&current->mm->mmap_sem))
+			return -EINTR;
+	} else {
 		down_read(&current->mm->mmap_sem);
+	}
 
 	blk_start_plug(&plug);
 
diff --git a/mm/mlock.c b/mm/mlock.c
index 96f001041928..ef8dc9f395c4 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -617,7 +617,7 @@ static int apply_vma_lock_flags(unsigned long start, size_t len,
 	return error;
 }
 
-static int do_mlock(unsigned long start, size_t len, vm_flags_t flags)
+static __must_check int do_mlock(unsigned long start, size_t len, vm_flags_t flags)
 {
 	unsigned long locked;
 	unsigned long lock_limit;
@@ -635,7 +635,8 @@ static int do_mlock(unsigned long start, size_t len, vm_flags_t flags)
 	lock_limit >>= PAGE_SHIFT;
 	locked = len >> PAGE_SHIFT;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 
 	locked += current->mm->locked_vm;
 
@@ -678,7 +679,8 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
 	len = PAGE_ALIGN(len + (offset_in_page(start)));
 	start &= PAGE_MASK;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 	ret = apply_vma_lock_flags(start, len, 0);
 	up_write(&current->mm->mmap_sem);
 
@@ -748,9 +750,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
 	lock_limit = rlimit(RLIMIT_MEMLOCK);
 	lock_limit >>= PAGE_SHIFT;
 
-	ret = -ENOMEM;
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 
+	ret = -ENOMEM;
 	if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
 	    capable(CAP_IPC_LOCK))
 		ret = apply_mlockall_flags(flags);
@@ -765,7 +768,8 @@ SYSCALL_DEFINE0(munlockall)
 {
 	int ret;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 	ret = apply_mlockall_flags(0);
 	up_write(&current->mm->mmap_sem);
 	return ret;
diff --git a/mm/mmap.c b/mm/mmap.c
index b1e30132eb52..a8ea76c22bb6 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -182,7 +182,8 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
 	unsigned long min_brk;
 	bool populate;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 #ifdef CONFIG_COMPAT_BRK
 	/*
@@ -1336,7 +1337,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
 
 	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
 
-	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff);
+	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff, true);
 out_fput:
 	if (file)
 		fput(file);
@@ -2498,6 +2499,10 @@ int vm_munmap(unsigned long start, size_t len)
 	int ret;
 	struct mm_struct *mm = current->mm;
 
+	/*
+	 * XXX convert to down_write_killable as soon as all users are able
+	 * to handle the error.
+	 */
 	down_write(&mm->mmap_sem);
 	ret = do_munmap(mm, start, len);
 	up_write(&mm->mmap_sem);
@@ -2507,8 +2512,15 @@ EXPORT_SYMBOL(vm_munmap);
 
 SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
 {
+	int ret;
+	struct mm_struct *mm = current->mm;
+
 	profile_munmap(addr);
-	return vm_munmap(addr, len);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+	ret = do_munmap(mm, addr, len);
+	up_write(&mm->mmap_sem);
+	return ret;
 }
 
 
@@ -2541,7 +2553,9 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
 	if (pgoff + (size >> PAGE_SHIFT) < pgoff)
 		return ret;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	vma = find_vma(mm, start);
 
 	if (!vma || !(vma->vm_flags & VM_SHARED))
@@ -2706,6 +2720,11 @@ unsigned long vm_brk(unsigned long addr, unsigned long len)
 	unsigned long ret;
 	bool populate;
 
+	/*
+	 * XXX not all users are chcecking the return value, convert
+	 * to down_write_killable after they are able to cope with
+	 * error
+	 */
 	down_write(&mm->mmap_sem);
 	ret = do_brk(addr, len);
 	populate = ((mm->def_flags & VM_LOCKED) != 0);
diff --git a/mm/mprotect.c b/mm/mprotect.c
index bf44caea638b..ccd0044f74bd 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -378,7 +378,8 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
 
 	reqprot = prot;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 
 	vma = find_vma(current->mm, start);
 	error = -ENOMEM;
diff --git a/mm/mremap.c b/mm/mremap.c
index 3fa0a467df66..b635ce0ddfb4 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -502,7 +502,8 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
 	if (!new_len)
 		return ret;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 
 	if (flags & MREMAP_FIXED) {
 		ret = mremap_to(addr, old_len, new_addr, new_len,
diff --git a/mm/nommu.c b/mm/nommu.c
index de8b6b6580c1..50b1d32921c2 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1448,7 +1448,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
 
 	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
 
-	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff);
+	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff, true);
 
 	if (file)
 		fput(file);
diff --git a/mm/util.c b/mm/util.c
index 3bf315fefeb6..98eeec742254 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(get_user_pages_fast);
 
 unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 	unsigned long len, unsigned long prot,
-	unsigned long flag, unsigned long pgoff)
+	unsigned long flag, unsigned long pgoff, bool killable)
 {
 	unsigned long ret;
 	struct mm_struct *mm = current->mm;
@@ -327,7 +327,12 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 
 	ret = security_mmap_file(file, prot, flag);
 	if (!ret) {
-		down_write(&mm->mmap_sem);
+		if (killable) {
+			if (down_write_killable(&mm->mmap_sem))
+				return -EINTR;
+		} else {
+			down_write(&mm->mmap_sem);
+		}
 		ret = do_mmap_pgoff(file, addr, len, prot, flag, pgoff,
 				    &populate);
 		up_write(&mm->mmap_sem);
@@ -337,6 +342,7 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 	return ret;
 }
 
+/* XXX are all callers checking an error */
 unsigned long vm_mmap(struct file *file, unsigned long addr,
 	unsigned long len, unsigned long prot,
 	unsigned long flag, unsigned long offset)
@@ -346,7 +352,7 @@ unsigned long vm_mmap(struct file *file, unsigned long addr,
 	if (unlikely(offset_in_page(offset)))
 		return -EINVAL;
 
-	return vm_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
+	return vm_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT, false);
 }
 EXPORT_SYMBOL(vm_mmap);
 
-- 
2.7.0

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

* [PATCH 01/18] mm: Make mmap_sem for write waits killable for mm syscalls
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

This is the first step in making mmap_sem write holders killable. It
focuses on the trivial ones which are taking the lock early after
entering the syscall and they are not changing state before.

Therefore it is very easy to change them to use down_write_killable
and immediately return with -EINTR. This will allow the waiter to
pass away without blocking the mmap_sem which might be required to
make a forward progress. E.g. the oom reaper will need the lock for
reading to dismantle the OOM victim address space.

The only tricky function in this patch is vm_mmap_pgoff which has many
call sites via vm_mmap. To reduce the risk keep vm_mmap with the
original non-killable semantic for now.

vm_munmap callers do not bother checking the return value so open code
it into the munmap syscall path for now for simplicity.

Cc: Mel Gorman <mgorman@suse.de>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 mm/internal.h |  5 +++--
 mm/madvise.c  |  8 +++++---
 mm/mlock.c    | 16 ++++++++++------
 mm/mmap.c     | 27 +++++++++++++++++++++++----
 mm/mprotect.c |  3 ++-
 mm/mremap.c   |  3 ++-
 mm/nommu.c    |  2 +-
 mm/util.c     | 12 +++++++++---
 8 files changed, 55 insertions(+), 21 deletions(-)

diff --git a/mm/internal.h b/mm/internal.h
index 72bbce3efc36..26576cb3247e 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -444,9 +444,10 @@ extern u64 hwpoison_filter_flags_value;
 extern u64 hwpoison_filter_memcg;
 extern u32 hwpoison_filter_enable;
 
-extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
+extern unsigned long  __must_check vm_mmap_pgoff(struct file *, unsigned long,
         unsigned long, unsigned long,
-        unsigned long, unsigned long);
+        unsigned long, unsigned long,
+        bool);
 
 extern void set_pageblock_order(void);
 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
diff --git a/mm/madvise.c b/mm/madvise.c
index a50ac1885d09..b1809a409a77 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -764,10 +764,12 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
 		return error;
 
 	write = madvise_need_mmap_write(behavior);
-	if (write)
-		down_write(&current->mm->mmap_sem);
-	else
+	if (write) {
+		if (down_write_killable(&current->mm->mmap_sem))
+			return -EINTR;
+	} else {
 		down_read(&current->mm->mmap_sem);
+	}
 
 	blk_start_plug(&plug);
 
diff --git a/mm/mlock.c b/mm/mlock.c
index 96f001041928..ef8dc9f395c4 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -617,7 +617,7 @@ static int apply_vma_lock_flags(unsigned long start, size_t len,
 	return error;
 }
 
-static int do_mlock(unsigned long start, size_t len, vm_flags_t flags)
+static __must_check int do_mlock(unsigned long start, size_t len, vm_flags_t flags)
 {
 	unsigned long locked;
 	unsigned long lock_limit;
@@ -635,7 +635,8 @@ static int do_mlock(unsigned long start, size_t len, vm_flags_t flags)
 	lock_limit >>= PAGE_SHIFT;
 	locked = len >> PAGE_SHIFT;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 
 	locked += current->mm->locked_vm;
 
@@ -678,7 +679,8 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
 	len = PAGE_ALIGN(len + (offset_in_page(start)));
 	start &= PAGE_MASK;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 	ret = apply_vma_lock_flags(start, len, 0);
 	up_write(&current->mm->mmap_sem);
 
@@ -748,9 +750,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
 	lock_limit = rlimit(RLIMIT_MEMLOCK);
 	lock_limit >>= PAGE_SHIFT;
 
-	ret = -ENOMEM;
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 
+	ret = -ENOMEM;
 	if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
 	    capable(CAP_IPC_LOCK))
 		ret = apply_mlockall_flags(flags);
@@ -765,7 +768,8 @@ SYSCALL_DEFINE0(munlockall)
 {
 	int ret;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 	ret = apply_mlockall_flags(0);
 	up_write(&current->mm->mmap_sem);
 	return ret;
diff --git a/mm/mmap.c b/mm/mmap.c
index b1e30132eb52..a8ea76c22bb6 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -182,7 +182,8 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
 	unsigned long min_brk;
 	bool populate;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 #ifdef CONFIG_COMPAT_BRK
 	/*
@@ -1336,7 +1337,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
 
 	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
 
-	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff);
+	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff, true);
 out_fput:
 	if (file)
 		fput(file);
@@ -2498,6 +2499,10 @@ int vm_munmap(unsigned long start, size_t len)
 	int ret;
 	struct mm_struct *mm = current->mm;
 
+	/*
+	 * XXX convert to down_write_killable as soon as all users are able
+	 * to handle the error.
+	 */
 	down_write(&mm->mmap_sem);
 	ret = do_munmap(mm, start, len);
 	up_write(&mm->mmap_sem);
@@ -2507,8 +2512,15 @@ EXPORT_SYMBOL(vm_munmap);
 
 SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
 {
+	int ret;
+	struct mm_struct *mm = current->mm;
+
 	profile_munmap(addr);
-	return vm_munmap(addr, len);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+	ret = do_munmap(mm, addr, len);
+	up_write(&mm->mmap_sem);
+	return ret;
 }
 
 
@@ -2541,7 +2553,9 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
 	if (pgoff + (size >> PAGE_SHIFT) < pgoff)
 		return ret;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	vma = find_vma(mm, start);
 
 	if (!vma || !(vma->vm_flags & VM_SHARED))
@@ -2706,6 +2720,11 @@ unsigned long vm_brk(unsigned long addr, unsigned long len)
 	unsigned long ret;
 	bool populate;
 
+	/*
+	 * XXX not all users are chcecking the return value, convert
+	 * to down_write_killable after they are able to cope with
+	 * error
+	 */
 	down_write(&mm->mmap_sem);
 	ret = do_brk(addr, len);
 	populate = ((mm->def_flags & VM_LOCKED) != 0);
diff --git a/mm/mprotect.c b/mm/mprotect.c
index bf44caea638b..ccd0044f74bd 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -378,7 +378,8 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
 
 	reqprot = prot;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 
 	vma = find_vma(current->mm, start);
 	error = -ENOMEM;
diff --git a/mm/mremap.c b/mm/mremap.c
index 3fa0a467df66..b635ce0ddfb4 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -502,7 +502,8 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
 	if (!new_len)
 		return ret;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 
 	if (flags & MREMAP_FIXED) {
 		ret = mremap_to(addr, old_len, new_addr, new_len,
diff --git a/mm/nommu.c b/mm/nommu.c
index de8b6b6580c1..50b1d32921c2 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1448,7 +1448,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
 
 	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
 
-	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff);
+	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff, true);
 
 	if (file)
 		fput(file);
diff --git a/mm/util.c b/mm/util.c
index 3bf315fefeb6..98eeec742254 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(get_user_pages_fast);
 
 unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 	unsigned long len, unsigned long prot,
-	unsigned long flag, unsigned long pgoff)
+	unsigned long flag, unsigned long pgoff, bool killable)
 {
 	unsigned long ret;
 	struct mm_struct *mm = current->mm;
@@ -327,7 +327,12 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 
 	ret = security_mmap_file(file, prot, flag);
 	if (!ret) {
-		down_write(&mm->mmap_sem);
+		if (killable) {
+			if (down_write_killable(&mm->mmap_sem))
+				return -EINTR;
+		} else {
+			down_write(&mm->mmap_sem);
+		}
 		ret = do_mmap_pgoff(file, addr, len, prot, flag, pgoff,
 				    &populate);
 		up_write(&mm->mmap_sem);
@@ -337,6 +342,7 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 	return ret;
 }
 
+/* XXX are all callers checking an error */
 unsigned long vm_mmap(struct file *file, unsigned long addr,
 	unsigned long len, unsigned long prot,
 	unsigned long flag, unsigned long offset)
@@ -346,7 +352,7 @@ unsigned long vm_mmap(struct file *file, unsigned long addr,
 	if (unlikely(offset_in_page(offset)))
 		return -EINVAL;
 
-	return vm_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
+	return vm_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT, false);
 }
 EXPORT_SYMBOL(vm_mmap);
 
-- 
2.7.0

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

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

* [PATCH 01/18] mm: Make mmap_sem for write waits killable for mm syscalls
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

This is the first step in making mmap_sem write holders killable. It
focuses on the trivial ones which are taking the lock early after
entering the syscall and they are not changing state before.

Therefore it is very easy to change them to use down_write_killable
and immediately return with -EINTR. This will allow the waiter to
pass away without blocking the mmap_sem which might be required to
make a forward progress. E.g. the oom reaper will need the lock for
reading to dismantle the OOM victim address space.

The only tricky function in this patch is vm_mmap_pgoff which has many
call sites via vm_mmap. To reduce the risk keep vm_mmap with the
original non-killable semantic for now.

vm_munmap callers do not bother checking the return value so open code
it into the munmap syscall path for now for simplicity.

Cc: Mel Gorman <mgorman@suse.de>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 mm/internal.h |  5 +++--
 mm/madvise.c  |  8 +++++---
 mm/mlock.c    | 16 ++++++++++------
 mm/mmap.c     | 27 +++++++++++++++++++++++----
 mm/mprotect.c |  3 ++-
 mm/mremap.c   |  3 ++-
 mm/nommu.c    |  2 +-
 mm/util.c     | 12 +++++++++---
 8 files changed, 55 insertions(+), 21 deletions(-)

diff --git a/mm/internal.h b/mm/internal.h
index 72bbce3efc36..26576cb3247e 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -444,9 +444,10 @@ extern u64 hwpoison_filter_flags_value;
 extern u64 hwpoison_filter_memcg;
 extern u32 hwpoison_filter_enable;
 
-extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
+extern unsigned long  __must_check vm_mmap_pgoff(struct file *, unsigned long,
         unsigned long, unsigned long,
-        unsigned long, unsigned long);
+        unsigned long, unsigned long,
+        bool);
 
 extern void set_pageblock_order(void);
 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
diff --git a/mm/madvise.c b/mm/madvise.c
index a50ac1885d09..b1809a409a77 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -764,10 +764,12 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
 		return error;
 
 	write = madvise_need_mmap_write(behavior);
-	if (write)
-		down_write(&current->mm->mmap_sem);
-	else
+	if (write) {
+		if (down_write_killable(&current->mm->mmap_sem))
+			return -EINTR;
+	} else {
 		down_read(&current->mm->mmap_sem);
+	}
 
 	blk_start_plug(&plug);
 
diff --git a/mm/mlock.c b/mm/mlock.c
index 96f001041928..ef8dc9f395c4 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -617,7 +617,7 @@ static int apply_vma_lock_flags(unsigned long start, size_t len,
 	return error;
 }
 
-static int do_mlock(unsigned long start, size_t len, vm_flags_t flags)
+static __must_check int do_mlock(unsigned long start, size_t len, vm_flags_t flags)
 {
 	unsigned long locked;
 	unsigned long lock_limit;
@@ -635,7 +635,8 @@ static int do_mlock(unsigned long start, size_t len, vm_flags_t flags)
 	lock_limit >>= PAGE_SHIFT;
 	locked = len >> PAGE_SHIFT;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 
 	locked += current->mm->locked_vm;
 
@@ -678,7 +679,8 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
 	len = PAGE_ALIGN(len + (offset_in_page(start)));
 	start &= PAGE_MASK;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 	ret = apply_vma_lock_flags(start, len, 0);
 	up_write(&current->mm->mmap_sem);
 
@@ -748,9 +750,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
 	lock_limit = rlimit(RLIMIT_MEMLOCK);
 	lock_limit >>= PAGE_SHIFT;
 
-	ret = -ENOMEM;
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 
+	ret = -ENOMEM;
 	if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
 	    capable(CAP_IPC_LOCK))
 		ret = apply_mlockall_flags(flags);
@@ -765,7 +768,8 @@ SYSCALL_DEFINE0(munlockall)
 {
 	int ret;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 	ret = apply_mlockall_flags(0);
 	up_write(&current->mm->mmap_sem);
 	return ret;
diff --git a/mm/mmap.c b/mm/mmap.c
index b1e30132eb52..a8ea76c22bb6 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -182,7 +182,8 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
 	unsigned long min_brk;
 	bool populate;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 #ifdef CONFIG_COMPAT_BRK
 	/*
@@ -1336,7 +1337,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
 
 	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
 
-	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff);
+	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff, true);
 out_fput:
 	if (file)
 		fput(file);
@@ -2498,6 +2499,10 @@ int vm_munmap(unsigned long start, size_t len)
 	int ret;
 	struct mm_struct *mm = current->mm;
 
+	/*
+	 * XXX convert to down_write_killable as soon as all users are able
+	 * to handle the error.
+	 */
 	down_write(&mm->mmap_sem);
 	ret = do_munmap(mm, start, len);
 	up_write(&mm->mmap_sem);
@@ -2507,8 +2512,15 @@ EXPORT_SYMBOL(vm_munmap);
 
 SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
 {
+	int ret;
+	struct mm_struct *mm = current->mm;
+
 	profile_munmap(addr);
-	return vm_munmap(addr, len);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+	ret = do_munmap(mm, addr, len);
+	up_write(&mm->mmap_sem);
+	return ret;
 }
 
 
@@ -2541,7 +2553,9 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
 	if (pgoff + (size >> PAGE_SHIFT) < pgoff)
 		return ret;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	vma = find_vma(mm, start);
 
 	if (!vma || !(vma->vm_flags & VM_SHARED))
@@ -2706,6 +2720,11 @@ unsigned long vm_brk(unsigned long addr, unsigned long len)
 	unsigned long ret;
 	bool populate;
 
+	/*
+	 * XXX not all users are chcecking the return value, convert
+	 * to down_write_killable after they are able to cope with
+	 * error
+	 */
 	down_write(&mm->mmap_sem);
 	ret = do_brk(addr, len);
 	populate = ((mm->def_flags & VM_LOCKED) != 0);
diff --git a/mm/mprotect.c b/mm/mprotect.c
index bf44caea638b..ccd0044f74bd 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -378,7 +378,8 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
 
 	reqprot = prot;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 
 	vma = find_vma(current->mm, start);
 	error = -ENOMEM;
diff --git a/mm/mremap.c b/mm/mremap.c
index 3fa0a467df66..b635ce0ddfb4 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -502,7 +502,8 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
 	if (!new_len)
 		return ret;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem))
+		return -EINTR;
 
 	if (flags & MREMAP_FIXED) {
 		ret = mremap_to(addr, old_len, new_addr, new_len,
diff --git a/mm/nommu.c b/mm/nommu.c
index de8b6b6580c1..50b1d32921c2 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1448,7 +1448,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
 
 	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
 
-	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff);
+	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff, true);
 
 	if (file)
 		fput(file);
diff --git a/mm/util.c b/mm/util.c
index 3bf315fefeb6..98eeec742254 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(get_user_pages_fast);
 
 unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 	unsigned long len, unsigned long prot,
-	unsigned long flag, unsigned long pgoff)
+	unsigned long flag, unsigned long pgoff, bool killable)
 {
 	unsigned long ret;
 	struct mm_struct *mm = current->mm;
@@ -327,7 +327,12 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 
 	ret = security_mmap_file(file, prot, flag);
 	if (!ret) {
-		down_write(&mm->mmap_sem);
+		if (killable) {
+			if (down_write_killable(&mm->mmap_sem))
+				return -EINTR;
+		} else {
+			down_write(&mm->mmap_sem);
+		}
 		ret = do_mmap_pgoff(file, addr, len, prot, flag, pgoff,
 				    &populate);
 		up_write(&mm->mmap_sem);
@@ -337,6 +342,7 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 	return ret;
 }
 
+/* XXX are all callers checking an error */
 unsigned long vm_mmap(struct file *file, unsigned long addr,
 	unsigned long len, unsigned long prot,
 	unsigned long flag, unsigned long offset)
@@ -346,7 +352,7 @@ unsigned long vm_mmap(struct file *file, unsigned long addr,
 	if (unlikely(offset_in_page(offset)))
 		return -EINVAL;
 
-	return vm_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
+	return vm_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT, false);
 }
 EXPORT_SYMBOL(vm_mmap);
 
-- 
2.7.0

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

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

* [PATCH 02/18] mm: make vm_mmap killable
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Al Viro

From: Michal Hocko <mhocko@suse.com>

All the callers of vm_mmap seem to check for the failure already
and bail out in one way or another on the error which means that
we can change it to use killable version of vm_mmap_pgoff and return
-EINTR if the current task gets killed while waiting for mmap_sem.
This also means that vm_mmap_pgoff can be killable by default and
drop the additional parameter.

This will help in the OOM conditions when the oom victim might be stuck
waiting for the mmap_sem for write which in turn can block oom_reaper
which relies on the mmap_sem for read to make a forward progress
and reclaim the address space of the victim.

Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 include/linux/mm.h |  2 +-
 mm/internal.h      |  3 +--
 mm/mmap.c          |  2 +-
 mm/nommu.c         |  2 +-
 mm/util.c          | 13 ++++---------
 5 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8a84cf07da8c..4ee6a3561540 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2079,7 +2079,7 @@ static inline void mm_populate(unsigned long addr, unsigned long len) {}
 /* These take the mm semaphore themselves */
 extern unsigned long vm_brk(unsigned long, unsigned long);
 extern int vm_munmap(unsigned long, size_t);
-extern unsigned long vm_mmap(struct file *, unsigned long,
+extern unsigned long __must_check vm_mmap(struct file *, unsigned long,
         unsigned long, unsigned long,
         unsigned long, unsigned long);
 
diff --git a/mm/internal.h b/mm/internal.h
index 26576cb3247e..d8d4c32bfce4 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -446,8 +446,7 @@ extern u32 hwpoison_filter_enable;
 
 extern unsigned long  __must_check vm_mmap_pgoff(struct file *, unsigned long,
         unsigned long, unsigned long,
-        unsigned long, unsigned long,
-        bool);
+        unsigned long, unsigned long);
 
 extern void set_pageblock_order(void);
 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
diff --git a/mm/mmap.c b/mm/mmap.c
index a8ea76c22bb6..4e1f852a52ff 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1337,7 +1337,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
 
 	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
 
-	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff, true);
+	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff);
 out_fput:
 	if (file)
 		fput(file);
diff --git a/mm/nommu.c b/mm/nommu.c
index 50b1d32921c2..de8b6b6580c1 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1448,7 +1448,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
 
 	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
 
-	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff, true);
+	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff);
 
 	if (file)
 		fput(file);
diff --git a/mm/util.c b/mm/util.c
index 98eeec742254..0e383fe48145 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(get_user_pages_fast);
 
 unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 	unsigned long len, unsigned long prot,
-	unsigned long flag, unsigned long pgoff, bool killable)
+	unsigned long flag, unsigned long pgoff)
 {
 	unsigned long ret;
 	struct mm_struct *mm = current->mm;
@@ -327,12 +327,8 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 
 	ret = security_mmap_file(file, prot, flag);
 	if (!ret) {
-		if (killable) {
-			if (down_write_killable(&mm->mmap_sem))
-				return -EINTR;
-		} else {
-			down_write(&mm->mmap_sem);
-		}
+		if (down_write_killable(&mm->mmap_sem))
+			return -EINTR;
 		ret = do_mmap_pgoff(file, addr, len, prot, flag, pgoff,
 				    &populate);
 		up_write(&mm->mmap_sem);
@@ -342,7 +338,6 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 	return ret;
 }
 
-/* XXX are all callers checking an error */
 unsigned long vm_mmap(struct file *file, unsigned long addr,
 	unsigned long len, unsigned long prot,
 	unsigned long flag, unsigned long offset)
@@ -352,7 +347,7 @@ unsigned long vm_mmap(struct file *file, unsigned long addr,
 	if (unlikely(offset_in_page(offset)))
 		return -EINVAL;
 
-	return vm_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT, false);
+	return vm_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
 }
 EXPORT_SYMBOL(vm_mmap);
 
-- 
2.7.0

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

* [PATCH 02/18] mm: make vm_mmap killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

All the callers of vm_mmap seem to check for the failure already
and bail out in one way or another on the error which means that
we can change it to use killable version of vm_mmap_pgoff and return
-EINTR if the current task gets killed while waiting for mmap_sem.
This also means that vm_mmap_pgoff can be killable by default and
drop the additional parameter.

This will help in the OOM conditions when the oom victim might be stuck
waiting for the mmap_sem for write which in turn can block oom_reaper
which relies on the mmap_sem for read to make a forward progress
and reclaim the address space of the victim.

Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 include/linux/mm.h |  2 +-
 mm/internal.h      |  3 +--
 mm/mmap.c          |  2 +-
 mm/nommu.c         |  2 +-
 mm/util.c          | 13 ++++---------
 5 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8a84cf07da8c..4ee6a3561540 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2079,7 +2079,7 @@ static inline void mm_populate(unsigned long addr, unsigned long len) {}
 /* These take the mm semaphore themselves */
 extern unsigned long vm_brk(unsigned long, unsigned long);
 extern int vm_munmap(unsigned long, size_t);
-extern unsigned long vm_mmap(struct file *, unsigned long,
+extern unsigned long __must_check vm_mmap(struct file *, unsigned long,
         unsigned long, unsigned long,
         unsigned long, unsigned long);
 
diff --git a/mm/internal.h b/mm/internal.h
index 26576cb3247e..d8d4c32bfce4 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -446,8 +446,7 @@ extern u32 hwpoison_filter_enable;
 
 extern unsigned long  __must_check vm_mmap_pgoff(struct file *, unsigned long,
         unsigned long, unsigned long,
-        unsigned long, unsigned long,
-        bool);
+        unsigned long, unsigned long);
 
 extern void set_pageblock_order(void);
 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
diff --git a/mm/mmap.c b/mm/mmap.c
index a8ea76c22bb6..4e1f852a52ff 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1337,7 +1337,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
 
 	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
 
-	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff, true);
+	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff);
 out_fput:
 	if (file)
 		fput(file);
diff --git a/mm/nommu.c b/mm/nommu.c
index 50b1d32921c2..de8b6b6580c1 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1448,7 +1448,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
 
 	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
 
-	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff, true);
+	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff);
 
 	if (file)
 		fput(file);
diff --git a/mm/util.c b/mm/util.c
index 98eeec742254..0e383fe48145 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(get_user_pages_fast);
 
 unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 	unsigned long len, unsigned long prot,
-	unsigned long flag, unsigned long pgoff, bool killable)
+	unsigned long flag, unsigned long pgoff)
 {
 	unsigned long ret;
 	struct mm_struct *mm = current->mm;
@@ -327,12 +327,8 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 
 	ret = security_mmap_file(file, prot, flag);
 	if (!ret) {
-		if (killable) {
-			if (down_write_killable(&mm->mmap_sem))
-				return -EINTR;
-		} else {
-			down_write(&mm->mmap_sem);
-		}
+		if (down_write_killable(&mm->mmap_sem))
+			return -EINTR;
 		ret = do_mmap_pgoff(file, addr, len, prot, flag, pgoff,
 				    &populate);
 		up_write(&mm->mmap_sem);
@@ -342,7 +338,6 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 	return ret;
 }
 
-/* XXX are all callers checking an error */
 unsigned long vm_mmap(struct file *file, unsigned long addr,
 	unsigned long len, unsigned long prot,
 	unsigned long flag, unsigned long offset)
@@ -352,7 +347,7 @@ unsigned long vm_mmap(struct file *file, unsigned long addr,
 	if (unlikely(offset_in_page(offset)))
 		return -EINVAL;
 
-	return vm_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT, false);
+	return vm_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
 }
 EXPORT_SYMBOL(vm_mmap);
 
-- 
2.7.0

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

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

* [PATCH 02/18] mm: make vm_mmap killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Al Viro

From: Michal Hocko <mhocko@suse.com>

All the callers of vm_mmap seem to check for the failure already
and bail out in one way or another on the error which means that
we can change it to use killable version of vm_mmap_pgoff and return
-EINTR if the current task gets killed while waiting for mmap_sem.
This also means that vm_mmap_pgoff can be killable by default and
drop the additional parameter.

This will help in the OOM conditions when the oom victim might be stuck
waiting for the mmap_sem for write which in turn can block oom_reaper
which relies on the mmap_sem for read to make a forward progress
and reclaim the address space of the victim.

Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 include/linux/mm.h |  2 +-
 mm/internal.h      |  3 +--
 mm/mmap.c          |  2 +-
 mm/nommu.c         |  2 +-
 mm/util.c          | 13 ++++---------
 5 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8a84cf07da8c..4ee6a3561540 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2079,7 +2079,7 @@ static inline void mm_populate(unsigned long addr, unsigned long len) {}
 /* These take the mm semaphore themselves */
 extern unsigned long vm_brk(unsigned long, unsigned long);
 extern int vm_munmap(unsigned long, size_t);
-extern unsigned long vm_mmap(struct file *, unsigned long,
+extern unsigned long __must_check vm_mmap(struct file *, unsigned long,
         unsigned long, unsigned long,
         unsigned long, unsigned long);
 
diff --git a/mm/internal.h b/mm/internal.h
index 26576cb3247e..d8d4c32bfce4 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -446,8 +446,7 @@ extern u32 hwpoison_filter_enable;
 
 extern unsigned long  __must_check vm_mmap_pgoff(struct file *, unsigned long,
         unsigned long, unsigned long,
-        unsigned long, unsigned long,
-        bool);
+        unsigned long, unsigned long);
 
 extern void set_pageblock_order(void);
 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
diff --git a/mm/mmap.c b/mm/mmap.c
index a8ea76c22bb6..4e1f852a52ff 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1337,7 +1337,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
 
 	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
 
-	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff, true);
+	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff);
 out_fput:
 	if (file)
 		fput(file);
diff --git a/mm/nommu.c b/mm/nommu.c
index 50b1d32921c2..de8b6b6580c1 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -1448,7 +1448,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
 
 	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
 
-	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff, true);
+	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff);
 
 	if (file)
 		fput(file);
diff --git a/mm/util.c b/mm/util.c
index 98eeec742254..0e383fe48145 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(get_user_pages_fast);
 
 unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 	unsigned long len, unsigned long prot,
-	unsigned long flag, unsigned long pgoff, bool killable)
+	unsigned long flag, unsigned long pgoff)
 {
 	unsigned long ret;
 	struct mm_struct *mm = current->mm;
@@ -327,12 +327,8 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 
 	ret = security_mmap_file(file, prot, flag);
 	if (!ret) {
-		if (killable) {
-			if (down_write_killable(&mm->mmap_sem))
-				return -EINTR;
-		} else {
-			down_write(&mm->mmap_sem);
-		}
+		if (down_write_killable(&mm->mmap_sem))
+			return -EINTR;
 		ret = do_mmap_pgoff(file, addr, len, prot, flag, pgoff,
 				    &populate);
 		up_write(&mm->mmap_sem);
@@ -342,7 +338,6 @@ unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
 	return ret;
 }
 
-/* XXX are all callers checking an error */
 unsigned long vm_mmap(struct file *file, unsigned long addr,
 	unsigned long len, unsigned long prot,
 	unsigned long flag, unsigned long offset)
@@ -352,7 +347,7 @@ unsigned long vm_mmap(struct file *file, unsigned long addr,
 	if (unlikely(offset_in_page(offset)))
 		return -EINVAL;
 
-	return vm_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT, false);
+	return vm_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
 }
 EXPORT_SYMBOL(vm_mmap);
 
-- 
2.7.0

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

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

* [PATCH 03/18] mm: make vm_munmap killable
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

From: Michal Hocko <mhocko@suse.com>

Almost all current users of vm_munmap are ignoring the return value
and so they do not handle potential error. This means that some VMAs
might stay behind. This patch doesn't try to solve those potential
problems. Quite contrary it adds a new failure mode by using
down_write_killable in vm_munmap. This should be safer than other
failure modes, though, because the process is guaranteed to die
as soon as it leaves the kernel and exit_mmap will clean the whole
address space.

This will help in the OOM conditions when the oom victim might be stuck
waiting for the mmap_sem for write which in turn can block oom_reaper
which relies on the mmap_sem for read to make a forward progress and
reclaim the address space of the victim.

Cc: Oleg Nesterov <oleg@redhat.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 mm/mmap.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index 4e1f852a52ff..5d33c841e3a2 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2499,11 +2499,9 @@ int vm_munmap(unsigned long start, size_t len)
 	int ret;
 	struct mm_struct *mm = current->mm;
 
-	/*
-	 * XXX convert to down_write_killable as soon as all users are able
-	 * to handle the error.
-	 */
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	ret = do_munmap(mm, start, len);
 	up_write(&mm->mmap_sem);
 	return ret;
-- 
2.7.0

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

* [PATCH 03/18] mm: make vm_munmap killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

Almost all current users of vm_munmap are ignoring the return value
and so they do not handle potential error. This means that some VMAs
might stay behind. This patch doesn't try to solve those potential
problems. Quite contrary it adds a new failure mode by using
down_write_killable in vm_munmap. This should be safer than other
failure modes, though, because the process is guaranteed to die
as soon as it leaves the kernel and exit_mmap will clean the whole
address space.

This will help in the OOM conditions when the oom victim might be stuck
waiting for the mmap_sem for write which in turn can block oom_reaper
which relies on the mmap_sem for read to make a forward progress and
reclaim the address space of the victim.

Cc: Oleg Nesterov <oleg@redhat.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 mm/mmap.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index 4e1f852a52ff..5d33c841e3a2 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2499,11 +2499,9 @@ int vm_munmap(unsigned long start, size_t len)
 	int ret;
 	struct mm_struct *mm = current->mm;
 
-	/*
-	 * XXX convert to down_write_killable as soon as all users are able
-	 * to handle the error.
-	 */
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	ret = do_munmap(mm, start, len);
 	up_write(&mm->mmap_sem);
 	return ret;
-- 
2.7.0

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

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

* [PATCH 03/18] mm: make vm_munmap killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

From: Michal Hocko <mhocko@suse.com>

Almost all current users of vm_munmap are ignoring the return value
and so they do not handle potential error. This means that some VMAs
might stay behind. This patch doesn't try to solve those potential
problems. Quite contrary it adds a new failure mode by using
down_write_killable in vm_munmap. This should be safer than other
failure modes, though, because the process is guaranteed to die
as soon as it leaves the kernel and exit_mmap will clean the whole
address space.

This will help in the OOM conditions when the oom victim might be stuck
waiting for the mmap_sem for write which in turn can block oom_reaper
which relies on the mmap_sem for read to make a forward progress and
reclaim the address space of the victim.

Cc: Oleg Nesterov <oleg@redhat.com>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 mm/mmap.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index 4e1f852a52ff..5d33c841e3a2 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2499,11 +2499,9 @@ int vm_munmap(unsigned long start, size_t len)
 	int ret;
 	struct mm_struct *mm = current->mm;
 
-	/*
-	 * XXX convert to down_write_killable as soon as all users are able
-	 * to handle the error.
-	 */
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	ret = do_munmap(mm, start, len);
 	up_write(&mm->mmap_sem);
 	return ret;
-- 
2.7.0

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

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

* [PATCH 04/18] mm, aout: handle vm_brk failures
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Ingo Molnar, Alexander Viro

From: Michal Hocko <mhocko@suse.com>

vm_brk is allowed to fail but load_aout_binary simply ignores the error
and happily continues. I haven't noticed any problem from that in real
life but later patches will make the failure more likely because
vm_brk will become killable (resp. mmap_sem for write waiting will become
killable) so we should be more careful now.

The error handling should be quite straightforward because there are
calls to vm_mmap which check the error properly already. The only
notable exception is set_brk which is called after beyond_if label.
But nothing indicates that we cannot move it above set_binfmt as the two
do not depend on each other and fail before we do set_binfmt and alter
reference counting.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 arch/x86/ia32/ia32_aout.c | 22 +++++++++++++++-------
 fs/binfmt_aout.c          |  9 +++++++--
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
index ae6aad1d24f7..f5e737ff0022 100644
--- a/arch/x86/ia32/ia32_aout.c
+++ b/arch/x86/ia32/ia32_aout.c
@@ -116,13 +116,13 @@ static struct linux_binfmt aout_format = {
 	.min_coredump	= PAGE_SIZE
 };
 
-static void set_brk(unsigned long start, unsigned long end)
+static unsigned long set_brk(unsigned long start, unsigned long end)
 {
 	start = PAGE_ALIGN(start);
 	end = PAGE_ALIGN(end);
 	if (end <= start)
-		return;
-	vm_brk(start, end - start);
+		return start;
+	return vm_brk(start, end - start);
 }
 
 #ifdef CONFIG_COREDUMP
@@ -349,7 +349,10 @@ static int load_aout_binary(struct linux_binprm *bprm)
 #endif
 
 		if (!bprm->file->f_op->mmap || (fd_offset & ~PAGE_MASK) != 0) {
-			vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
+			error = vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
+			if (IS_ERR_VALUE(error))
+				return error;
+
 			read_code(bprm->file, N_TXTADDR(ex), fd_offset,
 					ex.a_text+ex.a_data);
 			goto beyond_if;
@@ -372,10 +375,13 @@ static int load_aout_binary(struct linux_binprm *bprm)
 		if (error != N_DATADDR(ex))
 			return error;
 	}
+
 beyond_if:
-	set_binfmt(&aout_format);
+	error = set_brk(current->mm->start_brk, current->mm->brk);
+	if (IS_ERR_VALUE(error))
+		return error;
 
-	set_brk(current->mm->start_brk, current->mm->brk);
+	set_binfmt(&aout_format);
 
 	current->mm->start_stack =
 		(unsigned long)create_aout_tables((char __user *)bprm->p, bprm);
@@ -434,7 +440,9 @@ static int load_aout_library(struct file *file)
 			error_time = jiffies;
 		}
 #endif
-		vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
+		retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
+		if (IS_ERR_VALUE(retval))
+			goto out;
 
 		read_code(file, start_addr, N_TXTOFF(ex),
 			  ex.a_text + ex.a_data);
diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
index 4c556680fa74..5fb075f05706 100644
--- a/fs/binfmt_aout.c
+++ b/fs/binfmt_aout.c
@@ -297,7 +297,10 @@ static int load_aout_binary(struct linux_binprm * bprm)
 		}
 
 		if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) {
-			vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
+			error = vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
+			if (IS_ERR_VALUE(error))
+				return error;
+
 			read_code(bprm->file, N_TXTADDR(ex), fd_offset,
 				  ex.a_text + ex.a_data);
 			goto beyond_if;
@@ -378,7 +381,9 @@ static int load_aout_library(struct file *file)
 			       "N_TXTOFF is not page aligned. Please convert library: %pD\n",
 			       file);
 		}
-		vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
+		retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
+		if (IS_ERR_VALUE(retval))
+			goto out;
 		
 		read_code(file, start_addr, N_TXTOFF(ex),
 			  ex.a_text + ex.a_data);
-- 
2.7.0

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

* [PATCH 04/18] mm, aout: handle vm_brk failures
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

vm_brk is allowed to fail but load_aout_binary simply ignores the error
and happily continues. I haven't noticed any problem from that in real
life but later patches will make the failure more likely because
vm_brk will become killable (resp. mmap_sem for write waiting will become
killable) so we should be more careful now.

The error handling should be quite straightforward because there are
calls to vm_mmap which check the error properly already. The only
notable exception is set_brk which is called after beyond_if label.
But nothing indicates that we cannot move it above set_binfmt as the two
do not depend on each other and fail before we do set_binfmt and alter
reference counting.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 arch/x86/ia32/ia32_aout.c | 22 +++++++++++++++-------
 fs/binfmt_aout.c          |  9 +++++++--
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
index ae6aad1d24f7..f5e737ff0022 100644
--- a/arch/x86/ia32/ia32_aout.c
+++ b/arch/x86/ia32/ia32_aout.c
@@ -116,13 +116,13 @@ static struct linux_binfmt aout_format = {
 	.min_coredump	= PAGE_SIZE
 };
 
-static void set_brk(unsigned long start, unsigned long end)
+static unsigned long set_brk(unsigned long start, unsigned long end)
 {
 	start = PAGE_ALIGN(start);
 	end = PAGE_ALIGN(end);
 	if (end <= start)
-		return;
-	vm_brk(start, end - start);
+		return start;
+	return vm_brk(start, end - start);
 }
 
 #ifdef CONFIG_COREDUMP
@@ -349,7 +349,10 @@ static int load_aout_binary(struct linux_binprm *bprm)
 #endif
 
 		if (!bprm->file->f_op->mmap || (fd_offset & ~PAGE_MASK) != 0) {
-			vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
+			error = vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
+			if (IS_ERR_VALUE(error))
+				return error;
+
 			read_code(bprm->file, N_TXTADDR(ex), fd_offset,
 					ex.a_text+ex.a_data);
 			goto beyond_if;
@@ -372,10 +375,13 @@ static int load_aout_binary(struct linux_binprm *bprm)
 		if (error != N_DATADDR(ex))
 			return error;
 	}
+
 beyond_if:
-	set_binfmt(&aout_format);
+	error = set_brk(current->mm->start_brk, current->mm->brk);
+	if (IS_ERR_VALUE(error))
+		return error;
 
-	set_brk(current->mm->start_brk, current->mm->brk);
+	set_binfmt(&aout_format);
 
 	current->mm->start_stack =
 		(unsigned long)create_aout_tables((char __user *)bprm->p, bprm);
@@ -434,7 +440,9 @@ static int load_aout_library(struct file *file)
 			error_time = jiffies;
 		}
 #endif
-		vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
+		retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
+		if (IS_ERR_VALUE(retval))
+			goto out;
 
 		read_code(file, start_addr, N_TXTOFF(ex),
 			  ex.a_text + ex.a_data);
diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
index 4c556680fa74..5fb075f05706 100644
--- a/fs/binfmt_aout.c
+++ b/fs/binfmt_aout.c
@@ -297,7 +297,10 @@ static int load_aout_binary(struct linux_binprm * bprm)
 		}
 
 		if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) {
-			vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
+			error = vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
+			if (IS_ERR_VALUE(error))
+				return error;
+
 			read_code(bprm->file, N_TXTADDR(ex), fd_offset,
 				  ex.a_text + ex.a_data);
 			goto beyond_if;
@@ -378,7 +381,9 @@ static int load_aout_library(struct file *file)
 			       "N_TXTOFF is not page aligned. Please convert library: %pD\n",
 			       file);
 		}
-		vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
+		retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
+		if (IS_ERR_VALUE(retval))
+			goto out;
 		
 		read_code(file, start_addr, N_TXTOFF(ex),
 			  ex.a_text + ex.a_data);
-- 
2.7.0

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

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

* [PATCH 04/18] mm, aout: handle vm_brk failures
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Ingo Molnar, Alexander Viro

From: Michal Hocko <mhocko@suse.com>

vm_brk is allowed to fail but load_aout_binary simply ignores the error
and happily continues. I haven't noticed any problem from that in real
life but later patches will make the failure more likely because
vm_brk will become killable (resp. mmap_sem for write waiting will become
killable) so we should be more careful now.

The error handling should be quite straightforward because there are
calls to vm_mmap which check the error properly already. The only
notable exception is set_brk which is called after beyond_if label.
But nothing indicates that we cannot move it above set_binfmt as the two
do not depend on each other and fail before we do set_binfmt and alter
reference counting.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 arch/x86/ia32/ia32_aout.c | 22 +++++++++++++++-------
 fs/binfmt_aout.c          |  9 +++++++--
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
index ae6aad1d24f7..f5e737ff0022 100644
--- a/arch/x86/ia32/ia32_aout.c
+++ b/arch/x86/ia32/ia32_aout.c
@@ -116,13 +116,13 @@ static struct linux_binfmt aout_format = {
 	.min_coredump	= PAGE_SIZE
 };
 
-static void set_brk(unsigned long start, unsigned long end)
+static unsigned long set_brk(unsigned long start, unsigned long end)
 {
 	start = PAGE_ALIGN(start);
 	end = PAGE_ALIGN(end);
 	if (end <= start)
-		return;
-	vm_brk(start, end - start);
+		return start;
+	return vm_brk(start, end - start);
 }
 
 #ifdef CONFIG_COREDUMP
@@ -349,7 +349,10 @@ static int load_aout_binary(struct linux_binprm *bprm)
 #endif
 
 		if (!bprm->file->f_op->mmap || (fd_offset & ~PAGE_MASK) != 0) {
-			vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
+			error = vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
+			if (IS_ERR_VALUE(error))
+				return error;
+
 			read_code(bprm->file, N_TXTADDR(ex), fd_offset,
 					ex.a_text+ex.a_data);
 			goto beyond_if;
@@ -372,10 +375,13 @@ static int load_aout_binary(struct linux_binprm *bprm)
 		if (error != N_DATADDR(ex))
 			return error;
 	}
+
 beyond_if:
-	set_binfmt(&aout_format);
+	error = set_brk(current->mm->start_brk, current->mm->brk);
+	if (IS_ERR_VALUE(error))
+		return error;
 
-	set_brk(current->mm->start_brk, current->mm->brk);
+	set_binfmt(&aout_format);
 
 	current->mm->start_stack =
 		(unsigned long)create_aout_tables((char __user *)bprm->p, bprm);
@@ -434,7 +440,9 @@ static int load_aout_library(struct file *file)
 			error_time = jiffies;
 		}
 #endif
-		vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
+		retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
+		if (IS_ERR_VALUE(retval))
+			goto out;
 
 		read_code(file, start_addr, N_TXTOFF(ex),
 			  ex.a_text + ex.a_data);
diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
index 4c556680fa74..5fb075f05706 100644
--- a/fs/binfmt_aout.c
+++ b/fs/binfmt_aout.c
@@ -297,7 +297,10 @@ static int load_aout_binary(struct linux_binprm * bprm)
 		}
 
 		if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) {
-			vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
+			error = vm_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
+			if (IS_ERR_VALUE(error))
+				return error;
+
 			read_code(bprm->file, N_TXTADDR(ex), fd_offset,
 				  ex.a_text + ex.a_data);
 			goto beyond_if;
@@ -378,7 +381,9 @@ static int load_aout_library(struct file *file)
 			       "N_TXTOFF is not page aligned. Please convert library: %pD\n",
 			       file);
 		}
-		vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
+		retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
+		if (IS_ERR_VALUE(retval))
+			goto out;
 		
 		read_code(file, start_addr, N_TXTOFF(ex),
 			  ex.a_text + ex.a_data);
-- 
2.7.0

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

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

* [PATCH 05/18] mm, elf: handle vm_brk error
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

From: Michal Hocko <mhocko@suse.com>

load_elf_library doesn't handle vm_brk failure although nothing really
indicates it cannot do that because the function is allowed to fail
due to vm_mmap failures already. This might be not a problem now
but later patch will make vm_brk killable (resp. mmap_sem for write
waiting will become killable) and so the failure will be more probable.

Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/binfmt_elf.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 7d914c67a9d0..2e45ae57ea88 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1176,8 +1176,11 @@ static int load_elf_library(struct file *file)
 	len = ELF_PAGESTART(eppnt->p_filesz + eppnt->p_vaddr +
 			    ELF_MIN_ALIGN - 1);
 	bss = eppnt->p_memsz + eppnt->p_vaddr;
-	if (bss > len)
-		vm_brk(len, bss - len);
+	if (bss > len) {
+		error = vm_brk(len, bss - len);
+		if (BAD_ADDR(error))
+			goto out_free_ph;
+	}
 	error = 0;
 
 out_free_ph:
-- 
2.7.0

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

* [PATCH 05/18] mm, elf: handle vm_brk error
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

load_elf_library doesn't handle vm_brk failure although nothing really
indicates it cannot do that because the function is allowed to fail
due to vm_mmap failures already. This might be not a problem now
but later patch will make vm_brk killable (resp. mmap_sem for write
waiting will become killable) and so the failure will be more probable.

Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/binfmt_elf.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 7d914c67a9d0..2e45ae57ea88 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1176,8 +1176,11 @@ static int load_elf_library(struct file *file)
 	len = ELF_PAGESTART(eppnt->p_filesz + eppnt->p_vaddr +
 			    ELF_MIN_ALIGN - 1);
 	bss = eppnt->p_memsz + eppnt->p_vaddr;
-	if (bss > len)
-		vm_brk(len, bss - len);
+	if (bss > len) {
+		error = vm_brk(len, bss - len);
+		if (BAD_ADDR(error))
+			goto out_free_ph;
+	}
 	error = 0;
 
 out_free_ph:
-- 
2.7.0

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

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

* [PATCH 05/18] mm, elf: handle vm_brk error
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

From: Michal Hocko <mhocko@suse.com>

load_elf_library doesn't handle vm_brk failure although nothing really
indicates it cannot do that because the function is allowed to fail
due to vm_mmap failures already. This might be not a problem now
but later patch will make vm_brk killable (resp. mmap_sem for write
waiting will become killable) and so the failure will be more probable.

Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/binfmt_elf.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 7d914c67a9d0..2e45ae57ea88 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1176,8 +1176,11 @@ static int load_elf_library(struct file *file)
 	len = ELF_PAGESTART(eppnt->p_filesz + eppnt->p_vaddr +
 			    ELF_MIN_ALIGN - 1);
 	bss = eppnt->p_memsz + eppnt->p_vaddr;
-	if (bss > len)
-		vm_brk(len, bss - len);
+	if (bss > len) {
+		error = vm_brk(len, bss - len);
+		if (BAD_ADDR(error))
+			goto out_free_ph;
+	}
 	error = 0;
 
 out_free_ph:
-- 
2.7.0

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

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

* [PATCH 06/18] mm: make vm_brk killable
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

Now that all the callers handle vm_brk failure we can change it
wait for mmap_sem killable to help oom_reaper to not get blocked
just because vm_brk gets blocked behind mmap_sem readers.

Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 include/linux/mm.h | 2 +-
 mm/mmap.c          | 9 +++------
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 4ee6a3561540..dccaea8682f2 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2077,7 +2077,7 @@ static inline void mm_populate(unsigned long addr, unsigned long len) {}
 #endif
 
 /* These take the mm semaphore themselves */
-extern unsigned long vm_brk(unsigned long, unsigned long);
+extern unsigned long __must_check vm_brk(unsigned long, unsigned long);
 extern int vm_munmap(unsigned long, size_t);
 extern unsigned long __must_check vm_mmap(struct file *, unsigned long,
         unsigned long, unsigned long,
diff --git a/mm/mmap.c b/mm/mmap.c
index 5d33c841e3a2..3f264fb14118 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2718,12 +2718,9 @@ unsigned long vm_brk(unsigned long addr, unsigned long len)
 	unsigned long ret;
 	bool populate;
 
-	/*
-	 * XXX not all users are chcecking the return value, convert
-	 * to down_write_killable after they are able to cope with
-	 * error
-	 */
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	ret = do_brk(addr, len);
 	populate = ((mm->def_flags & VM_LOCKED) != 0);
 	up_write(&mm->mmap_sem);
-- 
2.7.0

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

* [PATCH 06/18] mm: make vm_brk killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

Now that all the callers handle vm_brk failure we can change it
wait for mmap_sem killable to help oom_reaper to not get blocked
just because vm_brk gets blocked behind mmap_sem readers.

Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 include/linux/mm.h | 2 +-
 mm/mmap.c          | 9 +++------
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 4ee6a3561540..dccaea8682f2 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2077,7 +2077,7 @@ static inline void mm_populate(unsigned long addr, unsigned long len) {}
 #endif
 
 /* These take the mm semaphore themselves */
-extern unsigned long vm_brk(unsigned long, unsigned long);
+extern unsigned long __must_check vm_brk(unsigned long, unsigned long);
 extern int vm_munmap(unsigned long, size_t);
 extern unsigned long __must_check vm_mmap(struct file *, unsigned long,
         unsigned long, unsigned long,
diff --git a/mm/mmap.c b/mm/mmap.c
index 5d33c841e3a2..3f264fb14118 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2718,12 +2718,9 @@ unsigned long vm_brk(unsigned long addr, unsigned long len)
 	unsigned long ret;
 	bool populate;
 
-	/*
-	 * XXX not all users are chcecking the return value, convert
-	 * to down_write_killable after they are able to cope with
-	 * error
-	 */
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	ret = do_brk(addr, len);
 	populate = ((mm->def_flags & VM_LOCKED) != 0);
 	up_write(&mm->mmap_sem);
-- 
2.7.0

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

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

* [PATCH 06/18] mm: make vm_brk killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

Now that all the callers handle vm_brk failure we can change it
wait for mmap_sem killable to help oom_reaper to not get blocked
just because vm_brk gets blocked behind mmap_sem readers.

Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 include/linux/mm.h | 2 +-
 mm/mmap.c          | 9 +++------
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 4ee6a3561540..dccaea8682f2 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2077,7 +2077,7 @@ static inline void mm_populate(unsigned long addr, unsigned long len) {}
 #endif
 
 /* These take the mm semaphore themselves */
-extern unsigned long vm_brk(unsigned long, unsigned long);
+extern unsigned long __must_check vm_brk(unsigned long, unsigned long);
 extern int vm_munmap(unsigned long, size_t);
 extern unsigned long __must_check vm_mmap(struct file *, unsigned long,
         unsigned long, unsigned long,
diff --git a/mm/mmap.c b/mm/mmap.c
index 5d33c841e3a2..3f264fb14118 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2718,12 +2718,9 @@ unsigned long vm_brk(unsigned long addr, unsigned long len)
 	unsigned long ret;
 	bool populate;
 
-	/*
-	 * XXX not all users are chcecking the return value, convert
-	 * to down_write_killable after they are able to cope with
-	 * error
-	 */
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	ret = do_brk(addr, len);
 	populate = ((mm->def_flags & VM_LOCKED) != 0);
 	up_write(&mm->mmap_sem);
-- 
2.7.0

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

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

* [PATCH 07/18] mm, proc: make clear_refs killable
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

CLEAR_REFS_MM_HIWATER_RSS and CLEAR_REFS_SOFT_DIRTY are relying on
mmap_sem for write. If the waiting task gets killed by the oom killer
and it would operate on the current's mm it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely OOM
resolving. Wait for the lock in the killable mode and return with EINTR
if the task got killed while waiting. This will also expedite the return
to the userspace and do_exit even if the mm is remote.

Cc: Petr Cermak <petrcermak@chromium.org>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/proc/task_mmu.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 9df431642042..fc303fa1f5c0 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -1027,11 +1027,15 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
 		};
 
 		if (type == CLEAR_REFS_MM_HIWATER_RSS) {
+			if (down_write_killable(&mm->mmap_sem)) {
+				put_task_struct(task);
+				return -EINTR;
+			}
+
 			/*
 			 * Writing 5 to /proc/pid/clear_refs resets the peak
 			 * resident set size to this mm's current rss value.
 			 */
-			down_write(&mm->mmap_sem);
 			reset_mm_hiwater_rss(mm);
 			up_write(&mm->mmap_sem);
 			goto out_mm;
@@ -1043,7 +1047,10 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
 				if (!(vma->vm_flags & VM_SOFTDIRTY))
 					continue;
 				up_read(&mm->mmap_sem);
-				down_write(&mm->mmap_sem);
+				if (down_write_killable(&mm->mmap_sem)) {
+					put_task_struct(task);
+					return -EINTR;
+				}
 				for (vma = mm->mmap; vma; vma = vma->vm_next) {
 					vma->vm_flags &= ~VM_SOFTDIRTY;
 					vma_set_page_prot(vma);
-- 
2.7.0

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

* [PATCH 07/18] mm, proc: make clear_refs killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

CLEAR_REFS_MM_HIWATER_RSS and CLEAR_REFS_SOFT_DIRTY are relying on
mmap_sem for write. If the waiting task gets killed by the oom killer
and it would operate on the current's mm it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely OOM
resolving. Wait for the lock in the killable mode and return with EINTR
if the task got killed while waiting. This will also expedite the return
to the userspace and do_exit even if the mm is remote.

Cc: Petr Cermak <petrcermak@chromium.org>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/proc/task_mmu.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 9df431642042..fc303fa1f5c0 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -1027,11 +1027,15 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
 		};
 
 		if (type == CLEAR_REFS_MM_HIWATER_RSS) {
+			if (down_write_killable(&mm->mmap_sem)) {
+				put_task_struct(task);
+				return -EINTR;
+			}
+
 			/*
 			 * Writing 5 to /proc/pid/clear_refs resets the peak
 			 * resident set size to this mm's current rss value.
 			 */
-			down_write(&mm->mmap_sem);
 			reset_mm_hiwater_rss(mm);
 			up_write(&mm->mmap_sem);
 			goto out_mm;
@@ -1043,7 +1047,10 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
 				if (!(vma->vm_flags & VM_SOFTDIRTY))
 					continue;
 				up_read(&mm->mmap_sem);
-				down_write(&mm->mmap_sem);
+				if (down_write_killable(&mm->mmap_sem)) {
+					put_task_struct(task);
+					return -EINTR;
+				}
 				for (vma = mm->mmap; vma; vma = vma->vm_next) {
 					vma->vm_flags &= ~VM_SOFTDIRTY;
 					vma_set_page_prot(vma);
-- 
2.7.0

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

* [PATCH 07/18] mm, proc: make clear_refs killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

CLEAR_REFS_MM_HIWATER_RSS and CLEAR_REFS_SOFT_DIRTY are relying on
mmap_sem for write. If the waiting task gets killed by the oom killer
and it would operate on the current's mm it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely OOM
resolving. Wait for the lock in the killable mode and return with EINTR
if the task got killed while waiting. This will also expedite the return
to the userspace and do_exit even if the mm is remote.

Cc: Petr Cermak <petrcermak@chromium.org>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/proc/task_mmu.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 9df431642042..fc303fa1f5c0 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -1027,11 +1027,15 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
 		};
 
 		if (type == CLEAR_REFS_MM_HIWATER_RSS) {
+			if (down_write_killable(&mm->mmap_sem)) {
+				put_task_struct(task);
+				return -EINTR;
+			}
+
 			/*
 			 * Writing 5 to /proc/pid/clear_refs resets the peak
 			 * resident set size to this mm's current rss value.
 			 */
-			down_write(&mm->mmap_sem);
 			reset_mm_hiwater_rss(mm);
 			up_write(&mm->mmap_sem);
 			goto out_mm;
@@ -1043,7 +1047,10 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
 				if (!(vma->vm_flags & VM_SOFTDIRTY))
 					continue;
 				up_read(&mm->mmap_sem);
-				down_write(&mm->mmap_sem);
+				if (down_write_killable(&mm->mmap_sem)) {
+					put_task_struct(task);
+					return -EINTR;
+				}
 				for (vma = mm->mmap; vma; vma = vma->vm_next) {
 					vma->vm_flags &= ~VM_SOFTDIRTY;
 					vma_set_page_prot(vma);
-- 
2.7.0

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

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

* [PATCH 08/18] mm, fork: make dup_mmap wait for mmap_sem for write killable
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

dup_mmap needs to lock current's mm mmap_sem for write. If the waiting
task gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely OOM
resolving. Wait for the lock in the killable mode and return with EINTR
if the task got killed while waiting.

Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 kernel/fork.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index d277e83ed3e0..e064bc8453dc 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -413,7 +413,10 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
 	unsigned long charge;
 
 	uprobe_start_dup_mmap();
-	down_write(&oldmm->mmap_sem);
+	if (down_write_killable(&oldmm->mmap_sem)) {
+		uprobe_end_dup_mmap();
+		return -EINTR;
+	}
 	flush_cache_dup_mm(oldmm);
 	uprobe_dup_mmap(oldmm, mm);
 	/*
-- 
2.7.0

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

* [PATCH 08/18] mm, fork: make dup_mmap wait for mmap_sem for write killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

dup_mmap needs to lock current's mm mmap_sem for write. If the waiting
task gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely OOM
resolving. Wait for the lock in the killable mode and return with EINTR
if the task got killed while waiting.

Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 kernel/fork.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index d277e83ed3e0..e064bc8453dc 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -413,7 +413,10 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
 	unsigned long charge;
 
 	uprobe_start_dup_mmap();
-	down_write(&oldmm->mmap_sem);
+	if (down_write_killable(&oldmm->mmap_sem)) {
+		uprobe_end_dup_mmap();
+		return -EINTR;
+	}
 	flush_cache_dup_mm(oldmm);
 	uprobe_dup_mmap(oldmm, mm);
 	/*
-- 
2.7.0

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

* [PATCH 08/18] mm, fork: make dup_mmap wait for mmap_sem for write killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

dup_mmap needs to lock current's mm mmap_sem for write. If the waiting
task gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely OOM
resolving. Wait for the lock in the killable mode and return with EINTR
if the task got killed while waiting.

Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 kernel/fork.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index d277e83ed3e0..e064bc8453dc 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -413,7 +413,10 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
 	unsigned long charge;
 
 	uprobe_start_dup_mmap();
-	down_write(&oldmm->mmap_sem);
+	if (down_write_killable(&oldmm->mmap_sem)) {
+		uprobe_end_dup_mmap();
+		return -EINTR;
+	}
 	flush_cache_dup_mm(oldmm);
 	uprobe_dup_mmap(oldmm, mm);
 	/*
-- 
2.7.0

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

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

* [PATCH 09/18] ipc, shm: make shmem attach/detach wait for mmap_sem killable
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

shmat and shmdt rely on mmap_sem for write. If the waiting task
gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely
OOM resolving. Wait for the lock in the killable mode and return with
EINTR if the task got killed while waiting.

Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 ipc/shm.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/ipc/shm.c b/ipc/shm.c
index 331fc1b0b3c7..b8cfa05940d2 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -1200,7 +1200,11 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
 	if (err)
 		goto out_fput;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem)) {
+		err = -EINVAL;
+		goto out_fput;
+	}
+
 	if (addr && !(shmflg & SHM_REMAP)) {
 		err = -EINVAL;
 		if (addr + size < addr)
@@ -1271,7 +1275,8 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr)
 	if (addr & ~PAGE_MASK)
 		return retval;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 	/*
 	 * This function tries to be smart and unmap shm segments that
-- 
2.7.0

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

* [PATCH 09/18] ipc, shm: make shmem attach/detach wait for mmap_sem killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

shmat and shmdt rely on mmap_sem for write. If the waiting task
gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely
OOM resolving. Wait for the lock in the killable mode and return with
EINTR if the task got killed while waiting.

Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 ipc/shm.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/ipc/shm.c b/ipc/shm.c
index 331fc1b0b3c7..b8cfa05940d2 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -1200,7 +1200,11 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
 	if (err)
 		goto out_fput;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem)) {
+		err = -EINVAL;
+		goto out_fput;
+	}
+
 	if (addr && !(shmflg & SHM_REMAP)) {
 		err = -EINVAL;
 		if (addr + size < addr)
@@ -1271,7 +1275,8 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr)
 	if (addr & ~PAGE_MASK)
 		return retval;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 	/*
 	 * This function tries to be smart and unmap shm segments that
-- 
2.7.0

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

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

* [PATCH 09/18] ipc, shm: make shmem attach/detach wait for mmap_sem killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

shmat and shmdt rely on mmap_sem for write. If the waiting task
gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely
OOM resolving. Wait for the lock in the killable mode and return with
EINTR if the task got killed while waiting.

Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 ipc/shm.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/ipc/shm.c b/ipc/shm.c
index 331fc1b0b3c7..b8cfa05940d2 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -1200,7 +1200,11 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
 	if (err)
 		goto out_fput;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem)) {
+		err = -EINVAL;
+		goto out_fput;
+	}
+
 	if (addr && !(shmflg & SHM_REMAP)) {
 		err = -EINVAL;
 		if (addr + size < addr)
@@ -1271,7 +1275,8 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr)
 	if (addr & ~PAGE_MASK)
 		return retval;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 	/*
 	 * This function tries to be smart and unmap shm segments that
-- 
2.7.0

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

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

* [PATCH 10/18] vdso: make arch_setup_additional_pages wait for mmap_sem for write killable
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

most architectures are relying on mmap_sem for write in their
arch_setup_additional_pages. If the waiting task gets killed by the oom
killer it would block oom_reaper from asynchronous address space reclaim
and reduce the chances of timely OOM resolving. Wait for the lock in
the killable mode and return with EINTR if the task got killed while
waiting.

Cc: linux-arch@vger.kernel.org
Cc: Andy Lutomirski <luto@amacapital.net>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 arch/arm/kernel/process.c          | 3 ++-
 arch/arm64/kernel/vdso.c           | 6 ++++--
 arch/hexagon/kernel/vdso.c         | 3 ++-
 arch/mips/kernel/vdso.c            | 3 ++-
 arch/powerpc/kernel/vdso.c         | 3 ++-
 arch/s390/kernel/vdso.c            | 3 ++-
 arch/sh/kernel/vsyscall/vsyscall.c | 4 +++-
 arch/x86/entry/vdso/vma.c          | 3 ++-
 arch/x86/um/vdso/vma.c             | 3 ++-
 9 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
index 4adfb46e3ee9..94cccae090fa 100644
--- a/arch/arm/kernel/process.c
+++ b/arch/arm/kernel/process.c
@@ -420,7 +420,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	npages = 1; /* for sigpage */
 	npages += vdso_total_pages;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 	hint = sigpage_addr(mm, npages);
 	addr = get_unmapped_area(NULL, hint, npages << PAGE_SHIFT, 0, 0);
 	if (IS_ERR_VALUE(addr)) {
diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c
index 97bc68f4c689..d7423dfb4a4a 100644
--- a/arch/arm64/kernel/vdso.c
+++ b/arch/arm64/kernel/vdso.c
@@ -95,7 +95,8 @@ int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp)
 	};
 	void *ret;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 	current->mm->context.vdso = (void *)addr;
 
 	/* Map vectors page at the high address. */
@@ -163,7 +164,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm,
 	/* Be sure to map the data page */
 	vdso_mapping_len = vdso_text_len + PAGE_SIZE;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 	vdso_base = get_unmapped_area(NULL, 0, vdso_mapping_len, 0, 0);
 	if (IS_ERR_VALUE(vdso_base)) {
 		ret = ERR_PTR(vdso_base);
diff --git a/arch/hexagon/kernel/vdso.c b/arch/hexagon/kernel/vdso.c
index 0bf5a87e4d0a..3ea968415539 100644
--- a/arch/hexagon/kernel/vdso.c
+++ b/arch/hexagon/kernel/vdso.c
@@ -65,7 +65,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	unsigned long vdso_base;
 	struct mm_struct *mm = current->mm;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 	/* Try to get it loaded right near ld.so/glibc. */
 	vdso_base = STACK_TOP;
diff --git a/arch/mips/kernel/vdso.c b/arch/mips/kernel/vdso.c
index 975e99759bab..54e1663ce639 100644
--- a/arch/mips/kernel/vdso.c
+++ b/arch/mips/kernel/vdso.c
@@ -104,7 +104,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	struct resource gic_res;
 	int ret;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 	/*
 	 * Determine total area size. This includes the VDSO data itself, the
diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
index def1b8b5e6c1..6767605ea8da 100644
--- a/arch/powerpc/kernel/vdso.c
+++ b/arch/powerpc/kernel/vdso.c
@@ -195,7 +195,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	 * and end up putting it elsewhere.
 	 * Add enough to the size so that the result can be aligned.
 	 */
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 	vdso_base = get_unmapped_area(NULL, vdso_base,
 				      (vdso_pages << PAGE_SHIFT) +
 				      ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
diff --git a/arch/s390/kernel/vdso.c b/arch/s390/kernel/vdso.c
index 94495cac8be3..5904abf6b1ae 100644
--- a/arch/s390/kernel/vdso.c
+++ b/arch/s390/kernel/vdso.c
@@ -216,7 +216,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	 * it at vdso_base which is the "natural" base for it, but we might
 	 * fail and end up putting it elsewhere.
 	 */
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 	vdso_base = get_unmapped_area(NULL, 0, vdso_pages << PAGE_SHIFT, 0, 0);
 	if (IS_ERR_VALUE(vdso_base)) {
 		rc = vdso_base;
diff --git a/arch/sh/kernel/vsyscall/vsyscall.c b/arch/sh/kernel/vsyscall/vsyscall.c
index ea2aa1393b87..cc0cc5b4ff18 100644
--- a/arch/sh/kernel/vsyscall/vsyscall.c
+++ b/arch/sh/kernel/vsyscall/vsyscall.c
@@ -64,7 +64,9 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	unsigned long addr;
 	int ret;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
 	if (IS_ERR_VALUE(addr)) {
 		ret = addr;
diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c
index 10f704584922..69d861f67c47 100644
--- a/arch/x86/entry/vdso/vma.c
+++ b/arch/x86/entry/vdso/vma.c
@@ -174,7 +174,8 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
 		addr = 0;
 	}
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 	addr = get_unmapped_area(NULL, addr,
 				 image->size - image->sym_vvar_start, 0, 0);
diff --git a/arch/x86/um/vdso/vma.c b/arch/x86/um/vdso/vma.c
index 237c6831e095..6be22f991b59 100644
--- a/arch/x86/um/vdso/vma.c
+++ b/arch/x86/um/vdso/vma.c
@@ -61,7 +61,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	if (!vdso_enabled)
 		return 0;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 	err = install_special_mapping(mm, um_vdso_addr, PAGE_SIZE,
 		VM_READ|VM_EXEC|
-- 
2.7.0

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

* [PATCH 10/18] vdso: make arch_setup_additional_pages wait for mmap_sem for write killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

most architectures are relying on mmap_sem for write in their
arch_setup_additional_pages. If the waiting task gets killed by the oom
killer it would block oom_reaper from asynchronous address space reclaim
and reduce the chances of timely OOM resolving. Wait for the lock in
the killable mode and return with EINTR if the task got killed while
waiting.

Cc: linux-arch@vger.kernel.org
Cc: Andy Lutomirski <luto@amacapital.net>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 arch/arm/kernel/process.c          | 3 ++-
 arch/arm64/kernel/vdso.c           | 6 ++++--
 arch/hexagon/kernel/vdso.c         | 3 ++-
 arch/mips/kernel/vdso.c            | 3 ++-
 arch/powerpc/kernel/vdso.c         | 3 ++-
 arch/s390/kernel/vdso.c            | 3 ++-
 arch/sh/kernel/vsyscall/vsyscall.c | 4 +++-
 arch/x86/entry/vdso/vma.c          | 3 ++-
 arch/x86/um/vdso/vma.c             | 3 ++-
 9 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
index 4adfb46e3ee9..94cccae090fa 100644
--- a/arch/arm/kernel/process.c
+++ b/arch/arm/kernel/process.c
@@ -420,7 +420,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	npages = 1; /* for sigpage */
 	npages += vdso_total_pages;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 	hint = sigpage_addr(mm, npages);
 	addr = get_unmapped_area(NULL, hint, npages << PAGE_SHIFT, 0, 0);
 	if (IS_ERR_VALUE(addr)) {
diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c
index 97bc68f4c689..d7423dfb4a4a 100644
--- a/arch/arm64/kernel/vdso.c
+++ b/arch/arm64/kernel/vdso.c
@@ -95,7 +95,8 @@ int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp)
 	};
 	void *ret;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 	current->mm->context.vdso = (void *)addr;
 
 	/* Map vectors page at the high address. */
@@ -163,7 +164,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm,
 	/* Be sure to map the data page */
 	vdso_mapping_len = vdso_text_len + PAGE_SIZE;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 	vdso_base = get_unmapped_area(NULL, 0, vdso_mapping_len, 0, 0);
 	if (IS_ERR_VALUE(vdso_base)) {
 		ret = ERR_PTR(vdso_base);
diff --git a/arch/hexagon/kernel/vdso.c b/arch/hexagon/kernel/vdso.c
index 0bf5a87e4d0a..3ea968415539 100644
--- a/arch/hexagon/kernel/vdso.c
+++ b/arch/hexagon/kernel/vdso.c
@@ -65,7 +65,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	unsigned long vdso_base;
 	struct mm_struct *mm = current->mm;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 	/* Try to get it loaded right near ld.so/glibc. */
 	vdso_base = STACK_TOP;
diff --git a/arch/mips/kernel/vdso.c b/arch/mips/kernel/vdso.c
index 975e99759bab..54e1663ce639 100644
--- a/arch/mips/kernel/vdso.c
+++ b/arch/mips/kernel/vdso.c
@@ -104,7 +104,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	struct resource gic_res;
 	int ret;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 	/*
 	 * Determine total area size. This includes the VDSO data itself, the
diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
index def1b8b5e6c1..6767605ea8da 100644
--- a/arch/powerpc/kernel/vdso.c
+++ b/arch/powerpc/kernel/vdso.c
@@ -195,7 +195,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	 * and end up putting it elsewhere.
 	 * Add enough to the size so that the result can be aligned.
 	 */
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 	vdso_base = get_unmapped_area(NULL, vdso_base,
 				      (vdso_pages << PAGE_SHIFT) +
 				      ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
diff --git a/arch/s390/kernel/vdso.c b/arch/s390/kernel/vdso.c
index 94495cac8be3..5904abf6b1ae 100644
--- a/arch/s390/kernel/vdso.c
+++ b/arch/s390/kernel/vdso.c
@@ -216,7 +216,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	 * it at vdso_base which is the "natural" base for it, but we might
 	 * fail and end up putting it elsewhere.
 	 */
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 	vdso_base = get_unmapped_area(NULL, 0, vdso_pages << PAGE_SHIFT, 0, 0);
 	if (IS_ERR_VALUE(vdso_base)) {
 		rc = vdso_base;
diff --git a/arch/sh/kernel/vsyscall/vsyscall.c b/arch/sh/kernel/vsyscall/vsyscall.c
index ea2aa1393b87..cc0cc5b4ff18 100644
--- a/arch/sh/kernel/vsyscall/vsyscall.c
+++ b/arch/sh/kernel/vsyscall/vsyscall.c
@@ -64,7 +64,9 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	unsigned long addr;
 	int ret;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
 	if (IS_ERR_VALUE(addr)) {
 		ret = addr;
diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c
index 10f704584922..69d861f67c47 100644
--- a/arch/x86/entry/vdso/vma.c
+++ b/arch/x86/entry/vdso/vma.c
@@ -174,7 +174,8 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
 		addr = 0;
 	}
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 	addr = get_unmapped_area(NULL, addr,
 				 image->size - image->sym_vvar_start, 0, 0);
diff --git a/arch/x86/um/vdso/vma.c b/arch/x86/um/vdso/vma.c
index 237c6831e095..6be22f991b59 100644
--- a/arch/x86/um/vdso/vma.c
+++ b/arch/x86/um/vdso/vma.c
@@ -61,7 +61,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	if (!vdso_enabled)
 		return 0;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 	err = install_special_mapping(mm, um_vdso_addr, PAGE_SIZE,
 		VM_READ|VM_EXEC|
-- 
2.7.0

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

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

* [PATCH 10/18] vdso: make arch_setup_additional_pages wait for mmap_sem for write killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

most architectures are relying on mmap_sem for write in their
arch_setup_additional_pages. If the waiting task gets killed by the oom
killer it would block oom_reaper from asynchronous address space reclaim
and reduce the chances of timely OOM resolving. Wait for the lock in
the killable mode and return with EINTR if the task got killed while
waiting.

Cc: linux-arch@vger.kernel.org
Cc: Andy Lutomirski <luto@amacapital.net>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 arch/arm/kernel/process.c          | 3 ++-
 arch/arm64/kernel/vdso.c           | 6 ++++--
 arch/hexagon/kernel/vdso.c         | 3 ++-
 arch/mips/kernel/vdso.c            | 3 ++-
 arch/powerpc/kernel/vdso.c         | 3 ++-
 arch/s390/kernel/vdso.c            | 3 ++-
 arch/sh/kernel/vsyscall/vsyscall.c | 4 +++-
 arch/x86/entry/vdso/vma.c          | 3 ++-
 arch/x86/um/vdso/vma.c             | 3 ++-
 9 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
index 4adfb46e3ee9..94cccae090fa 100644
--- a/arch/arm/kernel/process.c
+++ b/arch/arm/kernel/process.c
@@ -420,7 +420,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	npages = 1; /* for sigpage */
 	npages += vdso_total_pages;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 	hint = sigpage_addr(mm, npages);
 	addr = get_unmapped_area(NULL, hint, npages << PAGE_SHIFT, 0, 0);
 	if (IS_ERR_VALUE(addr)) {
diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c
index 97bc68f4c689..d7423dfb4a4a 100644
--- a/arch/arm64/kernel/vdso.c
+++ b/arch/arm64/kernel/vdso.c
@@ -95,7 +95,8 @@ int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp)
 	};
 	void *ret;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 	current->mm->context.vdso = (void *)addr;
 
 	/* Map vectors page at the high address. */
@@ -163,7 +164,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm,
 	/* Be sure to map the data page */
 	vdso_mapping_len = vdso_text_len + PAGE_SIZE;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 	vdso_base = get_unmapped_area(NULL, 0, vdso_mapping_len, 0, 0);
 	if (IS_ERR_VALUE(vdso_base)) {
 		ret = ERR_PTR(vdso_base);
diff --git a/arch/hexagon/kernel/vdso.c b/arch/hexagon/kernel/vdso.c
index 0bf5a87e4d0a..3ea968415539 100644
--- a/arch/hexagon/kernel/vdso.c
+++ b/arch/hexagon/kernel/vdso.c
@@ -65,7 +65,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	unsigned long vdso_base;
 	struct mm_struct *mm = current->mm;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 	/* Try to get it loaded right near ld.so/glibc. */
 	vdso_base = STACK_TOP;
diff --git a/arch/mips/kernel/vdso.c b/arch/mips/kernel/vdso.c
index 975e99759bab..54e1663ce639 100644
--- a/arch/mips/kernel/vdso.c
+++ b/arch/mips/kernel/vdso.c
@@ -104,7 +104,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	struct resource gic_res;
 	int ret;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 	/*
 	 * Determine total area size. This includes the VDSO data itself, the
diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
index def1b8b5e6c1..6767605ea8da 100644
--- a/arch/powerpc/kernel/vdso.c
+++ b/arch/powerpc/kernel/vdso.c
@@ -195,7 +195,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	 * and end up putting it elsewhere.
 	 * Add enough to the size so that the result can be aligned.
 	 */
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 	vdso_base = get_unmapped_area(NULL, vdso_base,
 				      (vdso_pages << PAGE_SHIFT) +
 				      ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
diff --git a/arch/s390/kernel/vdso.c b/arch/s390/kernel/vdso.c
index 94495cac8be3..5904abf6b1ae 100644
--- a/arch/s390/kernel/vdso.c
+++ b/arch/s390/kernel/vdso.c
@@ -216,7 +216,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	 * it at vdso_base which is the "natural" base for it, but we might
 	 * fail and end up putting it elsewhere.
 	 */
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 	vdso_base = get_unmapped_area(NULL, 0, vdso_pages << PAGE_SHIFT, 0, 0);
 	if (IS_ERR_VALUE(vdso_base)) {
 		rc = vdso_base;
diff --git a/arch/sh/kernel/vsyscall/vsyscall.c b/arch/sh/kernel/vsyscall/vsyscall.c
index ea2aa1393b87..cc0cc5b4ff18 100644
--- a/arch/sh/kernel/vsyscall/vsyscall.c
+++ b/arch/sh/kernel/vsyscall/vsyscall.c
@@ -64,7 +64,9 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	unsigned long addr;
 	int ret;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
 	if (IS_ERR_VALUE(addr)) {
 		ret = addr;
diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c
index 10f704584922..69d861f67c47 100644
--- a/arch/x86/entry/vdso/vma.c
+++ b/arch/x86/entry/vdso/vma.c
@@ -174,7 +174,8 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
 		addr = 0;
 	}
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 	addr = get_unmapped_area(NULL, addr,
 				 image->size - image->sym_vvar_start, 0, 0);
diff --git a/arch/x86/um/vdso/vma.c b/arch/x86/um/vdso/vma.c
index 237c6831e095..6be22f991b59 100644
--- a/arch/x86/um/vdso/vma.c
+++ b/arch/x86/um/vdso/vma.c
@@ -61,7 +61,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 	if (!vdso_enabled)
 		return 0;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 	err = install_special_mapping(mm, um_vdso_addr, PAGE_SIZE,
 		VM_READ|VM_EXEC|
-- 
2.7.0

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

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

* [PATCH 11/18] coredump: make coredump_wait wait for mma_sem for write killable
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

coredump_wait waits for mmap_sem for write currently which can
prevent oom_reaper to reclaim the oom victims address space
asynchronously because that requires mmap_sem for read. This might
happen if the oom victim is multi threaded and some thread(s) is
holding mmap_sem for read (e.g. page fault) and it is stuck in
the page allocator while other thread(s) reached coredump_wait
already.

This patch simply uses down_write_killable and bails out with EINTR
if the lock got interrupted by the fatal signal. do_coredump will
return right away and do_group_exit will take care to zap the whole
thread group.

Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/coredump.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/coredump.c b/fs/coredump.c
index 9ea87e9fdccf..6b8aa1629891 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -410,7 +410,9 @@ static int coredump_wait(int exit_code, struct core_state *core_state)
 	core_state->dumper.task = tsk;
 	core_state->dumper.next = NULL;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	if (!mm->core_state)
 		core_waiters = zap_threads(tsk, mm, core_state, exit_code);
 	up_write(&mm->mmap_sem);
-- 
2.7.0

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

* [PATCH 11/18] coredump: make coredump_wait wait for mma_sem for write killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

coredump_wait waits for mmap_sem for write currently which can
prevent oom_reaper to reclaim the oom victims address space
asynchronously because that requires mmap_sem for read. This might
happen if the oom victim is multi threaded and some thread(s) is
holding mmap_sem for read (e.g. page fault) and it is stuck in
the page allocator while other thread(s) reached coredump_wait
already.

This patch simply uses down_write_killable and bails out with EINTR
if the lock got interrupted by the fatal signal. do_coredump will
return right away and do_group_exit will take care to zap the whole
thread group.

Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/coredump.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/coredump.c b/fs/coredump.c
index 9ea87e9fdccf..6b8aa1629891 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -410,7 +410,9 @@ static int coredump_wait(int exit_code, struct core_state *core_state)
 	core_state->dumper.task = tsk;
 	core_state->dumper.next = NULL;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	if (!mm->core_state)
 		core_waiters = zap_threads(tsk, mm, core_state, exit_code);
 	up_write(&mm->mmap_sem);
-- 
2.7.0

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

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

* [PATCH 11/18] coredump: make coredump_wait wait for mma_sem for write killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

coredump_wait waits for mmap_sem for write currently which can
prevent oom_reaper to reclaim the oom victims address space
asynchronously because that requires mmap_sem for read. This might
happen if the oom victim is multi threaded and some thread(s) is
holding mmap_sem for read (e.g. page fault) and it is stuck in
the page allocator while other thread(s) reached coredump_wait
already.

This patch simply uses down_write_killable and bails out with EINTR
if the lock got interrupted by the fatal signal. do_coredump will
return right away and do_group_exit will take care to zap the whole
thread group.

Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/coredump.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/coredump.c b/fs/coredump.c
index 9ea87e9fdccf..6b8aa1629891 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -410,7 +410,9 @@ static int coredump_wait(int exit_code, struct core_state *core_state)
 	core_state->dumper.task = tsk;
 	core_state->dumper.next = NULL;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	if (!mm->core_state)
 		core_waiters = zap_threads(tsk, mm, core_state, exit_code);
 	up_write(&mm->mmap_sem);
-- 
2.7.0

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

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

* [PATCH 12/18] aio: make aio_setup_ring killable
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

From: Michal Hocko <mhocko@suse.com>

aio_setup_ring waits for mmap_sem in writable mode. If the waiting
task gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely
OOM resolving. Wait for the lock in the killable mode and return with
EINTR if the task got killed while waiting. This will also expedite
the return to the userspace and do_exit.

Cc: Benjamin LaHaise <bcrl@kvack.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/aio.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/aio.c b/fs/aio.c
index 56bcdf4105f4..1c2e7e2c1b2b 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -520,7 +520,12 @@ static int aio_setup_ring(struct kioctx *ctx)
 	ctx->mmap_size = nr_pages * PAGE_SIZE;
 	pr_debug("attempting mmap of %lu bytes\n", ctx->mmap_size);
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem)) {
+		ctx->mmap_size = 0;
+		aio_free_ring(ctx);
+		return -EINTR;
+	}
+
 	ctx->mmap_base = do_mmap_pgoff(ctx->aio_ring_file, 0, ctx->mmap_size,
 				       PROT_READ | PROT_WRITE,
 				       MAP_SHARED, 0, &unused);
-- 
2.7.0

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

* [PATCH 12/18] aio: make aio_setup_ring killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

aio_setup_ring waits for mmap_sem in writable mode. If the waiting
task gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely
OOM resolving. Wait for the lock in the killable mode and return with
EINTR if the task got killed while waiting. This will also expedite
the return to the userspace and do_exit.

Cc: Benjamin LaHaise <bcrl@kvack.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/aio.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/aio.c b/fs/aio.c
index 56bcdf4105f4..1c2e7e2c1b2b 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -520,7 +520,12 @@ static int aio_setup_ring(struct kioctx *ctx)
 	ctx->mmap_size = nr_pages * PAGE_SIZE;
 	pr_debug("attempting mmap of %lu bytes\n", ctx->mmap_size);
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem)) {
+		ctx->mmap_size = 0;
+		aio_free_ring(ctx);
+		return -EINTR;
+	}
+
 	ctx->mmap_base = do_mmap_pgoff(ctx->aio_ring_file, 0, ctx->mmap_size,
 				       PROT_READ | PROT_WRITE,
 				       MAP_SHARED, 0, &unused);
-- 
2.7.0

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

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

* [PATCH 12/18] aio: make aio_setup_ring killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

From: Michal Hocko <mhocko@suse.com>

aio_setup_ring waits for mmap_sem in writable mode. If the waiting
task gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely
OOM resolving. Wait for the lock in the killable mode and return with
EINTR if the task got killed while waiting. This will also expedite
the return to the userspace and do_exit.

Cc: Benjamin LaHaise <bcrl@kvack.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/aio.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/aio.c b/fs/aio.c
index 56bcdf4105f4..1c2e7e2c1b2b 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -520,7 +520,12 @@ static int aio_setup_ring(struct kioctx *ctx)
 	ctx->mmap_size = nr_pages * PAGE_SIZE;
 	pr_debug("attempting mmap of %lu bytes\n", ctx->mmap_size);
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem)) {
+		ctx->mmap_size = 0;
+		aio_free_ring(ctx);
+		return -EINTR;
+	}
+
 	ctx->mmap_base = do_mmap_pgoff(ctx->aio_ring_file, 0, ctx->mmap_size,
 				       PROT_READ | PROT_WRITE,
 				       MAP_SHARED, 0, &unused);
-- 
2.7.0

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

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

* [PATCH 13/18] exec: make exec path waiting for mmap_sem killable
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

From: Michal Hocko <mhocko@suse.com>

setup_arg_pages requires mmap_sem for write. If the waiting task
gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely
OOM resolving. Wait for the lock in the killable mode and return with
EINTR if the task got killed while waiting. All the callers are already
handling error path and the fatal signal doesn't need any additional
treatment.

The same applies to __bprm_mm_init.

Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/exec.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index c4010b8207a1..29f2f22ae067 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -267,7 +267,10 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
 	if (!vma)
 		return -ENOMEM;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem)) {
+		err = -EINTR;
+		goto err_free;
+	}
 	vma->vm_mm = mm;
 
 	/*
@@ -294,6 +297,7 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
 	return 0;
 err:
 	up_write(&mm->mmap_sem);
+err_free:
 	bprm->vma = NULL;
 	kmem_cache_free(vm_area_cachep, vma);
 	return err;
@@ -700,7 +704,9 @@ int setup_arg_pages(struct linux_binprm *bprm,
 		bprm->loader -= stack_shift;
 	bprm->exec -= stack_shift;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	vm_flags = VM_STACK_FLAGS;
 
 	/*
-- 
2.7.0

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

* [PATCH 13/18] exec: make exec path waiting for mmap_sem killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

setup_arg_pages requires mmap_sem for write. If the waiting task
gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely
OOM resolving. Wait for the lock in the killable mode and return with
EINTR if the task got killed while waiting. All the callers are already
handling error path and the fatal signal doesn't need any additional
treatment.

The same applies to __bprm_mm_init.

Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/exec.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index c4010b8207a1..29f2f22ae067 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -267,7 +267,10 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
 	if (!vma)
 		return -ENOMEM;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem)) {
+		err = -EINTR;
+		goto err_free;
+	}
 	vma->vm_mm = mm;
 
 	/*
@@ -294,6 +297,7 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
 	return 0;
 err:
 	up_write(&mm->mmap_sem);
+err_free:
 	bprm->vma = NULL;
 	kmem_cache_free(vm_area_cachep, vma);
 	return err;
@@ -700,7 +704,9 @@ int setup_arg_pages(struct linux_binprm *bprm,
 		bprm->loader -= stack_shift;
 	bprm->exec -= stack_shift;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	vm_flags = VM_STACK_FLAGS;
 
 	/*
-- 
2.7.0

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

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

* [PATCH 13/18] exec: make exec path waiting for mmap_sem killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

From: Michal Hocko <mhocko@suse.com>

setup_arg_pages requires mmap_sem for write. If the waiting task
gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely
OOM resolving. Wait for the lock in the killable mode and return with
EINTR if the task got killed while waiting. All the callers are already
handling error path and the fatal signal doesn't need any additional
treatment.

The same applies to __bprm_mm_init.

Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/exec.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index c4010b8207a1..29f2f22ae067 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -267,7 +267,10 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
 	if (!vma)
 		return -ENOMEM;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem)) {
+		err = -EINTR;
+		goto err_free;
+	}
 	vma->vm_mm = mm;
 
 	/*
@@ -294,6 +297,7 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
 	return 0;
 err:
 	up_write(&mm->mmap_sem);
+err_free:
 	bprm->vma = NULL;
 	kmem_cache_free(vm_area_cachep, vma);
 	return err;
@@ -700,7 +704,9 @@ int setup_arg_pages(struct linux_binprm *bprm,
 		bprm->loader -= stack_shift;
 	bprm->exec -= stack_shift;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	vm_flags = VM_STACK_FLAGS;
 
 	/*
-- 
2.7.0

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

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

* [PATCH 14/18] prctl: make PR_SET_THP_DISABLE wait for mmap_sem killable
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

PR_SET_THP_DISABLE requires mmap_sem for write. If the waiting
task gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely OOM
resolving. Wait for the lock in the killable mode and return with EINTR
if the task got killed while waiting.

Cc: Alex Thorlton <athorlton@sgi.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 kernel/sys.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/sys.c b/kernel/sys.c
index cf8ba545c7d3..89d5be418157 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -2246,7 +2246,8 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 	case PR_SET_THP_DISABLE:
 		if (arg3 || arg4 || arg5)
 			return -EINVAL;
-		down_write(&me->mm->mmap_sem);
+		if (down_write_killable(&me->mm->mmap_sem))
+			return -EINTR;
 		if (arg2)
 			me->mm->def_flags |= VM_NOHUGEPAGE;
 		else
-- 
2.7.0

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

* [PATCH 14/18] prctl: make PR_SET_THP_DISABLE wait for mmap_sem killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

PR_SET_THP_DISABLE requires mmap_sem for write. If the waiting
task gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely OOM
resolving. Wait for the lock in the killable mode and return with EINTR
if the task got killed while waiting.

Cc: Alex Thorlton <athorlton@sgi.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 kernel/sys.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/sys.c b/kernel/sys.c
index cf8ba545c7d3..89d5be418157 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -2246,7 +2246,8 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 	case PR_SET_THP_DISABLE:
 		if (arg3 || arg4 || arg5)
 			return -EINVAL;
-		down_write(&me->mm->mmap_sem);
+		if (down_write_killable(&me->mm->mmap_sem))
+			return -EINTR;
 		if (arg2)
 			me->mm->def_flags |= VM_NOHUGEPAGE;
 		else
-- 
2.7.0

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

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

* [PATCH 14/18] prctl: make PR_SET_THP_DISABLE wait for mmap_sem killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

PR_SET_THP_DISABLE requires mmap_sem for write. If the waiting
task gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely OOM
resolving. Wait for the lock in the killable mode and return with EINTR
if the task got killed while waiting.

Cc: Alex Thorlton <athorlton@sgi.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 kernel/sys.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/sys.c b/kernel/sys.c
index cf8ba545c7d3..89d5be418157 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -2246,7 +2246,8 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 	case PR_SET_THP_DISABLE:
 		if (arg3 || arg4 || arg5)
 			return -EINVAL;
-		down_write(&me->mm->mmap_sem);
+		if (down_write_killable(&me->mm->mmap_sem))
+			return -EINTR;
 		if (arg2)
 			me->mm->def_flags |= VM_NOHUGEPAGE;
 		else
-- 
2.7.0

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

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

* [PATCH 15/18] uprobes: wait for mmap_sem for write killable
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

xol_add_vma needs mmap_sem for write. If the waiting task gets killed by
the oom killer it would block oom_reaper from asynchronous address space
reclaim and reduce the chances of timely OOM resolving. Wait for the
lock in the killable mode and return with EINTR if the task got killed
while waiting.

Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 kernel/events/uprobes.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 8eef5f55d3f0..a79315d0f711 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
 	struct vm_area_struct *vma;
 	int ret;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	if (mm->uprobes_state.xol_area) {
 		ret = -EALREADY;
 		goto fail;
-- 
2.7.0

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

* [PATCH 15/18] uprobes: wait for mmap_sem for write killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

xol_add_vma needs mmap_sem for write. If the waiting task gets killed by
the oom killer it would block oom_reaper from asynchronous address space
reclaim and reduce the chances of timely OOM resolving. Wait for the
lock in the killable mode and return with EINTR if the task got killed
while waiting.

Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 kernel/events/uprobes.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 8eef5f55d3f0..a79315d0f711 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
 	struct vm_area_struct *vma;
 	int ret;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	if (mm->uprobes_state.xol_area) {
 		ret = -EALREADY;
 		goto fail;
-- 
2.7.0

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

* [PATCH 15/18] uprobes: wait for mmap_sem for write killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

xol_add_vma needs mmap_sem for write. If the waiting task gets killed by
the oom killer it would block oom_reaper from asynchronous address space
reclaim and reduce the chances of timely OOM resolving. Wait for the
lock in the killable mode and return with EINTR if the task got killed
while waiting.

Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 kernel/events/uprobes.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 8eef5f55d3f0..a79315d0f711 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
 	struct vm_area_struct *vma;
 	int ret;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	if (mm->uprobes_state.xol_area) {
 		ret = -EALREADY;
 		goto fail;
-- 
2.7.0

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

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

* [PATCH 16/18] drm/i915: make i915_gem_mmap_ioctl wait for mmap_sem killable
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

i915_gem_mmap_ioctl relies on mmap_sem for write. If the waiting
task gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely OOM
resolving. Wait for the lock in the killable mode and return with EINTR
if the task got killed while waiting.

Cc: Daniel Vetter <daniel.vetter@intel.com>
Cc: David Airlie <airlied@linux.ie>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 drivers/gpu/drm/i915/i915_gem.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index f68f34606f2f..a50136cbd332 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1754,7 +1754,10 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
 		struct mm_struct *mm = current->mm;
 		struct vm_area_struct *vma;
 
-		down_write(&mm->mmap_sem);
+		if (down_write_killable(&mm->mmap_sem)) {
+			drm_gem_object_unreference_unlocked(obj);
+			return -EINTR;
+		}
 		vma = find_vma(mm, addr);
 		if (vma)
 			vma->vm_page_prot =
-- 
2.7.0

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

* [PATCH 16/18] drm/i915: make i915_gem_mmap_ioctl wait for mmap_sem killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

i915_gem_mmap_ioctl relies on mmap_sem for write. If the waiting
task gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely OOM
resolving. Wait for the lock in the killable mode and return with EINTR
if the task got killed while waiting.

Cc: Daniel Vetter <daniel.vetter@intel.com>
Cc: David Airlie <airlied@linux.ie>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 drivers/gpu/drm/i915/i915_gem.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index f68f34606f2f..a50136cbd332 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1754,7 +1754,10 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
 		struct mm_struct *mm = current->mm;
 		struct vm_area_struct *vma;
 
-		down_write(&mm->mmap_sem);
+		if (down_write_killable(&mm->mmap_sem)) {
+			drm_gem_object_unreference_unlocked(obj);
+			return -EINTR;
+		}
 		vma = find_vma(mm, addr);
 		if (vma)
 			vma->vm_page_prot =
-- 
2.7.0

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

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

* [PATCH 16/18] drm/i915: make i915_gem_mmap_ioctl wait for mmap_sem killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

i915_gem_mmap_ioctl relies on mmap_sem for write. If the waiting
task gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely OOM
resolving. Wait for the lock in the killable mode and return with EINTR
if the task got killed while waiting.

Cc: Daniel Vetter <daniel.vetter@intel.com>
Cc: David Airlie <airlied@linux.ie>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 drivers/gpu/drm/i915/i915_gem.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index f68f34606f2f..a50136cbd332 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1754,7 +1754,10 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
 		struct mm_struct *mm = current->mm;
 		struct vm_area_struct *vma;
 
-		down_write(&mm->mmap_sem);
+		if (down_write_killable(&mm->mmap_sem)) {
+			drm_gem_object_unreference_unlocked(obj);
+			return -EINTR;
+		}
 		vma = find_vma(mm, addr);
 		if (vma)
 			vma->vm_page_prot =
-- 
2.7.0

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

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

* [PATCH 17/18] drm/radeon: make radeon_mn_get wait for mmap_sem killable
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

radeon_mn_get which is called during ioct path relies on mmap_sem for
write. If the waiting task gets killed by the oom killer it would block
oom_reaper from asynchronous address space reclaim and reduce the
chances of timely OOM resolving. Wait for the lock in the killable mode
and return with EINTR if the task got killed while waiting.

Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: "Christian König" <christian.koenig@amd.com>
Cc: David Airlie <airlied@linux.ie>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 drivers/gpu/drm/radeon/radeon_mn.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c
index eef006c48584..896f2cf51e4e 100644
--- a/drivers/gpu/drm/radeon/radeon_mn.c
+++ b/drivers/gpu/drm/radeon/radeon_mn.c
@@ -186,7 +186,9 @@ static struct radeon_mn *radeon_mn_get(struct radeon_device *rdev)
 	struct radeon_mn *rmn;
 	int r;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return ERR_PTR(-EINTR);
+
 	mutex_lock(&rdev->mn_lock);
 
 	hash_for_each_possible(rdev->mn_hash, rmn, node, (unsigned long)mm)
-- 
2.7.0

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

* [PATCH 17/18] drm/radeon: make radeon_mn_get wait for mmap_sem killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

radeon_mn_get which is called during ioct path relies on mmap_sem for
write. If the waiting task gets killed by the oom killer it would block
oom_reaper from asynchronous address space reclaim and reduce the
chances of timely OOM resolving. Wait for the lock in the killable mode
and return with EINTR if the task got killed while waiting.

Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: "Christian König" <christian.koenig@amd.com>
Cc: David Airlie <airlied@linux.ie>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 drivers/gpu/drm/radeon/radeon_mn.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c
index eef006c48584..896f2cf51e4e 100644
--- a/drivers/gpu/drm/radeon/radeon_mn.c
+++ b/drivers/gpu/drm/radeon/radeon_mn.c
@@ -186,7 +186,9 @@ static struct radeon_mn *radeon_mn_get(struct radeon_device *rdev)
 	struct radeon_mn *rmn;
 	int r;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return ERR_PTR(-EINTR);
+
 	mutex_lock(&rdev->mn_lock);
 
 	hash_for_each_possible(rdev->mn_hash, rmn, node, (unsigned long)mm)
-- 
2.7.0

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

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

* [PATCH 17/18] drm/radeon: make radeon_mn_get wait for mmap_sem killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

radeon_mn_get which is called during ioct path relies on mmap_sem for
write. If the waiting task gets killed by the oom killer it would block
oom_reaper from asynchronous address space reclaim and reduce the
chances of timely OOM resolving. Wait for the lock in the killable mode
and return with EINTR if the task got killed while waiting.

Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: "Christian KA?nig" <christian.koenig@amd.com>
Cc: David Airlie <airlied@linux.ie>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 drivers/gpu/drm/radeon/radeon_mn.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c
index eef006c48584..896f2cf51e4e 100644
--- a/drivers/gpu/drm/radeon/radeon_mn.c
+++ b/drivers/gpu/drm/radeon/radeon_mn.c
@@ -186,7 +186,9 @@ static struct radeon_mn *radeon_mn_get(struct radeon_device *rdev)
 	struct radeon_mn *rmn;
 	int r;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return ERR_PTR(-EINTR);
+
 	mutex_lock(&rdev->mn_lock);
 
 	hash_for_each_possible(rdev->mn_hash, rmn, node, (unsigned long)mm)
-- 
2.7.0

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

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

* [PATCH 18/18] drm/amdgpu: make amdgpu_mn_get wait for mmap_sem killable
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:26   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

amdgpu_mn_get which is called during ioct path relies on mmap_sem for
write. If the waiting task gets killed by the oom killer it would block
oom_reaper from asynchronous address space reclaim and reduce the
chances of timely OOM resolving. Wait for the lock in the killable mode
and return with EINTR if the task got killed while waiting.

Cc: David Airlie <airlied@linux.ie>
Cc: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
index d7ec9bd6755f..6f44f1c23be3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
@@ -181,7 +181,10 @@ static struct amdgpu_mn *amdgpu_mn_get(struct amdgpu_device *adev)
 	int r;
 
 	mutex_lock(&adev->mn_lock);
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem)) {
+		mutex_unlock(&adev->mn_lock);
+		return -EINTR;
+	}
 
 	hash_for_each_possible(adev->mn_hash, rmn, node, (unsigned long)mm)
 		if (rmn->mm == mm)
-- 
2.7.0

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

* [PATCH 18/18] drm/amdgpu: make amdgpu_mn_get wait for mmap_sem killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

From: Michal Hocko <mhocko@suse.com>

amdgpu_mn_get which is called during ioct path relies on mmap_sem for
write. If the waiting task gets killed by the oom killer it would block
oom_reaper from asynchronous address space reclaim and reduce the
chances of timely OOM resolving. Wait for the lock in the killable mode
and return with EINTR if the task got killed while waiting.

Cc: David Airlie <airlied@linux.ie>
Cc: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
index d7ec9bd6755f..6f44f1c23be3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
@@ -181,7 +181,10 @@ static struct amdgpu_mn *amdgpu_mn_get(struct amdgpu_device *adev)
 	int r;
 
 	mutex_lock(&adev->mn_lock);
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem)) {
+		mutex_unlock(&adev->mn_lock);
+		return -EINTR;
+	}
 
 	hash_for_each_possible(adev->mn_hash, rmn, node, (unsigned long)mm)
 		if (rmn->mm == mm)
-- 
2.7.0

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

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

* [PATCH 18/18] drm/amdgpu: make amdgpu_mn_get wait for mmap_sem killable
@ 2016-02-29 13:26   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:26 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

amdgpu_mn_get which is called during ioct path relies on mmap_sem for
write. If the waiting task gets killed by the oom killer it would block
oom_reaper from asynchronous address space reclaim and reduce the
chances of timely OOM resolving. Wait for the lock in the killable mode
and return with EINTR if the task got killed while waiting.

Cc: David Airlie <airlied@linux.ie>
Cc: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
index d7ec9bd6755f..6f44f1c23be3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
@@ -181,7 +181,10 @@ static struct amdgpu_mn *amdgpu_mn_get(struct amdgpu_device *adev)
 	int r;
 
 	mutex_lock(&adev->mn_lock);
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem)) {
+		mutex_unlock(&adev->mn_lock);
+		return -EINTR;
+	}
 
 	hash_for_each_possible(adev->mn_hash, rmn, node, (unsigned long)mm)
 		if (rmn->mm == mm)
-- 
2.7.0

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

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

* Re: [PATCH 0/18] change mmap_sem taken for write killable
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 13:31   ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:31 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner

On Mon 29-02-16 14:26:39, Michal Hocko wrote:
[...]
> As this work is touching more areas which are not directly connected I
> have tried to keep the CC list as small as possible and people who I
> believed would be familiar are CCed only to the specific patches (all
> should have received the cover though).

Damnt it. I thought that git-send-email will not use the same CC list
for all patches and use it only for the cover if the particular patches
have their CC list. I am sorry for the excessive spamming!
-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 0/18] change mmap_sem taken for write killable
@ 2016-02-29 13:31   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:31 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

On Mon 29-02-16 14:26:39, Michal Hocko wrote:
[...]
> As this work is touching more areas which are not directly connected I
> have tried to keep the CC list as small as possible and people who I
> believed would be familiar are CCed only to the specific patches (all
> should have received the cover though).

Damnt it. I thought that git-send-email will not use the same CC list
for all patches and use it only for the cover if the particular patches
have their CC list. I am sorry for the excessive spamming!
-- 
Michal Hocko
SUSE Labs

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

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

* Re: [PATCH 0/18] change mmap_sem taken for write killable
@ 2016-02-29 13:31   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 13:31 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner

On Mon 29-02-16 14:26:39, Michal Hocko wrote:
[...]
> As this work is touching more areas which are not directly connected I
> have tried to keep the CC list as small as possible and people who I
> believed would be familiar are CCed only to the specific patches (all
> should have received the cover though).

Damnt it. I thought that git-send-email will not use the same CC list
for all patches and use it only for the cover if the particular patches
have their CC list. I am sorry for the excessive spamming!
-- 
Michal Hocko
SUSE Labs

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

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

* Re: [PATCH 17/18] drm/radeon: make radeon_mn_get wait for mmap_sem killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
  (?)
@ 2016-02-29 13:35     ` Christian König
  -1 siblings, 0 replies; 234+ messages in thread
From: Christian König @ 2016-02-29 13:35 UTC (permalink / raw)
  To: Michal Hocko, LKML; +Cc: dri-devel, linux-mm, linux-arch

[Dropping CCing the individual people, but adding the dri-devel mailing 
list as well instead].

Am 29.02.2016 um 14:26 schrieb Michal Hocko:
> From: Michal Hocko <mhocko@suse.com>
>
> radeon_mn_get which is called during ioct path relies on mmap_sem for
> write. If the waiting task gets killed by the oom killer it would block
> oom_reaper from asynchronous address space reclaim and reduce the
> chances of timely OOM resolving. Wait for the lock in the killable mode
> and return with EINTR if the task got killed while waiting.
>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: "Christian König" <christian.koenig@amd.com>
> Cc: David Airlie <airlied@linux.ie>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

This one and patch #18 in this series are Reviewed-by: Christian König 
<christian.koenig@amd.com>.

Nice to see some improvements on this side,
Christian.

> ---
>   drivers/gpu/drm/radeon/radeon_mn.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c
> index eef006c48584..896f2cf51e4e 100644
> --- a/drivers/gpu/drm/radeon/radeon_mn.c
> +++ b/drivers/gpu/drm/radeon/radeon_mn.c
> @@ -186,7 +186,9 @@ static struct radeon_mn *radeon_mn_get(struct radeon_device *rdev)
>   	struct radeon_mn *rmn;
>   	int r;
>   
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return ERR_PTR(-EINTR);
> +
>   	mutex_lock(&rdev->mn_lock);
>   
>   	hash_for_each_possible(rdev->mn_hash, rmn, node, (unsigned long)mm)

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

* Re: [PATCH 17/18] drm/radeon: make radeon_mn_get wait for mmap_sem killable
@ 2016-02-29 13:35     ` Christian König
  0 siblings, 0 replies; 234+ messages in thread
From: Christian König @ 2016-02-29 13:35 UTC (permalink / raw)
  To: Michal Hocko, LKML; +Cc: linux-arch, linux-mm, dri-devel

[Dropping CCing the individual people, but adding the dri-devel mailing 
list as well instead].

Am 29.02.2016 um 14:26 schrieb Michal Hocko:
> From: Michal Hocko <mhocko@suse.com>
>
> radeon_mn_get which is called during ioct path relies on mmap_sem for
> write. If the waiting task gets killed by the oom killer it would block
> oom_reaper from asynchronous address space reclaim and reduce the
> chances of timely OOM resolving. Wait for the lock in the killable mode
> and return with EINTR if the task got killed while waiting.
>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: "Christian König" <christian.koenig@amd.com>
> Cc: David Airlie <airlied@linux.ie>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

This one and patch #18 in this series are Reviewed-by: Christian König 
<christian.koenig@amd.com>.

Nice to see some improvements on this side,
Christian.

> ---
>   drivers/gpu/drm/radeon/radeon_mn.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c
> index eef006c48584..896f2cf51e4e 100644
> --- a/drivers/gpu/drm/radeon/radeon_mn.c
> +++ b/drivers/gpu/drm/radeon/radeon_mn.c
> @@ -186,7 +186,9 @@ static struct radeon_mn *radeon_mn_get(struct radeon_device *rdev)
>   	struct radeon_mn *rmn;
>   	int r;
>   
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return ERR_PTR(-EINTR);
> +
>   	mutex_lock(&rdev->mn_lock);
>   
>   	hash_for_each_possible(rdev->mn_hash, rmn, node, (unsigned long)mm)

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH 17/18] drm/radeon: make radeon_mn_get wait for mmap_sem killable
@ 2016-02-29 13:35     ` Christian König
  0 siblings, 0 replies; 234+ messages in thread
From: Christian König @ 2016-02-29 13:35 UTC (permalink / raw)
  To: Michal Hocko, LKML; +Cc: dri-devel, linux-mm, linux-arch

[Dropping CCing the individual people, but adding the dri-devel mailing 
list as well instead].

Am 29.02.2016 um 14:26 schrieb Michal Hocko:
> From: Michal Hocko <mhocko@suse.com>
>
> radeon_mn_get which is called during ioct path relies on mmap_sem for
> write. If the waiting task gets killed by the oom killer it would block
> oom_reaper from asynchronous address space reclaim and reduce the
> chances of timely OOM resolving. Wait for the lock in the killable mode
> and return with EINTR if the task got killed while waiting.
>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: "Christian König" <christian.koenig@amd.com>
> Cc: David Airlie <airlied@linux.ie>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

This one and patch #18 in this series are Reviewed-by: Christian König 
<christian.koenig@amd.com>.

Nice to see some improvements on this side,
Christian.

> ---
>   drivers/gpu/drm/radeon/radeon_mn.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c
> index eef006c48584..896f2cf51e4e 100644
> --- a/drivers/gpu/drm/radeon/radeon_mn.c
> +++ b/drivers/gpu/drm/radeon/radeon_mn.c
> @@ -186,7 +186,9 @@ static struct radeon_mn *radeon_mn_get(struct radeon_device *rdev)
>   	struct radeon_mn *rmn;
>   	int r;
>   
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return ERR_PTR(-EINTR);
> +
>   	mutex_lock(&rdev->mn_lock);
>   
>   	hash_for_each_possible(rdev->mn_hash, rmn, node, (unsigned long)mm)


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

* Re: [PATCH 17/18] drm/radeon: make radeon_mn_get wait for mmap_sem killable
@ 2016-02-29 13:35     ` Christian König
  0 siblings, 0 replies; 234+ messages in thread
From: Christian König @ 2016-02-29 13:35 UTC (permalink / raw)
  To: Michal Hocko, LKML; +Cc: dri-devel, linux-mm, linux-arch

[Dropping CCing the individual people, but adding the dri-devel mailing 
list as well instead].

Am 29.02.2016 um 14:26 schrieb Michal Hocko:
> From: Michal Hocko <mhocko@suse.com>
>
> radeon_mn_get which is called during ioct path relies on mmap_sem for
> write. If the waiting task gets killed by the oom killer it would block
> oom_reaper from asynchronous address space reclaim and reduce the
> chances of timely OOM resolving. Wait for the lock in the killable mode
> and return with EINTR if the task got killed while waiting.
>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: "Christian KA?nig" <christian.koenig@amd.com>
> Cc: David Airlie <airlied@linux.ie>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

This one and patch #18 in this series are Reviewed-by: Christian KA?nig 
<christian.koenig@amd.com>.

Nice to see some improvements on this side,
Christian.

> ---
>   drivers/gpu/drm/radeon/radeon_mn.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c
> index eef006c48584..896f2cf51e4e 100644
> --- a/drivers/gpu/drm/radeon/radeon_mn.c
> +++ b/drivers/gpu/drm/radeon/radeon_mn.c
> @@ -186,7 +186,9 @@ static struct radeon_mn *radeon_mn_get(struct radeon_device *rdev)
>   	struct radeon_mn *rmn;
>   	int r;
>   
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return ERR_PTR(-EINTR);
> +
>   	mutex_lock(&rdev->mn_lock);
>   
>   	hash_for_each_possible(rdev->mn_hash, rmn, node, (unsigned long)mm)

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

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

* Re: [PATCH 01/18] mm: Make mmap_sem for write waits killable for mm syscalls
  2016-02-29 13:26   ` Michal Hocko
@ 2016-02-29 13:44     ` kbuild test robot
  -1 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 13:44 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, linux-mm, Alex Deucher,
	Alex Thorlton, Andrea Arcangeli, Andy Lutomirski,
	Benjamin LaHaise, Christian König, Daniel Vetter,
	Dave Hansen, David Airlie, Davidlohr Bueso, David Rientjes,
	H . Peter Anvin, Hugh Dickins, Ingo Molnar, Johannes Weiner,
	Kirill A . Shutemov, Konstantin Khlebnikov, linux-arch,
	Mel Gorman, Oleg Nesterov, Peter Zijlstra, Petr Cermak,
	Thomas Gleixner, Michal Hocko

[-- Attachment #1: Type: text/plain, Size: 2478 bytes --]

Hi Michal,

[auto build test ERROR on next-20160229]
[also build test ERROR on v4.5-rc6]
[cannot apply to drm/drm-next drm-intel/for-linux-next v4.5-rc6 v4.5-rc5 v4.5-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/change-mmap_sem-taken-for-write-killable/20160229-213258
config: i386-randconfig-x004-201609 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   mm/util.c: In function 'vm_mmap_pgoff':
>> mm/util.c:331:8: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
       if (down_write_killable(&mm->mmap_sem))
           ^
   cc1: some warnings being treated as errors
--
   mm/mlock.c: In function 'do_mlock':
>> mm/mlock.c:638:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&current->mm->mmap_sem))
         ^
   cc1: some warnings being treated as errors
--
   mm/mmap.c: In function 'SYSC_brk':
>> mm/mmap.c:185:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&mm->mmap_sem))
         ^
   cc1: some warnings being treated as errors
--
   mm/mprotect.c: In function 'SYSC_mprotect':
>> mm/mprotect.c:381:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&current->mm->mmap_sem))
         ^
   cc1: some warnings being treated as errors
--
   mm/mremap.c: In function 'SYSC_mremap':
>> mm/mremap.c:505:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&current->mm->mmap_sem))
         ^
   cc1: some warnings being treated as errors

vim +/down_write_killable +331 mm/util.c

   325		struct mm_struct *mm = current->mm;
   326		unsigned long populate;
   327	
   328		ret = security_mmap_file(file, prot, flag);
   329		if (!ret) {
   330			if (killable) {
 > 331				if (down_write_killable(&mm->mmap_sem))
   332					return -EINTR;
   333			} else {
   334				down_write(&mm->mmap_sem);

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 30172 bytes --]

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

* Re: [PATCH 01/18] mm: Make mmap_sem for write waits killable for mm syscalls
@ 2016-02-29 13:44     ` kbuild test robot
  0 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 13:44 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, linux-mm, Alex Deucher,
	Alex Thorlton, Andrea Arcangeli, Andy Lutomirski,
	Benjamin LaHaise, Christian König, Daniel Vetter,
	Dave Hansen, David Airlie, Davidlohr Bueso, David Rientjes,
	H . Peter Anvin, Hugh Dickins, Ingo Molnar, Johannes Weiner,
	Kirill A . Shutemov, Konstantin Khlebnikov, linux-arch,
	Mel Gorman

[-- Attachment #1: Type: text/plain, Size: 2478 bytes --]

Hi Michal,

[auto build test ERROR on next-20160229]
[also build test ERROR on v4.5-rc6]
[cannot apply to drm/drm-next drm-intel/for-linux-next v4.5-rc6 v4.5-rc5 v4.5-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/change-mmap_sem-taken-for-write-killable/20160229-213258
config: i386-randconfig-x004-201609 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   mm/util.c: In function 'vm_mmap_pgoff':
>> mm/util.c:331:8: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
       if (down_write_killable(&mm->mmap_sem))
           ^
   cc1: some warnings being treated as errors
--
   mm/mlock.c: In function 'do_mlock':
>> mm/mlock.c:638:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&current->mm->mmap_sem))
         ^
   cc1: some warnings being treated as errors
--
   mm/mmap.c: In function 'SYSC_brk':
>> mm/mmap.c:185:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&mm->mmap_sem))
         ^
   cc1: some warnings being treated as errors
--
   mm/mprotect.c: In function 'SYSC_mprotect':
>> mm/mprotect.c:381:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&current->mm->mmap_sem))
         ^
   cc1: some warnings being treated as errors
--
   mm/mremap.c: In function 'SYSC_mremap':
>> mm/mremap.c:505:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&current->mm->mmap_sem))
         ^
   cc1: some warnings being treated as errors

vim +/down_write_killable +331 mm/util.c

   325		struct mm_struct *mm = current->mm;
   326		unsigned long populate;
   327	
   328		ret = security_mmap_file(file, prot, flag);
   329		if (!ret) {
   330			if (killable) {
 > 331				if (down_write_killable(&mm->mmap_sem))
   332					return -EINTR;
   333			} else {
   334				down_write(&mm->mmap_sem);

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 30172 bytes --]

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

* Re: [PATCH 01/18] mm: Make mmap_sem for write waits killable for mm syscalls
  2016-02-29 13:26   ` Michal Hocko
@ 2016-02-29 13:44     ` kbuild test robot
  -1 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 13:44 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, linux-mm, Alex Deucher,
	Alex Thorlton, Andrea Arcangeli, Andy Lutomirski,
	Benjamin LaHaise, Christian König, Daniel Vetter,
	Dave Hansen, David Airlie, Davidlohr Bueso, David Rientjes,
	H . Peter Anvin, Hugh Dickins, Ingo Molnar, Johannes Weiner,
	Kirill A . Shutemov, Konstantin Khlebnikov, linux-arch,
	Mel Gorman, Oleg Nesterov, Peter Zijlstra, Petr Cermak,
	Thomas Gleixner, Michal Hocko

[-- Attachment #1: Type: text/plain, Size: 6807 bytes --]

Hi Michal,

[auto build test WARNING on next-20160229]
[also build test WARNING on v4.5-rc6]
[cannot apply to drm/drm-next drm-intel/for-linux-next v4.5-rc6 v4.5-rc5 v4.5-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/change-mmap_sem-taken-for-write-killable/20160229-213258
config: i386-randconfig-x003-201609 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

   In file included from include/asm-generic/bug.h:4:0,
                    from arch/x86/include/asm/bug.h:35,
                    from include/linux/bug.h:4,
                    from include/linux/mmdebug.h:4,
                    from include/linux/mm.h:8,
                    from mm/util.c:1:
   mm/util.c: In function 'vm_mmap_pgoff':
   mm/util.c:331:8: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
       if (down_write_killable(&mm->mmap_sem))
           ^
   include/linux/compiler.h:151:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^
>> mm/util.c:331:4: note: in expansion of macro 'if'
       if (down_write_killable(&mm->mmap_sem))
       ^
   cc1: some warnings being treated as errors
--
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/uapi/linux/capability.h:16,
                    from include/linux/capability.h:15,
                    from mm/mlock.c:8:
   mm/mlock.c: In function 'do_mlock':
   mm/mlock.c:638:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&current->mm->mmap_sem))
         ^
   include/linux/compiler.h:151:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^
>> mm/mlock.c:638:2: note: in expansion of macro 'if'
     if (down_write_killable(&current->mm->mmap_sem))
     ^
   cc1: some warnings being treated as errors
--
   In file included from include/linux/linkage.h:4:0,
                    from include/linux/kernel.h:6,
                    from mm/mmap.c:11:
   mm/mmap.c: In function 'SYSC_brk':
   mm/mmap.c:185:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&mm->mmap_sem))
         ^
   include/linux/compiler.h:151:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^
>> mm/mmap.c:185:2: note: in expansion of macro 'if'
     if (down_write_killable(&mm->mmap_sem))
     ^
   cc1: some warnings being treated as errors
--
   In file included from include/asm-generic/bug.h:4:0,
                    from arch/x86/include/asm/bug.h:35,
                    from include/linux/bug.h:4,
                    from include/linux/mmdebug.h:4,
                    from include/linux/mm.h:8,
                    from mm/mprotect.c:11:
   mm/mprotect.c: In function 'SYSC_mprotect':
   mm/mprotect.c:381:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&current->mm->mmap_sem))
         ^
   include/linux/compiler.h:151:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^
>> mm/mprotect.c:381:2: note: in expansion of macro 'if'
     if (down_write_killable(&current->mm->mmap_sem))
     ^
   cc1: some warnings being treated as errors
--
   In file included from include/asm-generic/bug.h:4:0,
                    from arch/x86/include/asm/bug.h:35,
                    from include/linux/bug.h:4,
                    from include/linux/mmdebug.h:4,
                    from include/linux/mm.h:8,
                    from mm/mremap.c:10:
   mm/mremap.c: In function 'SYSC_mremap':
   mm/mremap.c:505:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&current->mm->mmap_sem))
         ^
   include/linux/compiler.h:151:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^
>> mm/mremap.c:505:2: note: in expansion of macro 'if'
     if (down_write_killable(&current->mm->mmap_sem))
     ^
   cc1: some warnings being treated as errors
--
   In file included from include/asm-generic/bug.h:4:0,
                    from arch/x86/include/asm/bug.h:35,
                    from include/linux/bug.h:4,
                    from include/linux/mmdebug.h:4,
                    from include/linux/mm.h:8,
                    from include/linux/mman.h:4,
                    from mm/madvise.c:8:
   mm/madvise.c: In function 'SYSC_madvise':
   mm/madvise.c:768:7: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
      if (down_write_killable(&current->mm->mmap_sem))
          ^
   include/linux/compiler.h:151:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^
>> mm/madvise.c:768:3: note: in expansion of macro 'if'
      if (down_write_killable(&current->mm->mmap_sem))
      ^
   cc1: some warnings being treated as errors

vim +/if +331 mm/util.c

   315	{
   316		return get_user_pages_unlocked(start, nr_pages, write, 0, pages);
   317	}
   318	EXPORT_SYMBOL_GPL(get_user_pages_fast);
   319	
   320	unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
   321		unsigned long len, unsigned long prot,
   322		unsigned long flag, unsigned long pgoff, bool killable)
   323	{
   324		unsigned long ret;
   325		struct mm_struct *mm = current->mm;
   326		unsigned long populate;
   327	
   328		ret = security_mmap_file(file, prot, flag);
   329		if (!ret) {
   330			if (killable) {
 > 331				if (down_write_killable(&mm->mmap_sem))
   332					return -EINTR;
   333			} else {
   334				down_write(&mm->mmap_sem);
   335			}
   336			ret = do_mmap_pgoff(file, addr, len, prot, flag, pgoff,
   337					    &populate);
   338			up_write(&mm->mmap_sem);
   339			if (populate)

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 21680 bytes --]

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

* Re: [PATCH 01/18] mm: Make mmap_sem for write waits killable for mm syscalls
@ 2016-02-29 13:44     ` kbuild test robot
  0 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 13:44 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, linux-mm, Alex Deucher,
	Alex Thorlton, Andrea Arcangeli, Andy Lutomirski,
	Benjamin LaHaise, Christian König, Daniel Vetter,
	Dave Hansen, David Airlie, Davidlohr Bueso, David Rientjes,
	H . Peter Anvin, Hugh Dickins, Ingo Molnar, Johannes Weiner,
	Kirill A . Shutemov, Konstantin Khlebnikov, linux-arch,
	Mel Gorman

[-- Attachment #1: Type: text/plain, Size: 6807 bytes --]

Hi Michal,

[auto build test WARNING on next-20160229]
[also build test WARNING on v4.5-rc6]
[cannot apply to drm/drm-next drm-intel/for-linux-next v4.5-rc6 v4.5-rc5 v4.5-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/change-mmap_sem-taken-for-write-killable/20160229-213258
config: i386-randconfig-x003-201609 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

   In file included from include/asm-generic/bug.h:4:0,
                    from arch/x86/include/asm/bug.h:35,
                    from include/linux/bug.h:4,
                    from include/linux/mmdebug.h:4,
                    from include/linux/mm.h:8,
                    from mm/util.c:1:
   mm/util.c: In function 'vm_mmap_pgoff':
   mm/util.c:331:8: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
       if (down_write_killable(&mm->mmap_sem))
           ^
   include/linux/compiler.h:151:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^
>> mm/util.c:331:4: note: in expansion of macro 'if'
       if (down_write_killable(&mm->mmap_sem))
       ^
   cc1: some warnings being treated as errors
--
   In file included from include/uapi/linux/stddef.h:1:0,
                    from include/linux/stddef.h:4,
                    from include/uapi/linux/posix_types.h:4,
                    from include/uapi/linux/types.h:13,
                    from include/linux/types.h:5,
                    from include/uapi/linux/capability.h:16,
                    from include/linux/capability.h:15,
                    from mm/mlock.c:8:
   mm/mlock.c: In function 'do_mlock':
   mm/mlock.c:638:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&current->mm->mmap_sem))
         ^
   include/linux/compiler.h:151:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^
>> mm/mlock.c:638:2: note: in expansion of macro 'if'
     if (down_write_killable(&current->mm->mmap_sem))
     ^
   cc1: some warnings being treated as errors
--
   In file included from include/linux/linkage.h:4:0,
                    from include/linux/kernel.h:6,
                    from mm/mmap.c:11:
   mm/mmap.c: In function 'SYSC_brk':
   mm/mmap.c:185:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&mm->mmap_sem))
         ^
   include/linux/compiler.h:151:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^
>> mm/mmap.c:185:2: note: in expansion of macro 'if'
     if (down_write_killable(&mm->mmap_sem))
     ^
   cc1: some warnings being treated as errors
--
   In file included from include/asm-generic/bug.h:4:0,
                    from arch/x86/include/asm/bug.h:35,
                    from include/linux/bug.h:4,
                    from include/linux/mmdebug.h:4,
                    from include/linux/mm.h:8,
                    from mm/mprotect.c:11:
   mm/mprotect.c: In function 'SYSC_mprotect':
   mm/mprotect.c:381:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&current->mm->mmap_sem))
         ^
   include/linux/compiler.h:151:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^
>> mm/mprotect.c:381:2: note: in expansion of macro 'if'
     if (down_write_killable(&current->mm->mmap_sem))
     ^
   cc1: some warnings being treated as errors
--
   In file included from include/asm-generic/bug.h:4:0,
                    from arch/x86/include/asm/bug.h:35,
                    from include/linux/bug.h:4,
                    from include/linux/mmdebug.h:4,
                    from include/linux/mm.h:8,
                    from mm/mremap.c:10:
   mm/mremap.c: In function 'SYSC_mremap':
   mm/mremap.c:505:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&current->mm->mmap_sem))
         ^
   include/linux/compiler.h:151:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^
>> mm/mremap.c:505:2: note: in expansion of macro 'if'
     if (down_write_killable(&current->mm->mmap_sem))
     ^
   cc1: some warnings being treated as errors
--
   In file included from include/asm-generic/bug.h:4:0,
                    from arch/x86/include/asm/bug.h:35,
                    from include/linux/bug.h:4,
                    from include/linux/mmdebug.h:4,
                    from include/linux/mm.h:8,
                    from include/linux/mman.h:4,
                    from mm/madvise.c:8:
   mm/madvise.c: In function 'SYSC_madvise':
   mm/madvise.c:768:7: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
      if (down_write_killable(&current->mm->mmap_sem))
          ^
   include/linux/compiler.h:151:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^
>> mm/madvise.c:768:3: note: in expansion of macro 'if'
      if (down_write_killable(&current->mm->mmap_sem))
      ^
   cc1: some warnings being treated as errors

vim +/if +331 mm/util.c

   315	{
   316		return get_user_pages_unlocked(start, nr_pages, write, 0, pages);
   317	}
   318	EXPORT_SYMBOL_GPL(get_user_pages_fast);
   319	
   320	unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
   321		unsigned long len, unsigned long prot,
   322		unsigned long flag, unsigned long pgoff, bool killable)
   323	{
   324		unsigned long ret;
   325		struct mm_struct *mm = current->mm;
   326		unsigned long populate;
   327	
   328		ret = security_mmap_file(file, prot, flag);
   329		if (!ret) {
   330			if (killable) {
 > 331				if (down_write_killable(&mm->mmap_sem))
   332					return -EINTR;
   333			} else {
   334				down_write(&mm->mmap_sem);
   335			}
   336			ret = do_mmap_pgoff(file, addr, len, prot, flag, pgoff,
   337					    &populate);
   338			up_write(&mm->mmap_sem);
   339			if (populate)

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 21680 bytes --]

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

* Re: [PATCH 10/18] vdso: make arch_setup_additional_pages wait for mmap_sem for write killable
  2016-02-29 13:26   ` Michal Hocko
@ 2016-02-29 13:45     ` kbuild test robot
  -1 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 13:45 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, linux-mm, Alex Deucher,
	Alex Thorlton, Andrea Arcangeli, Andy Lutomirski,
	Benjamin LaHaise, Christian König, Daniel Vetter,
	Dave Hansen, David Airlie, Davidlohr Bueso, David Rientjes,
	H . Peter Anvin, Hugh Dickins, Ingo Molnar, Johannes Weiner,
	Kirill A . Shutemov, Konstantin Khlebnikov, linux-arch,
	Mel Gorman, Oleg Nesterov, Peter Zijlstra, Petr Cermak,
	Thomas Gleixner, Michal Hocko

[-- Attachment #1: Type: text/plain, Size: 1377 bytes --]

Hi Michal,

[auto build test ERROR on next-20160229]
[also build test ERROR on v4.5-rc6]
[cannot apply to drm/drm-next drm-intel/for-linux-next v4.5-rc6 v4.5-rc5 v4.5-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/change-mmap_sem-taken-for-write-killable/20160229-213258
config: i386-randconfig-x004-201609 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   arch/x86/entry/vdso/vma.c: In function 'map_vdso':
>> arch/x86/entry/vdso/vma.c:177:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&mm->mmap_sem))
         ^
   cc1: some warnings being treated as errors

vim +/down_write_killable +177 arch/x86/entry/vdso/vma.c

   171			addr = vdso_addr(current->mm->start_stack,
   172					 image->size - image->sym_vvar_start);
   173		} else {
   174			addr = 0;
   175		}
   176	
 > 177		if (down_write_killable(&mm->mmap_sem))
   178			return -EINTR;
   179	
   180		addr = get_unmapped_area(NULL, addr,

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 30172 bytes --]

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

* Re: [PATCH 10/18] vdso: make arch_setup_additional_pages wait for mmap_sem for write killable
@ 2016-02-29 13:45     ` kbuild test robot
  0 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 13:45 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, linux-mm, Alex Deucher,
	Alex Thorlton, Andrea Arcangeli, Andy Lutomirski,
	Benjamin LaHaise, Christian König, Daniel Vetter,
	Dave Hansen, David Airlie, Davidlohr Bueso, David Rientjes,
	H . Peter Anvin, Hugh Dickins, Ingo Molnar, Johannes Weiner,
	Kirill A . Shutemov, Konstantin Khlebnikov, linux-arch,
	Mel Gorman

[-- Attachment #1: Type: text/plain, Size: 1377 bytes --]

Hi Michal,

[auto build test ERROR on next-20160229]
[also build test ERROR on v4.5-rc6]
[cannot apply to drm/drm-next drm-intel/for-linux-next v4.5-rc6 v4.5-rc5 v4.5-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/change-mmap_sem-taken-for-write-killable/20160229-213258
config: i386-randconfig-x004-201609 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   arch/x86/entry/vdso/vma.c: In function 'map_vdso':
>> arch/x86/entry/vdso/vma.c:177:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&mm->mmap_sem))
         ^
   cc1: some warnings being treated as errors

vim +/down_write_killable +177 arch/x86/entry/vdso/vma.c

   171			addr = vdso_addr(current->mm->start_stack,
   172					 image->size - image->sym_vvar_start);
   173		} else {
   174			addr = 0;
   175		}
   176	
 > 177		if (down_write_killable(&mm->mmap_sem))
   178			return -EINTR;
   179	
   180		addr = get_unmapped_area(NULL, addr,

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 30172 bytes --]

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

* Re: [PATCH 07/18] mm, proc: make clear_refs killable
  2016-02-29 13:26   ` Michal Hocko
@ 2016-02-29 13:47     ` kbuild test robot
  -1 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 13:47 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, linux-mm, Alex Deucher,
	Alex Thorlton, Andrea Arcangeli, Andy Lutomirski,
	Benjamin LaHaise, Christian König, Daniel Vetter,
	Dave Hansen, David Airlie, Davidlohr Bueso, David Rientjes,
	H . Peter Anvin, Hugh Dickins, Ingo Molnar, Johannes Weiner,
	Kirill A . Shutemov, Konstantin Khlebnikov, linux-arch,
	Mel Gorman, Oleg Nesterov, Peter Zijlstra, Petr Cermak,
	Thomas Gleixner, Michal Hocko

[-- Attachment #1: Type: text/plain, Size: 2431 bytes --]

Hi Michal,

[auto build test WARNING on next-20160229]
[also build test WARNING on v4.5-rc6]
[cannot apply to drm/drm-next drm-intel/for-linux-next v4.5-rc6 v4.5-rc5 v4.5-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/change-mmap_sem-taken-for-write-killable/20160229-213258
config: i386-randconfig-x003-201609 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

   In file included from include/asm-generic/bug.h:4:0,
                    from arch/x86/include/asm/bug.h:35,
                    from include/linux/bug.h:4,
                    from include/linux/mmdebug.h:4,
                    from include/linux/mm.h:8,
                    from fs/proc/task_mmu.c:1:
   fs/proc/task_mmu.c: In function 'clear_refs_write':
   fs/proc/task_mmu.c:1030:8: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
       if (down_write_killable(&mm->mmap_sem)) {
           ^
   include/linux/compiler.h:151:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^
>> fs/proc/task_mmu.c:1030:4: note: in expansion of macro 'if'
       if (down_write_killable(&mm->mmap_sem)) {
       ^
   cc1: some warnings being treated as errors

vim +/if +1030 fs/proc/task_mmu.c

  1014		task = get_proc_task(file_inode(file));
  1015		if (!task)
  1016			return -ESRCH;
  1017		mm = get_task_mm(task);
  1018		if (mm) {
  1019			struct clear_refs_private cp = {
  1020				.type = type,
  1021			};
  1022			struct mm_walk clear_refs_walk = {
  1023				.pmd_entry = clear_refs_pte_range,
  1024				.test_walk = clear_refs_test_walk,
  1025				.mm = mm,
  1026				.private = &cp,
  1027			};
  1028	
  1029			if (type == CLEAR_REFS_MM_HIWATER_RSS) {
> 1030				if (down_write_killable(&mm->mmap_sem)) {
  1031					put_task_struct(task);
  1032					return -EINTR;
  1033				}
  1034	
  1035				/*
  1036				 * Writing 5 to /proc/pid/clear_refs resets the peak
  1037				 * resident set size to this mm's current rss value.
  1038				 */

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 21680 bytes --]

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

* Re: [PATCH 07/18] mm, proc: make clear_refs killable
@ 2016-02-29 13:47     ` kbuild test robot
  0 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 13:47 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, linux-mm, Alex Deucher,
	Alex Thorlton, Andrea Arcangeli, Andy Lutomirski,
	Benjamin LaHaise, Christian König, Daniel Vetter,
	Dave Hansen, David Airlie, Davidlohr Bueso, David Rientjes,
	H . Peter Anvin, Hugh Dickins, Ingo Molnar, Johannes Weiner,
	Kirill A . Shutemov, Konstantin Khlebnikov, linux-arch,
	Mel Gorman

[-- Attachment #1: Type: text/plain, Size: 2431 bytes --]

Hi Michal,

[auto build test WARNING on next-20160229]
[also build test WARNING on v4.5-rc6]
[cannot apply to drm/drm-next drm-intel/for-linux-next v4.5-rc6 v4.5-rc5 v4.5-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/change-mmap_sem-taken-for-write-killable/20160229-213258
config: i386-randconfig-x003-201609 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

   In file included from include/asm-generic/bug.h:4:0,
                    from arch/x86/include/asm/bug.h:35,
                    from include/linux/bug.h:4,
                    from include/linux/mmdebug.h:4,
                    from include/linux/mm.h:8,
                    from fs/proc/task_mmu.c:1:
   fs/proc/task_mmu.c: In function 'clear_refs_write':
   fs/proc/task_mmu.c:1030:8: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
       if (down_write_killable(&mm->mmap_sem)) {
           ^
   include/linux/compiler.h:151:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^
>> fs/proc/task_mmu.c:1030:4: note: in expansion of macro 'if'
       if (down_write_killable(&mm->mmap_sem)) {
       ^
   cc1: some warnings being treated as errors

vim +/if +1030 fs/proc/task_mmu.c

  1014		task = get_proc_task(file_inode(file));
  1015		if (!task)
  1016			return -ESRCH;
  1017		mm = get_task_mm(task);
  1018		if (mm) {
  1019			struct clear_refs_private cp = {
  1020				.type = type,
  1021			};
  1022			struct mm_walk clear_refs_walk = {
  1023				.pmd_entry = clear_refs_pte_range,
  1024				.test_walk = clear_refs_test_walk,
  1025				.mm = mm,
  1026				.private = &cp,
  1027			};
  1028	
  1029			if (type == CLEAR_REFS_MM_HIWATER_RSS) {
> 1030				if (down_write_killable(&mm->mmap_sem)) {
  1031					put_task_struct(task);
  1032					return -EINTR;
  1033				}
  1034	
  1035				/*
  1036				 * Writing 5 to /proc/pid/clear_refs resets the peak
  1037				 * resident set size to this mm's current rss value.
  1038				 */

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 21680 bytes --]

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

* Re: [PATCH 08/18] mm, fork: make dup_mmap wait for mmap_sem for write killable
  2016-02-29 13:26   ` Michal Hocko
@ 2016-02-29 13:48     ` kbuild test robot
  -1 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 13:48 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, linux-mm, Alex Deucher,
	Alex Thorlton, Andrea Arcangeli, Andy Lutomirski,
	Benjamin LaHaise, Christian König, Daniel Vetter,
	Dave Hansen, David Airlie, Davidlohr Bueso, David Rientjes,
	H . Peter Anvin, Hugh Dickins, Ingo Molnar, Johannes Weiner,
	Kirill A . Shutemov, Konstantin Khlebnikov, linux-arch,
	Mel Gorman, Oleg Nesterov, Peter Zijlstra, Petr Cermak,
	Thomas Gleixner, Michal Hocko

[-- Attachment #1: Type: text/plain, Size: 1380 bytes --]

Hi Michal,

[auto build test ERROR on next-20160229]
[also build test ERROR on v4.5-rc6]
[cannot apply to drm/drm-next drm-intel/for-linux-next v4.5-rc6 v4.5-rc5 v4.5-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/change-mmap_sem-taken-for-write-killable/20160229-213258
config: i386-randconfig-x004-201609 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   kernel/fork.c: In function 'dup_mmap':
>> kernel/fork.c:416:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&oldmm->mmap_sem)) {
         ^
   cc1: some warnings being treated as errors

vim +/down_write_killable +416 kernel/fork.c

   410		struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
   411		struct rb_node **rb_link, *rb_parent;
   412		int retval;
   413		unsigned long charge;
   414	
   415		uprobe_start_dup_mmap();
 > 416		if (down_write_killable(&oldmm->mmap_sem)) {
   417			uprobe_end_dup_mmap();
   418			return -EINTR;
   419		}

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 30172 bytes --]

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

* Re: [PATCH 08/18] mm, fork: make dup_mmap wait for mmap_sem for write killable
@ 2016-02-29 13:48     ` kbuild test robot
  0 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 13:48 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, linux-mm, Alex Deucher,
	Alex Thorlton, Andrea Arcangeli, Andy Lutomirski,
	Benjamin LaHaise, Christian König, Daniel Vetter,
	Dave Hansen, David Airlie, Davidlohr Bueso, David Rientjes,
	H . Peter Anvin, Hugh Dickins, Ingo Molnar, Johannes Weiner,
	Kirill A . Shutemov, Konstantin Khlebnikov, linux-arch,
	Mel Gorman

[-- Attachment #1: Type: text/plain, Size: 1380 bytes --]

Hi Michal,

[auto build test ERROR on next-20160229]
[also build test ERROR on v4.5-rc6]
[cannot apply to drm/drm-next drm-intel/for-linux-next v4.5-rc6 v4.5-rc5 v4.5-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/change-mmap_sem-taken-for-write-killable/20160229-213258
config: i386-randconfig-x004-201609 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   kernel/fork.c: In function 'dup_mmap':
>> kernel/fork.c:416:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&oldmm->mmap_sem)) {
         ^
   cc1: some warnings being treated as errors

vim +/down_write_killable +416 kernel/fork.c

   410		struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
   411		struct rb_node **rb_link, *rb_parent;
   412		int retval;
   413		unsigned long charge;
   414	
   415		uprobe_start_dup_mmap();
 > 416		if (down_write_killable(&oldmm->mmap_sem)) {
   417			uprobe_end_dup_mmap();
   418			return -EINTR;
   419		}

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 30172 bytes --]

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

* Re: [PATCH 10/18] vdso: make arch_setup_additional_pages wait for mmap_sem for write killable
  2016-02-29 13:26   ` Michal Hocko
@ 2016-02-29 13:50     ` kbuild test robot
  -1 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 13:50 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, linux-mm, Alex Deucher,
	Alex Thorlton, Andrea Arcangeli, Andy Lutomirski,
	Benjamin LaHaise, Christian König, Daniel Vetter,
	Dave Hansen, David Airlie, Davidlohr Bueso, David Rientjes,
	H . Peter Anvin, Hugh Dickins, Ingo Molnar, Johannes Weiner,
	Kirill A . Shutemov, Konstantin Khlebnikov, linux-arch,
	Mel Gorman, Oleg Nesterov, Peter Zijlstra, Petr Cermak,
	Thomas Gleixner, Michal Hocko

[-- Attachment #1: Type: text/plain, Size: 1676 bytes --]

Hi Michal,

[auto build test ERROR on next-20160229]
[also build test ERROR on v4.5-rc6]
[cannot apply to drm/drm-next drm-intel/for-linux-next v4.5-rc6 v4.5-rc5 v4.5-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/change-mmap_sem-taken-for-write-killable/20160229-213258
config: s390-allyesconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=s390 

All errors (new ones prefixed by >>):

   arch/s390/kernel/vdso.c: In function 'arch_setup_additional_pages':
>> arch/s390/kernel/vdso.c:219:2: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&mm->mmap_sem))
     ^
   cc1: some warnings being treated as errors

vim +/down_write_killable +219 arch/s390/kernel/vdso.c

   213	
   214		/*
   215		 * pick a base address for the vDSO in process space. We try to put
   216		 * it at vdso_base which is the "natural" base for it, but we might
   217		 * fail and end up putting it elsewhere.
   218		 */
 > 219		if (down_write_killable(&mm->mmap_sem))
   220			return -EINTR;
   221		vdso_base = get_unmapped_area(NULL, 0, vdso_pages << PAGE_SHIFT, 0, 0);
   222		if (IS_ERR_VALUE(vdso_base)) {

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 40506 bytes --]

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

* Re: [PATCH 10/18] vdso: make arch_setup_additional_pages wait for mmap_sem for write killable
@ 2016-02-29 13:50     ` kbuild test robot
  0 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 13:50 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, linux-mm, Alex Deucher,
	Alex Thorlton, Andrea Arcangeli, Andy Lutomirski,
	Benjamin LaHaise, Christian König, Daniel Vetter,
	Dave Hansen, David Airlie, Davidlohr Bueso, David Rientjes,
	H . Peter Anvin, Hugh Dickins, Ingo Molnar, Johannes Weiner,
	Kirill A . Shutemov, Konstantin Khlebnikov, linux-arch,
	Mel Gorman

[-- Attachment #1: Type: text/plain, Size: 1676 bytes --]

Hi Michal,

[auto build test ERROR on next-20160229]
[also build test ERROR on v4.5-rc6]
[cannot apply to drm/drm-next drm-intel/for-linux-next v4.5-rc6 v4.5-rc5 v4.5-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/change-mmap_sem-taken-for-write-killable/20160229-213258
config: s390-allyesconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=s390 

All errors (new ones prefixed by >>):

   arch/s390/kernel/vdso.c: In function 'arch_setup_additional_pages':
>> arch/s390/kernel/vdso.c:219:2: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&mm->mmap_sem))
     ^
   cc1: some warnings being treated as errors

vim +/down_write_killable +219 arch/s390/kernel/vdso.c

   213	
   214		/*
   215		 * pick a base address for the vDSO in process space. We try to put
   216		 * it at vdso_base which is the "natural" base for it, but we might
   217		 * fail and end up putting it elsewhere.
   218		 */
 > 219		if (down_write_killable(&mm->mmap_sem))
   220			return -EINTR;
   221		vdso_base = get_unmapped_area(NULL, 0, vdso_pages << PAGE_SHIFT, 0, 0);
   222		if (IS_ERR_VALUE(vdso_base)) {

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 40506 bytes --]

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

* Re: [PATCH 10/18] vdso: make arch_setup_additional_pages wait for mmap_sem for write killable
  2016-02-29 13:26   ` Michal Hocko
@ 2016-02-29 13:53     ` kbuild test robot
  -1 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 13:53 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, linux-mm, Alex Deucher,
	Alex Thorlton, Andrea Arcangeli, Andy Lutomirski,
	Benjamin LaHaise, Christian König, Daniel Vetter,
	Dave Hansen, David Airlie, Davidlohr Bueso, David Rientjes,
	H . Peter Anvin, Hugh Dickins, Ingo Molnar, Johannes Weiner,
	Kirill A . Shutemov, Konstantin Khlebnikov, linux-arch,
	Mel Gorman, Oleg Nesterov, Peter Zijlstra, Petr Cermak,
	Thomas Gleixner, Michal Hocko

[-- Attachment #1: Type: text/plain, Size: 1563 bytes --]

Hi Michal,

[auto build test ERROR on next-20160229]
[also build test ERROR on v4.5-rc6]
[cannot apply to drm/drm-next drm-intel/for-linux-next v4.5-rc6 v4.5-rc5 v4.5-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/change-mmap_sem-taken-for-write-killable/20160229-213258
config: mips-allyesconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=mips 

All errors (new ones prefixed by >>):

   arch/mips/kernel/vdso.c: In function 'arch_setup_additional_pages':
>> arch/mips/kernel/vdso.c:107:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&mm->mmap_sem))
         ^
   cc1: some warnings being treated as errors

vim +/down_write_killable +107 arch/mips/kernel/vdso.c

   101		struct mm_struct *mm = current->mm;
   102		unsigned long gic_size, vvar_size, size, base, data_addr, vdso_addr;
   103		struct vm_area_struct *vma;
   104		struct resource gic_res;
   105		int ret;
   106	
 > 107		if (down_write_killable(&mm->mmap_sem))
   108			return -EINTR;
   109	
   110		/*

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 41198 bytes --]

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

* Re: [PATCH 10/18] vdso: make arch_setup_additional_pages wait for mmap_sem for write killable
@ 2016-02-29 13:53     ` kbuild test robot
  0 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 13:53 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, linux-mm, Alex Deucher,
	Alex Thorlton, Andrea Arcangeli, Andy Lutomirski,
	Benjamin LaHaise, Christian König, Daniel Vetter,
	Dave Hansen, David Airlie, Davidlohr Bueso, David Rientjes,
	H . Peter Anvin, Hugh Dickins, Ingo Molnar, Johannes Weiner,
	Kirill A . Shutemov, Konstantin Khlebnikov, linux-arch,
	Mel Gorman

[-- Attachment #1: Type: text/plain, Size: 1563 bytes --]

Hi Michal,

[auto build test ERROR on next-20160229]
[also build test ERROR on v4.5-rc6]
[cannot apply to drm/drm-next drm-intel/for-linux-next v4.5-rc6 v4.5-rc5 v4.5-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/change-mmap_sem-taken-for-write-killable/20160229-213258
config: mips-allyesconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=mips 

All errors (new ones prefixed by >>):

   arch/mips/kernel/vdso.c: In function 'arch_setup_additional_pages':
>> arch/mips/kernel/vdso.c:107:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&mm->mmap_sem))
         ^
   cc1: some warnings being treated as errors

vim +/down_write_killable +107 arch/mips/kernel/vdso.c

   101		struct mm_struct *mm = current->mm;
   102		unsigned long gic_size, vvar_size, size, base, data_addr, vdso_addr;
   103		struct vm_area_struct *vma;
   104		struct resource gic_res;
   105		int ret;
   106	
 > 107		if (down_write_killable(&mm->mmap_sem))
   108			return -EINTR;
   109	
   110		/*

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 41198 bytes --]

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

* Re: [PATCH 0/18] change mmap_sem taken for write killable
  2016-02-29 13:26 ` Michal Hocko
  (?)
@ 2016-02-29 14:04   ` Kirill A. Shutemov
  -1 siblings, 0 replies; 234+ messages in thread
From: Kirill A. Shutemov @ 2016-02-29 14:04 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner

On Mon, Feb 29, 2016 at 02:26:39PM +0100, Michal Hocko wrote:
> Hi,
> this is a follow up work for oom_reaper [1]. As the async OOM killing
> depends on oom_sem for read we would really appreciate if a holder for
> write stood in the way. This patchset is changing many of down_write
> calls to be killable to help those cases when the writer is blocked and
> waiting for readers to release the lock and so help __oom_reap_task to
> process the oom victim.
> 
> Most of the patches are really trivial because the lock is help from a
> shallow syscall paths where we can return EINTR trivially. Others seem
> to be easy as well as the callers are already handling fatal errors and
> bail and return to userspace which should be sufficient to handle the
> failure gracefully. I am not familiar with all those code paths so a
> deeper review is really appreciated.

What about effect on userspace? IIUC, we would have now EINTR returned
from bunch of syscall, which haven't had this errno on the table before.
Should we care?

> As this work is touching more areas which are not directly connected I
> have tried to keep the CC list as small as possible and people who I
> believed would be familiar are CCed only to the specific patches (all
> should have received the cover though).
> 
> This patchset is based on linux-next and it depends on down_write_killable
> for rw_semaphores posted recently [2].
> 
> I haven't covered all the mmap_write(mm->mmap_sem) instances here
> 
> $ git grep "down_write(.*\<mmap_sem\>)" next/master | wc -l
> 102
> $ git grep "down_write(.*\<mmap_sem\>)" | wc -l
> 66
> 
> I have tried to cover those which should be relatively easy to review in
> this series because this alone should be a nice improvement. Other places
> can be changed on top.
> 
> Any feedback is highly appreciated.
> 
> ---
> [1] http://lkml.kernel.org/r/1452094975-551-1-git-send-email-mhocko@kernel.org
> [2] http://lkml.kernel.org/r/1456750705-7141-1-git-send-email-mhocko@kernel.org
> 
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org.  For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

-- 
 Kirill A. Shutemov

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

* Re: [PATCH 0/18] change mmap_sem taken for write killable
@ 2016-02-29 14:04   ` Kirill A. Shutemov
  0 siblings, 0 replies; 234+ messages in thread
From: Kirill A. Shutemov @ 2016-02-29 14:04 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov

On Mon, Feb 29, 2016 at 02:26:39PM +0100, Michal Hocko wrote:
> Hi,
> this is a follow up work for oom_reaper [1]. As the async OOM killing
> depends on oom_sem for read we would really appreciate if a holder for
> write stood in the way. This patchset is changing many of down_write
> calls to be killable to help those cases when the writer is blocked and
> waiting for readers to release the lock and so help __oom_reap_task to
> process the oom victim.
> 
> Most of the patches are really trivial because the lock is help from a
> shallow syscall paths where we can return EINTR trivially. Others seem
> to be easy as well as the callers are already handling fatal errors and
> bail and return to userspace which should be sufficient to handle the
> failure gracefully. I am not familiar with all those code paths so a
> deeper review is really appreciated.

What about effect on userspace? IIUC, we would have now EINTR returned
from bunch of syscall, which haven't had this errno on the table before.
Should we care?

> As this work is touching more areas which are not directly connected I
> have tried to keep the CC list as small as possible and people who I
> believed would be familiar are CCed only to the specific patches (all
> should have received the cover though).
> 
> This patchset is based on linux-next and it depends on down_write_killable
> for rw_semaphores posted recently [2].
> 
> I haven't covered all the mmap_write(mm->mmap_sem) instances here
> 
> $ git grep "down_write(.*\<mmap_sem\>)" next/master | wc -l
> 102
> $ git grep "down_write(.*\<mmap_sem\>)" | wc -l
> 66
> 
> I have tried to cover those which should be relatively easy to review in
> this series because this alone should be a nice improvement. Other places
> can be changed on top.
> 
> Any feedback is highly appreciated.
> 
> ---
> [1] http://lkml.kernel.org/r/1452094975-551-1-git-send-email-mhocko@kernel.org
> [2] http://lkml.kernel.org/r/1456750705-7141-1-git-send-email-mhocko@kernel.org
> 
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org.  For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

-- 
 Kirill A. Shutemov

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

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

* Re: [PATCH 0/18] change mmap_sem taken for write killable
@ 2016-02-29 14:04   ` Kirill A. Shutemov
  0 siblings, 0 replies; 234+ messages in thread
From: Kirill A. Shutemov @ 2016-02-29 14:04 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner

On Mon, Feb 29, 2016 at 02:26:39PM +0100, Michal Hocko wrote:
> Hi,
> this is a follow up work for oom_reaper [1]. As the async OOM killing
> depends on oom_sem for read we would really appreciate if a holder for
> write stood in the way. This patchset is changing many of down_write
> calls to be killable to help those cases when the writer is blocked and
> waiting for readers to release the lock and so help __oom_reap_task to
> process the oom victim.
> 
> Most of the patches are really trivial because the lock is help from a
> shallow syscall paths where we can return EINTR trivially. Others seem
> to be easy as well as the callers are already handling fatal errors and
> bail and return to userspace which should be sufficient to handle the
> failure gracefully. I am not familiar with all those code paths so a
> deeper review is really appreciated.

What about effect on userspace? IIUC, we would have now EINTR returned
from bunch of syscall, which haven't had this errno on the table before.
Should we care?

> As this work is touching more areas which are not directly connected I
> have tried to keep the CC list as small as possible and people who I
> believed would be familiar are CCed only to the specific patches (all
> should have received the cover though).
> 
> This patchset is based on linux-next and it depends on down_write_killable
> for rw_semaphores posted recently [2].
> 
> I haven't covered all the mmap_write(mm->mmap_sem) instances here
> 
> $ git grep "down_write(.*\<mmap_sem\>)" next/master | wc -l
> 102
> $ git grep "down_write(.*\<mmap_sem\>)" | wc -l
> 66
> 
> I have tried to cover those which should be relatively easy to review in
> this series because this alone should be a nice improvement. Other places
> can be changed on top.
> 
> Any feedback is highly appreciated.
> 
> ---
> [1] http://lkml.kernel.org/r/1452094975-551-1-git-send-email-mhocko@kernel.org
> [2] http://lkml.kernel.org/r/1456750705-7141-1-git-send-email-mhocko@kernel.org
> 
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org.  For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

-- 
 Kirill A. Shutemov

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

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

* Re: [PATCH 0/18] change mmap_sem taken for write killable
  2016-02-29 14:04   ` Kirill A. Shutemov
  (?)
@ 2016-02-29 14:16     ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 14:16 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner

On Mon 29-02-16 17:04:16, Kirill A. Shutemov wrote:
[...]
> > Most of the patches are really trivial because the lock is help from a
> > shallow syscall paths where we can return EINTR trivially. Others seem
> > to be easy as well as the callers are already handling fatal errors and
> > bail and return to userspace which should be sufficient to handle the
> > failure gracefully. I am not familiar with all those code paths so a
> > deeper review is really appreciated.
> 
> What about effect on userspace? IIUC, we would have now EINTR returned
> from bunch of syscall, which haven't had this errno on the table before.
> Should we care?

Those function will return EINTR only when the current was _killed_ when
we do not return to the userspace. So there shouldn't be any visible
effect.
-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 0/18] change mmap_sem taken for write killable
@ 2016-02-29 14:16     ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 14:16 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov

On Mon 29-02-16 17:04:16, Kirill A. Shutemov wrote:
[...]
> > Most of the patches are really trivial because the lock is help from a
> > shallow syscall paths where we can return EINTR trivially. Others seem
> > to be easy as well as the callers are already handling fatal errors and
> > bail and return to userspace which should be sufficient to handle the
> > failure gracefully. I am not familiar with all those code paths so a
> > deeper review is really appreciated.
> 
> What about effect on userspace? IIUC, we would have now EINTR returned
> from bunch of syscall, which haven't had this errno on the table before.
> Should we care?

Those function will return EINTR only when the current was _killed_ when
we do not return to the userspace. So there shouldn't be any visible
effect.
-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 0/18] change mmap_sem taken for write killable
@ 2016-02-29 14:16     ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 14:16 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner

On Mon 29-02-16 17:04:16, Kirill A. Shutemov wrote:
[...]
> > Most of the patches are really trivial because the lock is help from a
> > shallow syscall paths where we can return EINTR trivially. Others seem
> > to be easy as well as the callers are already handling fatal errors and
> > bail and return to userspace which should be sufficient to handle the
> > failure gracefully. I am not familiar with all those code paths so a
> > deeper review is really appreciated.
> 
> What about effect on userspace? IIUC, we would have now EINTR returned
> from bunch of syscall, which haven't had this errno on the table before.
> Should we care?

Those function will return EINTR only when the current was _killed_ when
we do not return to the userspace. So there shouldn't be any visible
effect.
-- 
Michal Hocko
SUSE Labs

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

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

* Re: [PATCH 0/18] change mmap_sem taken for write killable
  2016-02-29 14:16     ` Michal Hocko
  (?)
@ 2016-02-29 15:03       ` Kirill A. Shutemov
  -1 siblings, 0 replies; 234+ messages in thread
From: Kirill A. Shutemov @ 2016-02-29 15:03 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner

On Mon, Feb 29, 2016 at 03:16:22PM +0100, Michal Hocko wrote:
> On Mon 29-02-16 17:04:16, Kirill A. Shutemov wrote:
> [...]
> > > Most of the patches are really trivial because the lock is help from a
> > > shallow syscall paths where we can return EINTR trivially. Others seem
> > > to be easy as well as the callers are already handling fatal errors and
> > > bail and return to userspace which should be sufficient to handle the
> > > failure gracefully. I am not familiar with all those code paths so a
> > > deeper review is really appreciated.
> > 
> > What about effect on userspace? IIUC, we would have now EINTR returned
> > from bunch of syscall, which haven't had this errno on the table before.
> > Should we care?
> 
> Those function will return EINTR only when the current was _killed_ when
> we do not return to the userspace. So there shouldn't be any visible
> effect.

Ah. I confused killable with interruptible.

-- 
 Kirill A. Shutemov

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

* Re: [PATCH 0/18] change mmap_sem taken for write killable
@ 2016-02-29 15:03       ` Kirill A. Shutemov
  0 siblings, 0 replies; 234+ messages in thread
From: Kirill A. Shutemov @ 2016-02-29 15:03 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov

On Mon, Feb 29, 2016 at 03:16:22PM +0100, Michal Hocko wrote:
> On Mon 29-02-16 17:04:16, Kirill A. Shutemov wrote:
> [...]
> > > Most of the patches are really trivial because the lock is help from a
> > > shallow syscall paths where we can return EINTR trivially. Others seem
> > > to be easy as well as the callers are already handling fatal errors and
> > > bail and return to userspace which should be sufficient to handle the
> > > failure gracefully. I am not familiar with all those code paths so a
> > > deeper review is really appreciated.
> > 
> > What about effect on userspace? IIUC, we would have now EINTR returned
> > from bunch of syscall, which haven't had this errno on the table before.
> > Should we care?
> 
> Those function will return EINTR only when the current was _killed_ when
> we do not return to the userspace. So there shouldn't be any visible
> effect.

Ah. I confused killable with interruptible.

-- 
 Kirill A. Shutemov

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

* Re: [PATCH 0/18] change mmap_sem taken for write killable
@ 2016-02-29 15:03       ` Kirill A. Shutemov
  0 siblings, 0 replies; 234+ messages in thread
From: Kirill A. Shutemov @ 2016-02-29 15:03 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner

On Mon, Feb 29, 2016 at 03:16:22PM +0100, Michal Hocko wrote:
> On Mon 29-02-16 17:04:16, Kirill A. Shutemov wrote:
> [...]
> > > Most of the patches are really trivial because the lock is help from a
> > > shallow syscall paths where we can return EINTR trivially. Others seem
> > > to be easy as well as the callers are already handling fatal errors and
> > > bail and return to userspace which should be sufficient to handle the
> > > failure gracefully. I am not familiar with all those code paths so a
> > > deeper review is really appreciated.
> > 
> > What about effect on userspace? IIUC, we would have now EINTR returned
> > from bunch of syscall, which haven't had this errno on the table before.
> > Should we care?
> 
> Those function will return EINTR only when the current was _killed_ when
> we do not return to the userspace. So there shouldn't be any visible
> effect.

Ah. I confused killable with interruptible.

-- 
 Kirill A. Shutemov

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

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

* Re: [PATCH 10/18] vdso: make arch_setup_additional_pages wait for mmap_sem for write killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-02-29 15:41     ` Andy Lutomirski
  -1 siblings, 0 replies; 234+ messages in thread
From: Andy Lutomirski @ 2016-02-29 15:41 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Benjamin LaHaise, Christian König,
	Daniel Vetter, Dave Hansen, David Airlie, Davidlohr Bueso,
	David Rientjes, H . Peter Anvin, Hugh Dickins, Ingo Molnar,
	Johannes Weiner, Kirill A . Shutemov, Konstantin Khlebnikov,
	linux-arch, Mel Gorman, Oleg Nesterov, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Michal Hocko

On Mon, Feb 29, 2016 at 5:26 AM, Michal Hocko <mhocko@kernel.org> wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> most architectures are relying on mmap_sem for write in their
> arch_setup_additional_pages. If the waiting task gets killed by the oom
> killer it would block oom_reaper from asynchronous address space reclaim
> and reduce the chances of timely OOM resolving. Wait for the lock in
> the killable mode and return with EINTR if the task got killed while
> waiting.

Acked-by: Andy Lutomirski <luto@kernel.org> # for the x86 vdso

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

* Re: [PATCH 10/18] vdso: make arch_setup_additional_pages wait for mmap_sem for write killable
@ 2016-02-29 15:41     ` Andy Lutomirski
  0 siblings, 0 replies; 234+ messages in thread
From: Andy Lutomirski @ 2016-02-29 15:41 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Benjamin LaHaise, Christian König,
	Daniel Vetter, Dave Hansen, David Airlie, Davidlohr Bueso,
	David Rientjes, H . Peter Anvin, Hugh Dickins, Ingo Molnar,
	Johannes Weiner, Kirill A . Shutemov, Konstantin Khlebnikov,
	linux-arch, Mel Gorman, Oleg Nesterov

On Mon, Feb 29, 2016 at 5:26 AM, Michal Hocko <mhocko@kernel.org> wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> most architectures are relying on mmap_sem for write in their
> arch_setup_additional_pages. If the waiting task gets killed by the oom
> killer it would block oom_reaper from asynchronous address space reclaim
> and reduce the chances of timely OOM resolving. Wait for the lock in
> the killable mode and return with EINTR if the task got killed while
> waiting.

Acked-by: Andy Lutomirski <luto@kernel.org> # for the x86 vdso

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

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

* Re: [PATCH 10/18] vdso: make arch_setup_additional_pages wait for mmap_sem for write killable
@ 2016-02-29 15:41     ` Andy Lutomirski
  0 siblings, 0 replies; 234+ messages in thread
From: Andy Lutomirski @ 2016-02-29 15:41 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Benjamin LaHaise, Christian König,
	Daniel Vetter, Dave Hansen, David Airlie, Davidlohr Bueso,
	David Rientjes, H . Peter Anvin, Hugh Dickins, Ingo Molnar,
	Johannes Weiner, Kirill A . Shutemov, Konstantin Khlebnikov,
	linux-arch, Mel Gorman, Oleg Nesterov, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Michal Hocko

On Mon, Feb 29, 2016 at 5:26 AM, Michal Hocko <mhocko@kernel.org> wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> most architectures are relying on mmap_sem for write in their
> arch_setup_additional_pages. If the waiting task gets killed by the oom
> killer it would block oom_reaper from asynchronous address space reclaim
> and reduce the chances of timely OOM resolving. Wait for the lock in
> the killable mode and return with EINTR if the task got killed while
> waiting.

Acked-by: Andy Lutomirski <luto@kernel.org> # for the x86 vdso

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

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

* Re: [PATCH 15/18] uprobes: wait for mmap_sem for write killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-02-29 15:57     ` Oleg Nesterov
  -1 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 15:57 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29, Michal Hocko wrote:
>
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
>  	struct vm_area_struct *vma;
>  	int ret;
>
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return -EINTR;
> +

Yes, but then dup_xol_work() should probably check fatal_signal_pending() to
suppress uprobe_warn(), the warning looks like a kernel problem.

Oleg.

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

* Re: [PATCH 15/18] uprobes: wait for mmap_sem for write killable
@ 2016-02-29 15:57     ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 15:57 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra

On 02/29, Michal Hocko wrote:
>
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
>  	struct vm_area_struct *vma;
>  	int ret;
>
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return -EINTR;
> +

Yes, but then dup_xol_work() should probably check fatal_signal_pending() to
suppress uprobe_warn(), the warning looks like a kernel problem.

Oleg.

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

* Re: [PATCH 15/18] uprobes: wait for mmap_sem for write killable
@ 2016-02-29 15:57     ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 15:57 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29, Michal Hocko wrote:
>
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
>  	struct vm_area_struct *vma;
>  	int ret;
>
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return -EINTR;
> +

Yes, but then dup_xol_work() should probably check fatal_signal_pending() to
suppress uprobe_warn(), the warning looks like a kernel problem.

Oleg.

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

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

* Re: [PATCH 11/18] coredump: make coredump_wait wait for mma_sem for write killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-02-29 15:57     ` Oleg Nesterov
  -1 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 15:57 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29, Michal Hocko wrote:
>
> --- a/fs/coredump.c
> +++ b/fs/coredump.c
> @@ -410,7 +410,9 @@ static int coredump_wait(int exit_code, struct core_state *core_state)
>  	core_state->dumper.task = tsk;
>  	core_state->dumper.next = NULL;
>  
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return -EINTR;
> +

ACK, thanks.

Oleg.

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

* Re: [PATCH 11/18] coredump: make coredump_wait wait for mma_sem for write killable
@ 2016-02-29 15:57     ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 15:57 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra

On 02/29, Michal Hocko wrote:
>
> --- a/fs/coredump.c
> +++ b/fs/coredump.c
> @@ -410,7 +410,9 @@ static int coredump_wait(int exit_code, struct core_state *core_state)
>  	core_state->dumper.task = tsk;
>  	core_state->dumper.next = NULL;
>  
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return -EINTR;
> +

ACK, thanks.

Oleg.

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

* Re: [PATCH 11/18] coredump: make coredump_wait wait for mma_sem for write killable
@ 2016-02-29 15:57     ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 15:57 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29, Michal Hocko wrote:
>
> --- a/fs/coredump.c
> +++ b/fs/coredump.c
> @@ -410,7 +410,9 @@ static int coredump_wait(int exit_code, struct core_state *core_state)
>  	core_state->dumper.task = tsk;
>  	core_state->dumper.next = NULL;
>  
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return -EINTR;
> +

ACK, thanks.

Oleg.

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

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

* Re: [PATCH 12/18] aio: make aio_setup_ring killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-02-29 16:17     ` Jeff Moyer
  -1 siblings, 0 replies; 234+ messages in thread
From: Jeff Moyer @ 2016-02-29 16:17 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

Michal Hocko <mhocko@kernel.org> writes:

> From: Michal Hocko <mhocko@suse.com>
>
> aio_setup_ring waits for mmap_sem in writable mode. If the waiting
> task gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely
> OOM resolving. Wait for the lock in the killable mode and return with
> EINTR if the task got killed while waiting. This will also expedite
> the return to the userspace and do_exit.
>
> Cc: Benjamin LaHaise <bcrl@kvack.org>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Michal Hocko <mhocko@suse.com>
> ---
>  fs/aio.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/fs/aio.c b/fs/aio.c
> index 56bcdf4105f4..1c2e7e2c1b2b 100644
> --- a/fs/aio.c
> +++ b/fs/aio.c
> @@ -520,7 +520,12 @@ static int aio_setup_ring(struct kioctx *ctx)
>  	ctx->mmap_size = nr_pages * PAGE_SIZE;
>  	pr_debug("attempting mmap of %lu bytes\n", ctx->mmap_size);
>  
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem)) {
> +		ctx->mmap_size = 0;
> +		aio_free_ring(ctx);
> +		return -EINTR;
> +	}
> +
>  	ctx->mmap_base = do_mmap_pgoff(ctx->aio_ring_file, 0, ctx->mmap_size,
>  				       PROT_READ | PROT_WRITE,
>  				       MAP_SHARED, 0, &unused);

Reviewed-by: Jeff Moyer <jmoyer@redhat.com>

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

* Re: [PATCH 12/18] aio: make aio_setup_ring killable
@ 2016-02-29 16:17     ` Jeff Moyer
  0 siblings, 0 replies; 234+ messages in thread
From: Jeff Moyer @ 2016-02-29 16:17 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov

Michal Hocko <mhocko@kernel.org> writes:

> From: Michal Hocko <mhocko@suse.com>
>
> aio_setup_ring waits for mmap_sem in writable mode. If the waiting
> task gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely
> OOM resolving. Wait for the lock in the killable mode and return with
> EINTR if the task got killed while waiting. This will also expedite
> the return to the userspace and do_exit.
>
> Cc: Benjamin LaHaise <bcrl@kvack.org>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Michal Hocko <mhocko@suse.com>
> ---
>  fs/aio.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/fs/aio.c b/fs/aio.c
> index 56bcdf4105f4..1c2e7e2c1b2b 100644
> --- a/fs/aio.c
> +++ b/fs/aio.c
> @@ -520,7 +520,12 @@ static int aio_setup_ring(struct kioctx *ctx)
>  	ctx->mmap_size = nr_pages * PAGE_SIZE;
>  	pr_debug("attempting mmap of %lu bytes\n", ctx->mmap_size);
>  
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem)) {
> +		ctx->mmap_size = 0;
> +		aio_free_ring(ctx);
> +		return -EINTR;
> +	}
> +
>  	ctx->mmap_base = do_mmap_pgoff(ctx->aio_ring_file, 0, ctx->mmap_size,
>  				       PROT_READ | PROT_WRITE,
>  				       MAP_SHARED, 0, &unused);

Reviewed-by: Jeff Moyer <jmoyer@redhat.com>

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

* Re: [PATCH 12/18] aio: make aio_setup_ring killable
@ 2016-02-29 16:17     ` Jeff Moyer
  0 siblings, 0 replies; 234+ messages in thread
From: Jeff Moyer @ 2016-02-29 16:17 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

Michal Hocko <mhocko@kernel.org> writes:

> From: Michal Hocko <mhocko@suse.com>
>
> aio_setup_ring waits for mmap_sem in writable mode. If the waiting
> task gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely
> OOM resolving. Wait for the lock in the killable mode and return with
> EINTR if the task got killed while waiting. This will also expedite
> the return to the userspace and do_exit.
>
> Cc: Benjamin LaHaise <bcrl@kvack.org>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Michal Hocko <mhocko@suse.com>
> ---
>  fs/aio.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/fs/aio.c b/fs/aio.c
> index 56bcdf4105f4..1c2e7e2c1b2b 100644
> --- a/fs/aio.c
> +++ b/fs/aio.c
> @@ -520,7 +520,12 @@ static int aio_setup_ring(struct kioctx *ctx)
>  	ctx->mmap_size = nr_pages * PAGE_SIZE;
>  	pr_debug("attempting mmap of %lu bytes\n", ctx->mmap_size);
>  
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem)) {
> +		ctx->mmap_size = 0;
> +		aio_free_ring(ctx);
> +		return -EINTR;
> +	}
> +
>  	ctx->mmap_base = do_mmap_pgoff(ctx->aio_ring_file, 0, ctx->mmap_size,
>  				       PROT_READ | PROT_WRITE,
>  				       MAP_SHARED, 0, &unused);

Reviewed-by: Jeff Moyer <jmoyer@redhat.com>

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

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

* Re: [PATCH 15/18] uprobes: wait for mmap_sem for write killable
  2016-02-29 15:57     ` Oleg Nesterov
  (?)
@ 2016-02-29 16:28       ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 16:28 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner

On Mon 29-02-16 16:57:13, Oleg Nesterov wrote:
> On 02/29, Michal Hocko wrote:
> >
> > --- a/kernel/events/uprobes.c
> > +++ b/kernel/events/uprobes.c
> > @@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
> >  	struct vm_area_struct *vma;
> >  	int ret;
> >
> > -	down_write(&mm->mmap_sem);
> > +	if (down_write_killable(&mm->mmap_sem))
> > +		return -EINTR;
> > +
> 
> Yes, but then dup_xol_work() should probably check fatal_signal_pending() to
> suppress uprobe_warn(), the warning looks like a kernel problem.

Ahh, I see. I didn't understand what is the purpose of the warning. Does
the following work for you?
---
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index a79315d0f711..fb4a6bcc88ce 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1470,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
 	if (current->flags & PF_EXITING)
 		return;
 
-	if (!__create_xol_area(current->utask->dup_xol_addr))
+	if (!__create_xol_area(current->utask->dup_xol_addr) &&
+			!fatal_signal_pending(current)
 		uprobe_warn(current, "dup xol area");
 }
 
-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 15/18] uprobes: wait for mmap_sem for write killable
@ 2016-02-29 16:28       ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 16:28 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra

On Mon 29-02-16 16:57:13, Oleg Nesterov wrote:
> On 02/29, Michal Hocko wrote:
> >
> > --- a/kernel/events/uprobes.c
> > +++ b/kernel/events/uprobes.c
> > @@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
> >  	struct vm_area_struct *vma;
> >  	int ret;
> >
> > -	down_write(&mm->mmap_sem);
> > +	if (down_write_killable(&mm->mmap_sem))
> > +		return -EINTR;
> > +
> 
> Yes, but then dup_xol_work() should probably check fatal_signal_pending() to
> suppress uprobe_warn(), the warning looks like a kernel problem.

Ahh, I see. I didn't understand what is the purpose of the warning. Does
the following work for you?
---
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index a79315d0f711..fb4a6bcc88ce 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1470,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
 	if (current->flags & PF_EXITING)
 		return;
 
-	if (!__create_xol_area(current->utask->dup_xol_addr))
+	if (!__create_xol_area(current->utask->dup_xol_addr) &&
+			!fatal_signal_pending(current)
 		uprobe_warn(current, "dup xol area");
 }
 
-- 
Michal Hocko
SUSE Labs

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

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

* Re: [PATCH 15/18] uprobes: wait for mmap_sem for write killable
@ 2016-02-29 16:28       ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 16:28 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner

On Mon 29-02-16 16:57:13, Oleg Nesterov wrote:
> On 02/29, Michal Hocko wrote:
> >
> > --- a/kernel/events/uprobes.c
> > +++ b/kernel/events/uprobes.c
> > @@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
> >  	struct vm_area_struct *vma;
> >  	int ret;
> >
> > -	down_write(&mm->mmap_sem);
> > +	if (down_write_killable(&mm->mmap_sem))
> > +		return -EINTR;
> > +
> 
> Yes, but then dup_xol_work() should probably check fatal_signal_pending() to
> suppress uprobe_warn(), the warning looks like a kernel problem.

Ahh, I see. I didn't understand what is the purpose of the warning. Does
the following work for you?
---
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index a79315d0f711..fb4a6bcc88ce 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1470,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
 	if (current->flags & PF_EXITING)
 		return;
 
-	if (!__create_xol_area(current->utask->dup_xol_addr))
+	if (!__create_xol_area(current->utask->dup_xol_addr) &&
+			!fatal_signal_pending(current)
 		uprobe_warn(current, "dup xol area");
 }
 
-- 
Michal Hocko
SUSE Labs

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

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

* Re: [PATCH 15/18] uprobes: wait for mmap_sem for write killable
  2016-02-29 16:28       ` Michal Hocko
  (?)
@ 2016-02-29 17:12         ` Oleg Nesterov
  -1 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 17:12 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner

On 02/29, Michal Hocko wrote:
>
> Ahh, I see. I didn't understand what is the purpose of the warning. Does
> the following work for you?
> ---
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index a79315d0f711..fb4a6bcc88ce 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -1470,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
>  	if (current->flags & PF_EXITING)
>  		return;
>
> -	if (!__create_xol_area(current->utask->dup_xol_addr))
> +	if (!__create_xol_area(current->utask->dup_xol_addr) &&
> +			!fatal_signal_pending(current)
>  		uprobe_warn(current, "dup xol area");
>  }

Yes, I think this is fine.

Probably deserves a cleanup, but we can do it later.

Oleg.

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

* Re: [PATCH 15/18] uprobes: wait for mmap_sem for write killable
@ 2016-02-29 17:12         ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 17:12 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra

On 02/29, Michal Hocko wrote:
>
> Ahh, I see. I didn't understand what is the purpose of the warning. Does
> the following work for you?
> ---
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index a79315d0f711..fb4a6bcc88ce 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -1470,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
>  	if (current->flags & PF_EXITING)
>  		return;
>
> -	if (!__create_xol_area(current->utask->dup_xol_addr))
> +	if (!__create_xol_area(current->utask->dup_xol_addr) &&
> +			!fatal_signal_pending(current)
>  		uprobe_warn(current, "dup xol area");
>  }

Yes, I think this is fine.

Probably deserves a cleanup, but we can do it later.

Oleg.

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

* Re: [PATCH 15/18] uprobes: wait for mmap_sem for write killable
@ 2016-02-29 17:12         ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 17:12 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner

On 02/29, Michal Hocko wrote:
>
> Ahh, I see. I didn't understand what is the purpose of the warning. Does
> the following work for you?
> ---
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index a79315d0f711..fb4a6bcc88ce 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -1470,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
>  	if (current->flags & PF_EXITING)
>  		return;
>
> -	if (!__create_xol_area(current->utask->dup_xol_addr))
> +	if (!__create_xol_area(current->utask->dup_xol_addr) &&
> +			!fatal_signal_pending(current)
>  		uprobe_warn(current, "dup xol area");
>  }

Yes, I think this is fine.

Probably deserves a cleanup, but we can do it later.

Oleg.

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

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

* Re: [PATCH 13/18] exec: make exec path waiting for mmap_sem killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-02-29 17:23     ` Oleg Nesterov
  -1 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 17:23 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Michal Hocko, Alexander Viro

On 02/29, Michal Hocko wrote:
>
> @@ -267,7 +267,10 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
>  	if (!vma)
>  		return -ENOMEM;
>  
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem)) {
> +		err = -EINTR;
> +		goto err_free;
> +	}
>  	vma->vm_mm = mm;

I won't argue, but this looks unnecessary. Nobody else can see this new mm,
down_write() can't block.

In fact I think we can just remove down_write/up_write here. Except perhaps
there is lockdep_assert_held() somewhere in these paths.

Oleg.

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

* Re: [PATCH 13/18] exec: make exec path waiting for mmap_sem killable
@ 2016-02-29 17:23     ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 17:23 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra

On 02/29, Michal Hocko wrote:
>
> @@ -267,7 +267,10 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
>  	if (!vma)
>  		return -ENOMEM;
>  
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem)) {
> +		err = -EINTR;
> +		goto err_free;
> +	}
>  	vma->vm_mm = mm;

I won't argue, but this looks unnecessary. Nobody else can see this new mm,
down_write() can't block.

In fact I think we can just remove down_write/up_write here. Except perhaps
there is lockdep_assert_held() somewhere in these paths.

Oleg.

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

* Re: [PATCH 13/18] exec: make exec path waiting for mmap_sem killable
@ 2016-02-29 17:23     ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 17:23 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Michal Hocko, Alexander Viro

On 02/29, Michal Hocko wrote:
>
> @@ -267,7 +267,10 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
>  	if (!vma)
>  		return -ENOMEM;
>  
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem)) {
> +		err = -EINTR;
> +		goto err_free;
> +	}
>  	vma->vm_mm = mm;

I won't argue, but this looks unnecessary. Nobody else can see this new mm,
down_write() can't block.

In fact I think we can just remove down_write/up_write here. Except perhaps
there is lockdep_assert_held() somewhere in these paths.

Oleg.

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

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

* Re: [PATCH 07/18] mm, proc: make clear_refs killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-02-29 17:38     ` Oleg Nesterov
  -1 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 17:38 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29, Michal Hocko wrote:
>
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -1027,11 +1027,15 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
>  		};
>
>  		if (type == CLEAR_REFS_MM_HIWATER_RSS) {
> +			if (down_write_killable(&mm->mmap_sem)) {
> +				put_task_struct(task);
> +				return -EINTR;
> +			}
> +
>  			/*
>  			 * Writing 5 to /proc/pid/clear_refs resets the peak
>  			 * resident set size to this mm's current rss value.
>  			 */
> -			down_write(&mm->mmap_sem);
>  			reset_mm_hiwater_rss(mm);
>  			up_write(&mm->mmap_sem);
>  			goto out_mm;
> @@ -1043,7 +1047,10 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
>  				if (!(vma->vm_flags & VM_SOFTDIRTY))
>  					continue;
>  				up_read(&mm->mmap_sem);
> -				down_write(&mm->mmap_sem);
> +				if (down_write_killable(&mm->mmap_sem)) {
> +					put_task_struct(task);
> +					return -EINTR;
> +				}

Both lack mmput() afaics. Don't you need "goto out_mm" rather then "return" ? In
this case you do not need put_task_struct().

Oleg.

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

* Re: [PATCH 07/18] mm, proc: make clear_refs killable
@ 2016-02-29 17:38     ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 17:38 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra

On 02/29, Michal Hocko wrote:
>
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -1027,11 +1027,15 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
>  		};
>
>  		if (type == CLEAR_REFS_MM_HIWATER_RSS) {
> +			if (down_write_killable(&mm->mmap_sem)) {
> +				put_task_struct(task);
> +				return -EINTR;
> +			}
> +
>  			/*
>  			 * Writing 5 to /proc/pid/clear_refs resets the peak
>  			 * resident set size to this mm's current rss value.
>  			 */
> -			down_write(&mm->mmap_sem);
>  			reset_mm_hiwater_rss(mm);
>  			up_write(&mm->mmap_sem);
>  			goto out_mm;
> @@ -1043,7 +1047,10 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
>  				if (!(vma->vm_flags & VM_SOFTDIRTY))
>  					continue;
>  				up_read(&mm->mmap_sem);
> -				down_write(&mm->mmap_sem);
> +				if (down_write_killable(&mm->mmap_sem)) {
> +					put_task_struct(task);
> +					return -EINTR;
> +				}

Both lack mmput() afaics. Don't you need "goto out_mm" rather then "return" ? In
this case you do not need put_task_struct().

Oleg.

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

* Re: [PATCH 07/18] mm, proc: make clear_refs killable
@ 2016-02-29 17:38     ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 17:38 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29, Michal Hocko wrote:
>
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -1027,11 +1027,15 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
>  		};
>
>  		if (type == CLEAR_REFS_MM_HIWATER_RSS) {
> +			if (down_write_killable(&mm->mmap_sem)) {
> +				put_task_struct(task);
> +				return -EINTR;
> +			}
> +
>  			/*
>  			 * Writing 5 to /proc/pid/clear_refs resets the peak
>  			 * resident set size to this mm's current rss value.
>  			 */
> -			down_write(&mm->mmap_sem);
>  			reset_mm_hiwater_rss(mm);
>  			up_write(&mm->mmap_sem);
>  			goto out_mm;
> @@ -1043,7 +1047,10 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
>  				if (!(vma->vm_flags & VM_SOFTDIRTY))
>  					continue;
>  				up_read(&mm->mmap_sem);
> -				down_write(&mm->mmap_sem);
> +				if (down_write_killable(&mm->mmap_sem)) {
> +					put_task_struct(task);
> +					return -EINTR;
> +				}

Both lack mmput() afaics. Don't you need "goto out_mm" rather then "return" ? In
this case you do not need put_task_struct().

Oleg.

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

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

* [PATCH] uprobes: wait for mmap_sem for write killable
  2016-02-29 13:26   ` Michal Hocko
@ 2016-02-29 17:42     ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 17:42 UTC (permalink / raw)
  To: LKML; +Cc: Andrew Morton, Oleg Nesterov, linux-mm, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

xol_add_vma needs mmap_sem for write. If the waiting task gets killed by
the oom killer it would block oom_reaper from asynchronous address space
reclaim and reduce the chances of timely OOM resolving. Wait for the
lock in the killable mode and return with EINTR if the task got killed
while waiting.

Do not warn in dup_xol_work if __create_xol_area failed due to fatal
signal pending because this is usually considered a kernel issue.

Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 kernel/events/uprobes.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 8eef5f55d3f0..fb4a6bcc88ce 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
 	struct vm_area_struct *vma;
 	int ret;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	if (mm->uprobes_state.xol_area) {
 		ret = -EALREADY;
 		goto fail;
@@ -1468,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
 	if (current->flags & PF_EXITING)
 		return;
 
-	if (!__create_xol_area(current->utask->dup_xol_addr))
+	if (!__create_xol_area(current->utask->dup_xol_addr) &&
+			!fatal_signal_pending(current)
 		uprobe_warn(current, "dup xol area");
 }
 
-- 
2.7.0

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

* [PATCH] uprobes: wait for mmap_sem for write killable
@ 2016-02-29 17:42     ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 17:42 UTC (permalink / raw)
  To: LKML; +Cc: Andrew Morton, Oleg Nesterov, linux-mm, Michal Hocko

From: Michal Hocko <mhocko@suse.com>

xol_add_vma needs mmap_sem for write. If the waiting task gets killed by
the oom killer it would block oom_reaper from asynchronous address space
reclaim and reduce the chances of timely OOM resolving. Wait for the
lock in the killable mode and return with EINTR if the task got killed
while waiting.

Do not warn in dup_xol_work if __create_xol_area failed due to fatal
signal pending because this is usually considered a kernel issue.

Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 kernel/events/uprobes.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 8eef5f55d3f0..fb4a6bcc88ce 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
 	struct vm_area_struct *vma;
 	int ret;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
+
 	if (mm->uprobes_state.xol_area) {
 		ret = -EALREADY;
 		goto fail;
@@ -1468,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
 	if (current->flags & PF_EXITING)
 		return;
 
-	if (!__create_xol_area(current->utask->dup_xol_addr))
+	if (!__create_xol_area(current->utask->dup_xol_addr) &&
+			!fatal_signal_pending(current)
 		uprobe_warn(current, "dup xol area");
 }
 
-- 
2.7.0

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

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

* Re: [PATCH 13/18] exec: make exec path waiting for mmap_sem killable
  2016-02-29 17:23     ` Oleg Nesterov
  (?)
@ 2016-02-29 17:47       ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 17:47 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Alexander Viro

On Mon 29-02-16 18:23:34, Oleg Nesterov wrote:
> On 02/29, Michal Hocko wrote:
> >
> > @@ -267,7 +267,10 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
> >  	if (!vma)
> >  		return -ENOMEM;
> >  
> > -	down_write(&mm->mmap_sem);
> > +	if (down_write_killable(&mm->mmap_sem)) {
> > +		err = -EINTR;
> > +		goto err_free;
> > +	}
> >  	vma->vm_mm = mm;
> 
> I won't argue, but this looks unnecessary. Nobody else can see this new mm,
> down_write() can't block.
> 
> In fact I think we can just remove down_write/up_write here. Except perhaps
> there is lockdep_assert_held() somewhere in these paths.

This is what I had initially but then I've noticed that mm_alloc() does
mm_init(current)->init_new_context(current) so the outside can see this
mm AFAICS. Now I guess this shouldn't matter in the real life but the
code doesn't seem much harder to follow, the callers are already
handling all error paths so I guess it would be better to simply move on
this. Or am I misunderstanding the code or missing something?

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 13/18] exec: make exec path waiting for mmap_sem killable
@ 2016-02-29 17:47       ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 17:47 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra

On Mon 29-02-16 18:23:34, Oleg Nesterov wrote:
> On 02/29, Michal Hocko wrote:
> >
> > @@ -267,7 +267,10 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
> >  	if (!vma)
> >  		return -ENOMEM;
> >  
> > -	down_write(&mm->mmap_sem);
> > +	if (down_write_killable(&mm->mmap_sem)) {
> > +		err = -EINTR;
> > +		goto err_free;
> > +	}
> >  	vma->vm_mm = mm;
> 
> I won't argue, but this looks unnecessary. Nobody else can see this new mm,
> down_write() can't block.
> 
> In fact I think we can just remove down_write/up_write here. Except perhaps
> there is lockdep_assert_held() somewhere in these paths.

This is what I had initially but then I've noticed that mm_alloc() does
mm_init(current)->init_new_context(current) so the outside can see this
mm AFAICS. Now I guess this shouldn't matter in the real life but the
code doesn't seem much harder to follow, the callers are already
handling all error paths so I guess it would be better to simply move on
this. Or am I misunderstanding the code or missing something?

-- 
Michal Hocko
SUSE Labs

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

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

* Re: [PATCH 13/18] exec: make exec path waiting for mmap_sem killable
@ 2016-02-29 17:47       ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 17:47 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Alexander Viro

On Mon 29-02-16 18:23:34, Oleg Nesterov wrote:
> On 02/29, Michal Hocko wrote:
> >
> > @@ -267,7 +267,10 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
> >  	if (!vma)
> >  		return -ENOMEM;
> >  
> > -	down_write(&mm->mmap_sem);
> > +	if (down_write_killable(&mm->mmap_sem)) {
> > +		err = -EINTR;
> > +		goto err_free;
> > +	}
> >  	vma->vm_mm = mm;
> 
> I won't argue, but this looks unnecessary. Nobody else can see this new mm,
> down_write() can't block.
> 
> In fact I think we can just remove down_write/up_write here. Except perhaps
> there is lockdep_assert_held() somewhere in these paths.

This is what I had initially but then I've noticed that mm_alloc() does
mm_init(current)->init_new_context(current) so the outside can see this
mm AFAICS. Now I guess this shouldn't matter in the real life but the
code doesn't seem much harder to follow, the callers are already
handling all error paths so I guess it would be better to simply move on
this. Or am I misunderstanding the code or missing something?

-- 
Michal Hocko
SUSE Labs

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

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

* Re: [PATCH] uprobes: wait for mmap_sem for write killable
  2016-02-29 17:42     ` Michal Hocko
  (?)
@ 2016-02-29 17:52     ` kbuild test robot
  -1 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 17:52 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, Oleg Nesterov, linux-mm, Michal Hocko

[-- Attachment #1: Type: text/plain, Size: 3905 bytes --]

Hi Michal,

[auto build test ERROR on tip/perf/core]
[also build test ERROR on v4.5-rc6 next-20160229]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/uprobes-wait-for-mmap_sem-for-write-killable/20160301-014513
config: i386-randconfig-x003-201609 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   In file included from include/linux/linkage.h:4:0,
                    from include/linux/kernel.h:6,
                    from kernel/events/uprobes.c:25:
   kernel/events/uprobes.c: In function 'xol_add_vma':
   kernel/events/uprobes.c:1133:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&mm->mmap_sem))
         ^
   include/linux/compiler.h:147:30: note: in definition of macro '__trace_if'
     if (__builtin_constant_p(!!(cond)) ? !!(cond) :   \
                                 ^
   kernel/events/uprobes.c:1133:2: note: in expansion of macro 'if'
     if (down_write_killable(&mm->mmap_sem))
     ^
   kernel/events/uprobes.c: In function 'dup_xol_work':
>> kernel/events/uprobes.c:2029:0: error: unterminated argument list invoking macro "if"
    __initcall(init_uprobes);
    ^
>> kernel/events/uprobes.c:1473:2: error: expected '(' at end of input
     if (!__create_xol_area(current->utask->dup_xol_addr) &&
     ^
>> kernel/events/uprobes.c:1473:2: error: expected declaration or statement at end of input
   kernel/events/uprobes.c: At top level:
   kernel/events/uprobes.c:961:12: warning: 'unapply_uprobe' defined but not used [-Wunused-function]
    static int unapply_uprobe(struct uprobe *uprobe, struct mm_struct *mm)
               ^
   kernel/events/uprobes.c:1293:22: warning: 'xol_get_insn_slot' defined but not used [-Wunused-function]
    static unsigned long xol_get_insn_slot(struct uprobe *uprobe)
                         ^
   kernel/events/uprobes.c:1427:28: warning: 'get_utask' defined but not used [-Wunused-function]
    static struct uprobe_task *get_utask(void)
                               ^
   kernel/events/uprobes.c:1434:12: warning: 'dup_utask' defined but not used [-Wunused-function]
    static int dup_utask(struct task_struct *t, struct uprobe_task *o_utask)
               ^
   kernel/events/uprobes.c:1462:13: warning: 'uprobe_warn' defined but not used [-Wunused-function]
    static void uprobe_warn(struct task_struct *t, const char *msg)
                ^
   kernel/events/uprobes.c:1468:13: warning: 'dup_xol_work' defined but not used [-Wunused-function]
    static void dup_xol_work(struct callback_head *work)
                ^
   cc1: some warnings being treated as errors

vim +/if +2029 kernel/events/uprobes.c

0326f5a9 kernel/events/uprobes.c Srikar Dronamraju 2012-03-13  2023  
32cdba1e kernel/events/uprobes.c Oleg Nesterov     2012-11-14  2024  	if (percpu_init_rwsem(&dup_mmap_sem))
32cdba1e kernel/events/uprobes.c Oleg Nesterov     2012-11-14  2025  		return -ENOMEM;
32cdba1e kernel/events/uprobes.c Oleg Nesterov     2012-11-14  2026  
0326f5a9 kernel/events/uprobes.c Srikar Dronamraju 2012-03-13  2027  	return register_die_notifier(&uprobe_exception_nb);
2b144498 kernel/uprobes.c        Srikar Dronamraju 2012-02-09  2028  }
736e89d9 kernel/events/uprobes.c Oleg Nesterov     2013-10-31 @2029  __initcall(init_uprobes);

:::::: The code at line 2029 was first introduced by commit
:::::: 736e89d9f782a7dd9a38ecda13b2db916fa72f33 uprobes: Kill module_init() and module_exit()

:::::: TO: Oleg Nesterov <oleg@redhat.com>
:::::: CC: Oleg Nesterov <oleg@redhat.com>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 21703 bytes --]

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

* Re: [PATCH 07/18] mm, proc: make clear_refs killable
  2016-02-29 17:38     ` Oleg Nesterov
  (?)
@ 2016-02-29 17:53       ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 17:53 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner

On Mon 29-02-16 18:38:45, Oleg Nesterov wrote:
> On 02/29, Michal Hocko wrote:
> >
> > --- a/fs/proc/task_mmu.c
> > +++ b/fs/proc/task_mmu.c
> > @@ -1027,11 +1027,15 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
> >  		};
> >
> >  		if (type == CLEAR_REFS_MM_HIWATER_RSS) {
> > +			if (down_write_killable(&mm->mmap_sem)) {
> > +				put_task_struct(task);
> > +				return -EINTR;
> > +			}
> > +
> >  			/*
> >  			 * Writing 5 to /proc/pid/clear_refs resets the peak
> >  			 * resident set size to this mm's current rss value.
> >  			 */
> > -			down_write(&mm->mmap_sem);
> >  			reset_mm_hiwater_rss(mm);
> >  			up_write(&mm->mmap_sem);
> >  			goto out_mm;
> > @@ -1043,7 +1047,10 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
> >  				if (!(vma->vm_flags & VM_SOFTDIRTY))
> >  					continue;
> >  				up_read(&mm->mmap_sem);
> > -				down_write(&mm->mmap_sem);
> > +				if (down_write_killable(&mm->mmap_sem)) {
> > +					put_task_struct(task);
> > +					return -EINTR;
> > +				}
> 
> Both lack mmput() afaics. Don't you need "goto out_mm" rather then "return" ?

Of course I need! Thanks for catching that.

> In this case you do not need put_task_struct().

Why not? Both are after get_proc_task which takes a reference to the
task...

I will send an updated patch. Thanks!

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 07/18] mm, proc: make clear_refs killable
@ 2016-02-29 17:53       ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 17:53 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra

On Mon 29-02-16 18:38:45, Oleg Nesterov wrote:
> On 02/29, Michal Hocko wrote:
> >
> > --- a/fs/proc/task_mmu.c
> > +++ b/fs/proc/task_mmu.c
> > @@ -1027,11 +1027,15 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
> >  		};
> >
> >  		if (type == CLEAR_REFS_MM_HIWATER_RSS) {
> > +			if (down_write_killable(&mm->mmap_sem)) {
> > +				put_task_struct(task);
> > +				return -EINTR;
> > +			}
> > +
> >  			/*
> >  			 * Writing 5 to /proc/pid/clear_refs resets the peak
> >  			 * resident set size to this mm's current rss value.
> >  			 */
> > -			down_write(&mm->mmap_sem);
> >  			reset_mm_hiwater_rss(mm);
> >  			up_write(&mm->mmap_sem);
> >  			goto out_mm;
> > @@ -1043,7 +1047,10 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
> >  				if (!(vma->vm_flags & VM_SOFTDIRTY))
> >  					continue;
> >  				up_read(&mm->mmap_sem);
> > -				down_write(&mm->mmap_sem);
> > +				if (down_write_killable(&mm->mmap_sem)) {
> > +					put_task_struct(task);
> > +					return -EINTR;
> > +				}
> 
> Both lack mmput() afaics. Don't you need "goto out_mm" rather then "return" ?

Of course I need! Thanks for catching that.

> In this case you do not need put_task_struct().

Why not? Both are after get_proc_task which takes a reference to the
task...

I will send an updated patch. Thanks!

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 07/18] mm, proc: make clear_refs killable
@ 2016-02-29 17:53       ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 17:53 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner

On Mon 29-02-16 18:38:45, Oleg Nesterov wrote:
> On 02/29, Michal Hocko wrote:
> >
> > --- a/fs/proc/task_mmu.c
> > +++ b/fs/proc/task_mmu.c
> > @@ -1027,11 +1027,15 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
> >  		};
> >
> >  		if (type == CLEAR_REFS_MM_HIWATER_RSS) {
> > +			if (down_write_killable(&mm->mmap_sem)) {
> > +				put_task_struct(task);
> > +				return -EINTR;
> > +			}
> > +
> >  			/*
> >  			 * Writing 5 to /proc/pid/clear_refs resets the peak
> >  			 * resident set size to this mm's current rss value.
> >  			 */
> > -			down_write(&mm->mmap_sem);
> >  			reset_mm_hiwater_rss(mm);
> >  			up_write(&mm->mmap_sem);
> >  			goto out_mm;
> > @@ -1043,7 +1047,10 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
> >  				if (!(vma->vm_flags & VM_SOFTDIRTY))
> >  					continue;
> >  				up_read(&mm->mmap_sem);
> > -				down_write(&mm->mmap_sem);
> > +				if (down_write_killable(&mm->mmap_sem)) {
> > +					put_task_struct(task);
> > +					return -EINTR;
> > +				}
> 
> Both lack mmput() afaics. Don't you need "goto out_mm" rather then "return" ?

Of course I need! Thanks for catching that.

> In this case you do not need put_task_struct().

Why not? Both are after get_proc_task which takes a reference to the
task...

I will send an updated patch. Thanks!

-- 
Michal Hocko
SUSE Labs

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

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

* Re: [PATCH] uprobes: wait for mmap_sem for write killable
  2016-02-29 17:42     ` Michal Hocko
  (?)
  (?)
@ 2016-02-29 17:53     ` kbuild test robot
  -1 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 17:53 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, Oleg Nesterov, linux-mm, Michal Hocko

[-- Attachment #1: Type: text/plain, Size: 2232 bytes --]

Hi Michal,

[auto build test ERROR on tip/perf/core]
[also build test ERROR on v4.5-rc6 next-20160229]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/uprobes-wait-for-mmap_sem-for-write-killable/20160301-014513
config: x86_64-randconfig-x019-201609 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

   kernel/events/uprobes.c: In function 'xol_add_vma':
   kernel/events/uprobes.c:1133:6: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&mm->mmap_sem))
         ^
   kernel/events/uprobes.c: In function 'dup_xol_work':
>> kernel/events/uprobes.c:1475:3: error: expected ')' before 'uprobe_warn'
      uprobe_warn(current, "dup xol area");
      ^
>> kernel/events/uprobes.c:1476:1: error: expected expression before '}' token
    }
    ^
   cc1: some warnings being treated as errors

vim +1475 kernel/events/uprobes.c

aa59c53f Oleg Nesterov 2013-10-13  1469  {
aa59c53f Oleg Nesterov 2013-10-13  1470  	if (current->flags & PF_EXITING)
aa59c53f Oleg Nesterov 2013-10-13  1471  		return;
aa59c53f Oleg Nesterov 2013-10-13  1472  
6b584cb3 Michal Hocko  2016-02-29  1473  	if (!__create_xol_area(current->utask->dup_xol_addr) &&
6b584cb3 Michal Hocko  2016-02-29  1474  			!fatal_signal_pending(current)
aa59c53f Oleg Nesterov 2013-10-13 @1475  		uprobe_warn(current, "dup xol area");
aa59c53f Oleg Nesterov 2013-10-13 @1476  }
aa59c53f Oleg Nesterov 2013-10-13  1477  
e78aebfd Anton Arapov  2013-04-03  1478  /*
b68e0749 Oleg Nesterov 2013-10-13  1479   * Called in context of a new clone/fork from copy_process.

:::::: The code at line 1475 was first introduced by commit
:::::: aa59c53fd4599c91ccf9629af0c2777b89929076 uprobes: Change uprobe_copy_process() to dup xol_area

:::::: TO: Oleg Nesterov <oleg@redhat.com>
:::::: CC: Oleg Nesterov <oleg@redhat.com>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 22525 bytes --]

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

* Re: [PATCH 08/18] mm, fork: make dup_mmap wait for mmap_sem for write killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-02-29 17:54     ` Oleg Nesterov
  -1 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 17:54 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29, Michal Hocko wrote:
>
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -413,7 +413,10 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
>  	unsigned long charge;
>  
>  	uprobe_start_dup_mmap();
> -	down_write(&oldmm->mmap_sem);
> +	if (down_write_killable(&oldmm->mmap_sem)) {
> +		uprobe_end_dup_mmap();
> +		return -EINTR;
> +	}

This is really cosmetic and subjective, I won't insist if you prefer it this way.

But perhaps it makes sense to add another "fail" label above uprobe_end_dup_mmap()
we already have... IMO it is always better to avoid duplicating when it comes to
"unlock".

Oleg.

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

* Re: [PATCH 08/18] mm, fork: make dup_mmap wait for mmap_sem for write killable
@ 2016-02-29 17:54     ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 17:54 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra

On 02/29, Michal Hocko wrote:
>
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -413,7 +413,10 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
>  	unsigned long charge;
>  
>  	uprobe_start_dup_mmap();
> -	down_write(&oldmm->mmap_sem);
> +	if (down_write_killable(&oldmm->mmap_sem)) {
> +		uprobe_end_dup_mmap();
> +		return -EINTR;
> +	}

This is really cosmetic and subjective, I won't insist if you prefer it this way.

But perhaps it makes sense to add another "fail" label above uprobe_end_dup_mmap()
we already have... IMO it is always better to avoid duplicating when it comes to
"unlock".

Oleg.

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

* Re: [PATCH 08/18] mm, fork: make dup_mmap wait for mmap_sem for write killable
@ 2016-02-29 17:54     ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 17:54 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29, Michal Hocko wrote:
>
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -413,7 +413,10 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
>  	unsigned long charge;
>  
>  	uprobe_start_dup_mmap();
> -	down_write(&oldmm->mmap_sem);
> +	if (down_write_killable(&oldmm->mmap_sem)) {
> +		uprobe_end_dup_mmap();
> +		return -EINTR;
> +	}

This is really cosmetic and subjective, I won't insist if you prefer it this way.

But perhaps it makes sense to add another "fail" label above uprobe_end_dup_mmap()
we already have... IMO it is always better to avoid duplicating when it comes to
"unlock".

Oleg.

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

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

* [PATCH] mm, proc: make clear_refs killable
  2016-02-29 13:26   ` Michal Hocko
@ 2016-02-29 17:56     ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 17:56 UTC (permalink / raw)
  To: LKML; +Cc: Andrew Morton, linux-mm, Michal Hocko, Oleg Nesterov, Petr Cermak

From: Michal Hocko <mhocko@suse.com>

CLEAR_REFS_MM_HIWATER_RSS and CLEAR_REFS_SOFT_DIRTY are relying on
mmap_sem for write. If the waiting task gets killed by the oom killer
and it would operate on the current's mm it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely OOM
resolving. Wait for the lock in the killable mode and return with EINTR
if the task got killed while waiting. This will also expedite the return
to the userspace and do_exit even if the mm is remote.

Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Petr Cermak <petrcermak@chromium.org>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/proc/task_mmu.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 9df431642042..bb117356a04e 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -1027,11 +1027,15 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
 		};
 
 		if (type == CLEAR_REFS_MM_HIWATER_RSS) {
+			if (down_write_killable(&mm->mmap_sem)) {
+				count = -EINTR;
+				goto out_mm;
+			}
+
 			/*
 			 * Writing 5 to /proc/pid/clear_refs resets the peak
 			 * resident set size to this mm's current rss value.
 			 */
-			down_write(&mm->mmap_sem);
 			reset_mm_hiwater_rss(mm);
 			up_write(&mm->mmap_sem);
 			goto out_mm;
@@ -1043,7 +1047,10 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
 				if (!(vma->vm_flags & VM_SOFTDIRTY))
 					continue;
 				up_read(&mm->mmap_sem);
-				down_write(&mm->mmap_sem);
+				if (down_write_killable(&mm->mmap_sem)) {
+					count = -EINTR;
+					goto out_mm;
+				}
 				for (vma = mm->mmap; vma; vma = vma->vm_next) {
 					vma->vm_flags &= ~VM_SOFTDIRTY;
 					vma_set_page_prot(vma);
-- 
2.7.0

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

* [PATCH] mm, proc: make clear_refs killable
@ 2016-02-29 17:56     ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 17:56 UTC (permalink / raw)
  To: LKML; +Cc: Andrew Morton, linux-mm, Michal Hocko, Oleg Nesterov, Petr Cermak

From: Michal Hocko <mhocko@suse.com>

CLEAR_REFS_MM_HIWATER_RSS and CLEAR_REFS_SOFT_DIRTY are relying on
mmap_sem for write. If the waiting task gets killed by the oom killer
and it would operate on the current's mm it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely OOM
resolving. Wait for the lock in the killable mode and return with EINTR
if the task got killed while waiting. This will also expedite the return
to the userspace and do_exit even if the mm is remote.

Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Petr Cermak <petrcermak@chromium.org>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 fs/proc/task_mmu.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 9df431642042..bb117356a04e 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -1027,11 +1027,15 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
 		};
 
 		if (type == CLEAR_REFS_MM_HIWATER_RSS) {
+			if (down_write_killable(&mm->mmap_sem)) {
+				count = -EINTR;
+				goto out_mm;
+			}
+
 			/*
 			 * Writing 5 to /proc/pid/clear_refs resets the peak
 			 * resident set size to this mm's current rss value.
 			 */
-			down_write(&mm->mmap_sem);
 			reset_mm_hiwater_rss(mm);
 			up_write(&mm->mmap_sem);
 			goto out_mm;
@@ -1043,7 +1047,10 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
 				if (!(vma->vm_flags & VM_SOFTDIRTY))
 					continue;
 				up_read(&mm->mmap_sem);
-				down_write(&mm->mmap_sem);
+				if (down_write_killable(&mm->mmap_sem)) {
+					count = -EINTR;
+					goto out_mm;
+				}
 				for (vma = mm->mmap; vma; vma = vma->vm_next) {
 					vma->vm_flags &= ~VM_SOFTDIRTY;
 					vma_set_page_prot(vma);
-- 
2.7.0

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

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

* Re: [PATCH 07/18] mm, proc: make clear_refs killable
  2016-02-29 17:53       ` Michal Hocko
  (?)
@ 2016-02-29 17:58         ` Oleg Nesterov
  -1 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 17:58 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner

On 02/29, Michal Hocko wrote:
>
> On Mon 29-02-16 18:38:45, Oleg Nesterov wrote:
> 
> > In this case you do not need put_task_struct().
> 
> Why not? Both are after get_proc_task which takes a reference to the
> task...

Yes, but we already have put_task_struct(task) in the "out_mm" path, so
"goto out_mm" should work just fine?

Oleg.

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

* Re: [PATCH 07/18] mm, proc: make clear_refs killable
@ 2016-02-29 17:58         ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 17:58 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra

On 02/29, Michal Hocko wrote:
>
> On Mon 29-02-16 18:38:45, Oleg Nesterov wrote:
> 
> > In this case you do not need put_task_struct().
> 
> Why not? Both are after get_proc_task which takes a reference to the
> task...

Yes, but we already have put_task_struct(task) in the "out_mm" path, so
"goto out_mm" should work just fine?

Oleg.

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

* Re: [PATCH 07/18] mm, proc: make clear_refs killable
@ 2016-02-29 17:58         ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 17:58 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner

On 02/29, Michal Hocko wrote:
>
> On Mon 29-02-16 18:38:45, Oleg Nesterov wrote:
> 
> > In this case you do not need put_task_struct().
> 
> Why not? Both are after get_proc_task which takes a reference to the
> task...

Yes, but we already have put_task_struct(task) in the "out_mm" path, so
"goto out_mm" should work just fine?

Oleg.

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

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

* Re: [PATCH 07/18] mm, proc: make clear_refs killable
  2016-02-29 17:58         ` Oleg Nesterov
  (?)
@ 2016-02-29 18:02           ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 18:02 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner

On Mon 29-02-16 18:58:17, Oleg Nesterov wrote:
> On 02/29, Michal Hocko wrote:
> >
> > On Mon 29-02-16 18:38:45, Oleg Nesterov wrote:
> > 
> > > In this case you do not need put_task_struct().
> > 
> > Why not? Both are after get_proc_task which takes a reference to the
> > task...
> 
> Yes, but we already have put_task_struct(task) in the "out_mm" path, so
> "goto out_mm" should work just fine?

OK, got what you mean now. That's what I did and is on the way. I just
thought you mean that put_task_struct is implicit for other reason.

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 07/18] mm, proc: make clear_refs killable
@ 2016-02-29 18:02           ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 18:02 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra

On Mon 29-02-16 18:58:17, Oleg Nesterov wrote:
> On 02/29, Michal Hocko wrote:
> >
> > On Mon 29-02-16 18:38:45, Oleg Nesterov wrote:
> > 
> > > In this case you do not need put_task_struct().
> > 
> > Why not? Both are after get_proc_task which takes a reference to the
> > task...
> 
> Yes, but we already have put_task_struct(task) in the "out_mm" path, so
> "goto out_mm" should work just fine?

OK, got what you mean now. That's what I did and is on the way. I just
thought you mean that put_task_struct is implicit for other reason.

-- 
Michal Hocko
SUSE Labs

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

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

* Re: [PATCH 07/18] mm, proc: make clear_refs killable
@ 2016-02-29 18:02           ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 18:02 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner

On Mon 29-02-16 18:58:17, Oleg Nesterov wrote:
> On 02/29, Michal Hocko wrote:
> >
> > On Mon 29-02-16 18:38:45, Oleg Nesterov wrote:
> > 
> > > In this case you do not need put_task_struct().
> > 
> > Why not? Both are after get_proc_task which takes a reference to the
> > task...
> 
> Yes, but we already have put_task_struct(task) in the "out_mm" path, so
> "goto out_mm" should work just fine?

OK, got what you mean now. That's what I did and is on the way. I just
thought you mean that put_task_struct is implicit for other reason.

-- 
Michal Hocko
SUSE Labs

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

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

* [PATCH] mm, fork: make dup_mmap wait for mmap_sem for write killable
  2016-02-29 13:26   ` Michal Hocko
@ 2016-02-29 18:07     ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 18:07 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Michal Hocko, Ingo Molnar,
	Peter Zijlstra, Oleg Nesterov, Konstantin Khlebnikov

From: Michal Hocko <mhocko@suse.com>

dup_mmap needs to lock current's mm mmap_sem for write. If the waiting
task gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely OOM
resolving. Wait for the lock in the killable mode and return with EINTR
if the task got killed while waiting.

Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 kernel/fork.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index d277e83ed3e0..139968026b76 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -413,7 +413,10 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
 	unsigned long charge;
 
 	uprobe_start_dup_mmap();
-	down_write(&oldmm->mmap_sem);
+	if (down_write_killable(&oldmm->mmap_sem)) {
+		retval = -EINTR;
+		goto fail_uprobe_end;
+	}
 	flush_cache_dup_mm(oldmm);
 	uprobe_dup_mmap(oldmm, mm);
 	/*
@@ -525,6 +528,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
 	up_write(&mm->mmap_sem);
 	flush_tlb_mm(oldmm);
 	up_write(&oldmm->mmap_sem);
+fail_uprobe_end:
 	uprobe_end_dup_mmap();
 	return retval;
 fail_nomem_anon_vma_fork:
-- 
2.7.0

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

* [PATCH] mm, fork: make dup_mmap wait for mmap_sem for write killable
@ 2016-02-29 18:07     ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 18:07 UTC (permalink / raw)
  To: LKML
  Cc: Andrew Morton, linux-mm, Michal Hocko, Ingo Molnar,
	Peter Zijlstra, Oleg Nesterov, Konstantin Khlebnikov

From: Michal Hocko <mhocko@suse.com>

dup_mmap needs to lock current's mm mmap_sem for write. If the waiting
task gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely OOM
resolving. Wait for the lock in the killable mode and return with EINTR
if the task got killed while waiting.

Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 kernel/fork.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index d277e83ed3e0..139968026b76 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -413,7 +413,10 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
 	unsigned long charge;
 
 	uprobe_start_dup_mmap();
-	down_write(&oldmm->mmap_sem);
+	if (down_write_killable(&oldmm->mmap_sem)) {
+		retval = -EINTR;
+		goto fail_uprobe_end;
+	}
 	flush_cache_dup_mm(oldmm);
 	uprobe_dup_mmap(oldmm, mm);
 	/*
@@ -525,6 +528,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
 	up_write(&mm->mmap_sem);
 	flush_tlb_mm(oldmm);
 	up_write(&oldmm->mmap_sem);
+fail_uprobe_end:
 	uprobe_end_dup_mmap();
 	return retval;
 fail_nomem_anon_vma_fork:
-- 
2.7.0

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

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

* Re: [PATCH 13/18] exec: make exec path waiting for mmap_sem killable
  2016-02-29 17:47       ` Michal Hocko
  (?)
@ 2016-02-29 18:10         ` Oleg Nesterov
  -1 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 18:10 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Alexander Viro

On 02/29, Michal Hocko wrote:
>
> On Mon 29-02-16 18:23:34, Oleg Nesterov wrote:
> > On 02/29, Michal Hocko wrote:
> > >
> > > @@ -267,7 +267,10 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
> > >  	if (!vma)
> > >  		return -ENOMEM;
> > >
> > > -	down_write(&mm->mmap_sem);
> > > +	if (down_write_killable(&mm->mmap_sem)) {
> > > +		err = -EINTR;
> > > +		goto err_free;
> > > +	}
> > >  	vma->vm_mm = mm;
> >
> > I won't argue, but this looks unnecessary. Nobody else can see this new mm,
> > down_write() can't block.
> >
> > In fact I think we can just remove down_write/up_write here. Except perhaps
> > there is lockdep_assert_held() somewhere in these paths.
>
> This is what I had initially but then I've noticed that mm_alloc() does
> mm_init(current)->init_new_context(current)

yes, and init_new_context() is arch dependant...

> code doesn't seem much harder to follow, the callers are already
> handling all error paths so I guess it would be better to simply move on
> this.

Yes, agreed, please forget.

Oleg.

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

* Re: [PATCH 13/18] exec: make exec path waiting for mmap_sem killable
@ 2016-02-29 18:10         ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 18:10 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra

On 02/29, Michal Hocko wrote:
>
> On Mon 29-02-16 18:23:34, Oleg Nesterov wrote:
> > On 02/29, Michal Hocko wrote:
> > >
> > > @@ -267,7 +267,10 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
> > >  	if (!vma)
> > >  		return -ENOMEM;
> > >
> > > -	down_write(&mm->mmap_sem);
> > > +	if (down_write_killable(&mm->mmap_sem)) {
> > > +		err = -EINTR;
> > > +		goto err_free;
> > > +	}
> > >  	vma->vm_mm = mm;
> >
> > I won't argue, but this looks unnecessary. Nobody else can see this new mm,
> > down_write() can't block.
> >
> > In fact I think we can just remove down_write/up_write here. Except perhaps
> > there is lockdep_assert_held() somewhere in these paths.
>
> This is what I had initially but then I've noticed that mm_alloc() does
> mm_init(current)->init_new_context(current)

yes, and init_new_context() is arch dependant...

> code doesn't seem much harder to follow, the callers are already
> handling all error paths so I guess it would be better to simply move on
> this.

Yes, agreed, please forget.

Oleg.

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

* Re: [PATCH 13/18] exec: make exec path waiting for mmap_sem killable
@ 2016-02-29 18:10         ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 18:10 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Alexander Viro

On 02/29, Michal Hocko wrote:
>
> On Mon 29-02-16 18:23:34, Oleg Nesterov wrote:
> > On 02/29, Michal Hocko wrote:
> > >
> > > @@ -267,7 +267,10 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
> > >  	if (!vma)
> > >  		return -ENOMEM;
> > >
> > > -	down_write(&mm->mmap_sem);
> > > +	if (down_write_killable(&mm->mmap_sem)) {
> > > +		err = -EINTR;
> > > +		goto err_free;
> > > +	}
> > >  	vma->vm_mm = mm;
> >
> > I won't argue, but this looks unnecessary. Nobody else can see this new mm,
> > down_write() can't block.
> >
> > In fact I think we can just remove down_write/up_write here. Except perhaps
> > there is lockdep_assert_held() somewhere in these paths.
>
> This is what I had initially but then I've noticed that mm_alloc() does
> mm_init(current)->init_new_context(current)

yes, and init_new_context() is arch dependant...

> code doesn't seem much harder to follow, the callers are already
> handling all error paths so I guess it would be better to simply move on
> this.

Yes, agreed, please forget.

Oleg.

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

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

* Re: [PATCH] uprobes: wait for mmap_sem for write killable
  2016-02-29 17:42     ` Michal Hocko
@ 2016-02-29 18:11       ` Oleg Nesterov
  -1 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 18:11 UTC (permalink / raw)
  To: Michal Hocko; +Cc: LKML, Andrew Morton, linux-mm, Michal Hocko

On 02/29, Michal Hocko wrote:
>
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
>  	struct vm_area_struct *vma;
>  	int ret;
>  
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return -EINTR;
> +
>  	if (mm->uprobes_state.xol_area) {
>  		ret = -EALREADY;
>  		goto fail;
> @@ -1468,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
>  	if (current->flags & PF_EXITING)
>  		return;
>  
> -	if (!__create_xol_area(current->utask->dup_xol_addr))
> +	if (!__create_xol_area(current->utask->dup_xol_addr) &&
> +			!fatal_signal_pending(current)
>  		uprobe_warn(current, "dup xol area");
>  }

Looks good, thanks.

Oleg.

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

* Re: [PATCH] uprobes: wait for mmap_sem for write killable
@ 2016-02-29 18:11       ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 18:11 UTC (permalink / raw)
  To: Michal Hocko; +Cc: LKML, Andrew Morton, linux-mm, Michal Hocko

On 02/29, Michal Hocko wrote:
>
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
>  	struct vm_area_struct *vma;
>  	int ret;
>  
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return -EINTR;
> +
>  	if (mm->uprobes_state.xol_area) {
>  		ret = -EALREADY;
>  		goto fail;
> @@ -1468,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
>  	if (current->flags & PF_EXITING)
>  		return;
>  
> -	if (!__create_xol_area(current->utask->dup_xol_addr))
> +	if (!__create_xol_area(current->utask->dup_xol_addr) &&
> +			!fatal_signal_pending(current)
>  		uprobe_warn(current, "dup xol area");
>  }

Looks good, thanks.

Oleg.

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

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

* Re: [PATCH] mm, proc: make clear_refs killable
  2016-02-29 17:56     ` Michal Hocko
@ 2016-02-29 18:16       ` Oleg Nesterov
  -1 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 18:16 UTC (permalink / raw)
  To: Michal Hocko; +Cc: LKML, Andrew Morton, linux-mm, Michal Hocko, Petr Cermak

On 02/29, Michal Hocko wrote:
>
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -1027,11 +1027,15 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
>  		};
>
>  		if (type == CLEAR_REFS_MM_HIWATER_RSS) {
> +			if (down_write_killable(&mm->mmap_sem)) {
> +				count = -EINTR;
> +				goto out_mm;
> +			}
> +

We do not even need to change count, userspace won't see it anyway. But I agree
it look more clean this way.

I believe the patch is fine.

Oleg.

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

* Re: [PATCH] mm, proc: make clear_refs killable
@ 2016-02-29 18:16       ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 18:16 UTC (permalink / raw)
  To: Michal Hocko; +Cc: LKML, Andrew Morton, linux-mm, Michal Hocko, Petr Cermak

On 02/29, Michal Hocko wrote:
>
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -1027,11 +1027,15 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
>  		};
>
>  		if (type == CLEAR_REFS_MM_HIWATER_RSS) {
> +			if (down_write_killable(&mm->mmap_sem)) {
> +				count = -EINTR;
> +				goto out_mm;
> +			}
> +

We do not even need to change count, userspace won't see it anyway. But I agree
it look more clean this way.

I believe the patch is fine.

Oleg.

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

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

* Re: [PATCH] uprobes: wait for mmap_sem for write killable
  2016-02-29 18:11       ` Oleg Nesterov
@ 2016-02-29 18:22         ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 18:22 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: LKML, Andrew Morton, linux-mm

On Mon 29-02-16 19:11:06, Oleg Nesterov wrote:
> On 02/29, Michal Hocko wrote:
> >
> > --- a/kernel/events/uprobes.c
> > +++ b/kernel/events/uprobes.c
> > @@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
> >  	struct vm_area_struct *vma;
> >  	int ret;
> >  
> > -	down_write(&mm->mmap_sem);
> > +	if (down_write_killable(&mm->mmap_sem))
> > +		return -EINTR;
> > +
> >  	if (mm->uprobes_state.xol_area) {
> >  		ret = -EALREADY;
> >  		goto fail;
> > @@ -1468,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
> >  	if (current->flags & PF_EXITING)
> >  		return;
> >  
> > -	if (!__create_xol_area(current->utask->dup_xol_addr))
> > +	if (!__create_xol_area(current->utask->dup_xol_addr) &&
> > +			!fatal_signal_pending(current)
> >  		uprobe_warn(current, "dup xol area");
> >  }
> 
> Looks good, thanks.

Can I consider this your Acked-by?

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH] uprobes: wait for mmap_sem for write killable
@ 2016-02-29 18:22         ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-02-29 18:22 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: LKML, Andrew Morton, linux-mm

On Mon 29-02-16 19:11:06, Oleg Nesterov wrote:
> On 02/29, Michal Hocko wrote:
> >
> > --- a/kernel/events/uprobes.c
> > +++ b/kernel/events/uprobes.c
> > @@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
> >  	struct vm_area_struct *vma;
> >  	int ret;
> >  
> > -	down_write(&mm->mmap_sem);
> > +	if (down_write_killable(&mm->mmap_sem))
> > +		return -EINTR;
> > +
> >  	if (mm->uprobes_state.xol_area) {
> >  		ret = -EALREADY;
> >  		goto fail;
> > @@ -1468,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
> >  	if (current->flags & PF_EXITING)
> >  		return;
> >  
> > -	if (!__create_xol_area(current->utask->dup_xol_addr))
> > +	if (!__create_xol_area(current->utask->dup_xol_addr) &&
> > +			!fatal_signal_pending(current)
> >  		uprobe_warn(current, "dup xol area");
> >  }
> 
> Looks good, thanks.

Can I consider this your Acked-by?

-- 
Michal Hocko
SUSE Labs

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

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

* Re: [PATCH] uprobes: wait for mmap_sem for write killable
  2016-02-29 18:22         ` Michal Hocko
@ 2016-02-29 18:38           ` Oleg Nesterov
  -1 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 18:38 UTC (permalink / raw)
  To: Michal Hocko; +Cc: LKML, Andrew Morton, linux-mm

On 02/29, Michal Hocko wrote:
>
> On Mon 29-02-16 19:11:06, Oleg Nesterov wrote:
> > On 02/29, Michal Hocko wrote:
> > >
> > > --- a/kernel/events/uprobes.c
> > > +++ b/kernel/events/uprobes.c
> > > @@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
> > >  	struct vm_area_struct *vma;
> > >  	int ret;
> > >
> > > -	down_write(&mm->mmap_sem);
> > > +	if (down_write_killable(&mm->mmap_sem))
> > > +		return -EINTR;
> > > +
> > >  	if (mm->uprobes_state.xol_area) {
> > >  		ret = -EALREADY;
> > >  		goto fail;
> > > @@ -1468,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
> > >  	if (current->flags & PF_EXITING)
> > >  		return;
> > >
> > > -	if (!__create_xol_area(current->utask->dup_xol_addr))
> > > +	if (!__create_xol_area(current->utask->dup_xol_addr) &&
> > > +			!fatal_signal_pending(current)
> > >  		uprobe_warn(current, "dup xol area");
> > >  }
> >
> > Looks good, thanks.
>
> Can I consider this your Acked-by?

Yes, feel free to add. I forgot to add it.

Oleg.

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

* Re: [PATCH] uprobes: wait for mmap_sem for write killable
@ 2016-02-29 18:38           ` Oleg Nesterov
  0 siblings, 0 replies; 234+ messages in thread
From: Oleg Nesterov @ 2016-02-29 18:38 UTC (permalink / raw)
  To: Michal Hocko; +Cc: LKML, Andrew Morton, linux-mm

On 02/29, Michal Hocko wrote:
>
> On Mon 29-02-16 19:11:06, Oleg Nesterov wrote:
> > On 02/29, Michal Hocko wrote:
> > >
> > > --- a/kernel/events/uprobes.c
> > > +++ b/kernel/events/uprobes.c
> > > @@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
> > >  	struct vm_area_struct *vma;
> > >  	int ret;
> > >
> > > -	down_write(&mm->mmap_sem);
> > > +	if (down_write_killable(&mm->mmap_sem))
> > > +		return -EINTR;
> > > +
> > >  	if (mm->uprobes_state.xol_area) {
> > >  		ret = -EALREADY;
> > >  		goto fail;
> > > @@ -1468,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
> > >  	if (current->flags & PF_EXITING)
> > >  		return;
> > >
> > > -	if (!__create_xol_area(current->utask->dup_xol_addr))
> > > +	if (!__create_xol_area(current->utask->dup_xol_addr) &&
> > > +			!fatal_signal_pending(current)
> > >  		uprobe_warn(current, "dup xol area");
> > >  }
> >
> > Looks good, thanks.
>
> Can I consider this your Acked-by?

Yes, feel free to add. I forgot to add it.

Oleg.

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

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

* Re: [PATCH] mm, fork: make dup_mmap wait for mmap_sem for write killable
  2016-02-29 18:07     ` Michal Hocko
  (?)
@ 2016-02-29 20:13     ` kbuild test robot
  -1 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 20:13 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, linux-mm, Michal Hocko,
	Ingo Molnar, Peter Zijlstra, Oleg Nesterov,
	Konstantin Khlebnikov

[-- Attachment #1: Type: text/plain, Size: 1297 bytes --]

Hi Michal,

[auto build test ERROR on v4.5-rc6]
[also build test ERROR on next-20160229]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/mm-fork-make-dup_mmap-wait-for-mmap_sem-for-write-killable/20160301-021107
config: x86_64-lkp (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

   kernel/fork.c: In function 'dup_mmap':
>> kernel/fork.c:405:2: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&oldmm->mmap_sem)) {
     ^
   cc1: some warnings being treated as errors

vim +/down_write_killable +405 kernel/fork.c

   399		struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
   400		struct rb_node **rb_link, *rb_parent;
   401		int retval;
   402		unsigned long charge;
   403	
   404		uprobe_start_dup_mmap();
 > 405		if (down_write_killable(&oldmm->mmap_sem)) {
   406			retval = -EINTR;
   407			goto fail_uprobe_end;
   408		}

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 22426 bytes --]

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

* Re: [PATCH] mm, proc: make clear_refs killable
  2016-02-29 17:56     ` Michal Hocko
  (?)
  (?)
@ 2016-02-29 20:25     ` kbuild test robot
  -1 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-02-29 20:25 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, Andrew Morton, linux-mm, Michal Hocko,
	Oleg Nesterov, Petr Cermak

[-- Attachment #1: Type: text/plain, Size: 1257 bytes --]

Hi Michal,

[auto build test ERROR on v4.5-rc6]
[also build test ERROR on next-20160229]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/mm-proc-make-clear_refs-killable/20160301-020426
config: x86_64-lkp (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

   fs/proc/task_mmu.c: In function 'clear_refs_write':
>> fs/proc/task_mmu.c:1016:4: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
       if (down_write_killable(&mm->mmap_sem)) {
       ^
   cc1: some warnings being treated as errors

vim +/down_write_killable +1016 fs/proc/task_mmu.c

  1010				.test_walk = clear_refs_test_walk,
  1011				.mm = mm,
  1012				.private = &cp,
  1013			};
  1014	
  1015			if (type == CLEAR_REFS_MM_HIWATER_RSS) {
> 1016				if (down_write_killable(&mm->mmap_sem)) {
  1017					count = -EINTR;
  1018					goto out_mm;
  1019				}

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 22426 bytes --]

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

* Re: [PATCH 09/18] ipc, shm: make shmem attach/detach wait for mmap_sem killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-03-08 19:15     ` Davidlohr Bueso
  -1 siblings, 0 replies; 234+ messages in thread
From: Davidlohr Bueso @ 2016-03-08 19:15 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian K?nig, Daniel Vetter, Dave Hansen, David Airlie,
	David Rientjes, H . Peter Anvin, Hugh Dickins, Ingo Molnar,
	Johannes Weiner, Kirill A . Shutemov, Konstantin Khlebnikov,
	linux-arch, Mel Gorman, Oleg Nesterov, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Michal Hocko

On Mon, 29 Feb 2016, Michal Hocko wrote:

>From: Michal Hocko <mhocko@suse.com>
>
>shmat and shmdt rely on mmap_sem for write. If the waiting task
>gets killed by the oom killer it would block oom_reaper from
>asynchronous address space reclaim and reduce the chances of timely
>OOM resolving. Wait for the lock in the killable mode and return with
>EINTR if the task got killed while waiting.
>
>Cc: Davidlohr Bueso <dave@stgolabs.net>
>Cc: Hugh Dickins <hughd@google.com>
>Signed-off-by: Michal Hocko <mhocko@suse.com>

I have no objection to this perse, just one comment below.

Acked-by: Davidlohr Bueso <dave@stgolabs.net>

>---
> ipc/shm.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
>diff --git a/ipc/shm.c b/ipc/shm.c
>index 331fc1b0b3c7..b8cfa05940d2 100644
>--- a/ipc/shm.c
>+++ b/ipc/shm.c
>@@ -1200,7 +1200,11 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
> 	if (err)
> 		goto out_fput;
>
>-	down_write(&current->mm->mmap_sem);
>+	if (down_write_killable(&current->mm->mmap_sem)) {
>+		err = -EINVAL;
>+		goto out_fput;
>+	}

This should be EINTR, no?

Thanks,
Davidlohr

>+
> 	if (addr && !(shmflg & SHM_REMAP)) {
> 		err = -EINVAL;
> 		if (addr + size < addr)
>@@ -1271,7 +1275,8 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr)
> 	if (addr & ~PAGE_MASK)
> 		return retval;
>
>-	down_write(&mm->mmap_sem);
>+	if (down_write_killable(&mm->mmap_sem))
>+		return -EINTR;
>
> 	/*
> 	 * This function tries to be smart and unmap shm segments that
>-- 
>2.7.0
>

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

* Re: [PATCH 09/18] ipc, shm: make shmem attach/detach wait for mmap_sem killable
@ 2016-03-08 19:15     ` Davidlohr Bueso
  0 siblings, 0 replies; 234+ messages in thread
From: Davidlohr Bueso @ 2016-03-08 19:15 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian K?nig, Daniel Vetter, Dave Hansen, David Airlie,
	David Rientjes, H . Peter Anvin, Hugh Dickins, Ingo Molnar,
	Johannes Weiner, Kirill A . Shutemov, Konstantin Khlebnikov,
	linux-arch, Mel Gorman, Oleg Nesterov, Peter Zijlstra,
	Petr Cermak

On Mon, 29 Feb 2016, Michal Hocko wrote:

>From: Michal Hocko <mhocko@suse.com>
>
>shmat and shmdt rely on mmap_sem for write. If the waiting task
>gets killed by the oom killer it would block oom_reaper from
>asynchronous address space reclaim and reduce the chances of timely
>OOM resolving. Wait for the lock in the killable mode and return with
>EINTR if the task got killed while waiting.
>
>Cc: Davidlohr Bueso <dave@stgolabs.net>
>Cc: Hugh Dickins <hughd@google.com>
>Signed-off-by: Michal Hocko <mhocko@suse.com>

I have no objection to this perse, just one comment below.

Acked-by: Davidlohr Bueso <dave@stgolabs.net>

>---
> ipc/shm.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
>diff --git a/ipc/shm.c b/ipc/shm.c
>index 331fc1b0b3c7..b8cfa05940d2 100644
>--- a/ipc/shm.c
>+++ b/ipc/shm.c
>@@ -1200,7 +1200,11 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
> 	if (err)
> 		goto out_fput;
>
>-	down_write(&current->mm->mmap_sem);
>+	if (down_write_killable(&current->mm->mmap_sem)) {
>+		err = -EINVAL;
>+		goto out_fput;
>+	}

This should be EINTR, no?

Thanks,
Davidlohr

>+
> 	if (addr && !(shmflg & SHM_REMAP)) {
> 		err = -EINVAL;
> 		if (addr + size < addr)
>@@ -1271,7 +1275,8 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr)
> 	if (addr & ~PAGE_MASK)
> 		return retval;
>
>-	down_write(&mm->mmap_sem);
>+	if (down_write_killable(&mm->mmap_sem))
>+		return -EINTR;
>
> 	/*
> 	 * This function tries to be smart and unmap shm segments that
>-- 
>2.7.0
>

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

* Re: [PATCH 09/18] ipc, shm: make shmem attach/detach wait for mmap_sem killable
@ 2016-03-08 19:15     ` Davidlohr Bueso
  0 siblings, 0 replies; 234+ messages in thread
From: Davidlohr Bueso @ 2016-03-08 19:15 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian K?nig, Daniel Vetter, Dave Hansen, David Airlie,
	David Rientjes, H . Peter Anvin, Hugh Dickins, Ingo Molnar,
	Johannes Weiner, Kirill A . Shutemov, Konstantin Khlebnikov,
	linux-arch, Mel Gorman, Oleg Nesterov, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner, Michal Hocko

On Mon, 29 Feb 2016, Michal Hocko wrote:

>From: Michal Hocko <mhocko@suse.com>
>
>shmat and shmdt rely on mmap_sem for write. If the waiting task
>gets killed by the oom killer it would block oom_reaper from
>asynchronous address space reclaim and reduce the chances of timely
>OOM resolving. Wait for the lock in the killable mode and return with
>EINTR if the task got killed while waiting.
>
>Cc: Davidlohr Bueso <dave@stgolabs.net>
>Cc: Hugh Dickins <hughd@google.com>
>Signed-off-by: Michal Hocko <mhocko@suse.com>

I have no objection to this perse, just one comment below.

Acked-by: Davidlohr Bueso <dave@stgolabs.net>

>---
> ipc/shm.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
>diff --git a/ipc/shm.c b/ipc/shm.c
>index 331fc1b0b3c7..b8cfa05940d2 100644
>--- a/ipc/shm.c
>+++ b/ipc/shm.c
>@@ -1200,7 +1200,11 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
> 	if (err)
> 		goto out_fput;
>
>-	down_write(&current->mm->mmap_sem);
>+	if (down_write_killable(&current->mm->mmap_sem)) {
>+		err = -EINVAL;
>+		goto out_fput;
>+	}

This should be EINTR, no?

Thanks,
Davidlohr

>+
> 	if (addr && !(shmflg & SHM_REMAP)) {
> 		err = -EINVAL;
> 		if (addr + size < addr)
>@@ -1271,7 +1275,8 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr)
> 	if (addr & ~PAGE_MASK)
> 		return retval;
>
>-	down_write(&mm->mmap_sem);
>+	if (down_write_killable(&mm->mmap_sem))
>+		return -EINTR;
>
> 	/*
> 	 * This function tries to be smart and unmap shm segments that
>-- 
>2.7.0
>

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

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

* Re: [PATCH 09/18] ipc, shm: make shmem attach/detach wait for mmap_sem killable
  2016-03-08 19:15     ` Davidlohr Bueso
  (?)
@ 2016-03-09 10:16       ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-09 10:16 UTC (permalink / raw)
  To: Davidlohr Bueso
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian K?nig, Daniel Vetter, Dave Hansen, David Airlie,
	David Rientjes, H . Peter Anvin, Hugh Dickins, Ingo Molnar,
	Johannes Weiner, Kirill A . Shutemov, Konstantin Khlebnikov,
	linux-arch, Mel Gorman, Oleg Nesterov, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner

On Tue 08-03-16 11:15:50, Davidlohr Bueso wrote:
> On Mon, 29 Feb 2016, Michal Hocko wrote:
> 
> >From: Michal Hocko <mhocko@suse.com>
> >
> >shmat and shmdt rely on mmap_sem for write. If the waiting task
> >gets killed by the oom killer it would block oom_reaper from
> >asynchronous address space reclaim and reduce the chances of timely
> >OOM resolving. Wait for the lock in the killable mode and return with
> >EINTR if the task got killed while waiting.
> >
> >Cc: Davidlohr Bueso <dave@stgolabs.net>
> >Cc: Hugh Dickins <hughd@google.com>
> >Signed-off-by: Michal Hocko <mhocko@suse.com>
> 
> I have no objection to this perse, just one comment below.
> 
> Acked-by: Davidlohr Bueso <dave@stgolabs.net>

Thanks!

[...]
> >-	down_write(&current->mm->mmap_sem);
> >+	if (down_write_killable(&current->mm->mmap_sem)) {
> >+		err = -EINVAL;
> >+		goto out_fput;
> >+	}
> 
> This should be EINTR, no?

Of course. Thanks for catching that.
-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 09/18] ipc, shm: make shmem attach/detach wait for mmap_sem killable
@ 2016-03-09 10:16       ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-09 10:16 UTC (permalink / raw)
  To: Davidlohr Bueso
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian K?nig, Daniel Vetter, Dave Hansen, David Airlie,
	David Rientjes, H . Peter Anvin, Hugh Dickins, Ingo Molnar,
	Johannes Weiner, Kirill A . Shutemov, Konstantin Khlebnikov,
	linux-arch, Mel Gorman, Oleg Nesterov, Peter Zijlstra,
	Petr Cermak

On Tue 08-03-16 11:15:50, Davidlohr Bueso wrote:
> On Mon, 29 Feb 2016, Michal Hocko wrote:
> 
> >From: Michal Hocko <mhocko@suse.com>
> >
> >shmat and shmdt rely on mmap_sem for write. If the waiting task
> >gets killed by the oom killer it would block oom_reaper from
> >asynchronous address space reclaim and reduce the chances of timely
> >OOM resolving. Wait for the lock in the killable mode and return with
> >EINTR if the task got killed while waiting.
> >
> >Cc: Davidlohr Bueso <dave@stgolabs.net>
> >Cc: Hugh Dickins <hughd@google.com>
> >Signed-off-by: Michal Hocko <mhocko@suse.com>
> 
> I have no objection to this perse, just one comment below.
> 
> Acked-by: Davidlohr Bueso <dave@stgolabs.net>

Thanks!

[...]
> >-	down_write(&current->mm->mmap_sem);
> >+	if (down_write_killable(&current->mm->mmap_sem)) {
> >+		err = -EINVAL;
> >+		goto out_fput;
> >+	}
> 
> This should be EINTR, no?

Of course. Thanks for catching that.
-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 09/18] ipc, shm: make shmem attach/detach wait for mmap_sem killable
@ 2016-03-09 10:16       ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-09 10:16 UTC (permalink / raw)
  To: Davidlohr Bueso
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian K?nig, Daniel Vetter, Dave Hansen, David Airlie,
	David Rientjes, H . Peter Anvin, Hugh Dickins, Ingo Molnar,
	Johannes Weiner, Kirill A . Shutemov, Konstantin Khlebnikov,
	linux-arch, Mel Gorman, Oleg Nesterov, Peter Zijlstra,
	Petr Cermak, Thomas Gleixner

On Tue 08-03-16 11:15:50, Davidlohr Bueso wrote:
> On Mon, 29 Feb 2016, Michal Hocko wrote:
> 
> >From: Michal Hocko <mhocko@suse.com>
> >
> >shmat and shmdt rely on mmap_sem for write. If the waiting task
> >gets killed by the oom killer it would block oom_reaper from
> >asynchronous address space reclaim and reduce the chances of timely
> >OOM resolving. Wait for the lock in the killable mode and return with
> >EINTR if the task got killed while waiting.
> >
> >Cc: Davidlohr Bueso <dave@stgolabs.net>
> >Cc: Hugh Dickins <hughd@google.com>
> >Signed-off-by: Michal Hocko <mhocko@suse.com>
> 
> I have no objection to this perse, just one comment below.
> 
> Acked-by: Davidlohr Bueso <dave@stgolabs.net>

Thanks!

[...]
> >-	down_write(&current->mm->mmap_sem);
> >+	if (down_write_killable(&current->mm->mmap_sem)) {
> >+		err = -EINVAL;
> >+		goto out_fput;
> >+	}
> 
> This should be EINTR, no?

Of course. Thanks for catching that.
-- 
Michal Hocko
SUSE Labs

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

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

* [PATCH] ipc, shm: make shmem attach/detach wait for mmap_sem killable
  2016-02-29 13:26   ` Michal Hocko
@ 2016-03-09 10:19     ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-09 10:19 UTC (permalink / raw)
  To: LKML; +Cc: linux-mm, Davidlohr Bueso, Michal Hocko, Hugh Dickins

From: Michal Hocko <mhocko@suse.com>

shmat and shmdt rely on mmap_sem for write. If the waiting task
gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely
OOM resolving. Wait for the lock in the killable mode and return with
EINTR if the task got killed while waiting.

Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
Acked-by: Davidlohr Bueso <dave@stgolabs.net>
---
 ipc/shm.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/ipc/shm.c b/ipc/shm.c
index 331fc1b0b3c7..13282510bc0d 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -1200,7 +1200,11 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
 	if (err)
 		goto out_fput;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem)) {
+		err = -EINTR;
+		goto out_fput;
+	}
+
 	if (addr && !(shmflg & SHM_REMAP)) {
 		err = -EINVAL;
 		if (addr + size < addr)
@@ -1271,7 +1275,8 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr)
 	if (addr & ~PAGE_MASK)
 		return retval;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 	/*
 	 * This function tries to be smart and unmap shm segments that
-- 
2.7.0

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

* [PATCH] ipc, shm: make shmem attach/detach wait for mmap_sem killable
@ 2016-03-09 10:19     ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-09 10:19 UTC (permalink / raw)
  To: LKML; +Cc: linux-mm, Davidlohr Bueso, Michal Hocko, Hugh Dickins

From: Michal Hocko <mhocko@suse.com>

shmat and shmdt rely on mmap_sem for write. If the waiting task
gets killed by the oom killer it would block oom_reaper from
asynchronous address space reclaim and reduce the chances of timely
OOM resolving. Wait for the lock in the killable mode and return with
EINTR if the task got killed while waiting.

Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Michal Hocko <mhocko@suse.com>
Acked-by: Davidlohr Bueso <dave@stgolabs.net>
---
 ipc/shm.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/ipc/shm.c b/ipc/shm.c
index 331fc1b0b3c7..13282510bc0d 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -1200,7 +1200,11 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
 	if (err)
 		goto out_fput;
 
-	down_write(&current->mm->mmap_sem);
+	if (down_write_killable(&current->mm->mmap_sem)) {
+		err = -EINTR;
+		goto out_fput;
+	}
+
 	if (addr && !(shmflg & SHM_REMAP)) {
 		err = -EINVAL;
 		if (addr + size < addr)
@@ -1271,7 +1275,8 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr)
 	if (addr & ~PAGE_MASK)
 		return retval;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return -EINTR;
 
 	/*
 	 * This function tries to be smart and unmap shm segments that
-- 
2.7.0

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

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

* Re: [PATCH] ipc, shm: make shmem attach/detach wait for mmap_sem killable
  2016-03-09 10:19     ` Michal Hocko
  (?)
@ 2016-03-09 10:46     ` kbuild test robot
  -1 siblings, 0 replies; 234+ messages in thread
From: kbuild test robot @ 2016-03-09 10:46 UTC (permalink / raw)
  To: Michal Hocko
  Cc: kbuild-all, LKML, linux-mm, Davidlohr Bueso, Michal Hocko, Hugh Dickins

[-- Attachment #1: Type: text/plain, Size: 1399 bytes --]

Hi Michal,

[auto build test ERROR on v4.5-rc7]
[also build test ERROR on next-20160309]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Michal-Hocko/ipc-shm-make-shmem-attach-detach-wait-for-mmap_sem-killable/20160309-182238
config: xtensa-allyesconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=xtensa 

All errors (new ones prefixed by >>):

   ipc/shm.c: In function 'do_shmat':
>> ipc/shm.c:1203:2: error: implicit declaration of function 'down_write_killable' [-Werror=implicit-function-declaration]
     if (down_write_killable(&current->mm->mmap_sem)) {
     ^
   cc1: some warnings being treated as errors

vim +/down_write_killable +1203 ipc/shm.c

  1197		sfd->vm_ops = NULL;
  1198	
  1199		err = security_mmap_file(file, prot, flags);
  1200		if (err)
  1201			goto out_fput;
  1202	
> 1203		if (down_write_killable(&current->mm->mmap_sem)) {
  1204			err = -EINTR;
  1205			goto out_fput;
  1206		}

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 44058 bytes --]

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

* Re: [PATCH 01/18] mm: Make mmap_sem for write waits killable for mm syscalls
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-03-10 15:47     ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-10 15:47 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> This is the first step in making mmap_sem write holders killable. It

s/holders/waiters/?

> focuses on the trivial ones which are taking the lock early after
> entering the syscall and they are not changing state before.
>
> Therefore it is very easy to change them to use down_write_killable
> and immediately return with -EINTR. This will allow the waiter to
> pass away without blocking the mmap_sem which might be required to
> make a forward progress. E.g. the oom reaper will need the lock for
> reading to dismantle the OOM victim address space.
>
> The only tricky function in this patch is vm_mmap_pgoff which has many
> call sites via vm_mmap. To reduce the risk keep vm_mmap with the
> original non-killable semantic for now.
>
> vm_munmap callers do not bother checking the return value so open code
> it into the munmap syscall path for now for simplicity.
>
> Cc: Mel Gorman <mgorman@suse.de>
> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
> Cc: Konstantin Khlebnikov <koct9i@gmail.com>
> Cc: Hugh Dickins <hughd@google.com>
> Cc: Andrea Arcangeli <aarcange@redhat.com>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

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

* Re: [PATCH 01/18] mm: Make mmap_sem for write waits killable for mm syscalls
@ 2016-03-10 15:47     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-10 15:47 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> This is the first step in making mmap_sem write holders killable. It

s/holders/waiters/?

> focuses on the trivial ones which are taking the lock early after
> entering the syscall and they are not changing state before.
>
> Therefore it is very easy to change them to use down_write_killable
> and immediately return with -EINTR. This will allow the waiter to
> pass away without blocking the mmap_sem which might be required to
> make a forward progress. E.g. the oom reaper will need the lock for
> reading to dismantle the OOM victim address space.
>
> The only tricky function in this patch is vm_mmap_pgoff which has many
> call sites via vm_mmap. To reduce the risk keep vm_mmap with the
> original non-killable semantic for now.
>
> vm_munmap callers do not bother checking the return value so open code
> it into the munmap syscall path for now for simplicity.
>
> Cc: Mel Gorman <mgorman@suse.de>
> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
> Cc: Konstantin Khlebnikov <koct9i@gmail.com>
> Cc: Hugh Dickins <hughd@google.com>
> Cc: Andrea Arcangeli <aarcange@redhat.com>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

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

* Re: [PATCH 01/18] mm: Make mmap_sem for write waits killable for mm syscalls
@ 2016-03-10 15:47     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-10 15:47 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> This is the first step in making mmap_sem write holders killable. It

s/holders/waiters/?

> focuses on the trivial ones which are taking the lock early after
> entering the syscall and they are not changing state before.
>
> Therefore it is very easy to change them to use down_write_killable
> and immediately return with -EINTR. This will allow the waiter to
> pass away without blocking the mmap_sem which might be required to
> make a forward progress. E.g. the oom reaper will need the lock for
> reading to dismantle the OOM victim address space.
>
> The only tricky function in this patch is vm_mmap_pgoff which has many
> call sites via vm_mmap. To reduce the risk keep vm_mmap with the
> original non-killable semantic for now.
>
> vm_munmap callers do not bother checking the return value so open code
> it into the munmap syscall path for now for simplicity.
>
> Cc: Mel Gorman <mgorman@suse.de>
> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
> Cc: Konstantin Khlebnikov <koct9i@gmail.com>
> Cc: Hugh Dickins <hughd@google.com>
> Cc: Andrea Arcangeli <aarcange@redhat.com>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>


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

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

* Re: [PATCH 01/18] mm: Make mmap_sem for write waits killable for mm syscalls
  2016-03-10 15:47     ` Vlastimil Babka
  (?)
@ 2016-03-10 15:56       ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-10 15:56 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner

On Thu 10-03-16 16:47:16, Vlastimil Babka wrote:
> On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >From: Michal Hocko <mhocko@suse.com>
> >
> >This is the first step in making mmap_sem write holders killable. It
> 
> s/holders/waiters/?

right. Fixed
 
> >focuses on the trivial ones which are taking the lock early after
> >entering the syscall and they are not changing state before.
> >
> >Therefore it is very easy to change them to use down_write_killable
> >and immediately return with -EINTR. This will allow the waiter to
> >pass away without blocking the mmap_sem which might be required to
> >make a forward progress. E.g. the oom reaper will need the lock for
> >reading to dismantle the OOM victim address space.
> >
> >The only tricky function in this patch is vm_mmap_pgoff which has many
> >call sites via vm_mmap. To reduce the risk keep vm_mmap with the
> >original non-killable semantic for now.
> >
> >vm_munmap callers do not bother checking the return value so open code
> >it into the munmap syscall path for now for simplicity.
> >
> >Cc: Mel Gorman <mgorman@suse.de>
> >Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
> >Cc: Konstantin Khlebnikov <koct9i@gmail.com>
> >Cc: Hugh Dickins <hughd@google.com>
> >Cc: Andrea Arcangeli <aarcange@redhat.com>
> >Cc: David Rientjes <rientjes@google.com>
> >Cc: Dave Hansen <dave.hansen@linux.intel.com>
> >Cc: Johannes Weiner <hannes@cmpxchg.org>
> >Signed-off-by: Michal Hocko <mhocko@suse.com>
> 
> Acked-by: Vlastimil Babka <vbabka@suse.cz>

Thanks!
-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 01/18] mm: Make mmap_sem for write waits killable for mm syscalls
@ 2016-03-10 15:56       ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-10 15:56 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov

On Thu 10-03-16 16:47:16, Vlastimil Babka wrote:
> On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >From: Michal Hocko <mhocko@suse.com>
> >
> >This is the first step in making mmap_sem write holders killable. It
> 
> s/holders/waiters/?

right. Fixed
 
> >focuses on the trivial ones which are taking the lock early after
> >entering the syscall and they are not changing state before.
> >
> >Therefore it is very easy to change them to use down_write_killable
> >and immediately return with -EINTR. This will allow the waiter to
> >pass away without blocking the mmap_sem which might be required to
> >make a forward progress. E.g. the oom reaper will need the lock for
> >reading to dismantle the OOM victim address space.
> >
> >The only tricky function in this patch is vm_mmap_pgoff which has many
> >call sites via vm_mmap. To reduce the risk keep vm_mmap with the
> >original non-killable semantic for now.
> >
> >vm_munmap callers do not bother checking the return value so open code
> >it into the munmap syscall path for now for simplicity.
> >
> >Cc: Mel Gorman <mgorman@suse.de>
> >Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
> >Cc: Konstantin Khlebnikov <koct9i@gmail.com>
> >Cc: Hugh Dickins <hughd@google.com>
> >Cc: Andrea Arcangeli <aarcange@redhat.com>
> >Cc: David Rientjes <rientjes@google.com>
> >Cc: Dave Hansen <dave.hansen@linux.intel.com>
> >Cc: Johannes Weiner <hannes@cmpxchg.org>
> >Signed-off-by: Michal Hocko <mhocko@suse.com>
> 
> Acked-by: Vlastimil Babka <vbabka@suse.cz>

Thanks!
-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 01/18] mm: Make mmap_sem for write waits killable for mm syscalls
@ 2016-03-10 15:56       ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-10 15:56 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner

On Thu 10-03-16 16:47:16, Vlastimil Babka wrote:
> On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >From: Michal Hocko <mhocko@suse.com>
> >
> >This is the first step in making mmap_sem write holders killable. It
> 
> s/holders/waiters/?

right. Fixed
 
> >focuses on the trivial ones which are taking the lock early after
> >entering the syscall and they are not changing state before.
> >
> >Therefore it is very easy to change them to use down_write_killable
> >and immediately return with -EINTR. This will allow the waiter to
> >pass away without blocking the mmap_sem which might be required to
> >make a forward progress. E.g. the oom reaper will need the lock for
> >reading to dismantle the OOM victim address space.
> >
> >The only tricky function in this patch is vm_mmap_pgoff which has many
> >call sites via vm_mmap. To reduce the risk keep vm_mmap with the
> >original non-killable semantic for now.
> >
> >vm_munmap callers do not bother checking the return value so open code
> >it into the munmap syscall path for now for simplicity.
> >
> >Cc: Mel Gorman <mgorman@suse.de>
> >Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
> >Cc: Konstantin Khlebnikov <koct9i@gmail.com>
> >Cc: Hugh Dickins <hughd@google.com>
> >Cc: Andrea Arcangeli <aarcange@redhat.com>
> >Cc: David Rientjes <rientjes@google.com>
> >Cc: Dave Hansen <dave.hansen@linux.intel.com>
> >Cc: Johannes Weiner <hannes@cmpxchg.org>
> >Signed-off-by: Michal Hocko <mhocko@suse.com>
> 
> Acked-by: Vlastimil Babka <vbabka@suse.cz>

Thanks!
-- 
Michal Hocko
SUSE Labs

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

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

* Re: [PATCH 02/18] mm: make vm_mmap killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-03-11  9:59     ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11  9:59 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Al Viro

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> All the callers of vm_mmap seem to check for the failure already
> and bail out in one way or another on the error which means that

Hmm I'm not that sure about this one:
   17   1071  fs/binfmt_elf.c <<load_elf_binary>>

Assigns result of vm_mmap() to "error" variable which is never checked. 
Shouldn't __must_check trigger here?

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

* Re: [PATCH 02/18] mm: make vm_mmap killable
@ 2016-03-11  9:59     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11  9:59 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> All the callers of vm_mmap seem to check for the failure already
> and bail out in one way or another on the error which means that

Hmm I'm not that sure about this one:
   17   1071  fs/binfmt_elf.c <<load_elf_binary>>

Assigns result of vm_mmap() to "error" variable which is never checked. 
Shouldn't __must_check trigger here?


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

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

* Re: [PATCH 02/18] mm: make vm_mmap killable
@ 2016-03-11  9:59     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11  9:59 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Al Viro

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> All the callers of vm_mmap seem to check for the failure already
> and bail out in one way or another on the error which means that

Hmm I'm not that sure about this one:
   17   1071  fs/binfmt_elf.c <<load_elf_binary>>

Assigns result of vm_mmap() to "error" variable which is never checked. 
Shouldn't __must_check trigger here?


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

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

* Re: [PATCH 03/18] mm: make vm_munmap killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-03-11 10:06     ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 10:06 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> Almost all current users of vm_munmap are ignoring the return value
> and so they do not handle potential error. This means that some VMAs

    1   7834  arch/x86/kvm/x86.c <<__x86_set_memory_region>>

              r = vm_munmap(old.userspace_addr, old.npages * PAGE_SIZE);
              WARN_ON(r < 0);

This warning will potentially add noise to OOM output?

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

* Re: [PATCH 03/18] mm: make vm_munmap killable
@ 2016-03-11 10:06     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 10:06 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> Almost all current users of vm_munmap are ignoring the return value
> and so they do not handle potential error. This means that some VMAs

    1   7834  arch/x86/kvm/x86.c <<__x86_set_memory_region>>

              r = vm_munmap(old.userspace_addr, old.npages * PAGE_SIZE);
              WARN_ON(r < 0);

This warning will potentially add noise to OOM output?

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

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

* Re: [PATCH 03/18] mm: make vm_munmap killable
@ 2016-03-11 10:06     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 10:06 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> Almost all current users of vm_munmap are ignoring the return value
> and so they do not handle potential error. This means that some VMAs

    1   7834  arch/x86/kvm/x86.c <<__x86_set_memory_region>>

              r = vm_munmap(old.userspace_addr, old.npages * PAGE_SIZE);
              WARN_ON(r < 0);

This warning will potentially add noise to OOM output?

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

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

* Re: [PATCH 04/18] mm, aout: handle vm_brk failures
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-03-11 10:32     ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 10:32 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Ingo Molnar, Alexander Viro

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> vm_brk is allowed to fail but load_aout_binary simply ignores the error
> and happily continues. I haven't noticed any problem from that in real
> life but later patches will make the failure more likely because
> vm_brk will become killable (resp. mmap_sem for write waiting will become
> killable) so we should be more careful now.
>
> The error handling should be quite straightforward because there are
> calls to vm_mmap which check the error properly already. The only
> notable exception is set_brk which is called after beyond_if label.
> But nothing indicates that we cannot move it above set_binfmt as the two
> do not depend on each other and fail before we do set_binfmt and alter
> reference counting.
>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked--by: Vlastimil Babka <vbabka@suse.cz>

[...]

> @@ -378,7 +381,9 @@ static int load_aout_library(struct file *file)
>   			       "N_TXTOFF is not page aligned. Please convert library: %pD\n",
>   			       file);
>   		}
> -		vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
> +		retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
> +		if (IS_ERR_VALUE(retval))
> +			goto out;
>   		

You could have removed the extra whitespace on the line above, which my vim so 
prominently highlights :)

>   		read_code(file, start_addr, N_TXTOFF(ex),
>   			  ex.a_text + ex.a_data);
>

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

* Re: [PATCH 04/18] mm, aout: handle vm_brk failures
@ 2016-03-11 10:32     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 10:32 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> vm_brk is allowed to fail but load_aout_binary simply ignores the error
> and happily continues. I haven't noticed any problem from that in real
> life but later patches will make the failure more likely because
> vm_brk will become killable (resp. mmap_sem for write waiting will become
> killable) so we should be more careful now.
>
> The error handling should be quite straightforward because there are
> calls to vm_mmap which check the error properly already. The only
> notable exception is set_brk which is called after beyond_if label.
> But nothing indicates that we cannot move it above set_binfmt as the two
> do not depend on each other and fail before we do set_binfmt and alter
> reference counting.
>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked--by: Vlastimil Babka <vbabka@suse.cz>

[...]

> @@ -378,7 +381,9 @@ static int load_aout_library(struct file *file)
>   			       "N_TXTOFF is not page aligned. Please convert library: %pD\n",
>   			       file);
>   		}
> -		vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
> +		retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
> +		if (IS_ERR_VALUE(retval))
> +			goto out;
>   		

You could have removed the extra whitespace on the line above, which my vim so 
prominently highlights :)

>   		read_code(file, start_addr, N_TXTOFF(ex),
>   			  ex.a_text + ex.a_data);
>

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

* Re: [PATCH 04/18] mm, aout: handle vm_brk failures
@ 2016-03-11 10:32     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 10:32 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Ingo Molnar, Alexander Viro

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> vm_brk is allowed to fail but load_aout_binary simply ignores the error
> and happily continues. I haven't noticed any problem from that in real
> life but later patches will make the failure more likely because
> vm_brk will become killable (resp. mmap_sem for write waiting will become
> killable) so we should be more careful now.
>
> The error handling should be quite straightforward because there are
> calls to vm_mmap which check the error properly already. The only
> notable exception is set_brk which is called after beyond_if label.
> But nothing indicates that we cannot move it above set_binfmt as the two
> do not depend on each other and fail before we do set_binfmt and alter
> reference counting.
>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked--by: Vlastimil Babka <vbabka@suse.cz>

[...]

> @@ -378,7 +381,9 @@ static int load_aout_library(struct file *file)
>   			       "N_TXTOFF is not page aligned. Please convert library: %pD\n",
>   			       file);
>   		}
> -		vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
> +		retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
> +		if (IS_ERR_VALUE(retval))
> +			goto out;
>   		

You could have removed the extra whitespace on the line above, which my vim so 
prominently highlights :)

>   		read_code(file, start_addr, N_TXTOFF(ex),
>   			  ex.a_text + ex.a_data);
>

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

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

* Re: [PATCH 05/18] mm, elf: handle vm_brk error
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-03-11 10:35     ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 10:35 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> load_elf_library doesn't handle vm_brk failure although nothing really
> indicates it cannot do that because the function is allowed to fail
> due to vm_mmap failures already. This might be not a problem now
> but later patch will make vm_brk killable (resp. mmap_sem for write
> waiting will become killable) and so the failure will be more probable.
>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

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

* Re: [PATCH 05/18] mm, elf: handle vm_brk error
@ 2016-03-11 10:35     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 10:35 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> load_elf_library doesn't handle vm_brk failure although nothing really
> indicates it cannot do that because the function is allowed to fail
> due to vm_mmap failures already. This might be not a problem now
> but later patch will make vm_brk killable (resp. mmap_sem for write
> waiting will become killable) and so the failure will be more probable.
>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

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

* Re: [PATCH 05/18] mm, elf: handle vm_brk error
@ 2016-03-11 10:35     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 10:35 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> load_elf_library doesn't handle vm_brk failure although nothing really
> indicates it cannot do that because the function is allowed to fail
> due to vm_mmap failures already. This might be not a problem now
> but later patch will make vm_brk killable (resp. mmap_sem for write
> waiting will become killable) and so the failure will be more probable.
>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

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

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

* Re: [PATCH 06/18] mm: make vm_brk killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-03-11 10:44     ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 10:44 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> Now that all the callers handle vm_brk failure we can change it
> wait for mmap_sem killable to help oom_reaper to not get blocked
> just because vm_brk gets blocked behind mmap_sem readers.
>
> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Andrea Arcangeli <aarcange@redhat.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

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

* Re: [PATCH 06/18] mm: make vm_brk killable
@ 2016-03-11 10:44     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 10:44 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> Now that all the callers handle vm_brk failure we can change it
> wait for mmap_sem killable to help oom_reaper to not get blocked
> just because vm_brk gets blocked behind mmap_sem readers.
>
> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Andrea Arcangeli <aarcange@redhat.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

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

* Re: [PATCH 06/18] mm: make vm_brk killable
@ 2016-03-11 10:44     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 10:44 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> Now that all the callers handle vm_brk failure we can change it
> wait for mmap_sem killable to help oom_reaper to not get blocked
> just because vm_brk gets blocked behind mmap_sem readers.
>
> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Andrea Arcangeli <aarcange@redhat.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

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

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

* Re: [PATCH] mm, proc: make clear_refs killable
  2016-02-29 17:56     ` Michal Hocko
@ 2016-03-11 10:59       ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 10:59 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Michal Hocko, Oleg Nesterov, Petr Cermak

On 02/29/2016 06:56 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> CLEAR_REFS_MM_HIWATER_RSS and CLEAR_REFS_SOFT_DIRTY are relying on
> mmap_sem for write. If the waiting task gets killed by the oom killer
> and it would operate on the current's mm it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely OOM
> resolving. Wait for the lock in the killable mode and return with EINTR
> if the task got killed while waiting. This will also expedite the return
> to the userspace and do_exit even if the mm is remote.
>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Petr Cermak <petrcermak@chromium.org>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

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

* Re: [PATCH] mm, proc: make clear_refs killable
@ 2016-03-11 10:59       ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 10:59 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Michal Hocko, Oleg Nesterov, Petr Cermak

On 02/29/2016 06:56 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> CLEAR_REFS_MM_HIWATER_RSS and CLEAR_REFS_SOFT_DIRTY are relying on
> mmap_sem for write. If the waiting task gets killed by the oom killer
> and it would operate on the current's mm it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely OOM
> resolving. Wait for the lock in the killable mode and return with EINTR
> if the task got killed while waiting. This will also expedite the return
> to the userspace and do_exit even if the mm is remote.
>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Petr Cermak <petrcermak@chromium.org>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

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

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

* Re: [PATCH] mm, fork: make dup_mmap wait for mmap_sem for write killable
  2016-02-29 18:07     ` Michal Hocko
@ 2016-03-11 11:12       ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 11:12 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Michal Hocko, Ingo Molnar,
	Peter Zijlstra, Oleg Nesterov, Konstantin Khlebnikov

On 02/29/2016 07:07 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> dup_mmap needs to lock current's mm mmap_sem for write. If the waiting
> task gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely OOM
> resolving. Wait for the lock in the killable mode and return with EINTR
> if the task got killed while waiting.
>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Konstantin Khlebnikov <koct9i@gmail.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   kernel/fork.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/fork.c b/kernel/fork.c
> index d277e83ed3e0..139968026b76 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -413,7 +413,10 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
>   	unsigned long charge;
>
>   	uprobe_start_dup_mmap();
> -	down_write(&oldmm->mmap_sem);
> +	if (down_write_killable(&oldmm->mmap_sem)) {
> +		retval = -EINTR;
> +		goto fail_uprobe_end;
> +	}
>   	flush_cache_dup_mm(oldmm);
>   	uprobe_dup_mmap(oldmm, mm);
>   	/*
> @@ -525,6 +528,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
>   	up_write(&mm->mmap_sem);
>   	flush_tlb_mm(oldmm);
>   	up_write(&oldmm->mmap_sem);
> +fail_uprobe_end:
>   	uprobe_end_dup_mmap();
>   	return retval;
>   fail_nomem_anon_vma_fork:
>

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

* Re: [PATCH] mm, fork: make dup_mmap wait for mmap_sem for write killable
@ 2016-03-11 11:12       ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 11:12 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Michal Hocko, Ingo Molnar,
	Peter Zijlstra, Oleg Nesterov, Konstantin Khlebnikov

On 02/29/2016 07:07 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> dup_mmap needs to lock current's mm mmap_sem for write. If the waiting
> task gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely OOM
> resolving. Wait for the lock in the killable mode and return with EINTR
> if the task got killed while waiting.
>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Konstantin Khlebnikov <koct9i@gmail.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   kernel/fork.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/fork.c b/kernel/fork.c
> index d277e83ed3e0..139968026b76 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -413,7 +413,10 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
>   	unsigned long charge;
>
>   	uprobe_start_dup_mmap();
> -	down_write(&oldmm->mmap_sem);
> +	if (down_write_killable(&oldmm->mmap_sem)) {
> +		retval = -EINTR;
> +		goto fail_uprobe_end;
> +	}
>   	flush_cache_dup_mm(oldmm);
>   	uprobe_dup_mmap(oldmm, mm);
>   	/*
> @@ -525,6 +528,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
>   	up_write(&mm->mmap_sem);
>   	flush_tlb_mm(oldmm);
>   	up_write(&oldmm->mmap_sem);
> +fail_uprobe_end:
>   	uprobe_end_dup_mmap();
>   	return retval;
>   fail_nomem_anon_vma_fork:
>

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

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

* Re: [PATCH] ipc, shm: make shmem attach/detach wait for mmap_sem killable
  2016-03-09 10:19     ` Michal Hocko
@ 2016-03-11 11:18       ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 11:18 UTC (permalink / raw)
  To: Michal Hocko, LKML; +Cc: linux-mm, Davidlohr Bueso, Michal Hocko, Hugh Dickins

On 03/09/2016 11:19 AM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> shmat and shmdt rely on mmap_sem for write. If the waiting task
> gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely
> OOM resolving. Wait for the lock in the killable mode and return with
> EINTR if the task got killed while waiting.
>
> Cc: Hugh Dickins <hughd@google.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>
> Acked-by: Davidlohr Bueso <dave@stgolabs.net>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   ipc/shm.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/ipc/shm.c b/ipc/shm.c
> index 331fc1b0b3c7..13282510bc0d 100644
> --- a/ipc/shm.c
> +++ b/ipc/shm.c
> @@ -1200,7 +1200,11 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
>   	if (err)
>   		goto out_fput;
>
> -	down_write(&current->mm->mmap_sem);
> +	if (down_write_killable(&current->mm->mmap_sem)) {
> +		err = -EINTR;
> +		goto out_fput;
> +	}
> +
>   	if (addr && !(shmflg & SHM_REMAP)) {
>   		err = -EINVAL;
>   		if (addr + size < addr)
> @@ -1271,7 +1275,8 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr)
>   	if (addr & ~PAGE_MASK)
>   		return retval;
>
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return -EINTR;
>
>   	/*
>   	 * This function tries to be smart and unmap shm segments that
>

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

* Re: [PATCH] ipc, shm: make shmem attach/detach wait for mmap_sem killable
@ 2016-03-11 11:18       ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 11:18 UTC (permalink / raw)
  To: Michal Hocko, LKML; +Cc: linux-mm, Davidlohr Bueso, Michal Hocko, Hugh Dickins

On 03/09/2016 11:19 AM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> shmat and shmdt rely on mmap_sem for write. If the waiting task
> gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely
> OOM resolving. Wait for the lock in the killable mode and return with
> EINTR if the task got killed while waiting.
>
> Cc: Hugh Dickins <hughd@google.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>
> Acked-by: Davidlohr Bueso <dave@stgolabs.net>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   ipc/shm.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/ipc/shm.c b/ipc/shm.c
> index 331fc1b0b3c7..13282510bc0d 100644
> --- a/ipc/shm.c
> +++ b/ipc/shm.c
> @@ -1200,7 +1200,11 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
>   	if (err)
>   		goto out_fput;
>
> -	down_write(&current->mm->mmap_sem);
> +	if (down_write_killable(&current->mm->mmap_sem)) {
> +		err = -EINTR;
> +		goto out_fput;
> +	}
> +
>   	if (addr && !(shmflg & SHM_REMAP)) {
>   		err = -EINVAL;
>   		if (addr + size < addr)
> @@ -1271,7 +1275,8 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr)
>   	if (addr & ~PAGE_MASK)
>   		return retval;
>
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return -EINTR;
>
>   	/*
>   	 * This function tries to be smart and unmap shm segments that
>

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

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

* Re: [PATCH 10/18] vdso: make arch_setup_additional_pages wait for mmap_sem for write killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-03-11 11:28     ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 11:28 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> most architectures are relying on mmap_sem for write in their
> arch_setup_additional_pages. If the waiting task gets killed by the oom
> killer it would block oom_reaper from asynchronous address space reclaim
> and reduce the chances of timely OOM resolving. Wait for the lock in
> the killable mode and return with EINTR if the task got killed while
> waiting.
>
> Cc: linux-arch@vger.kernel.org
> Cc: Andy Lutomirski <luto@amacapital.net>
> Signed-off-by: Michal Hocko <mhocko@suse.com>


I don't have much arch-specific insight, but looks OK.

Acked-by: Vlastimil Babka <vbabka@suse.cz>

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

* Re: [PATCH 10/18] vdso: make arch_setup_additional_pages wait for mmap_sem for write killable
@ 2016-03-11 11:28     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 11:28 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> most architectures are relying on mmap_sem for write in their
> arch_setup_additional_pages. If the waiting task gets killed by the oom
> killer it would block oom_reaper from asynchronous address space reclaim
> and reduce the chances of timely OOM resolving. Wait for the lock in
> the killable mode and return with EINTR if the task got killed while
> waiting.
>
> Cc: linux-arch@vger.kernel.org
> Cc: Andy Lutomirski <luto@amacapital.net>
> Signed-off-by: Michal Hocko <mhocko@suse.com>


I don't have much arch-specific insight, but looks OK.

Acked-by: Vlastimil Babka <vbabka@suse.cz>

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

* Re: [PATCH 10/18] vdso: make arch_setup_additional_pages wait for mmap_sem for write killable
@ 2016-03-11 11:28     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 11:28 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> most architectures are relying on mmap_sem for write in their
> arch_setup_additional_pages. If the waiting task gets killed by the oom
> killer it would block oom_reaper from asynchronous address space reclaim
> and reduce the chances of timely OOM resolving. Wait for the lock in
> the killable mode and return with EINTR if the task got killed while
> waiting.
>
> Cc: linux-arch@vger.kernel.org
> Cc: Andy Lutomirski <luto@amacapital.net>
> Signed-off-by: Michal Hocko <mhocko@suse.com>


I don't have much arch-specific insight, but looks OK.

Acked-by: Vlastimil Babka <vbabka@suse.cz>

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

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

* Re: [PATCH 11/18] coredump: make coredump_wait wait for mma_sem for write killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-03-11 11:32     ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 11:32 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> coredump_wait waits for mmap_sem for write currently which can
> prevent oom_reaper to reclaim the oom victims address space
> asynchronously because that requires mmap_sem for read. This might
> happen if the oom victim is multi threaded and some thread(s) is
> holding mmap_sem for read (e.g. page fault) and it is stuck in
> the page allocator while other thread(s) reached coredump_wait
> already.
>
> This patch simply uses down_write_killable and bails out with EINTR
> if the lock got interrupted by the fatal signal. do_coredump will
> return right away and do_group_exit will take care to zap the whole
> thread group.
>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   fs/coredump.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/coredump.c b/fs/coredump.c
> index 9ea87e9fdccf..6b8aa1629891 100644
> --- a/fs/coredump.c
> +++ b/fs/coredump.c
> @@ -410,7 +410,9 @@ static int coredump_wait(int exit_code, struct core_state *core_state)
>   	core_state->dumper.task = tsk;
>   	core_state->dumper.next = NULL;
>
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return -EINTR;
> +
>   	if (!mm->core_state)
>   		core_waiters = zap_threads(tsk, mm, core_state, exit_code);
>   	up_write(&mm->mmap_sem);
>

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

* Re: [PATCH 11/18] coredump: make coredump_wait wait for mma_sem for write killable
@ 2016-03-11 11:32     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 11:32 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> coredump_wait waits for mmap_sem for write currently which can
> prevent oom_reaper to reclaim the oom victims address space
> asynchronously because that requires mmap_sem for read. This might
> happen if the oom victim is multi threaded and some thread(s) is
> holding mmap_sem for read (e.g. page fault) and it is stuck in
> the page allocator while other thread(s) reached coredump_wait
> already.
>
> This patch simply uses down_write_killable and bails out with EINTR
> if the lock got interrupted by the fatal signal. do_coredump will
> return right away and do_group_exit will take care to zap the whole
> thread group.
>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   fs/coredump.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/coredump.c b/fs/coredump.c
> index 9ea87e9fdccf..6b8aa1629891 100644
> --- a/fs/coredump.c
> +++ b/fs/coredump.c
> @@ -410,7 +410,9 @@ static int coredump_wait(int exit_code, struct core_state *core_state)
>   	core_state->dumper.task = tsk;
>   	core_state->dumper.next = NULL;
>
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return -EINTR;
> +
>   	if (!mm->core_state)
>   		core_waiters = zap_threads(tsk, mm, core_state, exit_code);
>   	up_write(&mm->mmap_sem);
>

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

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

* Re: [PATCH 11/18] coredump: make coredump_wait wait for mma_sem for write killable
@ 2016-03-11 11:32     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 11:32 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> coredump_wait waits for mmap_sem for write currently which can
> prevent oom_reaper to reclaim the oom victims address space
> asynchronously because that requires mmap_sem for read. This might
> happen if the oom victim is multi threaded and some thread(s) is
> holding mmap_sem for read (e.g. page fault) and it is stuck in
> the page allocator while other thread(s) reached coredump_wait
> already.
>
> This patch simply uses down_write_killable and bails out with EINTR
> if the lock got interrupted by the fatal signal. do_coredump will
> return right away and do_group_exit will take care to zap the whole
> thread group.
>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   fs/coredump.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/coredump.c b/fs/coredump.c
> index 9ea87e9fdccf..6b8aa1629891 100644
> --- a/fs/coredump.c
> +++ b/fs/coredump.c
> @@ -410,7 +410,9 @@ static int coredump_wait(int exit_code, struct core_state *core_state)
>   	core_state->dumper.task = tsk;
>   	core_state->dumper.next = NULL;
>
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return -EINTR;
> +
>   	if (!mm->core_state)
>   		core_waiters = zap_threads(tsk, mm, core_state, exit_code);
>   	up_write(&mm->mmap_sem);
>

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

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

* Re: [PATCH 11/18] coredump: make coredump_wait wait for mma_sem for write killable
  2016-03-11 11:32     ` Vlastimil Babka
  (?)
@ 2016-03-11 11:54       ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 11:54 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 03/11/2016 12:32 PM, Vlastimil Babka wrote:
> On 02/29/2016 02:26 PM, Michal Hocko wrote:
>> From: Michal Hocko <mhocko@suse.com>
>>
>> coredump_wait waits for mmap_sem for write currently which can
>> prevent oom_reaper to reclaim the oom victims address space
>> asynchronously because that requires mmap_sem for read. This might
>> happen if the oom victim is multi threaded and some thread(s) is
>> holding mmap_sem for read (e.g. page fault) and it is stuck in
>> the page allocator while other thread(s) reached coredump_wait
>> already.
>>
>> This patch simply uses down_write_killable and bails out with EINTR
>> if the lock got interrupted by the fatal signal. do_coredump will
>> return right away and do_group_exit will take care to zap the whole
>> thread group.
>>
>> Cc: Oleg Nesterov <oleg@redhat.com>
>> Signed-off-by: Michal Hocko <mhocko@suse.com>
>
> Acked-by: Vlastimil Babka <vbabka@suse.cz>

Forgot to point out typo in Subject which makes it hard to grep for mmap_sem

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

* Re: [PATCH 11/18] coredump: make coredump_wait wait for mma_sem for write killable
@ 2016-03-11 11:54       ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 11:54 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

On 03/11/2016 12:32 PM, Vlastimil Babka wrote:
> On 02/29/2016 02:26 PM, Michal Hocko wrote:
>> From: Michal Hocko <mhocko@suse.com>
>>
>> coredump_wait waits for mmap_sem for write currently which can
>> prevent oom_reaper to reclaim the oom victims address space
>> asynchronously because that requires mmap_sem for read. This might
>> happen if the oom victim is multi threaded and some thread(s) is
>> holding mmap_sem for read (e.g. page fault) and it is stuck in
>> the page allocator while other thread(s) reached coredump_wait
>> already.
>>
>> This patch simply uses down_write_killable and bails out with EINTR
>> if the lock got interrupted by the fatal signal. do_coredump will
>> return right away and do_group_exit will take care to zap the whole
>> thread group.
>>
>> Cc: Oleg Nesterov <oleg@redhat.com>
>> Signed-off-by: Michal Hocko <mhocko@suse.com>
>
> Acked-by: Vlastimil Babka <vbabka@suse.cz>

Forgot to point out typo in Subject which makes it hard to grep for mmap_sem

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

* Re: [PATCH 11/18] coredump: make coredump_wait wait for mma_sem for write killable
@ 2016-03-11 11:54       ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 11:54 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 03/11/2016 12:32 PM, Vlastimil Babka wrote:
> On 02/29/2016 02:26 PM, Michal Hocko wrote:
>> From: Michal Hocko <mhocko@suse.com>
>>
>> coredump_wait waits for mmap_sem for write currently which can
>> prevent oom_reaper to reclaim the oom victims address space
>> asynchronously because that requires mmap_sem for read. This might
>> happen if the oom victim is multi threaded and some thread(s) is
>> holding mmap_sem for read (e.g. page fault) and it is stuck in
>> the page allocator while other thread(s) reached coredump_wait
>> already.
>>
>> This patch simply uses down_write_killable and bails out with EINTR
>> if the lock got interrupted by the fatal signal. do_coredump will
>> return right away and do_group_exit will take care to zap the whole
>> thread group.
>>
>> Cc: Oleg Nesterov <oleg@redhat.com>
>> Signed-off-by: Michal Hocko <mhocko@suse.com>
>
> Acked-by: Vlastimil Babka <vbabka@suse.cz>

Forgot to point out typo in Subject which makes it hard to grep for mmap_sem

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

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

* Re: [PATCH 12/18] aio: make aio_setup_ring killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-03-11 11:57     ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 11:57 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> aio_setup_ring waits for mmap_sem in writable mode. If the waiting
> task gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely
> OOM resolving. Wait for the lock in the killable mode and return with
> EINTR if the task got killed while waiting. This will also expedite
> the return to the userspace and do_exit.
>
> Cc: Benjamin LaHaise <bcrl@kvack.org>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

The error handling could be changed to labels, but:

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   fs/aio.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/fs/aio.c b/fs/aio.c
> index 56bcdf4105f4..1c2e7e2c1b2b 100644
> --- a/fs/aio.c
> +++ b/fs/aio.c
> @@ -520,7 +520,12 @@ static int aio_setup_ring(struct kioctx *ctx)
>   	ctx->mmap_size = nr_pages * PAGE_SIZE;
>   	pr_debug("attempting mmap of %lu bytes\n", ctx->mmap_size);
>
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem)) {
> +		ctx->mmap_size = 0;
> +		aio_free_ring(ctx);
> +		return -EINTR;
> +	}
> +
>   	ctx->mmap_base = do_mmap_pgoff(ctx->aio_ring_file, 0, ctx->mmap_size,
>   				       PROT_READ | PROT_WRITE,
>   				       MAP_SHARED, 0, &unused);
>

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

* Re: [PATCH 12/18] aio: make aio_setup_ring killable
@ 2016-03-11 11:57     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 11:57 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> aio_setup_ring waits for mmap_sem in writable mode. If the waiting
> task gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely
> OOM resolving. Wait for the lock in the killable mode and return with
> EINTR if the task got killed while waiting. This will also expedite
> the return to the userspace and do_exit.
>
> Cc: Benjamin LaHaise <bcrl@kvack.org>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

The error handling could be changed to labels, but:

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   fs/aio.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/fs/aio.c b/fs/aio.c
> index 56bcdf4105f4..1c2e7e2c1b2b 100644
> --- a/fs/aio.c
> +++ b/fs/aio.c
> @@ -520,7 +520,12 @@ static int aio_setup_ring(struct kioctx *ctx)
>   	ctx->mmap_size = nr_pages * PAGE_SIZE;
>   	pr_debug("attempting mmap of %lu bytes\n", ctx->mmap_size);
>
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem)) {
> +		ctx->mmap_size = 0;
> +		aio_free_ring(ctx);
> +		return -EINTR;
> +	}
> +
>   	ctx->mmap_base = do_mmap_pgoff(ctx->aio_ring_file, 0, ctx->mmap_size,
>   				       PROT_READ | PROT_WRITE,
>   				       MAP_SHARED, 0, &unused);
>

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

* Re: [PATCH 12/18] aio: make aio_setup_ring killable
@ 2016-03-11 11:57     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 11:57 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> aio_setup_ring waits for mmap_sem in writable mode. If the waiting
> task gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely
> OOM resolving. Wait for the lock in the killable mode and return with
> EINTR if the task got killed while waiting. This will also expedite
> the return to the userspace and do_exit.
>
> Cc: Benjamin LaHaise <bcrl@kvack.org>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

The error handling could be changed to labels, but:

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   fs/aio.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/fs/aio.c b/fs/aio.c
> index 56bcdf4105f4..1c2e7e2c1b2b 100644
> --- a/fs/aio.c
> +++ b/fs/aio.c
> @@ -520,7 +520,12 @@ static int aio_setup_ring(struct kioctx *ctx)
>   	ctx->mmap_size = nr_pages * PAGE_SIZE;
>   	pr_debug("attempting mmap of %lu bytes\n", ctx->mmap_size);
>
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem)) {
> +		ctx->mmap_size = 0;
> +		aio_free_ring(ctx);
> +		return -EINTR;
> +	}
> +
>   	ctx->mmap_base = do_mmap_pgoff(ctx->aio_ring_file, 0, ctx->mmap_size,
>   				       PROT_READ | PROT_WRITE,
>   				       MAP_SHARED, 0, &unused);
>

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

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

* Re: [PATCH 02/18] mm: make vm_mmap killable
  2016-03-11  9:59     ` Vlastimil Babka
  (?)
@ 2016-03-11 12:12       ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-11 12:12 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Al Viro

On Fri 11-03-16 10:59:30, Vlastimil Babka wrote:
> On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >From: Michal Hocko <mhocko@suse.com>
> >
> >All the callers of vm_mmap seem to check for the failure already
> >and bail out in one way or another on the error which means that
> 
> Hmm I'm not that sure about this one:
>   17   1071  fs/binfmt_elf.c <<load_elf_binary>>
> 
> Assigns result of vm_mmap() to "error" variable which is never checked.

Yes it is not checked but not used either. If the current got killed
then it wouldn't return to the userspace so my understanding is that not
checking this value is not a problem. At least that is my understanding.

> Shouldn't __must_check trigger here?

well, __must_check is a misleading name. It doesn't actually enforce the
value is checked. It just has to be used and an assignment is
sufficient. I was discussing this without our gcc guy and he promissed
to look and try to come up with a different attribute which would
actually work like __must_check.

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 02/18] mm: make vm_mmap killable
@ 2016-03-11 12:12       ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-11 12:12 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov

On Fri 11-03-16 10:59:30, Vlastimil Babka wrote:
> On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >From: Michal Hocko <mhocko@suse.com>
> >
> >All the callers of vm_mmap seem to check for the failure already
> >and bail out in one way or another on the error which means that
> 
> Hmm I'm not that sure about this one:
>   17   1071  fs/binfmt_elf.c <<load_elf_binary>>
> 
> Assigns result of vm_mmap() to "error" variable which is never checked.

Yes it is not checked but not used either. If the current got killed
then it wouldn't return to the userspace so my understanding is that not
checking this value is not a problem. At least that is my understanding.

> Shouldn't __must_check trigger here?

well, __must_check is a misleading name. It doesn't actually enforce the
value is checked. It just has to be used and an assignment is
sufficient. I was discussing this without our gcc guy and he promissed
to look and try to come up with a different attribute which would
actually work like __must_check.

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 02/18] mm: make vm_mmap killable
@ 2016-03-11 12:12       ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-11 12:12 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Al Viro

On Fri 11-03-16 10:59:30, Vlastimil Babka wrote:
> On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >From: Michal Hocko <mhocko@suse.com>
> >
> >All the callers of vm_mmap seem to check for the failure already
> >and bail out in one way or another on the error which means that
> 
> Hmm I'm not that sure about this one:
>   17   1071  fs/binfmt_elf.c <<load_elf_binary>>
> 
> Assigns result of vm_mmap() to "error" variable which is never checked.

Yes it is not checked but not used either. If the current got killed
then it wouldn't return to the userspace so my understanding is that not
checking this value is not a problem. At least that is my understanding.

> Shouldn't __must_check trigger here?

well, __must_check is a misleading name. It doesn't actually enforce the
value is checked. It just has to be used and an assignment is
sufficient. I was discussing this without our gcc guy and he promissed
to look and try to come up with a different attribute which would
actually work like __must_check.

-- 
Michal Hocko
SUSE Labs

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

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

* Re: [PATCH 03/18] mm: make vm_munmap killable
  2016-03-11 10:06     ` Vlastimil Babka
  (?)
@ 2016-03-11 12:32       ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-11 12:32 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Alexander Viro

On Fri 11-03-16 11:06:41, Vlastimil Babka wrote:
> On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >From: Michal Hocko <mhocko@suse.com>
> >
> >Almost all current users of vm_munmap are ignoring the return value
> >and so they do not handle potential error. This means that some VMAs
> 
>    1   7834  arch/x86/kvm/x86.c <<__x86_set_memory_region>>
> 
>              r = vm_munmap(old.userspace_addr, old.npages * PAGE_SIZE);
>              WARN_ON(r < 0);
> 
> This warning will potentially add noise to OOM output?

Would it be harmfull though? I mean the warning is just goofy. I can
make it not warn on (r < 0 && r != -EINTR) but is it worth bothering?

Thanks!
-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 03/18] mm: make vm_munmap killable
@ 2016-03-11 12:32       ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-11 12:32 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov

On Fri 11-03-16 11:06:41, Vlastimil Babka wrote:
> On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >From: Michal Hocko <mhocko@suse.com>
> >
> >Almost all current users of vm_munmap are ignoring the return value
> >and so they do not handle potential error. This means that some VMAs
> 
>    1   7834  arch/x86/kvm/x86.c <<__x86_set_memory_region>>
> 
>              r = vm_munmap(old.userspace_addr, old.npages * PAGE_SIZE);
>              WARN_ON(r < 0);
> 
> This warning will potentially add noise to OOM output?

Would it be harmfull though? I mean the warning is just goofy. I can
make it not warn on (r < 0 && r != -EINTR) but is it worth bothering?

Thanks!
-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 03/18] mm: make vm_munmap killable
@ 2016-03-11 12:32       ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-11 12:32 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Alexander Viro

On Fri 11-03-16 11:06:41, Vlastimil Babka wrote:
> On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >From: Michal Hocko <mhocko@suse.com>
> >
> >Almost all current users of vm_munmap are ignoring the return value
> >and so they do not handle potential error. This means that some VMAs
> 
>    1   7834  arch/x86/kvm/x86.c <<__x86_set_memory_region>>
> 
>              r = vm_munmap(old.userspace_addr, old.npages * PAGE_SIZE);
>              WARN_ON(r < 0);
> 
> This warning will potentially add noise to OOM output?

Would it be harmfull though? I mean the warning is just goofy. I can
make it not warn on (r < 0 && r != -EINTR) but is it worth bothering?

Thanks!
-- 
Michal Hocko
SUSE Labs

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

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

* Re: [PATCH 04/18] mm, aout: handle vm_brk failures
  2016-03-11 10:32     ` Vlastimil Babka
  (?)
@ 2016-03-11 12:42       ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-11 12:42 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Ingo Molnar,
	Alexander Viro

On Fri 11-03-16 11:32:42, Vlastimil Babka wrote:
> On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >From: Michal Hocko <mhocko@suse.com>
> >
> >vm_brk is allowed to fail but load_aout_binary simply ignores the error
> >and happily continues. I haven't noticed any problem from that in real
> >life but later patches will make the failure more likely because
> >vm_brk will become killable (resp. mmap_sem for write waiting will become
> >killable) so we should be more careful now.
> >
> >The error handling should be quite straightforward because there are
> >calls to vm_mmap which check the error properly already. The only
> >notable exception is set_brk which is called after beyond_if label.
> >But nothing indicates that we cannot move it above set_binfmt as the two
> >do not depend on each other and fail before we do set_binfmt and alter
> >reference counting.
> >
> >Cc: Thomas Gleixner <tglx@linutronix.de>
> >Cc: Ingo Molnar <mingo@redhat.com>
> >Cc: "H. Peter Anvin" <hpa@zytor.com>
> >Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> >Signed-off-by: Michal Hocko <mhocko@suse.com>
> 
> Acked--by: Vlastimil Babka <vbabka@suse.cz>

thanks!
> 
> [...]
> 
> >@@ -378,7 +381,9 @@ static int load_aout_library(struct file *file)
> >  			       "N_TXTOFF is not page aligned. Please convert library: %pD\n",
> >  			       file);
> >  		}
> >-		vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
> >+		retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
> >+		if (IS_ERR_VALUE(retval))
> >+			goto out;
> >  		
> 
> You could have removed the extra whitespace on the line above, which my vim
> so prominently highlights :)

Fixed

> 
> >  		read_code(file, start_addr, N_TXTOFF(ex),
> >  			  ex.a_text + ex.a_data);
> >

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 04/18] mm, aout: handle vm_brk failures
@ 2016-03-11 12:42       ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-11 12:42 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov

On Fri 11-03-16 11:32:42, Vlastimil Babka wrote:
> On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >From: Michal Hocko <mhocko@suse.com>
> >
> >vm_brk is allowed to fail but load_aout_binary simply ignores the error
> >and happily continues. I haven't noticed any problem from that in real
> >life but later patches will make the failure more likely because
> >vm_brk will become killable (resp. mmap_sem for write waiting will become
> >killable) so we should be more careful now.
> >
> >The error handling should be quite straightforward because there are
> >calls to vm_mmap which check the error properly already. The only
> >notable exception is set_brk which is called after beyond_if label.
> >But nothing indicates that we cannot move it above set_binfmt as the two
> >do not depend on each other and fail before we do set_binfmt and alter
> >reference counting.
> >
> >Cc: Thomas Gleixner <tglx@linutronix.de>
> >Cc: Ingo Molnar <mingo@redhat.com>
> >Cc: "H. Peter Anvin" <hpa@zytor.com>
> >Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> >Signed-off-by: Michal Hocko <mhocko@suse.com>
> 
> Acked--by: Vlastimil Babka <vbabka@suse.cz>

thanks!
> 
> [...]
> 
> >@@ -378,7 +381,9 @@ static int load_aout_library(struct file *file)
> >  			       "N_TXTOFF is not page aligned. Please convert library: %pD\n",
> >  			       file);
> >  		}
> >-		vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
> >+		retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
> >+		if (IS_ERR_VALUE(retval))
> >+			goto out;
> >  		
> 
> You could have removed the extra whitespace on the line above, which my vim
> so prominently highlights :)

Fixed

> 
> >  		read_code(file, start_addr, N_TXTOFF(ex),
> >  			  ex.a_text + ex.a_data);
> >

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 04/18] mm, aout: handle vm_brk failures
@ 2016-03-11 12:42       ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-11 12:42 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Ingo Molnar,
	Alexander Viro

On Fri 11-03-16 11:32:42, Vlastimil Babka wrote:
> On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >From: Michal Hocko <mhocko@suse.com>
> >
> >vm_brk is allowed to fail but load_aout_binary simply ignores the error
> >and happily continues. I haven't noticed any problem from that in real
> >life but later patches will make the failure more likely because
> >vm_brk will become killable (resp. mmap_sem for write waiting will become
> >killable) so we should be more careful now.
> >
> >The error handling should be quite straightforward because there are
> >calls to vm_mmap which check the error properly already. The only
> >notable exception is set_brk which is called after beyond_if label.
> >But nothing indicates that we cannot move it above set_binfmt as the two
> >do not depend on each other and fail before we do set_binfmt and alter
> >reference counting.
> >
> >Cc: Thomas Gleixner <tglx@linutronix.de>
> >Cc: Ingo Molnar <mingo@redhat.com>
> >Cc: "H. Peter Anvin" <hpa@zytor.com>
> >Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> >Signed-off-by: Michal Hocko <mhocko@suse.com>
> 
> Acked--by: Vlastimil Babka <vbabka@suse.cz>

thanks!
> 
> [...]
> 
> >@@ -378,7 +381,9 @@ static int load_aout_library(struct file *file)
> >  			       "N_TXTOFF is not page aligned. Please convert library: %pD\n",
> >  			       file);
> >  		}
> >-		vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
> >+		retval = vm_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
> >+		if (IS_ERR_VALUE(retval))
> >+			goto out;
> >  		
> 
> You could have removed the extra whitespace on the line above, which my vim
> so prominently highlights :)

Fixed

> 
> >  		read_code(file, start_addr, N_TXTOFF(ex),
> >  			  ex.a_text + ex.a_data);
> >

-- 
Michal Hocko
SUSE Labs

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

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

* Re: [PATCH 02/18] mm: make vm_mmap killable
  2016-03-11 12:12       ` Michal Hocko
  (?)
@ 2016-03-11 12:43         ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 12:43 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Al Viro

On 03/11/2016 01:12 PM, Michal Hocko wrote:
> On Fri 11-03-16 10:59:30, Vlastimil Babka wrote:
>> On 02/29/2016 02:26 PM, Michal Hocko wrote:
>> >From: Michal Hocko <mhocko@suse.com>
>> >
>> >All the callers of vm_mmap seem to check for the failure already
>> >and bail out in one way or another on the error which means that
>>
>> Hmm I'm not that sure about this one:
>>   17   1071  fs/binfmt_elf.c <<load_elf_binary>>
>>
>> Assigns result of vm_mmap() to "error" variable which is never checked.
>
> Yes it is not checked but not used either. If the current got killed
> then it wouldn't return to the userspace so my understanding is that not
> checking this value is not a problem. At least that is my understanding.

Hmm, that's true. So,

Acked-by: Vlastimil Babka <vbabka@suse.cz>

>> Shouldn't __must_check trigger here?
>
> well, __must_check is a misleading name. It doesn't actually enforce the
> value is checked. It just has to be used and an assignment is
> sufficient. I was discussing this without our gcc guy and he promissed
> to look and try to come up with a different attribute which would
> actually work like __must_check.

OK!

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

* Re: [PATCH 02/18] mm: make vm_mmap killable
@ 2016-03-11 12:43         ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 12:43 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov

On 03/11/2016 01:12 PM, Michal Hocko wrote:
> On Fri 11-03-16 10:59:30, Vlastimil Babka wrote:
>> On 02/29/2016 02:26 PM, Michal Hocko wrote:
>> >From: Michal Hocko <mhocko@suse.com>
>> >
>> >All the callers of vm_mmap seem to check for the failure already
>> >and bail out in one way or another on the error which means that
>>
>> Hmm I'm not that sure about this one:
>>   17   1071  fs/binfmt_elf.c <<load_elf_binary>>
>>
>> Assigns result of vm_mmap() to "error" variable which is never checked.
>
> Yes it is not checked but not used either. If the current got killed
> then it wouldn't return to the userspace so my understanding is that not
> checking this value is not a problem. At least that is my understanding.

Hmm, that's true. So,

Acked-by: Vlastimil Babka <vbabka@suse.cz>

>> Shouldn't __must_check trigger here?
>
> well, __must_check is a misleading name. It doesn't actually enforce the
> value is checked. It just has to be used and an assignment is
> sufficient. I was discussing this without our gcc guy and he promissed
> to look and try to come up with a different attribute which would
> actually work like __must_check.

OK!

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

* Re: [PATCH 02/18] mm: make vm_mmap killable
@ 2016-03-11 12:43         ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 12:43 UTC (permalink / raw)
  To: Michal Hocko
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Al Viro

On 03/11/2016 01:12 PM, Michal Hocko wrote:
> On Fri 11-03-16 10:59:30, Vlastimil Babka wrote:
>> On 02/29/2016 02:26 PM, Michal Hocko wrote:
>> >From: Michal Hocko <mhocko@suse.com>
>> >
>> >All the callers of vm_mmap seem to check for the failure already
>> >and bail out in one way or another on the error which means that
>>
>> Hmm I'm not that sure about this one:
>>   17   1071  fs/binfmt_elf.c <<load_elf_binary>>
>>
>> Assigns result of vm_mmap() to "error" variable which is never checked.
>
> Yes it is not checked but not used either. If the current got killed
> then it wouldn't return to the userspace so my understanding is that not
> checking this value is not a problem. At least that is my understanding.

Hmm, that's true. So,

Acked-by: Vlastimil Babka <vbabka@suse.cz>

>> Shouldn't __must_check trigger here?
>
> well, __must_check is a misleading name. It doesn't actually enforce the
> value is checked. It just has to be used and an assignment is
> sufficient. I was discussing this without our gcc guy and he promissed
> to look and try to come up with a different attribute which would
> actually work like __must_check.

OK!


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

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

* Re: [PATCH 11/18] coredump: make coredump_wait wait for mma_sem for write killable
  2016-03-11 11:54       ` Vlastimil Babka
  (?)
@ 2016-03-11 12:46         ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-11 12:46 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner

On Fri 11-03-16 12:54:17, Vlastimil Babka wrote:
> On 03/11/2016 12:32 PM, Vlastimil Babka wrote:
> >On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >>From: Michal Hocko <mhocko@suse.com>
> >>
> >>coredump_wait waits for mmap_sem for write currently which can
> >>prevent oom_reaper to reclaim the oom victims address space
> >>asynchronously because that requires mmap_sem for read. This might
> >>happen if the oom victim is multi threaded and some thread(s) is
> >>holding mmap_sem for read (e.g. page fault) and it is stuck in
> >>the page allocator while other thread(s) reached coredump_wait
> >>already.
> >>
> >>This patch simply uses down_write_killable and bails out with EINTR
> >>if the lock got interrupted by the fatal signal. do_coredump will
> >>return right away and do_group_exit will take care to zap the whole
> >>thread group.
> >>
> >>Cc: Oleg Nesterov <oleg@redhat.com>
> >>Signed-off-by: Michal Hocko <mhocko@suse.com>
> >
> >Acked-by: Vlastimil Babka <vbabka@suse.cz>
> 
> Forgot to point out typo in Subject which makes it hard to grep for mmap_sem

Fixed and thanks!

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 11/18] coredump: make coredump_wait wait for mma_sem for write killable
@ 2016-03-11 12:46         ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-11 12:46 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov

On Fri 11-03-16 12:54:17, Vlastimil Babka wrote:
> On 03/11/2016 12:32 PM, Vlastimil Babka wrote:
> >On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >>From: Michal Hocko <mhocko@suse.com>
> >>
> >>coredump_wait waits for mmap_sem for write currently which can
> >>prevent oom_reaper to reclaim the oom victims address space
> >>asynchronously because that requires mmap_sem for read. This might
> >>happen if the oom victim is multi threaded and some thread(s) is
> >>holding mmap_sem for read (e.g. page fault) and it is stuck in
> >>the page allocator while other thread(s) reached coredump_wait
> >>already.
> >>
> >>This patch simply uses down_write_killable and bails out with EINTR
> >>if the lock got interrupted by the fatal signal. do_coredump will
> >>return right away and do_group_exit will take care to zap the whole
> >>thread group.
> >>
> >>Cc: Oleg Nesterov <oleg@redhat.com>
> >>Signed-off-by: Michal Hocko <mhocko@suse.com>
> >
> >Acked-by: Vlastimil Babka <vbabka@suse.cz>
> 
> Forgot to point out typo in Subject which makes it hard to grep for mmap_sem

Fixed and thanks!

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 11/18] coredump: make coredump_wait wait for mma_sem for write killable
@ 2016-03-11 12:46         ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-11 12:46 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner

On Fri 11-03-16 12:54:17, Vlastimil Babka wrote:
> On 03/11/2016 12:32 PM, Vlastimil Babka wrote:
> >On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >>From: Michal Hocko <mhocko@suse.com>
> >>
> >>coredump_wait waits for mmap_sem for write currently which can
> >>prevent oom_reaper to reclaim the oom victims address space
> >>asynchronously because that requires mmap_sem for read. This might
> >>happen if the oom victim is multi threaded and some thread(s) is
> >>holding mmap_sem for read (e.g. page fault) and it is stuck in
> >>the page allocator while other thread(s) reached coredump_wait
> >>already.
> >>
> >>This patch simply uses down_write_killable and bails out with EINTR
> >>if the lock got interrupted by the fatal signal. do_coredump will
> >>return right away and do_group_exit will take care to zap the whole
> >>thread group.
> >>
> >>Cc: Oleg Nesterov <oleg@redhat.com>
> >>Signed-off-by: Michal Hocko <mhocko@suse.com>
> >
> >Acked-by: Vlastimil Babka <vbabka@suse.cz>
> 
> Forgot to point out typo in Subject which makes it hard to grep for mmap_sem

Fixed and thanks!

-- 
Michal Hocko
SUSE Labs

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

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

* Re: [PATCH 13/18] exec: make exec path waiting for mmap_sem killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-03-11 12:51     ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 12:51 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> setup_arg_pages requires mmap_sem for write. If the waiting task
> gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely
> OOM resolving. Wait for the lock in the killable mode and return with
> EINTR if the task got killed while waiting. All the callers are already
> handling error path and the fatal signal doesn't need any additional
> treatment.
>
> The same applies to __bprm_mm_init.
>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Michal Hocko <mhocko@suse.com>


Acked-by: Vlastimil Babka <vbabka@suse.cz>

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

* Re: [PATCH 13/18] exec: make exec path waiting for mmap_sem killable
@ 2016-03-11 12:51     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 12:51 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> setup_arg_pages requires mmap_sem for write. If the waiting task
> gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely
> OOM resolving. Wait for the lock in the killable mode and return with
> EINTR if the task got killed while waiting. All the callers are already
> handling error path and the fatal signal doesn't need any additional
> treatment.
>
> The same applies to __bprm_mm_init.
>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Michal Hocko <mhocko@suse.com>


Acked-by: Vlastimil Babka <vbabka@suse.cz>

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

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

* Re: [PATCH 13/18] exec: make exec path waiting for mmap_sem killable
@ 2016-03-11 12:51     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 12:51 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko,
	Alexander Viro

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> setup_arg_pages requires mmap_sem for write. If the waiting task
> gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely
> OOM resolving. Wait for the lock in the killable mode and return with
> EINTR if the task got killed while waiting. All the callers are already
> handling error path and the fatal signal doesn't need any additional
> treatment.
>
> The same applies to __bprm_mm_init.
>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Michal Hocko <mhocko@suse.com>


Acked-by: Vlastimil Babka <vbabka@suse.cz>

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

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

* Re: [PATCH 14/18] prctl: make PR_SET_THP_DISABLE wait for mmap_sem killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-03-11 12:54     ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 12:54 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> PR_SET_THP_DISABLE requires mmap_sem for write. If the waiting
> task gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely OOM
> resolving. Wait for the lock in the killable mode and return with EINTR
> if the task got killed while waiting.
>
> Cc: Alex Thorlton <athorlton@sgi.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   kernel/sys.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/sys.c b/kernel/sys.c
> index cf8ba545c7d3..89d5be418157 100644
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -2246,7 +2246,8 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
>   	case PR_SET_THP_DISABLE:
>   		if (arg3 || arg4 || arg5)
>   			return -EINVAL;
> -		down_write(&me->mm->mmap_sem);
> +		if (down_write_killable(&me->mm->mmap_sem))
> +			return -EINTR;
>   		if (arg2)
>   			me->mm->def_flags |= VM_NOHUGEPAGE;
>   		else
>

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

* Re: [PATCH 14/18] prctl: make PR_SET_THP_DISABLE wait for mmap_sem killable
@ 2016-03-11 12:54     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 12:54 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> PR_SET_THP_DISABLE requires mmap_sem for write. If the waiting
> task gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely OOM
> resolving. Wait for the lock in the killable mode and return with EINTR
> if the task got killed while waiting.
>
> Cc: Alex Thorlton <athorlton@sgi.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   kernel/sys.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/sys.c b/kernel/sys.c
> index cf8ba545c7d3..89d5be418157 100644
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -2246,7 +2246,8 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
>   	case PR_SET_THP_DISABLE:
>   		if (arg3 || arg4 || arg5)
>   			return -EINVAL;
> -		down_write(&me->mm->mmap_sem);
> +		if (down_write_killable(&me->mm->mmap_sem))
> +			return -EINTR;
>   		if (arg2)
>   			me->mm->def_flags |= VM_NOHUGEPAGE;
>   		else
>

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

* Re: [PATCH 14/18] prctl: make PR_SET_THP_DISABLE wait for mmap_sem killable
@ 2016-03-11 12:54     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 12:54 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> PR_SET_THP_DISABLE requires mmap_sem for write. If the waiting
> task gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely OOM
> resolving. Wait for the lock in the killable mode and return with EINTR
> if the task got killed while waiting.
>
> Cc: Alex Thorlton <athorlton@sgi.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   kernel/sys.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/sys.c b/kernel/sys.c
> index cf8ba545c7d3..89d5be418157 100644
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -2246,7 +2246,8 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
>   	case PR_SET_THP_DISABLE:
>   		if (arg3 || arg4 || arg5)
>   			return -EINVAL;
> -		down_write(&me->mm->mmap_sem);
> +		if (down_write_killable(&me->mm->mmap_sem))
> +			return -EINTR;
>   		if (arg2)
>   			me->mm->def_flags |= VM_NOHUGEPAGE;
>   		else
>

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

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

* Re: [PATCH 02/18] mm: make vm_mmap killable
  2016-03-11 12:43         ` Vlastimil Babka
  (?)
@ 2016-03-11 12:55           ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-11 12:55 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Al Viro

On Fri 11-03-16 13:43:41, Vlastimil Babka wrote:
> On 03/11/2016 01:12 PM, Michal Hocko wrote:
> >On Fri 11-03-16 10:59:30, Vlastimil Babka wrote:
> >>On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >>>From: Michal Hocko <mhocko@suse.com>
> >>>
> >>>All the callers of vm_mmap seem to check for the failure already
> >>>and bail out in one way or another on the error which means that
> >>
> >>Hmm I'm not that sure about this one:
> >>  17   1071  fs/binfmt_elf.c <<load_elf_binary>>
> >>
> >>Assigns result of vm_mmap() to "error" variable which is never checked.
> >
> >Yes it is not checked but not used either. If the current got killed
> >then it wouldn't return to the userspace so my understanding is that not
> >checking this value is not a problem. At least that is my understanding.
> 
> Hmm, that's true. So,

I have updated the changelog and added the following note:
"
Please note that load_elf_binary is ignoring vm_mmap error for 
current->personality & MMAP_PAGE_ZERO case but that shouldn't be a
problem because the address is not used anywhere and we never return to
the userspace if we got killed.
"
 
> Acked-by: Vlastimil Babka <vbabka@suse.cz>

Thanks!

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 02/18] mm: make vm_mmap killable
@ 2016-03-11 12:55           ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-11 12:55 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov

On Fri 11-03-16 13:43:41, Vlastimil Babka wrote:
> On 03/11/2016 01:12 PM, Michal Hocko wrote:
> >On Fri 11-03-16 10:59:30, Vlastimil Babka wrote:
> >>On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >>>From: Michal Hocko <mhocko@suse.com>
> >>>
> >>>All the callers of vm_mmap seem to check for the failure already
> >>>and bail out in one way or another on the error which means that
> >>
> >>Hmm I'm not that sure about this one:
> >>  17   1071  fs/binfmt_elf.c <<load_elf_binary>>
> >>
> >>Assigns result of vm_mmap() to "error" variable which is never checked.
> >
> >Yes it is not checked but not used either. If the current got killed
> >then it wouldn't return to the userspace so my understanding is that not
> >checking this value is not a problem. At least that is my understanding.
> 
> Hmm, that's true. So,

I have updated the changelog and added the following note:
"
Please note that load_elf_binary is ignoring vm_mmap error for 
current->personality & MMAP_PAGE_ZERO case but that shouldn't be a
problem because the address is not used anywhere and we never return to
the userspace if we got killed.
"
 
> Acked-by: Vlastimil Babka <vbabka@suse.cz>

Thanks!

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH 02/18] mm: make vm_mmap killable
@ 2016-03-11 12:55           ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-11 12:55 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: LKML, Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Al Viro

On Fri 11-03-16 13:43:41, Vlastimil Babka wrote:
> On 03/11/2016 01:12 PM, Michal Hocko wrote:
> >On Fri 11-03-16 10:59:30, Vlastimil Babka wrote:
> >>On 02/29/2016 02:26 PM, Michal Hocko wrote:
> >>>From: Michal Hocko <mhocko@suse.com>
> >>>
> >>>All the callers of vm_mmap seem to check for the failure already
> >>>and bail out in one way or another on the error which means that
> >>
> >>Hmm I'm not that sure about this one:
> >>  17   1071  fs/binfmt_elf.c <<load_elf_binary>>
> >>
> >>Assigns result of vm_mmap() to "error" variable which is never checked.
> >
> >Yes it is not checked but not used either. If the current got killed
> >then it wouldn't return to the userspace so my understanding is that not
> >checking this value is not a problem. At least that is my understanding.
> 
> Hmm, that's true. So,

I have updated the changelog and added the following note:
"
Please note that load_elf_binary is ignoring vm_mmap error for 
current->personality & MMAP_PAGE_ZERO case but that shouldn't be a
problem because the address is not used anywhere and we never return to
the userspace if we got killed.
"
 
> Acked-by: Vlastimil Babka <vbabka@suse.cz>

Thanks!

-- 
Michal Hocko
SUSE Labs

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

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

* Re: [PATCH] uprobes: wait for mmap_sem for write killable
  2016-02-29 17:42     ` Michal Hocko
@ 2016-03-11 14:58       ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 14:58 UTC (permalink / raw)
  To: Michal Hocko, LKML; +Cc: Andrew Morton, Oleg Nesterov, linux-mm, Michal Hocko

On 02/29/2016 06:42 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> xol_add_vma needs mmap_sem for write. If the waiting task gets killed by
> the oom killer it would block oom_reaper from asynchronous address space
> reclaim and reduce the chances of timely OOM resolving. Wait for the
> lock in the killable mode and return with EINTR if the task got killed
> while waiting.
>
> Do not warn in dup_xol_work if __create_xol_area failed due to fatal
> signal pending because this is usually considered a kernel issue.
>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>
> ---
>   kernel/events/uprobes.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index 8eef5f55d3f0..fb4a6bcc88ce 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
>   	struct vm_area_struct *vma;
>   	int ret;
>
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return -EINTR;
> +
>   	if (mm->uprobes_state.xol_area) {
>   		ret = -EALREADY;
>   		goto fail;
> @@ -1468,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
>   	if (current->flags & PF_EXITING)
>   		return;
>
> -	if (!__create_xol_area(current->utask->dup_xol_addr))
> +	if (!__create_xol_area(current->utask->dup_xol_addr) &&
> +			!fatal_signal_pending(current)
                                                       ^ missing ")"

Other than that,
Acked-by: Vlastimil Babka <vbabka@suse.cz>

>   		uprobe_warn(current, "dup xol area");
>   }
>
>

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

* Re: [PATCH] uprobes: wait for mmap_sem for write killable
@ 2016-03-11 14:58       ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 14:58 UTC (permalink / raw)
  To: Michal Hocko, LKML; +Cc: Andrew Morton, Oleg Nesterov, linux-mm, Michal Hocko

On 02/29/2016 06:42 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> xol_add_vma needs mmap_sem for write. If the waiting task gets killed by
> the oom killer it would block oom_reaper from asynchronous address space
> reclaim and reduce the chances of timely OOM resolving. Wait for the
> lock in the killable mode and return with EINTR if the task got killed
> while waiting.
>
> Do not warn in dup_xol_work if __create_xol_area failed due to fatal
> signal pending because this is usually considered a kernel issue.
>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>
> ---
>   kernel/events/uprobes.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index 8eef5f55d3f0..fb4a6bcc88ce 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -1130,7 +1130,9 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
>   	struct vm_area_struct *vma;
>   	int ret;
>
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return -EINTR;
> +
>   	if (mm->uprobes_state.xol_area) {
>   		ret = -EALREADY;
>   		goto fail;
> @@ -1468,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
>   	if (current->flags & PF_EXITING)
>   		return;
>
> -	if (!__create_xol_area(current->utask->dup_xol_addr))
> +	if (!__create_xol_area(current->utask->dup_xol_addr) &&
> +			!fatal_signal_pending(current)
                                                       ^ missing ")"

Other than that,
Acked-by: Vlastimil Babka <vbabka@suse.cz>

>   		uprobe_warn(current, "dup xol area");
>   }
>
>

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

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

* Re: [PATCH 16/18] drm/i915: make i915_gem_mmap_ioctl wait for mmap_sem killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-03-11 15:23     ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 15:23 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> i915_gem_mmap_ioctl relies on mmap_sem for write. If the waiting
> task gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely OOM
> resolving. Wait for the lock in the killable mode and return with EINTR
> if the task got killed while waiting.
>
> Cc: Daniel Vetter <daniel.vetter@intel.com>
> Cc: David Airlie <airlied@linux.ie>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   drivers/gpu/drm/i915/i915_gem.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index f68f34606f2f..a50136cbd332 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -1754,7 +1754,10 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
>   		struct mm_struct *mm = current->mm;
>   		struct vm_area_struct *vma;
>
> -		down_write(&mm->mmap_sem);
> +		if (down_write_killable(&mm->mmap_sem)) {
> +			drm_gem_object_unreference_unlocked(obj);
> +			return -EINTR;
> +		}
>   		vma = find_vma(mm, addr);
>   		if (vma)
>   			vma->vm_page_prot =
>

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

* Re: [PATCH 16/18] drm/i915: make i915_gem_mmap_ioctl wait for mmap_sem killable
@ 2016-03-11 15:23     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 15:23 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> i915_gem_mmap_ioctl relies on mmap_sem for write. If the waiting
> task gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely OOM
> resolving. Wait for the lock in the killable mode and return with EINTR
> if the task got killed while waiting.
>
> Cc: Daniel Vetter <daniel.vetter@intel.com>
> Cc: David Airlie <airlied@linux.ie>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   drivers/gpu/drm/i915/i915_gem.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index f68f34606f2f..a50136cbd332 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -1754,7 +1754,10 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
>   		struct mm_struct *mm = current->mm;
>   		struct vm_area_struct *vma;
>
> -		down_write(&mm->mmap_sem);
> +		if (down_write_killable(&mm->mmap_sem)) {
> +			drm_gem_object_unreference_unlocked(obj);
> +			return -EINTR;
> +		}
>   		vma = find_vma(mm, addr);
>   		if (vma)
>   			vma->vm_page_prot =
>

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

* Re: [PATCH 16/18] drm/i915: make i915_gem_mmap_ioctl wait for mmap_sem killable
@ 2016-03-11 15:23     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 15:23 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> i915_gem_mmap_ioctl relies on mmap_sem for write. If the waiting
> task gets killed by the oom killer it would block oom_reaper from
> asynchronous address space reclaim and reduce the chances of timely OOM
> resolving. Wait for the lock in the killable mode and return with EINTR
> if the task got killed while waiting.
>
> Cc: Daniel Vetter <daniel.vetter@intel.com>
> Cc: David Airlie <airlied@linux.ie>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   drivers/gpu/drm/i915/i915_gem.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index f68f34606f2f..a50136cbd332 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -1754,7 +1754,10 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
>   		struct mm_struct *mm = current->mm;
>   		struct vm_area_struct *vma;
>
> -		down_write(&mm->mmap_sem);
> +		if (down_write_killable(&mm->mmap_sem)) {
> +			drm_gem_object_unreference_unlocked(obj);
> +			return -EINTR;
> +		}
>   		vma = find_vma(mm, addr);
>   		if (vma)
>   			vma->vm_page_prot =
>

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

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

* Re: [PATCH 17/18] drm/radeon: make radeon_mn_get wait for mmap_sem killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-03-11 15:27     ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 15:27 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> radeon_mn_get which is called during ioct path relies on mmap_sem for
> write. If the waiting task gets killed by the oom killer it would block
> oom_reaper from asynchronous address space reclaim and reduce the
> chances of timely OOM resolving. Wait for the lock in the killable mode
> and return with EINTR if the task got killed while waiting.
>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: "Christian König" <christian.koenig@amd.com>
> Cc: David Airlie <airlied@linux.ie>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   drivers/gpu/drm/radeon/radeon_mn.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c
> index eef006c48584..896f2cf51e4e 100644
> --- a/drivers/gpu/drm/radeon/radeon_mn.c
> +++ b/drivers/gpu/drm/radeon/radeon_mn.c
> @@ -186,7 +186,9 @@ static struct radeon_mn *radeon_mn_get(struct radeon_device *rdev)
>   	struct radeon_mn *rmn;
>   	int r;
>
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return ERR_PTR(-EINTR);
> +
>   	mutex_lock(&rdev->mn_lock);
>
>   	hash_for_each_possible(rdev->mn_hash, rmn, node, (unsigned long)mm)
>

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

* Re: [PATCH 17/18] drm/radeon: make radeon_mn_get wait for mmap_sem killable
@ 2016-03-11 15:27     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 15:27 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> radeon_mn_get which is called during ioct path relies on mmap_sem for
> write. If the waiting task gets killed by the oom killer it would block
> oom_reaper from asynchronous address space reclaim and reduce the
> chances of timely OOM resolving. Wait for the lock in the killable mode
> and return with EINTR if the task got killed while waiting.
>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: "Christian König" <christian.koenig@amd.com>
> Cc: David Airlie <airlied@linux.ie>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   drivers/gpu/drm/radeon/radeon_mn.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c
> index eef006c48584..896f2cf51e4e 100644
> --- a/drivers/gpu/drm/radeon/radeon_mn.c
> +++ b/drivers/gpu/drm/radeon/radeon_mn.c
> @@ -186,7 +186,9 @@ static struct radeon_mn *radeon_mn_get(struct radeon_device *rdev)
>   	struct radeon_mn *rmn;
>   	int r;
>
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return ERR_PTR(-EINTR);
> +
>   	mutex_lock(&rdev->mn_lock);
>
>   	hash_for_each_possible(rdev->mn_hash, rmn, node, (unsigned long)mm)
>

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

* Re: [PATCH 17/18] drm/radeon: make radeon_mn_get wait for mmap_sem killable
@ 2016-03-11 15:27     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 15:27 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> radeon_mn_get which is called during ioct path relies on mmap_sem for
> write. If the waiting task gets killed by the oom killer it would block
> oom_reaper from asynchronous address space reclaim and reduce the
> chances of timely OOM resolving. Wait for the lock in the killable mode
> and return with EINTR if the task got killed while waiting.
>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: "Christian KA?nig" <christian.koenig@amd.com>
> Cc: David Airlie <airlied@linux.ie>
> Signed-off-by: Michal Hocko <mhocko@suse.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   drivers/gpu/drm/radeon/radeon_mn.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c
> index eef006c48584..896f2cf51e4e 100644
> --- a/drivers/gpu/drm/radeon/radeon_mn.c
> +++ b/drivers/gpu/drm/radeon/radeon_mn.c
> @@ -186,7 +186,9 @@ static struct radeon_mn *radeon_mn_get(struct radeon_device *rdev)
>   	struct radeon_mn *rmn;
>   	int r;
>
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem))
> +		return ERR_PTR(-EINTR);
> +
>   	mutex_lock(&rdev->mn_lock);
>
>   	hash_for_each_possible(rdev->mn_hash, rmn, node, (unsigned long)mm)
>

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

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

* Re: [PATCH 18/18] drm/amdgpu: make amdgpu_mn_get wait for mmap_sem killable
  2016-02-29 13:26   ` Michal Hocko
  (?)
@ 2016-03-11 15:29     ` Vlastimil Babka
  -1 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 15:29 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> amdgpu_mn_get which is called during ioct path relies on mmap_sem for
> write. If the waiting task gets killed by the oom killer it would block
> oom_reaper from asynchronous address space reclaim and reduce the
> chances of timely OOM resolving. Wait for the lock in the killable mode
> and return with EINTR if the task got killed while waiting.
>
> Cc: David Airlie <airlied@linux.ie>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>


Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
> index d7ec9bd6755f..6f44f1c23be3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
> @@ -181,7 +181,10 @@ static struct amdgpu_mn *amdgpu_mn_get(struct amdgpu_device *adev)
>   	int r;
>
>   	mutex_lock(&adev->mn_lock);
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem)) {
> +		mutex_unlock(&adev->mn_lock);
> +		return -EINTR;
> +	}
>
>   	hash_for_each_possible(adev->mn_hash, rmn, node, (unsigned long)mm)
>   		if (rmn->mm == mm)
>

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

* Re: [PATCH 18/18] drm/amdgpu: make amdgpu_mn_get wait for mmap_sem killable
@ 2016-03-11 15:29     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 15:29 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> amdgpu_mn_get which is called during ioct path relies on mmap_sem for
> write. If the waiting task gets killed by the oom killer it would block
> oom_reaper from asynchronous address space reclaim and reduce the
> chances of timely OOM resolving. Wait for the lock in the killable mode
> and return with EINTR if the task got killed while waiting.
>
> Cc: David Airlie <airlied@linux.ie>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>


Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
> index d7ec9bd6755f..6f44f1c23be3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
> @@ -181,7 +181,10 @@ static struct amdgpu_mn *amdgpu_mn_get(struct amdgpu_device *adev)
>   	int r;
>
>   	mutex_lock(&adev->mn_lock);
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem)) {
> +		mutex_unlock(&adev->mn_lock);
> +		return -EINTR;
> +	}
>
>   	hash_for_each_possible(adev->mn_hash, rmn, node, (unsigned long)mm)
>   		if (rmn->mm == mm)
>

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

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

* Re: [PATCH 18/18] drm/amdgpu: make amdgpu_mn_get wait for mmap_sem killable
@ 2016-03-11 15:29     ` Vlastimil Babka
  0 siblings, 0 replies; 234+ messages in thread
From: Vlastimil Babka @ 2016-03-11 15:29 UTC (permalink / raw)
  To: Michal Hocko, LKML
  Cc: Andrew Morton, linux-mm, Alex Deucher, Alex Thorlton,
	Andrea Arcangeli, Andy Lutomirski, Benjamin LaHaise,
	Christian König, Daniel Vetter, Dave Hansen, David Airlie,
	Davidlohr Bueso, David Rientjes, H . Peter Anvin, Hugh Dickins,
	Ingo Molnar, Johannes Weiner, Kirill A . Shutemov,
	Konstantin Khlebnikov, linux-arch, Mel Gorman, Oleg Nesterov,
	Peter Zijlstra, Petr Cermak, Thomas Gleixner, Michal Hocko

On 02/29/2016 02:26 PM, Michal Hocko wrote:
> From: Michal Hocko <mhocko@suse.com>
>
> amdgpu_mn_get which is called during ioct path relies on mmap_sem for
> write. If the waiting task gets killed by the oom killer it would block
> oom_reaper from asynchronous address space reclaim and reduce the
> chances of timely OOM resolving. Wait for the lock in the killable mode
> and return with EINTR if the task got killed while waiting.
>
> Cc: David Airlie <airlied@linux.ie>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Signed-off-by: Michal Hocko <mhocko@suse.com>


Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
> index d7ec9bd6755f..6f44f1c23be3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
> @@ -181,7 +181,10 @@ static struct amdgpu_mn *amdgpu_mn_get(struct amdgpu_device *adev)
>   	int r;
>
>   	mutex_lock(&adev->mn_lock);
> -	down_write(&mm->mmap_sem);
> +	if (down_write_killable(&mm->mmap_sem)) {
> +		mutex_unlock(&adev->mn_lock);
> +		return -EINTR;
> +	}
>
>   	hash_for_each_possible(adev->mn_hash, rmn, node, (unsigned long)mm)
>   		if (rmn->mm == mm)
>

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

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

* Re: [PATCH] uprobes: wait for mmap_sem for write killable
  2016-03-11 14:58       ` Vlastimil Babka
@ 2016-03-11 15:32         ` Michal Hocko
  -1 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-11 15:32 UTC (permalink / raw)
  To: Vlastimil Babka; +Cc: LKML, Andrew Morton, Oleg Nesterov, linux-mm

On Fri 11-03-16 15:58:43, Vlastimil Babka wrote:
> On 02/29/2016 06:42 PM, Michal Hocko wrote:
[...]
> >@@ -1468,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
> >  	if (current->flags & PF_EXITING)
> >  		return;
> >
> >-	if (!__create_xol_area(current->utask->dup_xol_addr))
> >+	if (!__create_xol_area(current->utask->dup_xol_addr) &&
> >+			!fatal_signal_pending(current)
>                                                       ^ missing ")"
> 

Fixed

> Other than that,
> Acked-by: Vlastimil Babka <vbabka@suse.cz>

Thanks!

> 
> >  		uprobe_warn(current, "dup xol area");
> >  }
> >
> >

-- 
Michal Hocko
SUSE Labs

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

* Re: [PATCH] uprobes: wait for mmap_sem for write killable
@ 2016-03-11 15:32         ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-03-11 15:32 UTC (permalink / raw)
  To: Vlastimil Babka; +Cc: LKML, Andrew Morton, Oleg Nesterov, linux-mm

On Fri 11-03-16 15:58:43, Vlastimil Babka wrote:
> On 02/29/2016 06:42 PM, Michal Hocko wrote:
[...]
> >@@ -1468,7 +1470,8 @@ static void dup_xol_work(struct callback_head *work)
> >  	if (current->flags & PF_EXITING)
> >  		return;
> >
> >-	if (!__create_xol_area(current->utask->dup_xol_addr))
> >+	if (!__create_xol_area(current->utask->dup_xol_addr) &&
> >+			!fatal_signal_pending(current)
>                                                       ^ missing ")"
> 

Fixed

> Other than that,
> Acked-by: Vlastimil Babka <vbabka@suse.cz>

Thanks!

> 
> >  		uprobe_warn(current, "dup xol area");
> >  }
> >
> >

-- 
Michal Hocko
SUSE Labs

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

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

* [PATCH 17/18] drm/radeon: make radeon_mn_get wait for mmap_sem killable
  2016-04-26 12:56 [PATCH 0/18] change mmap_sem taken for write killable v2 Michal Hocko
@ 2016-04-26 12:56   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-04-26 12:56 UTC (permalink / raw)
  To: linux-mm, Andrew Morton
  Cc: LKML, Michal Hocko, Alex Deucher, Christian König,
	David Airlie, Vlastimil Babka

From: Michal Hocko <mhocko@suse.com>

radeon_mn_get which is called during ioct path relies on mmap_sem for
write. If the waiting task gets killed by the oom killer it would block
oom_reaper from asynchronous address space reclaim and reduce the
chances of timely OOM resolving. Wait for the lock in the killable mode
and return with EINTR if the task got killed while waiting.

Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: "Christian König" <christian.koenig@amd.com>
Cc: David Airlie <airlied@linux.ie>
Reviewed-by: Christian König <christian.koenig@amd.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 drivers/gpu/drm/radeon/radeon_mn.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c
index eef006c48584..896f2cf51e4e 100644
--- a/drivers/gpu/drm/radeon/radeon_mn.c
+++ b/drivers/gpu/drm/radeon/radeon_mn.c
@@ -186,7 +186,9 @@ static struct radeon_mn *radeon_mn_get(struct radeon_device *rdev)
 	struct radeon_mn *rmn;
 	int r;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return ERR_PTR(-EINTR);
+
 	mutex_lock(&rdev->mn_lock);
 
 	hash_for_each_possible(rdev->mn_hash, rmn, node, (unsigned long)mm)
-- 
2.8.0.rc3

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

* [PATCH 17/18] drm/radeon: make radeon_mn_get wait for mmap_sem killable
@ 2016-04-26 12:56   ` Michal Hocko
  0 siblings, 0 replies; 234+ messages in thread
From: Michal Hocko @ 2016-04-26 12:56 UTC (permalink / raw)
  To: linux-mm, Andrew Morton
  Cc: LKML, Michal Hocko, Alex Deucher, Christian König,
	David Airlie, Vlastimil Babka

From: Michal Hocko <mhocko@suse.com>

radeon_mn_get which is called during ioct path relies on mmap_sem for
write. If the waiting task gets killed by the oom killer it would block
oom_reaper from asynchronous address space reclaim and reduce the
chances of timely OOM resolving. Wait for the lock in the killable mode
and return with EINTR if the task got killed while waiting.

Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: "Christian KA?nig" <christian.koenig@amd.com>
Cc: David Airlie <airlied@linux.ie>
Reviewed-by: Christian KA?nig <christian.koenig@amd.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
 drivers/gpu/drm/radeon/radeon_mn.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c
index eef006c48584..896f2cf51e4e 100644
--- a/drivers/gpu/drm/radeon/radeon_mn.c
+++ b/drivers/gpu/drm/radeon/radeon_mn.c
@@ -186,7 +186,9 @@ static struct radeon_mn *radeon_mn_get(struct radeon_device *rdev)
 	struct radeon_mn *rmn;
 	int r;
 
-	down_write(&mm->mmap_sem);
+	if (down_write_killable(&mm->mmap_sem))
+		return ERR_PTR(-EINTR);
+
 	mutex_lock(&rdev->mn_lock);
 
 	hash_for_each_possible(rdev->mn_hash, rmn, node, (unsigned long)mm)
-- 
2.8.0.rc3

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

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

end of thread, other threads:[~2016-04-26 12:57 UTC | newest]

Thread overview: 234+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-29 13:26 [PATCH 0/18] change mmap_sem taken for write killable Michal Hocko
2016-02-29 13:26 ` Michal Hocko
2016-02-29 13:26 ` Michal Hocko
2016-02-29 13:26 ` [PATCH 01/18] mm: Make mmap_sem for write waits killable for mm syscalls Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:44   ` kbuild test robot
2016-02-29 13:44     ` kbuild test robot
2016-02-29 13:44   ` kbuild test robot
2016-02-29 13:44     ` kbuild test robot
2016-03-10 15:47   ` Vlastimil Babka
2016-03-10 15:47     ` Vlastimil Babka
2016-03-10 15:47     ` Vlastimil Babka
2016-03-10 15:56     ` Michal Hocko
2016-03-10 15:56       ` Michal Hocko
2016-03-10 15:56       ` Michal Hocko
2016-02-29 13:26 ` [PATCH 02/18] mm: make vm_mmap killable Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-03-11  9:59   ` Vlastimil Babka
2016-03-11  9:59     ` Vlastimil Babka
2016-03-11  9:59     ` Vlastimil Babka
2016-03-11 12:12     ` Michal Hocko
2016-03-11 12:12       ` Michal Hocko
2016-03-11 12:12       ` Michal Hocko
2016-03-11 12:43       ` Vlastimil Babka
2016-03-11 12:43         ` Vlastimil Babka
2016-03-11 12:43         ` Vlastimil Babka
2016-03-11 12:55         ` Michal Hocko
2016-03-11 12:55           ` Michal Hocko
2016-03-11 12:55           ` Michal Hocko
2016-02-29 13:26 ` [PATCH 03/18] mm: make vm_munmap killable Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-03-11 10:06   ` Vlastimil Babka
2016-03-11 10:06     ` Vlastimil Babka
2016-03-11 10:06     ` Vlastimil Babka
2016-03-11 12:32     ` Michal Hocko
2016-03-11 12:32       ` Michal Hocko
2016-03-11 12:32       ` Michal Hocko
2016-02-29 13:26 ` [PATCH 04/18] mm, aout: handle vm_brk failures Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-03-11 10:32   ` Vlastimil Babka
2016-03-11 10:32     ` Vlastimil Babka
2016-03-11 10:32     ` Vlastimil Babka
2016-03-11 12:42     ` Michal Hocko
2016-03-11 12:42       ` Michal Hocko
2016-03-11 12:42       ` Michal Hocko
2016-02-29 13:26 ` [PATCH 05/18] mm, elf: handle vm_brk error Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-03-11 10:35   ` Vlastimil Babka
2016-03-11 10:35     ` Vlastimil Babka
2016-03-11 10:35     ` Vlastimil Babka
2016-02-29 13:26 ` [PATCH 06/18] mm: make vm_brk killable Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-03-11 10:44   ` Vlastimil Babka
2016-03-11 10:44     ` Vlastimil Babka
2016-03-11 10:44     ` Vlastimil Babka
2016-02-29 13:26 ` [PATCH 07/18] mm, proc: make clear_refs killable Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:47   ` kbuild test robot
2016-02-29 13:47     ` kbuild test robot
2016-02-29 17:38   ` Oleg Nesterov
2016-02-29 17:38     ` Oleg Nesterov
2016-02-29 17:38     ` Oleg Nesterov
2016-02-29 17:53     ` Michal Hocko
2016-02-29 17:53       ` Michal Hocko
2016-02-29 17:53       ` Michal Hocko
2016-02-29 17:58       ` Oleg Nesterov
2016-02-29 17:58         ` Oleg Nesterov
2016-02-29 17:58         ` Oleg Nesterov
2016-02-29 18:02         ` Michal Hocko
2016-02-29 18:02           ` Michal Hocko
2016-02-29 18:02           ` Michal Hocko
2016-02-29 17:56   ` [PATCH] " Michal Hocko
2016-02-29 17:56     ` Michal Hocko
2016-02-29 18:16     ` Oleg Nesterov
2016-02-29 18:16       ` Oleg Nesterov
2016-02-29 20:25     ` kbuild test robot
2016-03-11 10:59     ` Vlastimil Babka
2016-03-11 10:59       ` Vlastimil Babka
2016-02-29 13:26 ` [PATCH 08/18] mm, fork: make dup_mmap wait for mmap_sem for write killable Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:48   ` kbuild test robot
2016-02-29 13:48     ` kbuild test robot
2016-02-29 17:54   ` Oleg Nesterov
2016-02-29 17:54     ` Oleg Nesterov
2016-02-29 17:54     ` Oleg Nesterov
2016-02-29 18:07   ` [PATCH] " Michal Hocko
2016-02-29 18:07     ` Michal Hocko
2016-02-29 20:13     ` kbuild test robot
2016-03-11 11:12     ` Vlastimil Babka
2016-03-11 11:12       ` Vlastimil Babka
2016-02-29 13:26 ` [PATCH 09/18] ipc, shm: make shmem attach/detach wait for mmap_sem killable Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-03-08 19:15   ` Davidlohr Bueso
2016-03-08 19:15     ` Davidlohr Bueso
2016-03-08 19:15     ` Davidlohr Bueso
2016-03-09 10:16     ` Michal Hocko
2016-03-09 10:16       ` Michal Hocko
2016-03-09 10:16       ` Michal Hocko
2016-03-09 10:19   ` [PATCH] " Michal Hocko
2016-03-09 10:19     ` Michal Hocko
2016-03-09 10:46     ` kbuild test robot
2016-03-11 11:18     ` Vlastimil Babka
2016-03-11 11:18       ` Vlastimil Babka
2016-02-29 13:26 ` [PATCH 10/18] vdso: make arch_setup_additional_pages wait for mmap_sem for write killable Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:45   ` kbuild test robot
2016-02-29 13:45     ` kbuild test robot
2016-02-29 13:50   ` kbuild test robot
2016-02-29 13:50     ` kbuild test robot
2016-02-29 13:53   ` kbuild test robot
2016-02-29 13:53     ` kbuild test robot
2016-02-29 15:41   ` Andy Lutomirski
2016-02-29 15:41     ` Andy Lutomirski
2016-02-29 15:41     ` Andy Lutomirski
2016-03-11 11:28   ` Vlastimil Babka
2016-03-11 11:28     ` Vlastimil Babka
2016-03-11 11:28     ` Vlastimil Babka
2016-02-29 13:26 ` [PATCH 11/18] coredump: make coredump_wait wait for mma_sem " Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 15:57   ` Oleg Nesterov
2016-02-29 15:57     ` Oleg Nesterov
2016-02-29 15:57     ` Oleg Nesterov
2016-03-11 11:32   ` Vlastimil Babka
2016-03-11 11:32     ` Vlastimil Babka
2016-03-11 11:32     ` Vlastimil Babka
2016-03-11 11:54     ` Vlastimil Babka
2016-03-11 11:54       ` Vlastimil Babka
2016-03-11 11:54       ` Vlastimil Babka
2016-03-11 12:46       ` Michal Hocko
2016-03-11 12:46         ` Michal Hocko
2016-03-11 12:46         ` Michal Hocko
2016-02-29 13:26 ` [PATCH 12/18] aio: make aio_setup_ring killable Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 16:17   ` Jeff Moyer
2016-02-29 16:17     ` Jeff Moyer
2016-02-29 16:17     ` Jeff Moyer
2016-03-11 11:57   ` Vlastimil Babka
2016-03-11 11:57     ` Vlastimil Babka
2016-03-11 11:57     ` Vlastimil Babka
2016-02-29 13:26 ` [PATCH 13/18] exec: make exec path waiting for mmap_sem killable Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 17:23   ` Oleg Nesterov
2016-02-29 17:23     ` Oleg Nesterov
2016-02-29 17:23     ` Oleg Nesterov
2016-02-29 17:47     ` Michal Hocko
2016-02-29 17:47       ` Michal Hocko
2016-02-29 17:47       ` Michal Hocko
2016-02-29 18:10       ` Oleg Nesterov
2016-02-29 18:10         ` Oleg Nesterov
2016-02-29 18:10         ` Oleg Nesterov
2016-03-11 12:51   ` Vlastimil Babka
2016-03-11 12:51     ` Vlastimil Babka
2016-03-11 12:51     ` Vlastimil Babka
2016-02-29 13:26 ` [PATCH 14/18] prctl: make PR_SET_THP_DISABLE wait " Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-03-11 12:54   ` Vlastimil Babka
2016-03-11 12:54     ` Vlastimil Babka
2016-03-11 12:54     ` Vlastimil Babka
2016-02-29 13:26 ` [PATCH 15/18] uprobes: wait for mmap_sem for write killable Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 15:57   ` Oleg Nesterov
2016-02-29 15:57     ` Oleg Nesterov
2016-02-29 15:57     ` Oleg Nesterov
2016-02-29 16:28     ` Michal Hocko
2016-02-29 16:28       ` Michal Hocko
2016-02-29 16:28       ` Michal Hocko
2016-02-29 17:12       ` Oleg Nesterov
2016-02-29 17:12         ` Oleg Nesterov
2016-02-29 17:12         ` Oleg Nesterov
2016-02-29 17:42   ` [PATCH] " Michal Hocko
2016-02-29 17:42     ` Michal Hocko
2016-02-29 17:52     ` kbuild test robot
2016-02-29 17:53     ` kbuild test robot
2016-02-29 18:11     ` Oleg Nesterov
2016-02-29 18:11       ` Oleg Nesterov
2016-02-29 18:22       ` Michal Hocko
2016-02-29 18:22         ` Michal Hocko
2016-02-29 18:38         ` Oleg Nesterov
2016-02-29 18:38           ` Oleg Nesterov
2016-03-11 14:58     ` Vlastimil Babka
2016-03-11 14:58       ` Vlastimil Babka
2016-03-11 15:32       ` Michal Hocko
2016-03-11 15:32         ` Michal Hocko
2016-02-29 13:26 ` [PATCH 16/18] drm/i915: make i915_gem_mmap_ioctl wait for mmap_sem killable Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-03-11 15:23   ` Vlastimil Babka
2016-03-11 15:23     ` Vlastimil Babka
2016-03-11 15:23     ` Vlastimil Babka
2016-02-29 13:26 ` [PATCH 17/18] drm/radeon: make radeon_mn_get " Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:35   ` Christian König
2016-02-29 13:35     ` Christian König
2016-02-29 13:35     ` Christian König
2016-02-29 13:35     ` Christian König
2016-03-11 15:27   ` Vlastimil Babka
2016-03-11 15:27     ` Vlastimil Babka
2016-03-11 15:27     ` Vlastimil Babka
2016-02-29 13:26 ` [PATCH 18/18] drm/amdgpu: make amdgpu_mn_get " Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-02-29 13:26   ` Michal Hocko
2016-03-11 15:29   ` Vlastimil Babka
2016-03-11 15:29     ` Vlastimil Babka
2016-03-11 15:29     ` Vlastimil Babka
2016-02-29 13:31 ` [PATCH 0/18] change mmap_sem taken for write killable Michal Hocko
2016-02-29 13:31   ` Michal Hocko
2016-02-29 13:31   ` Michal Hocko
2016-02-29 14:04 ` Kirill A. Shutemov
2016-02-29 14:04   ` Kirill A. Shutemov
2016-02-29 14:04   ` Kirill A. Shutemov
2016-02-29 14:16   ` Michal Hocko
2016-02-29 14:16     ` Michal Hocko
2016-02-29 14:16     ` Michal Hocko
2016-02-29 15:03     ` Kirill A. Shutemov
2016-02-29 15:03       ` Kirill A. Shutemov
2016-02-29 15:03       ` Kirill A. Shutemov
2016-04-26 12:56 [PATCH 0/18] change mmap_sem taken for write killable v2 Michal Hocko
2016-04-26 12:56 ` [PATCH 17/18] drm/radeon: make radeon_mn_get wait for mmap_sem killable Michal Hocko
2016-04-26 12:56   ` Michal Hocko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.