linux/arch/powerpc/include/asm/book3s/64/hash-pkey.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2#ifndef _ASM_POWERPC_BOOK3S_64_HASH_PKEY_H
   3#define _ASM_POWERPC_BOOK3S_64_HASH_PKEY_H
   4
   5/*  We use key 3 for KERNEL */
   6#define HASH_DEFAULT_KERNEL_KEY (HPTE_R_KEY_BIT0 | HPTE_R_KEY_BIT1)
   7
   8static inline u64 hash__vmflag_to_pte_pkey_bits(u64 vm_flags)
   9{
  10        return (((vm_flags & VM_PKEY_BIT0) ? H_PTE_PKEY_BIT0 : 0x0UL) |
  11                ((vm_flags & VM_PKEY_BIT1) ? H_PTE_PKEY_BIT1 : 0x0UL) |
  12                ((vm_flags & VM_PKEY_BIT2) ? H_PTE_PKEY_BIT2 : 0x0UL) |
  13                ((vm_flags & VM_PKEY_BIT3) ? H_PTE_PKEY_BIT3 : 0x0UL) |
  14                ((vm_flags & VM_PKEY_BIT4) ? H_PTE_PKEY_BIT4 : 0x0UL));
  15}
  16
  17static inline u64 pte_to_hpte_pkey_bits(u64 pteflags, unsigned long flags)
  18{
  19        unsigned long pte_pkey;
  20
  21        pte_pkey = (((pteflags & H_PTE_PKEY_BIT4) ? HPTE_R_KEY_BIT4 : 0x0UL) |
  22                    ((pteflags & H_PTE_PKEY_BIT3) ? HPTE_R_KEY_BIT3 : 0x0UL) |
  23                    ((pteflags & H_PTE_PKEY_BIT2) ? HPTE_R_KEY_BIT2 : 0x0UL) |
  24                    ((pteflags & H_PTE_PKEY_BIT1) ? HPTE_R_KEY_BIT1 : 0x0UL) |
  25                    ((pteflags & H_PTE_PKEY_BIT0) ? HPTE_R_KEY_BIT0 : 0x0UL));
  26
  27        if (mmu_has_feature(MMU_FTR_BOOK3S_KUAP) ||
  28            mmu_has_feature(MMU_FTR_BOOK3S_KUEP)) {
  29                if ((pte_pkey == 0) && (flags & HPTE_USE_KERNEL_KEY))
  30                        return HASH_DEFAULT_KERNEL_KEY;
  31        }
  32
  33        return pte_pkey;
  34}
  35
  36static inline u16 hash__pte_to_pkey_bits(u64 pteflags)
  37{
  38        return (((pteflags & H_PTE_PKEY_BIT4) ? 0x10 : 0x0UL) |
  39                ((pteflags & H_PTE_PKEY_BIT3) ? 0x8 : 0x0UL) |
  40                ((pteflags & H_PTE_PKEY_BIT2) ? 0x4 : 0x0UL) |
  41                ((pteflags & H_PTE_PKEY_BIT1) ? 0x2 : 0x0UL) |
  42                ((pteflags & H_PTE_PKEY_BIT0) ? 0x1 : 0x0UL));
  43}
  44
  45#endif
  46