Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp421653rwr; Thu, 27 Apr 2023 03:22:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ55/BqgqUxSB8wExSbjGq3MxYTTD8NF+waic+/uyAkxTaLW+s2jqNj1amdO39iJ8mdoBAWA X-Received: by 2002:a17:902:e5c7:b0:1a9:665f:8a19 with SMTP id u7-20020a170902e5c700b001a9665f8a19mr1196549plf.5.1682590959017; Thu, 27 Apr 2023 03:22:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682590958; cv=none; d=google.com; s=arc-20160816; b=MdY5NTW0/q0ca5/ZU2CoStNJFbnzTHjwiHzNjDrWM7GnM/AKG3SWx2v99H7mnkZxgy ESk4YVXa8DiKS8tbvATHXVLixyln+MiF0crcNe2Ue8XgfOPxhEMPHkcuET2kmDZSMPJp UHbjs0rQrtNNGC8pj58iJfX4N3WO+xOq+PV3tYxLePTfn6m8Rr99ZljubjUNP9EcQPTt J7DL15r2feiD1cPqTQftmWMvTjns9IcJFMFK2VR2ann8LOLOvYVHc7K/c1xEYgmlyxgO SLO3A54enAAtD0v34IegzGbcCxVswqC8lcDUo4cZxsYU3AdhPoLo8uqiWDGK74R2zrrm Mlsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=wujroK3oFuLuFeAGqgyWmkapQar9VPp2uSI/qBQOg4U=; b=chVTrPgky0Tsfe4j4Hetkx8W7IQKKnsvQKMW02KuLSrM+ysvNWPGe78L+t5GxVMnjW ebEQ5lMEFVGJn5rdCMXdJ3KSj8n14uovy0ck2hXSQaa5VQ5uy7Mx0ODWQOh4W8fOFUkb Zna5dcTtMFOxG/nN29+N55V5Ndx8BY9VQ8Ak5jjE8sekS94zN1z/jIL7UA9UoeiduAVm BpzKW4wgDim6TojJeXAj+7LhS0rudFxuulJ/KAKXKptZLB2ButqcPY0bFxAHUBfj6ivD s4rmj/Vs8aS/K4tEZH1I4jFi9eB48D10+o2UuClM5nRzBz+PKt7FlgUXhvv95Gh/XY3g a4PQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w9-20020a170902e88900b001a51bb4ad81si19383210plg.44.2023.04.27.03.22.24; Thu, 27 Apr 2023 03:22:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243518AbjD0KUg (ORCPT + 99 others); Thu, 27 Apr 2023 06:20:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243521AbjD0KUI (ORCPT ); Thu, 27 Apr 2023 06:20:08 -0400 X-Greylist: delayed 63 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 27 Apr 2023 03:19:58 PDT Received: from esa12.hc1455-7.c3s2.iphmx.com (esa12.hc1455-7.c3s2.iphmx.com [139.138.37.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B04CD4696 for ; Thu, 27 Apr 2023 03:19:58 -0700 (PDT) X-IronPort-AV: E=McAfee;i="6600,9927,10692"; a="94534338" X-IronPort-AV: E=Sophos;i="5.99,230,1677510000"; d="scan'208";a="94534338" Received: from unknown (HELO yto-r1.gw.nic.fujitsu.com) ([218.44.52.217]) by esa12.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2023 19:18:52 +0900 Received: from yto-m3.gw.nic.fujitsu.com (yto-nat-yto-m3.gw.nic.fujitsu.com [192.168.83.66]) by yto-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id C76A5D66A1 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 yto-m3.gw.nic.fujitsu.com (Postfix) with ESMTP id 0811ED969C for ; Thu, 27 Apr 2023 19:18:50 +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> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 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. -- 2.29.2