From: Oleg Nesterov <oleg@redhat.com>
To: Andrey Vagin <avagin@openvz.org>, Ingo Molnar <mingo@elte.hu>,
Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: David Rientjes <rientjes@google.com>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
linux-kernel@vger.kernel.org
Subject: Re: + x86-mm-handle-mm_fault_error-in-kernel-space.patch added to -mm tree
Date: Thu, 10 Mar 2011 15:28:12 +0100 [thread overview]
Message-ID: <20110310142812.GA25224@redhat.com> (raw)
(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(¤t->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))
next reply other threads:[~2011-03-10 14:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-10 14:28 Oleg Nesterov [this message]
2011-03-10 19:30 ` + x86-mm-handle-mm_fault_error-in-kernel-space.patch added to -mm tree 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110310142812.GA25224@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=avagin@openvz.org \
--cc=hpa@zytor.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=rientjes@google.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox