From 8aba5071e1a97b1b132bf7edadf55f2105a42f59 Mon Sep 17 00:00:00 2001 From: Ruihan Li Date: Fri, 25 Apr 2025 16:32:54 +0800 Subject: [PATCH] lkl: pci: Never override IORESOURCE_IO PCI resources can be a mix of I/O and memory resources: pci 0000:00:00.0: reg 0x10: [mem 0xc1060000-0xc1060fff pref] pci 0000:00:00.0: reg 0x14: [io 0x6040-0x607f] pci 0000:00:00.0: reg 0x18: [mem 0xc1040000-0xc105ffff] pci 0000:00:00.0: reg 0x30: [mem 0xffff0000-0xffffffff pref] In this case, the remapped_resource variable, which is filled with the address of the remapped memory resource in the first PCI BAR, should not be used for the I/O resource in the second PCI BAR. For the specific PCI device, the current code will cause errors in the device probe routine. First, the I/O resource is overridden by some invalid values, then the call to pci_request_regions will think the I/O resource is illegal and fail immediately because the I/O port is not in the normal [0, 0xffff] region. e100 0000:00:00.0: BAR 1: can't reserve [io 0xc1060000-0xc106003f] 0000:00:00.0 (uninitialized): Cannot obtain PCI resources, aborting e100: probe of 0000:00:00.0 failed with error -16 Fixes: 96de6a9f888f ("lkl: add PCI device interface and a vfio backend driver") Signed-off-by: Ruihan Li --- arch/lkl/drivers/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/lkl/drivers/pci.c b/arch/lkl/drivers/pci.c index 7d0242f084d745..ff84e0b58093ff 100644 --- a/arch/lkl/drivers/pci.c +++ b/arch/lkl/drivers/pci.c @@ -44,7 +44,7 @@ static int lkl_pci_override_resource(struct pci_dev *dev, void *data) int i; struct resource *r; resource_size_t start, size; - void *remapped_start = NULL; + void *remapped_start; if (dev->devfn != 0) return 0; @@ -67,6 +67,8 @@ static int lkl_pci_override_resource(struct pci_dev *dev, void *data) remapped_start = lkl_ops->pci_ops->resource_alloc( dev->sysdata, size, i); + } else { + remapped_start = NULL; } if (remapped_start) {