From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=113.46.200.223 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795774197; b=YAlvuek1NbFR+Jv50a10C7gMWDmXRSszNr6sYW6kv25b+8h7NfmRG/Gp4EOK1Yl75d2+ O8a5lz/GpB78Fj4Rslq7iZ4yMqEYj4y4+ajAAun9vzNPc4ZCFCQ5TKbTGhn3EiIDbYY+M qp5B1p5KI4kxw0Nq3+5/NEi7Lrx1HSqNNIvS+zqdyX56Fa574eL93pifZ9PBGs1o36eYI ebrIbBYyflWlUp52p+Y822GowbTO4vFGDjpoOGHv6mOG7x8GWSyLLGF7hhllkp/PK60YO +kv1tij8OxnxrTkWEU2mGftw0wh4psvVzW9wpbXp21neDUemUn6f9NsBlkPqw0yv0TQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795774197; h=DMARC-Filter:dkim-signature:Received:Received:Received:From:To:CC: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy; bh=HVSl6b5c2ppW1s1gs/r7uBuxxOLF4+FVkqsE8xMgcNA=; b=BLZa0hC8km9MDL2raMG4OabCNxDuxOWow8qyiD5c2ktY6DPKNqhQKDuwDpsCQBaq6p7Z FYrfY3OJO8S9yT1nZl7m3b1/ZZn0wt8R7qqT4fw/4FFo4opG0ArKSMTeQZjWhPkE5p4zt AmMSTx40nxxCFzmkPAQP/eKIDZ2Id1SrIbxCzTZyKnbQCI8hRUYnKdVQEAhykMoeviA1d wvBIGo76TOd0qN9zrRr/NKZdo1SeXT21EcuftzHVQCTjRpiRZ0ZHK5rn1/nwv6GE42KIq DznvvvIunwD85BB0F5UajR1riLxg7JwAbM2mANK7xKIAZ0QXh9EWhcYoheGERdzPQlQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=NpzGw6+M; arc=none smtp.remote-ip=113.46.200.223 Received: from canpmsgout08.his.huawei.com (canpmsgout08.his.huawei.com [113.46.200.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE1BB606A686; Fri, 27 Nov 2026 10:09:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AE1BB606A686 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.a=rsa-sha256 header.s=dkim header.b=NpzGw6+M dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=HVSl6b5c2ppW1s1gs/r7uBuxxOLF4+FVkqsE8xMgcNA=; b=NpzGw6+Maniy/c5MFunJnf7wYcJsTElQBOF11nkTDHOYpouatcIxn5TFiqapwtGxM9OjZyrR1 TjAEvlfSdFw+Eht4lbqYKdx5cVBPVpmFaS4uJrWbfyerOyiQmo7VA/zEJ3wsz3dYt2x3UKAuBRS 2WydvfmGfe+/sQQ/ctn39Lw= Received: from mail.maildlp.com (unknown [172.19.163.15]) by canpmsgout08.his.huawei.com (SkyGuard) with ESMTPS id 4jbTfQ69fTzmV63; Fri, 27 Nov 2026 18:09:18 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id D818B40586; Fri, 27 Nov 2026 18:09:43 +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; Fri, 27 Nov 2026 18:09:41 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v9 01/11] kexec: Free the elf core header in kimage_file_post_load_cleanup() Date: Fri, 27 Nov 2026 18:09:15 +0800 Message-ID: <20261127100925.3019877-2-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261127100925.3019877-1-ruanjinjie@huawei.com> References: <20261127100925.3019877-1-ruanjinjie@huawei.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 elf core header buffer is generic state, but arm64, LoongArch, RISC-V, x86 and powerpc each free it in their post-load cleanup. Move it into the generic cleanup, which also gives the loader a helper to release it on error. Cc: Catalin Marinas Cc: Will Deacon Cc: Huacai Chen Cc: Palmer Dabbelt Cc: Alexandre Ghiti Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: Michael Ellerman Cc: Nicholas Piggin Cc: Christophe Leroy Cc: Andrew Morton Cc: Baoquan He Cc: Mike Rapoport Signed-off-by: Jinjie Ruan --- arch/arm64/kernel/machine_kexec_file.c | 4 ---- arch/loongarch/kernel/machine_kexec_file.c | 4 ---- arch/powerpc/kexec/file_load_64.c | 4 ---- arch/riscv/kernel/machine_kexec_file.c | 4 ---- arch/x86/kernel/machine_kexec_64.c | 4 ---- kernel/kexec_file.c | 9 +++++++++ 6 files changed, 9 insertions(+), 20 deletions(-) diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c index 14f453dd0946..097ee397e949 100644 --- a/arch/arm64/kernel/machine_kexec_file.c +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -32,10 +32,6 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) kvfree(image->arch.dtb); image->arch.dtb = NULL; - vfree(image->elf_headers); - image->elf_headers = NULL; - image->elf_headers_sz = 0; - return kexec_image_post_load_cleanup_default(image); } diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/kernel/machine_kexec_file.c index 0fe60907b97f..f16d9ab14726 100644 --- a/arch/loongarch/kernel/machine_kexec_file.c +++ b/arch/loongarch/kernel/machine_kexec_file.c @@ -28,10 +28,6 @@ const struct kexec_file_ops * const kexec_file_loaders[] = { int arch_kimage_file_post_load_cleanup(struct kimage *image) { - vfree(image->elf_headers); - image->elf_headers = NULL; - image->elf_headers_sz = 0; - return kexec_image_post_load_cleanup_default(image); } diff --git a/arch/powerpc/kexec/file_load_64.c b/arch/powerpc/kexec/file_load_64.c index bd80c5fb1b1f..0cf03cee35a7 100644 --- a/arch/powerpc/kexec/file_load_64.c +++ b/arch/powerpc/kexec/file_load_64.c @@ -841,10 +841,6 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) vfree(image->arch.backup_buf); image->arch.backup_buf = NULL; - vfree(image->elf_headers); - image->elf_headers = NULL; - image->elf_headers_sz = 0; - kvfree(image->arch.fdt); image->arch.fdt = NULL; diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/machine_kexec_file.c index 26cd2a8bd0cd..1d67fb42617a 100644 --- a/arch/riscv/kernel/machine_kexec_file.c +++ b/arch/riscv/kernel/machine_kexec_file.c @@ -29,10 +29,6 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image) kvfree(image->arch.fdt); image->arch.fdt = NULL; - vfree(image->elf_headers); - image->elf_headers = NULL; - image->elf_headers_sz = 0; - return kexec_image_post_load_cleanup_default(image); } diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c index c3f4a389992d..0a66cc268ee7 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -600,10 +600,6 @@ int arch_kexec_apply_relocations_add(struct purgatory_info *pi, int arch_kimage_file_post_load_cleanup(struct kimage *image) { - vfree(image->elf_headers); - image->elf_headers = NULL; - image->elf_headers_sz = 0; - return kexec_image_post_load_cleanup_default(image); } #endif /* CONFIG_KEXEC_FILE */ diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index b668ce8d68ee..1f128c6e6fa3 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -102,6 +102,13 @@ int kexec_image_post_load_cleanup_default(struct kimage *image) return image->fops->cleanup(image->image_loader_data); } +static void kexec_free_elf_headers(struct kimage *image) +{ + vfree(image->elf_headers); + image->elf_headers = NULL; + image->elf_headers_sz = 0; +} + /* * Free up memory used by kernel, initrd, and command line. This is temporary * memory allocation which is not needed any more after these buffers have @@ -120,6 +127,8 @@ void kimage_file_post_load_cleanup(struct kimage *image) kfree(image->cmdline_buf); image->cmdline_buf = NULL; + kexec_free_elf_headers(image); + vfree(pi->purgatory_buf); pi->purgatory_buf = NULL; -- 2.34.1