LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: tip-bot for Kairui Song <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
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
Subject: [tip:x86/boot] x86/kexec: Add the EFI system tables and ACPI tables to the ident map
Date: Thu, 6 Jun 2019 12:22:12 -0700	[thread overview]
Message-ID: <tip-6bbeb276b71f06c5267bfd154629b1bec82e7136@git.kernel.org> (raw)
In-Reply-To: <20190429002318.GA25400@MiWiFi-R3L-srv>

Commit-ID:  6bbeb276b71f06c5267bfd154629b1bec82e7136
Gitweb:     https://git.kernel.org/tip/6bbeb276b71f06c5267bfd154629b1bec82e7136
Author:     Kairui Song <kasong@redhat.com>
AuthorDate: Mon, 29 Apr 2019 08:23:18 +0800
Committer:  Borislav Petkov <bp@suse.de>
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 <kasong@redhat.com>
Signed-off-by: Baoquan He <bhe@redhat.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Tested-by: Dirk van der Merwe <dirk.vandermerwe@netronome.com>
Cc: dyoung@redhat.com
Cc: fanc.fnst@cn.fujitsu.com
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: j-nomura@ce.jp.nec.com
Cc: kexec@lists.infradead.org
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Lianbo Jiang <lijiang@redhat.com>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: x86-ml <x86@kernel.org>
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 <linux/io.h>
 #include <linux/suspend.h>
 #include <linux/vmalloc.h>
+#include <linux/efi.h>
 
 #include <asm/init.h>
 #include <asm/pgtable.h>
@@ -29,6 +30,43 @@
 #include <asm/setup.h>
 #include <asm/set_memory.h>
 
+#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);
 }
 

  parent reply	other threads:[~2019-06-06 19:26 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-24  9:29 [PATCH v5 0/2] x86/boot: Use efi_setup_data for searching RSDP on kexec-ed kernel Baoquan He
2019-04-24  9:29 ` [PATCH v5 1/2] x86/kexec: Build identity mapping for EFI systab and ACPI tables Baoquan He
2019-04-27 16:11   ` Borislav Petkov
2019-04-28  5:41     ` Baoquan He
2019-04-29 12:50       ` Borislav Petkov
2019-04-29  0:23   ` [PATCH v6 " Baoquan He
2019-04-29 13:55     ` Borislav Petkov
2019-04-29 14:16       ` Baoquan He
2019-05-13  1:43       ` Baoquan He
2019-05-13  7:07         ` Borislav Petkov
2019-05-13  7:32           ` Baoquan He
2019-05-13  7:50             ` Borislav Petkov
2019-05-13  8:02               ` Baoquan He
2019-05-15  5:17                 ` Junichi Nomura
2019-05-15  6:58                   ` Borislav Petkov
2019-05-15  7:09                     ` Junichi Nomura
2019-05-21  9:02                       ` Kairui Song
2019-05-21 10:43                         ` Junichi Nomura
2019-05-21 18:09                         ` Borislav Petkov
2019-05-28  2:49                           ` Kairui Song
2019-06-06 19:20                             ` Borislav Petkov
2019-05-13  8:06               ` Baoquan He
2019-05-14  3:22                 ` Dave Young
2019-05-14  3:33                   ` Baoquan He
2019-05-21 21:53                     ` Dirk van der Merwe
2019-05-21 23:04                       ` Borislav Petkov
2019-05-14  8:48                   ` Dave Young
2019-05-14 11:18                     ` Kairui Song
2019-05-14 11:38                     ` Peter Zijlstra
2019-05-14 12:58                       ` Dave Young
2019-05-14 13:54                         ` Peter Zijlstra
2019-05-14 14:09                         ` Ingo Molnar
2019-05-15  1:08                           ` Dave Young
2019-05-15  6:43                             ` Junichi Nomura
2019-05-17 13:41                   ` Borislav Petkov
2019-05-17 13:50                     ` [PATCH] x86/boot: Call get_rsdp_addr() after console_init() Borislav Petkov
2019-05-21  9:28                       ` Baoquan He
2019-06-06 19:22     ` tip-bot for Kairui Song [this message]
2019-04-24  9:29 ` [PATCH v5 2/2] x86/boot: Use efi_setup_data for searching RSDP on kexec-ed kernels Baoquan He
2019-04-24  9:33   ` Baoquan He
2019-04-24  9:38 ` [PATCH v5 0/2] x86/boot: Use efi_setup_data for searching RSDP on kexec-ed kernel Borislav Petkov
2019-04-24 10:00   ` Baoquan He

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-6bbeb276b71f06c5267bfd154629b1bec82e7136@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=bhe@redhat.com \
    --cc=bp@suse.de \
    --cc=dirk.vandermerwe@netronome.com \
    --cc=hpa@zytor.com \
    --cc=kasong@redhat.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=lijiang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --subject='Re: [tip:x86/boot] x86/kexec: Add the EFI system tables and ACPI tables to the ident map' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).