All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC 0/2] Reenable might_sleep() checks for might_fault() when atomic
@ 2014-11-25 11:43 ` David Hildenbrand
  0 siblings, 0 replies; 89+ messages in thread
From: David Hildenbrand @ 2014-11-25 11:43 UTC (permalink / raw)
  To: linuxppc-dev, linux-arch, linux-kernel
  Cc: benh, paulus, akpm, heiko.carstens, dahi, schwidefsky, borntraeger

I recently discovered that commit 662bbcb2747c2422cf98d3d97619509379eee466
removed/skipped all might_sleep checks for might_fault() calls when in atomic.

Reason was to allow calling copy_(to|from)_user while in pagefault_disabled(),
because otherwise, CONFIG_DEBUG_ATOMIC_SLEEP would find false positives. However
we have the inatomic variants of these function for this purpose.

The result of this change was that all guest access (that correctly uses
might_fault()) doesn't perform atomic checks when CONFIG_DEBUG_ATOMIC_SLEEP is
enabled. We lost a mighty debugging feature for user access.

As I wasn't able to come up with any other reason why this should be
necessary, I suggest turning the might_sleep() checks on again in the
might_fault() code.

pagefault_disable/pagefault_enable seems to be used mainly for futex, perf event
and kmap.

Going over all changes since that commit, it seems like most code already uses the
inatomic variants of copy_(to|from)_user. Code relying on (get|put)_user during
pagefault_disable() don't make use of any might_fault() in their (get|put)_user
implementation. Examples:
- arch/m68k/include/asm/futex.h
- arch/parisc/include/asm/futex.h
- arch/sh/include/asm/futex-irq.h
- arch/tile/include/asm/futex.h
So changing might_fault() back to trigger might_sleep() won't change a thing for
them. Hope I haven't missed anything.

I only identified one might_fault() that would get triggered by get_user() on
powerpc and fixed it by using the inatomic variant (not tested). I am not sure
if we need some non-sleeping access_ok() prior to __get_user_inatomic().

By looking at the code I was wondering where the correct place for might_fault()
calls is? Doesn't seem to be very consistent. Examples:

                   | asm-generic | arm | arm64 | frv | m32r | x86 and s390
---------------------------------------------------------------------------
get_user()         |   Yes       | Yes | Yes   | No  | Yes  |     Yes
__get_user()       |   No        | Yes | No    | No  | Yes  |     No
put_user()         |   Yes       | Yes | Yes   | No  | Yes  |     Yes
__put_user()       |   No        | Yes | No    | No  | Yes  |     No
copy_to_user()     |   Yes       | No  | No    | Yes | Yes  |     Yes
__copy_to_user()   |   No        | No  | No    | Yes | No   |     No
copy_from_user()   |   Yes       | No  | No    | Yes | Yes  |     Yes
__copy_from_user() |   No        | No  | No    | Yes | No   |     No

So I would have assume that the way asm-generic, x86 and s390 (+ propably
others) do this is the right way?
So we can speed up multiple calls to e.g. copy_to_user() by doing the access
check manually (and also the might_fault() if relevant), then calling
__copy_to_user().

So in general, I conclude that the concept is:
1. __.* variants perform no checking and don't call might_fault()
2. [a-z].* variants perform access checking (access_ok() if implemented)
3. [a-z].* variants call might_fault()
4. .*_inatomic variants usually don't perform access checks
5. .*_inatomic variants don't call might_fault()
6. If common code uses the __.* variants, it has to trigger access_ok() and
   call might_fault()
7. For pagefault_disable(), the inatomic variants are to be used

Comments? Opinions?


David Hildenbrand (2):
  powerpc/fsl-pci: atomic get_user when pagefault_disabled
  mm, sched: trigger might_sleep() in might_fault() when atomic

 arch/powerpc/sysdev/fsl_pci.c |  2 +-
 include/linux/kernel.h        |  8 ++++++--
 mm/memory.c                   | 11 ++++-------
 3 files changed, 11 insertions(+), 10 deletions(-)

-- 
1.8.5.5


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

end of thread, other threads:[~2015-01-30  7:58 UTC | newest]

Thread overview: 89+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-25 11:43 [RFC 0/2] Reenable might_sleep() checks for might_fault() when atomic David Hildenbrand
2014-11-25 11:43 ` David Hildenbrand
2014-11-25 11:43 ` [RFC 1/2] powerpc/fsl-pci: atomic get_user when pagefault_disabled David Hildenbrand
2014-11-25 11:43   ` David Hildenbrand
2015-01-30  5:15   ` [RFC,1/2] " Scott Wood
2015-01-30  7:58     ` David Hildenbrand
2014-11-25 11:43 ` [RFC 2/2] mm, sched: trigger might_sleep() in might_fault() when atomic David Hildenbrand
2014-11-25 11:43   ` David Hildenbrand
2014-11-26  7:02 ` [RFC 0/2] Reenable might_sleep() checks for " Michael S. Tsirkin
2014-11-26  7:02   ` Michael S. Tsirkin
2014-11-26 10:05   ` David Hildenbrand
2014-11-26 10:05     ` David Hildenbrand
2014-11-26 15:17     ` Michael S. Tsirkin
2014-11-26 15:17       ` Michael S. Tsirkin
2014-11-26 15:23       ` Michael S. Tsirkin
2014-11-26 15:23         ` Michael S. Tsirkin
2014-11-26 15:23         ` Michael S. Tsirkin
2014-11-26 15:32         ` David Hildenbrand
2014-11-26 15:32           ` David Hildenbrand
2014-11-26 15:47           ` Michael S. Tsirkin
2014-11-26 15:47             ` Michael S. Tsirkin
2014-11-26 16:02             ` David Hildenbrand
2014-11-26 16:02               ` David Hildenbrand
2014-11-26 16:19               ` Michael S. Tsirkin
2014-11-26 16:19                 ` Michael S. Tsirkin
2014-11-26 16:30                 ` Christian Borntraeger
2014-11-26 16:30                   ` Christian Borntraeger
2014-11-26 16:50                   ` Michael S. Tsirkin
2014-11-26 16:50                     ` Michael S. Tsirkin
2014-11-26 16:07             ` Christian Borntraeger
2014-11-26 16:07               ` Christian Borntraeger
2014-11-26 16:32               ` Michael S. Tsirkin
2014-11-26 16:32                 ` Michael S. Tsirkin
2014-11-26 16:51                 ` Christian Borntraeger
2014-11-26 16:51                   ` Christian Borntraeger
2014-11-26 17:04                   ` Michael S. Tsirkin
2014-11-26 17:04                     ` Michael S. Tsirkin
2014-11-26 17:21                     ` Michael S. Tsirkin
2014-11-26 17:21                       ` Michael S. Tsirkin
2014-11-27  7:09                     ` Heiko Carstens
2014-11-27  7:09                       ` Heiko Carstens
2014-11-27  7:40                       ` Michael S. Tsirkin
2014-11-27  7:40                         ` Michael S. Tsirkin
2014-11-27  8:03                       ` David Hildenbrand
2014-11-27  8:03                         ` David Hildenbrand
2014-11-27 12:04                         ` Heiko Carstens
2014-11-27 12:04                           ` Heiko Carstens
2014-11-27 12:08                           ` David Hildenbrand
2014-11-27 12:08                             ` David Hildenbrand
2014-11-27 15:07                           ` Thomas Gleixner
2014-11-27 15:07                             ` Thomas Gleixner
2014-11-27 15:19                             ` David Hildenbrand
2014-11-27 15:19                               ` David Hildenbrand
2014-11-27 15:37                               ` David Laight
2014-11-27 15:37                                 ` David Laight
2014-11-27 15:37                                 ` David Laight
2014-11-27 15:45                                 ` David Hildenbrand
2014-11-27 15:45                                   ` David Hildenbrand
2014-11-27 16:27                                   ` David Laight
2014-11-27 16:27                                     ` David Laight
2014-11-27 16:49                                     ` David Hildenbrand
2014-11-27 16:49                                       ` David Hildenbrand
2014-11-27 16:49                                       ` David Hildenbrand
2014-11-27 21:52                               ` Thomas Gleixner
2014-11-27 21:52                                 ` Thomas Gleixner
2014-11-28  7:34                                 ` David Hildenbrand
2014-11-28  7:34                                   ` David Hildenbrand
2014-11-26 15:30       ` Christian Borntraeger
2014-11-26 15:30         ` Christian Borntraeger
2014-11-26 15:37         ` Michael S. Tsirkin
2014-11-26 15:37           ` Michael S. Tsirkin
2014-11-26 16:02           ` Christian Borntraeger
2014-11-26 16:02             ` Christian Borntraeger
2014-11-26 15:22     ` Michael S. Tsirkin
2014-11-26 15:22       ` Michael S. Tsirkin
2014-11-27 17:10 ` [PATCH RFC " David Hildenbrand
2014-11-27 17:10   ` David Hildenbrand
2014-11-27 17:10   ` [PATCH RFC 1/2] preempt: track pagefault_disable() calls in the preempt counter David Hildenbrand
2014-11-27 17:10     ` David Hildenbrand
2014-11-27 17:10   ` [PATCH RFC 2/2] mm, sched: trigger might_sleep() in might_fault() when pagefaults are disabled David Hildenbrand
2014-11-27 17:10     ` David Hildenbrand
2014-11-27 17:24     ` Michael S. Tsirkin
2014-11-27 17:24       ` Michael S. Tsirkin
2014-11-27 17:32       ` Michael S. Tsirkin
2014-11-27 17:32         ` Michael S. Tsirkin
2014-11-27 18:08         ` David Hildenbrand
2014-11-27 18:08           ` David Hildenbrand
2014-11-27 18:27           ` Michael S. Tsirkin
2014-11-27 18:27             ` Michael S. Tsirkin

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.