Skip to content

Commit 102d028

Browse files
mhklinuxgregkh
authored andcommitted
Drivers: hv: vmbus: Don't release fb_mmio resource in vmbus_free_mmio()
[ Upstream commit 73fe907 ] 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: be000f9 ("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>
1 parent 4545e2a commit 102d028

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

drivers/hv/vmbus_drv.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,12 +2262,25 @@ void vmbus_free_mmio(resource_size_t start, resource_size_t size)
22622262
struct resource *iter;
22632263

22642264
mutex_lock(&hyperv_mmio_lock);
2265+
2266+
/*
2267+
* If all bytes of the MMIO range to be released are within the
2268+
* special case fb_mmio shadow region, skip releasing the shadow
2269+
* region since no corresponding __request_region() was done
2270+
* in vmbus_allocate_mmio().
2271+
*/
2272+
if (fb_mmio && start >= fb_mmio->start &&
2273+
(start + size - 1 <= fb_mmio->end))
2274+
goto skip_shadow_release;
2275+
22652276
for (iter = hyperv_mmio; iter; iter = iter->sibling) {
22662277
if ((iter->start >= start + size) || (iter->end <= start))
22672278
continue;
22682279

22692280
__release_region(iter, start, size);
22702281
}
2282+
2283+
skip_shadow_release:
22712284
release_mem_region(start, size);
22722285
mutex_unlock(&hyperv_mmio_lock);
22732286

0 commit comments

Comments
 (0)