Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8493055ybi; Thu, 6 Jun 2019 13:19:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqz8f85qt1NxjOuAjjkvraBInbNi4Wn5gPKoPnCGyM8at75PSQJZwRTvYxJWaHUiOYMNm6gg X-Received: by 2002:a17:90a:ae02:: with SMTP id t2mr1681142pjq.41.1559852399122; Thu, 06 Jun 2019 13:19:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559852399; cv=none; d=google.com; s=arc-20160816; b=yRzlCegK6HuL2DdcdQRk97pWFnLCoTHB6tAw1DmBhn+scrf1+jcUvpHVRQIPald3fG 1U6TMmUMqZ5E3DnKuw856JAIsON+r4HNyy+EesZQRU4V+JVgg3Mj1Hgbk7W0KDj95Ado G25/pOJ91LVDVHdH7NW+mFIhOfspuIDmQlofB5/X8yTP0kfVRVKNYi4w7TFszaExWk74 7ym0NVlgTVzDhsueIfDclcdTkdMewIvSsumz2OdPKmc2tDDWxj7W57xdwVUNVEy2/hop NpXHnXkBWMzi05m8KIXakbrwZ3edhDSWUaWrGXwCtsP34u3Ugm+Bxj2paaLF3acVFzHa ux8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=B9H4CNnwxmfVdYMXYG4y49g0B29mcFnXNGsdvhYtCvA=; b=cySdLh1WE6TeRXsY0PPKey13TcXCUThwU/jy4oaWE0ZopkU0X38SpQ1MReierKvz2O b7ONpjq4f4+VuApBzR/L+s9FQkhdUpVvqI27kuolTaxcz/b1tdVrZ3MerBDVBudNgdSU sp51y0mQD5lTwhdh/EAJpPZ3wQt8Cv8/KWrEZwnKGpEK4zKl+ZfHgwT0TxXtU8MkSDYZ BKsRjpI9AhQ5zEK2rwHtNEugaTb/nSZHZsavuCy0eHLW9zVc6E8qlL22zS/jaEPOcHml 8ZzIirasLGK7KFwCua3+3hEH6M/tJ8Z/BY3wuc8qk0qjOdZ1oovLA5sS0VjyCgmgm/tv wQWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019051801 header.b=TuvpXNtL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31si47996plz.290.2019.06.06.13.19.42; Thu, 06 Jun 2019 13:19:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@zytor.com header.s=2019051801 header.b=TuvpXNtL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729315AbfFFTXc (ORCPT + 99 others); Thu, 6 Jun 2019 15:23:32 -0400 Received: from terminus.zytor.com ([198.137.202.136]:50801 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729053AbfFFTXb (ORCPT ); Thu, 6 Jun 2019 15:23:31 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x56JMDPp2102928 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 6 Jun 2019 12:22:14 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x56JMDPp2102928 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019051801; t=1559848934; bh=B9H4CNnwxmfVdYMXYG4y49g0B29mcFnXNGsdvhYtCvA=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=TuvpXNtL/hgp3bfk7h1qNIBbqYctJ2aEmY/KydNewBwwmHsc/7lp7Ofqf1A83rBOY kKr5MiK01i/77FH4c6pTj9fH/PkQ/6Qokh7fGOSOKY0oqcgL2ISzvda9AcPjdE684I iTVZ7qlpVcMgUz7jVfRdPL+dlDbj6RZCpQUiiGAlcynlp3CUffKWgGuzQqWhUqRPVj 272Dslgc8YCADDUkqPGCb0yJFN+6g19eybwNVhAhwhTQvEMGP/Re7SdFw5e3G8fdGu QdyRig2jPIIwsjr5K5QlJWqT/e/A6pMA2snqbJdTR6qzzblliJ5hQ0l++SJhhNIoNF 1YgfSPG9Cm5Pw== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x56JMCWL2102925; Thu, 6 Jun 2019 12:22:12 -0700 Date: Thu, 6 Jun 2019 12:22:12 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Kairui Song Message-ID: Cc: mingo@redhat.com, lijiang@redhat.com, penguin-kernel@I-love.SAKURA.ne.jp, dirk.vandermerwe@netronome.com, x86@kernel.org, bhe@redhat.com, bp@suse.de, hpa@zytor.com, tglx@linutronix.de, kasong@redhat.com, linux-kernel@vger.kernel.org, kirill.shutemov@linux.intel.com, mingo@kernel.org Reply-To: kirill.shutemov@linux.intel.com, lijiang@redhat.com, mingo@redhat.com, linux-kernel@vger.kernel.org, kasong@redhat.com, bp@suse.de, tglx@linutronix.de, hpa@zytor.com, mingo@kernel.org, bhe@redhat.com, dirk.vandermerwe@netronome.com, x86@kernel.org, penguin-kernel@I-love.SAKURA.ne.jp In-Reply-To: <20190429002318.GA25400@MiWiFi-R3L-srv> References: <20190429002318.GA25400@MiWiFi-R3L-srv> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/boot] x86/kexec: Add the EFI system tables and ACPI tables to the ident map Git-Commit-ID: 6bbeb276b71f06c5267bfd154629b1bec82e7136 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-3.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 6bbeb276b71f06c5267bfd154629b1bec82e7136 Gitweb: https://git.kernel.org/tip/6bbeb276b71f06c5267bfd154629b1bec82e7136 Author: Kairui Song AuthorDate: Mon, 29 Apr 2019 08:23:18 +0800 Committer: Borislav Petkov CommitDate: Thu, 6 Jun 2019 20:13:48 +0200 x86/kexec: Add the EFI system tables and ACPI tables to the ident map Currently, only the whole physical memory is identity-mapped for the kexec kernel and the regions reserved by firmware are ignored. However, the recent addition of RSDP parsing in the decompression stage and especially: 33f0df8d843d ("x86/boot: Search for RSDP in the EFI tables") which tries to access EFI system tables and to dig out the RDSP address from there, becomes a problem because in certain configurations, they might not be mapped in the kexec'ed kernel's address space. What is more, this problem doesn't appear on all systems because the kexec kernel uses gigabyte pages to build the identity mapping. And the EFI system tables and ACPI tables can, depending on the system configuration, end up being mapped as part of all physical memory, if they share the same 1 GB area with the physical memory. Therefore, make sure they're always mapped. [ bp: productize half-baked patch: - rewrite commit message. - correct the map_acpi_tables() function name in the !ACPI case. ] Signed-off-by: Kairui Song Signed-off-by: Baoquan He Signed-off-by: Borislav Petkov Tested-by: Dirk van der Merwe Cc: dyoung@redhat.com Cc: fanc.fnst@cn.fujitsu.com Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: j-nomura@ce.jp.nec.com Cc: kexec@lists.infradead.org Cc: "Kirill A. Shutemov" Cc: Lianbo Jiang Cc: Tetsuo Handa Cc: Thomas Gleixner Cc: x86-ml Link: https://lkml.kernel.org/r/20190429002318.GA25400@MiWiFi-R3L-srv --- arch/x86/kernel/machine_kexec_64.c | 75 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c index ceba408ea982..3c77bdf7b32a 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -29,6 +30,43 @@ #include #include +#ifdef CONFIG_ACPI +/* + * Used while adding mapping for ACPI tables. + * Can be reused when other iomem regions need be mapped + */ +struct init_pgtable_data { + struct x86_mapping_info *info; + pgd_t *level4p; +}; + +static int mem_region_callback(struct resource *res, void *arg) +{ + struct init_pgtable_data *data = arg; + unsigned long mstart, mend; + + mstart = res->start; + mend = mstart + resource_size(res) - 1; + + return kernel_ident_mapping_init(data->info, data->level4p, mstart, mend); +} + +static int +map_acpi_tables(struct x86_mapping_info *info, pgd_t *level4p) +{ + unsigned long flags = IORESOURCE_MEM | IORESOURCE_BUSY; + struct init_pgtable_data data; + + data.info = info; + data.level4p = level4p; + flags = IORESOURCE_MEM | IORESOURCE_BUSY; + return walk_iomem_res_desc(IORES_DESC_ACPI_TABLES, flags, 0, -1, + &data, mem_region_callback); +} +#else +static int map_acpi_tables(struct x86_mapping_info *info, pgd_t *level4p) { return 0; } +#endif + #ifdef CONFIG_KEXEC_FILE const struct kexec_file_ops * const kexec_file_loaders[] = { &kexec_bzImage64_ops, @@ -36,6 +74,31 @@ const struct kexec_file_ops * const kexec_file_loaders[] = { }; #endif +static int +map_efi_systab(struct x86_mapping_info *info, pgd_t *level4p) +{ +#ifdef CONFIG_EFI + unsigned long mstart, mend; + + if (!efi_enabled(EFI_BOOT)) + return 0; + + mstart = (boot_params.efi_info.efi_systab | + ((u64)boot_params.efi_info.efi_systab_hi<<32)); + + if (efi_enabled(EFI_64BIT)) + mend = mstart + sizeof(efi_system_table_64_t); + else + mend = mstart + sizeof(efi_system_table_32_t); + + if (!mstart) + return 0; + + return kernel_ident_mapping_init(info, level4p, mstart, mend); +#endif + return 0; +} + static void free_transition_pgtable(struct kimage *image) { free_page((unsigned long)image->arch.p4d); @@ -159,6 +222,18 @@ static int init_pgtable(struct kimage *image, unsigned long start_pgtable) return result; } + /* + * Prepare EFI systab and ACPI tables for kexec kernel since they are + * not covered by pfn_mapped. + */ + result = map_efi_systab(&info, level4p); + if (result) + return result; + + result = map_acpi_tables(&info, level4p); + if (result) + return result; + return init_transition_pgtable(image, level4p); }