Print this page
OS-7125 Need mitigation of L1TF (CVE-2018-3646)
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/i86pc/os/cpuid.c
          +++ new/usr/src/uts/i86pc/os/cpuid.c
↓ open down ↓ 2112 lines elided ↑ open up ↑
2113 2113  
2114 2114          cpi->cpi_chipid =
2115 2115              cpi->cpi_procnodeid / cpi->cpi_procnodes_per_pkg;
2116 2116  
2117 2117          cpi->cpi_ncore_bits = coreidsz;
2118 2118          cpi->cpi_nthread_bits = ddi_fls(cpi->cpi_ncpu_per_chip /
2119 2119              cpi->cpi_ncore_per_chip);
2120 2120  }
2121 2121  
2122 2122  static void
     2123 +spec_l1d_flush_noop(void)
     2124 +{
     2125 +}
     2126 +
     2127 +static void
     2128 +spec_l1d_flush_msr(void)
     2129 +{
     2130 +        wrmsr(MSR_IA32_FLUSH_CMD, IA32_FLUSH_CMD_L1D);
     2131 +}
     2132 +
     2133 +void (*spec_l1d_flush)(void) = spec_l1d_flush_noop;
     2134 +
     2135 +static void
2123 2136  cpuid_scan_security(cpu_t *cpu, uchar_t *featureset)
2124 2137  {
2125 2138          struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
2126 2139  
2127 2140          if (cpi->cpi_vendor == X86_VENDOR_AMD &&
2128 2141              cpi->cpi_xmaxeax >= CPUID_LEAF_EXT_8) {
2129 2142                  if (cpi->cpi_extd[8].cp_ebx & CPUID_AMD_EBX_IBPB)
2130 2143                          add_x86_feature(featureset, X86FSET_IBPB);
2131 2144                  if (cpi->cpi_extd[8].cp_ebx & CPUID_AMD_EBX_IBRS)
2132 2145                          add_x86_feature(featureset, X86FSET_IBRS);
↓ open down ↓ 64 lines elided ↑ open up ↑
2197 2210                          no_trap();
2198 2211                  }
2199 2212  #endif  /* !__xpv */
2200 2213  
2201 2214                  if (ecp->cp_edx & CPUID_INTC_EDX_7_0_SSBD)
2202 2215                          add_x86_feature(featureset, X86FSET_SSBD);
2203 2216  
2204 2217                  if (ecp->cp_edx & CPUID_INTC_EDX_7_0_FLUSH_CMD)
2205 2218                          add_x86_feature(featureset, X86FSET_FLUSH_CMD);
2206 2219          }
     2220 +
     2221 +        if (cpu->cpu_id != 0)
     2222 +                return;
     2223 +
     2224 +        /*
     2225 +         * We're the boot CPU, so let's figure out our L1TF status.
     2226 +         *
     2227 +         * First, if this is a RDCL_NO CPU, then we are not vulnerable: we don't
     2228 +         * need to exclude with ht_acquire(), and we don't need to flush.
     2229 +         */
     2230 +        if (is_x86_feature(featureset, X86FSET_RDCL_NO)) {
     2231 +                extern int ht_exclusion;
     2232 +                ht_exclusion = 0;
     2233 +                spec_l1d_flush = spec_l1d_flush_noop;
     2234 +                membar_producer();
     2235 +                return;
     2236 +        }
     2237 +
     2238 +        /*
     2239 +         * If HT is enabled, we will need HT exclusion, as well as the flush on
     2240 +         * VM entry.  If HT isn't enabled, we still need at least the flush for
     2241 +         * the L1TF sequential case.
     2242 +         *
     2243 +         * However, if X86FSET_L1D_VM_NO is set, we're most likely running
     2244 +         * inside a VM ourselves, and we don't need the flush.
     2245 +         *
     2246 +         * If we don't have the FLUSH_CMD available at all, we'd better just
     2247 +         * hope HT is disabled.
     2248 +         */
     2249 +        if (is_x86_feature(featureset, X86FSET_FLUSH_CMD) &&
     2250 +            !is_x86_feature(featureset, X86FSET_L1D_VM_NO)) {
     2251 +                spec_l1d_flush = spec_l1d_flush_msr;
     2252 +        } else {
     2253 +                spec_l1d_flush = spec_l1d_flush_noop;
     2254 +        }
     2255 +
     2256 +        membar_producer();
2207 2257  }
2208 2258  
2209 2259  /*
2210 2260   * Setup XFeature_Enabled_Mask register. Required by xsave feature.
2211 2261   */
2212 2262  void
2213 2263  setup_xfem(void)
2214 2264  {
2215 2265          uint64_t flags = XFEATURE_LEGACY_FP;
2216 2266  
↓ open down ↓ 4426 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX