Skip to content

Commit 7db44aa

Browse files
Stanislav Kinsburskiiliuw
authored andcommitted
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: 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 8927a10 commit 7db44aa

4 files changed

Lines changed: 28 additions & 16 deletions

File tree

drivers/hv/hv_proc.c

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

113+
bool hv_result_needs_memory(u64 status)
114+
{
115+
switch (hv_result(status)) {
116+
case HV_STATUS_INSUFFICIENT_MEMORY:
117+
return true;
118+
}
119+
return false;
120+
}
121+
EXPORT_SYMBOL_GPL(hv_result_needs_memory);
122+
113123
int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id)
114124
{
115125
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)
137147
input, output);
138148
local_irq_restore(flags);
139149

140-
if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
150+
if (!hv_result_needs_memory(status)) {
141151
if (!hv_result_success(status)) {
142152
hv_status_err(status, "cpu %u apic ID: %u\n",
143153
lp_index, apic_id);
@@ -179,7 +189,7 @@ int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags)
179189
status = hv_do_hypercall(HVCALL_CREATE_VP, input, NULL);
180190
local_irq_restore(irq_flags);
181191

182-
if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
192+
if (!hv_result_needs_memory(status)) {
183193
if (!hv_result_success(status)) {
184194
hv_status_err(status, "vcpu: %u, lp: %u\n",
185195
vp_index, flags);

drivers/hv/mshv_root_hv_call.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ int hv_call_create_partition(u64 flags,
115115
status = hv_do_hypercall(HVCALL_CREATE_PARTITION,
116116
input, output);
117117

118-
if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
118+
if (!hv_result_needs_memory(status)) {
119119
if (hv_result_success(status))
120120
*partition_id = output->partition_id;
121121
local_irq_restore(irq_flags);
@@ -147,7 +147,7 @@ int hv_call_initialize_partition(u64 partition_id)
147147
status = hv_do_fast_hypercall8(HVCALL_INITIALIZE_PARTITION,
148148
*(u64 *)&input);
149149

150-
if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
150+
if (!hv_result_needs_memory(status)) {
151151
ret = hv_result_to_errno(status);
152152
break;
153153
}
@@ -239,7 +239,7 @@ static int hv_do_map_gpa_hcall(u64 partition_id, u64 gfn, u64 page_struct_count,
239239

240240
completed = hv_repcomp(status);
241241

242-
if (hv_result(status) == HV_STATUS_INSUFFICIENT_MEMORY) {
242+
if (hv_result_needs_memory(status)) {
243243
ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id,
244244
HV_MAP_GPA_DEPOSIT_PAGES);
245245
if (ret)
@@ -455,7 +455,7 @@ int hv_call_get_vp_state(u32 vp_index, u64 partition_id,
455455

456456
status = hv_do_hypercall(control, input, output);
457457

458-
if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
458+
if (!hv_result_needs_memory(status)) {
459459
if (hv_result_success(status) && ret_output)
460460
memcpy(ret_output, output, sizeof(*output));
461461

@@ -518,7 +518,7 @@ int hv_call_set_vp_state(u32 vp_index, u64 partition_id,
518518

519519
status = hv_do_hypercall(control, input, NULL);
520520

521-
if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
521+
if (!hv_result_needs_memory(status)) {
522522
local_irq_restore(flags);
523523
ret = hv_result_to_errno(status);
524524
break;
@@ -563,7 +563,7 @@ static int hv_call_map_vp_state_page(u64 partition_id, u32 vp_index, u32 type,
563563
status = hv_do_hypercall(HVCALL_MAP_VP_STATE_PAGE, input,
564564
output);
565565

566-
if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
566+
if (!hv_result_needs_memory(status)) {
567567
if (hv_result_success(status))
568568
*state_page = pfn_to_page(output->map_location);
569569
local_irq_restore(flags);
@@ -718,7 +718,7 @@ hv_call_create_port(u64 port_partition_id, union hv_port_id port_id,
718718
if (hv_result_success(status))
719719
break;
720720

721-
if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
721+
if (!hv_result_needs_memory(status)) {
722722
ret = hv_result_to_errno(status);
723723
break;
724724
}
@@ -772,7 +772,7 @@ hv_call_connect_port(u64 port_partition_id, union hv_port_id port_id,
772772
if (hv_result_success(status))
773773
break;
774774

775-
if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
775+
if (!hv_result_needs_memory(status)) {
776776
ret = hv_result_to_errno(status);
777777
break;
778778
}
@@ -850,7 +850,7 @@ static int hv_call_map_stats_page2(enum hv_stats_object_type type,
850850
if (!ret)
851851
break;
852852

853-
if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) {
853+
if (!hv_result_needs_memory(status)) {
854854
hv_status_debug(status, "\n");
855855
break;
856856
}
@@ -899,7 +899,7 @@ hv_call_map_stats_page(enum hv_stats_object_type type,
899899
struct hv_input_map_stats_page *input;
900900
struct hv_output_map_stats_page *output;
901901
u64 status, pfn;
902-
int hv_status, ret = 0;
902+
int ret = 0;
903903

904904
do {
905905
local_irq_save(flags);
@@ -915,13 +915,12 @@ hv_call_map_stats_page(enum hv_stats_object_type type,
915915

916916
local_irq_restore(flags);
917917

918-
hv_status = hv_result(status);
919-
if (hv_status != HV_STATUS_INSUFFICIENT_MEMORY) {
918+
if (!hv_result_needs_memory(status)) {
920919
if (hv_result_success(status))
921920
break;
922921

923922
if (hv_stats_get_area_type(type, identity) == HV_STATS_AREA_PARENT &&
924-
hv_status == HV_STATUS_INVALID_PARAMETER) {
923+
hv_result(status) == HV_STATUS_INVALID_PARAMETER) {
925924
*addr = NULL;
926925
return 0;
927926
}

drivers/hv/mshv_root_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ static int mshv_ioctl_passthru_hvcall(struct mshv_partition *partition,
252252
if (hv_result_success(status))
253253
break;
254254

255-
if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY)
255+
if (!hv_result_needs_memory(status))
256256
ret = hv_result_to_errno(status);
257257
else
258258
ret = hv_call_deposit_pages(NUMA_NO_NODE,

include/asm-generic/mshyperv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ static inline bool hv_parent_partition(void)
342342
{
343343
return hv_root_partition() || hv_l1vh_partition();
344344
}
345+
346+
bool hv_result_needs_memory(u64 status);
345347
int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages);
346348
int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id);
347349
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);
350352
static inline bool hv_root_partition(void) { return false; }
351353
static inline bool hv_l1vh_partition(void) { return false; }
352354
static inline bool hv_parent_partition(void) { return false; }
355+
static inline bool hv_result_needs_memory(u64 status) { return false; }
353356
static inline int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages)
354357
{
355358
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)