Deleted Added
full compact
cpu_machdep.c (361561) cpu_machdep.c (362383)
1/*-
2 * Copyright (c) 2003 Peter Wemm.
3 * Copyright (c) 1992 Terrence R. Lambert.
4 * Copyright (c) 1982, 1987, 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * William Jolitz.

--- 25 unchanged lines hidden (view full) ---

34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91
39 */
40
41#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2003 Peter Wemm.
3 * Copyright (c) 1992 Terrence R. Lambert.
4 * Copyright (c) 1982, 1987, 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * William Jolitz.

--- 25 unchanged lines hidden (view full) ---

34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91
39 */
40
41#include <sys/cdefs.h>
42__FBSDID("$FreeBSD: stable/11/sys/x86/x86/cpu_machdep.c 361561 2020-05-27 18:55:24Z kib $");
42__FBSDID("$FreeBSD: stable/11/sys/x86/x86/cpu_machdep.c 362383 2020-06-19 13:48:23Z kib $");
43
44#include "opt_atpic.h"
45#include "opt_compat.h"
46#include "opt_cpu.h"
47#include "opt_ddb.h"
48#include "opt_inet.h"
49#include "opt_isa.h"
50#include "opt_kdb.h"

--- 1308 unchanged lines hidden (view full) ---

1359 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0,
1360 sysctl_taa_state_handler, "A",
1361 "TAA Mitigation state");
1362
1363int __read_frequently cpu_flush_rsb_ctxsw;
1364SYSCTL_INT(_machdep_mitigations, OID_AUTO, flush_rsb_ctxsw,
1365 CTLFLAG_RW | CTLFLAG_NOFETCH, &cpu_flush_rsb_ctxsw, 0,
1366 "Flush Return Stack Buffer on context switch");
43
44#include "opt_atpic.h"
45#include "opt_compat.h"
46#include "opt_cpu.h"
47#include "opt_ddb.h"
48#include "opt_inet.h"
49#include "opt_isa.h"
50#include "opt_kdb.h"

--- 1308 unchanged lines hidden (view full) ---

1359 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0,
1360 sysctl_taa_state_handler, "A",
1361 "TAA Mitigation state");
1362
1363int __read_frequently cpu_flush_rsb_ctxsw;
1364SYSCTL_INT(_machdep_mitigations, OID_AUTO, flush_rsb_ctxsw,
1365 CTLFLAG_RW | CTLFLAG_NOFETCH, &cpu_flush_rsb_ctxsw, 0,
1366 "Flush Return Stack Buffer on context switch");
1367
1368SYSCTL_NODE(_machdep_mitigations, OID_AUTO, rngds,
1369 CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
1370 "MCU Optimization, disable RDSEED mitigation");
1371
1372int x86_rngds_mitg_enable = 1;
1373void
1374x86_rngds_mitg_recalculate(bool all_cpus)
1375{
1376 if ((cpu_stdext_feature3 & CPUID_STDEXT3_MCUOPT) == 0)
1377 return;
1378 x86_msr_op(MSR_IA32_MCU_OPT_CTRL,
1379 (x86_rngds_mitg_enable ? MSR_OP_OR : MSR_OP_ANDNOT) |
1380 (all_cpus ? MSR_OP_RENDEZVOUS : MSR_OP_LOCAL),
1381 IA32_RNGDS_MITG_DIS);
1382}
1383
1384static int
1385sysctl_rngds_mitg_enable_handler(SYSCTL_HANDLER_ARGS)
1386{
1387 int error, val;
1388
1389 val = x86_rngds_mitg_enable;
1390 error = sysctl_handle_int(oidp, &val, 0, req);
1391 if (error != 0 || req->newptr == NULL)
1392 return (error);
1393 x86_rngds_mitg_enable = val;
1394 x86_rngds_mitg_recalculate(true);
1395 return (0);
1396}
1397SYSCTL_PROC(_machdep_mitigations_rngds, OID_AUTO, enable, CTLTYPE_INT |
1398 CTLFLAG_RWTUN | CTLFLAG_NOFETCH | CTLFLAG_MPSAFE, NULL, 0,
1399 sysctl_rngds_mitg_enable_handler, "I",
1400 "MCU Optimization, disabling RDSEED mitigation control "
1401 "(0 - mitigation disabled (RDSEED optimized), 1 - mitigation enabled");
1402
1403static int
1404sysctl_rngds_state_handler(SYSCTL_HANDLER_ARGS)
1405{
1406 const char *state;
1407
1408 if ((cpu_stdext_feature3 & CPUID_STDEXT3_MCUOPT) == 0) {
1409 state = "Not applicable";
1410 } else if (x86_rngds_mitg_enable == 0) {
1411 state = "RDSEED not serialized";
1412 } else {
1413 state = "Mitigated";
1414 }
1415 return (SYSCTL_OUT(req, state, strlen(state)));
1416}
1417SYSCTL_PROC(_machdep_mitigations_rngds, OID_AUTO, state,
1418 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0,
1419 sysctl_rngds_state_handler, "A",
1420 "MCU Optimization state");