Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x86 Extend the AMD NONARCH method to family 17h. Th...



details:   https://anonhg.NetBSD.org/src/rev/107aa09b2ee5
branches:  trunk
changeset: 319240:107aa09b2ee5
user:      maxv <maxv%NetBSD.org@localhost>
date:      Tue May 22 17:14:46 2018 +0000

description:
Extend the AMD NONARCH method to family 17h. The AMD spec states that for
17h care must be taken when handling sibling threads.

The concern is that if we have a protected two-thread process running on
two siblings, and context switch one thread to another unprotected thread,
disabling the SSB protection on one logical core will disable SSB on its
sibling too (which is still running the protected thread).

All of that doesn't matter to us, because the SSB value we set is
system-wide, not per-process.

diffstat:

 sys/arch/x86/include/specialreg.h |   3 +-
 sys/arch/x86/x86/spectre.c        |  53 ++++++++++++++++++++------------------
 2 files changed, 30 insertions(+), 26 deletions(-)

diffs (131 lines):

diff -r 7c51a242ec23 -r 107aa09b2ee5 sys/arch/x86/include/specialreg.h
--- a/sys/arch/x86/include/specialreg.h Tue May 22 16:44:42 2018 +0000
+++ b/sys/arch/x86/include/specialreg.h Tue May 22 17:14:46 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: specialreg.h,v 1.123 2018/05/22 10:20:04 maxv Exp $    */
+/*     $NetBSD: specialreg.h,v 1.124 2018/05/22 17:14:46 maxv Exp $    */
 
 /*-
  * Copyright (c) 1991 The Regents of the University of California.
@@ -860,6 +860,7 @@
 #define        LS_CFG_DIS_LS2_SQUISH   0x02000000
 #define        LS_CFG_DIS_SSB_F15H     0x0040000000000000ULL
 #define        LS_CFG_DIS_SSB_F16H     0x0000000200000000ULL
+#define        LS_CFG_DIS_SSB_F17H     0x0000000000000400ULL
 
 #define MSR_IC_CFG     0xc0011021
 #define        IC_CFG_DIS_SEQ_PREFETCH 0x00000800
diff -r 7c51a242ec23 -r 107aa09b2ee5 sys/arch/x86/x86/spectre.c
--- a/sys/arch/x86/x86/spectre.c        Tue May 22 16:44:42 2018 +0000
+++ b/sys/arch/x86/x86/spectre.c        Tue May 22 17:14:46 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: spectre.c,v 1.17 2018/05/22 16:44:42 maxv Exp $        */
+/*     $NetBSD: spectre.c,v 1.18 2018/05/22 17:14:46 maxv Exp $        */
 
 /*
  * Copyright (c) 2018 NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spectre.c,v 1.17 2018/05/22 16:44:42 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spectre.c,v 1.18 2018/05/22 17:14:46 maxv Exp $");
 
 #include "opt_spectre.h"
 
@@ -62,7 +62,8 @@
        V4_MITIGATION_INTEL_SSBD,
        V4_MITIGATION_INTEL_SSB_NO,
        V4_MITIGATION_AMD_NONARCH_F15H,
-       V4_MITIGATION_AMD_NONARCH_F16H
+       V4_MITIGATION_AMD_NONARCH_F16H,
+       V4_MITIGATION_AMD_NONARCH_F17H
 };
 
 static enum v2_mitigation v2_mitigation_method = V2_MITIGATION_NONE;
@@ -381,6 +382,7 @@
                        break;
                case V4_MITIGATION_AMD_NONARCH_F15H:
                case V4_MITIGATION_AMD_NONARCH_F16H:
+               case V4_MITIGATION_AMD_NONARCH_F17H:
                        strlcat(name, "[AMD NONARCH]", sizeof(name));
                        break;
                }
@@ -426,6 +428,9 @@
                case 0x16:
                        v4_mitigation_method = V4_MITIGATION_AMD_NONARCH_F16H;
                        return;
+               case 0x17:
+                       v4_mitigation_method = V4_MITIGATION_AMD_NONARCH_F17H;
+                       return;
                default:
                        break;
                }
@@ -437,40 +442,37 @@
 static void
 mitigation_v4_apply_cpu(bool enabled)
 {
-       uint64_t msr;
+       uint64_t msr, msrval = 0, msrbit = 0;
 
        switch (v4_mitigation_method) {
        case V4_MITIGATION_NONE:
        case V4_MITIGATION_INTEL_SSB_NO:
                panic("impossible");
        case V4_MITIGATION_INTEL_SSBD:
-               msr = rdmsr(MSR_IA32_SPEC_CTRL);
-               if (enabled) {
-                       msr |= IA32_SPEC_CTRL_SSBD;
-               } else {
-                       msr &= ~IA32_SPEC_CTRL_SSBD;
-               }
-               wrmsr(MSR_IA32_SPEC_CTRL, msr);
+               msrval = MSR_IA32_SPEC_CTRL;
+               msrbit = IA32_SPEC_CTRL_SSBD;
                break;
        case V4_MITIGATION_AMD_NONARCH_F15H:
-               msr = rdmsr(MSR_LS_CFG);
-               if (enabled) {
-                       msr |= LS_CFG_DIS_SSB_F15H;
-               } else {
-                       msr &= ~LS_CFG_DIS_SSB_F15H;
-               }
-               wrmsr(MSR_LS_CFG, msr);
+               msrval = MSR_LS_CFG;
+               msrbit = LS_CFG_DIS_SSB_F15H;
                break;
        case V4_MITIGATION_AMD_NONARCH_F16H:
-               msr = rdmsr(MSR_LS_CFG);
-               if (enabled) {
-                       msr |= LS_CFG_DIS_SSB_F16H;
-               } else {
-                       msr &= ~LS_CFG_DIS_SSB_F16H;
-               }
-               wrmsr(MSR_LS_CFG, msr);
+               msrval = MSR_LS_CFG;
+               msrbit = LS_CFG_DIS_SSB_F16H;
+               break;
+       case V4_MITIGATION_AMD_NONARCH_F17H:
+               msrval = MSR_LS_CFG;
+               msrbit = LS_CFG_DIS_SSB_F17H;
                break;
        }
+
+       msr = rdmsr(msrval);
+       if (enabled) {
+               msr |= msrbit;
+       } else {
+               msr &= ~msrbit;
+       }
+       wrmsr(msrval, msr);
 }
 
 static void
@@ -512,6 +514,7 @@
        case V4_MITIGATION_INTEL_SSBD:
        case V4_MITIGATION_AMD_NONARCH_F15H:
        case V4_MITIGATION_AMD_NONARCH_F16H:
+       case V4_MITIGATION_AMD_NONARCH_F17H:
                printf("[+] %s SpectreV4 Mitigation...",
                    enabled ? "Enabling" : "Disabling");
                xc = xc_broadcast(0, mitigation_v4_change_cpu,



Home | Main Index | Thread Index | Old Index