Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Stanislav Kinsburskii and committed by
Wei Liu
7db44aa1 8927a108

+28 -16
+12 -2
drivers/hv/hv_proc.c
··· 110 110 } 111 111 EXPORT_SYMBOL_GPL(hv_call_deposit_pages); 112 112 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 + 113 123 int hv_call_add_logical_proc(int node, u32 lp_index, u32 apic_id) 114 124 { 115 125 struct hv_input_add_logical_processor *input; ··· 147 137 input, output); 148 138 local_irq_restore(flags); 149 139 150 - if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) { 140 + if (!hv_result_needs_memory(status)) { 151 141 if (!hv_result_success(status)) { 152 142 hv_status_err(status, "cpu %u apic ID: %u\n", 153 143 lp_index, apic_id); ··· 189 179 status = hv_do_hypercall(HVCALL_CREATE_VP, input, NULL); 190 180 local_irq_restore(irq_flags); 191 181 192 - if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) { 182 + if (!hv_result_needs_memory(status)) { 193 183 if (!hv_result_success(status)) { 194 184 hv_status_err(status, "vcpu: %u, lp: %u\n", 195 185 vp_index, flags);
+12 -13
drivers/hv/mshv_root_hv_call.c
··· 115 115 status = hv_do_hypercall(HVCALL_CREATE_PARTITION, 116 116 input, output); 117 117 118 - if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) { 118 + if (!hv_result_needs_memory(status)) { 119 119 if (hv_result_success(status)) 120 120 *partition_id = output->partition_id; 121 121 local_irq_restore(irq_flags); ··· 147 147 status = hv_do_fast_hypercall8(HVCALL_INITIALIZE_PARTITION, 148 148 *(u64 *)&input); 149 149 150 - if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) { 150 + if (!hv_result_needs_memory(status)) { 151 151 ret = hv_result_to_errno(status); 152 152 break; 153 153 } ··· 239 239 240 240 completed = hv_repcomp(status); 241 241 242 - if (hv_result(status) == HV_STATUS_INSUFFICIENT_MEMORY) { 242 + if (hv_result_needs_memory(status)) { 243 243 ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 244 244 HV_MAP_GPA_DEPOSIT_PAGES); 245 245 if (ret) ··· 455 455 456 456 status = hv_do_hypercall(control, input, output); 457 457 458 - if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) { 458 + if (!hv_result_needs_memory(status)) { 459 459 if (hv_result_success(status) && ret_output) 460 460 memcpy(ret_output, output, sizeof(*output)); 461 461 ··· 518 518 519 519 status = hv_do_hypercall(control, input, NULL); 520 520 521 - if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) { 521 + if (!hv_result_needs_memory(status)) { 522 522 local_irq_restore(flags); 523 523 ret = hv_result_to_errno(status); 524 524 break; ··· 563 563 status = hv_do_hypercall(HVCALL_MAP_VP_STATE_PAGE, input, 564 564 output); 565 565 566 - if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) { 566 + if (!hv_result_needs_memory(status)) { 567 567 if (hv_result_success(status)) 568 568 *state_page = pfn_to_page(output->map_location); 569 569 local_irq_restore(flags); ··· 718 718 if (hv_result_success(status)) 719 719 break; 720 720 721 - if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) { 721 + if (!hv_result_needs_memory(status)) { 722 722 ret = hv_result_to_errno(status); 723 723 break; 724 724 } ··· 772 772 if (hv_result_success(status)) 773 773 break; 774 774 775 - if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) { 775 + if (!hv_result_needs_memory(status)) { 776 776 ret = hv_result_to_errno(status); 777 777 break; 778 778 } ··· 850 850 if (!ret) 851 851 break; 852 852 853 - if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) { 853 + if (!hv_result_needs_memory(status)) { 854 854 hv_status_debug(status, "\n"); 855 855 break; 856 856 } ··· 899 899 struct hv_input_map_stats_page *input; 900 900 struct hv_output_map_stats_page *output; 901 901 u64 status, pfn; 902 - int hv_status, ret = 0; 902 + int ret = 0; 903 903 904 904 do { 905 905 local_irq_save(flags); ··· 915 915 916 916 local_irq_restore(flags); 917 917 918 - hv_status = hv_result(status); 919 - if (hv_status != HV_STATUS_INSUFFICIENT_MEMORY) { 918 + if (!hv_result_needs_memory(status)) { 920 919 if (hv_result_success(status)) 921 920 break; 922 921 923 922 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) { 925 924 *addr = NULL; 926 925 return 0; 927 926 }
+1 -1
drivers/hv/mshv_root_main.c
··· 252 252 if (hv_result_success(status)) 253 253 break; 254 254 255 - if (hv_result(status) != HV_STATUS_INSUFFICIENT_MEMORY) 255 + if (!hv_result_needs_memory(status)) 256 256 ret = hv_result_to_errno(status); 257 257 else 258 258 ret = hv_call_deposit_pages(NUMA_NO_NODE,
+3
include/asm-generic/mshyperv.h
··· 342 342 { 343 343 return hv_root_partition() || hv_l1vh_partition(); 344 344 } 345 + 346 + bool hv_result_needs_memory(u64 status); 345 347 int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages); 346 348 int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id); 347 349 int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags); ··· 352 350 static inline bool hv_root_partition(void) { return false; } 353 351 static inline bool hv_l1vh_partition(void) { return false; } 354 352 static inline bool hv_parent_partition(void) { return false; } 353 + static inline bool hv_result_needs_memory(u64 status) { return false; } 355 354 static inline int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages) 356 355 { 357 356 return -EOPNOTSUPP;