Re: [PATCH 3/6] Drivers: hv: initialize partition table before device registration
From: Wei Liu
Date: Mon Nov 02 2026 - 19:59:27 EST
On Wed, Oct 28, 2026 at 12:48:23PM +0800, Jiale Yao wrote:
> misc_register() exposes /dev/mshv before the partition hash table and
> its lock are initialized. A partition ioctl racing module initialization
> can therefore access the table through an uninitialized spinlock.
>
> Initialize the partition table and lock before registering the misc
> device.
>
> Fixes: 621191d709b1 ("Drivers: hv: Introduce mshv_root module to expose /dev/mshv to VMMs")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Jiale Yao <yaojiale02@xxxxxxx>
If such races are really a problem, shouldn't the msic_register call be
the last in the function?
Wei
> ---
> drivers/hv/mshv_root_main.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
> index cc2cfce2aefd..ce26320035b6 100644
> --- a/drivers/hv/mshv_root_main.c
> +++ b/drivers/hv/mshv_root_main.c
> @@ -2369,6 +2369,9 @@ static int __init mshv_parent_partition_init(void)
> if (hv_get_hypervisor_version(&version_info))
> return -ENODEV;
>
> + spin_lock_init(&mshv_root.pt_ht_lock);
> + hash_init(mshv_root.pt_htable);
> +
> ret = misc_register(&mshv_dev);
> if (ret)
> return ret;
> @@ -2407,9 +2410,6 @@ static int __init mshv_parent_partition_init(void)
> if (ret)
> goto exit_debugfs;
>
> - spin_lock_init(&mshv_root.pt_ht_lock);
> - hash_init(mshv_root.pt_htable);
> -
> hv_setup_mshv_handler(mshv_isr);
>
> return 0;
> --
> 2.34.1
>