linux-stable/arch/x86/hyperv
Michael Kelley 0f34d11234 x86/hyperv: Make encrypted/decrypted changes safe for load_unaligned_zeropad()
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: Michael Kelley <mhklinux@outlook.com>
Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Link: https://lore.kernel.org/r/20240116022008.1023398-4-mhklinux@outlook.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Message-ID: <20240116022008.1023398-4-mhklinux@outlook.com>
2024-03-01 08:31:42 +00:00
..
hv_apic.c arch/x86: Fix typos 2024-01-03 11:46:22 +01:00
hv_init.c x86/hyperv: Fix the detection of E820_TYPE_PRAM in a Gen2 VM 2023-11-12 22:50:30 +00:00
hv_proc.c drivers: hv: Create a consistent pattern for checking Hyper-V hypercall status 2021-04-21 09:49:19 +00:00
hv_spinlock.c x86/apic: Wrap IPI calls into helper functions 2023-08-09 12:00:55 -07:00
hv_vtl.c X86 core code updates: 2023-10-30 17:37:47 -10:00
irqdomain.c arch/x86: Fix typos 2024-01-03 11:46:22 +01:00
ivm.c x86/hyperv: Make encrypted/decrypted changes safe for load_unaligned_zeropad() 2024-03-01 08:31:42 +00:00
Makefile x86/hyperv: VTL support for Hyper-V 2023-04-18 17:29:52 +00:00
mmu.c x86/hyperv: Improve code for referencing hyperv_pcpu_input_arg 2023-06-28 17:53:25 +00:00
nested.c x86/hyperv: Improve code for referencing hyperv_pcpu_input_arg 2023-06-28 17:53:25 +00:00