diff -r 61c96456a3e1 include/xen/interface/xen.h --- a/include/xen/interface/xen.h Thu Dec 20 16:58:14 2007 +0000 +++ b/include/xen/interface/xen.h Sat Jan 12 20:01:14 2008 -0700 @@ -168,9 +168,13 @@ * ptr[:2] -- Machine address within the frame whose mapping to modify. * The frame must belong to the FD, if one is specified. * val -- Value to write into the mapping entry. + * + * ptr[1:0] == MMU_PT_UPDATE_PRESERVE_AD: + * As MMU_NORMAL_PT_UPDATE above, but A/D bits in the PTE are preserved (ORed). */ -#define MMU_NORMAL_PT_UPDATE 0 /* checked '*ptr = val'. ptr is MA. */ -#define MMU_MACHPHYS_UPDATE 1 /* ptr = MA of frame to modify entry for */ +#define MMU_NORMAL_PT_UPDATE 0 /* checked '*ptr = val'. ptr is MA. */ +#define MMU_MACHPHYS_UPDATE 1 /* ptr = MA of frame to modify entry for */ +#define MMU_PT_UPDATE_PRESERVE_AD 2 /* '*ptr = val', preserve (OR) A/D bits */ /* * MMU EXTENDED OPERATIONS diff -r 61c96456a3e1 include/asm-i386/mach-xen/asm/pgtable.h --- a/include/asm-i386/mach-xen/asm/pgtable.h Thu Dec 20 16:58:14 2007 +0000 +++ b/include/asm-i386/mach-xen/asm/pgtable.h Mon Jan 07 17:47:31 2008 -0700 @@ -512,6 +512,12 @@ int touch_pte_range(struct mm_struct *mm unsigned long address, unsigned long size); +int xen_change_pte_range(struct mm_struct *mm, pmd_t *pmd, + unsigned long addr, unsigned long end, pgprot_t newprot); + +#define arch_change_pte_range(mm, pmd, addr, end, newprot) \ + xen_change_pte_range(mm, pmd, addr, end, newprot) + #define io_remap_pfn_range(vma,from,pfn,size,prot) \ direct_remap_pfn_range(vma,from,pfn,size,prot,DOMID_IO) diff -r 61c96456a3e1 include/asm-x86_64/mach-xen/asm/pgtable.h --- a/include/asm-x86_64/mach-xen/asm/pgtable.h Thu Dec 20 16:58:14 2007 +0000 +++ b/include/asm-x86_64/mach-xen/asm/pgtable.h Mon Jan 07 17:47:41 2008 -0700 @@ -541,6 +541,12 @@ int touch_pte_range(struct mm_struct *mm unsigned long address, unsigned long size); +int xen_change_pte_range(struct mm_struct *mm, pmd_t *pmd, + unsigned long addr, unsigned long end, pgprot_t newprot); + +#define arch_change_pte_range(mm, pmd, addr, end, newprot) \ + xen_change_pte_range(mm, pmd, addr, end, newprot) + #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \ direct_remap_pfn_range(vma,vaddr,pfn,size,prot,DOMID_IO) diff -r 61c96456a3e1 include/asm-generic/pgtable.h --- a/include/asm-generic/pgtable.h Thu Dec 20 16:58:14 2007 +0000 +++ b/include/asm-generic/pgtable.h Mon Jan 07 17:48:00 2008 -0700 @@ -188,6 +188,10 @@ static inline void ptep_set_wrprotect(st }) #endif +#ifndef arch_change_pte_range +#define arch_change_pte_range(mm, pmd, addr, end, newprot) 0 +#endif + #ifndef __ASSEMBLY__ /* * When walking page tables, we usually want to skip any p?d_none entries; diff -r 61c96456a3e1 arch/i386/mm/hypervisor.c --- a/arch/i386/mm/hypervisor.c Thu Dec 20 16:58:14 2007 +0000 +++ b/arch/i386/mm/hypervisor.c Sat Jan 12 20:01:40 2008 -0700 @@ -548,3 +548,33 @@ int write_ldt_entry(void *ldt, int entry mach_lp, (u64)entry_a | ((u64)entry_b<<32)); } #endif + +#define MAX_BATCHED_FULL_PTES 32 + +int xen_change_pte_range(struct mm_struct *mm, pmd_t *pmd, + unsigned long addr, unsigned long end, pgprot_t newprot) +{ + int rc = 0, i = 0; + mmu_update_t u[MAX_BATCHED_FULL_PTES]; + pte_t *pte; + spinlock_t *ptl; + + pte = pte_offset_map_lock(mm, pmd, addr, &ptl); + do { + if (pte_present(*pte)) { + u[i].ptr = virt_to_machine(pte) | MMU_PT_UPDATE_PRESERVE_AD; + u[i].val = __pte_val(pte_modify(*pte, newprot)); + if (++i == MAX_BATCHED_FULL_PTES) { + if ((rc = HYPERVISOR_mmu_update( + &u[0], i, NULL, DOMID_SELF)) != 0) + break; + i = 0; + } + } + } while (pte++, addr += PAGE_SIZE, addr != end); + if (i) + rc = HYPERVISOR_mmu_update( &u[0], i, NULL, DOMID_SELF); + pte_unmap_unlock(pte - 1, ptl); + BUG_ON(rc && rc != -ENOSYS); + return !rc; +} diff -r 61c96456a3e1 mm/mprotect.c --- a/mm/mprotect.c Thu Dec 20 16:58:14 2007 +0000 +++ b/mm/mprotect.c Mon Jan 07 17:48:42 2008 -0700 @@ -75,6 +75,8 @@ static inline void change_pmd_range(stru do { next = pmd_addr_end(addr, end); if (pmd_none_or_clear_bad(pmd)) + continue; + if (arch_change_pte_range(mm, pmd, addr, next, newprot)) continue; change_pte_range(mm, pmd, addr, next, newprot); } while (pmd++, addr = next, addr != end);