All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v2 0/6] Per process PTI activation
@ 2018-01-09 12:56 Willy Tarreau
  2018-01-09 12:56 ` [RFC PATCH v2 1/6] x86/mm: add a pti_disable entry in mm_context_t Willy Tarreau
                   ` (5 more replies)
  0 siblings, 6 replies; 103+ messages in thread
From: Willy Tarreau @ 2018-01-09 12:56 UTC (permalink / raw)
  To: linux-kernel, x86
  Cc: Willy Tarreau, Andy Lutomirski, Borislav Petkov, Brian Gerst,
	Dave Hansen, Ingo Molnar, Linus Torvalds, Peter Zijlstra,
	Thomas Gleixner, Josh Poimboeuf, H. Peter Anvin, Kees Cook

So here comes the second version after the first round of comments.

As suggested, I dropped the thread_info flag and placed it in the
mm_struct instead. There's now a per_cpu variable that can be checked
in the entry code to decide whether or not to switch CR3.

It's important to note that the new flag is lost upon execve(). I think
that this provides a better guarantee against any accidental use (eg: a
program calling some external helpers once in a while), but it also
means we can't use a wrapper anymore and have to modify the executable.

I continue to think that a mixed approach consisting in having a specific
flag that is only applied upon next execve() call and dropped could be
nice, but for now I'm not really sure how to do this cleanly.

Regarding the _PAGE_NX change, for now I didn't touch it. I like Andy's
approach consisting in changing it dynamically after the first page
fault caused by the return to userspace. I just don't know how to do
that for now.

I've split the entry code changes in two. The first part only updates the
kernel entry code to avoid updating CR3 if it already points to a kernel
PGD. The second one adds the flag check when going back to userspace.

This allowed me to check if the CR3-only changes brought any benefit, but
I failed to detect any improvement with that alone for now, including on
a preempt kernel.

With this patch, when haproxy starts with "arch_prctl(0x1022, 1)", the
performance drop compared to booting with "pti=off" is only ~1% and more
or less within measurement noise.

For now I've left the prctl to retrieve the current value as it helped
during debugging, though I think it should disappear before the final
version as it provides very little value.

Here are the numbers I'm seeing in the various situations for a few
tests on a hardware machine (core i7-4790K), numbers are in connections
per second, with the performance ratio compared to pti=off between
parenthesis :
                                     TEST(*)
                    reject       reject+acl       forward
 ---------------+-------------+---------------+----------------
  pti=off         444k (100%)    252k (100%)      83k (100%)
  pti=on          382k (86%)     195k (77%)       71k (85%)
  pti=on+prctl    439k (99%)     249k (99%)       83k (100%)

*: tests: 
   "reject"     : reject rule, accept(), setsockopt() and close()
   "reject+acl" : acl-based rule, does extra syscalls (getsockname(),
                  getsockopt, 2 setsockopt, recv, shutdown)
   "forward"    : connection forwarded to remote server, much heavier

It's interesting to node that the rule employing a few more syscalls
without adding much userspace work is obviously more impacted by PTI.
We have a total of 8 syscalls per connection on the middle one and
the difference is important.

Willy

Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>


Willy Tarreau (6):
  x86/mm: add a pti_disable entry in mm_context_t
  x86/arch_prctl: add ARCH_GET_NOPTI and ARCH_SET_NOPTI to
    enable/disable PTI
  x86/pti: add a per-cpu variable pti_disable
  x86/pti: don't mark the user PGD with _PAGE_NX.
  x86/entry/pti: avoid setting CR3 when it's already correct
  x86/entry/pti: don't switch PGD on when pti_disable is set

 arch/x86/entry/calling.h          | 25 +++++++++++++++++++++++++
 arch/x86/include/asm/mmu.h        |  4 ++++
 arch/x86/include/uapi/asm/prctl.h |  3 +++
 arch/x86/kernel/process_64.c      | 24 ++++++++++++++++++++++++
 arch/x86/mm/pti.c                 |  2 ++
 5 files changed, 58 insertions(+)

-- 
1.7.12.1

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

end of thread, other threads:[~2018-01-12 22:01 UTC | newest]

