[PATCH v11 09/23] drivers: hv: Remove redundant clearing after decryption

Aneesh Kumar K.V (Arm) aneesh.kumar at kernel.org
Wed Dec 2 01:54:32 PST 2026


Successful set_memory_decrypted() calls now return zeroed memory. Remove
redundant post-transition clears from the Hyper-V allocation paths. Keep
explicit clearing when a path does not call the transition helper.

Cc: Haiyang Zhang <haiyangz at microsoft.com>
Cc: Wei Liu <wei.liu at kernel.org>
Cc: Dexuan Cui <decui at microsoft.com>
Cc: x86 at kernel.org
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar at kernel.org>
---
 arch/x86/hyperv/hv_init.c |  1 -
 drivers/hv/connection.c   |  7 -------
 drivers/hv/hv.c           | 10 ++++++----
 drivers/hv/hv_common.c    |  2 --
 4 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index b90e6f487533..8b3e34a9d8de 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -157,7 +157,6 @@ static int hv_cpu_init(unsigned int cpu)
 			 */
 			if (*hvp && !ms_hyperv.paravisor_present && hv_isolation_type_snp()) {
 				WARN_ON_ONCE(set_memory_decrypted((unsigned long)(*hvp), 1));
-				memset(*hvp, 0, PAGE_SIZE);
 			}
 		}
 
diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index 818667ef9c74..856b30462a7d 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
@@ -279,13 +279,6 @@ int vmbus_connect(void)
 		goto cleanup;
 	}
 
-	/*
-	 * Set_memory_decrypted() will change the memory contents if
-	 * decryption occurs, so zero monitor pages here.
-	 */
-	memset(vmbus_connection.monitor_pages[0], 0x00, HV_HYP_PAGE_SIZE);
-	memset(vmbus_connection.monitor_pages[1], 0x00, HV_HYP_PAGE_SIZE);
-
 	msginfo = kzalloc(sizeof(*msginfo) +
 			  sizeof(struct vmbus_channel_initiate_contact),
 			  GFP_KERNEL);
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index fe50090dcc01..9f23c687b57b 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -123,12 +123,14 @@ static int hv_alloc_page(void **page, bool decrypt, const char *note)
 	if (!*page)
 		return -ENOMEM;
 
-	if (decrypt)
+	if (decrypt) {
 		ret = set_memory_decrypted((unsigned long)*page, 1);
-	if (ret)
-		goto failed;
+		if (ret)
+			goto failed;
+	} else {
+		memset(*page, 0, PAGE_SIZE);
+	}
 
-	memset(*page, 0, PAGE_SIZE);
 	return 0;
 
 failed:
diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index df2577896271..404d2436346e 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -534,8 +534,6 @@ int hv_common_cpu_init(unsigned int cpu)
 				/* It may be unsafe to free 'mem' */
 				return ret;
 			}
-
-			memset(mem, 0x00, pgcount * HV_HYP_PAGE_SIZE);
 		}
 
 		/*
-- 
2.43.0




More information about the linux-arm-kernel mailing list