Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/powernv: Fix vma page prot flags in opal-prd driver

opal-prd driver will mmap() firmware code/data area as private
mapping to prd user space daemon. Write to this page will
trigger COW faults. The new COW pages are normal kernel RAM
pages accounted by the kernel and are not special.

vma->vm_page_prot value will be used at page fault time
for the new COW pages, while pgprot_t value passed in
remap_pfn_range() is used for the initial page table entry.

Hence:
* Do not add _PAGE_SPECIAL in vma, but only for remap_pfn_range()
* Also remap_pfn_range() will add the _PAGE_SPECIAL flag using
pte_mkspecial() call, hence no need to specify in the driver

This fix resolves the page accounting warning shown below:
BUG: Bad rss-counter state mm:c0000007d34ac600 idx:1 val:19

The above warning is triggered since _PAGE_SPECIAL was incorrectly
being set for the normal kernel COW pages.

Signed-off-by: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
Acked-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Vaidyanathan Srinivasan and committed by
Michael Ellerman
d8ea782b d770e558

+4 -5
+4 -5
arch/powerpc/platforms/powernv/opal-prd.c
··· 112 112 static int opal_prd_mmap(struct file *file, struct vm_area_struct *vma) 113 113 { 114 114 size_t addr, size; 115 + pgprot_t page_prot; 115 116 int rc; 116 117 117 118 pr_devel("opal_prd_mmap(0x%016lx, 0x%016lx, 0x%lx, 0x%lx)\n", ··· 126 125 if (!opal_prd_range_is_valid(addr, size)) 127 126 return -EINVAL; 128 127 129 - vma->vm_page_prot = __pgprot(pgprot_val(phys_mem_access_prot(file, 130 - vma->vm_pgoff, 131 - size, vma->vm_page_prot)) 132 - | _PAGE_SPECIAL); 128 + page_prot = phys_mem_access_prot(file, vma->vm_pgoff, 129 + size, vma->vm_page_prot); 133 130 134 131 rc = remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, size, 135 - vma->vm_page_prot); 132 + page_prot); 136 133 137 134 return rc; 138 135 }