From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 23D7FCD6E56 for ; Mon, 1 Jun 2026 09:51:22 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4gTThb4jTlz2ytJ; Mon, 01 Jun 2026 19:49:51 +1000 (AEST) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=113.46.200.222 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1780307391; cv=none; b=RDyUDhQDz8UXb1jlXDHSK7FYxN5b2t/RkLvRQuc7P1ZAHt1p/1m0uJcb+M/HAlQUJSaAC37fOfEntiuoBWIrhkrNV44bRD7whaN1I2JEZSLyrsmf/JHQEMKaWGd9995xUJ8xwdV1mRnPzE0XZFxJtozC7qEZo/r60NKZtwoPcUymKJfaJhvt38wHX3xL8kYD694RH5KN9B40xUGim5LP3/pqX4M6jmjSw/lQ9d4/aXsXnDDjQ8s8qAZiEvOkqgcskIO1lULifI/Aqw1TMfd4CXC5d4/AxdvZddMA6d9Jy6r44fY5ox/c0mhFMgXfYvBHkF3Wmi+sA/gfvGaN47ZH4w== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1780307391; c=relaxed/relaxed; bh=VWBV2U5yMqcbh55EfObhiotNmBAp32Br2+ez2EoTpng=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fKffEA9W1I2XpAs+8I+qB0+EB0t99SArvR2XAJvkFdvNtPMZF4znJyJ75u6QICKlpj0kCYAbc2rRNhwAcVahFf6vow9WWZlXiWHJzW0Q2cX94FH2s5tgVVP84LOkqE38GCK7nINJoMVvjiZur7ixRcSNXLrTATmUH6gbiN119rCfa0CEyoP9H/1814/NVUP/KcBRz2sWsOlun8vIwhEzsplbWgaLts3D+4FO5Ve+mL1ZVeOwhluEP/POqLIR5AUJ+IA6a37vqFz3hyaH3gwqSakTwj6hBwisy0l/g96L+98cFgi4kldm+mctdg+fFB22xSWST1/fnS31c6dEkThB0g== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; dkim=pass (1024-bit key; unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=r9ZH1ej6; dkim-atps=neutral; spf=pass (client-ip=113.46.200.222; helo=canpmsgout07.his.huawei.com; envelope-from=ruanjinjie@huawei.com; receiver=lists.ozlabs.org) smtp.mailfrom=huawei.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=r9ZH1ej6; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=huawei.com (client-ip=113.46.200.222; helo=canpmsgout07.his.huawei.com; envelope-from=ruanjinjie@huawei.com; receiver=lists.ozlabs.org) Received: from canpmsgout07.his.huawei.com (canpmsgout07.his.huawei.com [113.46.200.222]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4gTThZ5PkWz3brC for ; Mon, 01 Jun 2026 19:49:50 +1000 (AEST) dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=VWBV2U5yMqcbh55EfObhiotNmBAp32Br2+ez2EoTpng=; b=r9ZH1ej6irADfT920XCGsNsznQD6yaMW19Luu1KKuC4Ox05HYGKMHMLbII4nYiAtxt+71DWk0 1DM+CHqbX5q/kzgSTvf7G65UhYBCRcchDTXMVus5Ri3KMrBxZEbUz1D6gP0zk1Fpt0/im4+E3Ey ER+lFBDEgbNoYLR/APqpYQE= Received: from mail.maildlp.com (unknown [172.19.163.200]) by canpmsgout07.his.huawei.com (SkyGuard) with ESMTPS id 4gTTWX1QtdzLlwm; Mon, 1 Jun 2026 17:42:00 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 8591A40563; Mon, 1 Jun 2026 17:49:48 +0800 (CST) Received: from huawei.com (10.90.53.73) 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, 1 Jun 2026 17:49:44 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v15 19/23] LoongArch: kexec_file: Use crash_prepare_headers() helper to simplify code Date: Mon, 1 Jun 2026 17:48:01 +0800 Message-ID: <20260601094805.2928614-20-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260601094805.2928614-1-ruanjinjie@huawei.com> References: <20260601094805.2928614-1-ruanjinjie@huawei.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To dggpemf500011.china.huawei.com (7.185.36.131) 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 | 48 +++++++--------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/kernel/machine_kexec_file.c index 3c369124586e..f3101bea9e45 100644 --- a/arch/loongarch/kernel/machine_kexec_file.c +++ b/arch/loongarch/kernel/machine_kexec_file.c @@ -56,52 +56,34 @@ 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; + /* for exclusion of crashkernel region */ + int nr_ranges = 2 + CRASH_HOTPLUG_SAFETY_PADDING; phys_addr_t start, end; - struct crash_mem *cmem; + uint64_t i; - /* for exclusion of crashkernel region */ - nr_ranges = 2 + CRASH_HOTPLUG_SAFETY_PADDING; 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) { - if (unlikely(cmem->nr_ranges >= cmem->max_nr_ranges)) { - ret = -EAGAIN; - goto out; - } + if (unlikely(cmem->nr_ranges >= cmem->max_nr_ranges)) + return -EAGAIN; 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; } /* @@ -169,7 +151,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; -- 2.34.1