Skip to content

Commit c7b5254

Browse files
kelleymhbp3tk0v
authored andcommitted
x86/mm: Handle decryption/re-encryption of bss_decrypted consistently
sme_postprocess_startup() decrypts the bss_decrypted section when sme_me_mask is non-zero. mem_encrypt_free_decrypted_mem() re-encrypts the unused portion based on CC_ATTR_MEM_ENCRYPT. In a Hyper-V guest VM using vTOM, these conditions are not equivalent as sme_me_mask is always zero when using vTOM. Consequently, mem_encrypt_free_decrypted_mem() attempts to re-encrypt memory that was never decrypted. So check sme_me_mask in mem_encrypt_free_decrypted_mem() too. Hyper-V guests using vTOM don't need the bss_decrypted section to be decrypted, so skipping the decryption/re-encryption doesn't cause a problem. Signed-off-by: Michael Kelley <mikelley@microsoft.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com> Link: https://lore.kernel.org/r/1678329614-3482-5-git-send-email-mikelley@microsoft.com
1 parent d33ddc9 commit c7b5254

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

arch/x86/mm/mem_encrypt_amd.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,10 +513,14 @@ void __init mem_encrypt_free_decrypted_mem(void)
513513
npages = (vaddr_end - vaddr) >> PAGE_SHIFT;
514514

515515
/*
516-
* The unused memory range was mapped decrypted, change the encryption
517-
* attribute from decrypted to encrypted before freeing it.
516+
* If the unused memory range was mapped decrypted, change the encryption
517+
* attribute from decrypted to encrypted before freeing it. Base the
518+
* re-encryption on the same condition used for the decryption in
519+
* sme_postprocess_startup(). Higher level abstractions, such as
520+
* CC_ATTR_MEM_ENCRYPT, aren't necessarily equivalent in a Hyper-V VM
521+
* using vTOM, where sme_me_mask is always zero.
518522
*/
519-
if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) {
523+
if (sme_me_mask) {
520524
r = set_memory_encrypted(vaddr, npages);
521525
if (r) {
522526
pr_warn("failed to free unused decrypted pages\n");

0 commit comments

Comments
 (0)