~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/x86/include/asm/kfence.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /*
  3  * x86 KFENCE support.
  4  *
  5  * Copyright (C) 2020, Google LLC.
  6  */
  7 
  8 #ifndef _ASM_X86_KFENCE_H
  9 #define _ASM_X86_KFENCE_H
 10 
 11 #ifndef MODULE
 12 
 13 #include <linux/bug.h>
 14 #include <linux/kfence.h>
 15 
 16 #include <asm/pgalloc.h>
 17 #include <asm/pgtable.h>
 18 #include <asm/set_memory.h>
 19 #include <asm/tlbflush.h>
 20 
 21 /* Force 4K pages for __kfence_pool. */
 22 static inline bool arch_kfence_init_pool(void)
 23 {
 24         unsigned long addr;
 25 
 26         for (addr = (unsigned long)__kfence_pool; is_kfence_address((void *)addr);
 27              addr += PAGE_SIZE) {
 28                 unsigned int level;
 29 
 30                 if (!lookup_address(addr, &level))
 31                         return false;
 32 
 33                 if (level != PG_LEVEL_4K)
 34                         set_memory_4k(addr, 1);
 35         }
 36 
 37         return true;
 38 }
 39 
 40 /* Protect the given page and flush TLB. */
 41 static inline bool kfence_protect_page(unsigned long addr, bool protect)
 42 {
 43         unsigned int level;
 44         pte_t *pte = lookup_address(addr, &level);
 45 
 46         if (WARN_ON(!pte || level != PG_LEVEL_4K))
 47                 return false;
 48 
 49         /*
 50          * We need to avoid IPIs, as we may get KFENCE allocations or faults
 51          * with interrupts disabled. Therefore, the below is best-effort, and
 52          * does not flush TLBs on all CPUs. We can tolerate some inaccuracy;
 53          * lazy fault handling takes care of faults after the page is PRESENT.
 54          */
 55 
 56         if (protect)
 57                 set_pte(pte, __pte(pte_val(*pte) & ~_PAGE_PRESENT));
 58         else
 59                 set_pte(pte, __pte(pte_val(*pte) | _PAGE_PRESENT));
 60 
 61         /*
 62          * Flush this CPU's TLB, assuming whoever did the allocation/free is
 63          * likely to continue running on this CPU.
 64          */
 65         preempt_disable();
 66         flush_tlb_one_kernel(addr);
 67         preempt_enable();
 68         return true;
 69 }
 70 
 71 #endif /* !MODULE */
 72 
 73 #endif /* _ASM_X86_KFENCE_H */
 74 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php