public inbox for linux-hyperv@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Improve Hyper-V memory deposit error handling
@ 2026-01-23  1:35 Stanislav Kinsburskii
  2026-01-23  1:35 ` [PATCH 1/4] mshv: Introduce hv_result_oom() helper function Stanislav Kinsburskii
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Stanislav Kinsburskii @ 2026-01-23  1:35 UTC (permalink / raw)
  To: kys, haiyangz, wei.liu, decui, longli; +Cc: linux-hyperv, linux-kernel

This series extends the MSHV driver to properly handle additional
memory-related error codes from the Microsofot Hypervisor by depositing
memory pages when needed.

Currently, when the hypervisor returns HV_STATUS_INSUFFICIENT_MEMORY
during partition creation, the driver calls hv_call_deposit_pages() to
provide the necessary memory. However, there are other memory-related
error codes that indicate the hypervisor needs additional memory
resources, but the driver does not attempt to deposit pages for these
cases.

This series introduces the hv_result_oom() helper function macro to
identify all memory-related error codes (HV_STATUS_INSUFFICIENT_MEMORY,
HV_STATUS_INSUFFICIENT_BUFFERS, HV_STATUS_INSUFFICIENT_DEVICE_DOMAINS, and
HV_STATUS_INSUFFICIENT_ROOT_MEMORY) and ensures the driver attempts to
deposit pages for all of them via new hv_deposit_memory() helper.

With these changes, partition creation becomes more robust by handling
all scenarios where the hypervisor requires additional memory deposits.

---

Stanislav Kinsburskii (4):
      mshv: Introduce hv_result_oom() helper function
      mshv: Introduce hv_deposit_memory helper functions
      mshv: Handle insufficient contiguous memory hypervisor status
      mshv: Handle insufficient root memory hypervisor status


 drivers/hv/hv_common.c         |    3 ++
 drivers/hv/hv_proc.c           |   54 +++++++++++++++++++++++++++++++++++---
 drivers/hv/mshv_root_hv_call.c |   45 +++++++++++++-------------------
 drivers/hv/mshv_root_main.c    |    5 +---
 include/asm-generic/mshyperv.h |   13 +++++++++
 include/hyperv/hvgdk_mini.h    |   57 +++++++++++++++++++++-------------------
 include/hyperv/hvhdk_mini.h    |    2 +
 7 files changed, 119 insertions(+), 60 deletions(-)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/4] mshv: Introduce hv_result_oom() helper function
  2026-01-23  1:35 [PATCH 0/4] Improve Hyper-V memory deposit error handling Stanislav Kinsburskii
@ 2026-01-23  1:35 ` Stanislav Kinsburskii
  2026-01-24  0:31   ` Mukesh R
  2026-01-23  1:35 ` [PATCH 2/4] mshv: Introduce hv_deposit_memory helper functions Stanislav Kinsburskii
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: Stanislav Kinsburskii @ 2026-01-23  1:35 UTC (permalink / raw)
  To: kys, haiyangz, wei.liu, decui, longli; +Cc: linux-hyperv, linux-kernel

Replace direct comparisons of hv_result(status) against
HV_STATUS_INSUFFICIENT_MEMORY with a new hv_result_oom() helper function.
This improves code readability and provides a consistent and extendable
interface for checking out-of-memory conditions in hypercall results.

No functional changes intended.

Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
---
 drivers/hv/hv_proc.c           |   14 ++++++++++++--
 drivers/hv/mshv_root_hv_call.c |   20 ++++++++++----------
 drivers/hv/mshv_root_main.c    |    2 +-
 include/asm-generic/mshyperv.h |    3 +++
 4 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
index fbb4eb3901bb..80c66d1c74d5 100644
--- a/drivers/hv/hv_proc.c
+++ b/drivers/hv/hv_proc.c
@@ -110,6 +110,16 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
 }
 EXPORT_SYMBOL_GPL(hv_call_deposit_pages);
 
+bool hv_result_oom(u64 status)
+{
+	switch (hv_result(status)) {
+	case HV_STATUS_INSUFFICIENT_MEMORY:
+		return true;
+	}
+	return false;
+}
+EXPORT_SYMBOL_GPL(hv_result_oom);
+
 int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
 {
 	struct hv_input_add_logical_processor *input;
@@ -137,7 +147,7 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
 					 input, output);
 		local_irq_restore(flags);
 
