* [PATCH v2 0/4] Improve Hyper-V memory deposit error handling
@ 2026-02-02 17:58 Stanislav Kinsburskii
2026-02-02 17:58 ` [PATCH v2 1/4] mshv: Introduce hv_result_needs_memory() helper function Stanislav Kinsburskii
` (4 more replies)
0 siblings, 5 replies; 12+ messages in thread
From: Stanislav Kinsburskii @ 2026-02-02 17:58 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 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.
v2:
- Rename hv_result_oom() into hv_result_needs_memory()
---
Stanislav Kinsburskii (4):
mshv: Introduce hv_result_needs_memory() helper function
mshv: Introduce hv_deposit_memory helper functions
mshv: Handle insufficient contiguous memory hypervisor status
mshv: Handle insufficient root memory hypervisor statuses
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] 12+ messages in thread
* [PATCH v2 1/4] mshv: Introduce hv_result_needs_memory() helper function
2026-02-02 17:58 [PATCH v2 0/4] Improve Hyper-V memory deposit error handling Stanislav Kinsburskii
@ 2026-02-02 17:58 ` Stanislav Kinsburskii
2026-02-05 17:58 ` Anirudh Rayabharam
2026-02-02 17:59 ` [PATCH v2 2/4] mshv: Introduce hv_deposit_memory helper functions Stanislav Kinsburskii
` (3 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Stanislav Kinsburskii @ 2026-02-02 17:58 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 | 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..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 598eaff4ff29..89afeeda21dd 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;
}
@@ -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_needs_memory(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_needs_memory(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 6a6bf641b352..ee30bfa6bb2e 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_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 v2 2/4] mshv: Introduce hv_deposit_memory helper functions
2026-02-02 17:58 [PATCH v2 0/4] Improve Hyper-V memory deposit error handling Stanislav Kinsburskii
2026-02-02 17:58 ` [PATCH v2 1/4] mshv: Introduce hv_result_needs_memory() helper function Stanislav Kinsburskii
@ 2026-02-02 17:59 ` Stanislav Kinsburskii
2026-02-03 23:01 ` Mukesh R
2026-02-05 18:01 ` Anirudh Rayabharam
2026-02-02 17:59 ` [PATCH v2 3/4] mshv: Handle insufficient contiguous memory hypervisor status Stanislav Kinsburskii
` (2 subsequent siblings)
4 siblings, 2 replies; 12+ messages in thread
From: Stanislav Kinsburskii @ 2026-02-02 17:59 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 e53204b9e05d..ffa25cd6e4e9 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_needs_memory(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 89afeeda21dd..174431cb5e0e 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 ee30bfa6bb2e..dce255c94f9e 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_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 v2 3/4] mshv: Handle insufficient contiguous memory hypervisor status
2026-02-02 17:58 [PATCH v2 0/4] Improve Hyper-V memory deposit error handling Stanislav Kinsburskii
2026-02-02 17:58 ` [PATCH v2 1/4] mshv: Introduce hv_result_needs_memory() helper function Stanislav Kinsburskii
2026-02-02 17:59 ` [PATCH v2 2/4] mshv: Introduce hv_deposit_memory helper functions Stanislav Kinsburskii
@ 2026-02-02 17:59 ` Stanislav Kinsburskii
2026-02-05 18:03 ` Anirudh Rayabharam
2026-02-02 17:59 ` [PATCH v2 4/4] mshv: Handle insufficient root memory hypervisor statuses Stanislav Kinsburskii
2026-02-03 23:03 ` [PATCH v2 0/4] Improve Hyper-V memory deposit error handling Mukesh R
4 siblings, 1 reply; 12+ messages in thread
From: Stanislav Kinsburskii @ 2026-02-02 17:59 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 ffa25cd6e4e9..dfa27be66ff7 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_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 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 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 v2 4/4] mshv: Handle insufficient root memory hypervisor statuses
2026-02-02 17:58 [PATCH v2 0/4] Improve Hyper-V memory deposit error handling Stanislav Kinsburskii
` (2 preceding siblings ...)
2026-02-02 17:59 ` [PATCH v2 3/4] mshv: Handle insufficient contiguous memory hypervisor status Stanislav Kinsburskii
@ 2026-02-02 17:59 ` Stanislav Kinsburskii
2026-02-05 18:07 ` Anirudh Rayabharam
2026-02-03 23:03 ` [PATCH v2 0/4] Improve Hyper-V memory deposit error handling Mukesh R
4 siblings, 1 reply; 12+ messages in thread
From: Stanislav Kinsburskii @ 2026-02-02 17:59 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 dfa27be66ff7..935129e0b39d 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_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 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] 12+ messages in thread
* Re: [PATCH v2 2/4] mshv: Introduce hv_deposit_memory helper functions
2026-02-02 17:59 ` [PATCH v2 2/4] mshv: Introduce hv_deposit_memory helper functions Stanislav Kinsburskii
@ 2026-02-03 23:01 ` Mukesh R
2026-02-05 18:01 ` Anirudh Rayabharam
1 sibling, 0 replies; 12+ messages in thread
From: Mukesh R @ 2026-02-03 23:01 UTC (permalink / raw)
To: Stanislav Kinsburskii, kys, haiyangz, wei.liu, decui, longli
Cc: linux-hyperv, linux-kernel
On 2/2/26 09:59, Stanislav Kinsburskii wrote:
> Introduce hv_deposit_memory_node() and hv_deposit_memory() helper
> functions to handle memory deposition with proper error handling.
deposition is a legal thing :) ... i think you just mean deposit.
> 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 e53204b9e05d..ffa25cd6e4e9 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_needs_memory(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 89afeeda21dd..174431cb5e0e 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 ee30bfa6bb2e..dce255c94f9e 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_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 [flat|nested] 12+ messages in thread
* Re: [PATCH v2 0/4] Improve Hyper-V memory deposit error handling
2026-02-02 17:58 [PATCH v2 0/4] Improve Hyper-V memory deposit error handling Stanislav Kinsburskii
` (3 preceding siblings ...)
2026-02-02 17:59 ` [PATCH v2 4/4] mshv: Handle insufficient root memory hypervisor statuses Stanislav Kinsburskii
@ 2026-02-03 23:03 ` Mukesh R
4 siblings, 0 replies; 12+ messages in thread
From: Mukesh R @ 2026-02-03 23:03 UTC (permalink / raw)
To: Stanislav Kinsburskii, kys, haiyangz, wei.liu, decui, longli
Cc: linux-hyperv, linux-kernel
On 2/2/26 09:58, 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.
>
> v2:
> - Rename hv_result_oom() into hv_result_needs_memory()
>
> ---
>
> Stanislav Kinsburskii (4):
> mshv: Introduce hv_result_needs_memory() helper function
> mshv: Introduce hv_deposit_memory helper functions
> mshv: Handle insufficient contiguous memory hypervisor status
> mshv: Handle insufficient root memory hypervisor statuses
>
>
> 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(-)
>
for the whole series:
Reviewed-by: Mukesh R <mrathor@linux.microsoft.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/4] mshv: Introduce hv_result_needs_memory() helper function
2026-02-02 17:58 ` [PATCH v2 1/4] mshv: Introduce hv_result_needs_memory() helper function Stanislav Kinsburskii
@ 2026-02-05 17:58 ` Anirudh Rayabharam
0 siblings, 0 replies; 12+ messages in thread
From: Anirudh Rayabharam @ 2026-02-05 17:58 UTC (permalink / raw)
To: Stanislav Kinsburskii
Cc: kys, haiyangz, wei.liu, decui, longli, linux-hyperv, linux-kernel
On Mon, Feb 02, 2026 at 05:58:57PM +0000, Stanislav Kinsburskii wrote:
> 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 | 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..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 598eaff4ff29..89afeeda21dd 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;
> }
> @@ -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_needs_memory(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_needs_memory(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 6a6bf641b352..ee30bfa6bb2e 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_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;
>
>
Reviewed-by: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 2/4] mshv: Introduce hv_deposit_memory helper functions
2026-02-02 17:59 ` [PATCH v2 2/4] mshv: Introduce hv_deposit_memory helper functions Stanislav Kinsburskii
2026-02-03 23:01 ` Mukesh R
@ 2026-02-05 18:01 ` Anirudh Rayabharam
1 sibling, 0 replies; 12+ messages in thread
From: Anirudh Rayabharam @ 2026-02-05 18:01 UTC (permalink / raw)
To: Stanislav Kinsburskii
Cc: kys, haiyangz, wei.liu, decui, longli, linux-hyperv, linux-kernel
On Mon, Feb 02, 2026 at 05:59:03PM +0000, 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 e53204b9e05d..ffa25cd6e4e9 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_needs_memory(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 89afeeda21dd..174431cb5e0e 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 ee30bfa6bb2e..dce255c94f9e 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_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
>
>
Reviewed-by: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 3/4] mshv: Handle insufficient contiguous memory hypervisor status
2026-02-02 17:59 ` [PATCH v2 3/4] mshv: Handle insufficient contiguous memory hypervisor status Stanislav Kinsburskii
@ 2026-02-05 18:03 ` Anirudh Rayabharam
0 siblings, 0 replies; 12+ messages in thread
From: Anirudh Rayabharam @ 2026-02-05 18:03 UTC (permalink / raw)
To: Stanislav Kinsburskii
Cc: kys, haiyangz, wei.liu, decui, longli, linux-hyperv, linux-kernel
On Mon, Feb 02, 2026 at 05:59:09PM +0000, Stanislav Kinsburskii wrote:
> 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 ffa25cd6e4e9..dfa27be66ff7 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_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 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 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.
> */
>
>
Reviewed-by: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 4/4] mshv: Handle insufficient root memory hypervisor statuses
2026-02-02 17:59 ` [PATCH v2 4/4] mshv: Handle insufficient root memory hypervisor statuses Stanislav Kinsburskii
@ 2026-02-05 18:07 ` Anirudh Rayabharam
2026-02-05 18:36 ` Stanislav Kinsburskii
0 siblings, 1 reply; 12+ messages in thread
From: Anirudh Rayabharam @ 2026-02-05 18:07 UTC (permalink / raw)
To: Stanislav Kinsburskii
Cc: kys, haiyangz, wei.liu, decui, longli, linux-hyperv, linux-kernel
On Mon, Feb 02, 2026 at 05:59:14PM +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.
>
> 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 dfa27be66ff7..935129e0b39d 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:
Is num_pages 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;
> @@ -135,6 +147,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 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 [flat|nested] 12+ messages in thread
* Re: [PATCH v2 4/4] mshv: Handle insufficient root memory hypervisor statuses
2026-02-05 18:07 ` Anirudh Rayabharam
@ 2026-02-05 18:36 ` Stanislav Kinsburskii
0 siblings, 0 replies; 12+ messages in thread
From: Stanislav Kinsburskii @ 2026-02-05 18:36 UTC (permalink / raw)
To: Anirudh Rayabharam
Cc: kys, haiyangz, wei.liu, decui, longli, linux-hyperv, linux-kernel
On Thu, Feb 05, 2026 at 11:37:49PM +0530, Anirudh Rayabharam wrote:
> On Mon, Feb 02, 2026 at 05:59:14PM +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.
> >
> > 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 dfa27be66ff7..935129e0b39d 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:
>
> Is num_pages uninitialized when we reach this case directly?
>
It actually does not. I'll fix it.
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;
> > @@ -135,6 +147,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 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 [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-02-05 18:37 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-02 17:58 [PATCH v2 0/4] Improve Hyper-V memory deposit error handling Stanislav Kinsburskii
2026-02-02 17:58 ` [PATCH v2 1/4] mshv: Introduce hv_result_needs_memory() helper function Stanislav Kinsburskii
2026-02-05 17:58 ` Anirudh Rayabharam
2026-02-02 17:59 ` [PATCH v2 2/4] mshv: Introduce hv_deposit_memory helper functions Stanislav Kinsburskii
2026-02-03 23:01 ` Mukesh R
2026-02-05 18:01 ` Anirudh Rayabharam
2026-02-02 17:59 ` [PATCH v2 3/4] mshv: Handle insufficient contiguous memory hypervisor status Stanislav Kinsburskii
2026-02-05 18:03 ` Anirudh Rayabharam
2026-02-02 17:59 ` [PATCH v2 4/4] mshv: Handle insufficient root memory hypervisor statuses Stanislav Kinsburskii
2026-02-05 18:07 ` Anirudh Rayabharam
2026-02-05 18:36 ` Stanislav Kinsburskii
2026-02-03 23:03 ` [PATCH v2 0/4] Improve Hyper-V memory deposit error handling Mukesh R
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox