x86_64: some minor paging cleanups
cover x86_64: some minor paging cleanups
This small series of patches cleans up the definition and use of the _PAGE_* and __PAGE_KERNEL* permissions for the x86_64 code in the x86 architecture a little bit.
The scripts are checked by checkpatch.pl now.
PATCH 1/3 x86_64: define all _PAGE_* in terms of _PAGE_BIT_*
This patch defines the _PAGE_* paging attributes in pgtable_64.h in terms of the former defined _PAGE_BIT_* values.
--- include/asm-x86/pgtable_64.h | 27 +++++++++++++++------------ 1 files changed, 15 insertions(+), 12 deletions(-)
include/asm-x86/pgtable_64.h +15 -12
@@ -150,19 +150,23 @@ static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm, unsigned long#define _PAGE_BIT_ACCESSED 5#define _PAGE_BIT_DIRTY 6#define _PAGE_BIT_PSE 7/* 4 MB (or 2MB) page */ +#define _PAGE_BIT_FILE 6#define _PAGE_BIT_GLOBAL 8/* Global TLB entry PPro+ */ #define _PAGE_BIT_NX 63/* No execute: only valid after cpuid check */ -#define _PAGE_PRESENT 0x001 -#define _PAGE_RW 0x002 -#define _PAGE_USER 0x004 -#define _PAGE_PWT 0x008 -#define _PAGE_PCD 0x010 -#define _PAGE_ACCESSED 0x020 -#define _PAGE_DIRTY 0x040 -#define _PAGE_PSE 0x080/* 2MB page */ -#define _PAGE_FILE 0x040/* nonlinear file mapping, saved PTE; unset:swap */ -#define _PAGE_GLOBAL 0x100/* Global TLB entry */ +#define _PAGE_PRESENT (_AC(1, UL)<<_PAGE_BIT_PRESENT) +#define _PAGE_RW (_AC(1, UL)<<_PAGE_BIT_RW) +#define _PAGE_USER (_AC(1, UL)<<_PAGE_BIT_USER) +#define _PAGE_PWT (_AC(1, UL)<<_PAGE_BIT_PWT) +#define _PAGE_PCD (_AC(1, UL)<<_PAGE_BIT_PCD) +#define _PAGE_ACCESSED (_AC(1, UL)<<_PAGE_BIT_ACCESSED) +#define _PAGE_DIRTY (_AC(1, UL)<<_PAGE_BIT_DIRTY) +/* 2MB page */ +#define _PAGE_PSE (_AC(1, UL)<<_PAGE_BIT_PSE) +/* nonlinear file mapping, saved PTE; unset:swap */ +#define _PAGE_FILE (_AC(1, UL)<<_PAGE_BIT_FILE) +/* Global TLB entry */ +#define _PAGE_GLOBAL (_AC(1, UL)<<_PAGE_BIT_GLOBAL)#define _PAGE_PROTNONE 0x080/* If not present */ #define _PAGE_NX (_AC(1,UL)<<_PAGE_BIT_NX)
@@ -248,8 +252,7 @@ static inline unsigned long pmd_bad(pmd_t pmd)#define pte_present (x) (pte_val(x) & (_PAGE_PRESENT | _PAGE_PROTNONE))#define pte_clear (mm,addr,xp) do { set_pte_at(mm, addr, xp, __pte(0)); } while (0) -#define pages_to_mb (x) ((x) >> (20-PAGE_SHIFT))/* FIXME: is this -right? */ +#define pages_to_mb (x) ((x) >> (20-PAGE_SHIFT))/* FIXME: is this right? */ #define pte_page (x) pfn_to_page(pte_pfn(x))#define pte_pfn (x) ((pte_val(x) & __PHYSICAL_MASK) >> PAGE_SHIFT)
Signature · 1 line
1.5.2.5
Re: [PATCH 1/3] x86_64: define all _PAGE_* in terms of _PAGE_BIT_*
Quoted 7 lines · Joerg Roedel
-#define
_PAGE_FILE0x040/* nonlinear file mapping, saved PTE;
unset:swap */include/asm-x86/pgtable_64.h +3
-1-#define _PAGE_GLOBAL 0x100/* Global TLB entry */ +#define _PAGE_PRESENT (_AC(1, UL)<<_PAGE_BIT_PRESENT) +#define _PAGE_RW (_AC(1, UL)<<_PAGE_BIT_RW) +#define _PAGE_USER (_AC(1, UL)<<_PAGE_BIT_USER)
include/asm-x86/pgtable_64.h static inline pte_t ptep_get_and_clear_full(struct mm_struct *mm, unsigned long · line 169
Quoted 10 lines
include/asm-x86/pgtable_64.h +10
-0+#define _PAGE_PWT (_AC(1, UL)<<_PAGE_BIT_PWT) +#define _PAGE_PCD (_AC(1, UL)<<_PAGE_BIT_PCD) +#define _PAGE_ACCESSED (_AC(1, UL)<<_PAGE_BIT_ACCESSED) +#define _PAGE_DIRTY (_AC(1, UL)<<_PAGE_BIT_DIRTY) +/* 2MB page */ +#define _PAGE_PSE (_AC(1, UL)<<_PAGE_BIT_PSE) +/* nonlinear file mapping, saved PTE; unset:swap */ +#define _PAGE_FILE (_AC(1, UL)<<_PAGE_BIT_FILE) +/* Global TLB entry */ +#define _PAGE_GLOBAL (_AC(1, UL)<<_PAGE_BIT_GLOBAL)
Since you're defining these as macros anyway now and doing it repetitively, could you make them a wee bit prettier?
Say something like:
#define _PAGE_MASK(x) (_AC(1, UL)<<(x))
-- Dave
PATCH 2/3 x86_64: use __PAGE_KERNEL* instead of _KERNPG_TABLE for 2MB PTEs in memory initialization
In reply to Joerg RoedelThis minor cleanup replaces _KERNPG_TABLE with the __PAGE_KERNEL* for 2MB PTEs in the x86_64 memory initialization code. The __PAGE_KERNEL* defines are more appropriate for PTEs.
--- arch/x86/mm/init_64.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/mm/init_64.c +2 -2
@@ -224,7 +224,7 @@ __meminit void *early_ioremap(unsigned long addr, unsigned long size) vaddr += addr & ~PMD_MASK ; addr &=PMD_MASK ;for (i =0 ; i < pmds; i++, addr +=PMD_SIZE ) -set_pmd (pmd + i,__pmd (addr | _KERNPG_TABLE | _PAGE_PSE)); +set_pmd (pmd+i,__pmd (addr | __PAGE_KERNEL_LARGE_EXEC));__flush_tlb ();return (void *)vaddr; next:
@@ -268,7 +268,7 @@ phys_pmd_init(pmd_t *pmd_page, unsigned long address, unsigned long end)if (pmd_val (*pmd))continue ; - entry = _PAGE_NX|_PAGE_PSE|_KERNPG_TABLE|_PAGE_GLOBAL|address; + entry = __PAGE_KERNEL_LARGE|_PAGE_GLOBAL|address; entry &= __supported_pte_mask;set_pmd (pmd,__pmd (entry)); }
Signature · 1 line
1.5.2.5
PATCH 3/3 x86_64: use __PAGE_KERNEL_EXEC in ioremap_64.c
In reply to Joerg RoedelThis patch replaces the manual permission setup for pages in ioremap_64.c with the pre-defined __PAGE_KERNEL_EXEC value.
--- arch/x86/mm/ioremap_64.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
arch/x86/mm/ioremap_64.c +1 -2
@@ -103,8 +103,7 @@ void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned l }#endif - pgprot =__pgprot (_PAGE_PRESENT | _PAGE_RW | _PAGE_GLOBAL - | _PAGE_DIRTY | _PAGE_ACCESSED | flags); + pgprot =__pgprot (__PAGE_KERNEL_EXEC | _PAGE_GLOBAL | flags);/* * Mappings have to be page-aligned */
Signature · 1 line
1.5.2.5