Skip to contentSkip to conversation

x86/sev: mem_encrypt_free_decrypted_mem(): encrypt the pages for AMD SME only

PATCH In review Dexuan Cui 1 participant 2 messages Nov 28, 2022

Subsystems (4)
lore
Share & tools
lore

Dexuan Cui

author maintainer
#0 lore raw

PATCH 1/1 x86/sev: mem_encrypt_free_decrypted_mem(): encrypt the pages for AMD SME only

sme_postprocess_startup() marks the __start_bss_decrypted pages shared for AMD SME only, so here set_memory_encrypted() should be called for AMD SME only, i.e. don't call the set_memory_encrypted() for TDX, otherwise the error "failed to free unused decrypted pages" appears in 'dmesg'.

Fixes b3f0907c71e0 ("x86/mm: Add .bss..decrypted section to hold shared variables")
---
 arch/x86/mm/mem_encrypt_amd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/mm/mem_encrypt_amd.c +1 -1
index 9c4d8dbcb129..fd9b58402a22 100644
@@ -516,7 +516,7 @@ void __init mem_encrypt_free_decrypted_mem(void)
 	 * The unused memory range was mapped decrypted, change the encryption
 	 * attribute from decrypted to encrypted before freeing it.
 	 */
-	if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) {
+	if (sme_me_mask && cc_platform_has(CC_ATTR_MEM_ENCRYPT)) {
 		r = set_memory_encrypted(vaddr, npages);
 		if (r) {
 			pr_warn("failed to free unused decrypted pages\n");
Signature · 1 line
2.25.1
author maintainer
#1 lore raw
Quoted 30 lines

From: Dexuan Cui <[email protected]>
Sent: Sunday, November 27, 2022 5:29 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Dexuan Cui <[email protected]>
Subject: [PATCH] x86/sev: mem_encrypt_free_decrypted_mem(): encrypt the pages for AMD SME only

sme_postprocess_startup() marks the __start_bss_decrypted pages shared for AMD SME only, so here set_memory_encrypted() should be called for AMD SME only, i.e. don't call the set_memory_encrypted() for TDX, otherwise the error "failed to free unused decrypted pages" appears in 'dmesg'.

Fixes b3f0907c71e0 ("x86/mm: Add .bss..decrypted section to hold shared

variables")

---
 arch/x86/mm/mem_encrypt_amd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/mm/mem_encrypt_amd.c +0 -0
index 9c4d8dbcb129..fd9b58402a22 100644
@@ -516,7 +516,7 @@ void __init mem_encrypt_free_decrypted_mem(void)
 	 * The unused memory range was mapped decrypted, change the

encryption

arch/x86/mm/mem_encrypt_amd.c void __init mem_encrypt_free_decrypted_mem(void)

Quoted 8 lines
arch/x86/mm/mem_encrypt_amd.c +1 -2
 	 * attribute from decrypted to encrypted before freeing it.
 	 */
-	if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) {
+	if (sme_me_mask && cc_platform_has(CC_ATTR_MEM_ENCRYPT)) {
 		r = set_memory_encrypted(vaddr, npages);
 		if (r) {
 			pr_warn("failed to free unused decrypted pages\n");
--

Please ignore this patch as Michael posted a similar patch earlier:
https://lwn.net/ml/linux-kernel/1668624097-14884-6-git-send-email-mikelley%40microsoft.com/