lkml.org 
[lkml]   [2017]   [Jul]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v1 1/2] x86/mm, kexec: Fix memory corruption with SME on successive kexecs
    Date
    After issuing successive kexecs it was found that the SHA hash failed
    verification when booting the kexec'd kernel. When SME is enabled, the
    change from using pages that were marked encrypted to now being marked as
    not encrypted (through new identify mapped page tables) results in memory
    corruption if there are any cache entries for the previously encrypted
    pages. This is because separate cache entries can exist for the same
    physical location but tagged both with and without the encryption bit.

    To prevent this, issue a wbinvd before copying the pages from the source
    location to the destination location to clear any possible cache entry
    conflicts.

    Cc: <kexec@lists.infradead.org>
    Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
    ---
    arch/x86/kernel/relocate_kernel_64.S | 7 +++++++
    1 file changed, 7 insertions(+)

    diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
    index 98111b3..c11d8bc 100644
    --- a/arch/x86/kernel/relocate_kernel_64.S
    +++ b/arch/x86/kernel/relocate_kernel_64.S
    @@ -132,6 +132,13 @@ identity_mapped:
    /* Flush the TLB (needed?) */
    movq %r9, %cr3

    + /*
    + * If SME is/was active, there could be old encrypted cache line
    + * entries that will conflict with the now unencrypted memory
    + * used by kexec. Flush the caches before copying the kernel.
    + */
    + wbinvd
    +
    movq %rcx, %r11
    call swap_pages

    --
    1.9.1
    \
     
     \ /
      Last update: 2017-07-26 20:05    [W:4.560 / U:0.012 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site