1 // SPDX-License-Identifier: MIT
3 * Copyright © 2021 Intel Corporation
6 #include <linux/kernel.h>
7 #include <linux/moduleparam.h>
8 #include <linux/slab.h>
9 #include <linux/string.h>
12 #include "i915_mitigations.h"
14 static unsigned long mitigations __read_mostly = ~0UL;
20 static const char * const names[] = {
21 [CLEAR_RESIDUALS] = "residuals",
24 bool i915_mitigate_clear_residuals(void)
26 return READ_ONCE(mitigations) & BIT(CLEAR_RESIDUALS);
29 static int mitigations_set(const char *val, const struct kernel_param *kp)
31 unsigned long new = ~0UL;
32 char *str, *sep, *tok;
36 BUILD_BUG_ON(ARRAY_SIZE(names) >= BITS_PER_TYPE(mitigations));
38 str = kstrdup(val, GFP_KERNEL);
42 for (sep = str; (tok = strsep(&sep, ","));) {
46 /* Be tolerant of leading/trailing whitespace */
52 if (!strcmp(tok, "auto"))
56 if (!strcmp(tok, "off"))
65 if (!strncmp(tok, "no", 2)) {
73 for (i = 0; i < ARRAY_SIZE(names); i++) {
74 if (!strcmp(tok, names[i])) {
82 if (i == ARRAY_SIZE(names)) {
83 pr_err("Bad \"%s.mitigations=%s\", '%s' is unknown\n",
84 DRIVER_NAME, val, tok);
93 WRITE_ONCE(mitigations, new);
97 static int mitigations_get(char *buffer, const struct kernel_param *kp)
99 unsigned long local = READ_ONCE(mitigations);
104 return scnprintf(buffer, PAGE_SIZE, "%s\n", "off");
106 if (local & BIT(BITS_PER_LONG - 1)) {
107 count = scnprintf(buffer, PAGE_SIZE, "%s,", "auto");
114 for (i = 0; i < ARRAY_SIZE(names); i++) {
115 if ((local & BIT(i)) != enable)
118 count += scnprintf(buffer + count, PAGE_SIZE - count,
119 "%s%s,", enable ? "" : "!", names[i]);
122 buffer[count - 1] = '\n';
126 static const struct kernel_param_ops ops = {
127 .set = mitigations_set,
128 .get = mitigations_get,
131 module_param_cb_unsafe(mitigations, &ops, NULL, 0600);
132 MODULE_PARM_DESC(mitigations,
133 "Selectively enable security mitigations for all Intel® GPUs in the system.\n"
135 " auto -- enables all mitigations required for the platform [default]\n"
136 " off -- disables all mitigations\n"
138 "Individual mitigations can be enabled by passing a comma-separated string,\n"
139 "e.g. mitigations=residuals to enable only clearing residuals or\n"
140 "mitigations=auto,noresiduals to disable only the clear residual mitigation.\n"
141 "Either '!' or 'no' may be used to switch from enabling the mitigation to\n"
144 "Active mitigations for Ivybridge, Baytrail, Haswell:\n"
145 " residuals -- clear all thread-local registers between contexts"