Skip to content

Commit daf3e35

Browse files
toshikaniKAGA-KOKO
authored andcommitted
x86/mm: Fix gup_huge_p?d() to handle large PAT bit
gup_huge_pud() and gup_huge_pmd() cast *pud and *pmd to *pte, and use pte_xxx() interfaces to obtain the flags and PFN. However, the pte_xxx() interface does not handle the large PAT bit properly for PUD/PMD. Fix gup_huge_pud() and gup_huge_pmd() to use pud_xxx() and pmd_xxx() interfaces according to their type. Signed-off-by: Toshi Kani <toshi.kani@hpe.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Juergen Gross <jgross@suse.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Konrad Wilk <konrad.wilk@oracle.com> Cc: Robert Elliot <elliott@hpe.com> Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/1442514264-12475-9-git-send-email-toshi.kani@hpe.com Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 34437e6 commit daf3e35

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

arch/x86/mm/gup.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,20 @@ static noinline int gup_huge_pmd(pmd_t pmd, unsigned long addr,
118118
unsigned long end, int write, struct page **pages, int *nr)
119119
{
120120
unsigned long mask;
121-
pte_t pte = *(pte_t *)&pmd;
122121
struct page *head, *page;
123122
int refs;
124123

125124
mask = _PAGE_PRESENT|_PAGE_USER;
126125
if (write)
127126
mask |= _PAGE_RW;
128-
if ((pte_flags(pte) & mask) != mask)
127+
if ((pmd_flags(pmd) & mask) != mask)
129128
return 0;
130129
/* hugepages are never "special" */
131-
VM_BUG_ON(pte_flags(pte) & _PAGE_SPECIAL);
132-
VM_BUG_ON(!pfn_valid(pte_pfn(pte)));
130+
VM_BUG_ON(pmd_flags(pmd) & _PAGE_SPECIAL);
131+
VM_BUG_ON(!pfn_valid(pmd_pfn(pmd)));
133132

134133
refs = 0;
135-
head = pte_page(pte);
134+
head = pmd_page(pmd);
136135
page = head + ((addr & ~PMD_MASK) >> PAGE_SHIFT);
137136
do {
138137
VM_BUG_ON_PAGE(compound_head(page) != head, page);
@@ -195,21 +194,20 @@ static noinline int gup_huge_pud(pud_t pud, unsigned long addr,
195194
unsigned long end, int write, struct page **pages, int *nr)
196195
{
197196
unsigned long mask;
198-
pte_t pte = *(pte_t *)&pud;
199197
struct page *head, *page;
200198
int refs;
201199

202200
mask = _PAGE_PRESENT|_PAGE_USER;
203201
if (write)
204202
mask |= _PAGE_RW;
205-
if ((pte_flags(pte) & mask) != mask)
203+
if ((pud_flags(pud) & mask) != mask)
206204
return 0;
207205
/* hugepages are never "special" */
208-
VM_BUG_ON(pte_flags(pte) & _PAGE_SPECIAL);
209-
VM_BUG_ON(!pfn_valid(pte_pfn(pte)));
206+
VM_BUG_ON(pud_flags(pud) & _PAGE_SPECIAL);
207+
VM_BUG_ON(!pfn_valid(pud_pfn(pud)));
210208

211209
refs = 0;
212-
head = pte_page(pte);
210+
head = pud_page(pud);
213211
page = head + ((addr & ~PUD_MASK) >> PAGE_SHIFT);
214212
do {
215213
VM_BUG_ON_PAGE(compound_head(page) != head, page);

0 commit comments

Comments
 (0)