From patchwork Fri Mar 4 03:51:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 12768434 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 77763C433F5 for ; Fri, 4 Mar 2022 03:52:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237411AbiCDDxA (ORCPT ); Thu, 3 Mar 2022 22:53:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233721AbiCDDxA (ORCPT ); Thu, 3 Mar 2022 22:53:00 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B65F17664F; Thu, 3 Mar 2022 19:52:13 -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 ams.source.kernel.org (Postfix) with ESMTPS id 6149CB82750; Fri, 4 Mar 2022 03:52:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B46E4C340E9; Fri, 4 Mar 2022 03:52:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646365931; bh=m3cd/87EOR5r5h766Li1ilZjsk6DttaYV2dfSZj3HW8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U+IeIAZtMDj2h2VkS9kcikAVbywsuF5BVTyyHjxby+l6VfZYaQyAHAG//+hCDPQrW sQSsdzIwbQBWA5pdHpDXlUE1HS0Qw20SGIj+W5n8j4P6SZBiuCM1EbdhH2kTGrvhkf LXKPzHQTvZnrIImNacKNRtWswo1uNgt2+nt0L6VJ4m4TydiAbNM0zW2ffaRCwwdkJ2 aiAQLfr4DQZ9xypgaN+zQYuxdpLHyvIJUzJ/HFwFKfeOnJk0R9tstyD3SAujONte3q GjzsaF+thPu6Ny8CpZP2YmJ5Pt+FseujbOTk+NZE/GzTNLZsfLOZsCeOsNJN57oeoI Ups0q+fIwOmyw== From: Bjorn Helgaas To: Hans de Goede , "Rafael J . Wysocki" , Borislav Petkov , "H . Peter Anvin" , Ingo Molnar Cc: Mika Westerberg , =?utf-8?q?Krzysztof_W?= =?utf-8?q?ilczy=C5=84ski?= , Myron Stowe , Juha-Pekka Heikkila , =?utf-8?q?Benoit_Gr?= =?utf-8?q?=C3=A9goire?= , Hui Wang , Kai-Heng Feng , linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Bjorn Helgaas Subject: [PATCH 1/3] x86/PCI: Eliminate remove_e820_regions() common subexpressions Date: Thu, 3 Mar 2022 21:51:09 -0600 Message-Id: <20220304035110.988712-2-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304035110.988712-1-helgaas@kernel.org> References: <20220304035110.988712-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Bjorn Helgaas Add local variables to reduce repetition later. No functional change intended. Signed-off-by: Bjorn Helgaas --- arch/x86/kernel/resource.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/resource.c b/arch/x86/kernel/resource.c index 9b9fb7882c20..8ffe68437744 100644 --- a/arch/x86/kernel/resource.c +++ b/arch/x86/kernel/resource.c @@ -27,12 +27,14 @@ static void remove_e820_regions(struct resource *avail) { int i; struct e820_entry *entry; + u64 e820_start, e820_end; for (i = 0; i < e820_table->nr_entries; i++) { entry = &e820_table->entries[i]; + e820_start = entry->addr; + e820_end = entry->addr + entry->size - 1; - resource_clip(avail, entry->addr, - entry->addr + entry->size - 1); + resource_clip(avail, e820_start, e820_end); } } From patchwork Fri Mar 4 03:51:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 12768435 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 8B2AEC433EF for ; Fri, 4 Mar 2022 03:52:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237594AbiCDDxG (ORCPT ); Thu, 3 Mar 2022 22:53:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234515AbiCDDxE (ORCPT ); Thu, 3 Mar 2022 22:53:04 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DA7217FD02; Thu, 3 Mar 2022 19:52:17 -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 ams.source.kernel.org (Postfix) with ESMTPS id 2BC24B826D4; Fri, 4 Mar 2022 03:52:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AC3CC340E9; Fri, 4 Mar 2022 03:52:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646365934; bh=CbSbR1Qb5nogbSSYnnK5tukbcwJVTkBgo2iOOiMKzRg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WDZ31iVtHppWxxiM+s1Tj+jup0dQyvzdzgjEb9JnmNtYFYBKZSzLPCa0IaA+8y5b7 qcMmn60xbaNpAXpMuCrrSJ3hLbF9ihUJ8l4o8qRZcKZDqGslw9txivGoazAWAhi3Cl lpYMRknAa6XrvYrILQtQQc47XPEvmnL8vnrJ4/o+tOkW2GclUDk0uLTKcEqWW9F4W4 TQkELBk3nRUn7c9WS6SWZmF75OQlB1vtUK3xKTOEs01mJ0O72F4D4Y1q7IHJUSgJBr nWx6TmAupSOIoGCzH6QfwHhY6dfZYFRDqK/YPYk8hbI01Os9KdraSItJilnQDMsSxk 1TfathMkYY/ww== From: Bjorn Helgaas To: Hans de Goede , "Rafael J . Wysocki" , Borislav Petkov , "H . Peter Anvin" , Ingo Molnar Cc: Mika Westerberg , =?utf-8?q?Krzysztof_W?= =?utf-8?q?ilczy=C5=84ski?= , Myron Stowe , Juha-Pekka Heikkila , =?utf-8?q?Benoit_Gr?= =?utf-8?q?=C3=A9goire?= , Hui Wang , Kai-Heng Feng , linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Bjorn Helgaas Subject: [PATCH 2/3] x86/PCI: Log host bridge window clipping for E820 regions Date: Thu, 3 Mar 2022 21:51:10 -0600 Message-Id: <20220304035110.988712-3-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304035110.988712-1-helgaas@kernel.org> References: <20220304035110.988712-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Bjorn Helgaas ACPI firmware advertises PCI host bridge resources via PNP0A03 _CRS methods. Some BIOSes include non-window address space in _CRS, and if we allocate that non-window space for PCI devices, they don't work. 4dc2287c1805 ("x86: avoid E820 regions when allocating address space") works around this issue by clipping out any regions mentioned in the E820 table in the allocate_resource() path, but the implementation has several issues: - The clipping is done for *all* allocations, not just those for PCI address space, - The clipping is done at each allocation instead of being done once when setting up the host bridge windows, and - The host bridge windows logged in dmesg do not reflect the clipping, and in fact there is *no* indication in dmesg, which complicates debugging. Rework the implementation so we only clip PCI host bridge windows, we do it once when setting them up, we a log message when a window is clipped, and we reflect the clip when printing the host bridge windows. I intend this only to improve the logging, not to fix any issues. Example output changes: BIOS-e820: [mem 0x00000000b0000000-0x00000000c00fffff] reserved + acpi PNP0A08:00: clipped [mem 0xc0000000-0xfebfffff window] to [mem 0xc0100000-0xfebfffff window] for e820 entry [mem 0xb0000000-0xc00fffff] - pci_bus 0000:00: root bus resource [mem 0xc0000000-0xfebfffff window] + pci_bus 0000:00: root bus resource [mem 0xc0100000-0xfebfffff window] Signed-off-by: Bjorn Helgaas --- arch/x86/include/asm/e820/api.h | 5 +++++ arch/x86/kernel/resource.c | 17 ++++++++++++----- arch/x86/pci/acpi.c | 5 +++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h index e8f58ddd06d9..5a39ed59b6db 100644 --- a/arch/x86/include/asm/e820/api.h +++ b/arch/x86/include/asm/e820/api.h @@ -4,6 +4,9 @@ #include +struct device; +struct resource; + extern struct e820_table *e820_table; extern struct e820_table *e820_table_kexec; extern struct e820_table *e820_table_firmware; @@ -43,6 +46,8 @@ extern void e820__register_nosave_regions(unsigned long limit_pfn); extern int e820__get_entry_type(u64 start, u64 end); +extern void remove_e820_regions(struct device *dev, struct resource *avail); + /* * Returns true iff the specified range [start,end) is completely contained inside * the ISA region. diff --git a/arch/x86/kernel/resource.c b/arch/x86/kernel/resource.c index 8ffe68437744..7378ea146976 100644 --- a/arch/x86/kernel/resource.c +++ b/arch/x86/kernel/resource.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include #include @@ -23,18 +24,27 @@ static void resource_clip(struct resource *res, resource_size_t start, res->start = end + 1; } -static void remove_e820_regions(struct resource *avail) +void remove_e820_regions(struct device *dev, struct resource *avail) { + struct resource orig = *avail; int i; struct e820_entry *entry; u64 e820_start, e820_end; + if (!(avail->flags & IORESOURCE_MEM)) + return; + for (i = 0; i < e820_table->nr_entries; i++) { entry = &e820_table->entries[i]; e820_start = entry->addr; e820_end = entry->addr + entry->size - 1; resource_clip(avail, e820_start, e820_end); + if (orig.start != avail->start || orig.end != avail->end) { + dev_info(dev, "clipped %pR to %pR for e820 entry [mem %#010Lx-%#010Lx]\n", + &orig, avail, e820_start, e820_end); + orig = *avail; + } } } @@ -45,9 +55,6 @@ void arch_remove_reservations(struct resource *avail) * the low 1MB unconditionally, as this area is needed for some ISA * cards requiring a memory range, e.g. the i82365 PCMCIA controller. */ - if (avail->flags & IORESOURCE_MEM) { + if (avail->flags & IORESOURCE_MEM) resource_clip(avail, BIOS_ROM_BASE, BIOS_ROM_END); - - remove_e820_regions(avail); - } } diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c index 052f1d78a562..562c81a51ea0 100644 --- a/arch/x86/pci/acpi.c +++ b/arch/x86/pci/acpi.c @@ -8,6 +8,7 @@ #include #include #include +#include struct pci_root_info { struct acpi_pci_root_info common; @@ -299,6 +300,10 @@ static int pci_acpi_root_prepare_resources(struct acpi_pci_root_info *ci) int status; status = acpi_pci_probe_root_resources(ci); + + resource_list_for_each_entry(entry, &ci->resources) + remove_e820_regions(&device->dev, entry->res); + if (pci_use_crs) { resource_list_for_each_entry_safe(entry, tmp, &ci->resources) if (resource_is_pcicfg_ioport(entry->res)) From patchwork Fri Mar 4 03:51:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 12768436 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 B2368C433F5 for ; Fri, 4 Mar 2022 03:52:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237633AbiCDDxH (ORCPT ); Thu, 3 Mar 2022 22:53:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237580AbiCDDxG (ORCPT ); Thu, 3 Mar 2022 22:53:06 -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 6B6D317F6AF; Thu, 3 Mar 2022 19:52:19 -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 9B1D561AB8; Fri, 4 Mar 2022 03:52:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B743AC340F0; Fri, 4 Mar 2022 03:52:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646365938; bh=75N+jcmKzyM15eD5aiw09cfBllrrBCD9pGfIotildII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BKgomiKxjAbEBYHFRqv8oZyBrDoEinlAxLe1VGVFAwtZw0nu5Ru8XsWX7+upw4bVk hg8kU2Q6BwdOJUPPzAZWFmeTW3W7qIhgcJC1MdZTCA7RLLGeyv6BWLF7sKTiRQm+UV Kyl1OsUbExBTMwX0UgifFG9l5gv4slkKwQg9djZ4cGaNUBQxJxUWcdHrU/WpkEGw50 I7Z7RV7IBsMUra0wNZpkILMe8EEIrwNczcKXBrx0FTgZzQACc4WoYKfgALAT3gEtRq 2lqqjrZW9tY2T3x82Oz+jQ1nnVWixoqi4nNTWzbOH6hzpI3YhrQYlJn3YvO9cCe8P5 XWLUMkEBLejkQ== From: Bjorn Helgaas To: Hans de Goede , "Rafael J . Wysocki" , Borislav Petkov , "H . Peter Anvin" , Ingo Molnar Cc: Mika Westerberg , =?utf-8?q?Krzysztof_W?= =?utf-8?q?ilczy=C5=84ski?= , Myron Stowe , Juha-Pekka Heikkila , =?utf-8?q?Benoit_Gr?= =?utf-8?q?=C3=A9goire?= , Hui Wang , Kai-Heng Feng , linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Bjorn Helgaas , wse@tuxedocomputers.com Subject: [PATCH 3/3] x86/PCI: Preserve host bridge windows completely covered by E820 Date: Thu, 3 Mar 2022 21:51:11 -0600 Message-Id: <20220304035110.988712-4-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304035110.988712-1-helgaas@kernel.org> References: <20220304035110.988712-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Bjorn Helgaas Many folks have reported PCI devices not working. It could affect any device, but most reports are for Thunderbolt controllers on Lenovo Yoga and Clevo Barebone laptops and the touchpad on Lenovo IdeaPads. In every report, a region in the E820 table entirely encloses a PCI host bridge window from _CRS, and because of 4dc2287c1805 ("x86: avoid E820 regions when allocating address space"), we ignore the entire window, preventing us from assigning space to PCI devices. For example, the dmesg log [2] from bug report [1] shows: BIOS-e820: [mem 0x000000004bc50000-0x00000000cfffffff] reserved pci_bus 0000:00: root bus resource [mem 0x65400000-0xbfffffff window] pci 0000:00:15.0: BAR 0: no space for [mem size 0x00001000 64bit] The efi=debug dmesg log [3] from the same report shows the EFI memory map entries that created the E820 map: efi: mem47: [Reserved | |WB|WT|WC|UC] range=[0x4bc50000-0x5fffffff] efi: mem48: [Reserved | |WB| | |UC] range=[0x60000000-0x60ffffff] efi: mem49: [Reserved | | | | | ] range=[0x61000000-0x653fffff] efi: mem50: [MMIO |RUN| | | |UC] range=[0x65400000-0xcfffffff] 4dc2287c1805 ("x86: avoid E820 regions when allocating address space") works around issues where _CRS contains non-window address space that can't be used for PCI devices. It does this by removing E820 regions from host bridge windows. But in these reports, the E820 region covers the entire window, so 4dc2287c1805 makes it completely unusable. Per UEFI v2.8, sec 7.2, the EfiMemoryMappedIO type means: Used by system firmware to request that a memory-mapped IO region be mapped by the OS to a virtual address so it can be accessed by EFI runtime services. A host bridge window is definitely a memory-mapped IO region, and EFI runtime services may need to access it, so I don't think we can argue that this is a firmware defect. Instead, change the 4dc2287c1805 strategy so it only removes E820 regions when they overlap *part* of a host bridge window on the assumption that a partial overlap is really register space, not part of the window proper. If an E820 region covers the entire window from _CRS, assume the _CRS window is correct and do nothing. [1] https://bugzilla.redhat.com/show_bug.cgi?id=1868899 [2] https://bugzilla.redhat.com/attachment.cgi?id=1711424 [3] https://bugzilla.redhat.com/attachment.cgi?id=1861407 BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=206459 BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=214259 BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1868899 BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1871793 BugLink: https://bugs.launchpad.net/bugs/1878279 BugLink: https://bugs.launchpad.net/bugs/1931715 BugLink: https://bugs.launchpad.net/bugs/1932069 BugLink: https://bugs.launchpad.net/bugs/1921649 Fixes: 4dc2287c1805 ("x86: avoid E820 regions when allocating address space") Link: https://lore.kernel.org/r/20220228105259.230903-1-hdegoede@redhat.com Based-on-patch-by: Hans de Goede Reported-by: Benoit Grégoire # BZ 206459 Reported-by: wse@tuxedocomputers.com # BZ 214259 Signed-off-by: Bjorn Helgaas Acked-by: Rafael J. Wysocki Tested-by: Matt Hansen <2lprbe78@duck.com> --- arch/x86/kernel/resource.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/kernel/resource.c b/arch/x86/kernel/resource.c index 7378ea146976..405f0af53e3d 100644 --- a/arch/x86/kernel/resource.c +++ b/arch/x86/kernel/resource.c @@ -39,6 +39,17 @@ void remove_e820_regions(struct device *dev, struct resource *avail) e820_start = entry->addr; e820_end = entry->addr + entry->size - 1; + /* + * If an E820 entry covers just part of the resource, we + * assume E820 is telling us about something like host + * bridge register space that is unavailable for PCI + * devices. But if it covers the *entire* resource, it's + * more likely just telling us that this is MMIO space, and + * that doesn't need to be removed. + */ + if (e820_start <= avail->start && avail->end <= e820_end) + continue; + resource_clip(avail, e820_start, e820_end); if (orig.start != avail->start || orig.end != avail->end) { dev_info(dev, "clipped %pR to %pR for e820 entry [mem %#010Lx-%#010Lx]\n",