Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp8308151rwl; Tue, 10 Jan 2023 11:39:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXss0ciQ/z/a0WdJ9iij+D4yMzGNTGZPFiyWS5OPX5POdze87sbQ+Y19upSQjO8PWW772cqH X-Received: by 2002:a17:902:edc3:b0:189:5ef4:6ae9 with SMTP id q3-20020a170902edc300b001895ef46ae9mr65887502plk.45.1673379571823; Tue, 10 Jan 2023 11:39:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673379571; cv=none; d=google.com; s=arc-20160816; b=UcSkj4nboKCRNKKM4PZnNX074Xi7Uj82t75BKEovSPrqoeTIu2ojGy3YMyucKMPjaC J0jEjE5g5y9yZBO37RYP658+MnKcfvHbT0snYNoyLSGZrUCr7j+j9YjoFjMpQkks4Rl+ pC5fSbfhI22Iz6ST0TE0EI/aAIBQCMqTvqYmnKjaGqKgj704wB7Pro58/5CiiCdZtm5l 6AvghpASwwG5uRl/XNX8v6DmDtKqEJsofG7W+i3e+HzlanF2JfhX0h0hRIaAViCUMctH EL9Llul6CQmRcZF66LFzYzPkDTjsOHVxjxLrTKPt9Jl0lah0gBeIgcZvf0XWhe49Vqmq NerQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=F7XquMRGiH5U2D0Ar+7qtKC98rbPHKcuz88U+xCtEoM=; b=KnWOkz2yFboBWOGoTWogx8eHK3upwVsWcDdhqdELEB72EoSGyLAWkNvGb202cnApIt PMdbkoQGMdAdNr+cQmNCuruUpncC+Id8PqDHl/iIFGppfs8msSGSced7w8iMD1B/dOZr aGr1NWbxtUm7847VqXFN6YWPoREF5/WowUE2rgwyUnC5SUQxiygOlVJIz51DEB0jUCQb z9dSqk2B5ebfSFTSpguOwcylQbmbzXXR5TvEQaOoFyR3LAuf8JXuoe9x5UgyK00HQKnf jNRf8EqXggdjZ5jm4f3KRtVb4czeJL7aEPgUt6HBcwSHJemM15kqoVN7DU1Mpb3Iwbkf o+Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BvzSqmM5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b17-20020a170902e95100b001926a7725e0si11588062pll.509.2023.01.10.11.39.24; Tue, 10 Jan 2023 11:39:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BvzSqmM5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231284AbjAJTav (ORCPT + 53 others); Tue, 10 Jan 2023 14:30:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbjAJTar (ORCPT ); Tue, 10 Jan 2023 14:30:47 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ECBCBC87; Tue, 10 Jan 2023 11:30:46 -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 A2A1361866; Tue, 10 Jan 2023 19:30:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D55A5C433D2; Tue, 10 Jan 2023 19:30:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673379045; bh=Z3VK4XjQQq+KEw1B3BXi5i7EA2vHGCfGtc50BK1cESg=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=BvzSqmM5VG/wtFQGgC8wSJpNGj6cgw68m0jQu72oiRnFxq9RH2qpedGzdleXXD71K bTBsYQxKBW9cIYMLJ5hW86luyWHFps5e033Rxv0V1np30bM6iPxMbEnOq3LZxcznoz BznUmmc9p9ltWZ/lTU/zDAJRJ7hEXXij4ac700Pigklzl426hos0/SURV2s3uNu2En JgVtQUOOkW+m5nkU1gJE61D6/3cQvy0UNYfSexkGczt7yic1BOCQ00rh6NRFweHxNW Z9ntIpgGQrsKhbJ7xwEtjqZfnJMi3Dzjj+lEcHbFdGHXsDUCmcXKyd6OnHFsgb3UXa AZBub3gX7p4lg== Date: Tue, 10 Jan 2023 13:30:43 -0600 From: Bjorn Helgaas To: Dan Williams Cc: linux-pci@vger.kernel.org, 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 , Benoit =?iso-8859-1?Q?Gr=E9goire?= , Werner Sembach , mumblingdrunkard@protonmail.com, linux-kernel@vger.kernel.org, Bjorn Helgaas Subject: Re: [PATCH 2/2] x86/pci: Treat EfiMemoryMappedIO as reservation of ECAM space Message-ID: <20230110193043.GA1603645@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <63bdae72740db_5178e294bd@dwillia2-xfh.jf.intel.com.notmuch> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 10, 2023 at 10:29:06AM -0800, Dan Williams wrote: > Bjorn Helgaas wrote: > > 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 > > --- > > 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 > > Perhaps the following trick (compile tested), but either way: > > Reviewed-by: Dan Williams That's a great trick, and I wish I'd thought of it. I have some follow-on patches I'm considering for v6.3, so in the interest of streamlining the path of this one to v6.2-rc4, I think I'll wait on this until v6.3. > diff --git a/arch/x86/pci/mmconfig-shared.c b/arch/x86/pci/mmconfig-shared.c > index da4b6e8e9df0..ae95d1b073c6 100644 > --- a/arch/x86/pci/mmconfig-shared.c > +++ b/arch/x86/pci/mmconfig-shared.c > @@ -445,7 +445,6 @@ static bool is_acpi_reserved(u64 start, u64 end, enum e820_type not_used) > > 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; > > @@ -464,7 +463,6 @@ static bool is_efi_mmio(u64 start, u64 end, enum e820_type not_used) > return true; > } > } > -#endif > > return false; > } > diff --git a/include/linux/efi.h b/include/linux/efi.h > index 4b27519143f5..3ab0c255b791 100644 > --- a/include/linux/efi.h > +++ b/include/linux/efi.h > @@ -790,8 +790,12 @@ extern int efi_memattr_apply_permissions(struct mm_struct *mm, > * > * Once the loop finishes @md must not be accessed. > */ > +#ifdef CONFIG_EFI > #define for_each_efi_memory_desc(md) \ > for_each_efi_memory_desc_in_map(&efi.memmap, md) > +#else > +#define for_each_efi_memory_desc(md) for (; 0;) > +#endif > > /* > * Format an EFI memory descriptor's type and attributes to a user-provided