mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 01:04:41 +01:00
mshv: Introduce hv_deposit_memory helper functions
Introduce hv_deposit_memory_node() and hv_deposit_memory() helper functions to handle memory deposit 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> Reviewed-by: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com> Reviewed-by: Mukesh R <mrathor@linux.microsoft.com> Signed-off-by: Wei Liu <wei.liu@kernel.org>
This commit is contained in:
parent
7db44aa173
commit
ede54383e6
4 changed files with 39 additions and 20 deletions
|
|
@ -110,6 +110,22 @@ free_buf:
|
|||
}
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -255,8 +255,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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue