Skip to content

Commit 5a674ef

Browse files
Anirudh Rayabharam (Microsoft)liuw
authored andcommitted
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>
1 parent f69cfd8 commit 5a674ef

3 files changed

Lines changed: 75 additions & 65 deletions

File tree

drivers/hv/mshv_root.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ struct hv_synic_pages {
190190
};
191191

192192
struct mshv_root {
193-
struct hv_synic_pages __percpu *synic_pages;
194193
spinlock_t pt_ht_lock;
195194
DECLARE_HASHTABLE(pt_htable, MSHV_PARTITIONS_HASH_BITS);
196195
struct hv_partition_property_vmm_capabilities vmm_caps;
@@ -249,8 +248,8 @@ int mshv_register_doorbell(u64 partition_id, doorbell_cb_t doorbell_cb,
249248
void mshv_unregister_doorbell(u64 partition_id, int doorbell_portid);
250249

251250
void mshv_isr(void);
252-
int mshv_synic_init(unsigned int cpu);
253-
int mshv_synic_cleanup(unsigned int cpu);
251+
int mshv_synic_init(struct device *dev);
252+
void mshv_synic_exit(void);
254253

255254
static inline bool mshv_partition_encrypted(struct mshv_partition *partition)
256255
{

drivers/hv/mshv_root_main.c

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,7 +2064,6 @@ mshv_dev_release(struct inode *inode, struct file *filp)
20642064
return 0;
20652065
}
20662066

2067-
static int mshv_cpuhp_online;
20682067
static int mshv_root_sched_online;
20692068

20702069
static const char *scheduler_type_to_string(enum hv_scheduler_type type)
@@ -2249,27 +2248,6 @@ root_scheduler_deinit(void)
22492248
free_percpu(root_scheduler_output);
22502249
}
22512250

2252-
static int mshv_reboot_notify(struct notifier_block *nb,
2253-
unsigned long code, void *unused)
2254-
{
2255-
cpuhp_remove_state(mshv_cpuhp_online);
2256-
return 0;
2257-
}
2258-
2259-
struct notifier_block mshv_reboot_nb = {
2260-
.notifier_call = mshv_reboot_notify,
2261-
};
2262-
2263-
static void mshv_root_partition_exit(void)
2264-
{
2265-
unregister_reboot_notifier(&mshv_reboot_nb);
2266-
}
2267-
2268-
static int __init mshv_root_partition_init(struct device *dev)
2269-
{
2270-
return register_reboot_notifier(&mshv_reboot_nb);
2271-
}
2272-
22732251
static int __init mshv_init_vmm_caps(struct device *dev)
22742252
{
22752253
int ret;
@@ -2314,39 +2292,21 @@ static int __init mshv_parent_partition_init(void)
23142292
MSHV_HV_MAX_VERSION);
23152293
}
23162294

2317-
mshv_root.synic_pages = alloc_percpu(struct hv_synic_pages);
2318-
if (!mshv_root.synic_pages) {
2319-
dev_err(dev, "Failed to allocate percpu synic page\n");
2320-
ret = -ENOMEM;
2295+
ret = mshv_synic_init(dev);
2296+
if (ret)
23212297
goto device_deregister;
2322-
}
2323-
2324-
ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mshv_synic",
2325-
mshv_synic_init,
2326-
mshv_synic_cleanup);
2327-
if (ret < 0) {
2328-
dev_err(dev, "Failed to setup cpu hotplug state: %i\n", ret);
2329-
goto free_synic_pages;
2330-
}
2331-
2332-
mshv_cpuhp_online = ret;
23332298

23342299
ret = mshv_init_vmm_caps(dev);
23352300
if (ret)
2336-
goto remove_cpu_state;
2301+
goto synic_cleanup;
23372302

23382303
ret = mshv_retrieve_scheduler_type(dev);
23392304
if (ret)
2340-
goto remove_cpu_state;
2341-
2342-
if (hv_root_partition())
2343-
ret = mshv_root_partition_init(dev);
2344-
if (ret)
2345-
goto remove_cpu_state;
2305+
goto synic_cleanup;
23462306

23472307
ret = root_scheduler_init(dev);
23482308
if (ret)
2349-
goto exit_partition;
2309+
goto synic_cleanup;
23502310

23512311
ret = mshv_debugfs_init();
23522312
if (ret)
@@ -2367,13 +2327,8 @@ static int __init mshv_parent_partition_init(void)
23672327
mshv_debugfs_exit();
23682328
deinit_root_scheduler:
23692329
root_scheduler_deinit();
2370-
exit_partition:
2371-
if (hv_root_partition())
2372-
mshv_root_partition_exit();
2373-
remove_cpu_state:
2374-
cpuhp_remove_state(mshv_cpuhp_online);
2375-
free_synic_pages:
2376-
free_percpu(mshv_root.synic_pages);
2330+
synic_cleanup:
2331+
mshv_synic_exit();
23772332
device_deregister:
23782333
misc_deregister(&mshv_dev);
23792334
return ret;
@@ -2387,10 +2342,7 @@ static void __exit mshv_parent_partition_exit(void)
23872342
misc_deregister(&mshv_dev);
23882343
mshv_irqfd_wq_cleanup();
23892344
root_scheduler_deinit();
2390-
if (hv_root_partition())
2391-
mshv_root_partition_exit();
2392-
cpuhp_remove_state(mshv_cpuhp_online);
2393-
free_percpu(mshv_root.synic_pages);
2345+
mshv_synic_exit();
23942346
}
23952347

