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: refactor synic init and cleanup

Rename mshv_synic_init() to mshv_synic_cpu_init() and
mshv_synic_cleanup() to mshv_synic_cpu_exit() to better reflect that
these functions handle per-cpu synic setup and teardown.

Use mshv_synic_init/cleanup() to perform init/cleanup that is not per-cpu.
Move all the synic related setup from mshv_parent_partition_init.

Move the reboot notifier to mshv_synic.c because it currently only
operates on the synic cpuhp state.

Move out synic_pages from the global mshv_root since its use is now
completely local to mshv_synic.c.

This is in preparation for adding more stuff to mshv_synic_init().

No functional change.

Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Signed-off-by: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>

authored by

Anirudh Rayabharam (Microsoft) and committed by
Wei Liu
5a674ef8 f69cfd8e

+75 -65
+2 -3
drivers/hv/mshv_root.h
··· 190 190 }; 191 191 192 192 struct mshv_root { 193 - struct hv_synic_pages __percpu *synic_pages; 194 193 spinlock_t pt_ht_lock; 195 194 DECLARE_HASHTABLE(pt_htable, MSHV_PARTITIONS_HASH_BITS); 196 195 struct hv_partition_property_vmm_capabilities vmm_caps; ··· 248 249 void mshv_unregister_doorbell(u64 partition_id, int doorbell_portid); 249 250 250 251 void mshv_isr(void); 251 - int mshv_synic_init(unsigned int cpu); 252 - int mshv_synic_cleanup(unsigned int cpu); 252 + int mshv_synic_init(struct device *dev); 253 + void mshv_synic_exit(void); 253 254 254 255 static inline bool mshv_partition_encrypted(struct mshv_partition *partition) 255 256 {
+8 -56
drivers/hv/mshv_root_main.c
··· 2064 2064 return 0; 2065 2065 } 2066 2066 2067 - static int mshv_cpuhp_online; 2068 2067 static int mshv_root_sched_online; 2069 2068 2070 2069 static const char *scheduler_type_to_string(enum hv_scheduler_type type) ··· 2248 2249 free_percpu(root_scheduler_output); 2249 2250 } 2250 2251 2251 - static int mshv_reboot_notify(struct notifier_block *nb, 2252 - unsigned long code, void *unused) 2253 - { 2254 - cpuhp_remove_state(mshv_cpuhp_online); 2255 - return 0; 2256 - } 2257 - 2258 - struct notifier_block mshv_reboot_nb = { 2259 - .notifier_call = mshv_reboot_notify, 2260 - }; 2261 - 2262 - static void mshv_root_partition_exit(void) 2263 - { 2264 - unregister_reboot_notifier(&mshv_reboot_nb); 2265 - } 2266 - 2267 - static int __init mshv_root_partition_init(struct device *dev) 2268 - { 2269 - return register_reboot_notifier(&mshv_reboot_nb); 2270 - } 2271 - 2272 2252 static int __init mshv_init_vmm_caps(struct device *dev) 2273 2253 { 2274 2254 int ret; ··· 2292 2314 MSHV_HV_MAX_VERSION); 2293 2315 } 2294 2316 2295 - mshv_root.synic_pages = alloc_percpu(struct hv_synic_pages); 2296 - if (!mshv_root.synic_pages) { 2297 - dev_err(dev, "Failed to allocate percpu synic page\n"); 2298 - ret = -ENOMEM; 2317 + ret = mshv_synic_init(dev); 2318 + if (ret) 2299 2319 goto device_deregister; 2300 - } 2301 - 2302 - ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mshv_synic", 2303 - mshv_synic_init, 2304 - mshv_synic_cleanup); 2305 - if (ret < 0) { 2306 - dev_err(dev, "Failed to setup cpu hotplug state: %i\n", ret); 2307 - goto free_synic_pages; 2308 - } 2309 - 2310 - mshv_cpuhp_online = ret; 2311 2320 2312 2321 ret = mshv_init_vmm_caps(dev); 2313 2322 if (ret) 2314 - goto remove_cpu_state; 2323 + goto synic_cleanup; 2315 2324 2316 2325 ret = mshv_retrieve_scheduler_type(dev); 2317 2326 if (ret) 2318 - goto remove_cpu_state; 2319 - 2320 - if (hv_root_partition()) 2321 - ret = mshv_root_partition_init(dev); 2322 - if (ret) 2323 - goto remove_cpu_state; 2327 + goto synic_cleanup; 2324 2328 2325 2329 ret = root_scheduler_init(dev); 2326 2330 if (ret) 2327 - goto exit_partition; 2331 + goto synic_cleanup; 2328 2332 2329 2333 ret = mshv_debugfs_init(); 2330 2334 if (ret) ··· 2327 2367 mshv_debugfs_exit(); 2328 2368 deinit_root_scheduler: 2329 2369 root_scheduler_deinit(); 2330 - exit_partition: 2331 - if (hv_root_partition()) 2332 - mshv_root_partition_exit(); 2333 - remove_cpu_state: 2334 - cpuhp_remove_state(mshv_cpuhp_online); 2335 - free_synic_pages: 2336 - free_percpu(mshv_root.synic_pages); 2370 + synic_cleanup: 2371 + mshv_synic_exit(); 2337 2372 device_deregister: 2338 2373 misc_deregister(&mshv_dev); 2339 2374 return ret; ··· 2342 2387 misc_deregister(&mshv_dev); 2343 2388 mshv_irqfd_wq_cleanup(); 2344 2389 root_scheduler_deinit(); 2345 - if (hv_root_partition()) 2346 - mshv_root_partition_exit(); 2347 - cpuhp_remove_state(mshv_cpuhp_online); 2348 - free_percpu(mshv_root.synic_pages); 2390 + mshv_synic_exit(); 2349 2391 } 2350 2392 2351 2393 module_init(mshv_parent_partition_init);
+65 -6
drivers/hv/mshv_synic.c
··· 12 12 #include <linux/mm.h> 13 13 #include <linux/io.h> 14 14 #include <linux/random.h> 15 + #include <linux/cpuhotplug.h> 16 + #include <linux/reboot.h> 15 17 #include <asm/mshyperv.h> 16 18 17 19 #include "mshv_eventfd.h" 18 20 #include "mshv.h" 21 + 22 + static int synic_cpuhp_online; 23 + static struct hv_synic_pages __percpu *synic_pages; 19 24 20 25 static u32 synic_event_ring_get_queued_port(u32 sint_index) 21 26 { ··· 31 26 u32 message; 32 27 u8 tail; 33 28 34 - spages = this_cpu_ptr(mshv_root.synic_pages); 29 + spages = this_cpu_ptr(synic_pages); 35 30 event_ring_page = &spages->synic_event_ring_page; 36 31 synic_eventring_tail = (u8 **)this_cpu_ptr(hv_synic_eventring_tail); 37 32 ··· 398 393 399 394 void mshv_isr(void) 400 395 { 401 - struct hv_synic_pages *spages = this_cpu_ptr(mshv_root.synic_pages); 396 + struct hv_synic_pages *spages = this_cpu_ptr(synic_pages); 402 397 struct hv_message_page **msg_page = &spages->hyp_synic_message_page; 403 398 struct hv_message *msg; 404 399 bool handled; ··· 451 446 } 452 447 } 453 448 454 - int mshv_synic_init(unsigned int cpu) 449 + static int mshv_synic_cpu_init(unsigned int cpu) 455 450 { 456 451 union hv_synic_simp simp; 457 452 union hv_synic_siefp siefp; ··· 460 455 union hv_synic_sint sint; 461 456 #endif 462 457 union hv_synic_scontrol sctrl; 463 - struct hv_synic_pages *spages = this_cpu_ptr(mshv_root.synic_pages); 458 + struct hv_synic_pages *spages = this_cpu_ptr(synic_pages); 464 459 struct hv_message_page **msg_page = &spages->hyp_synic_message_page; 465 460 struct hv_synic_event_flags_page **event_flags_page = 466 461 &spages->synic_event_flags_page; ··· 547 542 return -EFAULT; 548 543 } 549 544 550 - int mshv_synic_cleanup(unsigned int cpu) 545 + static int mshv_synic_cpu_exit(unsigned int cpu) 551 546 { 552 547 union hv_synic_sint sint; 553 548 union hv_synic_simp simp; 554 549 union hv_synic_siefp siefp; 555 550 union hv_synic_sirbp sirbp; 556 551 union hv_synic_scontrol sctrl; 557 - struct hv_synic_pages *spages = this_cpu_ptr(mshv_root.synic_pages); 552 + struct hv_synic_pages *spages = this_cpu_ptr(synic_pages); 558 553 struct hv_message_page **msg_page = &spages->hyp_synic_message_page; 559 554 struct hv_synic_event_flags_page **event_flags_page = 560 555 &spages->synic_event_flags_page; ··· 667 662 hv_call_delete_port(hv_current_partition_id, port_id); 668 663 669 664 mshv_portid_free(doorbell_portid); 665 + } 666 + 667 + static int mshv_synic_reboot_notify(struct notifier_block *nb, 668 + unsigned long code, void *unused) 669 + { 670 + if (!hv_root_partition()) 671 + return 0; 672 + 673 + cpuhp_remove_state(synic_cpuhp_online); 674 + return 0; 675 + } 676 + 677 + static struct notifier_block mshv_synic_reboot_nb = { 678 + .notifier_call = mshv_synic_reboot_notify, 679 + }; 680 + 681 + int __init mshv_synic_init(struct device *dev) 682 + { 683 + int ret = 0; 684 + 685 + synic_pages = alloc_percpu(struct hv_synic_pages); 686 + if (!synic_pages) { 687 + dev_err(dev, "Failed to allocate percpu synic page\n"); 688 + return -ENOMEM; 689 + } 690 + 691 + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mshv_synic", 692 + mshv_synic_cpu_init, 693 + mshv_synic_cpu_exit); 694 + if (ret < 0) { 695 + dev_err(dev, "Failed to setup cpu hotplug state: %i\n", ret); 696 + goto free_synic_pages; 697 + } 698 + 699 + synic_cpuhp_online = ret; 700 + 701 + ret = register_reboot_notifier(&mshv_synic_reboot_nb); 702 + if (ret) 703 + goto remove_cpuhp_state; 704 + 705 + return 0; 706 + 707 + remove_cpuhp_state: 708 + cpuhp_remove_state(synic_cpuhp_online); 709 + free_synic_pages: 710 + free_percpu(synic_pages); 711 + return ret; 712 + } 713 + 714 + void mshv_synic_exit(void) 715 + { 716 + unregister_reboot_notifier(&mshv_synic_reboot_nb); 717 + cpuhp_remove_state(synic_cpuhp_online); 718 + free_percpu(synic_pages); 670 719 }