mirror-linux/drivers/hv
Dexuan Cui 0d5acba633 Drivers: hv: vmbus: Export hv_vmbus_exists() and use it in pci-hyperv
With commit f84b21da36 ("PCI: hv: Don't load the driver for baremetal root partition"),
the bare metal Linux root partition won't use the pci-hyperv driver, but
when a Linux VM runs on the Linux root partition, pci-hyperv's module_init
function init_hv_pci_drv() can still run, e.g. in the case of
CONFIG_PCI_HYPERV=y, even if the VMBus driver is not used in such a VM
(i.e. the hv_vmbus driver's init function returns -ENODEV due to
vmbus_root_device being NULL).

In such a Linux VM, init_hv_pci_drv() runs with a side effect: the 3
hvpci_block_ops callbacks are set to functions that depend on hv_vmbus.

Later, when the MLX driver in such a VM invokes the callbacks, e.g. in
drivers/net/ethernet/mellanox/mlx5/core/lib/hv.c:
mlx5_hv_register_invalidate(), hvpci_block_ops.reg_blk_invalidate() is
hv_register_block_invalidate() rather than a NULL function pointer, and
hv_register_block_invalidate() assumes that it can find a struct
hv_pcibus_device from pdev->bus->sysdata, which is false in such a VM.

Consequently, hv_register_block_invalidate() -> get_pcichild_wslot() ->
spin_lock_irqsave() may hang since it can be accessing an invalid
spinlock pointer.

Fix the issue by exporting hv_vmbus_exists() and using it in pci-hyperv:

    hv_root_partition() is true and hv_nested is false ==>
	hv_vmbus_exists() is false.

    hv_root_partition() is true and hv_nested is true ==>
	hv_vmbus_exists() is true.

    hv_root_partition() is false ==> hv_vmbus_exists() is true.

While at it, rename vmbus_exists() to hv_vmbus_exists() to follow the
convention that all public functions have the hv_ prefix; also change
the return value's type from int to bool to make the code more readable;
also move the two pr_info() calls.

Reported-by: Mukesh Rathor <mrathor@linux.microsoft.com>
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>
2026-04-14 04:42:44 +00:00
..
Kconfig mshv: Add support for movable memory regions 2025-12-05 23:20:49 +00:00
Makefile mshv: Introduce tracing support 2026-04-14 04:42:02 +00:00
channel.c Drivers: hv: fix missing kernel-doc description for 'size' in request_arr_init() 2025-11-15 06:18:16 +00:00
channel_mgmt.c Drivers: hv: vmbus: Limit channel interrupt scan to relid high water mark 2026-04-14 04:42:02 +00:00
connection.c Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses 2026-02-22 08:26:33 -08:00
hv.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
hv_balloon.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
hv_common.c mshv: Handle insufficient root memory hypervisor statuses 2026-02-19 06:42:11 +00:00
hv_debugfs.c
hv_kvp.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
hv_proc.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
hv_snapshot.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
hv_trace.c
hv_trace.h Drivers: hv: vmbus: Drivers: hv: vmbus: Introduce CHANNELMSG_MODIFYCHANNEL_RESPONSE 2021-04-18 13:03:11 +00:00
hv_trace_balloon.h
hv_util.c Drivers: hv: use kmalloc_array() instead of kmalloc() 2025-12-05 23:16:49 +00:00
hv_utils_transport.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
hv_utils_transport.h
hyperv_vmbus.h Drivers: hv: vmbus: Limit channel interrupt scan to relid high water mark 2026-04-14 04:42:02 +00:00
mshv.h mshv: Use common "entry virt" APIs to do work in root before running guest 2025-09-30 22:50:48 +00:00
mshv_common.c mshv: hide x86-specific functions on arm64 2025-12-17 18:04:15 +00:00
mshv_debugfs.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
mshv_debugfs_counters.c mshv: Add data for printing stats page counters 2026-02-04 06:17:05 +00:00
mshv_eventfd.c mshv: Introduce tracing support 2026-04-14 04:42:02 +00:00
mshv_eventfd.h mshv: clear eventfd counter on irqfd shutdown 2026-02-04 06:36:19 +00:00
mshv_irq.c mshv: Introduce tracing support 2026-04-14 04:42:02 +00:00
mshv_portid_table.c Drivers: hv: Introduce mshv_root module to expose /dev/mshv to VMMs 2025-03-21 18:24:22 +00:00
mshv_regions.c mshv: Fix error handling in mshv_region_pin 2026-03-18 16:18:49 +00:00
mshv_root.h mshv: Introduce tracing support 2026-04-14 04:42:02 +00:00
mshv_root_hv_call.c mshv: Introduce tracing support 2026-04-14 04:42:02 +00:00
mshv_root_main.c mshv: Introduce tracing support 2026-04-14 04:42:02 +00:00
mshv_synic.c mshv: add arm64 support for doorbell & intercept SINTs 2026-02-25 19:09:49 +00:00
mshv_trace.c mshv: Introduce tracing support 2026-04-14 04:42:02 +00:00
mshv_trace.h mshv: Introduce tracing support 2026-04-14 04:42:02 +00:00
mshv_vtl.h Drivers: hv: Introduce mshv_vtl driver 2025-12-05 23:16:26 +00:00
mshv_vtl_main.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
ring_buffer.c Convert more 'alloc_obj' cases to default GFP_KERNEL arguments 2026-02-21 20:03:00 -08:00
vmbus_drv.c Drivers: hv: vmbus: Export hv_vmbus_exists() and use it in pci-hyperv 2026-04-14 04:42:44 +00:00