Skip to contentSkip to conversation

riscv: Resolve module loading issues

PATCH Superseded Charlie Jenkins 3 participants 5 messages Nov 17, 2023 – Nov 21, 2023 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover riscv: Resolve module loading issues

Previous commits caused compilation of module linking tests to fail on rv32 toolchains with uleb128 support. The first patch resolves that issue. The second patch resolves the type issues pointed out by sparse.

---
Charlie Jenkins (2):
Support rv32 ULEB128 test
Correct type casting in module loading

 arch/riscv/kernel/module.c                         | 8 ++++----
 arch/riscv/kernel/tests/module_test/test_uleb128.S | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

---
base-commit: 9bacdd8996c77c42ca004440be610692275ff9d0
change-id: 20231117-module_fixup-699787d9c567

Signature · 1 line
- Charlie
#1 lore raw

PATCH 1/2 Support rv32 ULEB128 test

Use opcodes available to both rv32 and rv64 in uleb128 module linking test.

Fixes af71bc194916 ("riscv: Add tests for riscv module loading")
---
 arch/riscv/kernel/tests/module_test/test_uleb128.S | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/riscv/kernel/tests/module_test/test_uleb128.S +4 -4
index 90f22049d553..8515ed7cd8c1 100644
@@ -6,13 +6,13 @@
 .text
 .global test_uleb_basic
 test_uleb_basic:
-	ld	a0, second
+	lw	a0, second
 	addi	a0, a0, -127
 	ret
 
 .global test_uleb_large
 test_uleb_large:
-	ld	a0, fourth
+	lw	a0, fourth
 	addi	a0, a0, -0x07e8
 	ret
 
@@ -22,10 +22,10 @@ first:
 second:
 	.reloc second, R_RISCV_SET_ULEB128, second
 	.reloc second, R_RISCV_SUB_ULEB128, first
-	.dword 0
+	.word 0
 third:
 	.space 1000
 fourth:
 	.reloc fourth, R_RISCV_SET_ULEB128, fourth
 	.reloc fourth, R_RISCV_SUB_ULEB128, third
-	.dword 0
+	.word 0
Signature · 1 line
2.34.1
Tested-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] Support rv32 ULEB128 test

Quoted 5 lines · Charlie Jenkins

Use opcodes available to both rv32 and rv64 in uleb128 module linking test.

Fixes af71bc194916 ("riscv: Add tests for riscv module loading")

Thanks.

Quoted 38 lines
---
 arch/riscv/kernel/tests/module_test/test_uleb128.S | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/riscv/kernel/tests/module_test/test_uleb128.S +4 -4
index 90f22049d553..8515ed7cd8c1 100644
@@ -6,13 +6,13 @@
 .text
 .global test_uleb_basic
 test_uleb_basic:
-	ld	a0, second
+	lw	a0, second
 	addi	a0, a0, -127
 	ret
 
 .global test_uleb_large
 test_uleb_large:
-	ld	a0, fourth
+	lw	a0, fourth
 	addi	a0, a0, -0x07e8
 	ret
 
@@ -22,10 +22,10 @@ first:
 second:
 	.reloc second, R_RISCV_SET_ULEB128, second
 	.reloc second, R_RISCV_SUB_ULEB128, first
-	.dword 0
+	.word 0
 third:
 	.space 1000
 fourth:
 	.reloc fourth, R_RISCV_SET_ULEB128, fourth
 	.reloc fourth, R_RISCV_SUB_ULEB128, third
-	.dword 0
+	.word 0
Signature · 6 lines
~Randy

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#3 lore raw

PATCH 2/2 Correct type casting in module loading

In reply to Charlie Jenkins

Make static variables static and use __le16.

Fixes 8fd6c5142395 ("riscv: Add remaining module relocations")
---
 arch/riscv/kernel/module.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/riscv/kernel/module.c +4 -4
index 56a8c78e9e21..9f2dc2c0e436 100644
@@ -45,9 +45,9 @@ void process_accumulated_relocations(struct module *me);
 int add_relocation_to_accumulate(struct module *me, int type, void *location,
 				 unsigned int hashtable_bits, Elf_Addr v);
 
-struct hlist_head *relocation_hashtable;
+static struct hlist_head *relocation_hashtable;
 
-struct list_head used_buckets_list;
+static struct list_head used_buckets_list;
 
 /*
  * The auipc+jalr instruction pair can reach any PC-relative offset
@@ -64,7 +64,7 @@ static bool riscv_insn_valid_32bit_offset(ptrdiff_t val)
 
 static int riscv_insn_rmw(void *location, u32 keep, u32 set)
 {
-	u16 *parcel = location;
+	__le16 *parcel = location;
 	u32 insn = (u32)le16_to_cpu(parcel[0]) | (u32)le16_to_cpu(parcel[1]) << 16;
 
 	insn &= keep;
@@ -77,7 +77,7 @@ static int riscv_insn_rmw(void *location, u32 keep, u32 set)
 
 static int riscv_insn_rvc_rmw(void *location, u16 keep, u16 set)
 {
-	u16 *parcel = location;
+	__le16 *parcel = location;
 	u16 insn = le16_to_cpu(*parcel);
 
 	insn &= keep;
Signature · 1 line
2.34.1
Reviewed-by Tested-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] Correct type casting in module loading

Quoted 7 lines · Charlie Jenkins

Make static variables static and use __le16.

Fixes 8fd6c5142395 ("riscv: Add remaining module relocations")
---
 arch/riscv/kernel/module.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)