public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: "Paolo 'Blaisorblade' Giarrusso" <blaisorblade@yahoo.it>
Cc: torvalds@osdl.org, jdike@addtoit.com,
	user-mode-linux-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 07/10] uml: avoid fixing faults while atomic
Date: Wed, 21 Sep 2005 12:49:57 -0700	[thread overview]
Message-ID: <20050921124957.437cf069.akpm@osdl.org> (raw)
In-Reply-To: <20050921172908.10219.57644.stgit@zion.home.lan>

"Paolo 'Blaisorblade' Giarrusso" <blaisorblade@yahoo.it> wrote:
>
> From: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
> 
> Following i386, we should maybe refuse trying to fault in pages when we're
> doing atomic operations, because to handle the fault we could need to take
> already taken spinlocks.
> 
> Also, if we're doing an atomic operation (in the sense of in_atomic()) we're
> surely in kernel mode and we're surely going to handle adequately the failed
> fault, so it's safe to behave this way.
> 
> Currently, on UML SMP is rarely used, and we don't support PREEMPT, so this is
> unlikely to create problems right now, but it might in the future.
> 

That's not really an accurate explanation/understanding of what's going on
in there.

There's an extremely special-case in the pagefault handlers where we fail
the fault if in_atomic().  It's unrelated to spinlocks (spinlocks don't
even cause in_atomic() to become true if !CONFIG_PREEMPT).

It has to do with kmap_atomic().  There's tricksy code in mm/filemap.c
which will fault the target page in by hand and will then take an atomic
kmap and will then raise current->preempt_count by hand, so in_atomic()
becomes true even if !COFNIG_PREEMPT.

So at this stage we expect to be able to do a copy_to/from_user to/from
pagecache without taking a fault, because we just faulted the page in by
hand.  And we're not allowed to take a fault, because we're holding an
atomic kmap.  But if we _do_ take a fault (extreme memory pressure, racing
munmap, etc) then we want to fail the pagefault immediately.

The in_atomic() test in x86's do_page_fault() is in fact a message passed
into it from filemap.c's kmap_atomic().  It has accidental side-effects,
such as making copy_to_user() fail if inside spinlocks when
CONFIG_PREEMPT=y.


So I think this change is only needed if UML implements kmap_atomic, as in
arch/i386/mm/highmem.c, which it surely does not do?


> 
> diff --git a/arch/um/kernel/trap_kern.c b/arch/um/kernel/trap_kern.c
> --- a/arch/um/kernel/trap_kern.c
> +++ b/arch/um/kernel/trap_kern.c
> @@ -40,6 +40,12 @@ int handle_page_fault(unsigned long addr
>  	int err = -EFAULT;
>  
>  	*code_out = SEGV_MAPERR;
> +
> +	/* If the fault was during atomic operation, don't take the fault, just
> +	 * fail. */
> +	if (in_atomic())
> +		goto out_nosemaphore;
> +
>  	down_read(&mm->mmap_sem);
>  	vma = find_vma(mm, address);
>  	if(!vma) 
> @@ -90,6 +96,7 @@ survive:
>  	flush_tlb_page(vma, address);
>  out:
>  	up_read(&mm->mmap_sem);
> +out_nosemaphore:
>  	return(err);
>  
>  /*

  reply	other threads:[~2005-09-21 19:50 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-21 17:23 [PATCH 0/10] "Bigger" UML fixes for 2.6.14 Blaisorblade
2005-09-21 17:27 ` [PATCH 01/10] uml: don't remove umid files in conflict case Paolo 'Blaisorblade' Giarrusso
2005-09-21 17:28 ` [PATCH 02/10] strlcat: use for uml umid.c Paolo 'Blaisorblade' Giarrusso
2005-09-21 17:28 ` [PATCH 03/10] uml: don't redundantly mark pte as newpage in pte_modify Paolo 'Blaisorblade' Giarrusso
2005-09-21 17:28 ` [PATCH 04/10] uml: fix hang in TT mode on fault Paolo 'Blaisorblade' Giarrusso
2005-09-21 17:28 ` [PATCH 05/10] uml: fix condition in tlb flush Paolo 'Blaisorblade' Giarrusso
2005-09-21 17:28 ` [PATCH 06/10] uml: run mconsole "sysrq" in process context Paolo 'Blaisorblade' Giarrusso
2005-09-21 20:50   ` [uml-devel] " Jeff Dike
2005-09-22 19:20     ` Blaisorblade
2005-09-22 20:37       ` Jeff Dike
2005-09-22 20:48         ` Blaisorblade
2005-09-23  7:40         ` Andrew Morton
2005-09-23 13:33           ` Jeff Dike
2005-09-25 21:34             ` Paul Jackson
2005-09-21 17:29 ` [PATCH 07/10] uml: avoid fixing faults while atomic Paolo 'Blaisorblade' Giarrusso
2005-09-21 19:49   ` Andrew Morton [this message]
2005-09-21 20:22     ` [uml-devel] " Blaisorblade
2005-09-21 20:47       ` Andrew Morton
2005-09-22 19:37         ` Blaisorblade
2005-09-22 19:58           ` Andrew Morton
2005-09-22 20:54           ` Linus Torvalds
2005-09-21 20:29     ` Linus Torvalds
2005-09-21 17:29 ` [PATCH 08/10] uml: Fix GFP_ flags usage Paolo 'Blaisorblade' Giarrusso
2005-09-21 19:19   ` Bill Davidsen
2005-09-21 20:52   ` [uml-devel] " Jeff Dike
2005-09-21 17:29 ` [PATCH 09/10] Uml: use GFP_ATOMIC for allocations under spinlocks Paolo 'Blaisorblade' Giarrusso
2005-09-21 17:29 ` [PATCH 10/10] uml: replace printk with "stack-friendly" printf - to report console failure Paolo 'Blaisorblade' Giarrusso

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=20050921124957.437cf069.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=blaisorblade@yahoo.it \
    --cc=jdike@addtoit.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /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