Print this page
11859 need swapgs mitigation
Reviewed by: Robert Mustacchi <rm@fingolfin.org>
Reviewed by: Dan McDonald <danmcd@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@fingolfin.org>

@@ -22,10 +22,14 @@
 /*
  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
+/*
+ * Copyright 2019 Joyent, Inc.
+ */
+
 #ifndef _AMD64_SYS_PRIVREGS_H
 #define _AMD64_SYS_PRIVREGS_H
 
 #include <sys/ccompile.h>
 

@@ -204,22 +208,28 @@
         __SAVE_REGS;                            \
         cmpw    $KCS_SEL, REGOFF_CS(%rsp);      \
         je      6f;                             \
         movq    $0, REGOFF_SAVFP(%rsp);         \
         SWAPGS;                                 \
-6:      CLEAN_CS
+6:      lfence; /* swapgs mitigation */         \
+        CLEAN_CS
 
 #define INTR_POP                        \
         leaq    sys_lcall32(%rip), %r11;\
         cmpq    %r11, REGOFF_RIP(%rsp); \
         __RESTORE_REGS;                 \
         je      5f;                     \
         cmpw    $KCS_SEL, REGOFF_CS(%rsp);\
         je      8f;                     \
 5:      SWAPGS;                         \
-8:      addq    $REGOFF_RIP, %rsp
+8:      lfence; /* swapgs mitigation */ \
+        addq    $REGOFF_RIP, %rsp
 
+/*
+ * No need for swapgs mitigation: it's unconditional, and we're heading
+ * back to userspace.
+ */
 #define USER_POP                        \
         __RESTORE_REGS;                 \
         SWAPGS;                         \
         addq    $REGOFF_RIP, %rsp       /* Adjust %rsp to prepare for iretq */