public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC 0/4] Per-task PTI activation
@ 2018-01-08 16:12 Willy Tarreau
  2018-01-08 16:12 ` [PATCH RFC 1/4] x86/thread_info: add TIF_NOPTI to disable PTI per task Willy Tarreau
                   ` (5 more replies)
  0 siblings, 6 replies; 53+ messages in thread
From: Willy Tarreau @ 2018-01-08 16:12 UTC (permalink / raw)
  To: linux-kernel, x86; +Cc: tglx, gnomes, torvalds, Willy Tarreau

Hi!

I could experiment a bit with the possibility to enable/disable PTI per
task. Please keep in mind that it's not my area of experitise at all, but
doing so I could recover the initial performance without disabling PTI on
the whole system.

So what I did in this series consists in the following :
  - addition of a new per-task TIF_NOPTI flag. Please note that I'm not
    proud of the way I did it, as 32 flags were already taken. The flags
    are declared as "long" so there are 32 more flags available on x86_64
    but C and asm disagree on the type of 1<<32 so I had to declare the
    hex value by hand... By the way I even suspect that _TIF_FSCHECK is
    wrong once cast to a long, I think it causes sign extension into the
    32 upper bits since it's supposed to be signed.

  - addition of a set of arch_prctl() calls (ARCH_GET_NOPTI and
    ARCH_SET_NOPTI), to check and change the activation of the
    protection. The change requires CAP_SYS_RAWIO and can be done in
    a wrapper (that's how I tested)

  - the user PGD was marked with _PAGE_NX to prevent an accidental leak
    of CR3 from not being detected. I obviously had to disable this since
    in this case we do want such a user task to run without switching the
    PGD. I think this could be performed per-task maybe. Another approach
    might consist in dealing with 3 PGDs and using a different one for
    unprotected tasks but that really starts to sound overkill.

  - upon return to userspace, I check if the task's flags contain the
    new TIF_NOPTI or not. If it does contain it, then we don't switch
    the CR3.

  - upon entry into the kernel from userspace, we can't access the task's
    flags but we can already check if CR3 points to the kernel or user PGD,
    and we refrain from switching if it's already the system one.

By doing so I could recover the initial performance of haproxy in a VM,
going from 12400 connections per second to 21000 once started with this
trivial wrapper :

  #include <asm/prctl.h>
  #include <sys/prctl.h>
  
  #ifndef ARCH_SET_NOPTI
  #define ARCH_SET_NOPTI 0x1022
  #endif
  
  int main(int argc, char **argv)
  {
          arch_prctl(ARCH_SET_NOPTI, 1);
          argv++;
          return execvp(argv[0], argv);
  }

I have not yet run it on real hardware. Before trying to go a bit further
I'd like to know if such an approach is acceptable or if I'm doing anything
stupid and looking in the wrong direction.

Thanks!
Willy


Willy Tarreau (4):
  x86/thread_info: add TIF_NOPTI to disable PTI per task
  x86/arch_prctl: add ARCH_GET_NOPTI and ARCH_SET_NOPTI to
    enable/disable PTI
  x86/pti: don't mark the user PGD with _PAGE_NX.
  x86/entry/pti: don't switch PGD on tasks holding flag TIF_NOPTI

 arch/x86/entry/calling.h           | 23 +++++++++++++++++++++++
 arch/x86/include/asm/thread_info.h |  8 ++++++++
 arch/x86/include/uapi/asm/prctl.h  |  3 +++
 arch/x86/kernel/process_64.c       | 24 ++++++++++++++++++++++++
 arch/x86/mm/pti.c                  |  2 ++
 5 files changed, 60 insertions(+)

-- 
1.7.12.1

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

end of thread, other threads:[~2018-01-09 21:57 UTC | newest]

Thread overview: 53+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-08 16:12 [PATCH RFC 0/4] Per-task PTI activation Willy Tarreau
2018-01-08 16:12 ` [PATCH RFC 1/4] x86/thread_info: add TIF_NOPTI to disable PTI per task Willy Tarreau
2018-01-08 16:57   ` Thomas Gleixner
2018-01-08 17:03     ` Willy Tarreau
2018-01-08 17:14       ` Ingo Molnar
2018-01-08 16:12 ` [PATCH RFC 2/4] x86/arch_prctl: add ARCH_GET_NOPTI and ARCH_SET_NOPTI to enable/disable PTI Willy Tarreau
2018-01-08 16:49   ` Peter Zijlstra
2018-01-08 16:56     ` Willy Tarreau
2018-01-08 17:02   ` Thomas Gleixner
2018-01-08 17:10     ` Willy Tarreau
2018-01-08 17:17     ` Ingo Molnar
2018-01-08 17:26       ` Thomas Gleixner
2018-01-08 17:46         ` Ingo Molnar
2018-01-08 17:05   ` Ingo Molnar
2018-01-08 17:19     ` Peter Zijlstra
2018-01-08 17:26       ` Ingo Molnar
2018-01-08 17:50   ` Borislav Petkov
2018-01-08 17:54   ` Linus Torvalds
2018-01-08 18:22     ` Willy Tarreau
2018-01-08 20:49       ` Thomas Gleixner
2018-01-08 21:03         ` Willy Tarreau
2018-01-08 20:35     ` Willy Tarreau
2018-01-08 16:12 ` [PATCH RFC 3/4] x86/pti: don't mark the user PGD with _PAGE_NX Willy Tarreau
2018-01-08 17:03   ` Dave Hansen
2018-01-08 17:17     ` Willy Tarreau
2018-01-08 17:23       ` Dave Hansen
2018-01-08 17:30         ` Peter Zijlstra
2018-01-08 17:49           ` Willy Tarreau
2018-01-08 17:21     ` Ingo Molnar
2018-01-08 23:05     ` Andy Lutomirski
2018-01-08 23:09       ` Kees Cook
2018-01-09  4:22       ` Willy Tarreau
2018-01-08 17:05   ` Thomas Gleixner
2018-01-08 17:28     ` Dave Hansen
2018-01-08 17:50       ` Ingo Molnar
2018-01-08 18:25         ` Alan Cox
2018-01-08 18:35           ` Ingo Molnar
2018-01-08 18:35           ` Linus Torvalds
2018-01-08 18:44         ` Dave Hansen
2018-01-08 16:12 ` [PATCH RFC 4/4] x86/entry/pti: don't switch PGD on tasks holding flag TIF_NOPTI Willy Tarreau
2018-01-08 17:11   ` Ingo Molnar
2018-01-08 17:20   ` Dave Hansen
2018-01-08 18:12     ` Willy Tarreau
2018-01-08 23:01   ` Andy Lutomirski
2018-01-08 16:59 ` [PATCH RFC 0/4] Per-task PTI activation Dave Hansen
2018-01-08 17:06   ` Willy Tarreau
2018-01-08 17:17     ` Dave Hansen
2018-01-08 17:13   ` Ingo Molnar
2018-01-09 15:31 ` Eric W. Biederman
2018-01-09 16:02   ` Willy Tarreau
2018-01-09 18:11     ` Zhi Wang
2018-01-09 21:07     ` Eric W. Biederman
2018-01-09 21:57       ` Willy Tarreau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox