From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout10.his.huawei.com (canpmsgout10.his.huawei.com [113.46.200.225]) (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 896C146AA65 for ; Mon, 21 Sep 2026 09:04:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.225 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789981468; cv=none; b=UsFQHOAFXARpW+yE5ihhaLOrAZC6V+/kHjCwmS1/9k0KNXIook+mqGJH98KzmdtlHKM4KCSg8PEGW0hGl/cs7uGVAexA5W59r++cYxmP/R3d/pNbgSqzxwgK+xb5LQsLzIpv5g5fdgTl5W9xyIivTKMgk9E8EEmlx1m0/wkxx34= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789981468; c=relaxed/simple; bh=bSE83igYe1W35rdRuNP69UJytL/ftjAhu118zl3lzcA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AcnMwkaVA+c4ACZEu6OlVYWPD/xePpdkFUP5XgEZD1cZszn/xne8drKpIZdQDeYHidervcf/aYMBhAaIPkXOE2P0DVuDMSheLsb2uictoke2zLzeDShapgwk3O7C20nf1hrSNEyUPNuS5oFEf4VM3n9fYm9NEyKzjyYHlnGpjFk= 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=Xk3K1Lag; arc=none smtp.client-ip=113.46.200.225 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="Xk3K1Lag" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=oJTPjIaIqy30CyW5gdpqj1ltYgKaERSOMcSOuwRttqY=; b=Xk3K1Lag16/7PUJwSJwRKAWcXn51YKwa9K4bTVig/jzNn34hk7LewtIKmtx+01VSKzFVqRzzQ wGiFlBwGpaMhKzr9S/eyYz1vcdeUtXIbZr9e9FiAHiBznYDu4EF1evoWFkMInlmtdm/yuNtiMKX /P1HTZPUO81RTQgB5/AToOM= Received: from mail.maildlp.com (unknown [172.19.163.15]) by canpmsgout10.his.huawei.com (SkyGuard) with ESMTPS id 4hpH7b1rDqz1K9D2; Mon, 21 Sep 2026 16:53:15 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id 2860E40586; Mon, 21 Sep 2026 17:04:17 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Mon, 21 Sep 2026 17:04:15 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v6 11/14] crash: Factor out crash_find_elfcorehdr() helper Date: Mon, 21 Sep 2026 17:04:47 +0800 Message-ID: <20260921090450.807575-12-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260921090450.807575-1-ruanjinjie@huawei.com> References: <20260921090450.807575-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemk200008.china.huawei.com (7.202.194.74) The elfcorehdr segment is located by scanning the segments for the ELF magic. Factor that scan out into a new helper function, crash_find_elfcorehdr(), to clean up crash_handle_hotplug_event() and prepare for its reuse in crash hotplug code. Cc: Andrew Morton Cc: Baoquan He Cc: Mike Rapoport Cc: Pasha Tatashin Cc: Pratyush Yadav Cc: Dave Young Cc: Breno Leitao Signed-off-by: Jinjie Ruan --- kernel/crash_core.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 406b68d2adfd..4a990b17b66c 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -647,6 +647,28 @@ int crash_check_hotplug_support(void) return rc; } +static void crash_find_elfcorehdr(struct kimage *image) +{ + unsigned char *ptr; + unsigned long mem; + unsigned int n; + + if (image->elfcorehdr_index >= 0) + return; + + for (n = 0; n < image->nr_segments; n++) { + mem = image->segment[n].mem; + ptr = kmap_local_page(pfn_to_page(mem >> PAGE_SHIFT)); + if (!ptr) + continue; + + /* The segment containing elfcorehdr */ + if (memcmp(ptr, ELFMAG, SELFMAG) == 0) + image->elfcorehdr_index = (int)n; + kunmap_local(ptr); + } +} + /* * To accurately reflect hot un/plug changes of CPU and Memory resources * (including onling and offlining of those resources), the relevant @@ -702,22 +724,7 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu, * is allocated. Find the segment containing the elfcorehdr, * if not already found. */ - if (image->elfcorehdr_index < 0) { - unsigned long mem; - unsigned char *ptr; - unsigned int n; - - for (n = 0; n < image->nr_segments; n++) { - mem = image->segment[n].mem; - ptr = kmap_local_page(pfn_to_page(mem >> PAGE_SHIFT)); - if (ptr) { - /* The segment containing elfcorehdr */ - if (memcmp(ptr, ELFMAG, SELFMAG) == 0) - image->elfcorehdr_index = (int)n; - kunmap_local(ptr); - } - } - } + crash_find_elfcorehdr(image); if (image->elfcorehdr_index < 0) { pr_err("unable to locate elfcorehdr segment"); -- 2.34.1