All of lore.kernel.org
 help / color / mirror / Atom feed
From: Youling Tang <youling.tang@linux.dev>
To: Simon Horman <horms@verge.net.au>
Cc: Simon Horman <horms@kernel.org>,
	Huacai Chen <chenhuacai@kernel.org>,
	kexec@lists.infradead.org, youling.tang@linux.dev,
	Youling Tang <tangyouling@kylinos.cn>
Subject: [PATCH v2 06/10] LoongArch: Fix the use of loongarch_image_header in ELF format
Date: Tue, 16 Sep 2025 09:46:51 +0800	[thread overview]
Message-ID: <20250916014655.841632-7-youling.tang@linux.dev> (raw)
In-Reply-To: <20250916014655.841632-1-youling.tang@linux.dev>

From: Youling Tang <tangyouling@kylinos.cn>

loongarch_image_header should not be used in the ELF format. When the CONFIG_EFI_STUB
configuration is turned off, the ELF kernel image will not add loongarch_image_heade
processing, as can be seen from the kernel code arch/loongarch/kernel/head.S.

Thus, use the elf header content to fix this issue.

Signed-off-by: Youling Tang <tangyouling@kylinos.cn>
---
 kexec/arch/loongarch/image-header.h        |  2 +-
 kexec/arch/loongarch/kexec-elf-loongarch.c | 12 ++++--------
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/kexec/arch/loongarch/image-header.h b/kexec/arch/loongarch/image-header.h
index 223d81f..0db7615 100644
--- a/kexec/arch/loongarch/image-header.h
+++ b/kexec/arch/loongarch/image-header.h
@@ -1,5 +1,5 @@
 /*
- * LoongArch binary image header.
+ * LoongArch binary image header. (for pei/pez format)
  */
 
 #if !defined(__LOONGARCH_IMAGE_HEADER_H)
diff --git a/kexec/arch/loongarch/kexec-elf-loongarch.c b/kexec/arch/loongarch/kexec-elf-loongarch.c
index 44b63a9..92fa9f8 100644
--- a/kexec/arch/loongarch/kexec-elf-loongarch.c
+++ b/kexec/arch/loongarch/kexec-elf-loongarch.c
@@ -72,7 +72,6 @@ static bool laabs_section(const struct mem_ehdr *ehdr)
 int elf_loongarch_load(int argc, char **argv, const char *kernel_buf,
 	off_t kernel_size, struct kexec_info *info)
 {
-	const struct loongarch_image_header *header = NULL;
 	unsigned long kernel_segment;
 	struct mem_ehdr ehdr;
 	int result;
@@ -95,22 +94,19 @@ int elf_loongarch_load(int argc, char **argv, const char *kernel_buf,
 		}
 	}
 
-	/* Find and process the loongarch image header. */
 	for (i = 0; i < ehdr.e_phnum; i++) {
 		struct mem_phdr *phdr = &ehdr.e_phdr[i];
 
 		if (phdr->p_type != PT_LOAD)
 			continue;
 
-		header = (const struct loongarch_image_header *)(
-			kernel_buf + phdr->p_offset);
-
-		if (!loongarch_process_image_header(header))
-			break;
+		loongarch_mem.text_offset = virt_to_phys(phdr->p_paddr);
+		loongarch_mem.image_size = _ALIGN_UP(phdr->p_memsz, KiB(64));
+		break;
 	}
 
 	if (i == ehdr.e_phnum) {
-		dbgprintf("%s: Valid loongarch image header not found\n", __func__);
+		dbgprintf("%s: Valid loongarch phdr not found\n", __func__);
 		result = EFAILED;
 		goto exit;
 	}
-- 
2.34.1



  parent reply	other threads:[~2025-09-16  1:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-16  1:46 [PATCH v2 00/10] Fix and improve the LoongArch implementation Youling Tang
2025-09-16  1:46 ` [PATCH v2 01/10] kexec: Handle removal of multiple 'crashkernel' parameters Youling Tang
2025-09-16  1:46 ` [PATCH v2 02/10] LoongArch: Fix comments Youling Tang
2025-09-16  1:46 ` [PATCH v2 03/10] LoongArch: Terminate the cmdline string using '\0' Youling Tang
2025-09-16  1:46 ` [PATCH v2 04/10] LoongArch: Enforce relocatable kernel check for crash dump Youling Tang
2025-09-16  1:46 ` [PATCH v2 05/10] LoongArch: Change initrd allocation to top-down Youling Tang
2025-09-16  1:46 ` Youling Tang [this message]
2025-09-16  1:46 ` [PATCH v2 07/10] LoongArch: Add pe_hdr->machine check for pei format images Youling Tang
2025-09-16  1:46 ` [PATCH v2 08/10] LoongArch/pez: Fix kernel_fd handling when kexec_file is supported Youling Tang
2025-09-16  1:46 ` [PATCH v2 09/10] LoongArch: Add kexec_file_load syscall Youling Tang
2025-09-16  1:46 ` [PATCH v2 10/10] LoongArch: Remove 'kexec_file' cmdline parameters when using --reuse-cmdline option Youling Tang
2025-09-23 16:51 ` [PATCH v2 00/10] Fix and improve the LoongArch implementation Simon Horman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250916014655.841632-7-youling.tang@linux.dev \
    --to=youling.tang@linux.dev \
    --cc=chenhuacai@kernel.org \
    --cc=horms@kernel.org \
    --cc=horms@verge.net.au \
    --cc=kexec@lists.infradead.org \
    --cc=tangyouling@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.