-		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
+		if (!hv_result_oom(status)) {
 			if (!hv_result_success(status)) {
 				hv_status_err(status, "cpu %u apic ID: %u\n",
 					      lp_index, apic_id);
@@ -179,7 +189,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
 		status = hv_do_hypercall(HVCALL_CREATE_VP, input, NULL);
 		local_irq_restore(irq_flags);
 
-		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
+		if (!hv_result_oom(status)) {
 			if (!hv_result_success(status)) {
 				hv_status_err(status, "vcpu: %u, lp: %u\n",
 					      vp_index, flags);
diff --git a/drivers/hv/mshv_root_hv_call.c b/drivers/hv/mshv_root_hv_call.c
index 598eaff4ff29..58c5cbf2e567 100644
--- a/drivers/hv/mshv_root_hv_call.c
+++ b/drivers/hv/mshv_root_hv_call.c
@@ -115,7 +115,7 @@ int hv_call_create_partition(u64 flags,
 		status = hv_do_hypercall(HVCALL_CREATE_PARTITION,
 					 input, output);
 
-		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
+		if (!hv_result_oom(status)) {
 			if (hv_result_success(status))
 				*partition_id = output->partition_id;
 			local_irq_restore(irq_flags);
@@ -147,7 +147,7 @@ int hv_call_initialize_partition(u64 partition_id)
 		status = hv_do_fast_hypercall8(HVCALL_INITIALIZE_PARTITION,
 					       *(u64 *)&input);
 
-		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
+		if (!hv_result_oom(status)) {
 			ret = hv_result_to_errno(status);
 			break;
 		}
@@ -239,7 +239,7 @@ static int hv_do_map_gpa_hcall(u64 partition_id, u64 gfn, u64 page_struct_count,
 
 		completed = hv_repcomp(status);
 
-		if (hv_result(status) == HV_STATUS_INSUFFICIENT_MEMORY) {
+		if (hv_result_oom(status)) {
 			ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id,
 						    HV_MAP_GPA_DEPOSIT_PAGES);
 			if (ret)
@@ -455,7 +455,7 @@ int hv_call_get_vp_state(u32 vp_index, u64 partition_id,
 
 		status = hv_do_hypercall(control, input, output);
 
-		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
+		if (!hv_result_oom(status)) {
 			if (hv_result_success(status) && ret_output)
 				memcpy(ret_output, output, sizeof(*output));
 
@@ -518,7 +518,7 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_id,
 
 		status = hv_do_hypercall(control, input, NULL);
 
-		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
+		if (!hv_result_oom(status)) {
 			local_irq_restore(flags);
 			ret = hv_result_to_errno(status);
 			break;
@@ -563,7 +563,7 @@ static int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
 		status = hv_do_hypercall(HVCALL_MAP_VP_STATE_PAGE, input,
 					 output);
 
-		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
+		if (!hv_result_oom(status)) {
 			if (hv_result_success(status))
 				*state_page = pfn_to_page(output->map_location);
 			local_irq_restore(flags);
@@ -718,7 +718,7 @@ hv_call_create_port(u64 port_partition_id, union hv_port_id port_id,
 		if (hv_result_success(status))
 			break;
 
-		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
+		if (!hv_result_oom(status)) {
 			ret = hv_result_to_errno(status);
 			break;
 		}
@@ -772,7 +772,7 @@ hv_call_connect_port(u64 port_partition_id, union hv_port_id port_id,
 		if (hv_result_success(status))
 			break;
 
-		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
+		if (!hv_result_oom(status)) {
 			ret = hv_result_to_errno(status);
 			break;
 		}
@@ -843,7 +843,7 @@ static int hv_call_map_stats_page2(enum hv_stats_object_type type,
 		if (!ret)
 			break;
 
-		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
+		if (!hv_result_oom(status)) {
 			hv_status_debug(status, "\n");
 			break;
 		}
@@ -878,7 +878,7 @@ static int hv_call_map_stats_page(enum hv_stats_object_type type,
 		pfn = output->map_location;
 
 		local_irq_restore(flags);
-		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
+		if (!hv_result_oom(status)) {
 			ret = hv_result_to_errno(status);
 			if (hv_result_success(status))
 				break;
diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
index 7a36297feea7..f4697497f83e 100644
--- a/drivers/hv/mshv_root_main.c
+++ b/drivers/hv/mshv_root_main.c
@@ -261,7 +261,7 @@ static int mshv_ioctl_passthru_hvcall(struct mshv_partition *partition,
 		if (hv_result_success(status))
 			break;
 
-		if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY)
+		if (!hv_result_oom(status))
 			ret = hv_result_to_errno(status);
 		else
 			ret = hv_call_deposit_pages(NUMA_NO_NODE,
diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
index ecedab554c80..b73352a7fc9e 100644
--- a/include/asm-generic/mshyperv.h
+++ b/include/asm-generic/mshyperv.h
@@ -342,6 +342,8 @@ static inline bool hv_parent_partition(void)
 {
 	return hv_root_partition() || hv_l1vh_partition();
 }
+
+bool hv_result_oom(u64 status);
 int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
 int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
 int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
@@ -350,6 +352,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
 static inline bool hv_root_partition(void) { return false; }
 static inline bool hv_l1vh_partition(void) { return false; }
 static inline bool hv_parent_partition(void) { return false; }
+static inline bool hv_result_oom(u64 status) { return false; }
 static inline int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
 {
 	return -EOPNOTSUPP;



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/4] mshv: Introduce hv_deposit_memory helper functions
  2026-01-23  1:35 [PATCH 0/4] Improve Hyper-V memory deposit error handling Stanislav Kinsburskii
  2026-01-23  1:35 ` [PATCH 1/4] mshv: Introduce hv_result_oom() helper function Stanislav Kinsburskii
@ 2026-01-23  1:35 ` Stanislav Kinsburskii
  2026-01-24  0:33   ` Mukesh R
  2026-01-23  1:35 ` [PATCH 3/4] mshv: Handle insufficient contiguous memory hypervisor status Stanislav Kinsburskii
  2026-01-23  1:35 ` [PATCH 4/4] mshv: Handle insufficient root memory hypervisor statuses Stanislav Kinsburskii
  3 siblings, 1 reply; 13+ messages in thread
From: Stanislav Kinsburskii @ 2026-01-23  1:35 UTC (permalink / raw)
  To: kys, haiyangz, wei.liu, decui, longli; +Cc: linux-hyperv, linux-kernel

Introduce hv_deposit_memory_node() and hv_deposit_memory() helper
functions to handle memory deposition with proper error handling.

The new hv_deposit_memory_node() function takes the hypervisor status
as a parameter and validates it before depositing pages. It checks for
HV_STATUS_INSUFFICIENT_MEMORY specifically and returns an error for
unexpected status codes.

This is a precursor patch to new out-of-memory error codes support.
No functional changes intended.

Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
---
 drivers/hv/hv_proc.c           |   22 ++++++++++++++++++++--
 drivers/hv/mshv_root_hv_call.c |   25 +++++++++----------------
 drivers/hv/mshv_root_main.c    |    3 +--
 include/asm-generic/mshyperv.h |   10 ++++++++++
 4 files changed, 40 insertions(+), 20 deletions(-)

diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
index 80c66d1c74d5..c0c2bfc80d77 100644
--- a/drivers/hv/hv_proc.c
+++ b/drivers/hv/hv_proc.c
@@ -110,6 +110,23 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
 }
 EXPORT_SYMBOL_GPL(hv_call_deposit_pages);
 
+int hv_deposit_memory_node(int node, u64 partition_id,
+			   u64 hv_status)
+{
+	u32 num_pages;
+
+	switch (hv_result(hv_status)) {
+	case HV_STATUS_INSUFFICIENT_MEMORY:
+		num_pages = 1;
+		break;
+	default:
+		hv_status_err(hv_status, "Unexpected!\n");
+		return -ENOMEM;
+	}
+	return hv_call_deposit_pages(node, partition_id, num_pages);
+}
+EXPORT_SYMBOL_GPL(hv_deposit_memory_node);
+
 bool hv_result_oom(u64 status)
 {
 	switch (hv_result(status)) {
@@ -155,7 +172,8 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
 			}
 			break;
 		}
-		ret = hv_call_deposit_pages(node, hv_current_partition_id, 1);
+		ret = hv_deposit_memory_node(node, hv_current_partition_id,
+					     status);
 	} while (!ret);
 
 	return ret;
@@ -197,7 +215,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
 			}
 			break;
 		}
-		ret = hv_call_deposit_pages(node, partition_id, 1);
+		ret = hv_deposit_memory_node(node, partition_id, status);
 
 	} while (!ret);
 
diff --git a/drivers/hv/mshv_root_hv_call.c b/drivers/hv/mshv_root_hv_call.c
index 58c5cbf2e567..06f2bac8039d 100644
--- a/drivers/hv/mshv_root_hv_call.c
+++ b/drivers/hv/mshv_root_hv_call.c
@@ -123,8 +123,7 @@ int hv_call_create_partition(u64 flags,
 			break;
 		}
 		local_irq_restore(irq_flags);
-		ret = hv_call_deposit_pages(NUMA_NO_NODE,
-					    hv_current_partition_id, 1);
+		ret = hv_deposit_memory(hv_current_partition_id, status);
 	} while (!ret);
 
 	return ret;
@@ -151,7 +150,7 @@ int hv_call_initialize_partition(u64 partition_id)
 			ret = hv_result_to_errno(status);
 			break;
 		}
-		ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
+		ret = hv_deposit_memory(partition_id, status);
 	} while (!ret);
 
 	return ret;
@@ -465,8 +464,7 @@ int hv_call_get_vp_state(u32 vp_index, u64 partition_id,
 		}
 		local_irq_restore(flags);
 
-		ret = hv_call_deposit_pages(NUMA_NO_NODE,
-					    partition_id, 1);
+		ret = hv_deposit_memory(partition_id, status);
 	} while (!ret);
 
 	return ret;
@@ -525,8 +523,7 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_id,
 		}
 		local_irq_restore(flags);
 
-		ret = hv_call_deposit_pages(NUMA_NO_NODE,
-					    partition_id, 1);
+		ret = hv_deposit_memory(partition_id, status);
 	} while (!ret);
 
 	return ret;
@@ -573,7 +570,7 @@ static int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
 
 		local_irq_restore(flags);
 
-		ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
+		ret = hv_deposit_memory(partition_id, status);
 	} while (!ret);
 
 	return ret;
@@ -722,8 +719,7 @@ hv_call_create_port(u64 port_partition_id, union hv_port_id port_id,
 			ret = hv_result_to_errno(status);
 			break;
 		}
-		ret = hv_call_deposit_pages(NUMA_NO_NODE, port_partition_id, 1);
-
+		ret = hv_deposit_memory(port_partition_id, status);
 	} while (!ret);
 
 	return ret;
@@ -776,8 +772,7 @@ hv_call_connect_port(u64 port_partition_id, union hv_port_id port_id,
 			ret = hv_result_to_errno(status);
 			break;
 		}
-		ret = hv_call_deposit_pages(NUMA_NO_NODE,
-					    connection_partition_id, 1);
+		ret = hv_deposit_memory(connection_partition_id, status);
 	} while (!ret);
 
 	return ret;
@@ -848,8 +843,7 @@ static int hv_call_map_stats_page2(enum hv_stats_object_type type,
 			break;
 		}
 
-		ret = hv_call_deposit_pages(NUMA_NO_NODE,
-					    hv_current_partition_id, 1);
+		ret = hv_deposit_memory(hv_current_partition_id, status);
 	} while (!ret);
 
 	return ret;
@@ -885,8 +879,7 @@ static int hv_call_map_stats_page(enum hv_stats_object_type type,
 			return ret;
 		}
 
-		ret = hv_call_deposit_pages(NUMA_NO_NODE,
-					    hv_current_partition_id, 1);
+		ret = hv_deposit_memory(hv_current_partition_id, status);
 		if (ret)
 			return ret;
 	} while (!ret);
diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
index f4697497f83e..5fc572e31cd7 100644
--- a/drivers/hv/mshv_root_main.c
+++ b/drivers/hv/mshv_root_main.c
@@ -264,8 +264,7 @@ static int mshv_ioctl_passthru_hvcall(struct mshv_partition *partition,
 		if (!hv_result_oom(status))
 			ret = hv_result_to_errno(status);
 		else
-			ret = hv_call_deposit_pages(NUMA_NO_NODE,
-						    pt_id, 1);
+			ret = hv_deposit_memory(pt_id, status);
 	} while (!ret);
 
 	args.status = hv_result(status);
diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
index b73352a7fc9e..c8e8976839f8 100644
--- a/include/asm-generic/mshyperv.h
+++ b/include/asm-generic/mshyperv.h
@@ -344,6 +344,7 @@ static inline bool hv_parent_partition(void)
 }
 
 bool hv_result_oom(u64 status);
+int hv_deposit_memory_node(int node, u64 partition_id, u64 status);
 int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
 int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
 int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
@@ -353,6 +354,10 @@ static inline bool hv_root_partition(void) { return false; }
 static inline bool hv_l1vh_partition(void) { return false; }
 static inline bool hv_parent_partition(void) { return false; }
 static inline bool hv_result_oom(u64 status) { return false; }
+static inline int hv_deposit_memory_node(int node, u64 partition_id, u64 status)
+{
+	return -EOPNOTSUPP;
+}
 static inline int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
 {
 	return -EOPNOTSUPP;
@@ -367,6 +372,11 @@ static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u3
 }
 #endif /* CONFIG_MSHV_ROOT */
 
+static inline int hv_deposit_memory(u64 partition_id, u64 status)
+{
+	return hv_deposit_memory_node(NUMA_NO_NODE, partition_id, status);
+}
+
 #if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
 u8 __init get_vtl(void);
 #else



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/4] mshv: Handle insufficient contiguous memory hypervisor status
  2026-01-23  1:35 [PATCH 0/4] Improve Hyper-V memory deposit error handling Stanislav Kinsburskii
  2026-01-23  1:35 ` [PATCH 1/4] mshv: Introduce hv_result_oom() helper function Stanislav Kinsburskii
  2026-01-23  1:35 ` [PATCH 2/4] mshv: Introduce hv_deposit_memory helper functions Stanislav Kinsburskii
@ 2026-01-23  1:35 ` Stanislav Kinsburskii
  2026-01-23  1:35 ` [PATCH 4/4] mshv: Handle insufficient root memory hypervisor statuses Stanislav Kinsburskii
  3 siblings, 0 replies; 13+ messages in thread
From: Stanislav Kinsburskii @ 2026-01-23  1:35 UTC (permalink / raw)
  To: kys, haiyangz, wei.liu, decui, longli; +Cc: linux-hyperv, linux-kernel

The HV_STATUS_INSUFFICIENT_CONTIGUOUS_MEMORY status indicates that the
hypervisor lacks sufficient contiguous memory for its internal allocations.

When this status is encountered, allocate and deposit
HV_MAX_CONTIGUOUS_ALLOCATION_PAGES contiguous pages to the hypervisor.
HV_MAX_CONTIGUOUS_ALLOCATION_PAGES is defined in the hypervisor headers, a
deposit of this size will always satisfy the hypervisor's requirements.

Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
---
 drivers/hv/hv_common.c      |    1 +
 drivers/hv/hv_proc.c        |    4 ++++
 include/hyperv/hvgdk_mini.h |    1 +
 include/hyperv/hvhdk_mini.h |    2 ++
 4 files changed, 8 insertions(+)

diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index 0a3ab7efed46..c7f63c9de503 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -791,6 +791,7 @@ static const struct hv_status_info hv_status_infos[] = {
 	_STATUS_INFO(HV_STATUS_UNKNOWN_PROPERTY,		-EIO),
 	_STATUS_INFO(HV_STATUS_PROPERTY_VALUE_OUT_OF_RANGE,	-EIO),
 	_STATUS_INFO(HV_STATUS_INSUFFICIENT_MEMORY,		-ENOMEM),
+	_STATUS_INFO(HV_STATUS_INSUFFICIENT_CONTIGUOUS_MEMORY,	-ENOMEM),
 	_STATUS_INFO(HV_STATUS_INVALID_PARTITION_ID,		-EINVAL),
 	_STATUS_INFO(HV_STATUS_INVALID_VP_INDEX,		-EINVAL),
 	_STATUS_INFO(HV_STATUS_NOT_FOUND,			-EIO),
diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
index c0c2bfc80d77..ac21e16f9348 100644
--- a/drivers/hv/hv_proc.c
+++ b/drivers/hv/hv_proc.c
@@ -119,6 +119,9 @@ int hv_deposit_memory_node(int node, u64 partition_id,
 	case HV_STATUS_INSUFFICIENT_MEMORY:
 		num_pages = 1;
 		break;
+	case HV_STATUS_INSUFFICIENT_CONTIGUOUS_MEMORY:
+		num_pages = HV_MAX_CONTIGUOUS_ALLOCATION_PAGES;
+		break;
 	default:
 		hv_status_err(hv_status, "Unexpected!\n");
 		return -ENOMEM;
@@ -131,6 +134,7 @@ bool hv_result_oom(u64 status)
 {
 	switch (hv_result(status)) {
 	case HV_STATUS_INSUFFICIENT_MEMORY:
+	case HV_STATUS_INSUFFICIENT_CONTIGUOUS_MEMORY:
 		return true;
 	}
 	return false;
diff --git a/include/hyperv/hvgdk_mini.h b/include/hyperv/hvgdk_mini.h
index 04b18d0e37af..70f22ef44948 100644
--- a/include/hyperv/hvgdk_mini.h
+++ b/include/hyperv/hvgdk_mini.h
@@ -38,6 +38,7 @@ struct hv_u128 {
 #define HV_STATUS_INVALID_LP_INDEX		    0x41
 #define HV_STATUS_INVALID_REGISTER_VALUE	    0x50
 #define HV_STATUS_OPERATION_FAILED		    0x71
+#define HV_STATUS_INSUFFICIENT_CONTIGUOUS_MEMORY    0x75
 #define HV_STATUS_TIME_OUT			    0x78
 #define HV_STATUS_CALL_PENDING			    0x79
 #define HV_STATUS_VTL_ALREADY_ENABLED		    0x86
diff --git a/include/hyperv/hvhdk_mini.h b/include/hyperv/hvhdk_mini.h
index 0f7178fa88a8..c5cfe13fae57 100644
--- a/include/hyperv/hvhdk_mini.h
+++ b/include/hyperv/hvhdk_mini.h
@@ -7,6 +7,8 @@
 
 #include "hvgdk_mini.h"
 
+#define HV_MAX_CONTIGUOUS_ALLOCATION_PAGES	8
+
 /*
  * Doorbell connection_info flags.
  */



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 4/4] mshv: Handle insufficient root memory hypervisor statuses
  2026-01-23  1:35 [PATCH 0/4] Improve Hyper-V memory deposit error handling Stanislav Kinsburskii
                   ` (2 preceding siblings ...)
  2026-01-23  1:35 ` [PATCH 3/4] mshv: Handle insufficient contiguous memory hypervisor status Stanislav Kinsburskii
@ 2026-01-23  1:35 ` Stanislav Kinsburskii
  3 siblings, 0 replies; 13+ messages in thread
From: Stanislav Kinsburskii @ 2026-01-23  1:35 UTC (permalink / raw)
  To: kys, haiyangz, wei.liu, decui, longli; +Cc: linux-hyperv, linux-kernel

When creating guest partition objects, the hypervisor may fail to
allocate root partition pages and return an insufficient memory status.
In this case, deposit memory using the root partition ID instead.

Note: This error should never occur in a guest of L1VH partition context.

Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
---
 drivers/hv/hv_common.c      |    2 +
 drivers/hv/hv_proc.c        |   14 ++++++++++
 include/hyperv/hvgdk_mini.h |   58 ++++++++++++++++++++++---------------------
 3 files changed, 46 insertions(+), 28 deletions(-)

diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index c7f63c9de503..cab0d1733607 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -792,6 +792,8 @@ static const struct hv_status_info hv_status_infos[] = {
 	_STATUS_INFO(HV_STATUS_PROPERTY_VALUE_OUT_OF_RANGE,	-EIO),
 	_STATUS_INFO(HV_STATUS_INSUFFICIENT_MEMORY,		-ENOMEM),
 	_STATUS_INFO(HV_STATUS_INSUFFICIENT_CONTIGUOUS_MEMORY,	-ENOMEM),
+	_STATUS_INFO(HV_STATUS_INSUFFICIENT_ROOT_MEMORY,	-ENOMEM),
+	_STATUS_INFO(HV_STATUS_INSUFFICIENT_CONTIGUOUS_ROOT_MEMORY,	-ENOMEM),
 	_STATUS_INFO(HV_STATUS_INVALID_PARTITION_ID,		-EINVAL),
 	_STATUS_INFO(HV_STATUS_INVALID_VP_INDEX,		-EINVAL),
 	_STATUS_INFO(HV_STATUS_NOT_FOUND,			-EIO),
diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
index ac21e16f9348..89870c1b0087 100644
--- a/drivers/hv/hv_proc.c
+++ b/drivers/hv/hv_proc.c
@@ -122,6 +122,18 @@ int hv_deposit_memory_node(int node, u64 partition_id,
 	case HV_STATUS_INSUFFICIENT_CONTIGUOUS_MEMORY:
 		num_pages = HV_MAX_CONTIGUOUS_ALLOCATION_PAGES;
 		break;
+
+	case HV_STATUS_INSUFFICIENT_CONTIGUOUS_ROOT_MEMORY:
+		num_pages = HV_MAX_CONTIGUOUS_ALLOCATION_PAGES;
+		fallthrough;
+	case HV_STATUS_INSUFFICIENT_ROOT_MEMORY:
+		if (!hv_root_partition()) {
+			hv_status_err(hv_status, "Unexpected root memory deposit\n");
+			return -ENOMEM;
+		}
+		partition_id = HV_PARTITION_ID_SELF;
+		break;
+
 	default:
 		hv_status_err(hv_status, "Unexpected!\n");
 		return -ENOMEM;
@@ -135,6 +147,8 @@ bool hv_result_oom(u64 status)
 	switch (hv_result(status)) {
 	case HV_STATUS_INSUFFICIENT_MEMORY:
 	case HV_STATUS_INSUFFICIENT_CONTIGUOUS_MEMORY:
+	case HV_STATUS_INSUFFICIENT_ROOT_MEMORY:
+	case HV_STATUS_INSUFFICIENT_CONTIGUOUS_ROOT_MEMORY:
 		return true;
 	}
 	return false;
diff --git a/include/hyperv/hvgdk_mini.h b/include/hyperv/hvgdk_mini.h
index 70f22ef44948..5b74a857ef43 100644
--- a/include/hyperv/hvgdk_mini.h
+++ b/include/hyperv/hvgdk_mini.h
@@ -14,34 +14,36 @@ struct hv_u128 {
 } __packed;
 
 /* NOTE: when adding below, update hv_result_to_string() */
-#define HV_STATUS_SUCCESS			    0x0
-#define HV_STATUS_INVALID_HYPERCALL_CODE	    0x2
-#define HV_STATUS_INVALID_HYPERCALL_INPUT	    0x3
-#define HV_STATUS_INVALID_ALIGNMENT		    0x4
-#define HV_STATUS_INVALID_PARAMETER		    0x5
-#define HV_STATUS_ACCESS_DENIED			    0x6
-#define HV_STATUS_INVALID_PARTITION_STATE	    0x7
-#define HV_STATUS_OPERATION_DENIED		    0x8
-#define HV_STATUS_UNKNOWN_PROPERTY		    0x9
-#define HV_STATUS_PROPERTY_VALUE_OUT_OF_RANGE	    0xA
-#define HV_STATUS_INSUFFICIENT_MEMORY		    0xB
-#define HV_STATUS_INVALID_PARTITION_ID		    0xD
-#define HV_STATUS_INVALID_VP_INDEX		    0xE
-#define HV_STATUS_NOT_FOUND			    0x10
-#define HV_STATUS_INVALID_PORT_ID		    0x11
-#define HV_STATUS_INVALID_CONNECTION_ID		    0x12
-#define HV_STATUS_INSUFFICIENT_BUFFERS		    0x13
-#define HV_STATUS_NOT_ACKNOWLEDGED		    0x14
-#define HV_STATUS_INVALID_VP_STATE		    0x15
-#define HV_STATUS_NO_RESOURCES			    0x1D
-#define HV_STATUS_PROCESSOR_FEATURE_NOT_SUPPORTED   0x20
-#define HV_STATUS_INVALID_LP_INDEX		    0x41
-#define HV_STATUS_INVALID_REGISTER_VALUE	    0x50
-#define HV_STATUS_OPERATION_FAILED		    0x71
-#define HV_STATUS_INSUFFICIENT_CONTIGUOUS_MEMORY    0x75
-#define HV_STATUS_TIME_OUT			    0x78
-#define HV_STATUS_CALL_PENDING			    0x79
-#define HV_STATUS_VTL_ALREADY_ENABLED		    0x86
+#define HV_STATUS_SUCCESS				0x0
+#define HV_STATUS_INVALID_HYPERCALL_CODE		0x2
+#define HV_STATUS_INVALID_HYPERCALL_INPUT		0x3
+#define HV_STATUS_INVALID_ALIGNMENT			0x4
+#define HV_STATUS_INVALID_PARAMETER			0x5
+#define HV_STATUS_ACCESS_DENIED				0x6
+#define HV_STATUS_INVALID_PARTITION_STATE		0x7
+#define HV_STATUS_OPERATION_DENIED			0x8
+#define HV_STATUS_UNKNOWN_PROPERTY			0x9
+#define HV_STATUS_PROPERTY_VALUE_OUT_OF_RANGE		0xA
+#define HV_STATUS_INSUFFICIENT_MEMORY			0xB
+#define HV_STATUS_INVALID_PARTITION_ID			0xD
+#define HV_STATUS_INVALID_VP_INDEX			0xE
+#define HV_STATUS_NOT_FOUND				0x10
+#define HV_STATUS_INVALID_PORT_ID			0x11
+#define HV_STATUS_INVALID_CONNECTION_ID			0x12
+#define HV_STATUS_INSUFFICIENT_BUFFERS			0x13
+#define HV_STATUS_NOT_ACKNOWLEDGED			0x14
+#define HV_STATUS_INVALID_VP_STATE			0x15
+#define HV_STATUS_NO_RESOURCES				0x1D
+#define HV_STATUS_PROCESSOR_FEATURE_NOT_SUPPORTED	0x20
+#define HV_STATUS_INVALID_LP_INDEX			0x41
+#define HV_STATUS_INVALID_REGISTER_VALUE		0x50
+#define HV_STATUS_OPERATION_FAILED			0x71
+#define HV_STATUS_INSUFFICIENT_ROOT_MEMORY		0x73
+#define HV_STATUS_INSUFFICIENT_CONTIGUOUS_MEMORY	0x75
+#define HV_STATUS_TIME_OUT				0x78
+#define HV_STATUS_CALL_PENDING				0x79
+#define HV_STATUS_INSUFFICIENT_CONTIGUOUS_ROOT_MEMORY	0x83
+#define HV_STATUS_VTL_ALREADY_ENABLED			0x86
 
 /*
  * The Hyper-V TimeRefCount register and the TSC



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/4] mshv: Introduce hv_result_oom() helper function
  2026-01-23  1:35 ` [PATCH 1/4] mshv: Introduce hv_result_oom() helper function Stanislav Kinsburskii
@ 2026-01-24  0:31   ` Mukesh R
  0 siblings, 0 replies; 13+ messages in thread
From: Mukesh R @ 2026-01-24  0:31 UTC (permalink / raw)
  To: Stanislav Kinsburskii, kys, haiyangz, wei.liu, decui, longli
  Cc: linux-hyperv, linux-kernel

On 1/22/26 17:35, Stanislav Kinsburskii wrote:
> Replace direct comparisons of hv_result(status) against
> HV_STATUS_INSUFFICIENT_MEMORY with a new hv_result_oom() helper function.
> This improves code readability and provides a consistent and extendable
> interface for checking out-of-memory conditions in hypercall results.
> 
> No functional changes intended.
> 
> Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
> ---
>   drivers/hv/hv_proc.c           |   14 ++++++++++++--
>   drivers/hv/mshv_root_hv_call.c |   20 ++++++++++----------
>   drivers/hv/mshv_root_main.c    |    2 +-
>   include/asm-generic/mshyperv.h |    3 +++
>   4 files changed, 26 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
> index fbb4eb3901bb..80c66d1c74d5 100644
> --- a/drivers/hv/hv_proc.c
> +++ b/drivers/hv/hv_proc.c
> @@ -110,6 +110,16 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
>   }
>   EXPORT_SYMBOL_GPL(hv_call_deposit_pages);
>   
> +bool hv_result_oom(u64 status)
> +{
> +	switch (hv_result(status)) {
> +	case HV_STATUS_INSUFFICIENT_MEMORY:
> +		return true;
> +	}
> +	return false;
> +}
> +EXPORT_SYMBOL_GPL(hv_result_oom);

I had mentioned this during internal review previously, so forgive me
for repeating. I don't think using _oom suffix is a good idea. Firstly,
system is not out of memory, hypervisor will continue to work perfectly,
just the particalur hypercall needs a bit more ram to succeed. Secondly
and more importantly, "oom" has come to mean a very specific event
in linux, and as such reusing it for something totally different is
unnecessary. For example, if another maintainer working on oom happens
to see this, and not being familiar with HyperV may get totally confused
and waste time unnecessarily.

It can easily be renamed: hv_result_insuff_mem, or hv_result_enomem,
or hv_result_deposit_ram etc... there are many options.

Thanks,
-Mukesh

.... deleted ...


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/4] mshv: Introduce hv_deposit_memory helper functions
  2026-01-23  1:35 ` [PATCH 2/4] mshv: Introduce hv_deposit_memory helper functions Stanislav Kinsburskii
@ 2026-01-24  0:33   ` Mukesh R
  2026-01-25 22:41     ` Stanislav Kinsburskii
  0 siblings, 1 reply; 13+ messages in thread
From: Mukesh R @ 2026-01-24  0:33 UTC (permalink / raw)
  To: Stanislav Kinsburskii, kys, haiyangz, wei.liu, decui, longli
  Cc: linux-hyperv, linux-kernel

On 1/22/26 17:35, Stanislav Kinsburskii wrote:
> Introduce hv_deposit_memory_node() and hv_deposit_memory() helper
> functions to handle memory deposition with proper error handling.
> 
> The new hv_deposit_memory_node() function takes the hypervisor status
> as a parameter and validates it before depositing pages. It checks for
> HV_STATUS_INSUFFICIENT_MEMORY specifically and returns an error for
> unexpected status codes.
> 
> This is a precursor patch to new out-of-memory error codes support.
> No functional changes intended.
> 
> Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
> ---
>   drivers/hv/hv_proc.c           |   22 ++++++++++++++++++++--
>   drivers/hv/mshv_root_hv_call.c |   25 +++++++++----------------
>   drivers/hv/mshv_root_main.c    |    3 +--
>   include/asm-generic/mshyperv.h |   10 ++++++++++
>   4 files changed, 40 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
> index 80c66d1c74d5..c0c2bfc80d77 100644
> --- a/drivers/hv/hv_proc.c
> +++ b/drivers/hv/hv_proc.c
> @@ -110,6 +110,23 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
>   }
>   EXPORT_SYMBOL_GPL(hv_call_deposit_pages);
>   
> +int hv_deposit_memory_node(int node, u64 partition_id,
> +			   u64 hv_status)
> +{
> +	u32 num_pages;
> +
> +	switch (hv_result(hv_status)) {
> +	case HV_STATUS_INSUFFICIENT_MEMORY:
> +		num_pages = 1;
> +		break;
> +	default:
> +		hv_status_err(hv_status, "Unexpected!\n");
> +		return -ENOMEM;
> +	}
> +	return hv_call_deposit_pages(node, partition_id, num_pages);
> +}
> +EXPORT_SYMBOL_GPL(hv_deposit_memory_node);
> +

Different hypercalls may want to deposit different number of pages in one
shot. As feature evolves, page sizes get mixed, we'd almost need that
flexibility. So, imo, either we just don't do this for now, or add num pages
parameter to be passed down.

Thanks,
-Mukesh



>   bool hv_result_oom(u64 status)
>   {
>   	switch (hv_result(status)) {
> @@ -155,7 +172,8 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
>   			}
>   			break;
>   		}
> -		ret = hv_call_deposit_pages(node, hv_current_partition_id, 1);
> +		ret = hv_deposit_memory_node(node, hv_current_partition_id,
> +					     status);
>   	} while (!ret);
>   
>   	return ret;
> @@ -197,7 +215,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
>   			}
>   			break;
>   		}
> -		ret = hv_call_deposit_pages(node, partition_id, 1);
> +		ret = hv_deposit_memory_node(node, partition_id, status);
>   
>   	} while (!ret);
>   
> diff --git a/drivers/hv/mshv_root_hv_call.c b/drivers/hv/mshv_root_hv_call.c
> index 58c5cbf2e567..06f2bac8039d 100644
> --- a/drivers/hv/mshv_root_hv_call.c
> +++ b/drivers/hv/mshv_root_hv_call.c
> @@ -123,8 +123,7 @@ int hv_call_create_partition(u64 flags,
>   			break;
>   		}
>   		local_irq_restore(irq_flags);
> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> -					    hv_current_partition_id, 1);
> +		ret = hv_deposit_memory(hv_current_partition_id, status);
>   	} while (!ret);
>   
>   	return ret;
> @@ -151,7 +150,7 @@ int hv_call_initialize_partition(u64 partition_id)
>   			ret = hv_result_to_errno(status);
>   			break;
>   		}
> -		ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
> +		ret = hv_deposit_memory(partition_id, status);
>   	} while (!ret);
>   
>   	return ret;
> @@ -465,8 +464,7 @@ int hv_call_get_vp_state(u32 vp_index, u64 partition_id,
>   		}
>   		local_irq_restore(flags);
>   
> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> -					    partition_id, 1);
> +		ret = hv_deposit_memory(partition_id, status);
>   	} while (!ret);
>   
>   	return ret;
> @@ -525,8 +523,7 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_id,
>   		}
>   		local_irq_restore(flags);
>   
> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> -					    partition_id, 1);
> +		ret = hv_deposit_memory(partition_id, status);
>   	} while (!ret);
>   
>   	return ret;
> @@ -573,7 +570,7 @@ static int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
>   
>   		local_irq_restore(flags);
>   
> -		ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
> +		ret = hv_deposit_memory(partition_id, status);
>   	} while (!ret);
>   
>   	return ret;
> @@ -722,8 +719,7 @@ hv_call_create_port(u64 port_partition_id, union hv_port_id port_id,
>   			ret = hv_result_to_errno(status);
>   			break;
>   		}
> -		ret = hv_call_deposit_pages(NUMA_NO_NODE, port_partition_id, 1);
> -
> +		ret = hv_deposit_memory(port_partition_id, status);
>   	} while (!ret);
>   
>   	return ret;
> @@ -776,8 +772,7 @@ hv_call_connect_port(u64 port_partition_id, union hv_port_id port_id,
>   			ret = hv_result_to_errno(status);
>   			break;
>   		}
> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> -					    connection_partition_id, 1);
> +		ret = hv_deposit_memory(connection_partition_id, status);
>   	} while (!ret);
>   
>   	return ret;
> @@ -848,8 +843,7 @@ static int hv_call_map_stats_page2(enum hv_stats_object_type type,
>   			break;
>   		}
>   
> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> -					    hv_current_partition_id, 1);
> +		ret = hv_deposit_memory(hv_current_partition_id, status);
>   	} while (!ret);
>   
>   	return ret;
> @@ -885,8 +879,7 @@ static int hv_call_map_stats_page(enum hv_stats_object_type type,
>   			return ret;
>   		}
>   
> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> -					    hv_current_partition_id, 1);
> +		ret = hv_deposit_memory(hv_current_partition_id, status);
>   		if (ret)
>   			return ret;
>   	} while (!ret);
> diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
> index f4697497f83e..5fc572e31cd7 100644
> --- a/drivers/hv/mshv_root_main.c
> +++ b/drivers/hv/mshv_root_main.c
> @@ -264,8 +264,7 @@ static int mshv_ioctl_passthru_hvcall(struct mshv_partition *partition,
>   		if (!hv_result_oom(status))
>   			ret = hv_result_to_errno(status);
>   		else
> -			ret = hv_call_deposit_pages(NUMA_NO_NODE,
> -						    pt_id, 1);
> +			ret = hv_deposit_memory(pt_id, status);
>   	} while (!ret);
>   
>   	args.status = hv_result(status);
> diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
> index b73352a7fc9e..c8e8976839f8 100644
> --- a/include/asm-generic/mshyperv.h
> +++ b/include/asm-generic/mshyperv.h
> @@ -344,6 +344,7 @@ static inline bool hv_parent_partition(void)
>   }
>   
>   bool hv_result_oom(u64 status);
> +int hv_deposit_memory_node(int node, u64 partition_id, u64 status);
>   int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
>   int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
>   int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
> @@ -353,6 +354,10 @@ static inline bool hv_root_partition(void) { return false; }
>   static inline bool hv_l1vh_partition(void) { return false; }
>   static inline bool hv_parent_partition(void) { return false; }
>   static inline bool hv_result_oom(u64 status) { return false; }
> +static inline int hv_deposit_memory_node(int node, u64 partition_id, u64 status)
> +{
> +	return -EOPNOTSUPP;
> +}
>   static inline int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
>   {
>   	return -EOPNOTSUPP;
> @@ -367,6 +372,11 @@ static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u3
>   }
>   #endif /* CONFIG_MSHV_ROOT */
>   
> +static inline int hv_deposit_memory(u64 partition_id, u64 status)
> +{
> +	return hv_deposit_memory_node(NUMA_NO_NODE, partition_id, status);
> +}
> +
>   #if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
>   u8 __init get_vtl(void);
>   #else
> 
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/4] mshv: Introduce hv_deposit_memory helper functions
  2026-01-24  0:33   ` Mukesh R
@ 2026-01-25 22:41     ` Stanislav Kinsburskii
  2026-01-27  2:06       ` Mukesh R
  0 siblings, 1 reply; 13+ messages in thread
From: Stanislav Kinsburskii @ 2026-01-25 22:41 UTC (permalink / raw)
  To: Mukesh R
  Cc: kys, haiyangz, wei.liu, decui, longli, linux-hyperv, linux-kernel

On Fri, Jan 23, 2026 at 04:33:39PM -0800, Mukesh R wrote:
> On 1/22/26 17:35, Stanislav Kinsburskii wrote:
> > Introduce hv_deposit_memory_node() and hv_deposit_memory() helper
> > functions to handle memory deposition with proper error handling.
> > 
> > The new hv_deposit_memory_node() function takes the hypervisor status
> > as a parameter and validates it before depositing pages. It checks for
> > HV_STATUS_INSUFFICIENT_MEMORY specifically and returns an error for
> > unexpected status codes.
> > 
> > This is a precursor patch to new out-of-memory error codes support.
> > No functional changes intended.
> > 
> > Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
> > ---
> >   drivers/hv/hv_proc.c           |   22 ++++++++++++++++++++--
> >   drivers/hv/mshv_root_hv_call.c |   25 +++++++++----------------
> >   drivers/hv/mshv_root_main.c    |    3 +--
> >   include/asm-generic/mshyperv.h |   10 ++++++++++
> >   4 files changed, 40 insertions(+), 20 deletions(-)
> > 
> > diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
> > index 80c66d1c74d5..c0c2bfc80d77 100644
> > --- a/drivers/hv/hv_proc.c
> > +++ b/drivers/hv/hv_proc.c
> > @@ -110,6 +110,23 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
> >   }
> >   EXPORT_SYMBOL_GPL(hv_call_deposit_pages);
> > +int hv_deposit_memory_node(int node, u64 partition_id,
> > +			   u64 hv_status)
> > +{
> > +	u32 num_pages;
> > +
> > +	switch (hv_result(hv_status)) {
> > +	case HV_STATUS_INSUFFICIENT_MEMORY:
> > +		num_pages = 1;
> > +		break;
> > +	default:
> > +		hv_status_err(hv_status, "Unexpected!\n");
> > +		return -ENOMEM;
> > +	}
> > +	return hv_call_deposit_pages(node, partition_id, num_pages);
> > +}
> > +EXPORT_SYMBOL_GPL(hv_deposit_memory_node);
> > +
> 
> Different hypercalls may want to deposit different number of pages in one
> shot. As feature evolves, page sizes get mixed, we'd almost need that
> flexibility. So, imo, either we just don't do this for now, or add num pages
> parameter to be passed down.
> 

What you do mean by "page sizes get mixed"?
A helper to deposit num pages already exists: its
hv_call_deposit_pages().

Thanks,
Stanislav

> Thanks,
> -Mukesh
> 
> 
> 
> >   bool hv_result_oom(u64 status)
> >   {
> >   	switch (hv_result(status)) {
> > @@ -155,7 +172,8 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
> >   			}
> >   			break;
> >   		}
> > -		ret = hv_call_deposit_pages(node, hv_current_partition_id, 1);
> > +		ret = hv_deposit_memory_node(node, hv_current_partition_id,
> > +					     status);
> >   	} while (!ret);
> >   	return ret;
> > @@ -197,7 +215,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
> >   			}
> >   			break;
> >   		}
> > -		ret = hv_call_deposit_pages(node, partition_id, 1);
> > +		ret = hv_deposit_memory_node(node, partition_id, status);
> >   	} while (!ret);
> > diff --git a/drivers/hv/mshv_root_hv_call.c b/drivers/hv/mshv_root_hv_call.c
> > index 58c5cbf2e567..06f2bac8039d 100644
> > --- a/drivers/hv/mshv_root_hv_call.c
> > +++ b/drivers/hv/mshv_root_hv_call.c
> > @@ -123,8 +123,7 @@ int hv_call_create_partition(u64 flags,
> >   			break;
> >   		}
> >   		local_irq_restore(irq_flags);
> > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > -					    hv_current_partition_id, 1);
> > +		ret = hv_deposit_memory(hv_current_partition_id, status);
> >   	} while (!ret);
> >   	return ret;
> > @@ -151,7 +150,7 @@ int hv_call_initialize_partition(u64 partition_id)
> >   			ret = hv_result_to_errno(status);
> >   			break;
> >   		}
> > -		ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
> > +		ret = hv_deposit_memory(partition_id, status);
> >   	} while (!ret);
> >   	return ret;
> > @@ -465,8 +464,7 @@ int hv_call_get_vp_state(u32 vp_index, u64 partition_id,
> >   		}
> >   		local_irq_restore(flags);
> > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > -					    partition_id, 1);
> > +		ret = hv_deposit_memory(partition_id, status);
> >   	} while (!ret);
> >   	return ret;
> > @@ -525,8 +523,7 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_id,
> >   		}
> >   		local_irq_restore(flags);
> > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > -					    partition_id, 1);
> > +		ret = hv_deposit_memory(partition_id, status);
> >   	} while (!ret);
> >   	return ret;
> > @@ -573,7 +570,7 @@ static int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
> >   		local_irq_restore(flags);
> > -		ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
> > +		ret = hv_deposit_memory(partition_id, status);
> >   	} while (!ret);
> >   	return ret;
> > @@ -722,8 +719,7 @@ hv_call_create_port(u64 port_partition_id, union hv_port_id port_id,
> >   			ret = hv_result_to_errno(status);
> >   			break;
> >   		}
> > -		ret = hv_call_deposit_pages(NUMA_NO_NODE, port_partition_id, 1);
> > -
> > +		ret = hv_deposit_memory(port_partition_id, status);
> >   	} while (!ret);
> >   	return ret;
> > @@ -776,8 +772,7 @@ hv_call_connect_port(u64 port_partition_id, union hv_port_id port_id,
> >   			ret = hv_result_to_errno(status);
> >   			break;
> >   		}
> > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > -					    connection_partition_id, 1);
> > +		ret = hv_deposit_memory(connection_partition_id, status);
> >   	} while (!ret);
> >   	return ret;
> > @@ -848,8 +843,7 @@ static int hv_call_map_stats_page2(enum hv_stats_object_type type,
> >   			break;
> >   		}
> > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > -					    hv_current_partition_id, 1);
> > +		ret = hv_deposit_memory(hv_current_partition_id, status);
> >   	} while (!ret);
> >   	return ret;
> > @@ -885,8 +879,7 @@ static int hv_call_map_stats_page(enum hv_stats_object_type type,
> >   			return ret;
> >   		}
> > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > -					    hv_current_partition_id, 1);
> > +		ret = hv_deposit_memory(hv_current_partition_id, status);
> >   		if (ret)
> >   			return ret;
> >   	} while (!ret);
> > diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
> > index f4697497f83e..5fc572e31cd7 100644
> > --- a/drivers/hv/mshv_root_main.c
> > +++ b/drivers/hv/mshv_root_main.c
> > @@ -264,8 +264,7 @@ static int mshv_ioctl_passthru_hvcall(struct mshv_partition *partition,
> >   		if (!hv_result_oom(status))
> >   			ret = hv_result_to_errno(status);
> >   		else
> > -			ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > -						    pt_id, 1);
> > +			ret = hv_deposit_memory(pt_id, status);
> >   	} while (!ret);
> >   	args.status = hv_result(status);
> > diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
> > index b73352a7fc9e..c8e8976839f8 100644
> > --- a/include/asm-generic/mshyperv.h
> > +++ b/include/asm-generic/mshyperv.h
> > @@ -344,6 +344,7 @@ static inline bool hv_parent_partition(void)
> >   }
> >   bool hv_result_oom(u64 status);
> > +int hv_deposit_memory_node(int node, u64 partition_id, u64 status);
> >   int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
> >   int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
> >   int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
> > @@ -353,6 +354,10 @@ static inline bool hv_root_partition(void) { return false; }
> >   static inline bool hv_l1vh_partition(void) { return false; }
> >   static inline bool hv_parent_partition(void) { return false; }
> >   static inline bool hv_result_oom(u64 status) { return false; }
> > +static inline int hv_deposit_memory_node(int node, u64 partition_id, u64 status)
> > +{
> > +	return -EOPNOTSUPP;
> > +}
> >   static inline int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
> >   {
> >   	return -EOPNOTSUPP;
> > @@ -367,6 +372,11 @@ static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u3
> >   }
> >   #endif /* CONFIG_MSHV_ROOT */
> > +static inline int hv_deposit_memory(u64 partition_id, u64 status)
> > +{
> > +	return hv_deposit_memory_node(NUMA_NO_NODE, partition_id, status);
> > +}
> > +
> >   #if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
> >   u8 __init get_vtl(void);
> >   #else
> > 
> > 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/4] mshv: Introduce hv_deposit_memory helper functions
  2026-01-25 22:41     ` Stanislav Kinsburskii
@ 2026-01-27  2:06       ` Mukesh R
  2026-01-27 18:30         ` Stanislav Kinsburskii
  0 siblings, 1 reply; 13+ messages in thread
From: Mukesh R @ 2026-01-27  2:06 UTC (permalink / raw)
  To: Stanislav Kinsburskii
  Cc: kys, haiyangz, wei.liu, decui, longli, linux-hyperv, linux-kernel

On 1/25/26 14:41, Stanislav Kinsburskii wrote:
> On Fri, Jan 23, 2026 at 04:33:39PM -0800, Mukesh R wrote:
>> On 1/22/26 17:35, Stanislav Kinsburskii wrote:
>>> Introduce hv_deposit_memory_node() and hv_deposit_memory() helper
>>> functions to handle memory deposition with proper error handling.
>>>
>>> The new hv_deposit_memory_node() function takes the hypervisor status
>>> as a parameter and validates it before depositing pages. It checks for
>>> HV_STATUS_INSUFFICIENT_MEMORY specifically and returns an error for
>>> unexpected status codes.
>>>
>>> This is a precursor patch to new out-of-memory error codes support.
>>> No functional changes intended.
>>>
>>> Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
>>> ---
>>>    drivers/hv/hv_proc.c           |   22 ++++++++++++++++++++--
>>>    drivers/hv/mshv_root_hv_call.c |   25 +++++++++----------------
>>>    drivers/hv/mshv_root_main.c    |    3 +--
>>>    include/asm-generic/mshyperv.h |   10 ++++++++++
>>>    4 files changed, 40 insertions(+), 20 deletions(-)
>>>
>>> diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
>>> index 80c66d1c74d5..c0c2bfc80d77 100644
>>> --- a/drivers/hv/hv_proc.c
>>> +++ b/drivers/hv/hv_proc.c
>>> @@ -110,6 +110,23 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
>>>    }
>>>    EXPORT_SYMBOL_GPL(hv_call_deposit_pages);
>>> +int hv_deposit_memory_node(int node, u64 partition_id,
>>> +			   u64 hv_status)
>>> +{
>>> +	u32 num_pages;
>>> +
>>> +	switch (hv_result(hv_status)) {
>>> +	case HV_STATUS_INSUFFICIENT_MEMORY:
>>> +		num_pages = 1;
>>> +		break;
>>> +	default:
>>> +		hv_status_err(hv_status, "Unexpected!\n");
>>> +		return -ENOMEM;
>>> +	}
>>> +	return hv_call_deposit_pages(node, partition_id, num_pages);
>>> +}
>>> +EXPORT_SYMBOL_GPL(hv_deposit_memory_node);
>>> +
>>
>> Different hypercalls may want to deposit different number of pages in one
>> shot. As feature evolves, page sizes get mixed, we'd almost need that
>> flexibility. So, imo, either we just don't do this for now, or add num pages
>> parameter to be passed down.
>>
> 
> What you do mean by "page sizes get mixed"?
> A helper to deposit num pages already exists: its
> hv_call_deposit_pages().

My point, you are removing number of pages, and we may want to keep
that so one can quickly play around and change them.

-                       ret = hv_call_deposit_pages(NUMA_NO_NODE,
-                                                   pt_id, 1);
+                       ret = hv_deposit_memory(pt_id, status);

For example, in hv_call_initialize_partition() we may realize after
some analysis that depositing 2 pages or 4 pages is much better.

> Thanks,
> Stanislav
> 
>> Thanks,
>> -Mukesh
>>
>>
>>
>>>    bool hv_result_oom(u64 status)
>>>    {
>>>    	switch (hv_result(status)) {
>>> @@ -155,7 +172,8 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
>>>    			}
>>>    			break;
>>>    		}
>>> -		ret = hv_call_deposit_pages(node, hv_current_partition_id, 1);
>>> +		ret = hv_deposit_memory_node(node, hv_current_partition_id,
>>> +					     status);
>>>    	} while (!ret);
>>>    	return ret;
>>> @@ -197,7 +215,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
>>>    			}
>>>    			break;
>>>    		}
>>> -		ret = hv_call_deposit_pages(node, partition_id, 1);
>>> +		ret = hv_deposit_memory_node(node, partition_id, status);
>>>    	} while (!ret);
>>> diff --git a/drivers/hv/mshv_root_hv_call.c b/drivers/hv/mshv_root_hv_call.c
>>> index 58c5cbf2e567..06f2bac8039d 100644
>>> --- a/drivers/hv/mshv_root_hv_call.c
>>> +++ b/drivers/hv/mshv_root_hv_call.c
>>> @@ -123,8 +123,7 @@ int hv_call_create_partition(u64 flags,
>>>    			break;
>>>    		}
>>>    		local_irq_restore(irq_flags);
>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>> -					    hv_current_partition_id, 1);
>>> +		ret = hv_deposit_memory(hv_current_partition_id, status);
>>>    	} while (!ret);
>>>    	return ret;
>>> @@ -151,7 +150,7 @@ int hv_call_initialize_partition(u64 partition_id)
>>>    			ret = hv_result_to_errno(status);
>>>    			break;
>>>    		}
>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
>>> +		ret = hv_deposit_memory(partition_id, status);
>>>    	} while (!ret);
>>>    	return ret;
>>> @@ -465,8 +464,7 @@ int hv_call_get_vp_state(u32 vp_index, u64 partition_id,
>>>    		}
>>>    		local_irq_restore(flags);
>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>> -					    partition_id, 1);
>>> +		ret = hv_deposit_memory(partition_id, status);
>>>    	} while (!ret);
>>>    	return ret;
>>> @@ -525,8 +523,7 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_id,
>>>    		}
>>>    		local_irq_restore(flags);
>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>> -					    partition_id, 1);
>>> +		ret = hv_deposit_memory(partition_id, status);
>>>    	} while (!ret);
>>>    	return ret;
>>> @@ -573,7 +570,7 @@ static int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
>>>    		local_irq_restore(flags);
>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
>>> +		ret = hv_deposit_memory(partition_id, status);
>>>    	} while (!ret);
>>>    	return ret;
>>> @@ -722,8 +719,7 @@ hv_call_create_port(u64 port_partition_id, union hv_port_id port_id,
>>>    			ret = hv_result_to_errno(status);
>>>    			break;
>>>    		}
>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE, port_partition_id, 1);
>>> -
>>> +		ret = hv_deposit_memory(port_partition_id, status);
>>>    	} while (!ret);
>>>    	return ret;
>>> @@ -776,8 +772,7 @@ hv_call_connect_port(u64 port_partition_id, union hv_port_id port_id,
>>>    			ret = hv_result_to_errno(status);
>>>    			break;
>>>    		}
>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>> -					    connection_partition_id, 1);
>>> +		ret = hv_deposit_memory(connection_partition_id, status);
>>>    	} while (!ret);
>>>    	return ret;
>>> @@ -848,8 +843,7 @@ static int hv_call_map_stats_page2(enum hv_stats_object_type type,
>>>    			break;
>>>    		}
>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>> -					    hv_current_partition_id, 1);
>>> +		ret = hv_deposit_memory(hv_current_partition_id, status);
>>>    	} while (!ret);
>>>    	return ret;
>>> @@ -885,8 +879,7 @@ static int hv_call_map_stats_page(enum hv_stats_object_type type,
>>>    			return ret;
>>>    		}
>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>> -					    hv_current_partition_id, 1);
>>> +		ret = hv_deposit_memory(hv_current_partition_id, status);
>>>    		if (ret)
>>>    			return ret;
>>>    	} while (!ret);
>>> diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
>>> index f4697497f83e..5fc572e31cd7 100644
>>> --- a/drivers/hv/mshv_root_main.c
>>> +++ b/drivers/hv/mshv_root_main.c
>>> @@ -264,8 +264,7 @@ static int mshv_ioctl_passthru_hvcall(struct mshv_partition *partition,
>>>    		if (!hv_result_oom(status))
>>>    			ret = hv_result_to_errno(status);
>>>    		else
>>> -			ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>> -						    pt_id, 1);
>>> +			ret = hv_deposit_memory(pt_id, status);
>>>    	} while (!ret);
>>>    	args.status = hv_result(status);
>>> diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
>>> index b73352a7fc9e..c8e8976839f8 100644
>>> --- a/include/asm-generic/mshyperv.h
>>> +++ b/include/asm-generic/mshyperv.h
>>> @@ -344,6 +344,7 @@ static inline bool hv_parent_partition(void)
>>>    }
>>>    bool hv_result_oom(u64 status);
>>> +int hv_deposit_memory_node(int node, u64 partition_id, u64 status);
>>>    int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
>>>    int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
>>>    int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
>>> @@ -353,6 +354,10 @@ static inline bool hv_root_partition(void) { return false; }
>>>    static inline bool hv_l1vh_partition(void) { return false; }
>>>    static inline bool hv_parent_partition(void) { return false; }
>>>    static inline bool hv_result_oom(u64 status) { return false; }
>>> +static inline int hv_deposit_memory_node(int node, u64 partition_id, u64 status)
>>> +{
>>> +	return -EOPNOTSUPP;
>>> +}
>>>    static inline int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
>>>    {
>>>    	return -EOPNOTSUPP;
>>> @@ -367,6 +372,11 @@ static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u3
>>>    }
>>>    #endif /* CONFIG_MSHV_ROOT */
>>> +static inline int hv_deposit_memory(u64 partition_id, u64 status)
>>> +{
>>> +	return hv_deposit_memory_node(NUMA_NO_NODE, partition_id, status);
>>> +}
>>> +
>>>    #if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
>>>    u8 __init get_vtl(void);
>>>    #else
>>>
>>>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/4] mshv: Introduce hv_deposit_memory helper functions
  2026-01-27  2:06       ` Mukesh R
@ 2026-01-27 18:30         ` Stanislav Kinsburskii
  2026-01-27 19:44           ` Mukesh R
  0 siblings, 1 reply; 13+ messages in thread
From: Stanislav Kinsburskii @ 2026-01-27 18:30 UTC (permalink / raw)
  To: Mukesh R
  Cc: kys, haiyangz, wei.liu, decui, longli, linux-hyperv, linux-kernel

On Mon, Jan 26, 2026 at 06:06:23PM -0800, Mukesh R wrote:
> On 1/25/26 14:41, Stanislav Kinsburskii wrote:
> > On Fri, Jan 23, 2026 at 04:33:39PM -0800, Mukesh R wrote:
> > > On 1/22/26 17:35, Stanislav Kinsburskii wrote:
> > > > Introduce hv_deposit_memory_node() and hv_deposit_memory() helper
> > > > functions to handle memory deposition with proper error handling.
> > > > 
> > > > The new hv_deposit_memory_node() function takes the hypervisor status
> > > > as a parameter and validates it before depositing pages. It checks for
> > > > HV_STATUS_INSUFFICIENT_MEMORY specifically and returns an error for
> > > > unexpected status codes.
> > > > 
> > > > This is a precursor patch to new out-of-memory error codes support.
> > > > No functional changes intended.
> > > > 
> > > > Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
> > > > ---
> > > >    drivers/hv/hv_proc.c           |   22 ++++++++++++++++++++--
> > > >    drivers/hv/mshv_root_hv_call.c |   25 +++++++++----------------
> > > >    drivers/hv/mshv_root_main.c    |    3 +--
> > > >    include/asm-generic/mshyperv.h |   10 ++++++++++
> > > >    4 files changed, 40 insertions(+), 20 deletions(-)
> > > > 
> > > > diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
> > > > index 80c66d1c74d5..c0c2bfc80d77 100644
> > > > --- a/drivers/hv/hv_proc.c
> > > > +++ b/drivers/hv/hv_proc.c
> > > > @@ -110,6 +110,23 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
> > > >    }
> > > >    EXPORT_SYMBOL_GPL(hv_call_deposit_pages);
> > > > +int hv_deposit_memory_node(int node, u64 partition_id,
> > > > +			   u64 hv_status)
> > > > +{
> > > > +	u32 num_pages;
> > > > +
> > > > +	switch (hv_result(hv_status)) {
> > > > +	case HV_STATUS_INSUFFICIENT_MEMORY:
> > > > +		num_pages = 1;
> > > > +		break;
> > > > +	default:
> > > > +		hv_status_err(hv_status, "Unexpected!\n");
> > > > +		return -ENOMEM;
> > > > +	}
> > > > +	return hv_call_deposit_pages(node, partition_id, num_pages);
> > > > +}
> > > > +EXPORT_SYMBOL_GPL(hv_deposit_memory_node);
> > > > +
> > > 
> > > Different hypercalls may want to deposit different number of pages in one
> > > shot. As feature evolves, page sizes get mixed, we'd almost need that
> > > flexibility. So, imo, either we just don't do this for now, or add num pages
> > > parameter to be passed down.
> > > 
> > 
> > What you do mean by "page sizes get mixed"?
> > A helper to deposit num pages already exists: its
> > hv_call_deposit_pages().
> 
> My point, you are removing number of pages, and we may want to keep
> that so one can quickly play around and change them.
> 
> -                       ret = hv_call_deposit_pages(NUMA_NO_NODE,
> -                                                   pt_id, 1);
> +                       ret = hv_deposit_memory(pt_id, status);
> 
> For example, in hv_call_initialize_partition() we may realize after
> some analysis that depositing 2 pages or 4 pages is much better.
> 

We have been using this 1-page deposit logic from the beginning. To
change the number of pages, simply replace hv_deposit_memory with
hv_call_deposit_pages and specify the desired number of pages.

The proposed approach reduces code duplication and is less error-prone,
as there are multiple error codes to handle. Consolidating the logic
also makes the driver more robust.


Thanks,  Stanislav

> > Thanks,
> > Stanislav
> > 
> > > Thanks,
> > > -Mukesh
> > > 
> > > 
> > > 
> > > >    bool hv_result_oom(u64 status)
> > > >    {
> > > >    	switch (hv_result(status)) {
> > > > @@ -155,7 +172,8 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
> > > >    			}
> > > >    			break;
> > > >    		}
> > > > -		ret = hv_call_deposit_pages(node, hv_current_partition_id, 1);
> > > > +		ret = hv_deposit_memory_node(node, hv_current_partition_id,
> > > > +					     status);
> > > >    	} while (!ret);
> > > >    	return ret;
> > > > @@ -197,7 +215,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
> > > >    			}
> > > >    			break;
> > > >    		}
> > > > -		ret = hv_call_deposit_pages(node, partition_id, 1);
> > > > +		ret = hv_deposit_memory_node(node, partition_id, status);
> > > >    	} while (!ret);
> > > > diff --git a/drivers/hv/mshv_root_hv_call.c b/drivers/hv/mshv_root_hv_call.c
> > > > index 58c5cbf2e567..06f2bac8039d 100644
> > > > --- a/drivers/hv/mshv_root_hv_call.c
> > > > +++ b/drivers/hv/mshv_root_hv_call.c
> > > > @@ -123,8 +123,7 @@ int hv_call_create_partition(u64 flags,
> > > >    			break;
> > > >    		}
> > > >    		local_irq_restore(irq_flags);
> > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > > > -					    hv_current_partition_id, 1);
> > > > +		ret = hv_deposit_memory(hv_current_partition_id, status);
> > > >    	} while (!ret);
> > > >    	return ret;
> > > > @@ -151,7 +150,7 @@ int hv_call_initialize_partition(u64 partition_id)
> > > >    			ret = hv_result_to_errno(status);
> > > >    			break;
> > > >    		}
> > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
> > > > +		ret = hv_deposit_memory(partition_id, status);
> > > >    	} while (!ret);
> > > >    	return ret;
> > > > @@ -465,8 +464,7 @@ int hv_call_get_vp_state(u32 vp_index, u64 partition_id,
> > > >    		}
> > > >    		local_irq_restore(flags);
> > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > > > -					    partition_id, 1);
> > > > +		ret = hv_deposit_memory(partition_id, status);
> > > >    	} while (!ret);
> > > >    	return ret;
> > > > @@ -525,8 +523,7 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_id,
> > > >    		}
> > > >    		local_irq_restore(flags);
> > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > > > -					    partition_id, 1);
> > > > +		ret = hv_deposit_memory(partition_id, status);
> > > >    	} while (!ret);
> > > >    	return ret;
> > > > @@ -573,7 +570,7 @@ static int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
> > > >    		local_irq_restore(flags);
> > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
> > > > +		ret = hv_deposit_memory(partition_id, status);
> > > >    	} while (!ret);
> > > >    	return ret;
> > > > @@ -722,8 +719,7 @@ hv_call_create_port(u64 port_partition_id, union hv_port_id port_id,
> > > >    			ret = hv_result_to_errno(status);
> > > >    			break;
> > > >    		}
> > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE, port_partition_id, 1);
> > > > -
> > > > +		ret = hv_deposit_memory(port_partition_id, status);
> > > >    	} while (!ret);
> > > >    	return ret;
> > > > @@ -776,8 +772,7 @@ hv_call_connect_port(u64 port_partition_id, union hv_port_id port_id,
> > > >    			ret = hv_result_to_errno(status);
> > > >    			break;
> > > >    		}
> > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > > > -					    connection_partition_id, 1);
> > > > +		ret = hv_deposit_memory(connection_partition_id, status);
> > > >    	} while (!ret);
> > > >    	return ret;
> > > > @@ -848,8 +843,7 @@ static int hv_call_map_stats_page2(enum hv_stats_object_type type,
> > > >    			break;
> > > >    		}
> > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > > > -					    hv_current_partition_id, 1);
> > > > +		ret = hv_deposit_memory(hv_current_partition_id, status);
> > > >    	} while (!ret);
> > > >    	return ret;
> > > > @@ -885,8 +879,7 @@ static int hv_call_map_stats_page(enum hv_stats_object_type type,
> > > >    			return ret;
> > > >    		}
> > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > > > -					    hv_current_partition_id, 1);
> > > > +		ret = hv_deposit_memory(hv_current_partition_id, status);
> > > >    		if (ret)
> > > >    			return ret;
> > > >    	} while (!ret);
> > > > diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
> > > > index f4697497f83e..5fc572e31cd7 100644
> > > > --- a/drivers/hv/mshv_root_main.c
> > > > +++ b/drivers/hv/mshv_root_main.c
> > > > @@ -264,8 +264,7 @@ static int mshv_ioctl_passthru_hvcall(struct mshv_partition *partition,
> > > >    		if (!hv_result_oom(status))
> > > >    			ret = hv_result_to_errno(status);
> > > >    		else
> > > > -			ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > > > -						    pt_id, 1);
> > > > +			ret = hv_deposit_memory(pt_id, status);
> > > >    	} while (!ret);
> > > >    	args.status = hv_result(status);
> > > > diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
> > > > index b73352a7fc9e..c8e8976839f8 100644
> > > > --- a/include/asm-generic/mshyperv.h
> > > > +++ b/include/asm-generic/mshyperv.h
> > > > @@ -344,6 +344,7 @@ static inline bool hv_parent_partition(void)
> > > >    }
> > > >    bool hv_result_oom(u64 status);
> > > > +int hv_deposit_memory_node(int node, u64 partition_id, u64 status);
> > > >    int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
> > > >    int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
> > > >    int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
> > > > @@ -353,6 +354,10 @@ static inline bool hv_root_partition(void) { return false; }
> > > >    static inline bool hv_l1vh_partition(void) { return false; }
> > > >    static inline bool hv_parent_partition(void) { return false; }
> > > >    static inline bool hv_result_oom(u64 status) { return false; }
> > > > +static inline int hv_deposit_memory_node(int node, u64 partition_id, u64 status)
> > > > +{
> > > > +	return -EOPNOTSUPP;
> > > > +}
> > > >    static inline int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
> > > >    {
> > > >    	return -EOPNOTSUPP;
> > > > @@ -367,6 +372,11 @@ static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u3
> > > >    }
> > > >    #endif /* CONFIG_MSHV_ROOT */
> > > > +static inline int hv_deposit_memory(u64 partition_id, u64 status)
> > > > +{
> > > > +	return hv_deposit_memory_node(NUMA_NO_NODE, partition_id, status);
> > > > +}
> > > > +
> > > >    #if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
> > > >    u8 __init get_vtl(void);
> > > >    #else
> > > > 
> > > > 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/4] mshv: Introduce hv_deposit_memory helper functions
  2026-01-27 18:30         ` Stanislav Kinsburskii
