Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2016 ARM Ltd.
0004  */
0005 #ifndef __ASM_PGTABLE_PROT_H
0006 #define __ASM_PGTABLE_PROT_H
0007 
0008 #include <asm/memory.h>
0009 #include <asm/pgtable-hwdef.h>
0010 
0011 #include <linux/const.h>
0012 
0013 /*
0014  * Software defined PTE bits definition.
0015  */
0016 #define PTE_WRITE       (PTE_DBM)        /* same as DBM (51) */
0017 #define PTE_SWP_EXCLUSIVE   (_AT(pteval_t, 1) << 2)  /* only for swp ptes */
0018 #define PTE_DIRTY       (_AT(pteval_t, 1) << 55)
0019 #define PTE_SPECIAL     (_AT(pteval_t, 1) << 56)
0020 #define PTE_DEVMAP      (_AT(pteval_t, 1) << 57)
0021 #define PTE_PROT_NONE       (_AT(pteval_t, 1) << 58) /* only when !PTE_VALID */
0022 
0023 /*
0024  * This bit indicates that the entry is present i.e. pmd_page()
0025  * still points to a valid huge page in memory even if the pmd
0026  * has been invalidated.
0027  */
0028 #define PMD_PRESENT_INVALID (_AT(pteval_t, 1) << 59) /* only when !PMD_SECT_VALID */
0029 
0030 #ifndef __ASSEMBLY__
0031 
0032 #include <asm/cpufeature.h>
0033 #include <asm/pgtable-types.h>
0034 
0035 extern bool arm64_use_ng_mappings;
0036 
0037 #define _PROT_DEFAULT       (PTE_TYPE_PAGE | PTE_AF | PTE_SHARED)
0038 #define _PROT_SECT_DEFAULT  (PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S)
0039 
0040 #define PTE_MAYBE_NG        (arm64_use_ng_mappings ? PTE_NG : 0)
0041 #define PMD_MAYBE_NG        (arm64_use_ng_mappings ? PMD_SECT_NG : 0)
0042 
0043 /*
0044  * If we have userspace only BTI we don't want to mark kernel pages
0045  * guarded even if the system does support BTI.
0046  */
0047 #ifdef CONFIG_ARM64_BTI_KERNEL
0048 #define PTE_MAYBE_GP        (system_supports_bti() ? PTE_GP : 0)
0049 #else
0050 #define PTE_MAYBE_GP        0
0051 #endif
0052 
0053 #define PROT_DEFAULT        (_PROT_DEFAULT | PTE_MAYBE_NG)
0054 #define PROT_SECT_DEFAULT   (_PROT_SECT_DEFAULT | PMD_MAYBE_NG)
0055 
0056 #define PROT_DEVICE_nGnRnE  (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRnE))
0057 #define PROT_DEVICE_nGnRE   (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_DEVICE_nGnRE))
0058 #define PROT_NORMAL_NC      (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL_NC))
0059 #define PROT_NORMAL     (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL))
0060 #define PROT_NORMAL_TAGGED  (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL_TAGGED))
0061 
0062 #define PROT_SECT_DEVICE_nGnRE  (PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PMD_ATTRINDX(MT_DEVICE_nGnRE))
0063 #define PROT_SECT_NORMAL    (PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PMD_ATTRINDX(MT_NORMAL))
0064 #define PROT_SECT_NORMAL_EXEC   (PROT_SECT_DEFAULT | PMD_SECT_UXN | PMD_ATTRINDX(MT_NORMAL))
0065 
0066 #define _PAGE_DEFAULT       (_PROT_DEFAULT | PTE_ATTRINDX(MT_NORMAL))
0067 
0068 #define PAGE_KERNEL     __pgprot(PROT_NORMAL)
0069 #define PAGE_KERNEL_RO      __pgprot((PROT_NORMAL & ~PTE_WRITE) | PTE_RDONLY)
0070 #define PAGE_KERNEL_ROX     __pgprot((PROT_NORMAL & ~(PTE_WRITE | PTE_PXN)) | PTE_RDONLY)
0071 #define PAGE_KERNEL_EXEC    __pgprot(PROT_NORMAL & ~PTE_PXN)
0072 #define PAGE_KERNEL_EXEC_CONT   __pgprot((PROT_NORMAL & ~PTE_PXN) | PTE_CONT)
0073 
0074 #define PAGE_S2_MEMATTR(attr, has_fwb)                  \
0075     ({                              \
0076         u64 __val;                      \
0077         if (has_fwb)                        \
0078             __val = PTE_S2_MEMATTR(MT_S2_FWB_ ## attr); \
0079         else                            \
0080             __val = PTE_S2_MEMATTR(MT_S2_ ## attr);     \
0081         __val;                          \
0082      })
0083 
0084 #define PAGE_NONE       __pgprot(((_PAGE_DEFAULT) & ~PTE_VALID) | PTE_PROT_NONE | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN)
0085 /* shared+writable pages are clean by default, hence PTE_RDONLY|PTE_WRITE */
0086 #define PAGE_SHARED     __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN | PTE_WRITE)
0087 #define PAGE_SHARED_EXEC    __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_WRITE)
0088 #define PAGE_READONLY       __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN)
0089 #define PAGE_READONLY_EXEC  __pgprot(_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN)
0090 #define PAGE_EXECONLY       __pgprot(_PAGE_DEFAULT | PTE_RDONLY | PTE_NG | PTE_PXN)
0091 
0092 #endif /* __ASSEMBLY__ */
0093 
0094 #endif /* __ASM_PGTABLE_PROT_H */