Commit 7db44aa1 authored by Stanislav Kinsburskii's avatar Stanislav Kinsburskii Committed by Wei Liu
Browse files

mshv: Introduce hv_result_needs_memory() helper function



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: default avatarStanislav Kinsburskii <skinsburskii@linux.microsoft.com>
Reviewed-by: default avatarAnirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com>
Reviewed-by: default avatarMukesh R <mrathor@linux.microsoft.com>
Signed-off-by: default avatarWei Liu <wei.liu@kernel.org>
parent 8927a108
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -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);
+12 −13
Original line number Diff line number Diff line
@@ -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;
			}
+1 −1
Original line number Diff line number Diff line
@@ -252,7 +252,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,
+3 −0
Original line number Diff line number Diff line
@@ -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;