@ 2026-01-27 19:44           ` Mukesh R
  2026-01-28 23:18             ` Stanislav Kinsburskii
  0 siblings, 1 reply; 13+ messages in thread
From: Mukesh R @ 2026-01-27 19:44 UTC (permalink / raw)
  To: Stanislav Kinsburskii
  Cc: kys, haiyangz, wei.liu, decui, longli, linux-hyperv, linux-kernel

On 1/27/26 10:30, Stanislav Kinsburskii wrote:
> On Mon, Jan 26, 2026 at 06:06:23PM -0800, Mukesh R wrote:
>> On 1/25/26 14:41, Stanislav Kinsburskii wrote:
>>> On Fri, Jan 23, 2026 at 04:33:39PM -0800, Mukesh R wrote:
>>>> On 1/22/26 17:35, Stanislav Kinsburskii wrote:
>>>>> Introduce hv_deposit_memory_node() and hv_deposit_memory() helper
>>>>> functions to handle memory deposition with proper error handling.
>>>>>
>>>>> The new hv_deposit_memory_node() function takes the hypervisor status
>>>>> as a parameter and validates it before depositing pages. It checks for
>>>>> HV_STATUS_INSUFFICIENT_MEMORY specifically and returns an error for
>>>>> unexpected status codes.
>>>>>
>>>>> This is a precursor patch to new out-of-memory error codes support.
>>>>> No functional changes intended.
>>>>>
>>>>> Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
>>>>> ---
>>>>>     drivers/hv/hv_proc.c           |   22 ++++++++++++++++++++--
>>>>>     drivers/hv/mshv_root_hv_call.c |   25 +++++++++----------------
>>>>>     drivers/hv/mshv_root_main.c    |    3 +--
>>>>>     include/asm-generic/mshyperv.h |   10 ++++++++++
>>>>>     4 files changed, 40 insertions(+), 20 deletions(-)
>>>>>
>>>>> diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
>>>>> index 80c66d1c74d5..c0c2bfc80d77 100644
>>>>> --- a/drivers/hv/hv_proc.c
>>>>> +++ b/drivers/hv/hv_proc.c
>>>>> @@ -110,6 +110,23 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
>>>>>     }
>>>>>     EXPORT_SYMBOL_GPL(hv_call_deposit_pages);
>>>>> +int hv_deposit_memory_node(int node, u64 partition_id,
>>>>> +			   u64 hv_status)
>>>>> +{
>>>>> +	u32 num_pages;
>>>>> +
>>>>> +	switch (hv_result(hv_status)) {
>>>>> +	case HV_STATUS_INSUFFICIENT_MEMORY:
>>>>> +		num_pages = 1;
>>>>> +		break;
>>>>> +	default:
>>>>> +		hv_status_err(hv_status, "Unexpected!\n");
>>>>> +		return -ENOMEM;
>>>>> +	}
>>>>> +	return hv_call_deposit_pages(node, partition_id, num_pages);
>>>>> +}
>>>>> +EXPORT_SYMBOL_GPL(hv_deposit_memory_node);
>>>>> +
>>>>
>>>> Different hypercalls may want to deposit different number of pages in one
>>>> shot. As feature evolves, page sizes get mixed, we'd almost need that
>>>> flexibility. So, imo, either we just don't do this for now, or add num pages
>>>> parameter to be passed down.
>>>>
>>>
>>> What you do mean by "page sizes get mixed"?
>>> A helper to deposit num pages already exists: its
>>> hv_call_deposit_pages().
>>
>> My point, you are removing number of pages, and we may want to keep
>> that so one can quickly play around and change them.
>>
>> -                       ret = hv_call_deposit_pages(NUMA_NO_NODE,
>> -                                                   pt_id, 1);
>> +                       ret = hv_deposit_memory(pt_id, status);
>>
>> For example, in hv_call_initialize_partition() we may realize after
>> some analysis that depositing 2 pages or 4 pages is much better.
>>
> 
> We have been using this 1-page deposit logic from the beginning. To
> change the number of pages, simply replace hv_deposit_memory with
> hv_call_deposit_pages and specify the desired number of pages.

