From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout02.his.huawei.com (canpmsgout02.his.huawei.com [113.46.200.217]) (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 956CB2DAFDE; Thu, 18 Jun 2026 01:55:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.217 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781747712; cv=none; b=lyMK2mRTBE9xOra10HH/yte34C5NpI/EDxQbQ7qKEZ9Ogj1qwm8+PmDdFbQ9a6ns+fz2BD5N75AXfjdfGgn7hipULnJYzcjy6Z3irSztEjwz4WkL1YlniulFP38DNJX++EdmnXzruvO8yJ7dMmpxHvHS9K9KxlrkvvF4fZSU4OY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781747712; c=relaxed/simple; bh=2xVUDeu7m5v732YAAonOHjgizv9iOHbiDq/qEfMgCkI=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=RRu+ZZHB7jksaUa4KHcV7NJ2WjtT81dlbLwCrfp0UwIDLI9cn1cmixCKdkNmHFyiIfAHC+sRhIvP06MLcakoAwdSsV3vhOGCTHa/7sB0d9yART6/uP7x0btHvGDOR090dRZxWhpRev1oI2QtKdtqzqF0jAICaYEM2iUdtRE7jLU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=35QD5KYB; arc=none smtp.client-ip=113.46.200.217 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="35QD5KYB" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=UOH0r2GKmZinHZXHsCVUvBFIRyCZaXIIn59yPqlKYRQ=; b=35QD5KYBf8iWm3rSHGgu5lrD1IM1oRlAbbVOXF6oMi5OW7M8yZlBjxwAJDI7B4dZe3/wWYw3i u1FsPuVNCgRGRIq4XPKt8ko5A2ZywXPGblpb9i9d6ACKRzVYyCRKVU0tJtsMiLrk1LIdelLq3nq AYJjys3AV3rY6Q7icuxh40k= Received: from mail.maildlp.com (unknown [172.19.163.0]) by canpmsgout02.his.huawei.com (SkyGuard) with ESMTPS id 4ggk934xC5zcZyL; Thu, 18 Jun 2026 09:46:31 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id A97B840561; Thu, 18 Jun 2026 09:54:57 +0800 (CST) Received: from [10.67.109.254] (10.67.109.254) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 18 Jun 2026 09:54:53 +0800 Message-ID: <7d8492c5-fc17-4c94-bc88-e77d6c1a849d@huawei.com> Date: Thu, 18 Jun 2026 09:54:52 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v16 06/10] riscv: kexec_file: Use crash_prepare_headers() helper to simplify code To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , References: <20260608073459.3119290-1-ruanjinjie@huawei.com> <20260608073459.3119290-7-ruanjinjie@huawei.com> From: Jinjie Ruan In-Reply-To: <20260608073459.3119290-7-ruanjinjie@huawei.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemf500011.china.huawei.com (7.185.36.131) On 6/8/2026 3:34 PM, Jinjie Ruan wrote: > Use the newly introduced crash_prepare_headers() function to replace > the existing prepare_elf_headers(), allocate cmem and exclude crash kernel > memory in the crash core, which reduce code duplication. > > Only the following two architecture functions need to be implemented: > - arch_get_system_nr_ranges(). Call get_nr_ram_ranges_callback() > to pre-counts the max number of memory ranges. > > - arch_crash_populate_cmem(). Use prepare_elf64_ram_headers_callback() > to collects the memory ranges and fills them into cmem. Hi Paul, Palmer, Albert, Alexandre and RISC-V maintainers, Sorry for the interruption. This patch set aims to clean up and refactor the crash memory allocation and the exclusion logic of crashk_res, crashk_low_res, and crashk_cma. Currently, these routines are almost identical across different architectures, leading to a lot of duplicated code. This series consolidates the logic into the generic crash core, removing redundant implementations from architecture-specific directories, including arch/riscv. There are no functional changes intended for RISC-V. The patches will be queued in the liveupdate tree for wider testing. Could you please take a look at the RISC-V side and consider providing an Acked-by? The patch series can be reviewed here: https://lore.kernel.org/all/20260608073459.3119290-1-ruanjinjie@huawei.com/ Thank you very much for your time and review! Best regards, Jinjie > > Cc: Paul Walmsley > Cc: Palmer Dabbelt > Cc: Albert Ou > Cc: Alexandre Ghiti > Cc: Guo Ren > Reviewed-by: Sourabh Jain > Acked-by: Baoquan He > Acked-by: Mike Rapoport (Microsoft) > Signed-off-by: Jinjie Ruan > --- > arch/riscv/kernel/machine_kexec_file.c | 47 +++++++------------------- > 1 file changed, 12 insertions(+), 35 deletions(-) > > diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/machine_kexec_file.c > index 3f7766057cac..439cbc50dfa6 100644 > --- a/arch/riscv/kernel/machine_kexec_file.c > +++ b/arch/riscv/kernel/machine_kexec_file.c > @@ -44,6 +44,15 @@ static int get_nr_ram_ranges_callback(struct resource *res, void *arg) > return 0; > } > > +unsigned int arch_get_system_nr_ranges(void) > +{ > + unsigned int nr_ranges = 2; /* For exclusion of crashkernel region */ > + > + walk_system_ram_res(0, -1, &nr_ranges, get_nr_ram_ranges_callback); > + > + return nr_ranges; > +} > + > static int prepare_elf64_ram_headers_callback(struct resource *res, void *arg) > { > struct crash_mem *cmem = arg; > @@ -55,41 +64,9 @@ static int prepare_elf64_ram_headers_callback(struct resource *res, void *arg) > return 0; > } > > -static int prepare_elf_headers(void **addr, unsigned long *sz) > +int arch_crash_populate_cmem(struct crash_mem *cmem) > { > - struct crash_mem *cmem; > - unsigned int nr_ranges; > - int ret; > - > - nr_ranges = 2; /* For exclusion of crashkernel region */ > - walk_system_ram_res(0, -1, &nr_ranges, get_nr_ram_ranges_callback); > - > - cmem = kmalloc_flex(*cmem, ranges, nr_ranges); > - if (!cmem) > - return -ENOMEM; > - > - cmem->max_nr_ranges = nr_ranges; > - cmem->nr_ranges = 0; > - ret = walk_system_ram_res(0, -1, cmem, prepare_elf64_ram_headers_callback); > - if (ret) > - goto out; > - > - /* Exclude crashkernel region */ > - ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); > - if (ret) > - goto out; > - > - if (crashk_low_res.end) { > - ret = crash_exclude_mem_range(cmem, crashk_low_res.start, crashk_low_res.end); > - if (ret) > - goto out; > - } > - > - ret = crash_prepare_elf64_headers(cmem, true, addr, sz); > - > -out: > - kfree(cmem); > - return ret; > + return walk_system_ram_res(0, -1, cmem, prepare_elf64_ram_headers_callback); > } > > static char *setup_kdump_cmdline(struct kimage *image, char *cmdline, > @@ -281,7 +258,7 @@ int load_extra_segments(struct kimage *image, unsigned long kernel_start, > if (image->type == KEXEC_TYPE_CRASH) { > void *headers; > unsigned long headers_sz; > - ret = prepare_elf_headers(&headers, &headers_sz); > + ret = crash_prepare_headers(true, &headers, &headers_sz, NULL); > if (ret) { > pr_err("Preparing elf core header failed\n"); > goto out;