lkml.org 
[lkml]   [2017]   [Nov]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH 25/30] x86, kaiser: add debugfs file to turn KAISER on/off at runtime
From
Date

From: Dave Hansen <dave.hansen@linux.intel.com>

We will use this in a few patches. Right now, it's not wired up
to do anything useful.

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Moritz Lipp <moritz.lipp@iaik.tugraz.at>
Cc: Daniel Gruss <daniel.gruss@iaik.tugraz.at>
Cc: Michael Schwarz <michael.schwarz@iaik.tugraz.at>
Cc: Richard Fellner <richard.fellner@student.tugraz.at>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Kees Cook <keescook@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: x86@kernel.org
---

b/arch/x86/mm/kaiser.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)

diff -puN arch/x86/mm/kaiser.c~kaiser-dynamic-debugfs arch/x86/mm/kaiser.c
--- a/arch/x86/mm/kaiser.c~kaiser-dynamic-debugfs 2017-11-08 10:45:39.690681369 -0800
+++ b/arch/x86/mm/kaiser.c 2017-11-08 10:45:39.693681369 -0800
@@ -18,6 +18,7 @@
#include <linux/string.h>
#include <linux/types.h>
#include <linux/bug.h>
+#include <linux/debugfs.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/spinlock.h>
@@ -446,3 +447,50 @@ void kaiser_remove_mapping(unsigned long
*/
__native_flush_tlb_global();
}
+
+int kaiser_enabled = 1;
+static ssize_t kaiser_enabled_read_file(struct file *file, char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ char buf[32];
+ unsigned int len;
+
+ len = sprintf(buf, "%d\n", kaiser_enabled);
+ return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+}
+
+static ssize_t kaiser_enabled_write_file(struct file *file,
+ const char __user *user_buf, size_t count, loff_t *ppos)
+{
+ char buf[32];
+ ssize_t len;
+ unsigned int enable;
+
+ len = min(count, sizeof(buf) - 1);
+ if (copy_from_user(buf, user_buf, len))
+ return -EFAULT;
+
+ buf[len] = '\0';
+ if (kstrtoint(buf, 0, &enable))
+ return -EINVAL;
+
+ if (enable > 1)
+ return -EINVAL;
+
+ WRITE_ONCE(kaiser_enabled, enable);
+ return count;
+}
+
+static const struct file_operations fops_kaiser_enabled = {
+ .read = kaiser_enabled_read_file,
+ .write = kaiser_enabled_write_file,
+ .llseek = default_llseek,
+};
+
+static int __init create_kaiser_enabled(void)
+{
+ debugfs_create_file("kaiser-enabled", S_IRUSR | S_IWUSR,
+ arch_debugfs_dir, NULL, &fops_kaiser_enabled);
+ return 0;
+}
+late_initcall(create_kaiser_enabled);
_
\
 
 \ /
  Last update: 2017-11-08 21:15    [W:0.259 / U:6.140 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site