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>
11 #include "i915_driver.h"
13 #include "i915_mitigations.h"
15 static unsigned long mitigations __read_mostly = ~0UL;
21 static const char * const names[] = {
22 [CLEAR_RESIDUALS] = "residuals",
25 bool i915_mitigate_clear_residuals(void)
27 return READ_ONCE(mitigations) & BIT(CLEAR_RESIDUALS);
30 static int mitigations_set(const char *val, const struct kernel_param *kp)
32 unsigned long new = ~0UL;
33 char *str, *sep, *tok;
37 BUILD_BUG_ON(ARRAY_SIZE(names) >= BITS_PER_TYPE(mitigations));
39 str = kstrdup(val, GFP_KERNEL);
43 for (sep = str; (tok = strsep(&sep, ","));) {
47 /* Be tolerant of leading/trailing whitespace */
53 if (!strcmp(tok, "auto"))
57 if (!strcmp(tok, "off"))
66 if (!strncmp(tok, "no", 2)) {
74 for (i = 0; i < ARRAY_SIZE(names); i++) {
75 if (!strcmp(tok, names[i])) {
83 if (i == ARRAY_SIZE(names)) {
84 pr_err("Bad \"%s.mitigations=%s\", '%s' is unknown\n",
85 DRIVER_NAME, val, tok);
94 WRITE_ONCE(mitigations, new);
98 static int mitigations_get(char *buffer, const struct kernel_param *kp)
100 unsigned long local = READ_ONCE(mitigations);
105 return scnprintf(buffer, PAGE_SIZE, "%s\n", "off");
107 if (local & BIT(BITS_PER_LONG - 1)) {
108 count = scnprintf(buffer, PAGE_SIZE, "%s,", "auto");
115 for (i = 0; i < ARRAY_SIZE(names); i++) {
116 if ((local & BIT(i)) != enable)
119 count += scnprintf(buffer + count, PAGE_SIZE - count,
120 "%s%s,", enable ? "" : "!", names[i]);
123 buffer[count - 1] = '\n';
127 static const struct kernel_param_ops ops = {
128 .set = mitigations_set,
129 .get = mitigations_get,
132 module_param_cb_unsafe(mitigations, &ops, NULL, 0600);
133 MODULE_PARM_DESC(mitigations,
134 "Selectively enable security mitigations for all Intel® GPUs in the system.\n"
136 " auto -- enables all mitigations required for the platform [default]\n"
137 " off -- disables all mitigations\n"
139 "Individual mitigations can be enabled by passing a comma-separated string,\n"
140 "e.g. mitigations=residuals to enable only clearing residuals or\n"
141 "mitigations=auto,noresiduals to disable only the clear residual mitigation.\n"
142 "Either '!' or 'no' may be used to switch from enabling the mitigation to\n"
145 "Active mitigations for Ivybridge, Baytrail, Haswell:\n"
146 " residuals -- clear all thread-local registers between contexts"