Skip to contentSkip to conversation

Drivers: hv: Do not free synic pages when they were not allocated

PATCH In review Nuno Das Neves 3 participants 3 messages Apr 3, 2023 – Apr 7, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Drivers: hv: Do not free synic pages when they were not allocated

In case of root partition or snp, the synic pages are allocated by the hypervisor instead of the kernel, so they should not be freed.

---
 drivers/hv/hv.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/hv/hv.c +4 -2
index c7f7652932ca..a10cf642c9ad 100644
@@ -193,8 +193,10 @@ void hv_synic_free(void)
 		struct hv_per_cpu_context *hv_cpu
 			= per_cpu_ptr(hv_context.cpu_context, cpu);
 
-		free_page((unsigned long)hv_cpu->synic_event_page);
-		free_page((unsigned long)hv_cpu->synic_message_page);
+		if (!hv_isolation_type_snp() && !hv_root_partition) {
+			free_page((unsigned long)hv_cpu->synic_event_page);
+			free_page((unsigned long)hv_cpu->synic_message_page);
+		}
 		free_page((unsigned long)hv_cpu->post_msg_page);
 	}
 
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Nuno Das Neves

In case of root partition or snp, the synic pages are allocated by the hypervisor instead of the kernel, so they should not be freed.

---
  drivers/hv/hv.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/hv/hv.c +4 -2
index c7f7652932ca..a10cf642c9ad 100644
@@ -193,8 +193,10 @@ void hv_synic_free(void)
  		struct hv_per_cpu_context *hv_cpu
  			= per_cpu_ptr(hv_context.cpu_context, cpu);
 
-		free_page((unsigned long)hv_cpu->synic_event_page);
-		free_page((unsigned long)hv_cpu->synic_message_page);
+		if (!hv_isolation_type_snp() && !hv_root_partition) {
+			free_page((unsigned long)hv_cpu->synic_event_page);
+			free_page((unsigned long)hv_cpu->synic_message_page);
+		}
  		free_page((unsigned long)hv_cpu->post_msg_page);
  	}
 
#2 lore raw
In reply to Nuno Das Neves

From: Nuno Das Neves <[email protected]> Sent: Monday, April 3, 2023 4:22 PM

Quoted 3 lines

In case of root partition or snp, the synic pages are allocated by the hypervisor instead of the kernel, so they should not be freed.

This patch doesn't hurt anything, but is it really needed? In the SNP
Isolation or root partition case, after hv_synic_alloc() has run, the synic_event_page and synic_message_page pointers are NULL. Then when hv_synic_enable_regs() is run by a particular CPU, that CPU maps the pages and the pointers are non-NULL. But the corresponding hv_synic_disable_regs() sets the pointers back to NULL, so hv_synic_free() will already skip those pages.

Is there ever a case where hv_synic_free() would run after a CPU has done hv_synic_enable_regs(), but not hv_synic_disable_regs()? If that were the case, it seems like we would have other problems, such as missing calls to iounmap().

Michael

Quoted 25 lines
---
 drivers/hv/hv.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/hv/hv.c +4 -3
index c7f7652932ca..a10cf642c9ad 100644
@@ -193,8 +193,10 @@ void hv_synic_free(void)
 		struct hv_per_cpu_context *hv_cpu
 			= per_cpu_ptr(hv_context.cpu_context, cpu);
 
-		free_page((unsigned long)hv_cpu->synic_event_page);
-		free_page((unsigned long)hv_cpu->synic_message_page);
+		if (!hv_isolation_type_snp() && !hv_root_partition) {
+			free_page((unsigned long)hv_cpu->synic_event_page);
+			free_page((unsigned long)hv_cpu->synic_message_page);
+		}
 		free_page((unsigned long)hv_cpu->post_msg_page);
 	}
 
--

2.25.1