Skip to content

Commit dcb32d9

Browse files
hansendcIngo Molnar
authored andcommitted
x86/mm: Use pte_none() to test for empty PTE
The page table manipulation code seems to have grown a couple of sites that are looking for empty PTEs. Just in case one of these entries got a stray bit set, use pte_none() instead of checking for a zero pte_val(). The use pte_same() makes me a bit nervous. If we were doing a pte_same() check against two cleared entries and one of them had a stray bit set, it might fail the pte_same() check. But, I don't think we ever _do_ pte_same() for cleared entries. It is almost entirely used for checking for races in fault-in paths. Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Dave Hansen <dave@sr71.net> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Luis R. Rodriguez <mcgrof@suse.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Toshi Kani <toshi.kani@hp.com> Cc: dave.hansen@intel.com Cc: linux-mm@kvack.org Cc: mhocko@suse.com Link: http://lkml.kernel.org/r/20160708001915.813703D9@viggo.jf.intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent e4a84be commit dcb32d9

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

arch/x86/mm/init_64.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ phys_pte_init(pte_t *pte_page, unsigned long addr, unsigned long end,
354354
* pagetable pages as RO. So assume someone who pre-setup
355355
* these mappings are more intelligent.
356356
*/
357-
if (pte_val(*pte)) {
357+
if (!pte_none(*pte)) {
358358
if (!after_bootmem)
359359
pages++;
360360
continue;
@@ -396,7 +396,7 @@ phys_pmd_init(pmd_t *pmd_page, unsigned long address, unsigned long end,
396396
continue;
397397
}
398398

399-
if (pmd_val(*pmd)) {
399+
if (!pmd_none(*pmd)) {
400400
if (!pmd_large(*pmd)) {
401401
spin_lock(&init_mm.page_table_lock);
402402
pte = (pte_t *)pmd_page_vaddr(*pmd);
@@ -470,7 +470,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
470470
continue;
471471
}
472472

473-
if (pud_val(*pud)) {
473+
if (!pud_none(*pud)) {
474474
if (!pud_large(*pud)) {
475475
pmd = pmd_offset(pud, 0);
476476
last_map_addr = phys_pmd_init(pmd, addr, end,
@@ -673,7 +673,7 @@ static void __meminit free_pte_table(pte_t *pte_start, pmd_t *pmd)
673673

674674
for (i = 0; i < PTRS_PER_PTE; i++) {
675675
pte = pte_start + i;
676-
if (pte_val(*pte))
676+
if (!pte_none(*pte))
677677
return;
678678
}
679679

@@ -691,7 +691,7 @@ static void __meminit free_pmd_table(pmd_t *pmd_start, pud_t *pud)
691691

692692
for (i = 0; i < PTRS_PER_PMD; i++) {
693693
pmd = pmd_start + i;
694-
if (pmd_val(*pmd))
694+
if (!pmd_none(*pmd))
695695
return;
696696
}
697697

@@ -710,7 +710,7 @@ static bool __meminit free_pud_table(pud_t *pud_start, pgd_t *pgd)
710710

711711
for (i = 0; i < PTRS_PER_PUD; i++) {
712712
pud = pud_start + i;
713-
if (pud_val(*pud))
713+
if (!pud_none(*pud))
714714
return false;
715715
}
716716

arch/x86/mm/pageattr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ static int __change_page_attr(struct cpa_data *cpa, int primary)
11851185
return __cpa_process_fault(cpa, address, primary);
11861186

11871187
old_pte = *kpte;
1188-
if (!pte_val(old_pte))
1188+
if (pte_none(old_pte))
11891189
return __cpa_process_fault(cpa, address, primary);
11901190

11911191
if (level == PG_LEVEL_4K) {

arch/x86/mm/pgtable_32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
4747
return;
4848
}
4949
pte = pte_offset_kernel(pmd, vaddr);
50-
if (pte_val(pteval))
50+
if (!pte_none(pteval))
5151
set_pte_at(&init_mm, vaddr, pte, pteval);
5252
else
5353
pte_clear(&init_mm, vaddr, pte);

0 commit comments

Comments
 (0)