You could perhaps rename it to hv_deposit_page().

> The proposed approach reduces code duplication and is less error-prone,
> as there are multiple error codes to handle. Consolidating the logic
> also makes the driver more robust.
> 
> 
> Thanks,  Stanislav
> 
>>> Thanks,
>>> Stanislav
>>>
>>>> Thanks,
>>>> -Mukesh
>>>>
>>>>
>>>>
>>>>>     bool hv_result_oom(u64 status)
>>>>>     {
>>>>>     	switch (hv_result(status)) {
>>>>> @@ -155,7 +172,8 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
>>>>>     			}
>>>>>     			break;
>>>>>     		}
>>>>> -		ret = hv_call_deposit_pages(node, hv_current_partition_id, 1);
>>>>> +		ret = hv_deposit_memory_node(node, hv_current_partition_id,
>>>>> +					     status);
>>>>>     	} while (!ret);
>>>>>     	return ret;
>>>>> @@ -197,7 +215,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
>>>>>     			}
>>>>>     			break;
>>>>>     		}
>>>>> -		ret = hv_call_deposit_pages(node, partition_id, 1);
>>>>> +		ret = hv_deposit_memory_node(node, partition_id, status);
>>>>>     	} while (!ret);
>>>>> diff --git a/drivers/hv/mshv_root_hv_call.c b/drivers/hv/mshv_root_hv_call.c
>>>>> index 58c5cbf2e567..06f2bac8039d 100644
>>>>> --- a/drivers/hv/mshv_root_hv_call.c
>>>>> +++ b/drivers/hv/mshv_root_hv_call.c
>>>>> @@ -123,8 +123,7 @@ int hv_call_create_partition(u64 flags,
>>>>>     			break;
>>>>>     		}
>>>>>     		local_irq_restore(irq_flags);
>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>>>> -					    hv_current_partition_id, 1);
>>>>> +		ret = hv_deposit_memory(hv_current_partition_id, status);
>>>>>     	} while (!ret);
>>>>>     	return ret;
>>>>> @@ -151,7 +150,7 @@ int hv_call_initialize_partition(u64 partition_id)
>>>>>     			ret = hv_result_to_errno(status);
>>>>>     			break;
>>>>>     		}
>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
>>>>> +		ret = hv_deposit_memory(partition_id, status);
>>>>>     	} while (!ret);
>>>>>     	return ret;
>>>>> @@ -465,8 +464,7 @@ int hv_call_get_vp_state(u32 vp_index, u64 partition_id,
>>>>>     		}
>>>>>     		local_irq_restore(flags);
>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>>>> -					    partition_id, 1);
>>>>> +		ret = hv_deposit_memory(partition_id, status);
>>>>>     	} while (!ret);
>>>>>     	return ret;
>>>>> @@ -525,8 +523,7 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_id,
>>>>>     		}
>>>>>     		local_irq_restore(flags);
>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>>>> -					    partition_id, 1);
>>>>> +		ret = hv_deposit_memory(partition_id, status);
>>>>>     	} while (!ret);
>>>>>     	return ret;
>>>>> @@ -573,7 +570,7 @@ static int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
>>>>>     		local_irq_restore(flags);
>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
>>>>> +		ret = hv_deposit_memory(partition_id, status);
>>>>>     	} while (!ret);
>>>>>     	return ret;
>>>>> @@ -722,8 +719,7 @@ hv_call_create_port(u64 port_partition_id, union hv_port_id port_id,
>>>>>     			ret = hv_result_to_errno(status);
>>>>>     			break;
>>>>>     		}
>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE, port_partition_id, 1);
>>>>> -
>>>>> +		ret = hv_deposit_memory(port_partition_id, status);
>>>>>     	} while (!ret);
>>>>>     	return ret;
>>>>> @@ -776,8 +772,7 @@ hv_call_connect_port(u64 port_partition_id, union hv_port_id port_id,
>>>>>     			ret = hv_result_to_errno(status);
>>>>>     			break;
>>>>>     		}
>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>>>> -					    connection_partition_id, 1);
>>>>> +		ret = hv_deposit_memory(connection_partition_id, status);
>>>>>     	} while (!ret);
>>>>>     	return ret;
>>>>> @@ -848,8 +843,7 @@ static int hv_call_map_stats_page2(enum hv_stats_object_type type,
>>>>>     			break;
>>>>>     		}
>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>>>> -					    hv_current_partition_id, 1);
>>>>> +		ret = hv_deposit_memory(hv_current_partition_id, status);
>>>>>     	} while (!ret);
>>>>>     	return ret;
>>>>> @@ -885,8 +879,7 @@ static int hv_call_map_stats_page(enum hv_stats_object_type type,
>>>>>     			return ret;
>>>>>     		}
>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>>>> -					    hv_current_partition_id, 1);
>>>>> +		ret = hv_deposit_memory(hv_current_partition_id, status);
>>>>>     		if (ret)
>>>>>     			return ret;
>>>>>     	} while (!ret);
>>>>> diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
>>>>> index f4697497f83e..5fc572e31cd7 100644
>>>>> --- a/drivers/hv/mshv_root_main.c
>>>>> +++ b/drivers/hv/mshv_root_main.c
>>>>> @@ -264,8 +264,7 @@ static int mshv_ioctl_passthru_hvcall(struct mshv_partition *partition,
>>>>>     		if (!hv_result_oom(status))
>>>>>     			ret = hv_result_to_errno(status);
>>>>>     		else
>>>>> -			ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>>>> -						    pt_id, 1);
>>>>> +			ret = hv_deposit_memory(pt_id, status);
>>>>>     	} while (!ret);
>>>>>     	args.status = hv_result(status);
>>>>> diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
>>>>> index b73352a7fc9e..c8e8976839f8 100644
>>>>> --- a/include/asm-generic/mshyperv.h
>>>>> +++ b/include/asm-generic/mshyperv.h
>>>>> @@ -344,6 +344,7 @@ static inline bool hv_parent_partition(void)
>>>>>     }
>>>>>     bool hv_result_oom(u64 status);
>>>>> +int hv_deposit_memory_node(int node, u64 partition_id, u64 status);
>>>>>     int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
>>>>>     int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
>>>>>     int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
>>>>> @@ -353,6 +354,10 @@ static inline bool hv_root_partition(void) { return false; }
>>>>>     static inline bool hv_l1vh_partition(void) { return false; }
>>>>>     static inline bool hv_parent_partition(void) { return false; }
>>>>>     static inline bool hv_result_oom(u64 status) { return false; }
>>>>> +static inline int hv_deposit_memory_node(int node, u64 partition_id, u64 status)
>>>>> +{
>>>>> +	return -EOPNOTSUPP;
>>>>> +}
>>>>>     static inline int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
>>>>>     {
>>>>>     	return -EOPNOTSUPP;
>>>>> @@ -367,6 +372,11 @@ static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u3
>>>>>     }
>>>>>     #endif /* CONFIG_MSHV_ROOT */
>>>>> +static inline int hv_deposit_memory(u64 partition_id, u64 status)
>>>>> +{
>>>>> +	return hv_deposit_memory_node(NUMA_NO_NODE, partition_id, status);
>>>>> +}
>>>>> +
>>>>>     #if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
>>>>>     u8 __init get_vtl(void);
>>>>>     #else
>>>>>
>>>>>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/4] mshv: Introduce hv_deposit_memory helper functions
  2026-01-27 19:44           ` Mukesh R
@ 2026-01-28 23:18             ` Stanislav Kinsburskii
  2026-01-30  2:49               ` Mukesh R
  0 siblings, 1 reply; 13+ messages in thread
From: Stanislav Kinsburskii @ 2026-01-28 23:18 UTC (permalink / raw)
  To: Mukesh R
  Cc: kys, haiyangz, wei.liu, decui, longli, linux-hyperv, linux-kernel

On Tue, Jan 27, 2026 at 11:44:25AM -0800, Mukesh R wrote:
> On 1/27/26 10:30, Stanislav Kinsburskii wrote:
> > On Mon, Jan 26, 2026 at 06:06:23PM -0800, Mukesh R wrote:
> > > On 1/25/26 14:41, Stanislav Kinsburskii wrote:
> > > > On Fri, Jan 23, 2026 at 04:33:39PM -0800, Mukesh R wrote:
> > > > > On 1/22/26 17:35, Stanislav Kinsburskii wrote:
> > > > > > Introduce hv_deposit_memory_node() and hv_deposit_memory() helper
> > > > > > functions to handle memory deposition with proper error handling.
> > > > > > 
> > > > > > The new hv_deposit_memory_node() function takes the hypervisor status
> > > > > > as a parameter and validates it before depositing pages. It checks for
> > > > > > HV_STATUS_INSUFFICIENT_MEMORY specifically and returns an error for
> > > > > > unexpected status codes.
> > > > > > 
> > > > > > This is a precursor patch to new out-of-memory error codes support.
> > > > > > No functional changes intended.
> > > > > > 
> > > > > > Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
> > > > > > ---
> > > > > >     drivers/hv/hv_proc.c           |   22 ++++++++++++++++++++--
> > > > > >     drivers/hv/mshv_root_hv_call.c |   25 +++++++++----------------
> > > > > >     drivers/hv/mshv_root_main.c    |    3 +--
> > > > > >     include/asm-generic/mshyperv.h |   10 ++++++++++
> > > > > >     4 files changed, 40 insertions(+), 20 deletions(-)
> > > > > > 
> > > > > > diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
> > > > > > index 80c66d1c74d5..c0c2bfc80d77 100644
> > > > > > --- a/drivers/hv/hv_proc.c
> > > > > > +++ b/drivers/hv/hv_proc.c
> > > > > > @@ -110,6 +110,23 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
> > > > > >     }
> > > > > >     EXPORT_SYMBOL_GPL(hv_call_deposit_pages);
> > > > > > +int hv_deposit_memory_node(int node, u64 partition_id,
> > > > > > +			   u64 hv_status)
> > > > > > +{
> > > > > > +	u32 num_pages;
> > > > > > +
> > > > > > +	switch (hv_result(hv_status)) {
> > > > > > +	case HV_STATUS_INSUFFICIENT_MEMORY:
> > > > > > +		num_pages = 1;
> > > > > > +		break;
> > > > > > +	default:
> > > > > > +		hv_status_err(hv_status, "Unexpected!\n");
> > > > > > +		return -ENOMEM;
> > > > > > +	}
> > > > > > +	return hv_call_deposit_pages(node, partition_id, num_pages);
> > > > > > +}
> > > > > > +EXPORT_SYMBOL_GPL(hv_deposit_memory_node);
> > > > > > +
> > > > > 
> > > > > Different hypercalls may want to deposit different number of pages in one
> > > > > shot. As feature evolves, page sizes get mixed, we'd almost need that
> > > > > flexibility. So, imo, either we just don't do this for now, or add num pages
> > > > > parameter to be passed down.
> > > > > 
> > > > 
> > > > What you do mean by "page sizes get mixed"?
> > > > A helper to deposit num pages already exists: its
> > > > hv_call_deposit_pages().
> > > 
> > > My point, you are removing number of pages, and we may want to keep
> > > that so one can quickly play around and change them.
> > > 
> > > -                       ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > > -                                                   pt_id, 1);
> > > +                       ret = hv_deposit_memory(pt_id, status);
> > > 
> > > For example, in hv_call_initialize_partition() we may realize after
> > > some analysis that depositing 2 pages or 4 pages is much better.
> > > 
> > 
> > We have been using this 1-page deposit logic from the beginning. To
> > change the number of pages, simply replace hv_deposit_memory with
> > hv_call_deposit_pages and specify the desired number of pages.
> 
> You could perhaps rename it to hv_deposit_page().
> 

Yes, this would be a good name, but unfortunately we can now receive
statuses like HV_STATUS_INSUFFICIENT_CONTIGUOUS_MEMORY, where we need to
deposit at least 8 consecutive pages. There is also another pair of
status codes for required root pages, even when a guest partition-related
hypercall is performed (see the next patch for details).
This new helper is intended to cover all such cases, instead of branching
for all these different cases in every function.

Thanks,
Stanislav


> > The proposed approach reduces code duplication and is less error-prone,
> > as there are multiple error codes to handle. Consolidating the logic
> > also makes the driver more robust.
> > 
> > 
> > Thanks,  Stanislav
> > 
> > > > Thanks,
> > > > Stanislav
> > > > 
> > > > > Thanks,
> > > > > -Mukesh
> > > > > 
> > > > > 
> > > > > 
> > > > > >     bool hv_result_oom(u64 status)
> > > > > >     {
> > > > > >     	switch (hv_result(status)) {
> > > > > > @@ -155,7 +172,8 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
> > > > > >     			}
> > > > > >     			break;
> > > > > >     		}
> > > > > > -		ret = hv_call_deposit_pages(node, hv_current_partition_id, 1);
> > > > > > +		ret = hv_deposit_memory_node(node, hv_current_partition_id,
> > > > > > +					     status);
> > > > > >     	} while (!ret);
> > > > > >     	return ret;
> > > > > > @@ -197,7 +215,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
> > > > > >     			}
> > > > > >     			break;
> > > > > >     		}
> > > > > > -		ret = hv_call_deposit_pages(node, partition_id, 1);
> > > > > > +		ret = hv_deposit_memory_node(node, partition_id, status);
> > > > > >     	} while (!ret);
> > > > > > diff --git a/drivers/hv/mshv_root_hv_call.c b/drivers/hv/mshv_root_hv_call.c
> > > > > > index 58c5cbf2e567..06f2bac8039d 100644
> > > > > > --- a/drivers/hv/mshv_root_hv_call.c
> > > > > > +++ b/drivers/hv/mshv_root_hv_call.c
> > > > > > @@ -123,8 +123,7 @@ int hv_call_create_partition(u64 flags,
> > > > > >     			break;
> > > > > >     		}
> > > > > >     		local_irq_restore(irq_flags);
> > > > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > > > > > -					    hv_current_partition_id, 1);
> > > > > > +		ret = hv_deposit_memory(hv_current_partition_id, status);
> > > > > >     	} while (!ret);
> > > > > >     	return ret;
> > > > > > @@ -151,7 +150,7 @@ int hv_call_initialize_partition(u64 partition_id)
> > > > > >     			ret = hv_result_to_errno(status);
> > > > > >     			break;
> > > > > >     		}
> > > > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
> > > > > > +		ret = hv_deposit_memory(partition_id, status);
> > > > > >     	} while (!ret);
> > > > > >     	return ret;
> > > > > > @@ -465,8 +464,7 @@ int hv_call_get_vp_state(u32 vp_index, u64 partition_id,
> > > > > >     		}
> > > > > >     		local_irq_restore(flags);
> > > > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > > > > > -					    partition_id, 1);
> > > > > > +		ret = hv_deposit_memory(partition_id, status);
> > > > > >     	} while (!ret);
> > > > > >     	return ret;
> > > > > > @@ -525,8 +523,7 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_id,
> > > > > >     		}
> > > > > >     		local_irq_restore(flags);
> > > > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > > > > > -					    partition_id, 1);
> > > > > > +		ret = hv_deposit_memory(partition_id, status);
> > > > > >     	} while (!ret);
> > > > > >     	return ret;
> > > > > > @@ -573,7 +570,7 @@ static int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
> > > > > >     		local_irq_restore(flags);
> > > > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
> > > > > > +		ret = hv_deposit_memory(partition_id, status);
> > > > > >     	} while (!ret);
> > > > > >     	return ret;
> > > > > > @@ -722,8 +719,7 @@ hv_call_create_port(u64 port_partition_id, union hv_port_id port_id,
> > > > > >     			ret = hv_result_to_errno(status);
> > > > > >     			break;
> > > > > >     		}
> > > > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE, port_partition_id, 1);
> > > > > > -
> > > > > > +		ret = hv_deposit_memory(port_partition_id, status);
> > > > > >     	} while (!ret);
> > > > > >     	return ret;
> > > > > > @@ -776,8 +772,7 @@ hv_call_connect_port(u64 port_partition_id, union hv_port_id port_id,
> > > > > >     			ret = hv_result_to_errno(status);
> > > > > >     			break;
> > > > > >     		}
> > > > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > > > > > -					    connection_partition_id, 1);
> > > > > > +		ret = hv_deposit_memory(connection_partition_id, status);
> > > > > >     	} while (!ret);
> > > > > >     	return ret;
> > > > > > @@ -848,8 +843,7 @@ static int hv_call_map_stats_page2(enum hv_stats_object_type type,
> > > > > >     			break;
> > > > > >     		}
> > > > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > > > > > -					    hv_current_partition_id, 1);
> > > > > > +		ret = hv_deposit_memory(hv_current_partition_id, status);
> > > > > >     	} while (!ret);
> > > > > >     	return ret;
> > > > > > @@ -885,8 +879,7 @@ static int hv_call_map_stats_page(enum hv_stats_object_type type,
> > > > > >     			return ret;
> > > > > >     		}
> > > > > > -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > > > > > -					    hv_current_partition_id, 1);
> > > > > > +		ret = hv_deposit_memory(hv_current_partition_id, status);
> > > > > >     		if (ret)
> > > > > >     			return ret;
> > > > > >     	} while (!ret);
> > > > > > diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
> > > > > > index f4697497f83e..5fc572e31cd7 100644
> > > > > > --- a/drivers/hv/mshv_root_main.c
> > > > > > +++ b/drivers/hv/mshv_root_main.c
> > > > > > @@ -264,8 +264,7 @@ static int mshv_ioctl_passthru_hvcall(struct mshv_partition *partition,
> > > > > >     		if (!hv_result_oom(status))
> > > > > >     			ret = hv_result_to_errno(status);
> > > > > >     		else
> > > > > > -			ret = hv_call_deposit_pages(NUMA_NO_NODE,
> > > > > > -						    pt_id, 1);
> > > > > > +			ret = hv_deposit_memory(pt_id, status);
> > > > > >     	} while (!ret);
> > > > > >     	args.status = hv_result(status);
> > > > > > diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
> > > > > > index b73352a7fc9e..c8e8976839f8 100644
> > > > > > --- a/include/asm-generic/mshyperv.h
> > > > > > +++ b/include/asm-generic/mshyperv.h
> > > > > > @@ -344,6 +344,7 @@ static inline bool hv_parent_partition(void)
> > > > > >     }
> > > > > >     bool hv_result_oom(u64 status);
> > > > > > +int hv_deposit_memory_node(int node, u64 partition_id, u64 status);
> > > > > >     int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
> > > > > >     int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
> > > > > >     int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
> > > > > > @@ -353,6 +354,10 @@ static inline bool hv_root_partition(void) { return false; }
> > > > > >     static inline bool hv_l1vh_partition(void) { return false; }
> > > > > >     static inline bool hv_parent_partition(void) { return false; }
> > > > > >     static inline bool hv_result_oom(u64 status) { return false; }
> > > > > > +static inline int hv_deposit_memory_node(int node, u64 partition_id, u64 status)
> > > > > > +{
> > > > > > +	return -EOPNOTSUPP;
> > > > > > +}
> > > > > >     static inline int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
> > > > > >     {
> > > > > >     	return -EOPNOTSUPP;
> > > > > > @@ -367,6 +372,11 @@ static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u3
> > > > > >     }
> > > > > >     #endif /* CONFIG_MSHV_ROOT */
> > > > > > +static inline int hv_deposit_memory(u64 partition_id, u64 status)
> > > > > > +{
> > > > > > +	return hv_deposit_memory_node(NUMA_NO_NODE, partition_id, status);
> > > > > > +}
> > > > > > +
> > > > > >     #if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
> > > > > >     u8 __init get_vtl(void);
> > > > > >     #else
> > > > > > 
> > > > > > 
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/4] mshv: Introduce hv_deposit_memory helper functions
  2026-01-28 23:18             ` Stanislav Kinsburskii
