• Michael Kelley's avatar
    x86/hyperv: Make encrypted/decrypted changes safe for load_unaligned_zeropad() · 0f34d112
    Michael Kelley authored
    In a CoCo VM, when transitioning memory from encrypted to decrypted, or
    vice versa, the caller of set_memory_encrypted() or set_memory_decrypted()
    is responsible for ensuring the memory isn't in use and isn't referenced
    while the transition is in progress.  The transition has multiple steps,
    and the memory is in an inconsistent state until all steps are complete.
    A reference while the state is inconsistent could result in an exception
    that can't be cleanly fixed up.
    
    However, the kernel load_unaligned_zeropad() mechanism could cause a stray
    reference that can't be prevented by the caller of set_memory_encrypted()
    or set_memory_decrypted(), so there's specific code to handle this case.
    But a CoCo VM running on Hyper-V may be configured to run with a paravisor,
    with the #VC or #VE exception routed to the paravisor. There's no
    architectural way to forward the exceptions back to the guest kernel, and
    in such a case, the load_unaligned_zeropad() specific code doesn't work.
    
    To avoid this problem, mark pages as "not present" while a transition
    is in progress. If load_unaligned_zeropad() causes a stray reference, a
    normal page fault is generated instead of #VC or #VE, and the
    page-fault-based fixup handlers for load_unaligned_zeropad() resolve the
    reference. When the encrypted/decrypted transition is complete, mark the
    pages as "present" again.
    Signed-off-by: default avatarMichael Kelley <mhklinux@outlook.com>
    Reviewed-by: default avatarKuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
    Link: https://lore.kernel.org/r/20240116022008.1023398-4-mhklinux@outlook.comSigned-off-by: default avatarWei Liu <wei.liu@kernel.org>
    Message-ID: <20240116022008.1023398-4-mhklinux@outlook.com>
    0f34d112
ivm.c 18.1 KB