riscv: Add remaining module relocations#334
Conversation
community inclusion category: revert bugzilla: RVCK-Project#310 ------------------------------------------------- This reverts commit 56d768f. The relevant optimization is implemented in the upstream Linux kernel in commit 080c432 (“riscv: optimize ELF relocation function in riscv”). Before performing a backport, revert this vendor patch. Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
mainline inclusion from mainline-v6.7 commit 8cbe0ac category: bugfix bugzilla: RVCK-Project#310 -------------------------------- With the C-extension regular 32bit instructions are not necessarily aligned on 4-byte boundaries. RISC-V instructions are in fact an ordered list of 16bit little-endian "parcels", so access the instruction as such. This should also make the code work in case someone builds a big-endian RISC-V machine. Signed-off-by: Emil Renner Berthing <kernel@esmil.dk> Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> Link: https://lore.kernel.org/r/20231101-module_relocations-v9-1-8dfa3483c400@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com> Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
mainline inclusion from mainline-v6.7 commit 8fd6c51 category: bugfix bugzilla: RVCK-Project#310 -------------------------------- Add all final module relocations and add error logs explaining the ones that are not supported. Implement overflow checks for ADD/SUB/SET/ULEB128 relocations. Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> Link: https://lore.kernel.org/r/20231101-module_relocations-v9-2-8dfa3483c400@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com> Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
mainline inclusion from mainline-v6.7 commit 28ea54b category: bugfix bugzilla: RVCK-Project#310 -------------------------------- Without this I get a bunch of warnings along the lines of arch/riscv/kernel/module.c:535:26: error: positional initialization of field in 'struct' declared with 'designated_init' attribute [-Werror=designated-init] 535 | [R_RISCV_32] = { apply_r_riscv_32_rela }, This just mades the member initializers explicit instead of positional. I also aligned some of the table, but mostly just to make the batch editing go faster. Fixes: b51fc88 ("Merge patch series "riscv: Add remaining module relocations and tests"") Reviewed-by: Charlie Jenkins <charlie@rivosinc.com> Link: https://lore.kernel.org/r/20231107155529.8368-1-palmer@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com> Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
mainline inclusion from mainline-v6.7 commit d8792a5 category: bugfix bugzilla: RVCK-Project#310 -------------------------------- Use the safe versions of list and hlist iteration to safely remove entries from the module relocation lists. To allow mutliple threads to load modules concurrently, move relocation list pointers onto the stack rather than using global variables. Fixes: 8fd6c51 ("riscv: Add remaining module relocations") Reported-by: Ron Economos <re@w6rz.net> Closes: https://lore.kernel.org/linux-riscv/444de86a-7e7c-4de7-5d1d-c1c40eefa4ba@w6rz.net Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> Tested-by: Björn Töpel <bjorn@rivosinc.com> Link: https://lore.kernel.org/r/20231127-module_linking_freeing-v4-1-a2ca1d7027d0@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com> Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
mainline inclusion from mainline-v6.7 commit 4a92a87 category: bugfix bugzilla: RVCK-Project#310 -------------------------------- Use __le16 with le16_to_cpu. Fixes: 8fd6c51 ("riscv: Add remaining module relocations") Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Björn Töpel <bjorn@rivosinc.com> Link: https://lore.kernel.org/r/20231127-module_linking_freeing-v4-2-a2ca1d7027d0@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com> Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
mainline inclusion from mainline-v6.15 commit 1ee1313 category: bugfix bugzilla: RVCK-Project#310 -------------------------------- apply_r_riscv_plt32_rela() may need to emit a PLT entry for the referenced symbol, so there must be space allocated in the PLT. Fixes: 8fd6c51 ("riscv: Add remaining module relocations") Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Link: https://lore.kernel.org/r/20250409171526.862481-2-samuel.holland@sifive.com Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
mainline inclusion from mainline-v6.8 commit 78996ee category: bugfix bugzilla: RVCK-Project#310 -------------------------------- Reverse order of kfree calls to resolve use-after-free error. Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> Fixes: d8792a5 ("riscv: Safely remove entries from relocation list") Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <error27@gmail.com> Closes: https://lore.kernel.org/r/202312132019.iYGTwW0L-lkp@intel.com/ Reported-by: kernel test robot <lkp@intel.com> Reported-by: Julia Lawall <julia.lawall@inria.fr> Closes: https://lore.kernel.org/r/202312120044.wTI1Uyaa-lkp@intel.com/ Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org> Link: https://lore.kernel.org/r/20240104-module_loading_fix-v3-1-a71f8de6ce0f@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com> Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
mainline inclusion from mainline-v6.8 commit 4b38b36 category: bugfix bugzilla: RVCK-Project#310 -------------------------------- When there is not enough allocatable memory for the relocation hashtable, module loading should exit gracefully. Previously, this was attempted to be accomplished by checking if an unsigned number is less than zero which does not work. Instead have the caller check if the hashtable was correctly allocated and add a comment explaining that hashtable_bits that is 0 is valid. Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> Fixes: d8792a5 ("riscv: Safely remove entries from relocation list") Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Closes: https://lore.kernel.org/r/202312132019.iYGTwW0L-lkp@intel.com/ Reported-by: kernel test robot <lkp@intel.com> Reported-by: Julia Lawall <julia.lawall@inria.fr> Closes: https://lore.kernel.org/r/202312120044.wTI1Uyaa-lkp@intel.com/ Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org> Link: https://lore.kernel.org/r/20240104-module_loading_fix-v3-2-a71f8de6ce0f@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com> Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
mainline inclusion from mainline-v6.8 commit a35551c category: bugfix bugzilla: RVCK-Project#310 -------------------------------- A second dereference is needed to get the accurate size of the relocation_hashtable. Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> Fixes: d8792a5 ("riscv: Safely remove entries from relocation list") Reported-by: kernel test robot <lkp@intel.com> Reported-by: Julia Lawall <julia.lawall@inria.fr> Closes: https://lore.kernel.org/r/202312120044.wTI1Uyaa-lkp@intel.com/ Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org> Link: https://lore.kernel.org/r/20240104-module_loading_fix-v3-3-a71f8de6ce0f@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com> Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
mainline inclusion from mainline-v6.13 commit 03f0b54 category: bugfix bugzilla: RVCK-Project#310 -------------------------------- relocation_head's list_head member, rel_entry, doesn't need to be allocated, its storage can just be part of the allocated relocation_head. Remove the pointer which allows to get rid of the allocation as well as an existing memory leak found by Kai Zhang using kmemleak. Fixes: 8fd6c51 ("riscv: Add remaining module relocations") Reported-by: Kai Zhang <zhangkai@iscas.ac.cn> Signed-off-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Charlie Jenkins <charlie@rivosinc.com> Tested-by: Charlie Jenkins <charlie@rivosinc.com> Link: https://lore.kernel.org/r/20241128081636.3620468-1-cleger@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com> Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
mainline inclusion from mainline-v6.15 commit 8578b2f category: bugfix bugzilla: RVCK-Project#310 -------------------------------- The number of relocations may be a huge value that is unallocatable by kmalloc. Use kvmalloc instead so that it does not fail. Fixes: 8fd6c51 ("riscv: Add remaining module relocations") Suggested-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com> Signed-off-by: Will Pierce <wgpierce17@gmail.com> Link: https://lore.kernel.org/r/20250402081426.5197-1-wgpierce17@gmail.com Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> Signed-off-by: Mingzheng Xing <xingmingzheng@iscas.ac.cn>
|
开始测试 log: https://github.com/RVCK-Project/rvck/actions/runs/29353724774 参数解析结果
测试完成 详细结果:
Kunit Test Result[17:30:17] Testing complete. Ran 482 tests: passed: 465, skipped: 17
Kernel Build Result
Check Patch Result
LAVA Check (qemu)
result: Lava check done!
|
请问如何制作出这种 ko?对工具链和编译选项有何要求,我这里想试一下。
这个问题和硬件应该没有关系吧,我想基于 QEMU 测试一下,ok?
|
Backport the upstream RISC-V module relocation support to allow loading
kernel modules built with newer binutils (e.g. 2.42) that emit
R_RISCV_32_PCREL and other relocation types.
This fixes the "Unknown relocation type 57" error observed when loading
modules such as cambricon_drv compiled with newer toolchains.
Included patches:
Test:
Built a minimal test module (pcrel_test.ko) that forces generation of
an R_RISCV_32_PCREL relocation. Verified with readelf:
$ riscv64-unknown-linux-gnu-readelf -r pcrel_test.ko | grep 32_PCREL
000000000000 003600000039 R_RISCV_32_PCREL 0000000000000000 pcrel_target + 0
Loaded the module successfully on LicheePi 4A board.
dmesg output:
fix: #310