Skip to content

Commit f0880e2

Browse files
vittyvkliuw
authored andcommitted
Drivers: hv: Never allocate anything besides framebuffer from framebuffer memory region
Passed through PCI device sometimes misbehave on Gen1 VMs when Hyper-V DRM driver is also loaded. Looking at IOMEM assignment, we can see e.g. $ cat /proc/iomem ... f8000000-fffbffff : PCI Bus 0000:00 f8000000-fbffffff : 0000:00:08.0 f8000000-f8001fff : bb8c4f33-2ba2-4808-9f7f-02f3b4da22fe ... fe0000000-fffffffff : PCI Bus 0000:00 fe0000000-fe07fffff : bb8c4f33-2ba2-4808-9f7f-02f3b4da22fe fe0000000-fe07fffff : 2ba2:00:02.0 fe0000000-fe07fffff : mlx4_core the interesting part is the 'f8000000' region as it is actually the VM's framebuffer: $ lspci -v ... 0000:00:08.0 VGA compatible controller: Microsoft Corporation Hyper-V virtual VGA (prog-if 00 [VGA controller]) Flags: bus master, fast devsel, latency 0, IRQ 11 Memory at f8000000 (32-bit, non-prefetchable) [size=64M] ... hv_vmbus: registering driver hyperv_drm hyperv_drm 5620e0c7-8062-4dce-aeb7-520c7ef76171: [drm] Synthvid Version major 3, minor 5 hyperv_drm 0000:00:08.0: vgaarb: deactivate vga console hyperv_drm 0000:00:08.0: BAR 0: can't reserve [mem 0xf8000000-0xfbffffff] hyperv_drm 5620e0c7-8062-4dce-aeb7-520c7ef76171: [drm] Cannot request framebuffer, boot fb still active? Note: "Cannot request framebuffer" is not a fatal error in hyperv_setup_gen1() as the code assumes there's some other framebuffer device there but we actually have some other PCI device (mlx4 in this case) config space there! The problem appears to be that vmbus_allocate_mmio() can use dedicated framebuffer region to serve any MMIO request from any device. The semantics one might assume of a parameter named "fb_overlap_ok" aren't implemented because !fb_overlap_ok essentially has no effect. The existing semantics are really "prefer_fb_overlap". This patch implements the expected and needed semantics, which is to not allocate from the frame buffer space when !fb_overlap_ok. Note, Gen2 VMs are usually unaffected by the issue because framebuffer region is already taken by EFI fb (in case kernel supports it) but Gen1 VMs may have this region unclaimed by the time Hyper-V PCI pass-through driver tries allocating MMIO space if Hyper-V DRM/FB drivers load after it. Devices can be brought up in any sequence so let's resolve the issue by always ignoring 'fb_mmio' region for non-FB requests, even if the region is unclaimed. Reviewed-by: Michael Kelley <[email protected]> Signed-off-by: Vitaly Kuznetsov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Wei Liu <[email protected]>
1 parent 2a8a8af commit f0880e2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/hv/vmbus_drv.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2331,7 +2331,7 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
23312331
bool fb_overlap_ok)
23322332
{
23332333
struct resource *iter, *shadow;
2334-
resource_size_t range_min, range_max, start;
2334+
resource_size_t range_min, range_max, start, end;
23352335
const char *dev_n = dev_name(&device_obj->device);
23362336
int retval;
23372337

@@ -2366,6 +2366,14 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
23662366
range_max = iter->end;
23672367
start = (range_min + align - 1) & ~(align - 1);
23682368
for (; start + size - 1 <= range_max; start += align) {
2369+
end = start + size - 1;
2370+
2371+
/* Skip the whole fb_mmio region if not fb_overlap_ok */
2372+
if (!fb_overlap_ok && fb_mmio &&
2373+
(((start >= fb_mmio->start) && (start <= fb_mmio->end)) ||
2374+
((end >= fb_mmio->start) && (end <= fb_mmio->end))))
2375+
continue;
2376+
23692377
shadow = __request_region(iter, start, size, NULL,
23702378
IORESOURCE_BUSY);
23712379
if (!shadow)

0 commit comments

Comments
 (0)