Thread overview: 103+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-09 12:56 [RFC PATCH v2 0/6] Per process PTI activation Willy Tarreau
2018-01-09 12:56 ` [RFC PATCH v2 1/6] x86/mm: add a pti_disable entry in mm_context_t Willy Tarreau
2018-01-09 12:56 ` [RFC PATCH v2 2/6] x86/arch_prctl: add ARCH_GET_NOPTI and ARCH_SET_NOPTI to enable/disable PTI Willy Tarreau
2018-01-09 14:17   ` Borislav Petkov
2018-01-09 14:36     ` Willy Tarreau
2018-01-09 14:51       ` Borislav Petkov
2018-01-09 14:54         ` Willy Tarreau
2018-01-09 21:26           ` Andy Lutomirski
2018-01-09 21:29             ` Borislav Petkov
2018-01-09 21:32               ` Willy Tarreau
2018-01-09 21:46                 ` Borislav Petkov
2018-01-09 22:06                   ` Willy Tarreau
2018-01-09 22:20                     ` Borislav Petkov
2018-01-09 22:29                       ` Dave Hansen
2018-01-09 22:40                       ` Willy Tarreau
2018-01-10 14:42                         ` Borislav Petkov
2018-01-10 15:39                           ` Willy Tarreau
2018-01-10 16:09                             ` Borislav Petkov
2018-01-10 16:19                               ` Willy Tarreau
2018-01-10 17:28                                 ` Borislav Petkov
2018-01-10  7:31                       ` Ingo Molnar
2018-01-10  7:37                         ` Willy Tarreau
2018-01-10  7:59                           ` Ingo Molnar
2018-01-09 23:53                     ` Andy Lutomirski
2018-01-10  4:25                       ` Willy Tarreau
2018-01-10  7:25               ` Ingo Molnar
2018-01-10 14:45                 ` Borislav Petkov
2018-01-10 15:43                   ` Willy Tarreau
2018-01-10 15:45                   ` Ingo Molnar
2018-01-09 21:34             ` Kees Cook
2018-01-09 21:41             ` Willy Tarreau
2018-01-09 21:50               ` Kees Cook
2018-01-09 22:03                 ` Willy Tarreau
2018-01-10  7:13             ` Ingo Molnar
2018-01-12 15:03   ` David Laight
2018-01-12 15:06     ` Willy Tarreau
2018-01-09 12:56 ` [RFC PATCH v2 3/6] x86/pti: add a per-cpu variable pti_disable Willy Tarreau
2018-01-10  7:19   ` Ingo Molnar
2018-01-10  7:29     ` Willy Tarreau
2018-01-10  8:01       ` Ingo Molnar
2018-01-10  8:50         ` Willy Tarreau
2018-01-10  8:59           ` Ingo Molnar
2018-01-10  9:00             ` Willy Tarreau
2018-01-09 12:56 ` [RFC PATCH v2 4/6] x86/pti: don't mark the user PGD with _PAGE_NX Willy Tarreau
2018-01-09 12:56 ` [RFC PATCH v2 5/6] x86/entry/pti: avoid setting CR3 when it's already correct Willy Tarreau
2018-01-10  7:16   ` Ingo Molnar
2018-01-10  7:18     ` Willy Tarreau
2018-01-10 20:29   ` Dave Hansen
2018-01-11  6:46     ` Willy Tarreau
2018-01-09 12:56 ` [RFC PATCH v2 6/6] x86/entry/pti: don't switch PGD on when pti_disable is set Willy Tarreau
2018-01-10  7:15   ` Ingo Molnar
2018-01-10  7:23     ` Willy Tarreau
2018-01-10  8:22   ` Peter Zijlstra
2018-01-10  9:11     ` Willy Tarreau
2018-01-10 19:21       ` Andy Lutomirski
2018-01-10 19:39         ` Willy Tarreau
2018-01-10 19:44           ` Andy Lutomirski
2018-01-10 19:50         ` Linus Torvalds
2018-01-10 20:04           ` Andy Lutomirski
2018-01-11  6:42           ` Willy Tarreau
2018-01-11 15:29             ` Dave Hansen
2018-01-11 15:44               ` Willy Tarreau
2018-01-11 15:51                 ` Dave Hansen
2018-01-11 17:02                   ` Andy Lutomirski
2018-01-11 18:21                     ` Alexei Starovoitov
2018-01-11 18:30                       ` Dave Hansen
2018-01-11 18:32                       ` Josh Poimboeuf
2018-01-11 18:36                         ` Linus Torvalds
2018-01-11 18:38                         ` Dave Hansen
2018-01-11 18:51                           ` Linus Torvalds
2018-01-11 18:57                             ` Dave Hansen
2018-01-11 19:05                               ` Josh Poimboeuf
2018-01-11 19:07                               ` Borislav Petkov
2018-01-11 19:17                                 ` Dave Hansen
2018-01-11 19:19                                   ` Olivier Galibert
2018-01-11 19:26                                     ` Josh Poimboeuf
2018-01-11 19:34                                       ` Alan Cox
2018-01-11 21:23                                         ` Willy Tarreau
2018-01-11 21:28                                           ` Linus Torvalds
2018-01-11 22:06                                             ` Willy Tarreau
2018-01-12 16:37                                               ` David Laight
2018-01-11 19:12                               ` Linus Torvalds
2018-01-11 19:38                               ` Alexei Starovoitov
2018-01-11 19:11                           ` Willy Tarreau
2018-01-11 20:00                     ` Dave Hansen
2018-01-11 17:09                 ` Andy Lutomirski
2018-01-11 17:40                   ` Willy Tarreau
2018-01-11 17:53                     ` Andy Lutomirski
2018-01-11 18:05                       ` Willy Tarreau
2018-01-11 18:15                         ` Dave Hansen
2018-01-11 18:31                           ` Linus Torvalds
2018-01-11 18:25                     ` Linus Torvalds
2018-01-11 18:26                       ` Linus Torvalds
2018-01-11 19:33                         ` Andy Lutomirski
2018-01-12 20:22                           ` Ingo Molnar
2018-01-12 21:18                             ` Andy Lutomirski
2018-01-12 21:54                               ` Willy Tarreau
2018-01-11 21:59                       ` Willy Tarreau
2018-01-12 16:27                       ` David Laight
2018-01-12 17:55                         ` Linus Torvalds
2018-01-12 19:36                           ` Willy Tarreau
2018-01-11 18:35                 ` Dave Hansen
2018-01-11 21:49                   ` Willy Tarreau

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.