Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Dave Hansen and committed by
Ingo Molnar
dcb32d99 e4a84be6

+8 -8
+6 -6
arch/x86/mm/init_64.c
··· 354 354 * pagetable pages as RO. So assume someone who pre-setup 355 355 * these mappings are more intelligent. 356 356 */ 357 - if (pte_val(*pte)) { 357 + if (!pte_none(*pte)) { 358 358 if (!after_bootmem) 359 359 pages++; 360 360 continue; ··· 396 396 continue; 397 397 } 398 398 399 - if (pmd_val(*pmd)) { 399 + if (!pmd_none(*pmd)) { 400 400 if (!pmd_large(*pmd)) { 401 401 spin_lock(&init_mm.page_table_lock); 402 402 pte = (pte_t *)pmd_page_vaddr(*pmd); ··· 470 470 continue; 471 471 } 472 472 473 - if (pud_val(*pud)) { 473 + if (!pud_none(*pud)) { 474 474 if (!pud_large(*pud)) { 475 475 pmd = pmd_offset(pud, 0); 476 476 last_map_addr = phys_pmd_init(pmd, addr, end, ··· 673 673 674 674 for (i = 0; i < PTRS_PER_PTE; i++) { 675 675 pte = pte_start + i; 676 - if (pte_val(*pte)) 676 + if (!pte_none(*pte)) 677 677 return; 678 678 } 679 679 ··· 691 691 692 692 for (i = 0; i < PTRS_PER_PMD; i++) { 693 693 pmd = pmd_start + i; 694 - if (pmd_val(*pmd)) 694 + if (!pmd_none(*pmd)) 695 695 return; 696 696 } 697 697 ··· 710 710 711 711 for (i = 0; i < PTRS_PER_PUD; i++) { 712 712 pud = pud_start + i; 713 - if (pud_val(*pud)) 713 + if (!pud_none(*pud)) 714 714 return false; 715 715 } 716 716
+1 -1
arch/x86/mm/pageattr.c
··· 1185 1185 return __cpa_process_fault(cpa, address, primary); 1186 1186 1187 1187 old_pte = *kpte; 1188 - if (!pte_val(old_pte)) 1188 + if (pte_none(old_pte)) 1189 1189 return __cpa_process_fault(cpa, address, primary); 1190 1190 1191 1191 if (level == PG_LEVEL_4K) {
+1 -1
arch/x86/mm/pgtable_32.c
··· 47 47 return; 48 48 } 49 49 pte = pte_offset_kernel(pmd, vaddr); 50 - if (pte_val(pteval)) 50 + if (!pte_none(pteval)) 51 51 set_pte_at(&init_mm, vaddr, pte, pteval); 52 52 else 53 53 pte_clear(&init_mm, vaddr, pte);