190cbac0eSChristophe Leroy /* SPDX-License-Identifier: GPL-2.0 */ 290cbac0eSChristophe Leroy /* 390cbac0eSChristophe Leroy * powerpc KFENCE support. 490cbac0eSChristophe Leroy * 590cbac0eSChristophe Leroy * Copyright (C) 2020 CS GROUP France 690cbac0eSChristophe Leroy */ 790cbac0eSChristophe Leroy 890cbac0eSChristophe Leroy #ifndef __ASM_POWERPC_KFENCE_H 990cbac0eSChristophe Leroy #define __ASM_POWERPC_KFENCE_H 1090cbac0eSChristophe Leroy 1190cbac0eSChristophe Leroy #include <linux/mm.h> 1290cbac0eSChristophe Leroy #include <asm/pgtable.h> 1390cbac0eSChristophe Leroy 14*a5edf981SNicholas Miehlbradt #ifdef CONFIG_PPC64_ELF_ABI_V1 15*a5edf981SNicholas Miehlbradt #define ARCH_FUNC_PREFIX "." 16*a5edf981SNicholas Miehlbradt #endif 17*a5edf981SNicholas Miehlbradt 1890cbac0eSChristophe Leroy static inline bool arch_kfence_init_pool(void) 1990cbac0eSChristophe Leroy { 2090cbac0eSChristophe Leroy return true; 2190cbac0eSChristophe Leroy } 2290cbac0eSChristophe Leroy 23*a5edf981SNicholas Miehlbradt #ifdef CONFIG_PPC64 24*a5edf981SNicholas Miehlbradt static inline bool kfence_protect_page(unsigned long addr, bool protect) 25*a5edf981SNicholas Miehlbradt { 26*a5edf981SNicholas Miehlbradt struct page *page = virt_to_page(addr); 27*a5edf981SNicholas Miehlbradt 28*a5edf981SNicholas Miehlbradt __kernel_map_pages(page, 1, !protect); 29*a5edf981SNicholas Miehlbradt 30*a5edf981SNicholas Miehlbradt return true; 31*a5edf981SNicholas Miehlbradt } 32*a5edf981SNicholas Miehlbradt #else 3390cbac0eSChristophe Leroy static inline bool kfence_protect_page(unsigned long addr, bool protect) 3490cbac0eSChristophe Leroy { 3590cbac0eSChristophe Leroy pte_t *kpte = virt_to_kpte(addr); 3690cbac0eSChristophe Leroy 3790cbac0eSChristophe Leroy if (protect) { 3890cbac0eSChristophe Leroy pte_update(&init_mm, addr, kpte, _PAGE_PRESENT, 0, 0); 3990cbac0eSChristophe Leroy flush_tlb_kernel_range(addr, addr + PAGE_SIZE); 4090cbac0eSChristophe Leroy } else { 4190cbac0eSChristophe Leroy pte_update(&init_mm, addr, kpte, 0, _PAGE_PRESENT, 0); 4290cbac0eSChristophe Leroy } 4390cbac0eSChristophe Leroy 4490cbac0eSChristophe Leroy return true; 4590cbac0eSChristophe Leroy } 46*a5edf981SNicholas Miehlbradt #endif 4790cbac0eSChristophe Leroy 4890cbac0eSChristophe Leroy #endif /* __ASM_POWERPC_KFENCE_H */ 49