i386 virtualization - Attempt to clean up pgtable code motion
PATCH 6/6 i386 virtualization - Attempt to clean up pgtable code motion
Virtualization aware Linux kernels may need to redefine functions which write to hardware page tables at the sub-architecture layer. Previously, this was done by encapsulation in a split mach-xxx/pgtable-{2|3}level-ops.h file, but having 8 pgtable header files is simply unacceptable. This goes some ways towards cleaning that up by deprecating the 2/3 level subarch functions. This is accomplished by using __HAVE_ARCH_FUNC macros, and allowing one sub-arch file, pgtable-ops.h, which gets included before any functions which write to hardware page tables, allowing the sub-architecture to override any or all definitions it needs.
include/asm-i386/pgtable-2level.h +21 -0
@@ -55,4 +55,25 @@#define __pte_to_swp_entry (pte) ((swp_entry_t) { (pte).pte_low })#define __swp_entry_to_pte (x) ((pte_t) { (x).val }) +/* +* Certain architectures need to do special things when PTEs +* within a page table are directly modified. Thus, the following +* hook is made available. +*/ +#ifndef __HAVE_ARCH_SET_PTE +#define __HAVE_ARCH_SET_PTE +#define set_pte (pteptr, pteval) (*(pteptr) = pteval) +#endif +#define set_pte_atomic (pteptr, pteval) set_pte(pteptr, pteval) + +#ifndef __HAVE_ARCH_SET_PMD +#define __HAVE_ARCH_SET_PMD +#define set_pmd (pmdptr, pmdval) (*(pmdptr) = (pmdval)) +#endif + +#ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR +#define __HAVE_ARCH_PTEP_GET_AND_CLEAR +#define ptep_get_and_clear (mm,addr,xp) __pte(xchg(&(xp)->pte_low, 0)) +#endif +#endif /* _I386_PGTABLE_2LEVEL_H */
include/asm-i386/pgtable-3level.h +54 -0
58 lines not on this page · raw message
include/asm-i386/pgtable.h +44 -5
67 lines not on this page · raw message
include/asm-i386/mach-default/pgtable-2level-ops.h +0 -15
@@ -1,15 +0,0 @@ -#ifndef _MACH_PGTABLE_LEVEL_OPS_H -#define _MACH_PGTABLE_LEVEL_OPS_H - -/* -* Certain architectures need to do special things when PTEs -* within a page table are directly modified. Thus, the following -* hook is made available. -*/ -#define set_pte (pteptr, pteval) (*(pteptr) = pteval) -#define set_pte_atomic (pteptr, pteval) set_pte(pteptr,pteval) -#define set_pmd (pmdptr, pmdval) (*(pmdptr) = (pmdval)) - -#define ptep_get_and_clear (mm,addr,xp) __pte(xchg(&(xp)->pte_low, 0)) - -#endif /* _PGTABLE_OPS_H */
include/asm-i386/mach-default/pgtable-3level-ops.h +0 -37
@@ -1,37 +0,0 @@ -#ifndef _MACH_PGTABLE_LEVEL_OPS_H -#define _MACH_PGTABLE_LEVEL_OPS_H - -/* Rules for using set_pte: the pte being assigned *must* be -* either not present or in a state where the hardware will -* not attempt to update the pte. In places where this is -* not possible, use pte_get_and_clear to obtain the old pte -* value and then use set_pte to update it. -ben -*/ -static inline void set_pte (pte_t *ptep,pte_t pte) -{ - ptep->pte_high = pte.pte_high; -smp_wmb (); - ptep->pte_low = pte.pte_low; -} - -#define __HAVE_ARCH_SET_PTE_ATOMIC -#define set_pte_atomic (pteptr,pteval) \ - set_64bit((unsigned long long *)(pteptr),pte_val(pteval)) -#define set_pmd (pmdptr,pmdval) \ - set_64bit((unsigned long long *)(pmdptr),pmd_val(pmdval)) -#define set_pud (pudptr,pudval) \ - (*(pudptr) = (pudval)) - -static inline pte_t ptep_get_and_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep) -{ -pte_t res; - -/* xchg acts as a barrier before the setting of the high bits */ - res.pte_low =xchg (&ptep->pte_low,0 ); - res.pte_high = ptep->pte_high; - ptep->pte_high =0 ; - -return res; -} - -#endif
include/asm-i386/mach-default/pgtable-ops.h +0 -34
@@ -25,31 +25,6 @@#ifndef _PGTABLE_OPS_H#define _PGTABLE_OPS_H -#ifdef CONFIG_X86_PAE -# include <pgtable-3level-ops.h> -#else -# include <pgtable-2level-ops.h> -#endif - -static inline int ptep_test_and_clear_dirty (struct vm_area_struct *vma,unsigned long addr,pte_t *ptep) -{ -if (!pte_dirty (*ptep)) -return 0 ; -return test_and_clear_bit (_PAGE_BIT_DIRTY, &ptep->pte_low); -} - -static inline int ptep_test_and_clear_young (struct vm_area_struct *vma,unsigned long addr,pte_t *ptep) -{ -if (!pte_young (*ptep)) -return 0 ; -return test_and_clear_bit (_PAGE_BIT_ACCESSED, &ptep->pte_low); -} - -static inline void ptep_set_wrprotect (struct mm_struct *mm,unsigned long addr,pte_t *ptep) -{ -clear_bit (_PAGE_BIT_RW, &ptep->pte_low); -} -/* * clone_pgd_range(pgd_t *dst, pgd_t *src, int count); *
@@ -65,13 +40,4 @@ memcpy(dst, src, count * sizeof(pgd_t)); } -#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS -#define ptep_set_access_flags (__vma, __address, __ptep, __entry, __dirty) \ - do { \ - if (__dirty) { \ - (__ptep)->pte_low = (__entry).pte_low; \ - flush_tlb_page(__vma, __address); \ - } \ - } while (0) -#endif /* _PGTABLE_OPS_H */
Quoted 9 lines · * [email protected] ([email protected]) wrote:
Virtualization aware Linux kernels may need to redefine functions which write to hardware page tables at the sub-architecture layer. Previously, this was done by encapsulation in a split mach-xxx/pgtable-{2|3}level-ops.h file, but having 8 pgtable header files is simply unacceptable. This goes some ways towards cleaning that up by deprecating the 2/3 level subarch functions. This is accomplished by using
__HAVE_ARCH_FUNCmacros, and allowing one sub-arch file,pgtable-ops.h, which gets included before any functions which write to hardware page tables, allowing the sub-architecture to override any or all definitions it needs.
This looks like a better tradeoff.