From patchwork Sat Nov 11 08:37:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saurabh Singh Sengar X-Patchwork-Id: 164105 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp117971vqg; Sat, 11 Nov 2023 00:38:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IFx1I/zeRJgmCeaj8fz4sDvfM0N6kTuDeg5rElUCvdMA2Ub1ILO7OmWPuIcxaDvvprebMRY X-Received: by 2002:a05:6e02:1c83:b0:359:6af2:67bb with SMTP id w3-20020a056e021c8300b003596af267bbmr2315203ill.23.1699691888350; Sat, 11 Nov 2023 00:38:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699691888; cv=none; d=google.com; s=arc-20160816; b=n4Fg1pm/fGkpfLguykUoPC9SGOVSnpgOKt7Xrsr9bL62nY5nfwF6psp949361HCWd3 CNU2xTOyP9G3K4NGesVJL24+zuoXoGGw/UeL2SBSHt0I2MRU2ontLAYk0I8nUVdzLR/i 8Vy4IYbIVnwyVK7cKOhJVZmsl3AIka56ZSkC8/rpig96nI1aZ+J9SaaUQ1IkAHne00so aLogQz60naqNoVvGLnsdeGv3CmP7SfYVAlKNnwmTNW1nhyLcdZ3knO7N/poyfvfwe/X4 FPaSHRIVItiMJqUvwlwfKohC/VKdhpoe2K6MqQMQT0iMFtHMBgO71Zs8T6NZZWvpRPli Ai1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=zbDWAPIzznRNV4elr6XvwFsGYrHF7a5O7SZKO+Ys2fU=; fh=Q90LcKQU9isaEX5E6EGA77zJrhNMo5wuUyqVhBPa5Uw=; b=hhMmO10IIUOqAdmE6EOWgJzG2xrtE7JAHdGM8yeACg5HrNlCF47rXsvKTZFyhcUcYf dYujv/7FWKFsH8I01h4vCmWwpJtpsHImCbj49tr7LORK9aIuCSiJC0GYmOONIpxaqBIA Lir5jUlS/scjS/g5PQ7z8TI3VtuW2L+cTCWfZoSMkxn9/EAqa3R33uBSFY3bEh6vUVSS 3DbjmnPyMjTCN8mtDkVGaudJwNzHhCQcNEpVZ4OgiOEyHFaFukSLjuaBUmEc37BL9vOr EzfoA4ap2U0lq4Nc2XPIpMIKYLKL+DXBAuBfTQCA7hIIjJ/VS75KCDKAxRgLH+IHiQ96 VL4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=tNT+XvlH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id l12-20020a17090270cc00b001c566ea86eesi1223008plt.177.2023.11.11.00.38.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Nov 2023 00:38:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=tNT+XvlH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 6F90A81B94CB; Sat, 11 Nov 2023 00:38:07 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230274AbjKKIh4 (ORCPT + 29 others); Sat, 11 Nov 2023 03:37:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229881AbjKKIhz (ORCPT ); Sat, 11 Nov 2023 03:37:55 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8FED33C3C; Sat, 11 Nov 2023 00:37:52 -0800 (PST) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 0C4FD20B74C0; Sat, 11 Nov 2023 00:37:52 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0C4FD20B74C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1699691872; bh=zbDWAPIzznRNV4elr6XvwFsGYrHF7a5O7SZKO+Ys2fU=; h=From:To:Cc:Subject:Date:From; b=tNT+XvlHT2BC8YzvppYf4rY9JG7lwqdImsQ8lCLh+JCNuJzwIvJ37pj8C15bMhAhJ s07GqOoQve+WmQi4emGwWsCQNEUXxmD6CXX9yCHmWSbbl8scnpXwS8Dr7LQAlFCB6w cHgj6kdSUB988nnsSS2kMp1jw6Kf+80XHrLDcQRc= From: Saurabh Sengar To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ssengar@microsoft.com Subject: [PATCH v2] x86/hyperv: Fix the detection of E820_TYPE_PRAM in a Gen2 VM Date: Sat, 11 Nov 2023 00:37:47 -0800 Message-Id: <1699691867-9827-1-git-send-email-ssengar@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-17.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 11 Nov 2023 00:38:07 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782256121402194352 X-GMAIL-MSGID: 1782256121402194352 A Gen2 VM doesn't support legacy PCI/PCIe, so both raw_pci_ops and raw_pci_ext_ops are NULL, and pci_subsys_init() -> pcibios_init() doesn't call pcibios_resource_survey() -> e820__reserve_resources_late(); as a result, any emulated persistent memory of E820_TYPE_PRAM (12) via the kernel parameter memmap=nn[KMG]!ss is not added into iomem_resource and hence can't be detected by register_e820_pmem(). Fix this by directly calling e820__reserve_resources_late() in hv_pci_init(), which is called from arch_initcall(pci_arch_init). It's ok to move a Gen2 VM's e820__reserve_resources_late() from subsys_initcall(pci_subsys_init) to arch_initcall(pci_arch_init) because the code in-between doesn't depend on the E820 resources. e820__reserve_resources_late() depends on e820__reserve_resources(), which has been called earlier from setup_arch(). For a Gen-2 VM, the new hv_pci_init() also adds any memory of E820_TYPE_PMEM (7) into iomem_resource, and acpi_nfit_register_region() -> acpi_nfit_insert_resource() -> region_intersects() returns REGION_INTERSECTS, so the memory of E820_TYPE_PMEM won't get added twice. Changed the local variable "int gen2vm" to "bool gen2vm". Signed-off-by: Saurabh Sengar Signed-off-by: Dexuan Cui --- [V2] Rebase to latest arch/x86/hyperv/hv_init.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 21556ad87f4b..8f3a4d16bb79 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -286,15 +287,31 @@ static int hv_cpu_die(unsigned int cpu) static int __init hv_pci_init(void) { - int gen2vm = efi_enabled(EFI_BOOT); + bool gen2vm = efi_enabled(EFI_BOOT); /* - * For Generation-2 VM, we exit from pci_arch_init() by returning 0. - * The purpose is to suppress the harmless warning: + * A Generation-2 VM doesn't support legacy PCI/PCIe, so both + * raw_pci_ops and raw_pci_ext_ops are NULL, and pci_subsys_init() -> + * pcibios_init() doesn't call pcibios_resource_survey() -> + * e820__reserve_resources_late(); as a result, any emulated persistent + * memory of E820_TYPE_PRAM (12) via the kernel parameter + * memmap=nn[KMG]!ss is not added into iomem_resource and hence can't be + * detected by register_e820_pmem(). Fix this by directly calling + * e820__reserve_resources_late() here: e820__reserve_resources_late() + * depends on e820__reserve_resources(), which has been called earlier + * from setup_arch(). Note: e820__reserve_resources_late() also adds + * any memory of E820_TYPE_PMEM (7) into iomem_resource, and + * acpi_nfit_register_region() -> acpi_nfit_insert_resource() -> + * region_intersects() returns REGION_INTERSECTS, so the memory of + * E820_TYPE_PMEM won't get added twice. + * + * We return 0 here so that pci_arch_init() won't print the warning: * "PCI: Fatal: No config space access function found" */ - if (gen2vm) + if (gen2vm) { + e820__reserve_resources_late(); return 0; + } /* For Generation-1 VM, we'll proceed in pci_arch_init(). */ return 1;