gsgx_fsgsbase.c 919 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * (C) Copyright 2015 Intel Corporation
  3. * Author: Chia-Che Tsai <chiache-che.tsai@intel.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; version 2
  8. * of the License.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/version.h>
  13. #include <linux/highmem.h>
  14. #include <linux/miscdevice.h>
  15. #include <linux/module.h>
  16. #include <linux/security.h>
  17. #include <asm/tlbflush.h>
  18. #include "gsgx.h"
  19. static void __enable_fsgsbase(void *v)
  20. {
  21. #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
  22. write_cr4(read_cr4() | X86_CR4_FSGSBASE);
  23. #else
  24. cr4_set_bits(X86_CR4_FSGSBASE);
  25. __write_cr4(__read_cr4() | X86_CR4_FSGSBASE);
  26. #endif
  27. }
  28. int gsgx_open(struct inode *inode, struct file *file)
  29. {
  30. __enable_fsgsbase(NULL);
  31. smp_call_function(__enable_fsgsbase, NULL, 1);
  32. return 0;
  33. }