sst-linux/drivers/hv
Michael Kelley 1c954950f8 Drivers: hv: vmbus: Don't release fb_mmio resource in vmbus_free_mmio()
[ Upstream commit 73fe9073c0cc28056cb9de0c8a516dac070f1d1f ]

The VMBus driver manages the MMIO space it owns via the hyperv_mmio
resource tree. Because the synthetic video framebuffer portion of the
MMIO space is initially setup by the Hyper-V host for each guest, the
VMBus driver does an early reserve of that portion of MMIO space in the
hyperv_mmio resource tree. It saves a pointer to that resource in
fb_mmio. When a VMBus driver requests MMIO space and passes "true"
for the "fb_overlap_ok" argument, the reserved framebuffer space is
used if possible. In that case it's not necessary to do another request
against the "shadow" hyperv_mmio resource tree because that resource
was already requested in the early reserve steps.

However, the vmbus_free_mmio() function currently does no special
handling for the fb_mmio resource. When a framebuffer device is
removed, or the driver is unbound, the current code for
vmbus_free_mmio() releases the reserved resource, leaving fb_mmio
pointing to memory that has been freed. If the same or another
driver is subsequently bound to the device, vmbus_allocate_mmio()
checks against fb_mmio, and potentially gets garbage. Furthermore
a second unbind operation produces this "nonexistent resource" error
because of the unbalanced behavior between vmbus_allocate_mmio() and
vmbus_free_mmio():

[   55.499643] resource: Trying to free nonexistent
			resource <0x00000000f0000000-0x00000000f07fffff>

Fix this by adding logic to vmbus_free_mmio() to recognize when
MMIO space in the fb_mmio reserved area would be released, and don't
release it. This filtering ensures the fb_mmio resource always exists,
and makes vmbus_free_mmio() more parallel with vmbus_allocate_mmio().

Fixes: be000f93e5 ("drivers:hv: Track allocations of children of hv_vmbus in private resource tree")
Signed-off-by: Michael Kelley <mhklinux@outlook.com>
Tested-by: Saurabh Sengar <ssengar@linux.microsoft.com>
Reviewed-by: Saurabh Sengar <ssengar@linux.microsoft.com>
Link: https://lore.kernel.org/r/20250310035208.275764-1-mhklinux@outlook.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Message-ID: <20250310035208.275764-1-mhklinux@outlook.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2025-03-28 21:58:49 +01:00
..
channel_mgmt.c
channel.c
connection.c
hv_balloon.c
hv_common.c
hv_debugfs.c
hv_fcopy.c
hv_kvp.c Drivers: hv: util: Avoid accessing a ringbuffer not initialized yet 2024-12-27 13:52:59 +01:00
hv_snapshot.c Drivers: hv: util: Avoid accessing a ringbuffer not initialized yet 2024-12-27 13:52:59 +01:00
hv_trace_balloon.h
hv_trace.c
hv_trace.h
hv_util.c Drivers: hv: util: Avoid accessing a ringbuffer not initialized yet 2024-12-27 13:52:59 +01:00
hv_utils_transport.c
hv_utils_transport.h
hv.c
hyperv_vmbus.h Drivers: hv: util: Avoid accessing a ringbuffer not initialized yet 2024-12-27 13:52:59 +01:00
Kconfig
Makefile
ring_buffer.c
vmbus_drv.c Drivers: hv: vmbus: Don't release fb_mmio resource in vmbus_free_mmio() 2025-03-28 21:58:49 +01:00