All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: + x86-mm-handle-mm_fault_error-in-kernel-space.patch added to -mm tree
@ 2011-03-10 14:28 Oleg Nesterov
  2011-03-10 19:30 ` Andrew Vagin
  0 siblings, 1 reply; 8+ messages in thread
From: Oleg Nesterov @ 2011-03-10 14:28 UTC (permalink / raw)
  To: Andrey Vagin, Ingo Molnar, Thomas Gleixner, H. Peter Anvin,
	Andrew Morton
  Cc: David Rientjes, KAMEZAWA Hiroyuki, KOSAKI Motohiro, linux-kernel

(add cc's)

> Subject: x86/mm: handle mm_fault_error() in kernel space
> From: Andrey Vagin <avagin@openvz.org>
>
> mm_fault_error() should not execute oom-killer, if page fault occurs in
> kernel space.  E.g.  in copy_from_user/copy_to_user.

Why? I don't understand this part.

> This would happen if we find ourselves in OOM on a copy_to_user(), or a
> copy_from_user() which faults.
>
> Without this patch, the kernels hangs up in copy_from_user, because OOM
> killer sends SIG_KILL to current process,

This depends. OOM can choose another victim, and if it does we shouldn't
return -EFAULT.

> but it can't handle a signal
> while in syscall, then the kernel returns to copy_from_user, reexcute
> current command and provokes page_fault again.

Yes. This is buggy.

> --- a/arch/x86/mm/fault.c~x86-mm-handle-mm_fault_error-in-kernel-space
> +++ a/arch/x86/mm/fault.c
> @@ -827,6 +827,13 @@ mm_fault_error(struct pt_regs *regs, uns
>  	       unsigned long address, unsigned int fault)
>  {
>  	if (fault & VM_FAULT_OOM) {
> +		/* Kernel mode? Handle exceptions or die: */
> +		if (!(error_code & PF_USER)) {
> +			up_read(&current->mm->mmap_sem);
> +			no_context(regs, error_code, address);
> +			return;
> +		}
> +

At first glance, this is not optimal...

Perhaps I missed something, but afaics it is better to call
out_of_memory() first, then check if current was killed. In this case
no_context() is fine, we are not going to return to the user-mode.

IOW, what do you think about the (untested/uncompiled) patch below?

Oleg.

--- x/arch/x86/mm/fault.c
+++ x/arch/x86/mm/fault.c
@@ -829,6 +829,11 @@ mm_fault_error(struct pt_regs *regs, uns
 {
 	if (fault & VM_FAULT_OOM) {
 		out_of_memory(regs, error_code, address);
+
+		if (!(error_code & PF_USER) && fatal_signal_pending(current)) {
+			no_context(regs, error_code, address);
+			return;
+		}
 	} else {
 		if (fault & (VM_FAULT_SIGBUS|VM_FAULT_HWPOISON|
 			     VM_FAULT_HWPOISON_LARGE))


^ permalink raw reply	[flat|nested] 8+ messages in thread
* + x86-mm-handle-mm_fault_error-in-kernel-space.patch added to -mm tree
@ 2011-03-09 23:22 akpm
  0 siblings, 0 replies; 8+ messages in thread
From: akpm @ 2011-03-09 23:22 UTC (permalink / raw)
  To: mm-commits; +Cc: avagin, hpa, mingo, tglx


The patch titled
     x86/mm: handle mm_fault_error() in kernel space
has been added to the -mm tree.  Its filename is
     x86-mm-handle-mm_fault_error-in-kernel-space.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

See http://userweb.kernel.org/~akpm/stuff/added-to-mm.txt to find
out what to do about this

The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/

------------------------------------------------------
Subject: x86/mm: handle mm_fault_error() in kernel space
From: Andrey Vagin <avagin@openvz.org>

mm_fault_error() should not execute oom-killer, if page fault occurs in
kernel space.  E.g.  in copy_from_user/copy_to_user.

This would happen if we find ourselves in OOM on a copy_to_user(), or a
copy_from_user() which faults.

Without this patch, the kernels hangs up in copy_from_user, because OOM
killer sends SIG_KILL to current process, but it can't handle a signal
while in syscall, then the kernel returns to copy_from_user, reexcute
current command and provokes page_fault again.

With this patch the kernel return -EFAULT from copy_from_user.

The code, which checks that page fault occurred in kernel space, has been
copied from do_sigbus.

This situation is handled by the same way on powerpc, xtensa, tile, ...

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 arch/x86/mm/fault.c |    7 +++++++
 1 file changed, 7 insertions(+)

diff -puN arch/x86/mm/fault.c~x86-mm-handle-mm_fault_error-in-kernel-space arch/x86/mm/fault.c
--- a/arch/x86/mm/fault.c~x86-mm-handle-mm_fault_error-in-kernel-space
+++ a/arch/x86/mm/fault.c
@@ -827,6 +827,13 @@ mm_fault_error(struct pt_regs *regs, uns
 	       unsigned long address, unsigned int fault)
 {
 	if (fault & VM_FAULT_OOM) {
+		/* Kernel mode? Handle exceptions or die: */
+		if (!(error_code & PF_USER)) {
+			up_read(&current->mm->mmap_sem);
+			no_context(regs, error_code, address);
+			return;
+		}
+
 		out_of_memory(regs, error_code, address);
 	} else {
 		if (fault & (VM_FAULT_SIGBUS|VM_FAULT_HWPOISON|
_

Patches currently in -mm which might be from avagin@openvz.org are

x86-mm-handle-mm_fault_error-in-kernel-space.patch
oom-prevent-unnecessary-oom-kills-or-kernel-panics.patch
oom-skip-zombies-when-iterating-tasklist.patch
fs-devpts-inodec-correctly-check-d_alloc_name-return-code-in-devpts_pty_new.patch
fs-devpts_pty_new-return-enomem-if-dentry-allocation-failed.patch


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

end of thread, other threads:[~2011-03-13 10:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-10 14:28 + x86-mm-handle-mm_fault_error-in-kernel-space.patch added to -mm tree Oleg Nesterov
2011-03-10 19:30 ` Andrew Vagin
2011-03-11 11:19   ` Oleg Nesterov
2011-03-11 14:21     ` Andrew Vagin
2011-03-11 16:57       ` Oleg Nesterov
2011-03-12 21:11         ` Oleg Nesterov
2011-03-13 10:29           ` KOSAKI Motohiro
  -- strict thread matches above, loose matches on Subject: below --
2011-03-09 23:22 akpm

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.