From patchwork Thu Apr 27 10:18:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhijian Li (Fujitsu)" X-Patchwork-Id: 13225348 Received: from esa3.hc1455-7.c3s2.iphmx.com (esa3.hc1455-7.c3s2.iphmx.com [207.54.90.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 502C323BD for ; Thu, 27 Apr 2023 10:19:58 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6600,9927,10692"; a="115116672" X-IronPort-AV: E=Sophos;i="5.99,230,1677510000"; d="scan'208";a="115116672" Received: from unknown (HELO oym-r3.gw.nic.fujitsu.com) ([210.162.30.91]) by esa3.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2023 19:18:47 +0900 Received: from oym-m3.gw.nic.fujitsu.com (oym-nat-oym-m3.gw.nic.fujitsu.com [192.168.87.60]) by oym-r3.gw.nic.fujitsu.com (Postfix) with ESMTP id AD5B2D6478 for ; Thu, 27 Apr 2023 19:18:45 +0900 (JST) Received: from kws-ab1.gw.nic.fujitsu.com (kws-ab1.gw.nic.fujitsu.com [192.51.206.11]) by oym-m3.gw.nic.fujitsu.com (Postfix) with ESMTP id D73CDD55E5 for ; Thu, 27 Apr 2023 19:18:44 +0900 (JST) Received: from FNSTPC.g08.fujitsu.local (unknown [10.167.226.45]) by kws-ab1.gw.nic.fujitsu.com (Postfix) with ESMTP id 090451145FC8; Thu, 27 Apr 2023 19:18:42 +0900 (JST) From: Li Zhijian To: x86@kernel.org, nvdimm@lists.linux.dev, kexec@lists.infradead.org Cc: linux-kernel@vger.kernel.org, y-goto@fujitsu.com, yangx.jy@fujitsu.com, ruansy.fnst@fujitsu.com, Li Zhijian , Baoquan He , Vivek Goyal , Dave Young Subject: [RFC PATCH v2 1/3] crash: export dev memmap header to vmcoreinfo Date: Thu, 27 Apr 2023 18:18:32 +0800 Message-Id: <20230427101838.12267-2-lizhijian@fujitsu.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427101838.12267-1-lizhijian@fujitsu.com> References: <20230427101838.12267-1-lizhijian@fujitsu.com> Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1408-9.0.0.1002-27590.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1408-9.0.1002-27590.006 X-TMASE-Result: 10--8.579600-10.000000 X-TMASE-MatchedRID: NusNVSlhHE3o2ZWMy24DXxFbgtHjUWLyEDnDEqNPdupgPgeggVwCFnOw /jufb+urjx5X3FdI4UDmn3xyPJAJoh2P280ZiGmRFDuTLTe6zcPDCscXmnDN70ekR3VSvOYVfMZ 9Z21cFRwZ+9qD5ZvwhynYQ5Puko8IFIetOq2+pVD/2ZGj3BST5dC1Z3HzBbIHEu7wSQdRGs93I3 P+EY3BjRcfmI3+RkHYnagtny7ZPcQfE8yM4pjsDzXJPZYaymc4xEHRux+uk8h+ICquNi0WJMFcj FTxsO89PnFUB9od7fL1uFbUDrfyNiyqaup2Gcf5ftwZ3X11IV0= X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Introduce a symbol and export it to vmcoreinfo. Dumping applications such as makedumpfile, with this variable, they are able to restore a linked list which contained the memmap region located in device. With this mechanism, nvdimm/pmem which allows placing memmap in device is able to export the its memmap(page array) to kdump kernel via vmcoreinfo. CC: Baoquan He CC: Vivek Goyal CC: Dave Young Signed-off-by: Li Zhijian --- include/linux/crash_core.h | 8 +++++ kernel/crash_core.c | 61 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h index de62a722431e..05ec2777f4fd 100644 --- a/include/linux/crash_core.h +++ b/include/linux/crash_core.h @@ -84,4 +84,12 @@ int parse_crashkernel_high(char *cmdline, unsigned long long system_ram, int parse_crashkernel_low(char *cmdline, unsigned long long system_ram, unsigned long long *crash_size, unsigned long long *crash_base); +#ifdef CONFIG_CRASH_CORE +void devm_memmap_vmcore_delete(void *match); +void devm_memmap_vmcore_update(void *match, u64 pfn, u64 npfn, bool dev); +#else +#define devm_memmap_vmcore_delete(match) do {} while (0) +#define devm_memmap_vmcore_update(match, pfn, npfn, dev) do {} while (0) +#endif + #endif /* LINUX_CRASH_CORE_H */ diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 755f5f08ab38..f28cbd98f28b 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -401,6 +401,61 @@ phys_addr_t __weak paddr_vmcoreinfo_note(void) } EXPORT_SYMBOL(paddr_vmcoreinfo_note); +struct devm_memmap_vmcore { + struct list_head entry; + unsigned long start; + unsigned long end; + void *match; +}; + +static struct devm_memmap_vmcore devm_memmap_vmcore_head = { + .entry = LIST_HEAD_INIT(devm_memmap_vmcore_head.entry), +}; +static DEFINE_MUTEX(devm_memmap_vmcore_mutex); + +static void devm_memmap_vmcore_add(void *match, u64 pfn, u64 npfn) +{ + struct devm_memmap_vmcore *metadata; + + metadata = kzalloc(sizeof(*metadata), GFP_KERNEL); + if (!metadata) { + pr_err("No enough memory"); + return; + } + + metadata->start = pfn; + metadata->end = pfn + npfn; + metadata->match = match; + + mutex_lock(&devm_memmap_vmcore_mutex); + list_add(&metadata->entry, &devm_memmap_vmcore_head.entry); + mutex_unlock(&devm_memmap_vmcore_mutex); +} + +void devm_memmap_vmcore_delete(void *match) +{ + struct devm_memmap_vmcore *metadata; + + mutex_lock(&devm_memmap_vmcore_mutex); + list_for_each_entry(metadata, &devm_memmap_vmcore_head.entry, entry) { + if (metadata->match == match) { + list_del(&metadata->entry); + kfree(metadata); + break; + } + } + mutex_unlock(&devm_memmap_vmcore_mutex); +} +EXPORT_SYMBOL_GPL(devm_memmap_vmcore_delete); + +void devm_memmap_vmcore_update(void *match, u64 start_pfn, u64 npfn, bool dev) +{ + devm_memmap_vmcore_delete(match); + if (dev) + devm_memmap_vmcore_add(match, start_pfn, npfn); +} +EXPORT_SYMBOL_GPL(devm_memmap_vmcore_update); + static int __init crash_save_vmcoreinfo_init(void) { vmcoreinfo_data = (unsigned char *)get_zeroed_page(GFP_KERNEL); @@ -436,6 +491,12 @@ static int __init crash_save_vmcoreinfo_init(void) VMCOREINFO_SYMBOL(contig_page_data); #endif #ifdef CONFIG_SPARSEMEM + VMCOREINFO_SYMBOL(devm_memmap_vmcore_head); + VMCOREINFO_STRUCT_SIZE(devm_memmap_vmcore); + VMCOREINFO_OFFSET(devm_memmap_vmcore, entry); + VMCOREINFO_OFFSET(devm_memmap_vmcore, start); + VMCOREINFO_OFFSET(devm_memmap_vmcore, end); + VMCOREINFO_SYMBOL_ARRAY(mem_section); VMCOREINFO_LENGTH(mem_section, NR_SECTION_ROOTS); VMCOREINFO_STRUCT_SIZE(mem_section); From patchwork Thu Apr 27 10:18:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhijian Li (Fujitsu)" X-Patchwork-Id: 13225350 Received: from esa7.hc1455-7.c3s2.iphmx.com (esa7.hc1455-7.c3s2.iphmx.com [139.138.61.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B39523DC for ; Thu, 27 Apr 2023 10:20:01 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6600,9927,10692"; a="93785519" X-IronPort-AV: E=Sophos;i="5.99,230,1677510000"; d="scan'208";a="93785519" Received: from unknown (HELO yto-r3.gw.nic.fujitsu.com) ([218.44.52.219]) by esa7.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2023 19:18:49 +0900 Received: from yto-m1.gw.nic.fujitsu.com (yto-nat-yto-m1.gw.nic.fujitsu.com [192.168.83.64]) by yto-r3.gw.nic.fujitsu.com (Postfix) with ESMTP id A16EDC3F7E for ; Thu, 27 Apr 2023 19:18:47 +0900 (JST) Received: from kws-ab1.gw.nic.fujitsu.com (kws-ab1.gw.nic.fujitsu.com [192.51.206.11]) by yto-m1.gw.nic.fujitsu.com (Postfix) with ESMTP id E5A25CFFAE for ; Thu, 27 Apr 2023 19:18:46 +0900 (JST) Received: from FNSTPC.g08.fujitsu.local (unknown [10.167.226.45]) by kws-ab1.gw.nic.fujitsu.com (Postfix) with ESMTP id AE45F114626A; Thu, 27 Apr 2023 19:18:44 +0900 (JST) From: Li Zhijian To: x86@kernel.org, nvdimm@lists.linux.dev, kexec@lists.infradead.org Cc: linux-kernel@vger.kernel.org, y-goto@fujitsu.com, yangx.jy@fujitsu.com, ruansy.fnst@fujitsu.com, Li Zhijian , Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny Subject: [RFC PATCH v2 2/3] drivers/nvdimm: export memmap of namespace to vmcoreinfo Date: Thu, 27 Apr 2023 18:18:33 +0800 Message-Id: <20230427101838.12267-3-lizhijian@fujitsu.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427101838.12267-1-lizhijian@fujitsu.com> References: <20230427101838.12267-1-lizhijian@fujitsu.com> Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1408-9.0.0.1002-27590.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1408-9.0.1002-27590.006 X-TMASE-Result: 10--5.296600-10.000000 X-TMASE-MatchedRID: mJ3yV3MWQwmUkDPUhpX2vh1kSRHxj+Z5A81piVnI+HU1SqhT+J6xsUbg XczvLJKOjx5X3FdI4UDmn3xyPJAJoh2P280ZiGmRfiKzBf4Yf9iOVGny5q72hp4Q+L3BXIWuyL5 QmWOgMfBI7ocMJBgR6/WV3EhAhFD6Sry0z8DqbhLNgrlT5Ajc7n0tCKdnhB589yM15V5aWpj6C0 ePs7A07Xi4XEoPXecxVvpTJmXb4dua6fR6Q+5OxeYzpCWDqqUZ3tGV3hp+Y+4= X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 Each namespace has its own memmap, it will be udpated when namespace initializing/creating, updating, and deleting. CC: Dan Williams CC: Vishal Verma CC: Dave Jiang CC: Ira Weiny Signed-off-by: Li Zhijian --- drivers/nvdimm/namespace_devs.c | 2 ++ drivers/nvdimm/pfn_devs.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c index c60ec0b373c5..096203e6203f 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "nd-core.h" #include "pmem.h" #include "pfn.h" @@ -853,6 +854,7 @@ static ssize_t size_store(struct device *dev, if (rc == 0 && val == 0 && is_namespace_pmem(dev)) { struct nd_namespace_pmem *nspm = to_nd_namespace_pmem(dev); + devm_memmap_vmcore_delete(to_ndns(dev)); kfree(nspm->uuid); nspm->uuid = NULL; } diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c index af7d9301520c..80076996b2da 100644 --- a/drivers/nvdimm/pfn_devs.c +++ b/drivers/nvdimm/pfn_devs.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "nd-core.h" #include "pfn.h" #include "nd.h" @@ -716,6 +717,8 @@ static int __nvdimm_setup_pfn(struct nd_pfn *nd_pfn, struct dev_pagemap *pgmap) } else return -ENXIO; + devm_memmap_vmcore_update(ndns, altmap->base_pfn, PHYS_PFN(offset), + nd_pfn->mode == PFN_MODE_PMEM); return 0; } From patchwork Thu Apr 27 10:18:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhijian Li (Fujitsu)" X-Patchwork-Id: 13225349 Received: from esa3.hc1455-7.c3s2.iphmx.com (esa3.hc1455-7.c3s2.iphmx.com [207.54.90.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E29F23BD for ; Thu, 27 Apr 2023 10:20:00 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6600,9927,10692"; a="115116714" X-IronPort-AV: E=Sophos;i="5.99,230,1677510000"; d="scan'208";a="115116714" Received: from unknown (HELO oym-r3.gw.nic.fujitsu.com) ([210.162.30.91]) by esa3.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2023 19:18:53 +0900 Received: from oym-m3.gw.nic.fujitsu.com (oym-nat-oym-m3.gw.nic.fujitsu.com [192.168.87.60]) by oym-r3.gw.nic.fujitsu.com (Postfix) with ESMTP id D6704D647B for ; Thu, 27 Apr 2023 19:18:50 +0900 (JST) Received: from kws-ab1.gw.nic.fujitsu.com (kws-ab1.gw.nic.fujitsu.com [192.51.206.11]) by oym-m3.gw.nic.fujitsu.com (Postfix) with ESMTP id EF39CD5638 for ; Thu, 27 Apr 2023 19:18:49 +0900 (JST) Received: from FNSTPC.g08.fujitsu.local (unknown [10.167.226.45]) by kws-ab1.gw.nic.fujitsu.com (Postfix) with ESMTP id B3D861145FC8; Thu, 27 Apr 2023 19:18:46 +0900 (JST) From: Li Zhijian To: x86@kernel.org, nvdimm@lists.linux.dev, kexec@lists.infradead.org Cc: linux-kernel@vger.kernel.org, y-goto@fujitsu.com, yangx.jy@fujitsu.com, ruansy.fnst@fujitsu.com, Li Zhijian , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Eric Biederman , Takashi Iwai , Baoquan He , Vlastimil Babka , Sean Christopherson , Jonathan Cameron , Greg Kroah-Hartman , Andy Shevchenko , Dan Williams , "Rafael J. Wysocki" , Ira Weiny , Raul E Rangel , Colin Foster , Vishal Verma Subject: [RFC PATCH v2 3/3] resource, crash: Make kexec_file_load support pmem Date: Thu, 27 Apr 2023 18:18:34 +0800 Message-Id: <20230427101838.12267-4-lizhijian@fujitsu.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427101838.12267-1-lizhijian@fujitsu.com> References: <20230427101838.12267-1-lizhijian@fujitsu.com> Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1408-9.0.0.1002-27590.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1408-9.0.1002-27590.006 X-TMASE-Result: 10--7.728400-10.000000 X-TMASE-MatchedRID: +Dq5+AB/HWKUG5QaGlcSvSFcmxL76KeOwMc7ZZ8e7/dgPgeggVwCFnOw /jufb+urjx5X3FdI4UDmn3xyPJAJoh2P280ZiGmRutvHF25zoU8YH39vFLryE7rfxlRjqBJ3k8q tQTvc3FF+J/o+y9+xUrCUXHFFjdR48ZTibkDR5X0JGwniUXM+M9Y3ddD/vCxPaskqKES/kfLiuX 4UcbdWgHeRkG9uGhVN3B7MhNx6/YcfE8yM4pjsDwtuKBGekqUpI/NGWt0UYPCqPXzIJWKFRWTxV nPsfXK/2KFWEl0RCT8sKsYTWZ7DajkOabXnQVrB X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 It does: 1. Add pmem region into PT_LOADs of vmcore 2. Mark pmem region's p_flags as PF_DEV CC: Thomas Gleixner CC: Ingo Molnar CC: Borislav Petkov CC: Dave Hansen CC: "H. Peter Anvin" CC: Eric Biederman CC: Takashi Iwai CC: Baoquan He CC: Vlastimil Babka CC: Sean Christopherson CC: Jonathan Cameron CC: Greg Kroah-Hartman CC: Andy Shevchenko CC: Dan Williams CC: "Rafael J. Wysocki" CC: Ira Weiny CC: Raul E Rangel CC: Colin Foster CC: Vishal Verma CC: x86@kernel.org Signed-off-by: Li Zhijian --- 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 #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.