Skip to content

Commit 2a8a8af

Browse files
vittyvkliuw
authored andcommitted
Drivers: hv: Always reserve framebuffer region for Gen1 VMs
vmbus_reserve_fb() tries reserving framebuffer region iff 'screen_info.lfb_base' is set. Gen2 VMs seem to have it set by EFI and/or by the kernel EFI FB driver (or, in some edge cases like kexec, the address where the buffer was moved, see https://lore.kernel.org/all/[email protected]/) but on Gen1 VM it depends on bootloader behavior. With grub, it depends on 'gfxpayload=' setting but in some cases it is observed to be zero. That being said, relying on 'screen_info.lfb_base' to reserve framebuffer region is risky. For Gen1 VMs, it should always be possible to get the address from the dedicated PCI device instead. Check for legacy PCI video device presence and reserve the whole region for framebuffer on Gen1 VMs. 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 8409fe9 commit 2a8a8af

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

drivers/hv/vmbus_drv.c

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/kernel.h>
3636
#include <linux/syscore_ops.h>
3737
#include <linux/dma-map-ops.h>
38+
#include <linux/pci.h>
3839
#include <clocksource/hyperv_timer.h>
3940
#include "hyperv_vmbus.h"
4041

@@ -2262,26 +2263,43 @@ static int vmbus_acpi_remove(struct acpi_device *device)
22622263

22632264
static void vmbus_reserve_fb(void)
22642265
{
2265-
int size;
2266+
resource_size_t start = 0, size;
2267+
struct pci_dev *pdev;
2268+
2269+
if (efi_enabled(EFI_BOOT)) {
2270+
/* Gen2 VM: get FB base from EFI framebuffer */
2271+
start = screen_info.lfb_base;
2272+
size = max_t(__u32, screen_info.lfb_size, 0x800000);
2273+
} else {
2274+
/* Gen1 VM: get FB base from PCI */
2275+
pdev = pci_get_device(PCI_VENDOR_ID_MICROSOFT,
2276+
PCI_DEVICE_ID_HYPERV_VIDEO, NULL);
2277+
if (!pdev)
2278+
return;
2279+
2280+
if (pdev->resource[0].flags & IORESOURCE_MEM) {
2281+
start = pci_resource_start(pdev, 0);
2282+
size = pci_resource_len(pdev, 0);
2283+
}
2284+
2285+
/*
2286+
* Release the PCI device so hyperv_drm or hyperv_fb driver can
2287+
* grab it later.
2288+
*/
2289+
pci_dev_put(pdev);
2290+
}
2291+
2292+
if (!start)
2293+
return;
2294+
22662295
/*
22672296
* Make a claim for the frame buffer in the resource tree under the
22682297
* first node, which will be the one below 4GB. The length seems to
22692298
* be underreported, particularly in a Generation 1 VM. So start out
22702299
* reserving a larger area and make it smaller until it succeeds.
22712300
*/
2272-
2273-
if (screen_info.lfb_base) {
2274-
if (efi_enabled(EFI_BOOT))
2275-
size = max_t(__u32, screen_info.lfb_size, 0x800000);
2276-
else
2277-
size = max_t(__u32, screen_info.lfb_size, 0x4000000);
2278-
2279-
for (; !fb_mmio && (size >= 0x100000); size >>= 1) {
2280-
fb_mmio = __request_region(hyperv_mmio,
2281-
screen_info.lfb_base, size,
2282-
fb_mmio_name, 0);
2283-
}
2284-
}
2301+
for (; !fb_mmio && (size >= 0x100000); size >>= 1)
2302+
fb_mmio = __request_region(hyperv_mmio, start, size, fb_mmio_name, 0);
22852303
}
22862304

22872305
/**

0 commit comments

Comments
 (0)