• Brijesh Singh's avatar
    x86/mm: Do not use set_{pud, pmd}_safe() when splitting a large page · eccd9064
    Brijesh Singh authored
    The commit
    
      0a9fe8ca ("x86/mm: Validate kernel_physical_mapping_init() PTE population")
    
    triggers this warning in SEV guests:
    
      WARNING: CPU: 0 PID: 0 at arch/x86/include/asm/pgalloc.h:87 phys_pmd_init+0x30d/0x386
      Call Trace:
       kernel_physical_mapping_init+0xce/0x259
       early_set_memory_enc_dec+0x10f/0x160
       kvm_smp_prepare_boot_cpu+0x71/0x9d
       start_kernel+0x1c9/0x50b
       secondary_startup_64+0xa4/0xb0
    
    A SEV guest calls kernel_physical_mapping_init() to clear the encryption
    mask from an existing mapping. While doing so, it also splits large
    pages into smaller.
    
    To split a page, kernel_physical_mapping_init() allocates a new page and
    updates the existing entry. The set_{pud,pmd}_safe() helpers trigger a
    warning when updating an entry with a page in the present state.
    
    Add a new kernel_physical_mapping_change() helper which uses the
    non-safe variants of set_{pmd,pud,p4d}() and {pmd,pud,p4d}_populate()
    routines when updating the entry.
    
    Since kernel_physical_mapping_change() may replace an existing
    entry with a new entry, the caller is responsible to flush
    the TLB at the end. Change early_set_memory_enc_dec() to use
    kernel_physical_mapping_change() when it wants to clear the memory
    encryption mask from the page table entry.
    
     [ bp:
       - massage commit message.
       - flesh out comment according to dhansen's request.
       - align function arguments at opening brace. ]
    
    Fixes: 0a9fe8ca ("x86/mm: Validate kernel_physical_mapping_init() PTE population")
    Signed-off-by: default avatarBrijesh Singh <brijesh.singh@amd.com>
    Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
    Reviewed-by: default avatarDave Hansen <dave.hansen@intel.com>
    Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Cc: Andy Lutomirski <luto@kernel.org>
    Cc: Dan Williams <dan.j.williams@intel.com>
    Cc: "H. Peter Anvin" <hpa@zytor.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Thomas Lendacky <Thomas.Lendacky@amd.com>
    Cc: x86-ml <x86@kernel.org>
    Link: https://lkml.kernel.org/r/20190417154102.22613-1-brijesh.singh@amd.com
    eccd9064
mm_internal.h 747 Bytes