linux/arch/x86/include/asm/kaiser.h
<<
>>
Prefs
   1#ifndef _ASM_X86_KAISER_H
   2#define _ASM_X86_KAISER_H
   3/*
   4 * Copyright(c) 2017 Intel Corporation. All rights reserved.
   5 *
   6 * This program is free software; you can redistribute it and/or modify
   7 * it under the terms of version 2 of the GNU General Public License as
   8 * published by the Free Software Foundation.
   9 *
  10 * This program is distributed in the hope that it will be useful, but
  11 * WITHOUT ANY WARRANTY; without even the implied warranty of
  12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13 * General Public License for more details.
  14 *
  15 * Based on work published here: https://github.com/IAIK/KAISER
  16 * Modified by Dave Hansen <dave.hansen@intel.com to actually work.
  17 */
  18
  19#define KAISER_SHADOW_PCID_ASID 1
  20
  21#define KAISER_PCP_ENABLED      (1<<0)
  22#define KAISER_PCP_PCID         (1<<1)
  23
  24#ifndef __ASSEMBLY__
  25
  26#ifdef CONFIG_PAGE_TABLE_ISOLATION
  27#include <linux/percpu.h>
  28
  29/**
  30 *  kaiser_add_mapping - map a kernel range into the user page tables
  31 *  @addr: the start address of the range
  32 *  @size: the size of the range
  33 *  @flags: The mapping flags of the pages
  34 *
  35 *  Use this on all data and code that need to be mapped into both
  36 *  copies of the page tables.  This includes the code that switches
  37 *  to/from userspace and all of the hardware structures that are
  38 *  virtually-addressed and needed in userspace like the interrupt
  39 *  table.
  40 */
  41extern int kaiser_add_mapping(unsigned long addr, unsigned long size,
  42                              pteval_t flags);
  43
  44/**
  45 *  kaiser_add_mapping_cpu_entry - map the cpu entry area
  46 *  @cpu: the CPU for which the entry area is being mapped
  47 */
  48extern void kaiser_add_mapping_cpu_entry(int cpu);
  49
  50/**
  51 *  kaiser_remove_mapping - remove a kernel mapping from the userpage tables
  52 *  @addr: the start address of the range
  53 *  @size: the size of the range
  54 */
  55extern void kaiser_remove_mapping(unsigned long start, unsigned long size);
  56
  57/**
  58 *  kaiser_init - Initialize the shadow mapping
  59 *
  60 *  Most parts of the shadow mapping can be mapped upon boot
  61 *  time.  Only per-process things like the thread stacks
  62 *  or a new LDT have to be mapped at runtime.  These boot-
  63 *  time mappings are permanent and never unmapped.
  64 */
  65extern void kaiser_init(void);
  66
  67extern bool is_kaiser_pgd(pgd_t *pgd);
  68
  69extern int kaiser_enabled;
  70static __always_inline bool kaiser_active(void)
  71{
  72        return __this_cpu_read(kaiser_enabled_pcp);
  73}
  74
  75#else
  76static inline void kaiser_add_mapping_cpu_entry(int cpu) {}
  77#endif
  78
  79#endif /* __ASSEMBLY__ */
  80
  81#endif /* _ASM_X86_KAISER_H */
  82