Skip to content

Commit ede5438

Browse files
Stanislav Kinsburskiiliuw
authored andcommitted
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>
1 parent 7db44aa commit ede5438

4 files changed

Lines changed: 39 additions & 20 deletions

File tree

drivers/hv/hv_proc.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,22 @@ int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
110110
}
111111
EXPORT_SYMBOL_GPL(hv_call_deposit_pages);
112112

113+
int hv_deposit_memory_node(int node, u64 partition_id,
114+
u64 hv_status)
115+
{
116+
u32 num_pages = 1;
117+
118+
switch (hv_result(hv_status)) {
119+
case HV_STATUS_INSUFFICIENT_MEMORY:
120+
break;
121+
default:
122+
hv_status_err(hv_status, "Unexpected!\n");
123+
return -ENOMEM;
124+
}
125+
return hv_call_deposit_pages(node, partition_id, num_pages);
126+
}
127+
EXPORT_SYMBOL_GPL(hv_deposit_memory_node);
128+
113129
bool hv_result_needs_memory(u64 status)
114130
{
115131
switch (hv_result(status)) {
@@ -155,7 +171,8 @@ int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
155171
}
156172
break;
157173
}
158-
ret = hv_call_deposit_pages(node, hv_current_partition_id, 1);
174+
ret = hv_deposit_memory_node(node, hv_current_partition_id,
175+
status);
159176
} while (!ret);
160177

161178
return ret;
@@ -197,7 +214,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
197214
}
198215
break;
199216
}
200-
ret = hv_call_deposit_pages(node, partition_id, 1);
217+
ret = hv_deposit_memory_node(node, partition_id, status);
201218

202219
} while (!ret);
203220

drivers/hv/mshv_root_hv_call.c

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ int hv_call_create_partition(u64 flags,
123123
break;
124124
}
125125
local_irq_restore(irq_flags);
126-
ret = hv_call_deposit_pages(NUMA_NO_NODE,
127-
hv_current_partition_id, 1);
126+
ret = hv_deposit_memory(hv_current_partition_id, status);
128127
} while (!ret);
129128

130129
return ret;
@@ -151,7 +150,7 @@ int hv_call_initialize_partition(u64 partition_id)
151150
ret = hv_result_to_errno(status);
152151
break;
153152
}
154-
ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
153+
ret = hv_deposit_memory(partition_id, status);
155154
} while (!ret);
156155

157156
return ret;
@@ -465,8 +464,7 @@ int hv_call_get_vp_state(u32 vp_index, u64 partition_id,
465464
}
466465
local_irq_restore(flags);
467466

468-
ret = hv_call_deposit_pages(NUMA_NO_NODE,
469-
partition_id, 1);
467+
ret = hv_deposit_memory(partition_id, status);
470468
} while (!ret);
471469

472470
return ret;
@@ -525,8 +523,7 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_id,
525523
}
526524
local_irq_restore(flags);
527525

528-
ret = hv_call_deposit_pages(NUMA_NO_NODE,
529-
partition_id, 1);
526+
ret = hv_deposit_memory(partition_id, status);
530527
} while (!ret);
531528

532529
return ret;
@@ -573,7 +570,7 @@ static int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
573570

574571
local_irq_restore(flags);
575572

576-
ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1);
573+
ret = hv_deposit_memory(partition_id, status);
577574
} while (!ret);
578575

579576
return ret;
@@ -722,8 +719,7 @@ hv_call_create_port(u64 port_partition_id, union hv_port_id port_id,
722719
ret = hv_result_to_errno(status);
723720
break;
724721
}
725-
ret = hv_call_deposit_pages(NUMA_NO_NODE, port_partition_id, 1);
726-
722+
ret = hv_deposit_memory(port_partition_id, status);
727723
} while (!ret);
728724

729725
return ret;
@@ -776,8 +772,7 @@ hv_call_connect_port(u64 port_partition_id, union hv_port_id port_id,
776772
ret = hv_result_to_errno(status);
777773
break;
778774
}
779-
ret = hv_call_deposit_pages(NUMA_NO_NODE,
780-
connection_partition_id, 1);
775+
ret = hv_deposit_memory(connection_partition_id, status);
781776
} while (!ret);
782777

783778
return ret;
@@ -855,8 +850,7 @@ static int hv_call_map_stats_page2(enum hv_stats_object_type type,
855850
break;
856851
}
857852

858-
ret = hv_call_deposit_pages(NUMA_NO_NODE,
859-
hv_current_partition_id, 1);
853+
ret = hv_deposit_memory(hv_current_partition_id, status);
860854
} while (!ret);
861855

862856
return ret;
@@ -929,8 +923,7 @@ hv_call_map_stats_page(enum hv_stats_object_type type,
929923
return hv_result_to_errno(status);
930924
}
931925

932-
ret = hv_call_deposit_pages(NUMA_NO_NODE,
933-
hv_current_partition_id, 1);
926+
ret = hv_deposit_memory(hv_current_partition_id, status);
934927
if (ret)
935928
return ret;
936929
} while (!ret);

drivers/hv/mshv_root_main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@ static int mshv_ioctl_passthru_hvcall(struct mshv_partition *partition,
255255
if (!hv_result_needs_memory(status))
256256
ret = hv_result_to_errno(status);
257257
else
258-
ret = hv_call_deposit_pages(NUMA_NO_NODE,
259-
pt_id, 1);
258+
ret = hv_deposit_memory(pt_id, status);
260259
} while (!ret);
261260

262261
args.status = hv_result(status);

include/asm-generic/mshyperv.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ static inline bool hv_parent_partition(void)
344344
}
345345

346346
bool hv_result_needs_memory(u64 status);
347+
int hv_deposit_memory_node(int node, u64 partition_id, u64 status);
347348
int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
348349
int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
349350
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; }
353354
static inline bool hv_l1vh_partition(void) { return false; }
354355
static inline bool hv_parent_partition(void) { return false; }
355356
static inline bool hv_result_needs_memory(u64 status) { return false; }
357+
static inline int hv_deposit_memory_node(int node, u64 partition_id, u64 status)
358+
{
359+
return -EOPNOTSUPP;
360+
}
356361
static inline int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
357362
{
358363
return -EOPNOTSUPP;
@@ -367,6 +372,11 @@ static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u3
367372
}
368373
#endif /* CONFIG_MSHV_ROOT */
369374

375+
static inline int hv_deposit_memory(u64 partition_id, u64 status)
376+
{
377+
return hv_deposit_memory_node(NUMA_NO_NODE, partition_id, status);
378+
}
379+
370380
#if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
371381
u8 __init get_vtl(void);
372382
#else

0 commit comments

Comments
 (0)