* [PATCH v3 1/4] mshv: Introduce hv_result_needs_memory() helper function
2026-02-05 18:42 [PATCH v3 0/4] Improve Hyper-V memory deposit error handling Stanislav Kinsburskii
@ 2026-02-05 18:42 ` Stanislav Kinsburskii
2026-02-05 18:42 ` [PATCH v3 2/4] mshv: Introduce hv_deposit_memory helper functions Stanislav Kinsburskii
` (3 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: Stanislav Kinsburskii @ 2026-02-05 18:42 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_needs_memory() 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 | 25 ++++++++++++-------------
drivers/hv/mshv_root_main.c | 2 +-
include/asm-generic/mshyperv.h | 3 +++
4 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
index fbb4eb3901bb..e53204b9e05d 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_needs_memory(u64 status)
+{
+ switch (hv_result(status)) {
+ case HV_STATUS_INSUFFICIENT_MEMORY:
+ return true;
+ }
+ return false;
+}
+EXPORT_SYMBOL_GPL(hv_result_needs_memory);
+
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_needs_memory(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_needs_memory(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 daee036e48bc..1c4a2dbf49c0 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_needs_memory(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_needs_memory(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_needs_memory(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_needs_memory(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_needs_memory(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_needs_memory(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_needs_memory(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_needs_memory(status)) {
ret = hv_result_to_errno(status);
break;
}
@@ -850,7 +850,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_needs_memory(status)) {
hv_status_debug(status, "\n");
break;
}
@@ -899,7 +899,7 @@ hv_call_map_stats_page(enum hv_stats_object_type type,
struct hv_input_map_stats_page *input;
struct hv_output_map_stats_page *output;
u64 status, pfn;
- int hv_status, ret = 0;
+ int ret = 0;
do {
local_irq_save(flags);
@@ -915,13 +915,12 @@ hv_call_map_stats_page(enum hv_stats_object_type type,
local_irq_restore(flags);
- hv_status = hv_result(status);
- if (hv_status != HV_STATUS_INSUFFICIENT_MEMORY) {
+ if (!hv_result_needs_memory(status)) {
if (hv_result_success(status))
break;
if (hv_stats_get_area_type(type, identity) == HV_STATS_AREA_PARENT &&
- hv_status == HV_STATUS_INVALID_PARAMETER) {
+ hv_result(status) == HV_STATUS_INVALID_PARAMETER) {
*addr = NULL;
return 0;
}
diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
index b429bb1fdffa..f5525651a565 100644
--- a/drivers/hv/mshv_root_main.c
+++ b/drivers/hv/mshv_root_main.c
@@ -251,7 +251,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_needs_memory(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..452426d5b2ab 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_needs_memory(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_needs_memory(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] 12+ messages in thread* [PATCH v3 2/4] mshv: Introduce hv_deposit_memory helper functions
2026-02-05 18:42 [PATCH v3 0/4] Improve Hyper-V memory deposit error handling Stanislav Kinsburskii
2026-02-05 18:42 ` [PATCH v3 1/4] mshv: Introduce hv_result_needs_memory() helper function Stanislav Kinsburskii
@ 2026-02-05 18:42 ` Stanislav Kinsburskii
2026-02-05 18:42 ` [PATCH v3 3/4] mshv: Handle insufficient contiguous memory hypervisor status Stanislav Kinsburskii
` (2 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: Stanislav Kinsburskii @ 2026-02-05 18:42 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 | 21 +++++++++++++++++++--
drivers/hv/mshv_root_hv_call.c | 25 +++++++++----------------
drivers/hv/mshv_root_main.c | 3 +--
include/asm-generic/mshyperv.h | 10 ++++++++++
4 files changed, 39 insertions(+), 20 deletions(-)
diff --git a/drivers/hv/hv_proc.c b/drivers/hv/hv_proc.c
index e53204b9e05d..53622e5886b8 100644
--- a/drivers/hv/hv_proc.c
+++ b/drivers/hv/hv_proc.c
@@ -110,6 +110,22 @@ 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 = 1;
+
+ switch (hv_result(hv_status)) {
+ case HV_STATUS_INSUFFICIENT_MEMORY:
+ 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_needs_memory(u64 status)
{
switch (hv_result(status)) {
@@ -155,7 +171,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 +214,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 1c4a2dbf49c0..7f91096f95a8 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;
@@ -855,8 +850,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;
@@ -929,8 +923,7 @@ hv_call_map_stats_page(enum hv_stats_object_type type,
return hv_result_to_errno(status);
}
- 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 f5525651a565..cf58d9954638 100644
--- a/drivers/hv/mshv_root_main.c
+++ b/drivers/hv/mshv_root_main.c
@@ -254,8 +254,7 @@ static int mshv_ioctl_passthru_hvcall(struct mshv_partition *partition,
if (!hv_result_needs_memory(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 452426d5b2ab..d37b68238c97 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_needs_memory(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_needs_memory(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] 12+ messages in thread* [PATCH v3 3/4] mshv: Handle insufficient contiguous memory hypervisor status
2026-02-05 18:42 [PATCH v3 0/4] Improve Hyper-V memory deposit error handling Stanislav Kinsburskii
2026-02-05 18:42 ` [PATCH v3 1/4] mshv: Introduce hv_result_needs_memory() helper function Stanislav Kinsburskii
2026-02-05 18:42 ` [PATCH v3 2/4] mshv: Introduce hv_deposit_memory helper functions Stanislav Kinsburskii
@ 2026-02-05 18:42 ` Stanislav Kinsburskii
2026-02-05 18:42 ` [PATCH v3 4/4] mshv: Handle insufficient root memory hypervisor statuses Stanislav Kinsburskii
2026-02-19 6:49 ` [PATCH v3 0/4] Improve Hyper-V memory deposit error handling Wei Liu
4 siblings, 0 replies; 12+ messages in thread
From: Stanislav Kinsburskii @ 2026-02-05 18:42 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 f1c17fb60dc1..f20596276662 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -793,6 +793,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 53622e5886b8..181f6d02bce3 100644
--- a/drivers/hv/hv_proc.c
+++ b/drivers/hv/hv_proc.c
@@ -118,6 +118,9 @@ int hv_deposit_memory_node(int node, u64 partition_id,
switch (hv_result(hv_status)) {
case HV_STATUS_INSUFFICIENT_MEMORY:
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;
@@ -130,6 +133,7 @@ bool hv_result_needs_memory(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 30fbbde81c5c..99ea0d03e657 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 c0300910808b..091c03e26046 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] 12+ messages in thread* [PATCH v3 4/4] mshv: Handle insufficient root memory hypervisor statuses
2026-02-05 18:42 [PATCH v3 0/4] Improve Hyper-V memory deposit error handling Stanislav Kinsburskii
` (2 preceding siblings ...)
2026-02-05 18:42 ` [PATCH v3 3/4] mshv: Handle insufficient contiguous memory hypervisor status Stanislav Kinsburskii
@ 2026-02-05 18:42 ` Stanislav Kinsburskii
2026-02-06 5:56 ` Anirudh Rayabharam
2026-02-06 18:54 ` Michael Kelley
2026-02-19 6:49 ` [PATCH v3 0/4] Improve Hyper-V memory deposit error handling Wei Liu
4 siblings, 2 replies; 12+ messages in thread
From: Stanislav Kinsburskii @ 2026-02-05 18:42 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 f20596276662..6b67ac616789 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -794,6 +794,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 181f6d02bce3..5f4fd9c3231c 100644
--- a/drivers/hv/hv_proc.c
+++ b/drivers/hv/hv_proc.c
@@ -121,6 +121,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;
@@ -134,6 +146,8 @@ bool hv_result_needs_memory(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 99ea0d03e657..50f5a1419052 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] 12+ messages in thread* Re: [PATCH v3 4/4] mshv: Handle insufficient root memory hypervisor statuses
2026-02-05 18:42 ` [PATCH v3 4/4] mshv: Handle insufficient root memory hypervisor statuses Stanislav Kinsburskii
@ 2026-02-06 5:56 ` Anirudh Rayabharam
2026-02-06 17:02 ` Stanislav Kinsburskii
2026-02-19 6:44 ` Wei Liu
2026-02-06 18:54 ` Michael Kelley
1 sibling, 2 replies; 12+ messages in thread
From: Anirudh Rayabharam @ 2026-02-06 5:56 UTC (permalink / raw)
To: Stanislav Kinsburskii
Cc: kys, haiyangz, wei.liu, decui, longli, linux-hyperv, linux-kernel
On Thu, Feb 05, 2026 at 06:42:27PM +0000, Stanislav Kinsburskii wrote:
> 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.
I think you should rephrse this to:
"... should never occur in an L1VH partition"
because none of the errors in this patch series occur inside a guest. They
either occur in L1VH or root or both.
>
> 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 f20596276662..6b67ac616789 100644
> --- a/drivers/hv/hv_common.c
> +++ b/drivers/hv/hv_common.c
> @@ -794,6 +794,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 181f6d02bce3..5f4fd9c3231c 100644
> --- a/drivers/hv/hv_proc.c
> +++ b/drivers/hv/hv_proc.c
> @@ -121,6 +121,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:
I have the same comment as on v2 about num_pages being uninitialized when we
reach this case directly.
Thanks,
Anirudh.
> + 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;
> @@ -134,6 +146,8 @@ bool hv_result_needs_memory(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 99ea0d03e657..50f5a1419052 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 [flat|nested] 12+ messages in thread* Re: [PATCH v3 4/4] mshv: Handle insufficient root memory hypervisor statuses
2026-02-06 5:56 ` Anirudh Rayabharam
@ 2026-02-06 17:02 ` Stanislav Kinsburskii
2026-02-19 6:44 ` Wei Liu
1 sibling, 0 replies; 12+ messages in thread
From: Stanislav Kinsburskii @ 2026-02-06 17:02 UTC (permalink / raw)
To: Anirudh Rayabharam
Cc: kys, haiyangz, wei.liu, decui, longli, linux-hyperv, linux-kernel
On Fri, Feb 06, 2026 at 05:56:41AM +0000, Anirudh Rayabharam wrote:
> On Thu, Feb 05, 2026 at 06:42:27PM +0000, Stanislav Kinsburskii wrote:
> > 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.
>
> I think you should rephrse this to:
>
> "... should never occur in an L1VH partition"
>
> because none of the errors in this patch series occur inside a guest. They
> either occur in L1VH or root or both.
>
> >
> > 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 f20596276662..6b67ac616789 100644
> > --- a/drivers/hv/hv_common.c
> > +++ b/drivers/hv/hv_common.c
> > @@ -794,6 +794,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 181f6d02bce3..5f4fd9c3231c 100644
> > --- a/drivers/hv/hv_proc.c
> > +++ b/drivers/hv/hv_proc.c
> > @@ -121,6 +121,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:
>
> I have the same comment as on v2 about num_pages being uninitialized when we
> reach this case directly.
>
It is initialized to 1 on top of the function.
Thanks,
Stanislav.
> Thanks,
> Anirudh.
>
> > + 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;
> > @@ -134,6 +146,8 @@ bool hv_result_needs_memory(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 99ea0d03e657..50f5a1419052 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 [flat|nested] 12+ messages in thread* Re: [PATCH v3 4/4] mshv: Handle insufficient root memory hypervisor statuses
2026-02-06 5:56 ` Anirudh Rayabharam
2026-02-06 17:02 ` Stanislav Kinsburskii
@ 2026-02-19 6:44 ` Wei Liu
1 sibling, 0 replies; 12+ messages in thread
From: Wei Liu @ 2026-02-19 6:44 UTC (permalink / raw)
To: Anirudh Rayabharam
Cc: Stanislav Kinsburskii, kys, haiyangz, wei.liu, decui, longli,
linux-hyperv, linux-kernel
On Fri, Feb 06, 2026 at 05:56:41AM +0000, Anirudh Rayabharam wrote:
> On Thu, Feb 05, 2026 at 06:42:27PM +0000, Stanislav Kinsburskii wrote:
> > 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.
>
> I think you should rephrse this to:
>
> "... should never occur in an L1VH partition"
>
> because none of the errors in this patch series occur inside a guest. They
> either occur in L1VH or root or both.
I have dropped this note from the commit message. If anything, this
should be in the code so that it can be kept up to date.
Wei
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [PATCH v3 4/4] mshv: Handle insufficient root memory hypervisor statuses
2026-02-05 18:42 ` [PATCH v3 4/4] mshv: Handle insufficient root memory hypervisor statuses Stanislav Kinsburskii
2026-02-06 5:56 ` Anirudh Rayabharam
@ 2026-02-06 18:54 ` Michael Kelley
2026-02-19 6:47 ` Wei Liu
1 sibling, 1 reply; 12+ messages in thread
From: Michael Kelley @ 2026-02-06 18:54 UTC (permalink / raw)
To: Stanislav Kinsburskii, kys@microsoft.com, haiyangz@microsoft.com,
wei.liu@kernel.org, decui@microsoft.com, longli@microsoft.com
Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
From: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com> Sent: Thursday, February 5, 2026 10:42 AM
> To: kys@microsoft.com; haiyangz@microsoft.com; wei.liu@kernel.org;
> decui@microsoft.com; longli@microsoft.com
> Cc: linux-hyperv@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: [PATCH v3 4/4] mshv: Handle insufficient root memory hypervisor statuses
>
> 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 f20596276662..6b67ac616789 100644
> --- a/drivers/hv/hv_common.c
> +++ b/drivers/hv/hv_common.c
> @@ -794,6 +794,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 181f6d02bce3..5f4fd9c3231c 100644
> --- a/drivers/hv/hv_proc.c
> +++ b/drivers/hv/hv_proc.c
> @@ -121,6 +121,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;
> +
Per the discussion in v1 of this patch set, if the number of pages that should be
deposited in a particular situation is different from what this function provides,
the fallback is to use hv_call_deposit_pages() directly. From what I see, there's
only one such fallback case after a hypercall failure -- in hv_do_map_gpa_hcall().
The other uses of hv_call_deposit_pages() are initial deposits when creating a
VP or partition.
But if hv_call_deposit_pages() is used directly, the logic added here to detect
insufficient root memory and deposit to HV_PARTITION_ID_SELF isn't applied.
So if the hypercall in hv_do_map_gpa_hcall() fails with insufficient root
memory, the deposit is done to the wrong partition ID. If that case can
actually happen, then some additional logic is needed in
hv_do_map_gpa_hcall() to handle it. Or there needs to be a fallback
function that contains the logic.
Other than that, everything else in this patch set looks good to me.
Michael
> default:
> hv_status_err(hv_status, "Unexpected!\n");
> return -ENOMEM;
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v3 4/4] mshv: Handle insufficient root memory hypervisor statuses
2026-02-06 18:54 ` Michael Kelley
@ 2026-02-19 6:47 ` Wei Liu
2026-02-19 21:46 ` Stanislav Kinsburskii
0 siblings, 1 reply; 12+ messages in thread
From: Wei Liu @ 2026-02-19 6:47 UTC (permalink / raw)
To: Michael Kelley
Cc: Stanislav Kinsburskii, kys@microsoft.com, haiyangz@microsoft.com,
wei.liu@kernel.org, decui@microsoft.com, longli@microsoft.com,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
On Fri, Feb 06, 2026 at 06:54:55PM +0000, Michael Kelley wrote:
> From: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com> Sent: Thursday, February 5, 2026 10:42 AM
> > To: kys@microsoft.com; haiyangz@microsoft.com; wei.liu@kernel.org;
> > decui@microsoft.com; longli@microsoft.com
> > Cc: linux-hyperv@vger.kernel.org; linux-kernel@vger.kernel.org
> > Subject: [PATCH v3 4/4] mshv: Handle insufficient root memory hypervisor statuses
> >
> > 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 f20596276662..6b67ac616789 100644
> > --- a/drivers/hv/hv_common.c
> > +++ b/drivers/hv/hv_common.c
> > @@ -794,6 +794,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 181f6d02bce3..5f4fd9c3231c 100644
> > --- a/drivers/hv/hv_proc.c
> > +++ b/drivers/hv/hv_proc.c
> > @@ -121,6 +121,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;
> > +
>
> Per the discussion in v1 of this patch set, if the number of pages that should be
> deposited in a particular situation is different from what this function provides,
> the fallback is to use hv_call_deposit_pages() directly. From what I see, there's
> only one such fallback case after a hypercall failure -- in hv_do_map_gpa_hcall().
> The other uses of hv_call_deposit_pages() are initial deposits when creating a
> VP or partition.
>
> But if hv_call_deposit_pages() is used directly, the logic added here to detect
> insufficient root memory and deposit to HV_PARTITION_ID_SELF isn't applied.
> So if the hypercall in hv_do_map_gpa_hcall() fails with insufficient root
> memory, the deposit is done to the wrong partition ID. If that case can
> actually happen, then some additional logic is needed in
> hv_do_map_gpa_hcall() to handle it. Or there needs to be a fallback
> function that contains the logic.
Stanislav, how about this comment? Please submit a follow-up patch if
necessary.
Wei
>
> Other than that, everything else in this patch set looks good to me.
>
> Michael
>
> > default:
> > hv_status_err(hv_status, "Unexpected!\n");
> > return -ENOMEM;
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v3 4/4] mshv: Handle insufficient root memory hypervisor statuses
2026-02-19 6:47 ` Wei Liu
@ 2026-02-19 21:46 ` Stanislav Kinsburskii
0 siblings, 0 replies; 12+ messages in thread
From: Stanislav Kinsburskii @ 2026-02-19 21:46 UTC (permalink / raw)
To: Wei Liu
Cc: Michael Kelley, kys@microsoft.com, haiyangz@microsoft.com,
decui@microsoft.com, longli@microsoft.com,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
On Thu, Feb 19, 2026 at 06:47:01AM +0000, Wei Liu wrote:
> On Fri, Feb 06, 2026 at 06:54:55PM +0000, Michael Kelley wrote:
> > From: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com> Sent: Thursday, February 5, 2026 10:42 AM
> > > To: kys@microsoft.com; haiyangz@microsoft.com; wei.liu@kernel.org;
> > > decui@microsoft.com; longli@microsoft.com
> > > Cc: linux-hyperv@vger.kernel.org; linux-kernel@vger.kernel.org
> > > Subject: [PATCH v3 4/4] mshv: Handle insufficient root memory hypervisor statuses
> > >
> > > 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 f20596276662..6b67ac616789 100644
> > > --- a/drivers/hv/hv_common.c
> > > +++ b/drivers/hv/hv_common.c
> > > @@ -794,6 +794,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 181f6d02bce3..5f4fd9c3231c 100644
> > > --- a/drivers/hv/hv_proc.c
> > > +++ b/drivers/hv/hv_proc.c
> > > @@ -121,6 +121,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;
> > > +
> >
> > Per the discussion in v1 of this patch set, if the number of pages that should be
> > deposited in a particular situation is different from what this function provides,
> > the fallback is to use hv_call_deposit_pages() directly. From what I see, there's
> > only one such fallback case after a hypercall failure -- in hv_do_map_gpa_hcall().
> > The other uses of hv_call_deposit_pages() are initial deposits when creating a
> > VP or partition.
> >
> > But if hv_call_deposit_pages() is used directly, the logic added here to detect
> > insufficient root memory and deposit to HV_PARTITION_ID_SELF isn't applied.
> > So if the hypercall in hv_do_map_gpa_hcall() fails with insufficient root
> > memory, the deposit is done to the wrong partition ID. If that case can
> > actually happen, then some additional logic is needed in
> > hv_do_map_gpa_hcall() to handle it. Or there needs to be a fallback
> > function that contains the logic.
>
> Stanislav, how about this comment? Please submit a follow-up patch if
> necessary.
>
I'll sumbit a follow-up patch.
Thanks,
Stanislav
> Wei
>
> >
> > Other than that, everything else in this patch set looks good to me.
> >
> > Michael
> >
> > > default:
> > > hv_status_err(hv_status, "Unexpected!\n");
> > > return -ENOMEM;
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v3 0/4] Improve Hyper-V memory deposit error handling
2026-02-05 18:42 [PATCH v3 0/4] Improve Hyper-V memory deposit error handling Stanislav Kinsburskii
` (3 preceding siblings ...)
2026-02-05 18:42 ` [PATCH v3 4/4] mshv: Handle insufficient root memory hypervisor statuses Stanislav Kinsburskii
@ 2026-02-19 6:49 ` Wei Liu
4 siblings, 0 replies; 12+ messages in thread
From: Wei Liu @ 2026-02-19 6:49 UTC (permalink / raw)
To: Stanislav Kinsburskii
Cc: kys, haiyangz, wei.liu, decui, longli, linux-hyperv, linux-kernel
On Thu, Feb 05, 2026 at 06:42:04PM +0000, Stanislav Kinsburskii wrote:
> This series extends the MSHV driver to properly handle additional
> memory-related error codes from the Microsoft 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 a dedicated 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.
>
> v3:
> - Fix uninitialized num_pages variable in hv_deposit_memory_node() in case
> of HV_STATUS_INSUFFICIENT_ROOT_MEMORY status
>
I fixed a typo pointed out by Mukesh in the previous version, dropped
the note from the commit message in the last patch, and applied this to
hyperv-next.
Please address Michael's comment in patch four and send out a follow-up
patch if necessary.
Wei
^ permalink raw reply [flat|nested] 12+ messages in thread