Skip to content

Commit 9a9731b

Browse files
committed
mm: Add vmf_insert_pfn_xxx_prot() for huge page-table entries
For graphics drivers needing to modify the page-protection, add huge page-table entries counterparts to vmf_insert_pfn_prot(). Cc: Andrew Morton <[email protected]> Cc: Michal Hocko <[email protected]> Cc: "Matthew Wilcox (Oracle)" <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Cc: Ralph Campbell <[email protected]> Cc: "Jérôme Glisse" <[email protected]> Cc: "Christian König" <[email protected]> Cc: Dan Williams <[email protected]> Signed-off-by: Thomas Hellstrom (VMware) <[email protected]> Acked-by: Christian König <[email protected]> Acked-by: Andrew Morton <[email protected]>
1 parent 327e9fd commit 9a9731b

File tree

2 files changed

+71
-8
lines changed

2 files changed

+71
-8
lines changed

include/linux/huge_mm.h

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,45 @@ extern bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr,
4747
extern int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
4848
unsigned long addr, pgprot_t newprot,
4949
int prot_numa);
50-
vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, pfn_t pfn, bool write);
51-
vm_fault_t vmf_insert_pfn_pud(struct vm_fault *vmf, pfn_t pfn, bool write);
50+
vm_fault_t vmf_insert_pfn_pmd_prot(struct vm_fault *vmf, pfn_t pfn,
51+
pgprot_t pgprot, bool write);
52+
53+
/**
54+
* vmf_insert_pfn_pmd - insert a pmd size pfn
55+
* @vmf: Structure describing the fault
56+
* @pfn: pfn to insert
57+
* @pgprot: page protection to use
58+
* @write: whether it's a write fault
59+
*
60+
* Insert a pmd size pfn. See vmf_insert_pfn() for additional info.
61+
*
62+
* Return: vm_fault_t value.
63+
*/
64+
static inline vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, pfn_t pfn,
65+
bool write)
66+
{
67+
return vmf_insert_pfn_pmd_prot(vmf, pfn, vmf->vma->vm_page_prot, write);
68+
}
69+
vm_fault_t vmf_insert_pfn_pud_prot(struct vm_fault *vmf, pfn_t pfn,
70+
pgprot_t pgprot, bool write);
71+
72+
/**
73+
* vmf_insert_pfn_pud - insert a pud size pfn
74+
* @vmf: Structure describing the fault
75+
* @pfn: pfn to insert
76+
* @pgprot: page protection to use
77+
* @write: whether it's a write fault
78+
*
79+
* Insert a pud size pfn. See vmf_insert_pfn() for additional info.
80+
*
81+
* Return: vm_fault_t value.
82+
*/
83+
static inline vm_fault_t vmf_insert_pfn_pud(struct vm_fault *vmf, pfn_t pfn,
84+
bool write)
85+
{
86+
return vmf_insert_pfn_pud_prot(vmf, pfn, vmf->vma->vm_page_prot, write);
87+
}
88+
5289
enum transparent_hugepage_flag {
5390
TRANSPARENT_HUGEPAGE_FLAG,
5491
TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG,

mm/huge_memory.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -824,11 +824,24 @@ static void insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr,
824824
pte_free(mm, pgtable);
825825
}
826826

827-
vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, pfn_t pfn, bool write)
827+
/**
828+
* vmf_insert_pfn_pmd_prot - insert a pmd size pfn
829+
* @vmf: Structure describing the fault
830+
* @pfn: pfn to insert
831+
* @pgprot: page protection to use
832+
* @write: whether it's a write fault
833+
*
834+
* Insert a pmd size pfn. See vmf_insert_pfn() for additional info and
835+
* also consult the vmf_insert_mixed_prot() documentation when
836+
* @pgprot != @vmf->vma->vm_page_prot.
837+
*
838+
* Return: vm_fault_t value.
839+
*/
840+
vm_fault_t vmf_insert_pfn_pmd_prot(struct vm_fault *vmf, pfn_t pfn,
841+
pgprot_t pgprot, bool write)
828842
{
829843
unsigned long addr = vmf->address & PMD_MASK;
830844
struct vm_area_struct *vma = vmf->vma;
831-
pgprot_t pgprot = vma->vm_page_prot;
832845
pgtable_t pgtable = NULL;
833846

834847
/*
@@ -856,7 +869,7 @@ vm_fault_t vmf_insert_pfn_pmd(struct vm_fault *vmf, pfn_t pfn, bool write)
856869
insert_pfn_pmd(vma, addr, vmf->pmd, pfn, pgprot, write, pgtable);
857870
return VM_FAULT_NOPAGE;
858871
}
859-
EXPORT_SYMBOL_GPL(vmf_insert_pfn_pmd);
872+
EXPORT_SYMBOL_GPL(vmf_insert_pfn_pmd_prot);
860873

861874
#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
862875
static pud_t maybe_pud_mkwrite(pud_t pud, struct vm_area_struct *vma)
@@ -902,11 +915,24 @@ static void insert_pfn_pud(struct vm_area_struct *vma, unsigned long addr,
902915
spin_unlock(ptl);
903916
}
904917

905-
vm_fault_t vmf_insert_pfn_pud(struct vm_fault *vmf, pfn_t pfn, bool write)
918+
/**
919+
* vmf_insert_pfn_pud_prot - insert a pud size pfn
920+
* @vmf: Structure describing the fault
921+
* @pfn: pfn to insert
922+
* @pgprot: page protection to use
923+
* @write: whether it's a write fault
924+
*
925+
* Insert a pud size pfn. See vmf_insert_pfn() for additional info and
926+
* also consult the vmf_insert_mixed_prot() documentation when
927+
* @pgprot != @vmf->vma->vm_page_prot.
928+
*
929+
* Return: vm_fault_t value.
930+
*/
931+
vm_fault_t vmf_insert_pfn_pud_prot(struct vm_fault *vmf, pfn_t pfn,
932+
pgprot_t pgprot, bool write)
906933
{
907934
unsigned long addr = vmf->address & PUD_MASK;
908935
struct vm_area_struct *vma = vmf->vma;
909-
pgprot_t pgprot = vma->vm_page_prot;
910936

911937
/*
912938
* If we had pud_special, we could avoid all these restrictions,
@@ -927,7 +953,7 @@ vm_fault_t vmf_insert_pfn_pud(struct vm_fault *vmf, pfn_t pfn, bool write)
927953
insert_pfn_pud(vma, addr, vmf->pud, pfn, pgprot, write);
928954
return VM_FAULT_NOPAGE;
929955
}
930-
EXPORT_SYMBOL_GPL(vmf_insert_pfn_pud);
956+
EXPORT_SYMBOL_GPL(vmf_insert_pfn_pud_prot);
931957
#endif /* CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD */
932958

933959
static void touch_pmd(struct vm_area_struct *vma, unsigned long addr,

0 commit comments

Comments
 (0)