lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230427101838.12267-4-lizhijian@fujitsu.com>
Date:   Thu, 27 Apr 2023 18:18:34 +0800
From:   Li Zhijian <lizhijian@...itsu.com>
To:     x86@...nel.org, nvdimm@...ts.linux.dev, kexec@...ts.infradead.org
Cc:     linux-kernel@...r.kernel.org, y-goto@...itsu.com,
        yangx.jy@...itsu.com, ruansy.fnst@...itsu.com,
        Li Zhijian <lizhijian@...itsu.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        "H. Peter Anvin" <hpa@...or.com>,
        Eric Biederman <ebiederm@...ssion.com>,
        Takashi Iwai <tiwai@...e.de>, Baoquan He <bhe@...hat.com>,
        Vlastimil Babka <vbabka@...e.cz>,
        Sean Christopherson <seanjc@...gle.com>,
        Jonathan Cameron <Jonathan.Cameron@...wei.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Dan Williams <dan.j.williams@...el.com>,
        "Rafael J. Wysocki" <rafael@...nel.org>,
        Ira Weiny <ira.weiny@...el.com>,
        Raul E Rangel <rrangel@...omium.org>,
        Colin Foster <colin.foster@...advantage.com>,
        Vishal Verma <vishal.l.verma@...el.com>
Subject: [RFC PATCH v2 3/3] resource, crash: Make kexec_file_load support pmem

It does:
1. Add pmem region into PT_LOADs of vmcore
2. Mark pmem region's p_flags as PF_DEV

CC: Thomas Gleixner <tglx@...utronix.de>
CC: Ingo Molnar <mingo@...hat.com>
CC: Borislav Petkov <bp@...en8.de>
CC: Dave Hansen <dave.hansen@...ux.intel.com>
CC: "H. Peter Anvin" <hpa@...or.com>
CC: Eric Biederman <ebiederm@...ssion.com>
CC: Takashi Iwai <tiwai@...e.de>
CC: Baoquan He <bhe@...hat.com>
CC: Vlastimil Babka <vbabka@...e.cz>
CC: Sean Christopherson <seanjc@...gle.com>
CC: Jonathan Cameron <Jonathan.Cameron@...wei.com>
CC: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
CC: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
CC: Dan Williams <dan.j.williams@...el.com>
CC: "Rafael J. Wysocki" <rafael@...nel.org>
CC: Ira Weiny <ira.weiny@...el.com>
CC: Raul E Rangel <rrangel@...omium.org>
CC: Colin Foster <colin.foster@...advantage.com>
CC: Vishal Verma <vishal.l.verma@...el.com>
CC: x86@...nel.org
Signed-off-by: Li Zhijian <lizhijian@...itsu.com>
---
 arch/x86/kernel/crash.c |  2 ++
 include/linux/ioport.h  |  3 +++
 kernel/kexec_file.c     | 10 ++++++++++
 kernel/resource.c       | 11 +++++++++++
 4 files changed, 26 insertions(+)

diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index cdd92ab43cda..dc9d03083565 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -178,6 +178,7 @@ static struct crash_mem *fill_up_crash_elf_data(void)
 	if (!nr_ranges)
 		return NULL;
 
+	walk_pmem_res(0, -1, &nr_ranges, get_nr_ram_ranges_callback);
 	/*
 	 * Exclusion of crash region and/or crashk_low_res may cause
 	 * another range split. So add extra two slots here.
@@ -243,6 +244,7 @@ static int prepare_elf_headers(struct kimage *image, void **addr,
 	ret = walk_system_ram_res(0, -1, cmem, prepare_elf64_ram_headers_callback);
 	if (ret)
 		goto out;
+	walk_pmem_res(0, -1, cmem, prepare_elf64_ram_headers_callback);
 
 	/* Exclude unwanted mem ranges */
 	ret = elf_header_exclude_ranges(cmem);
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index 25d768d48970..bde88a47cc1a 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -331,6 +331,9 @@ extern int
 walk_system_ram_res(u64 start, u64 end, void *arg,
 		    int (*func)(struct resource *, void *));
 extern int
+walk_pmem_res(u64 start, u64 end, void *arg,
+	      int (*func)(struct resource *, void *));
+extern int
 walk_iomem_res_desc(unsigned long desc, unsigned long flags, u64 start, u64 end,
 		    void *arg, int (*func)(struct resource *, void *));
 
diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index f1a0e4e3fb5c..e79ceaee2926 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -29,6 +29,8 @@
 #include <linux/vmalloc.h>
 #include "kexec_internal.h"
 
+#define PF_DEV (1 << 4)
+
 #ifdef CONFIG_KEXEC_SIG
 static bool sig_enforce = IS_ENABLED(CONFIG_KEXEC_SIG_FORCE);
 
@@ -1221,6 +1223,12 @@ int crash_exclude_mem_range(struct crash_mem *mem,
 	return 0;
 }
 
+static bool is_pmem_range(u64 start, u64 size)
+{
+	return REGION_INTERSECTS == region_intersects(start, size,
+			IORESOURCE_MEM, IORES_DESC_PERSISTENT_MEMORY);
+}
+
 int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map,
 			  void **addr, unsigned long *sz)
 {
@@ -1302,6 +1310,8 @@ int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map,
 
 		phdr->p_type = PT_LOAD;
 		phdr->p_flags = PF_R|PF_W|PF_X;
+		if (is_pmem_range(mstart, mend - mstart))
+			phdr->p_flags |= PF_DEV;
 		phdr->p_offset  = mstart;
 
 		phdr->p_paddr = mstart;
diff --git a/kernel/resource.c b/kernel/resource.c
index b1763b2fd7ef..f3f1ce6fc384 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -431,6 +431,17 @@ int walk_system_ram_res(u64 start, u64 end, void *arg,
 				     func);
 }
 
+/*
+ * This function calls the @func callback against all memory ranges, which
+ * are ranges marked as IORESOURCE_MEM and IORES_DESC_PERSISTENT_MEMORY.
+ */
+int walk_pmem_res(u64 start, u64 end, void *arg,
+			int (*func)(struct resource *, void *))
+{
+	return __walk_iomem_res_desc(start, end, IORESOURCE_MEM,
+				     IORES_DESC_PERSISTENT_MEMORY, arg, func);
+}
+
 /*
  * This function calls the @func callback against all memory ranges, which
  * are ranges marked as IORESOURCE_MEM and IORESOUCE_BUSY.
-- 
2.29.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