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