23962348
module_init(mshv_parent_partition_init);

drivers/hv/mshv_synic.c

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@
1212
#include <linux/mm.h>
1313
#include <linux/io.h>
1414
#include <linux/random.h>
15+
#include <linux/cpuhotplug.h>
16+
#include <linux/reboot.h>
1517
#include <asm/mshyperv.h>
1618

1719
#include "mshv_eventfd.h"
1820
#include "mshv.h"
1921

22+
static int synic_cpuhp_online;
23+
static struct hv_synic_pages __percpu *synic_pages;
24+
2025
static u32 synic_event_ring_get_queued_port(u32 sint_index)
2126
{
2227
struct hv_synic_event_ring_page **event_ring_page;
@@ -26,7 +31,7 @@ static u32 synic_event_ring_get_queued_port(u32 sint_index)
2631
u32 message;
2732
u8 tail;
2833

29-
spages = this_cpu_ptr(mshv_root.synic_pages);
34+
spages = this_cpu_ptr(synic_pages);
3035
event_ring_page = &spages->synic_event_ring_page;
3136
synic_eventring_tail = (u8 **)this_cpu_ptr(hv_synic_eventring_tail);
3237

@@ -393,7 +398,7 @@ mshv_intercept_isr(struct hv_message *msg)
393398

394399
void mshv_isr(void)
395400
{
396-
struct hv_synic_pages *spages = this_cpu_ptr(mshv_root.synic_pages);
401+
struct hv_synic_pages *spages = this_cpu_ptr(synic_pages);
397402
struct hv_message_page **msg_page = &spages->hyp_synic_message_page;
398403
struct hv_message *msg;
399404
bool handled;
@@ -446,7 +451,7 @@ void mshv_isr(void)
446451
}
447452
}
448453

449-
int mshv_synic_init(unsigned int cpu)
454+
static int mshv_synic_cpu_init(unsigned int cpu)
450455
{
451456
union hv_synic_simp simp;
452457
union hv_synic_siefp siefp;
@@ -455,7 +460,7 @@ int mshv_synic_init(unsigned int cpu)
455460
union hv_synic_sint sint;
456461
#endif
457462
union hv_synic_scontrol sctrl;
458-
struct hv_synic_pages *spages = this_cpu_ptr(mshv_root.synic_pages);
463+
struct hv_synic_pages *spages = this_cpu_ptr(synic_pages);
459464
struct hv_message_page **msg_page = &spages->hyp_synic_message_page;
460465
struct hv_synic_event_flags_page **event_flags_page =
461466
&spages->synic_event_flags_page;
@@ -542,14 +547,14 @@ int mshv_synic_init(unsigned int cpu)
542547
return -EFAULT;
543548
}
544549

545-
int mshv_synic_cleanup(unsigned int cpu)
550+
static int mshv_synic_cpu_exit(unsigned int cpu)
546551
{
547552
union hv_synic_sint sint;
548553
union hv_synic_simp simp;
549554
union hv_synic_siefp siefp;
550555
union hv_synic_sirbp sirbp;
551556
union hv_synic_scontrol sctrl;
552-
struct hv_synic_pages *spages = this_cpu_ptr(mshv_root.synic_pages);
557+
struct hv_synic_pages *spages = this_cpu_ptr(synic_pages);
553558
struct hv_message_page **msg_page = &spages->hyp_synic_message_page;
554559
struct hv_synic_event_flags_page **event_flags_page =
555560
&spages->synic_event_flags_page;
@@ -663,3 +668,57 @@ mshv_unregister_doorbell(u64 partition_id, int doorbell_portid)
663668

664669
mshv_portid_free(doorbell_portid);
665670
}
671+
672+
static int mshv_synic_reboot_notify(struct notifier_block *nb,
673+
unsigned long code, void *unused)
674+
{
675+
if (!hv_root_partition())
676+
return 0;
677+
678+
cpuhp_remove_state(synic_cpuhp_online);
679+
return 0;
680+
}
681+
682+
static struct notifier_block mshv_synic_reboot_nb = {
683+
.notifier_call = mshv_synic_reboot_notify,
684+
};
685+
686+
int __init mshv_synic_init(struct device *dev)
687+
{
688+
int ret = 0;
689+
690+
synic_pages = alloc_percpu(struct hv_synic_pages);
691+
if (!synic_pages) {
692+
dev_err(dev, "Failed to allocate percpu synic page\n");
693+
return -ENOMEM;
694+
}
695+
696+
ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mshv_synic",
697+
mshv_synic_cpu_init,
698+
mshv_synic_cpu_exit);
699+
if (ret < 0) {
700+
dev_err(dev, "Failed to setup cpu hotplug state: %i\n", ret);
701+
goto free_synic_pages;
702+
}
703+
704+
synic_cpuhp_online = ret;
705+
706+
ret = register_reboot_notifier(&mshv_synic_reboot_nb);
707+
if (ret)
708+
goto remove_cpuhp_state;
709+
710+
return 0;
711+
712+
remove_cpuhp_state:
713+
cpuhp_remove_state(synic_cpuhp_online);
714+
free_synic_pages:
715+
free_percpu(synic_pages);
716+
return ret;
717+
}
718+
719+
void mshv_synic_exit(void)
720+
{
721+
unregister_reboot_notifier(&mshv_synic_reboot_nb);
722+
cpuhp_remove_state(synic_cpuhp_online);
723+
free_percpu(synic_pages);
724+
}

0 commit comments

Comments
 (0)