aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2016-01-15 19:56:40 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-15 20:56:32 -0500
commit01c8f1c44b83a0825b573e7c723b033cece37b86 (patch)
tree5900d53e74db4515aa6aa760dd120122171fdaa0
parent69660fd797c3e52f7f20478a27687f293d1a41be (diff)
mm, dax, gpu: convert vm_insert_mixed to pfn_t
Convert the raw unsigned long 'pfn' argument to pfn_t for the purpose of evaluating the PFN_MAP and PFN_DEV flags. When both are set it triggers _PAGE_DEVMAP to be set in the resulting pte. There are no functional changes to the gpu drivers as a result of this conversion. Signed-off-by: Dan Williams <dan.j.williams@intel.com> Cc: Dave Hansen <dave@sr71.net> Cc: David Airlie <airlied@linux.ie> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--arch/x86/include/asm/pgtable.h5
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_gem.c4
-rw-r--r--drivers/gpu/drm/gma500/framebuffer.c4
-rw-r--r--drivers/gpu/drm/msm/msm_gem.c4
-rw-r--r--drivers/gpu/drm/omapdrm/omap_gem.c7
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo_vm.c4
-rw-r--r--fs/dax.c2
-rw-r--r--include/linux/mm.h2
-rw-r--r--include/linux/pfn_t.h27
-rw-r--r--mm/memory.c16
10 files changed, 61 insertions, 14 deletions
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index 4973cc9eacce..4c668f15a532 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -247,6 +247,11 @@ static inline pte_t pte_mkspecial(pte_t pte)
247 return pte_set_flags(pte, _PAGE_SPECIAL); 247 return pte_set_flags(pte, _PAGE_SPECIAL);
248} 248}
249 249
250static inline pte_t pte_mkdevmap(pte_t pte)
251{
252 return pte_set_flags(pte, _PAGE_SPECIAL|_PAGE_DEVMAP);
253}
254
250static inline pmd_t pmd_set_flags(pmd_t pmd, pmdval_t set) 255static inline pmd_t pmd_set_flags(pmd_t pmd, pmdval_t set)
251{ 256{
252 pmdval_t v = native_pmd_val(pmd); 257 pmdval_t v = native_pmd_val(pmd);
diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c
index 252eb301470c..32358c5e3db4 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_gem.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c
@@ -14,6 +14,7 @@
14 14
15#include <linux/shmem_fs.h> 15#include <linux/shmem_fs.h>
16#include <linux/dma-buf.h> 16#include <linux/dma-buf.h>
17#include <linux/pfn_t.h>
17#include <drm/exynos_drm.h> 18#include <drm/exynos_drm.h>
18 19
19#include "exynos_drm_drv.h" 20#include "exynos_drm_drv.h"
@@ -490,7 +491,8 @@ int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
490 } 491 }
491 492
492 pfn = page_to_pfn(exynos_gem->pages[page_offset]); 493 pfn = page_to_pfn(exynos_gem->pages[page_offset]);
493 ret = vm_insert_mixed(vma, (unsigned long)vmf->virtual_address, pfn); 494 ret = vm_insert_mixed(vma, (unsigned long)vmf->virtual_address,
495 __pfn_to_pfn_t(pfn, PFN_DEV));
494 496
495out: 497out:
496 switch (ret) { 498 switch (ret) {
diff --git a/drivers/gpu/drm/gma500/framebuffer.c b/drivers/gpu/drm/gma500/framebuffer.c
index 2eaf1b31c7bd..72bc979fa0dc 100644
--- a/drivers/gpu/drm/gma500/framebuffer.c
+++ b/drivers/gpu/drm/gma500/framebuffer.c
@@ -21,6 +21,7 @@
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/errno.h> 22#include <linux/errno.h>
23#include <linux/string.h> 23#include <linux/string.h>
24#include <linux/pfn_t.h>
24#include <linux/mm.h> 25#include <linux/mm.h>
25#include <linux/tty.h> 26#include <linux/tty.h>
26#include <linux/slab.h> 27#include <linux/slab.h>
@@ -132,7 +133,8 @@ static int psbfb_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
132 for (i = 0; i < page_num; i++) { 133 for (i = 0; i < page_num; i++) {
133 pfn = (phys_addr >> PAGE_SHIFT); 134 pfn = (phys_addr >> PAGE_SHIFT);
134 135
135 ret = vm_insert_mixed(vma, address, pfn); 136 ret = vm_insert_mixed(vma, address,
137 __pfn_to_pfn_t(pfn, PFN_DEV));
136 if (unlikely((ret == -EBUSY) || (ret != 0 && i > 0))) 138 if (unlikely((ret == -EBUSY) || (ret != 0 && i > 0)))
137 break; 139 break;
138 else if (unlikely(ret != 0)) { 140 else if (unlikely(ret != 0)) {
diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
index c76cc853b08a..3cedb8d5c855 100644
--- a/drivers/gpu/drm/msm/msm_gem.c
+++ b/drivers/gpu/drm/msm/msm_gem.c
@@ -18,6 +18,7 @@
18#include <linux/spinlock.h> 18#include <linux/spinlock.h>
19#include <linux/shmem_fs.h> 19#include <linux/shmem_fs.h>
20#include <linux/dma-buf.h> 20#include <linux/dma-buf.h>
21#include <linux/pfn_t.h>
21 22
22#include "msm_drv.h" 23#include "msm_drv.h"
23#include "msm_gem.h" 24#include "msm_gem.h"
@@ -222,7 +223,8 @@ int msm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
222 VERB("Inserting %p pfn %lx, pa %lx", vmf->virtual_address, 223 VERB("Inserting %p pfn %lx, pa %lx", vmf->virtual_address,
223 pfn, pfn << PAGE_SHIFT); 224 pfn, pfn << PAGE_SHIFT);
224 225
225 ret = vm_insert_mixed(vma, (unsigned long)vmf->virtual_address, pfn); 226 ret = vm_insert_mixed(vma, (unsigned long)vmf->virtual_address,
227 __pfn_to_pfn_t(pfn, PFN_DEV));
226 228
227out_unlock: 229out_unlock:
228 mutex_unlock(&dev->struct_mutex); 230 mutex_unlock(&dev->struct_mutex);
diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c b/drivers/gpu/drm/omapdrm/omap_gem.c
index 7ed08fdc4c42..ceba5459ceb7 100644
--- a/drivers/gpu/drm/omapdrm/omap_gem.c
+++ b/drivers/gpu/drm/omapdrm/omap_gem.c
@@ -19,6 +19,7 @@
19 19
20#include <linux/shmem_fs.h> 20#include <linux/shmem_fs.h>
21#include <linux/spinlock.h> 21#include <linux/spinlock.h>
22#include <linux/pfn_t.h>
22 23
23#include <drm/drm_vma_manager.h> 24#include <drm/drm_vma_manager.h>
24 25
@@ -385,7 +386,8 @@ static int fault_1d(struct drm_gem_object *obj,
385 VERB("Inserting %p pfn %lx, pa %lx", vmf->virtual_address, 386 VERB("Inserting %p pfn %lx, pa %lx", vmf->virtual_address,
386 pfn, pfn << PAGE_SHIFT); 387 pfn, pfn << PAGE_SHIFT);
387 388
388 return vm_insert_mixed(vma, (unsigned long)vmf->virtual_address, pfn); 389 return vm_insert_mixed(vma, (unsigned long)vmf->virtual_address,
390 __pfn_to_pfn_t(pfn, PFN_DEV));
389} 391}
390 392
391/* Special handling for the case of faulting in 2d tiled buffers */ 393/* Special handling for the case of faulting in 2d tiled buffers */
@@ -478,7 +480,8 @@ static int fault_2d(struct drm_gem_object *obj,
478 pfn, pfn << PAGE_SHIFT); 480 pfn, pfn << PAGE_SHIFT);
479 481
480 for (i = n; i > 0; i--) { 482 for (i = n; i > 0; i--) {
481 vm_insert_mixed(vma, (unsigned long)vaddr, pfn); 483 vm_insert_mixed(vma, (unsigned long)vaddr,
484 __pfn_to_pfn_t(pfn, PFN_DEV));
482 pfn += usergart[fmt].stride_pfn; 485 pfn += usergart[fmt].stride_pfn;
483 vaddr += PAGE_SIZE * m; 486 vaddr += PAGE_SIZE * m;
484 } 487 }
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index 8fb7213277cc..06d26dc438b2 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -35,6 +35,7 @@
35#include <ttm/ttm_placement.h> 35#include <ttm/ttm_placement.h>
36#include <drm/drm_vma_manager.h> 36#include <drm/drm_vma_manager.h>
37#include <linux/mm.h> 37#include <linux/mm.h>
38#include <linux/pfn_t.h>
38#include <linux/rbtree.h> 39#include <linux/rbtree.h>
39#include <linux/module.h> 40#include <linux/module.h>
40#include <linux/uaccess.h> 41#include <linux/uaccess.h>
@@ -229,7 +230,8 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
229 } 230 }
230 231
231 if (vma->vm_flags & VM_MIXEDMAP) 232 if (vma->vm_flags & VM_MIXEDMAP)
232 ret = vm_insert_mixed(&cvma, address, pfn); 233 ret = vm_insert_mixed(&cvma, address,
234 __pfn_to_pfn_t(pfn, PFN_DEV));
233 else 235 else
234 ret = vm_insert_pfn(&cvma, address, pfn); 236 ret = vm_insert_pfn(&cvma, address, pfn);
235 237
diff --git a/fs/dax.c b/fs/dax.c
index 6b13d6cd9a9a..574763eed8a3 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -363,7 +363,7 @@ static int dax_insert_mapping(struct inode *inode, struct buffer_head *bh,
363 } 363 }
364 dax_unmap_atomic(bdev, &dax); 364 dax_unmap_atomic(bdev, &dax);
365 365
366 error = vm_insert_mixed(vma, vaddr, pfn_t_to_pfn(dax.pfn)); 366 error = vm_insert_mixed(vma, vaddr, dax.pfn);
367 367
368 out: 368 out:
369 i_mmap_unlock_read(mapping); 369 i_mmap_unlock_read(mapping);
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8bb0907a3603..a9902152449f 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2107,7 +2107,7 @@ int vm_insert_page(struct vm_area_struct *, unsigned long addr, struct page *);
2107int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr, 2107int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
2108 unsigned long pfn); 2108 unsigned long pfn);
2109int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr, 2109int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
2110 unsigned long pfn); 2110 pfn_t pfn);
2111int vm_iomap_memory(struct vm_area_struct *vma, phys_addr_t start, unsigned long len); 2111int vm_iomap_memory(struct vm_area_struct *vma, phys_addr_t start, unsigned long len);
2112 2112
2113 2113
diff --git a/include/linux/pfn_t.h b/include/linux/pfn_t.h
index c557a0e0b20c..bdaa275d7623 100644
--- a/include/linux/pfn_t.h
+++ b/include/linux/pfn_t.h
@@ -64,4 +64,31 @@ static inline pfn_t page_to_pfn_t(struct page *page)
64{ 64{
65 return pfn_to_pfn_t(page_to_pfn(page)); 65 return pfn_to_pfn_t(page_to_pfn(page));
66} 66}
67
68static inline int pfn_t_valid(pfn_t pfn)
69{
70 return pfn_valid(pfn_t_to_pfn(pfn));
71}
72
73#ifdef CONFIG_MMU
74static inline pte_t pfn_t_pte(pfn_t pfn, pgprot_t pgprot)
75{
76 return pfn_pte(pfn_t_to_pfn(pfn), pgprot);
77}
78#endif
79
80#ifdef __HAVE_ARCH_PTE_DEVMAP
81static inline bool pfn_t_devmap(pfn_t pfn)
82{
83 const unsigned long flags = PFN_DEV|PFN_MAP;
84
85 return (pfn.val & flags) == flags;
86}
87#else
88static inline bool pfn_t_devmap(pfn_t pfn)
89{
90 return false;
91}
92pte_t pte_mkdevmap(pte_t pte);
93#endif
67#endif /* _LINUX_PFN_T_H_ */ 94#endif /* _LINUX_PFN_T_H_ */
diff --git a/mm/memory.c b/mm/memory.c
index 5a73c6ed8e5c..7f03652723ea 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -50,6 +50,7 @@
50#include <linux/export.h> 50#include <linux/export.h>
51#include <linux/delayacct.h> 51#include <linux/delayacct.h>
52#include <linux/init.h> 52#include <linux/init.h>
53#include <linux/pfn_t.h>
53#include <linux/writeback.h> 54#include <linux/writeback.h>
54#include <linux/memcontrol.h> 55#include <linux/memcontrol.h>
55#include <linux/mmu_notifier.h> 56#include <linux/mmu_notifier.h>
@@ -1500,7 +1501,7 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
1500EXPORT_SYMBOL(vm_insert_page); 1501EXPORT_SYMBOL(vm_insert_page);
1501 1502
1502static int insert_pfn(struct vm_area_struct *vma, unsigned long addr, 1503static int insert_pfn(struct vm_area_struct *vma, unsigned long addr,
1503 unsigned long pfn, pgprot_t prot) 1504 pfn_t pfn, pgprot_t prot)
1504{ 1505{
1505 struct mm_struct *mm = vma->vm_mm; 1506 struct mm_struct *mm = vma->vm_mm;
1506 int retval; 1507 int retval;
@@ -1516,7 +1517,10 @@ static int insert_pfn(struct vm_area_struct *vma, unsigned long addr,
1516 goto out_unlock; 1517 goto out_unlock;
1517 1518
1518 /* Ok, finally just insert the thing.. */ 1519 /* Ok, finally just insert the thing.. */
1519 entry = pte_mkspecial(pfn_pte(pfn, prot)); 1520 if (pfn_t_devmap(pfn))
1521 entry = pte_mkdevmap(pfn_t_pte(pfn, prot));
1522 else
1523 entry = pte_mkspecial(pfn_t_pte(pfn, prot));
1520 set_pte_at(mm, addr, pte, entry); 1524 set_pte_at(mm, addr, pte, entry);
1521 update_mmu_cache(vma, addr, pte); /* XXX: why not for insert_page? */ 1525 update_mmu_cache(vma, addr, pte); /* XXX: why not for insert_page? */
1522 1526
@@ -1566,14 +1570,14 @@ int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
1566 if (track_pfn_insert(vma, &pgprot, pfn)) 1570 if (track_pfn_insert(vma, &pgprot, pfn))
1567 return -EINVAL; 1571 return -EINVAL;
1568 1572
1569 ret = insert_pfn(vma, addr, pfn, pgprot); 1573 ret = insert_pfn(vma, addr, __pfn_to_pfn_t(pfn, PFN_DEV), pgprot);
1570 1574
1571 return ret; 1575 return ret;
1572} 1576}
1573EXPORT_SYMBOL(vm_insert_pfn); 1577EXPORT_SYMBOL(vm_insert_pfn);
1574 1578
1575int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr, 1579int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
1576 unsigned long pfn) 1580 pfn_t pfn)
1577{ 1581{
1578 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP)); 1582 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
1579 1583
@@ -1587,10 +1591,10 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
1587 * than insert_pfn). If a zero_pfn were inserted into a VM_MIXEDMAP 1591 * than insert_pfn). If a zero_pfn were inserted into a VM_MIXEDMAP
1588 * without pte special, it would there be refcounted as a normal page. 1592 * without pte special, it would there be refcounted as a normal page.
1589 */ 1593 */
1590 if (!HAVE_PTE_SPECIAL && pfn_valid(pfn)) { 1594 if (!HAVE_PTE_SPECIAL && pfn_t_valid(pfn)) {
1591 struct page *page; 1595 struct page *page;
1592 1596
1593 page = pfn_to_page(pfn); 1597 page = pfn_t_to_page(pfn);
1594 return insert_page(vma, addr, page, vma->vm_page_prot); 1598 return insert_page(vma, addr, page, vma->vm_page_prot);
1595 } 1599 }
1596 return insert_pfn(vma, addr, pfn, vma->vm_page_prot); 1600 return insert_pfn(vma, addr, pfn, vma->vm_page_prot);