@ 2026-01-30  2:49               ` Mukesh R
  0 siblings, 0 replies; 13+ messages in thread
From: Mukesh R @ 2026-01-30  2:49 UTC (permalink / raw)
  To: Stanislav Kinsburskii
  Cc: kys, haiyangz, wei.liu, decui, longli, linux-hyperv, linux-kernel

On 1/28/26 15:18, Stanislav Kinsburskii wrote:
> On Tue, Jan 27, 2026 at 11:44:25AM -0800, Mukesh R wrote:
>> On 1/27/26 10:30, Stanislav Kinsburskii wrote:
>>> On Mon, Jan 26, 2026 at 06:06:23PM -0800, Mukesh R wrote:
>>>> On 1/25/26 14:41, Stanislav Kinsburskii wrote:
>>>>> On Fri, Jan 23, 2026 at 04:33:39PM -0800, Mukesh R wrote:
>>>>>> On 1/22/26 17:35, Stanislav Kinsburskii wrote:
>>>>>>> Introduce hv_deposit_memory_node() and hv_deposit_memory() helper
>>>>>>> functions to handle memory deposition with proper error handling.
>>>>>>>
>>>>>>> The new hv_deposit_memory_node() function takes the hypervisor status
>>>>>>> as a parameter and validates it before depositing pages. It checks for
>>>>>>> HV_STATUS_INSUFFICIENT_MEMORY specifically and returns an error for
>>>>>>> unexpected status codes.
>>>>>>>
>>>>>>> This is a precursor patch to new out-of-memory error codes support.
>>>>>>> No functional changes intended.
>>>>>>>
>>>>>>> Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
>>>>>>> ---
>>>>>>>      drivers/hv/hv_proc.c           |   22 ++++++++++++++++++++--
>>>>>>>      drivers/hv/mshv_root_hv_call.c |   25 +++++++++----------------
>>>>>>>      drivers/hv/mshv_root_main.c    |    3 +--
>>>>>>>      include/asm-generic/mshyperv.h |   10 ++++++++++
>>>>>>>      4 files changed, 40 insertions(+), 20 deletions(-)
>>>>>>>
>>>>>>> diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
>>>>>>> index 80c66d1c74d5..c0c2bfc80d77 100644
>>>>>>> --- a/drivers/hv/hv_proc.c
>>>>>>> +++ b/drivers/hv/hv_proc.c
>>>>>>> @@ -110,6 +110,23 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
>>>>>>>      }
>>>>>>>      EXPORT_SYMBOL_GPL(hv_call_deposit_pages);
>>>>>>> +int hv_deposit_memory_node(int node, u64 partition_id,
>>>>>>> +			   u64 hv_status)
>>>>>>> +{
>>>>>>> +	u32 num_pages;
>>>>>>> +
>>>>>>> +	switch (hv_result(hv_status)) {
>>>>>>> +	case HV_STATUS_INSUFFICIENT_MEMORY:
>>>>>>> +		num_pages = 1;
>>>>>>> +		break;
>>>>>>> +	default:
>>>>>>> +		hv_status_err(hv_status, "Unexpected!\n");
>>>>>>> +		return -ENOMEM;
>>>>>>> +	}
>>>>>>> +	return hv_call_deposit_pages(node, partition_id, num_pages);
>>>>>>> +}
>>>>>>> +EXPORT_SYMBOL_GPL(hv_deposit_memory_node);
>>>>>>> +
>>>>>>
>>>>>> Different hypercalls may want to deposit different number of pages in one
>>>>>> shot. As feature evolves, page sizes get mixed, we'd almost need that
>>>>>> flexibility. So, imo, either we just don't do this for now, or add num pages
>>>>>> parameter to be passed down.
>>>>>>
>>>>>
>>>>> What you do mean by "page sizes get mixed"?
>>>>> A helper to deposit num pages already exists: its
>>>>> hv_call_deposit_pages().
>>>>
>>>> My point, you are removing number of pages, and we may want to keep
>>>> that so one can quickly play around and change them.
>>>>
>>>> -                       ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>>> -                                                   pt_id, 1);
>>>> +                       ret = hv_deposit_memory(pt_id, status);
>>>>
>>>> For example, in hv_call_initialize_partition() we may realize after
>>>> some analysis that depositing 2 pages or 4 pages is much better.
>>>>
>>>
>>> We have been using this 1-page deposit logic from the beginning. To
>>> change the number of pages, simply replace hv_deposit_memory with
>>> hv_call_deposit_pages and specify the desired number of pages.
>>
>> You could perhaps rename it to hv_deposit_page().
>>
> 
> Yes, this would be a good name, but unfortunately we can now receive
> statuses like HV_STATUS_INSUFFICIENT_CONTIGUOUS_MEMORY, where we need to
> deposit at least 8 consecutive pages. There is also another pair of
> status codes for required root pages, even when a guest partition-related
> hypercall is performed (see the next patch for details).
> This new helper is intended to cover all such cases, instead of branching
> for all these different cases in every function.

Got it, thanks.

> Thanks,
> Stanislav
> 
> 
>>> The proposed approach reduces code duplication and is less error-prone,
>>> as there are multiple error codes to handle. Consolidating the logic
>>> also makes the driver more robust.
>>>
>>>
>>> Thanks,  Stanislav
>>>
>>>>> Thanks,
>>>>> Stanislav
>>>>>
>>>>>> Thanks,
>>>>>> -Mukesh
>>>>>>
>>>>>>
>>>>>>
>>>>>>>      bool hv_result_oom(u64 status)
>>>>>>>      {
>>>>>>>      	switch (hv_result(status)) {
>>>>>>> @@ -155,7 +172,8 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
>>>>>>>      			}
>>>>>>>      			break;
>>>>>>>      		}
>>>>>>> -		ret = hv_call_deposit_pages(node, hv_current_partition_id, 1);
>>>>>>> +		ret = hv_deposit_memory_node(node, hv_current_partition_id,
>>>>>>> +					     status);
>>>>>>>      	} while (!ret);
>>>>>>>      	return ret;
>>>>>>> @@ -197,7 +215,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
>>>>>>>      			}
>>>>>>>      			break;
>>>>>>>      		}
>>>>>>> -		ret = hv_call_deposit_pages(node, partition_id, 1);
>>>>>>> +		ret = hv_deposit_memory_node(node, partition_id, status);
>>>>>>>      	} while (!ret);
>>>>>>> diff --git a/drivers/hv/mshv_root_hv_call.c b/drivers/hv/mshv_root_hv_call.c
>>>>>>> index 58c5cbf2e567..06f2bac8039d 100644
>>>>>>> --- a/drivers/hv/mshv_root_hv_call.c
>>>>>>> +++ b/drivers/hv/mshv_root_hv_call.c
>>>>>>> @@ -123,8 +123,7 @@ int hv_call_create_partition(u64 flags,
>>>>>>>      			break;
>>>>>>>      		}
>>>>>>>      		local_irq_restore(irq_flags);
>>>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>>>>>> -					    hv_current_partition_id, 1);
>>>>>>> +		ret = hv_deposit_memory(hv_current_partition_id, status);
>>>>>>>      	} while (!ret);
>>>>>>>      	return ret;
>>>>>>> @@ -151,7 +150,7 @@ int hv_call_initialize_partition(u64 partition_id)
>>>>>>>      			ret = hv_result_to_errno(status);
>>>>>>>      			break;
>>>>>>>      		}
>>>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
>>>>>>> +		ret = hv_deposit_memory(partition_id, status);
>>>>>>>      	} while (!ret);
>>>>>>>      	return ret;
>>>>>>> @@ -465,8 +464,7 @@ int hv_call_get_vp_state(u32 vp_index, u64 partition_id,
>>>>>>>      		}
>>>>>>>      		local_irq_restore(flags);
>>>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>>>>>> -					    partition_id, 1);
>>>>>>> +		ret = hv_deposit_memory(partition_id, status);
>>>>>>>      	} while (!ret);
>>>>>>>      	return ret;
>>>>>>> @@ -525,8 +523,7 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_id,
>>>>>>>      		}
>>>>>>>      		local_irq_restore(flags);
>>>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>>>>>> -					    partition_id, 1);
>>>>>>> +		ret = hv_deposit_memory(partition_id, status);
>>>>>>>      	} while (!ret);
>>>>>>>      	return ret;
>>>>>>> @@ -573,7 +570,7 @@ static int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
>>>>>>>      		local_irq_restore(flags);
>>>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
>>>>>>> +		ret = hv_deposit_memory(partition_id, status);
>>>>>>>      	} while (!ret);
>>>>>>>      	return ret;
>>>>>>> @@ -722,8 +719,7 @@ hv_call_create_port(u64 port_partition_id, union hv_port_id port_id,
>>>>>>>      			ret = hv_result_to_errno(status);
>>>>>>>      			break;
>>>>>>>      		}
>>>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE, port_partition_id, 1);
>>>>>>> -
>>>>>>> +		ret = hv_deposit_memory(port_partition_id, status);
>>>>>>>      	} while (!ret);
>>>>>>>      	return ret;
>>>>>>> @@ -776,8 +772,7 @@ hv_call_connect_port(u64 port_partition_id, union hv_port_id port_id,
>>>>>>>      			ret = hv_result_to_errno(status);
>>>>>>>      			break;
>>>>>>>      		}
>>>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>>>>>> -					    connection_partition_id, 1);
>>>>>>> +		ret = hv_deposit_memory(connection_partition_id, status);
>>>>>>>      	} while (!ret);
>>>>>>>      	return ret;
>>>>>>> @@ -848,8 +843,7 @@ static int hv_call_map_stats_page2(enum hv_stats_object_type type,
>>>>>>>      			break;
>>>>>>>      		}
>>>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>>>>>> -					    hv_current_partition_id, 1);
>>>>>>> +		ret = hv_deposit_memory(hv_current_partition_id, status);
>>>>>>>      	} while (!ret);
>>>>>>>      	return ret;
>>>>>>> @@ -885,8 +879,7 @@ static int hv_call_map_stats_page(enum hv_stats_object_type type,
>>>>>>>      			return ret;
>>>>>>>      		}
>>>>>>> -		ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>>>>>> -					    hv_current_partition_id, 1);
>>>>>>> +		ret = hv_deposit_memory(hv_current_partition_id, status);
>>>>>>>      		if (ret)
>>>>>>>      			return ret;
>>>>>>>      	} while (!ret);
>>>>>>> diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
>>>>>>> index f4697497f83e..5fc572e31cd7 100644
>>>>>>> --- a/drivers/hv/mshv_root_main.c
>>>>>>> +++ b/drivers/hv/mshv_root_main.c
>>>>>>> @@ -264,8 +264,7 @@ static int mshv_ioctl_passthru_hvcall(struct mshv_partition *partition,
>>>>>>>      		if (!hv_result_oom(status))
>>>>>>>      			ret = hv_result_to_errno(status);
>>>>>>>      		else
>>>>>>> -			ret = hv_call_deposit_pages(NUMA_NO_NODE,
>>>>>>> -						    pt_id, 1);
>>>>>>> +			ret = hv_deposit_memory(pt_id, status);
>>>>>>>      	} while (!ret);
>>>>>>>      	args.status = hv_result(status);
>>>>>>> diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
>>>>>>> index b73352a7fc9e..c8e8976839f8 100644
>>>>>>> --- a/include/asm-generic/mshyperv.h
>>>>>>> +++ b/include/asm-generic/mshyperv.h
>>>>>>> @@ -344,6 +344,7 @@ static inline bool hv_parent_partition(void)
>>>>>>>      }
>>>>>>>      bool hv_result_oom(u64 status);
>>>>>>> +int hv_deposit_memory_node(int node, u64 partition_id, u64 status);
>>>>>>>      int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
>>>>>>>      int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
>>>>>>>      int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags);
>>>>>>> @@ -353,6 +354,10 @@ static inline bool hv_root_partition(void) { return false; }
>>>>>>>      static inline bool hv_l1vh_partition(void) { return false; }
>>>>>>>      static inline bool hv_parent_partition(void) { return false; }
>>>>>>>      static inline bool hv_result_oom(u64 status) { return false; }
>>>>>>> +static inline int hv_deposit_memory_node(int node, u64 partition_id, u64 status)
>>>>>>> +{
>>>>>>> +	return -EOPNOTSUPP;
>>>>>>> +}
>>>>>>>      static inline int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
>>>>>>>      {
>>>>>>>      	return -EOPNOTSUPP;
>>>>>>> @@ -367,6 +372,11 @@ static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u3
>>>>>>>      }
>>>>>>>      #endif /* CONFIG_MSHV_ROOT */
>>>>>>> +static inline int hv_deposit_memory(u64 partition_id, u64 status)
>>>>>>> +{
>>>>>>> +	return hv_deposit_memory_node(NUMA_NO_NODE, partition_id, status);
>>>>>>> +}
>>>>>>> +
>>>>>>>      #if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
>>>>>>>      u8 __init get_vtl(void);
>>>>>>>      #else
>>>>>>>
>>>>>>>
>>


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-01-30  2:49 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-23  1:35 [PATCH 0/4] Improve Hyper-V memory deposit error handling Stanislav Kinsburskii
2026-01-23  1:35 ` [PATCH 1/4] mshv: Introduce hv_result_oom() helper function Stanislav Kinsburskii
2026-01-24  0:31   ` Mukesh R
2026-01-23  1:35 ` [PATCH 2/4] mshv: Introduce hv_deposit_memory helper functions Stanislav Kinsburskii
2026-01-24  0:33   ` Mukesh R
2026-01-25 22:41     ` Stanislav Kinsburskii
2026-01-27  2:06       ` Mukesh R
2026-01-27 18:30         ` Stanislav Kinsburskii
2026-01-27 19:44           ` Mukesh R
2026-01-28 23:18             ` Stanislav Kinsburskii
2026-01-30  2:49               ` Mukesh R
2026-01-23  1:35 ` [PATCH 3/4] mshv: Handle insufficient contiguous memory hypervisor status Stanislav Kinsburskii
2026-01-23  1:35 ` [PATCH 4/4] mshv: Handle insufficient root memory hypervisor statuses Stanislav Kinsburskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox