Skip to content

Commit 01c8f1c

Browse files
djbwtorvalds
authored andcommitted
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 <[email protected]> Cc: Dave Hansen <[email protected]> Cc: David Airlie <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 69660fd commit 01c8f1c

File tree

10 files changed

+61
-14
lines changed

10 files changed

+61
-14
lines changed

arch/x86/include/asm/pgtable.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ static inline pte_t pte_mkspecial(pte_t pte)
247247
return pte_set_flags(pte, _PAGE_SPECIAL);
248248
}
249249

250+
static inline pte_t pte_mkdevmap(pte_t pte)
251+
{
252+
return pte_set_flags(pte, _PAGE_SPECIAL|_PAGE_DEVMAP);
253+
}
254+
250255
static inline pmd_t pmd_set_flags(pmd_t pmd, pmdval_t set)
251256
{
252257
pmdval_t v = native_pmd_val(pmd);

drivers/gpu/drm/exynos/exynos_drm_gem.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <linux/shmem_fs.h>
1616
#include <linux/dma-buf.h>
17+
#include <linux/pfn_t.h>
1718
#include <drm/exynos_drm.h>
1819

1920
#include "exynos_drm_drv.h"
@@ -490,7 +491,8 @@ int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
490491
}
491492

492493
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));
494496

495497
out:
496498
switch (ret) {

drivers/gpu/drm/gma500/framebuffer.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/kernel.h>
2222
#include <linux/errno.h>
2323
#include <linux/string.h>
24+
#include <linux/pfn_t.h>
2425
#include <linux/mm.h>
2526
#include <linux/tty.h>
2627
#include <linux/slab.h>
@@ -132,7 +133,8 @@ static int psbfb_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
132133
for (i = 0; i < page_num; i++) {
133134
pfn = (phys_addr >> PAGE_SHIFT);
134135

135-
ret = vm_insert_mixed(vma, address, pfn);
136+
ret = vm_insert_mixed(vma, address,
137+
__pfn_to_pfn_t(pfn, PFN_DEV));
136138
if (unlikely((ret == -EBUSY) || (ret != 0 && i > 0)))
137139
break;
138140
else if (unlikely(ret != 0)) {

drivers/gpu/drm/msm/msm_gem.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/spinlock.h>
1919
#include <linux/shmem_fs.h>
2020
#include <linux/dma-buf.h>
21+
#include <linux/pfn_t.h>
2122

2223
#include "msm_drv.h"
2324
#include "msm_gem.h"
@@ -222,7 +223,8 @@ int msm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
222223
VERB("Inserting %p pfn %lx, pa %lx", vmf->virtual_address,
223224
pfn, pfn << PAGE_SHIFT);
224225

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));
226228

227229
out_unlock:
228230
mutex_unlock(&dev->struct_mutex);

drivers/gpu/drm/omapdrm/omap_gem.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <linux/shmem_fs.h>
2121
#include <linux/spinlock.h>
22+
#include <linux/pfn_t.h>
2223

2324
#include <drm/drm_vma_manager.h>
2425

@@ -385,7 +386,8 @@ static int fault_1d(struct drm_gem_object *obj,
385386
VERB("Inserting %p pfn %lx, pa %lx", vmf->virtual_address,
386387
pfn, pfn << PAGE_SHIFT);
387388

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));
389391
}
390392

391393
/* Special handling for the case of faulting in 2d tiled buffers */
@@ -478,7 +480,8 @@ static int fault_2d(struct drm_gem_object *obj,
478480
pfn, pfn << PAGE_SHIFT);
479481

480482
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));
482485
pfn += usergart[fmt].stride_pfn;
483486
vaddr += PAGE_SIZE * m;
484487
}

drivers/gpu/drm/ttm/ttm_bo_vm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <ttm/ttm_placement.h>
3636
#include <drm/drm_vma_manager.h>
3737
#include <linux/mm.h>
38+
#include <linux/pfn_t.h>
3839
#include <linux/rbtree.h>
3940
#include <linux/module.h>
4041
#include <linux/uaccess.h>
@@ -229,7 +230,8 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
229230
}
230231

231232
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));
233235
else
234236
ret = vm_insert_pfn(&cvma, address, pfn);
235237

fs/dax.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ static int dax_insert_mapping(struct inode *inode, struct buffer_head *bh,
363363
}
364364
dax_unmap_atomic(bdev, &dax);
365365

366-
error = vm_insert_mixed(vma, vaddr, pfn_t_to_pfn(dax.pfn));
366+
error = vm_insert_mixed(vma, vaddr, dax.pfn);
367367

368368
out:
369369
i_mmap_unlock_read(mapping);

include/linux/mm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2107,7 +2107,7 @@ int vm_insert_page(struct vm_area_struct *, unsigned long addr, struct page *);
21072107
int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
21082108
unsigned long pfn);
21092109
int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
2110-
unsigned long pfn);
2110+
pfn_t pfn);
21112111
int vm_iomap_memory(struct vm_area_struct *vma, phys_addr_t start, unsigned long len);
21122112

21132113

include/linux/pfn_t.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,31 @@ static inline pfn_t page_to_pfn_t(struct page *page)
6464
{
6565
return pfn_to_pfn_t(page_to_pfn(page));
6666
}
67+
68+
static inline int pfn_t_valid(pfn_t pfn)
69+
{
70+
return pfn_valid(pfn_t_to_pfn(pfn));
71+
}
72+
73+
#ifdef CONFIG_MMU
74+
static 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
81+
static 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
88+
static inline bool pfn_t_devmap(pfn_t pfn)
89+
{
90+
return false;
91+
}
92+
pte_t pte_mkdevmap(pte_t pte);
93+
#endif
6794
#endif /* _LINUX_PFN_T_H_ */

mm/memory.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include <linux/export.h>
5151
#include <linux/delayacct.h>
5252
#include <linux/init.h>
53+
#include <linux/pfn_t.h>
5354
#include <linux/writeback.h>
5455
#include <linux/memcontrol.h>
5556
#include <linux/mmu_notifier.h>
@@ -1500,7 +1501,7 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
15001501
EXPORT_SYMBOL(vm_insert_page);
15011502

15021503
static 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)
15041505
{
15051506
struct mm_struct *mm = vma->vm_mm;
15061507
int retval;
@@ -1516,7 +1517,10 @@ static int insert_pfn(struct vm_area_struct *vma, unsigned long addr,
15161517
goto out_unlock;
15171518

15181519
/* 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));
15201524
set_pte_at(mm, addr, pte, entry);
15211525
update_mmu_cache(vma, addr, pte); /* XXX: why not for insert_page? */
15221526

@@ -1566,14 +1570,14 @@ int vm_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
15661570
if (track_pfn_insert(vma, &pgprot, pfn))
15671571
return -EINVAL;
15681572

1569-
ret = insert_pfn(vma, addr, pfn, pgprot);
1573+
ret = insert_pfn(vma, addr, __pfn_to_pfn_t(pfn, PFN_DEV), pgprot);
15701574

15711575
return ret;
15721576
}
15731577
EXPORT_SYMBOL(vm_insert_pfn);
15741578

15751579
int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
1576-
unsigned long pfn)
1580+
pfn_t pfn)
15771581
{
15781582
BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
15791583

@@ -1587,10 +1591,10 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
15871591
* than insert_pfn). If a zero_pfn were inserted into a VM_MIXEDMAP
15881592
* without pte special, it would there be refcounted as a normal page.
15891593
*/
1590-
if (!HAVE_PTE_SPECIAL && pfn_valid(pfn)) {
1594+
if (!HAVE_PTE_SPECIAL && pfn_t_valid(pfn)) {
15911595
struct page *page;
15921596

1593-
page = pfn_to_page(pfn);
1597+
page = pfn_t_to_page(pfn);
15941598
return insert_page(vma, addr, page, vma->vm_page_prot);
15951599
}
15961600
return insert_pfn(vma, addr, pfn, vma->vm_page_prot);

0 commit comments

Comments
 (0)