linux-um archives
 help / color / mirror / Atom feed
From: Blaisorblade <blaisorblade@yahoo.it>
To: user-mode-linux-devel@lists.sourceforge.net,
	Young Koh <young.koh@gmail.com>
Subject: Re: [uml-devel] a question about sigsetjmp() in copy_from/to_user()
Date: Wed, 28 Sep 2005 10:41:15 +0200	[thread overview]
Message-ID: <200509281041.15953.blaisorblade@yahoo.it> (raw)
In-Reply-To: <3524bf1f050927070645b999bd@mail.gmail.com>

On Tuesday 27 September 2005 16:06, Young Koh wrote:
> Hi,

> i have a question about copy_from/to_user() implementation in skas mode.

Ok, and here I'll explain also about TT mode, since they're reasonably 
similar, and TT mode is more similar to i386.
> as my understanding,
> when copy_from/to_user() is  invoked, before the address translation
> happens, UML kernel calls sigsetjmp() to come back when there is a
> segmentation fault. and if there is, it seems that the system call an
> application triggered eventually returns EFAULT.
Yes, copy_*_user returns a failure code and the calling code is supposed to 
check and return EFAULT.

Assuming the fault is a *real* fault, i.e. an unfixable one - maybe we simply 
need to call handle_page_fault() and load the page from swap.
> then, it seems to me 
> that sigsetjmp() is to catch the error when the application gave the
> invalid user space address.
Exactly.
> my question is, if so, shouldn't the error be caught when UML kernel
> translates the user space address to the kernel space address? i mean,
> UML kernel must know the valid memory regions
Well, saying "regions" is a bit confusing - in fact, you are coping with 
installed mappings (mmap()s done on the host), which are like page tables 
(populated on fault).
> and if the address is 
> out of the valid regions, then it knows the address is invalid before
> UML tries to access the address.

> why should it use sigsetjmp() and let 
> a segfault occur?
In general, because it would be faster, because you must optimize for the fast 
path, when a segfault won't occur and predoing the checking 

1) Background: TT mode and i386 implementation. They can access the user 
address directly, so they do, and catch the error afterwards. Why? Because 
when we care for performance, the application will pass correct address. So 
it's better to optimize the performance of the fast path (correct address) 
than the one of the slow path. The hardware walking of page tables is faster 
than the software one (even due to TLBs, which are processor caches of page 
tables).

Whenever a fault occur, the i386 exception handler (see 
search_exception_tables() and 
grep ".section __ex_table" include/asm-i386/*)

and/or the TT mode fault catcher make copy_*_user return an error.

2) SKAS instead. SKAS is like 4G/4G on the host (it is actually a 3G/3G).

In SKAS mode, we actually walk the page tables, because we cannot access the 
host mapping - we're using a different mapping set.

In fact, what you see doesn't catch user space wrong addresses.

It catches kernelspace faulting addresses - which is legal to happen, because 
i386 implementation catches any fault, and doesn't make a distinction, and 
which happens, when you try to do things like "cat /dev/kmem" - you're trying 
to do copy_to_user(to, offset /* which is 0 */, size).

In fact, that sigsegjmp() was added back in 2.4.24-?um (IIRC) and then around 
~2.6.7-um after I and Jeff analyzed this.
-- 
Inform me of my mistakes, so I can keep imitating Homer Simpson's "Doh!".
Paolo Giarrusso, aka Blaisorblade (Skype ID "PaoloGiarrusso", ICQ 215621894)
http://www.user-mode-linux.org/~blaisorblade


		
___________________________________ 
Yahoo! Messenger: chiamate gratuite in tutto il mondo 
http://it.messenger.yahoo.com



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

  parent reply	other threads:[~2005-09-28 11:59 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-27 14:06 [uml-devel] a question about sigsetjmp() in copy_from/to_user() Young Koh
2005-09-27 17:28 ` Jeff Dike
2005-09-28 11:59   ` Blaisorblade
2005-09-28 13:47     ` Young Koh
2005-09-28 14:50       ` Jeff Dike
2005-09-28 19:25         ` Young Koh
2005-09-29 12:09           ` Blaisorblade
2005-09-30 15:08             ` Young Koh
2005-09-30 15:44               ` Geert Uytterhoeven
2005-10-02  1:03             ` Jeff Dike
2005-10-02 10:23               ` Blaisorblade
2005-10-02 18:31                 ` Jeff Dike
2005-10-03 18:35                   ` Blaisorblade
2005-10-03 20:38                     ` Jeff Dike
2005-09-28 16:09     ` Jeff Dike
2005-09-28 17:26       ` Blaisorblade
2005-09-28 18:43         ` Jeff Dike
2005-09-28  8:41 ` Blaisorblade [this message]
2005-09-28 14:22   ` Young Koh
2005-09-28 16:43     ` Blaisorblade

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=200509281041.15953.blaisorblade@yahoo.it \
    --to=blaisorblade@yahoo.it \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    --cc=young.koh@gmail.com \
    /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