From patchwork Tue Jan 10 18:02:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 13095446 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 102BFC61DB3 for ; Tue, 10 Jan 2023 18:05:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233719AbjAJSFY (ORCPT ); Tue, 10 Jan 2023 13:05:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238763AbjAJSEt (ORCPT ); Tue, 10 Jan 2023 13:04:49 -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 37A8085C89; Tue, 10 Jan 2023 10:02:57 -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 E340AB81903; Tue, 10 Jan 2023 18:02:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E8EAC433EF; Tue, 10 Jan 2023 18:02:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673373774; bh=YIJe4Sbi90ZM5MZspqHWq3/zFAVIJE3Xh1CUKfmBVlA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JU9RwYbn8DPJol5KQGf8epu5BTm/Kx3sREhzcYfXoT/QNOm2kNElrMgQKTRQq9BFA uC/u812UPJlCmqPUGWctbVQFdRgZOwHn59pEQYeln4Ho8WbFBLu+L0j+NRHJ7JbgoH 5NIIJ0Vpe7YV6HXXh16JW/F/QBg82oZwcCpNguxPm7i/yrvu1o4mJteZ7E8nNrdr8b BeeIBTpq5a+VM0F3Dv79z+MEMGOnHWQkqbVhexd8NdtqsFN1d/vl6n/9aCVpsmfcod BKoQc3gXUIMJt7P0fbVPJkw0XibgNsdSiaAyR6lOCk37K08fs2YmYXjJgvM2QC0Wg1 9kYi8sKlrbYug== From: Bjorn Helgaas To: linux-pci@vger.kernel.org Cc: Dan J Williams , Kan Liang , Tony Luck , David E Box , Yunying Sun , Dave Jiang , Mika Westerberg , Giovanni Cabiddu , Herbert Xu , Hans de Goede , Florent DELAHAYE , Konrad J Hambrick , Matt Hansen <2lprbe78@duck.com>, Nicholas Johnson , =?utf-8?q?Be?= =?utf-8?q?noit_Gr=C3=A9goire?= , Werner Sembach , mumblingdrunkard@protonmail.com, linux-kernel@vger.kernel.org, Bjorn Helgaas Subject: [PATCH 1/2] x86/pci: Simplify is_mmconf_reserved() messages Date: Tue, 10 Jan 2023 12:02:42 -0600 Message-Id: <20230110180243.1590045-2-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230110180243.1590045-1-helgaas@kernel.org> References: <20230110180243.1590045-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas is_mmconf_reserved() takes a "with_e820" parameter that only determines the message logged if it finds the MMCONFIG region is reserved. Pass the message directly, which will simplify a future patch that adds a new way of looking for that reservation. No functional change intended. Signed-off-by: Bjorn Helgaas Reviewed-by: Dan Williams --- arch/x86/pci/mmconfig-shared.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/x86/pci/mmconfig-shared.c b/arch/x86/pci/mmconfig-shared.c index 758cbfe55daa..cd16bef5f2d9 100644 --- a/arch/x86/pci/mmconfig-shared.c +++ b/arch/x86/pci/mmconfig-shared.c @@ -446,13 +446,12 @@ typedef bool (*check_reserved_t)(u64 start, u64 end, enum e820_type type); static bool __ref is_mmconf_reserved(check_reserved_t is_reserved, struct pci_mmcfg_region *cfg, - struct device *dev, int with_e820) + struct device *dev, char *method) { u64 addr = cfg->res.start; u64 size = resource_size(&cfg->res); u64 old_size = size; int num_buses; - char *method = with_e820 ? "E820" : "ACPI motherboard resources"; while (!is_reserved(addr, addr + size, E820_TYPE_RESERVED)) { size >>= 1; @@ -464,10 +463,10 @@ static bool __ref is_mmconf_reserved(check_reserved_t is_reserved, return false; if (dev) - dev_info(dev, "MMCONFIG at %pR reserved in %s\n", + dev_info(dev, "MMCONFIG at %pR reserved as %s\n", &cfg->res, method); else - pr_info(PREFIX "MMCONFIG at %pR reserved in %s\n", + pr_info(PREFIX "MMCONFIG at %pR reserved as %s\n", &cfg->res, method); if (old_size != size) { @@ -500,7 +499,8 @@ static bool __ref pci_mmcfg_check_reserved(struct device *dev, struct pci_mmcfg_region *cfg, int early) { if (!early && !acpi_disabled) { - if (is_mmconf_reserved(is_acpi_reserved, cfg, dev, 0)) + if (is_mmconf_reserved(is_acpi_reserved, cfg, dev, + "ACPI motherboard resource")) return true; if (dev) @@ -527,7 +527,8 @@ pci_mmcfg_check_reserved(struct device *dev, struct pci_mmcfg_region *cfg, int e /* Don't try to do this check unless configuration type 1 is available. how about type 2 ?*/ if (raw_pci_ops) - return is_mmconf_reserved(e820__mapped_all, cfg, dev, 1); + return is_mmconf_reserved(e820__mapped_all, cfg, dev, + "E820 entry"); return false; } From patchwork Tue Jan 10 18:02:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 13095447 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 61270C678D7 for ; Tue, 10 Jan 2023 18:05:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235296AbjAJSF0 (ORCPT ); Tue, 10 Jan 2023 13:05:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233936AbjAJSEu (ORCPT ); Tue, 10 Jan 2023 13:04:50 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05FC984BCB; Tue, 10 Jan 2023 10:02:59 -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 A3AAEB818ED; Tue, 10 Jan 2023 18:02:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CBDAC433D2; Tue, 10 Jan 2023 18:02:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673373776; bh=LPpzoeHYi2j3MioTZ/ZfEBoc1LHscwPMxPEaHTQLHMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=svSLJsikLXRw4iRJaQTBGxNd09rSFTSsUnFxvU07Za8WHGA5pvYTYNcNBbm6fAKmN 4ePzRBqiU5Ga/gMxmjQjdR4QspKM4FGKt+7fkjOtIGujd8gEupF5vKE8cHxXYovLwm goXHxb4wXTfR0JLp86mzYYcVbFcs/Wbd5Nd0/JuAl3LgukH3uuC5WROTQeOCORrg53 Ls4SiLhzNzjhRp0pdCTFCLWugBUnPgsUz8Pe08/OWakvNjvOZnPK2+aTdWwDKd9hq8 OqBsWU8k821XL46zmo7x4n+KjBt3nTSnHbpPmbp1Xo7F/UPGRJrqawIx7rBLd8eaPv upT9zKgoj0iww== From: Bjorn Helgaas To: linux-pci@vger.kernel.org Cc: Dan J Williams , Kan Liang , Tony Luck , David E Box , Yunying Sun , Dave Jiang , Mika Westerberg , Giovanni Cabiddu , Herbert Xu , Hans de Goede , Florent DELAHAYE , Konrad J Hambrick , Matt Hansen <2lprbe78@duck.com>, Nicholas Johnson , =?utf-8?q?Be?= =?utf-8?q?noit_Gr=C3=A9goire?= , Werner Sembach , mumblingdrunkard@protonmail.com, linux-kernel@vger.kernel.org, Bjorn Helgaas Subject: [PATCH 2/2] x86/pci: Treat EfiMemoryMappedIO as reservation of ECAM space Date: Tue, 10 Jan 2023 12:02:43 -0600 Message-Id: <20230110180243.1590045-3-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230110180243.1590045-1-helgaas@kernel.org> References: <20230110180243.1590045-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas Normally we reject ECAM space unless it is reported as reserved in the E820 table or via a PNP0C02 _CRS method (PCI Firmware, r3.3, sec 4.1.2). This means PCI extended config space (offsets 0x100-0xfff) may not be accessible. Some firmware doesn't report ECAM space via PNP0C02 _CRS methods, but does mention it as an EfiMemoryMappedIO region via EFI GetMemoryMap(), which is normally converted to an E820 entry by a bootloader or EFI stub. 07eab0901ede ("efi/x86: Remove EfiMemoryMappedIO from E820 map"), removes E820 entries that correspond to EfiMemoryMappedIO regions because some other firmware uses EfiMemoryMappedIO for PCI host bridge windows, and the E820 entries prevent Linux from allocating BAR space for hot-added devices. Allow use of ECAM for extended config space when the region is covered by an EfiMemoryMappedIO region, even if it's not included in E820 or PNP0C02 _CRS. Reported by Kan Liang, Tony Luck, and Giovanni Cabiddu. Fixes: 07eab0901ede ("efi/x86: Remove EfiMemoryMappedIO from E820 map") Link: https://lore.kernel.org/r/ac2693d8-8ba3-72e0-5b66-b3ae008d539d@linux.intel.com Reported-by: Kan Liang Reported-by: Tony Luck Reported-by: Giovanni Cabiddu Signed-off-by: Bjorn Helgaas Reviewed-by: Rafael J. Wysocki Reviewed-by: Dan Williams --- arch/x86/pci/mmconfig-shared.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/arch/x86/pci/mmconfig-shared.c b/arch/x86/pci/mmconfig-shared.c index cd16bef5f2d9..da4b6e8e9df0 100644 --- a/arch/x86/pci/mmconfig-shared.c +++ b/arch/x86/pci/mmconfig-shared.c @@ -12,6 +12,7 @@ */ #include +#include #include #include #include @@ -442,6 +443,32 @@ static bool is_acpi_reserved(u64 start, u64 end, enum e820_type not_used) return mcfg_res.flags; } +static bool is_efi_mmio(u64 start, u64 end, enum e820_type not_used) +{ +#ifdef CONFIG_EFI + efi_memory_desc_t *md; + u64 size, mmio_start, mmio_end; + + for_each_efi_memory_desc(md) { + if (md->type == EFI_MEMORY_MAPPED_IO) { + size = md->num_pages << EFI_PAGE_SHIFT; + mmio_start = md->phys_addr; + mmio_end = mmio_start + size; + + /* + * N.B. Caller supplies (start, start + size), + * so to match, mmio_end is the first address + * *past* the EFI_MEMORY_MAPPED_IO area. + */ + if (mmio_start <= start && end <= mmio_end) + return true; + } + } +#endif + + return false; +} + typedef bool (*check_reserved_t)(u64 start, u64 end, enum e820_type type); static bool __ref is_mmconf_reserved(check_reserved_t is_reserved, @@ -513,6 +540,10 @@ pci_mmcfg_check_reserved(struct device *dev, struct pci_mmcfg_region *cfg, int e "MMCONFIG at %pR not reserved in " "ACPI motherboard resources\n", &cfg->res); + + if (is_mmconf_reserved(is_efi_mmio, cfg, dev, + "EfiMemoryMappedIO")) + return true; } /*