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_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>

authored by

Stanislav Kinsburskii and committed by
Wei Liu
ede54383 7db44aa1

+39 -20
+19 -2
drivers/hv/hv_proc.c
··· 110 110 } 111 111 EXPORT_SYMBOL_GPL(hv_call_deposit_pages); 112 112 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 + 113 129 bool hv_result_needs_memory(u64 status) 114 130 { 115 131 switch (hv_result(status)) { ··· 171 155 } 172 156 break; 173 157 } 174 - ret = hv_call_deposit_pages(node, hv_current_partition_id, 1); 158 + ret = hv_deposit_memory_node(node, hv_current_partition_id, 159 + status); 175 160 } while (!ret); 176 161 177 162 return ret; ··· 214 197 } 215 198 break; 216 199 } 217 - ret = hv_call_deposit_pages(node, partition_id, 1); 200 + ret = hv_deposit_memory_node(node, partition_id, status); 218 201 219 202 } while (!ret); 220 203
+9 -16
drivers/hv/mshv_root_hv_call.c
··· 123 123 break; 124 124 } 125 125 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); 128 127 } while (!ret); 129 128 130 129 return ret; ··· 150 151 ret = hv_result_to_errno(status); 151 152 break; 152 153 } 153 - ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1); 154 + ret = hv_deposit_memory(partition_id, status); 154 155 } while (!ret); 155 156 156 157 return ret; ··· 464 465 } 465 466 local_irq_restore(flags); 466 467 467 - ret = hv_call_deposit_pages(NUMA_NO_NODE, 468 - partition_id, 1); 468 + ret = hv_deposit_memory(partition_id, status); 469 469 } while (!ret); 470 470 471 471 return ret; ··· 523 525 } 524 526 local_irq_restore(flags); 525 527 526 - ret = hv_call_deposit_pages(NUMA_NO_NODE, 527 - partition_id, 1); 528 + ret = hv_deposit_memory(partition_id, status); 528 529 } while (!ret); 529 530 530 531 return ret; ··· 570 573 571 574 local_irq_restore(flags); 572 575 573 - ret = hv_call_deposit_pages(NUMA_NO_NODE, partition_id, 1); 576 + ret = hv_deposit_memory(partition_id, status); 574 577 } while (!ret); 575 578 576 579 return ret; ··· 719 722 ret = hv_result_to_errno(status); 720 723 break; 721 724 } 722 - ret = hv_call_deposit_pages(NUMA_NO_NODE, port_partition_id, 1); 723 - 725 + ret = hv_deposit_memory(port_partition_id, status); 724 726 } while (!ret); 725 727 726 728 return ret; ··· 772 776 ret = hv_result_to_errno(status); 773 777 break; 774 778 } 775 - ret = hv_call_deposit_pages(NUMA_NO_NODE, 776 - connection_partition_id, 1); 779 + ret = hv_deposit_memory(connection_partition_id, status); 777 780 } while (!ret); 778 781 779 782 return ret; ··· 850 855 break; 851 856 } 852 857 853 - ret = hv_call_deposit_pages(NUMA_NO_NODE, 854 - hv_current_partition_id, 1); 858 + ret = hv_deposit_memory(hv_current_partition_id, status); 855 859 } while (!ret); 856 860 857 861 return ret; ··· 923 929 return hv_result_to_errno(status); 924 930 } 925 931 926 - ret = hv_call_deposit_pages(NUMA_NO_NODE, 927 - hv_current_partition_id, 1); 932 + ret = hv_deposit_memory(hv_current_partition_id, status); 928 933 if (ret) 929 934 return ret; 930 935 } while (!ret);
+1 -2
drivers/hv/mshv_root_main.c
··· 255 255 if (!hv_result_needs_memory(status)) 256 256 ret = hv_result_to_errno(status); 257 257 else 258 - ret = hv_call_deposit_pages(NUMA_NO_NODE, 259 - pt_id, 1); 258 + ret = hv_deposit_memory(pt_id, status); 260 259 } while (!ret); 261 260 262 261 args.status = hv_result(status);
+10
include/asm-generic/mshyperv.h
··· 344 344 } 345 345 346 346 bool hv_result_needs_memory(u64 status); 347 + int hv_deposit_memory_node(int node, u64 partition_id, u64 status); 347 348 int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages); 348 349 int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id); 349 350 int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags); ··· 354 353 static inline bool hv_l1vh_partition(void) { return false; } 355 354 static inline bool hv_parent_partition(void) { return false; } 356 355 static inline bool hv_result_needs_memory(u64 status) { return false; } 356 + static inline int hv_deposit_memory_node(int node, u64 partition_id, u64 status) 357 + { 358 + return -EOPNOTSUPP; 359 + } 357 360 static inline int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages) 358 361 { 359 362 return -EOPNOTSUPP; ··· 371 366 return -EOPNOTSUPP; 372 367 } 373 368 #endif /* CONFIG_MSHV_ROOT */ 369 + 370 + static inline int hv_deposit_memory(u64 partition_id, u64 status) 371 + { 372 + return hv_deposit_memory_node(NUMA_NO_NODE, partition_id, status); 373 + } 374 374 375 375 #if IS_ENABLED(CONFIG_HYPERV_VTL_MODE) 376 376 u8 __init get_vtl(void);