diff mbox series

[RFC,v2,7/7] Drivers: hv: Allocate persistent pages for root partition

Message ID 169567730882.19708.11955721929072363659.stgit@skinsburskii. (mailing list archive)
State New
Headers show
Series Introduce persistent memory pool | expand

Commit Message

Stanislav Kinsburskii Sept. 25, 2023, 9:28 p.m. UTC
Deposited pages are owned by the hypervisor. Accessing them can trigger a
kernel panic due to a general protection fault.

This patch ensures that pages for the root partition are allocated from the
persistent memory pool. This allocation guarantees stability post-kexec,
protecting hypervisor-deposited pages from unintended reuse by the new
kernel.

Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
---
 drivers/hv/hv_common.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index 335aec5ec504..a81c5613e745 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -426,7 +426,10 @@  int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
 		order = 31 - __builtin_clz(num_pages);
 
 		while (1) {
-			pages[i] = alloc_pages_node(node, GFP_KERNEL, order);
+			if (paritition_id == hv_current_partition_id)
+				pages[i] = pmpool_alloc(1 << order);
+			else
+				pages[i] = alloc_pages_node(node, GFP_KERNEL, order);
 			if (pages[i])
 				break;
 			if (!order) {
@@ -471,8 +474,12 @@  int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
 err_free_allocations:
 	for (i = 0; i < num_allocations; ++i) {
 		base_pfn = page_to_pfn(pages[i]);
-		for (j = 0; j < counts[i]; ++j)
-			__free_page(pfn_to_page(base_pfn + j));
+		for (j = 0; j < counts[i]; ++j) {
+			if (paritition_id == hv_current_partition_id)
+				pmpool_release(pages[i], counts[i]);
+			else
+				__free_page(pfn_to_page(base_pfn + j));
+		}
 	}
 
 free_buf: