From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout04.his.huawei.com (canpmsgout04.his.huawei.com [113.46.200.219]) (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 CF6BB3A3E8B; Mon, 8 Jun 2026 08:23:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.219 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780907002; cv=none; b=EBXfx1K7phVRsDQOcoNYqoGn7LQntfkKKdtPdbgUGsVi/lNhICHr2+QCL9VyK2nRGmhJjO0wFPwyDHoO2BRO8rfG2nMrRec0FuKCgGTuMUeAFhN+UEJMCH+4dG1CqIscYWeroBXhn3HszcLFdWORwUpWH/fqzeJ4erTHx2kYQq0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780907002; c=relaxed/simple; bh=zBJ0+6iki8mXgDpkiRZdp2up2Qck5jTHuoY18SoxxP4=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=fAqBG4PcBpcQlWbp5bjUCDSpKGX8YoprtnbAw/i52RvApJ1wkLWTb9cD+Og+B/fjROmx4d9jSSBvulLPofHGq6eSzvOSfhPnC/KnzD1leh/06QIUJusrOuuJKrhSdP/8qc2HKshaeA2kG87ARRTQp4MlN+1TED8BeYmaetRUZ78= 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=edYZDT01; arc=none smtp.client-ip=113.46.200.219 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="edYZDT01" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=0w7UuJbrk8/79aFOsVk7Yx0ya08/zmKmr0eY8n6NxvI=; b=edYZDT01btd+1flK3bhqZkCTyQ1fdstH4uPirfjz64VnuvQ6C0+kgEBnVmGkQl91G2HuUuQd3 YnoMXpdUg0VxM1R0RhaeorcUkYBKjeZAmgdSezV4PTEuybgqEahh1J3J0tMUrT3g/AcXrpX26wD QFQmQtODscQdT0EOeHgm+c0= Received: from mail.maildlp.com (unknown [172.19.163.104]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4gYlGK66HYz1prMB; Mon, 8 Jun 2026 16:15:21 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 5B4DD4048F; Mon, 8 Jun 2026 16:23:17 +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; Mon, 8 Jun 2026 16:23:13 +0800 Message-ID: <4f3ae5f8-abf1-42ef-b613-7d69349f0cc8@huawei.com> Date: Mon, 8 Jun 2026 16:23:12 +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 07/10] LoongArch: kexec_file: Use crash_prepare_headers() helper to simplify code To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , References: <20260608073459.3119290-1-ruanjinjie@huawei.com> <20260608073459.3119290-8-ruanjinjie@huawei.com> From: Jinjie Ruan In-Reply-To: <20260608073459.3119290-8-ruanjinjie@huawei.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) 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(). Use for_each_mem_range to traverse > and pre-count the max number of memory ranges. > > - arch_crash_populate_cmem(). Use for_each_mem_range to traverse > and collect the memory ranges and fills them into cmem. > > Cc: Huacai Chen > Cc: WANG Xuerui > Cc: Youling Tang > Cc: Baoquan He > Reviewed-by: Sourabh Jain > Acked-by: Baoquan He > Acked-by: Mike Rapoport (Microsoft) > Signed-off-by: Jinjie Ruan > --- > arch/loongarch/kernel/machine_kexec_file.c | 40 +++++++--------------- > 1 file changed, 12 insertions(+), 28 deletions(-) The below AI reported TOCTOU bug is an existing artifact and completely unrelated to the rework here. Therefore, we will skip fixing it in this series to avoid unnecessary noise. Link: https://lore.kernel.org/all/20260608075258.0F6D91F00893@smtp.kernel.org/ > > diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/kernel/machine_kexec_file.c > index 5584b798ba46..5412aa9f3568 100644 > --- a/arch/loongarch/kernel/machine_kexec_file.c > +++ b/arch/loongarch/kernel/machine_kexec_file.c > @@ -56,46 +56,30 @@ static void cmdline_add_initrd(struct kimage *image, unsigned long *cmdline_tmpl > } > > #ifdef CONFIG_CRASH_DUMP > - > -static int prepare_elf_headers(void **addr, unsigned long *sz) > +unsigned int arch_get_system_nr_ranges(void) > { > - int ret, nr_ranges; > - uint64_t i; > + int nr_ranges = 2; /* for exclusion of crashkernel region */ > phys_addr_t start, end; > - struct crash_mem *cmem; > + uint64_t i; > > - nr_ranges = 2; /* for exclusion of crashkernel region */ > for_each_mem_range(i, &start, &end) > nr_ranges++; > > - cmem = kmalloc_flex(*cmem, ranges, nr_ranges); > - if (!cmem) > - return -ENOMEM; > + return nr_ranges; > +} > + > +int arch_crash_populate_cmem(struct crash_mem *cmem) > +{ > + phys_addr_t start, end; > + uint64_t i; > > - cmem->max_nr_ranges = nr_ranges; > - cmem->nr_ranges = 0; > for_each_mem_range(i, &start, &end) { > cmem->ranges[cmem->nr_ranges].start = start; > cmem->ranges[cmem->nr_ranges].end = end - 1; > cmem->nr_ranges++; > } > > - /* Exclude crashkernel region */ > - ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end); > - if (ret < 0) > - goto out; > - > - if (crashk_low_res.end) { > - ret = crash_exclude_mem_range(cmem, crashk_low_res.start, crashk_low_res.end); > - if (ret < 0) > - goto out; > - } > - > - ret = crash_prepare_elf64_headers(cmem, true, addr, sz); > - > -out: > - kfree(cmem); > - return ret; > + return 0; > } > > /* > @@ -163,7 +147,7 @@ int load_other_segments(struct kimage *image, > void *headers; > unsigned long headers_sz; > > - ret = prepare_elf_headers(&headers, &headers_sz); > + ret = crash_prepare_headers(true, &headers, &headers_sz, NULL); > if (ret < 0) { > pr_err("Preparing elf core header failed\n"); > goto out_err;