From nobody Tue Feb 10 12:40:26 2026 Received: from sender4-of-o52.zoho.com (sender4-of-o52.zoho.com [136.143.188.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB8AA33E37C; Wed, 4 Feb 2026 17:44:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770227056; cv=pass; b=nHewFaL/Pb2iiYLRclQM9dqhTCJ3RFdFuT0C1fJo5f+VS87bca1W7UdWFKyjx7Cm5lQc3vXKESQQY/g9FpoLtBXExZQQnFYjHbApqfL0f0SeFACGp7uc0BN1r2fOdEw2II+VAmXjJyIe6m54h4g4HBbq4zmKepAWf9+tDUgIM5E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770227056; c=relaxed/simple; bh=1xxvT3Kg/iBSXBR9OzxkfsDxJiscX72o/Y1BvlTRM3k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jKi+90JbCyyYIn2fkG6w19ZSxKx1McJAFRTvueiHyxpu7tVS2HlE1nLPfx/moXnG6ah2eTggfpvThZjfJ0v5g5ldBq6WNE9ayDAhD3PKW2y+p5h+04tohlg8H+9AdP6JSZh/w9Gw7GnKiB3T8Lr7sYmlsNOA6HbiSmSeXPSwtRo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=anirudhrb.com; spf=pass smtp.mailfrom=anirudhrb.com; dkim=pass (1024-bit key) header.d=anirudhrb.com header.i=anirudh@anirudhrb.com header.b=W+SXSFek; arc=pass smtp.client-ip=136.143.188.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=anirudhrb.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=anirudhrb.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=anirudhrb.com header.i=anirudh@anirudhrb.com header.b="W+SXSFek" ARC-Seal: i=1; a=rsa-sha256; t=1770227049; cv=none; d=zohomail.com; s=zohoarc; b=i+QaQbnjvMUkNuCYrLYzcZFpcBElLbhQ38G8eFAm07qaeo7vdyy/7Ef+H3EWS8i9GFALm9FP8l9fgw7gpCbX8Alct7RXBsOn2gsMZwY64d+/WOxpUyNWlUiH93eeujLZPkGBpbk1qric6MdTVPmcxZ6fqpxnhvX3Be1tyvMImRk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770227049; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=ljSpnXCWzU5CBVVyspBfoSk6H97ioubmGofKkf0JI1c=; b=gFLVlRqMzFj3LppngcKxU8mHAS7anO+k2ejapIXaWrlG8gFaQ+TwYnw5kwqmQbd+4o+rJ1ywnwKwxYJ5tMIPO1S4rIQ6MleyrPZVcDzmUkbqOT6MgBm7BbBIPIX5kxB7fq0QmvsABIZk02AOr2CaxVA8hXclO7V6b5agjRME/aU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=anirudhrb.com; spf=pass smtp.mailfrom=anirudh@anirudhrb.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1770227049; s=zoho; d=anirudhrb.com; i=anirudh@anirudhrb.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=ljSpnXCWzU5CBVVyspBfoSk6H97ioubmGofKkf0JI1c=; b=W+SXSFekG4yDUkXqUHA8IhTPC3l74rdbJYo6nGTSTu6VPPEzUBCrQe9o1OoRzb6G LChipsqKQeKfs2K0HLBSR9KqC/znGIaiqJbARqatB0SIvsGE9wCkGpdBQJdHs+o19GS uo/w7QibohWodCmaf4dS82DUkmLQxjvK8Tlkx5lY= Received: by mx.zohomail.com with SMTPS id 1770227046669730.4776678628339; Wed, 4 Feb 2026 09:44:06 -0800 (PST) From: Anirudh Rayabharam To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, longli@microsoft.com, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Cc: anirudh@anirudhrb.com Subject: [PATCH v3 1/2] mshv: refactor synic init and cleanup Date: Wed, 4 Feb 2026 17:42:36 +0000 Message-Id: <20260204174237.1201153-2-anirudh@anirudhrb.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260204174237.1201153-1-anirudh@anirudhrb.com> References: <20260204174237.1201153-1-anirudh@anirudhrb.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" From: Anirudh Rayabharam (Microsoft) 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 it's use is now completely local to mshv_synic.c. This is in preparation for the next patch which will add more stuff to mshv_synic_init(). No functional change. Signed-off-by: Anirudh Rayabharam (Microsoft) --- drivers/hv/mshv_root.h | 5 ++- drivers/hv/mshv_root_main.c | 59 +++++------------------------- drivers/hv/mshv_synic.c | 71 +++++++++++++++++++++++++++++++++---- 3 files changed, 75 insertions(+), 60 deletions(-) diff --git a/drivers/hv/mshv_root.h b/drivers/hv/mshv_root.h index 3c1d88b36741..26e0320c8097 100644 --- a/drivers/hv/mshv_root.h +++ b/drivers/hv/mshv_root.h @@ -183,7 +183,6 @@ struct hv_synic_pages { }; =20 struct mshv_root { - struct hv_synic_pages __percpu *synic_pages; spinlock_t pt_ht_lock; DECLARE_HASHTABLE(pt_htable, MSHV_PARTITIONS_HASH_BITS); struct hv_partition_property_vmm_capabilities vmm_caps; @@ -242,8 +241,8 @@ int mshv_register_doorbell(u64 partition_id, doorbell_c= b_t doorbell_cb, void mshv_unregister_doorbell(u64 partition_id, int doorbell_portid); =20 void mshv_isr(void); -int mshv_synic_init(unsigned int cpu); -int mshv_synic_cleanup(unsigned int cpu); +int mshv_synic_init(struct device *dev); +void mshv_synic_cleanup(void); =20 static inline bool mshv_partition_encrypted(struct mshv_partition *partiti= on) { diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index 681b58154d5e..7c1666456e78 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -2035,7 +2035,6 @@ mshv_dev_release(struct inode *inode, struct file *fi= lp) return 0; } =20 -static int mshv_cpuhp_online; static int mshv_root_sched_online; =20 static const char *scheduler_type_to_string(enum hv_scheduler_type type) @@ -2198,40 +2197,14 @@ root_scheduler_deinit(void) free_percpu(root_scheduler_output); } =20 -static int mshv_reboot_notify(struct notifier_block *nb, - unsigned long code, void *unused) -{ - cpuhp_remove_state(mshv_cpuhp_online); - return 0; -} - -struct notifier_block mshv_reboot_nb =3D { - .notifier_call =3D mshv_reboot_notify, -}; - static void mshv_root_partition_exit(void) { - unregister_reboot_notifier(&mshv_reboot_nb); root_scheduler_deinit(); } =20 static int __init mshv_root_partition_init(struct device *dev) { - int err; - - err =3D root_scheduler_init(dev); - if (err) - return err; - - err =3D register_reboot_notifier(&mshv_reboot_nb); - if (err) - goto root_sched_deinit; - - return 0; - -root_sched_deinit: - root_scheduler_deinit(); - return err; + return root_scheduler_init(dev); } =20 static void mshv_init_vmm_caps(struct device *dev) @@ -2276,31 +2249,18 @@ static int __init mshv_parent_partition_init(void) MSHV_HV_MAX_VERSION); } =20 - mshv_root.synic_pages =3D alloc_percpu(struct hv_synic_pages); - if (!mshv_root.synic_pages) { - dev_err(dev, "Failed to allocate percpu synic page\n"); - ret =3D -ENOMEM; + ret =3D mshv_synic_init(dev); + if (ret) goto device_deregister; - } - - ret =3D cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mshv_synic", - mshv_synic_init, - mshv_synic_cleanup); - if (ret < 0) { - dev_err(dev, "Failed to setup cpu hotplug state: %i\n", ret); - goto free_synic_pages; - } - - mshv_cpuhp_online =3D ret; =20 ret =3D mshv_retrieve_scheduler_type(dev); if (ret) - goto remove_cpu_state; + goto synic_cleanup; =20 if (hv_root_partition()) ret =3D mshv_root_partition_init(dev); if (ret) - goto remove_cpu_state; + goto synic_cleanup; =20 mshv_init_vmm_caps(dev); =20 @@ -2318,10 +2278,8 @@ static int __init mshv_parent_partition_init(void) exit_partition: if (hv_root_partition()) mshv_root_partition_exit(); -remove_cpu_state: - cpuhp_remove_state(mshv_cpuhp_online); -free_synic_pages: - free_percpu(mshv_root.synic_pages); +synic_cleanup: + mshv_synic_cleanup(); device_deregister: misc_deregister(&mshv_dev); return ret; @@ -2335,8 +2293,7 @@ static void __exit mshv_parent_partition_exit(void) mshv_irqfd_wq_cleanup(); if (hv_root_partition()) mshv_root_partition_exit(); - cpuhp_remove_state(mshv_cpuhp_online); - free_percpu(mshv_root.synic_pages); + mshv_synic_cleanup(); } =20 module_init(mshv_parent_partition_init); diff --git a/drivers/hv/mshv_synic.c b/drivers/hv/mshv_synic.c index f8b0337cdc82..074e37c48876 100644 --- a/drivers/hv/mshv_synic.c +++ b/drivers/hv/mshv_synic.c @@ -12,11 +12,16 @@ #include #include #include +#include +#include #include =20 #include "mshv_eventfd.h" #include "mshv.h" =20 +static int synic_cpuhp_online; +static struct hv_synic_pages __percpu *synic_pages; + static u32 synic_event_ring_get_queued_port(u32 sint_index) { struct hv_synic_event_ring_page **event_ring_page; @@ -26,7 +31,7 @@ static u32 synic_event_ring_get_queued_port(u32 sint_inde= x) u32 message; u8 tail; =20 - spages =3D this_cpu_ptr(mshv_root.synic_pages); + spages =3D this_cpu_ptr(synic_pages); event_ring_page =3D &spages->synic_event_ring_page; synic_eventring_tail =3D (u8 **)this_cpu_ptr(hv_synic_eventring_tail); =20 @@ -393,7 +398,7 @@ mshv_intercept_isr(struct hv_message *msg) =20 void mshv_isr(void) { - struct hv_synic_pages *spages =3D this_cpu_ptr(mshv_root.synic_pages); + struct hv_synic_pages *spages =3D this_cpu_ptr(synic_pages); struct hv_message_page **msg_page =3D &spages->hyp_synic_message_page; struct hv_message *msg; bool handled; @@ -446,7 +451,7 @@ void mshv_isr(void) } } =20 -int mshv_synic_init(unsigned int cpu) +static int mshv_synic_cpu_init(unsigned int cpu) { union hv_synic_simp simp; union hv_synic_siefp siefp; @@ -455,7 +460,7 @@ int mshv_synic_init(unsigned int cpu) union hv_synic_sint sint; #endif union hv_synic_scontrol sctrl; - struct hv_synic_pages *spages =3D this_cpu_ptr(mshv_root.synic_pages); + struct hv_synic_pages *spages =3D this_cpu_ptr(synic_pages); struct hv_message_page **msg_page =3D &spages->hyp_synic_message_page; struct hv_synic_event_flags_page **event_flags_page =3D &spages->synic_event_flags_page; @@ -542,14 +547,14 @@ int mshv_synic_init(unsigned int cpu) return -EFAULT; } =20 -int mshv_synic_cleanup(unsigned int cpu) +static int mshv_synic_cpu_exit(unsigned int cpu) { union hv_synic_sint sint; union hv_synic_simp simp; union hv_synic_siefp siefp; union hv_synic_sirbp sirbp; union hv_synic_scontrol sctrl; - struct hv_synic_pages *spages =3D this_cpu_ptr(mshv_root.synic_pages); + struct hv_synic_pages *spages =3D this_cpu_ptr(synic_pages); struct hv_message_page **msg_page =3D &spages->hyp_synic_message_page; struct hv_synic_event_flags_page **event_flags_page =3D &spages->synic_event_flags_page; @@ -663,3 +668,57 @@ mshv_unregister_doorbell(u64 partition_id, int doorbel= l_portid) =20 mshv_portid_free(doorbell_portid); } + +static int mshv_synic_reboot_notify(struct notifier_block *nb, + unsigned long code, void *unused) +{ + if (!hv_root_partition()) + return 0; + + cpuhp_remove_state(synic_cpuhp_online); + return 0; +} + +static struct notifier_block mshv_synic_reboot_nb =3D { + .notifier_call =3D mshv_synic_reboot_notify, +}; + +int __init mshv_synic_init(struct device *dev) +{ + int ret =3D 0; + + synic_pages =3D alloc_percpu(struct hv_synic_pages); + if (!synic_pages) { + dev_err(dev, "Failed to allocate percpu synic page\n"); + return -ENOMEM; + } + + ret =3D cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "mshv_synic", + mshv_synic_cpu_init, + mshv_synic_cpu_exit); + if (ret < 0) { + dev_err(dev, "Failed to setup cpu hotplug state: %i\n", ret); + goto free_synic_pages; + } + + synic_cpuhp_online =3D ret; + + ret =3D register_reboot_notifier(&mshv_synic_reboot_nb); + if (ret) + goto remove_cpuhp_state; + + return 0; + +remove_cpuhp_state: + cpuhp_remove_state(synic_cpuhp_online); +free_synic_pages: + free_percpu(synic_pages); + return ret; +} + +void mshv_synic_cleanup(void) +{ + unregister_reboot_notifier(&mshv_synic_reboot_nb); + cpuhp_remove_state(synic_cpuhp_online); + free_percpu(synic_pages); +} --=20 2.34.1