From patchwork Fri Dec 2 21:18:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 13063261 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A23C4C4708D for ; Fri, 2 Dec 2022 21:19:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234426AbiLBVS7 (ORCPT ); Fri, 2 Dec 2022 16:18:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234204AbiLBVSx (ORCPT ); Fri, 2 Dec 2022 16:18:53 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F3D573F75; Fri, 2 Dec 2022 13:18:50 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id E641DCE1FBA; Fri, 2 Dec 2022 21:18:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8581C433C1; Fri, 2 Dec 2022 21:18:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670015926; bh=ubkFfiu5Wnnhs5ib/lclNCLynBsh33oIb0GlenBh+UE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P1Btn/vL5p35gOwKHoiCm8WQDttirgms2zGjwwU/ndnOUY96WabGqgLcHzPcAYf4a PXzk1gHcdUxMKKrb7ApFKVqUM5iRyPTdZ19dwhZm1Zol0VikITpNngYJYyrhxlbV7l 3kKNjjR4VOCBgpOURKbkqJ5+C26iaz+PGC0088mVCcFAFuEqMB5gJVFNXeYybw/SWj CcL8svAVJSFUKv9OchGxOwabE8rehffMzEFqotkr9FhjJreJcub+Fd/I9KviVZjvpG dceJ/A9sIoo4xjs6wG0Oekui8aRBxRnshTP+KB9yZuj7xpqiF7P77qSPiQcIBwaEpB c1EwXgAUkpQjQ== From: Bjorn Helgaas To: linux-pci@vger.kernel.org Cc: Hans de Goede , Florent DELAHAYE , Konrad J Hambrick , Matt Hansen <2lprbe78@duck.com>, =?utf-8?q?Benoit_Gr=C3=A9goire?= , Nicholas Johnson , Mika Westerberg , Werner Sembach , mumblingdrunkard@protonmail.com, linux-kernel@vger.kernel.org, Bjorn Helgaas Subject: [PATCH 1/4] efi/x86: Remove EfiMemoryMappedIO from E820 map Date: Fri, 2 Dec 2022 15:18:35 -0600 Message-Id: <20221202211838.1061278-2-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221202211838.1061278-1-helgaas@kernel.org> References: <20221202211838.1061278-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas Firmware can use EfiMemoryMappedIO to request that MMIO regions be mapped by the OS so they can be accessed by EFI runtime services, but should have no other significance to the OS (UEFI r2.10, sec 7.2). However, most bootloaders and EFI stubs convert EfiMemoryMappedIO regions to E820_TYPE_RESERVED entries, which prevent Linux from allocating space from them (see remove_e820_regions()). Some platforms use EfiMemoryMappedIO entries for PCI MMCONFIG space and PCI host bridge windows, which means Linux can't allocate BAR space for hot-added devices. Remove any EfiMemoryMappedIO regions from the E820 map to avoid this problem. The previous solution to the problem of allocating BARs in these regions was to add pci_crs_quirks[] entries to disable E820 checking for these machines (see d341838d776a ("x86/PCI: Disable E820 reserved region clipping via quirks")): Acer DMI_PRODUCT_NAME Spin SP513-54N Clevo DMI_BOARD_NAME X170KM-G Lenovo DMI_PRODUCT_VERSION *IIL* Florent reported the BAR allocation issue on the Clevo NL4XLU. We could add another quirk for the NL4XLU, but I hope this generic change can solve it for many machines without having to add quirks. This change has been tested on Clevo X170KM-G (Konrad) and Lenovo Ideapad Slim 3 (Matt) and solves the problem even when overriding the existing quirks by booting with "pci=use_e820". Link: https://bugzilla.kernel.org/show_bug.cgi?id=216565 Clevo NL4XLU Link: https://bugzilla.kernel.org/show_bug.cgi?id=206459#c78 Clevo X170KM-G Link: https://bugzilla.redhat.com/show_bug.cgi?id=1868899 Ideapad Slim 3 Reported-by: Florent DELAHAYE Signed-off-by: Bjorn Helgaas Tested-by: Konrad J Hambrick Tested-by: Matt Hansen <2lprbe78@duck.com> Cc: Hans de Goede --- arch/x86/platform/efi/efi.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index ebc98a68c400..4728f60119da 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -303,6 +303,40 @@ static void __init efi_clean_memmap(void) } } +/* + * Firmware can use EfiMemoryMappedIO to request that MMIO regions be + * mapped by the OS so they can be accessed by EFI runtime services, but + * should have no other significance to the OS (UEFI r2.10, sec 7.2). + * However, most bootloaders and EFI stubs convert EfiMemoryMappedIO + * regions to E820_TYPE_RESERVED entries, which prevent Linux from + * allocating space from them (see remove_e820_regions()). + * + * Some platforms use EfiMemoryMappedIO entries for PCI MMCONFIG space and + * PCI host bridge windows, which means Linux can't allocate BAR space for + * hot-added devices. + * + * Remove any EfiMemoryMappedIO regions from the E820 map to avoid this + * problem. + */ +static void __init efi_remove_e820_mmio(void) +{ + efi_memory_desc_t *md; + u64 size, start, end; + int i = 0; + + for_each_efi_memory_desc(md) { + if (md->type == EFI_MEMORY_MAPPED_IO) { + size = md->num_pages << EFI_PAGE_SHIFT; + start = md->phys_addr; + end = start + size - 1; + pr_info("Remove mem%02u: MMIO range=[0x%08llx-0x%08llx] (%lluMB) from e820 map\n", + i, start, end, size >> 20); + e820__range_remove(start, size, E820_TYPE_RESERVED, 1); + } + i++; + } +} + void __init efi_print_memmap(void) { efi_memory_desc_t *md; @@ -474,6 +508,8 @@ void __init efi_init(void) set_bit(EFI_RUNTIME_SERVICES, &efi.flags); efi_clean_memmap(); + efi_remove_e820_mmio(); + if (efi_enabled(EFI_DBG)) efi_print_memmap(); } From patchwork Fri Dec 2 21:18:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 13063257 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A67A4C4332F for ; Fri, 2 Dec 2022 21:18:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233664AbiLBVS4 (ORCPT ); Fri, 2 Dec 2022 16:18:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234041AbiLBVSv (ORCPT ); Fri, 2 Dec 2022 16:18:51 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B33E97046F; Fri, 2 Dec 2022 13:18:49 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 505F6623C0; Fri, 2 Dec 2022 21:18:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 809A1C433D7; Fri, 2 Dec 2022 21:18:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670015928; bh=jsOes6lsRyJazCweN98/1MgbRRFwiPjB2+BoIczXWYE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hHcSTLEU0se8MLHfKx412OkDrWWRGjN1mwbgjdtwhjAg9ONVOxHbB5dUE1EoK2VCG uUWJmcgCzJU6WmOFB9UZR8u0mN+Ptaqs0AbVVQ03qEBUXb6LMmrt0pz31DzlNfoaCB JTCtFbZDVp3Kp1BFCQ77CEfhK61B4ufWOuCvdKcFXqlSOwE3k3PUlR98fOLiwYh36m ZJetJFy3D2FBjUzjyajNfGq47D5CAW7D6RrXQlXC0SaBfLMwXGE4KRzFv9qfq9uDWZ NMmLqx4mCX8rNUxlWIf8mr1Ov1knSLExOVf2e9W9jHMPWGoLH3ErzySppAjn+sSHCy 3cg562HdjPOeg== From: Bjorn Helgaas To: linux-pci@vger.kernel.org Cc: Hans de Goede , Florent DELAHAYE , Konrad J Hambrick , Matt Hansen <2lprbe78@duck.com>, =?utf-8?q?Benoit_Gr=C3=A9goire?= , Nicholas Johnson , Mika Westerberg , Werner Sembach , mumblingdrunkard@protonmail.com, linux-kernel@vger.kernel.org, Bjorn Helgaas Subject: [PATCH 2/4] PCI: Skip allocate_resource() if too little space available Date: Fri, 2 Dec 2022 15:18:36 -0600 Message-Id: <20221202211838.1061278-3-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221202211838.1061278-1-helgaas@kernel.org> References: <20221202211838.1061278-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas pci_bus_alloc_from_region() allocates MMIO space by iterating through all the resources available on the bus. The available resource might be reduced if the caller requires 32-bit space or we're avoiding BIOS or E820 areas. Don't bother calling allocate_resource() if we need more space than is available in this resource. This prevents some pointless and annoying messages about avoided areas. Signed-off-by: Bjorn Helgaas Cc: Hans de Goede --- drivers/pci/bus.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 3cef835b375f..83ae838ceb5f 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -197,6 +197,10 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res, max = avail.end; + /* Don't bother if available space isn't large enough */ + if (size > max - min_used + 1) + continue; + /* Ok, try it out.. */ ret = allocate_resource(r, res, size, min_used, max, align, alignf, alignf_data); From patchwork Fri Dec 2 21:18:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 13063260 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08491C47090 for ; Fri, 2 Dec 2022 21:19:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233977AbiLBVS6 (ORCPT ); Fri, 2 Dec 2022 16:18:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229480AbiLBVSw (ORCPT ); Fri, 2 Dec 2022 16:18:52 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8776481382; Fri, 2 Dec 2022 13:18:51 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 25EA9623D6; Fri, 2 Dec 2022 21:18:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EA61C433D6; Fri, 2 Dec 2022 21:18:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670015930; bh=98iM6PYlP1DYwAk+kn2Y+b30wbZFzaWkuIMVL5eYs9E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JHW5goLi4gEr/sxsDqMHLD3F5/TDtVgc5DMrBwUgfeIk5J/Sz6gZmeriQGHK0b+Rw fjm0AjUwPVDtaCe/N0Y17PHViz0nvNsN+X3/LSfcRRWNslFzP1SaVtVap8XKIZYzPf AmCiOVIjCOpzc3XXS9KZjJ/MfBQYF06WcOckJ2xs2gr/iQCdPE54shmflRAI1ueOa2 AcUjige64Bw1PGcXzqboU1gv4iN7bolYEAhDgsCOMxdVMBc1PxtoTeNnzCxo9nulA1 c6vC0P6mCcbZqjWwSnuTI3esa2V7pynZUy0qtH+WLKRzs5hBmqYVmEgyR76mANbClo OEg/V+ZT/Yp1g== From: Bjorn Helgaas To: linux-pci@vger.kernel.org Cc: Hans de Goede , Florent DELAHAYE , Konrad J Hambrick , Matt Hansen <2lprbe78@duck.com>, =?utf-8?q?Benoit_Gr=C3=A9goire?= , Nicholas Johnson , Mika Westerberg , Werner Sembach , mumblingdrunkard@protonmail.com, linux-kernel@vger.kernel.org, Bjorn Helgaas Subject: [PATCH 3/4] x86/PCI: Tidy E820 removal messages Date: Fri, 2 Dec 2022 15:18:37 -0600 Message-Id: <20221202211838.1061278-4-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221202211838.1061278-1-helgaas@kernel.org> References: <20221202211838.1061278-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas These messages: clipped [mem size 0x00000000 64bit] to [mem size 0xfffffffffffa0000 64bit] for e820 entry [mem 0x0009f000-0x000fffff] aren't as useful as they could be because (a) the resource is often IORESOURCE_UNSET, so we print the size instead of the start/end and (b) we print the available resource even if it is empty after removing the E820 entry. Print the available space by hand to avoid the IORESOURCE_UNSET problem and only if it's non-empty. No functional change intended. Signed-off-by: Bjorn Helgaas Cc: Hans de Goede --- arch/x86/kernel/resource.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/resource.c b/arch/x86/kernel/resource.c index bba1abd05bfe..f34454f694cb 100644 --- a/arch/x86/kernel/resource.c +++ b/arch/x86/kernel/resource.c @@ -42,8 +42,11 @@ static void remove_e820_regions(struct resource *avail) resource_clip(avail, e820_start, e820_end); if (orig.start != avail->start || orig.end != avail->end) { - pr_info("clipped %pR to %pR for e820 entry [mem %#010Lx-%#010Lx]\n", - &orig, avail, e820_start, e820_end); + pr_info("resource: avoiding allocation from e820 entry [mem %#010Lx-%#010Lx]\n", + e820_start, e820_end); + if (avail->end > avail->start) + pr_info("resource: remaining [mem %#010Lx-%#010Lx] available\n", + avail->start, avail->end); orig = *avail; } } From patchwork Fri Dec 2 21:18:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 13063258 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC1D8C47088 for ; Fri, 2 Dec 2022 21:18:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234407AbiLBVS4 (ORCPT ); Fri, 2 Dec 2022 16:18:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234266AbiLBVSz (ORCPT ); Fri, 2 Dec 2022 16:18:55 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54B048B39E; Fri, 2 Dec 2022 13:18:53 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E647C623D6; Fri, 2 Dec 2022 21:18:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28D03C433D6; Fri, 2 Dec 2022 21:18:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670015932; bh=wsQic+DniH74o9yizSX8yaBBMzi/Wi+iIyhKaROtdo8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p3sXXHwxN9VweUd0NumRiwmL3FmBqGo0lrQpAsZNTwWMWhlAH1z4Hvw4Z2wNQpPec owEC9CSEADGVaI21ILS1qF6lSOHhZoQiAlIGQE2DWLNzxtIuIyERr1u9ESbAiaBI6d YwAzIC2FtT/KwO8JBE+KbzFalYk/b/UTa22xwt8zT8KaURtErdrMTiCj0mcY9qsxWA zeFGtNAaoZV6aeMlbE1Q83Lvr/5KjtOhLXYN4P63q8Z0kZXaVFBw8XJ1qOX3Owuyw5 wQw2xSON9scGc4fj0HxEFCwhTVfD749EM94NFKN9LtFef604z9Imao+T5hXLlUll1v Yd9Uozi/3S5tw== From: Bjorn Helgaas To: linux-pci@vger.kernel.org Cc: Hans de Goede , Florent DELAHAYE , Konrad J Hambrick , Matt Hansen <2lprbe78@duck.com>, =?utf-8?q?Benoit_Gr=C3=A9goire?= , Nicholas Johnson , Mika Westerberg , Werner Sembach , mumblingdrunkard@protonmail.com, linux-kernel@vger.kernel.org, Bjorn Helgaas Subject: [PATCH 4/4] x86/PCI: Fix log message typo Date: Fri, 2 Dec 2022 15:18:38 -0600 Message-Id: <20221202211838.1061278-5-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221202211838.1061278-1-helgaas@kernel.org> References: <20221202211838.1061278-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas Add missing word in the log message: - ... so future kernels can this automatically + ... so future kernels can do this automatically Signed-off-by: Bjorn Helgaas Cc: Hans de Goede --- arch/x86/pci/acpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c index 2f82480fd430..83dfea9e9894 100644 --- a/arch/x86/pci/acpi.c +++ b/arch/x86/pci/acpi.c @@ -245,7 +245,7 @@ void __init pci_acpi_crs_quirks(void) printk(KERN_INFO "PCI: %s E820 reservations for host bridge windows\n", pci_use_e820 ? "Using" : "Ignoring"); if (pci_probe & (PCI_NO_E820 | PCI_USE_E820)) - printk(KERN_INFO "PCI: Please notify linux-pci@vger.kernel.org so future kernels can this automatically\n"); + printk(KERN_INFO "PCI: Please notify linux-pci@vger.kernel.org so future kernels can do this automatically\n"); } #ifdef CONFIG_PCI_MMCONFIG