Skip to contentSkip to conversation

Support kexec_file on 32-bit RISC-V

PATCH In review Palmer Dabbelt 2 participants 10 messages Jun 24, 2022 – Jun 30, 2022

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v2 cover Support kexec_file on 32-bit RISC-V

This rolled itself back to the top of my inbox, so I figured I'd send it again as Rob's review landed. IMO the security/integrity/ima/ change is sufficiently trivial that it's fine to take it through the RISC-V tree but I don't have an Review/Ack so I'll wait until this loops back again to give the security/integrity/ folks a chance to chime in.

If this loops back to the top of my queue (which looks about a month deep right now) without any comments then I'll put it in riscv/for-next.

Thanks!

Changes since v1
<https://lore.kernel.org/all/[email protected]/>
* Collected reviews for drivers/of/kexec.c.

#1 lore raw

PATCH v2 1/5 drivers: of: kexec ima: Support 32-bit platforms

RISC-V recently added kexec_file() support, which uses enables kexec IMA. We're the first 32-bit platform to support this, so we found a build bug.

---
 drivers/of/kexec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/of/kexec.c +2 -2
index b9bd1cff1793..ed3451ec2b24 100644
@@ -236,8 +236,8 @@ static int setup_ima_buffer(const struct kimage *image, void *fdt,
 	if (ret)
 		return -EINVAL;
 
-	pr_debug("IMA buffer at 0x%llx, size = 0x%zx\n",
-		 image->ima_buffer_addr, image->ima_buffer_size);
+	pr_debug("IMA buffer at 0x%pa, size = 0x%zx\n",
+		 &image->ima_buffer_addr, image->ima_buffer_size);
 
 	return 0;
 }
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 2/5 ima: Fix a build issue on 32-bit platforms

In reply to Palmer Dabbelt

ima_dump_measurement_list() took an "unsigned long *", but was passed a size_t. This triggers build warnings on 32-bit RISC-V.

---
 security/integrity/ima/ima_kexec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/integrity/ima/ima_kexec.c +1 -1
index 13753136f03f..f2a94ec3002a 100644
@@ -15,7 +15,7 @@
 #include "ima.h"
 
 #ifdef CONFIG_IMA_KEXEC
-static int ima_dump_measurement_list(unsigned long *buffer_size, void **buffer,
+static int ima_dump_measurement_list(size_t *buffer_size, void **buffer,
 				     unsigned long segment_size)
 {
 	struct ima_queue_entry *qe;
Signature · 1 line
2.34.1
#6 lore raw

PATCH v2 3/5 RISC-V: kexec: Use Elf64 on 64-bit targets

In reply to Palmer Dabbelt

Most of the Elf macros automatically select the correct Elf type, this converts the one explicit Elf64 usage to depend on XLEN.

---
 arch/riscv/kernel/elf_kexec.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/riscv/kernel/elf_kexec.c +7 -1
index 9cb85095fd45..4532e3cf17a5 100644
@@ -342,6 +342,12 @@ static void *elf_kexec_load(struct kimage *image, char *kernel_buf,
 #define CLEAN_IMM(type, x) \
 	((~ENCODE_##type##_IMM((uint64_t)(-1))) & (x))
 
+#if __riscv_xlen == 32
+#define ELFN(T) ELF32 ## T
+#else
+#define ELFN(T) ELF64 ## T
+#endif
+
 int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
 				     Elf_Shdr *section,
 				     const Elf_Shdr *relsec,
@@ -367,7 +373,7 @@ int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
 		void *loc;		/* tmp location to modify */
 
 		sym = (void *)pi->ehdr + symtab->sh_offset;
-		sym += ELF64_R_SYM(relas[i].r_info);
+		sym += ELFN(_R_SYM)(relas[i].r_info);
 
 		if (sym->st_name)
 			name = strtab + sym->st_name;
Signature · 1 line
2.34.1
#7 lore raw

PATCH v2 4/5 RISC-V: purgatory: Use XLEN-length loads to support rv32

In reply to Palmer Dabbelt

This uses an explicit "ld" to load up target address, which dosn't work on rv32. Convert it to a REG_L macro, like everywhere else.

---
 arch/riscv/purgatory/entry.S | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/riscv/purgatory/entry.S +4 -2
index 0194f4554130..71c50fef051c 100644
@@ -8,6 +8,8 @@
  *
  */
 
+#include <asm/asm.h>
+
 .macro	size, sym:req
 	.size \sym, . - \sym
 .endm
@@ -26,7 +28,7 @@ purgatory_start:
 	/* Start new image. */
 	mv	a0, s0
 	mv	a1, s1
-	ld	a2, riscv_kernel_entry
+	REG_L	a2, riscv_kernel_entry
 	jr	a2
 
 size purgatory_start
@@ -41,7 +43,7 @@ size purgatory_start
 
 .globl riscv_kernel_entry
 riscv_kernel_entry:
-	.quad	0
+	REG_ASM	0
 size riscv_kernel_entry
 
 .end
Signature · 1 line
2.34.1
#8 lore raw

PATCH v2 5/5 RISC-V: Allow kexec_file() on 32-bit platforms

In reply to Palmer Dabbelt

With the build issues now sorted out we can enable kexec_file() on 32-bit platforms as well.

---
 arch/riscv/Kconfig | 1 -
 1 file changed, 1 deletion(-)
arch/riscv/Kconfig +0 -1
index 898052ff743e..a246f2fe60c2 100644
@@ -388,7 +388,6 @@ config KEXEC_FILE
 	select KEXEC_CORE
 	select KEXEC_ELF
 	select HAVE_IMA_KEXEC if IMA
-	depends on 64BIT
 	help
 	  This is new version of kexec system call. This system call is
 	  file based and takes file descriptors as system call argument
Signature · 1 line
2.34.1
maintainer
#9 lore raw
In reply to Palmer Dabbelt

Hi Palmer,

Quoted 6 lines · Palmer Dabbelt

This rolled itself back to the top of my inbox, so I figured I'd send it again as Rob's review landed. IMO the security/integrity/ima/ change is sufficiently trivial that it's fine to take it through the RISC-V tree but I don't have an Review/Ack so I'll wait until this loops back again to give the security/integrity/ folks a chance to chime in.

Quoted 8 lines

If this loops back to the top of my queue (which looks about a month deep right now) without any comments then I'll put it in riscv/for-next.

Thanks!

Changes since v1
<https://lore.kernel.org/all/[email protected]/>
* Collected reviews for drivers/of/kexec.c.

Maybe better that you upstream the RISC-V changes. So far there aren't any merge conflicts with this patchset, but a number of other kexec patch sets will hopefully be upstreamed in the coming open window. I'd appreciate if you could create a topic branch for the first two patches.

thanks,

Mimi