From f78fae8c9c8941e9f424191c9c9df26ff1d588f2 Mon Sep 17 00:00:00 2001 From: Niklas Cassel Date: Wed, 10 Aug 2022 13:50:55 +0200 Subject: [PATCH] board/riscv/nommu: bump kernel version and drop no longer needed patch Bump the kernel version for all riscv nommu configs from 5.18 to 5.19. That way, we can remove the one and only riscv nommu patch, since this patch is included in kernel 5.19. Signed-off-by: Niklas Cassel Reviewed-by: Damien Le Moal Signed-off-by: Thomas Petazzoni --- ...ot-stop-relocating-GOT-entries-prema.patch | 110 ------------------ board/riscv/nommu/patches/linux/readme.txt | 3 - configs/canaan_kd233_defconfig | 5 +- configs/qemu_riscv64_nommu_virt_defconfig | 5 +- configs/sipeed_maix_bit_defconfig | 5 +- configs/sipeed_maix_bit_sdcard_defconfig | 5 +- configs/sipeed_maix_dock_defconfig | 5 +- configs/sipeed_maix_dock_sdcard_defconfig | 5 +- configs/sipeed_maix_go_defconfig | 5 +- configs/sipeed_maix_go_sdcard_defconfig | 5 +- configs/sipeed_maixduino_defconfig | 5 +- configs/sipeed_maixduino_sdcard_defconfig | 5 +- 12 files changed, 10 insertions(+), 153 deletions(-) delete mode 100644 board/riscv/nommu/patches/linux/5.18/0001-binfmt_flat-do-not-stop-relocating-GOT-entries-prema.patch delete mode 100644 board/riscv/nommu/patches/linux/readme.txt diff --git a/board/riscv/nommu/patches/linux/5.18/0001-binfmt_flat-do-not-stop-relocating-GOT-entries-prema.patch b/board/riscv/nommu/patches/linux/5.18/0001-binfmt_flat-do-not-stop-relocating-GOT-entries-prema.patch deleted file mode 100644 index e5513b729b..0000000000 --- a/board/riscv/nommu/patches/linux/5.18/0001-binfmt_flat-do-not-stop-relocating-GOT-entries-prema.patch +++ /dev/null @@ -1,110 +0,0 @@ -From 6045ab5fea4c849153ebeb0acb532da5f29d69c4 Mon Sep 17 00:00:00 2001 -From: Niklas Cassel -Date: Thu, 14 Apr 2022 11:10:18 +0200 -Subject: binfmt_flat: do not stop relocating GOT entries prematurely on riscv - -Upstream commit 6045ab5fea4c849153ebeb0acb532da5f29d69c4. - -bFLT binaries are usually created using elf2flt. - -The linker script used by elf2flt has defined the .data section like the -following for the last 19 years: - -.data : { - _sdata = . ; - __data_start = . ; - data_start = . ; - *(.got.plt) - *(.got) - FILL(0) ; - . = ALIGN(0x20) ; - LONG(-1) - . = ALIGN(0x20) ; - ... -} - -It places the .got.plt input section before the .got input section. -The same is true for the default linker script (ld --verbose) on most -architectures except x86/x86-64. - -The binfmt_flat loader should relocate all GOT entries until it encounters -a -1 (the LONG(-1) in the linker script). - -The problem is that the .got.plt input section starts with a GOTPLT header -(which has size 16 bytes on elf64-riscv and 8 bytes on elf32-riscv), where -the first word is set to -1. See the binutils implementation for riscv [1]. - -This causes the binfmt_flat loader to stop relocating GOT entries -prematurely and thus causes the application to crash when running. - -Fix this by skipping the whole GOTPLT header, since the whole GOTPLT header -is reserved for the dynamic linker. - -The GOTPLT header will only be skipped for bFLT binaries with flag -FLAT_FLAG_GOTPIC set. This flag is unconditionally set by elf2flt if the -supplied ELF binary has the symbol _GLOBAL_OFFSET_TABLE_ defined. -ELF binaries without a .got input section should thus remain unaffected. - -Tested on RISC-V Canaan Kendryte K210 and RISC-V QEMU nommu_virt_defconfig. - -[1] https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/elfnn-riscv.c;hb=binutils-2_38#l3275 - -Cc: -Signed-off-by: Niklas Cassel -Reviewed-by: Damien Le Moal -Link: https://lore.kernel.org/r/20220414091018.896737-1-niklas.cassel@wdc.com -Fixed-by: kernel test robot -Link: https://lore.kernel.org/lkml/202204182333.OIUOotK8-lkp@intel.com -Signed-off-by: Kees Cook ---- - fs/binfmt_flat.c | 27 ++++++++++++++++++++++++++- - 1 file changed, 26 insertions(+), 1 deletion(-) - -diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c -index 6268981500112..dca0b6875f9c3 100644 ---- a/fs/binfmt_flat.c -+++ b/fs/binfmt_flat.c -@@ -440,6 +440,30 @@ static void old_reloc(unsigned long rl) - - /****************************************************************************/ - -+static inline u32 __user *skip_got_header(u32 __user *rp) -+{ -+ if (IS_ENABLED(CONFIG_RISCV)) { -+ /* -+ * RISC-V has a 16 byte GOT PLT header for elf64-riscv -+ * and 8 byte GOT PLT header for elf32-riscv. -+ * Skip the whole GOT PLT header, since it is reserved -+ * for the dynamic linker (ld.so). -+ */ -+ u32 rp_val0, rp_val1; -+ -+ if (get_user(rp_val0, rp)) -+ return rp; -+ if (get_user(rp_val1, rp + 1)) -+ return rp; -+ -+ if (rp_val0 == 0xffffffff && rp_val1 == 0xffffffff) -+ rp += 4; -+ else if (rp_val0 == 0xffffffff) -+ rp += 2; -+ } -+ return rp; -+} -+ - static int load_flat_file(struct linux_binprm *bprm, - struct lib_info *libinfo, int id, unsigned long *extra_stack) - { -@@ -789,7 +813,8 @@ static int load_flat_file(struct linux_binprm *bprm, - * image. - */ - if (flags & FLAT_FLAG_GOTPIC) { -- for (rp = (u32 __user *)datapos; ; rp++) { -+ rp = skip_got_header((u32 __user *) datapos); -+ for (; ; rp++) { - u32 addr, rp_val; - if (get_user(rp_val, rp)) - return -EFAULT; --- -cgit - diff --git a/board/riscv/nommu/patches/linux/readme.txt b/board/riscv/nommu/patches/linux/readme.txt deleted file mode 100644 index ea754c9920..0000000000 --- a/board/riscv/nommu/patches/linux/readme.txt +++ /dev/null @@ -1,3 +0,0 @@ -RISC-V NOMMU Common Support - -This directory provides Linux kernel patches common to all RISC-V NO-MMU builds. diff --git a/configs/canaan_kd233_defconfig b/configs/canaan_kd233_defconfig index 278fb883bf..3aa5dccf08 100644 --- a/configs/canaan_kd233_defconfig +++ b/configs/canaan_kd233_defconfig @@ -10,9 +10,6 @@ BR2_RISCV_ISA_CUSTOM_RVC=y # BR2_RISCV_USE_MMU is not set BR2_RISCV_ABI_LP64D=y -# Patches -BR2_GLOBAL_PATCH_DIR="board/riscv/nommu/patches" - # Binary format BR2_BINFMT_FLAT=y BR2_BINFMT_FLAT_ONE=y @@ -21,7 +18,7 @@ BR2_BINFMT_FLAT_ONE=y # Kernel BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y -BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.18" +BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.19" BR2_LINUX_KERNEL_DEFCONFIG="nommu_k210" BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="board/canaan/kd233/linux-cpio.config" BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM=y diff --git a/configs/qemu_riscv64_nommu_virt_defconfig b/configs/qemu_riscv64_nommu_virt_defconfig index 691cf31748..5fab255d88 100644 --- a/configs/qemu_riscv64_nommu_virt_defconfig +++ b/configs/qemu_riscv64_nommu_virt_defconfig @@ -3,9 +3,6 @@ BR2_riscv=y BR2_RISCV_64=y # BR2_RISCV_USE_MMU is not set -# Patches -BR2_GLOBAL_PATCH_DIR="board/riscv/nommu/patches" - # Busybox with hush BR2_PACKAGE_BUSYBOX_CONFIG="package/busybox/busybox-minimal.config" @@ -22,7 +19,7 @@ BR2_ROOTFS_POST_SCRIPT_ARGS="$(BR2_DEFCONFIG)" # Kernel BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y -BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.18" +BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.19" BR2_LINUX_KERNEL_DEFCONFIG="nommu_virt" BR2_LINUX_KERNEL_IMAGE=y diff --git a/configs/sipeed_maix_bit_defconfig b/configs/sipeed_maix_bit_defconfig index b31bc1309b..d2bac9e0b8 100644 --- a/configs/sipeed_maix_bit_defconfig +++ b/configs/sipeed_maix_bit_defconfig @@ -10,9 +10,6 @@ BR2_RISCV_ISA_CUSTOM_RVC=y # BR2_RISCV_USE_MMU is not set BR2_RISCV_ABI_LP64D=y -# Patches -BR2_GLOBAL_PATCH_DIR="board/riscv/nommu/patches" - # Binary format BR2_BINFMT_FLAT=y BR2_BINFMT_FLAT_ONE=y @@ -21,7 +18,7 @@ BR2_BINFMT_FLAT_ONE=y # Kernel BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y -BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.18" +BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.19" BR2_LINUX_KERNEL_DEFCONFIG="nommu_k210" BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="board/sipeed/maix-bit/linux-cpio.config" BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM=y diff --git a/configs/sipeed_maix_bit_sdcard_defconfig b/configs/sipeed_maix_bit_sdcard_defconfig index e42c3ee425..e1c9dc417e 100644 --- a/configs/sipeed_maix_bit_sdcard_defconfig +++ b/configs/sipeed_maix_bit_sdcard_defconfig @@ -10,9 +10,6 @@ BR2_RISCV_ISA_CUSTOM_RVC=y # BR2_RISCV_USE_MMU is not set BR2_RISCV_ABI_LP64D=y -# Patches -BR2_GLOBAL_PATCH_DIR="board/riscv/nommu/patches" - # System BR2_BINFMT_FLAT=y BR2_BINFMT_FLAT_ONE=y @@ -21,7 +18,7 @@ BR2_BINFMT_FLAT_ONE=y # Kernel BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y -BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.18" +BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.19" BR2_LINUX_KERNEL_DEFCONFIG="nommu_k210_sdcard" BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="board/canaan/k210-soc/linux-sdcard.config" BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM=y diff --git a/configs/sipeed_maix_dock_defconfig b/configs/sipeed_maix_dock_defconfig index d071e5d380..a7f0441e53 100644 --- a/configs/sipeed_maix_dock_defconfig +++ b/configs/sipeed_maix_dock_defconfig @@ -10,9 +10,6 @@ BR2_RISCV_ISA_CUSTOM_RVC=y # BR2_RISCV_USE_MMU is not set BR2_RISCV_ABI_LP64D=y -# Patches -BR2_GLOBAL_PATCH_DIR="board/riscv/nommu/patches" - # Binary format BR2_BINFMT_FLAT=y BR2_BINFMT_FLAT_ONE=y @@ -21,7 +18,7 @@ BR2_BINFMT_FLAT_ONE=y # Kernel BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y -BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.18" +BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.19" BR2_LINUX_KERNEL_DEFCONFIG="nommu_k210" BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="board/sipeed/maix-dock/linux-cpio.config" BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM=y diff --git a/configs/sipeed_maix_dock_sdcard_defconfig b/configs/sipeed_maix_dock_sdcard_defconfig index d1a1b2886d..6b7f8d9c68 100644 --- a/configs/sipeed_maix_dock_sdcard_defconfig +++ b/configs/sipeed_maix_dock_sdcard_defconfig @@ -10,9 +10,6 @@ BR2_RISCV_ISA_CUSTOM_RVC=y # BR2_RISCV_USE_MMU is not set BR2_RISCV_ABI_LP64D=y -# Patches -BR2_GLOBAL_PATCH_DIR="board/riscv/nommu/patches" - # System BR2_BINFMT_FLAT=y BR2_BINFMT_FLAT_ONE=y @@ -21,7 +18,7 @@ BR2_BINFMT_FLAT_ONE=y # Kernel BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y -BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.18" +BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.19" BR2_LINUX_KERNEL_DEFCONFIG="nommu_k210_sdcard" BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="board/canaan/k210-soc/linux-sdcard.config" BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM=y diff --git a/configs/sipeed_maix_go_defconfig b/configs/sipeed_maix_go_defconfig index 3055379db4..a68f9d3b72 100644 --- a/configs/sipeed_maix_go_defconfig +++ b/configs/sipeed_maix_go_defconfig @@ -10,9 +10,6 @@ BR2_RISCV_ISA_CUSTOM_RVC=y # BR2_RISCV_USE_MMU is not set BR2_RISCV_ABI_LP64D=y -# Patches -BR2_GLOBAL_PATCH_DIR="board/riscv/nommu/patches" - # Binary format BR2_BINFMT_FLAT=y BR2_BINFMT_FLAT_ONE=y @@ -21,7 +18,7 @@ BR2_BINFMT_FLAT_ONE=y # Kernel BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y -BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.18" +BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.19" BR2_LINUX_KERNEL_DEFCONFIG="nommu_k210" BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="board/sipeed/maix-go/linux-cpio.config" BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM=y diff --git a/configs/sipeed_maix_go_sdcard_defconfig b/configs/sipeed_maix_go_sdcard_defconfig index 65a6815c20..a127872cd8 100644 --- a/configs/sipeed_maix_go_sdcard_defconfig +++ b/configs/sipeed_maix_go_sdcard_defconfig @@ -10,9 +10,6 @@ BR2_RISCV_ISA_CUSTOM_RVC=y # BR2_RISCV_USE_MMU is not set BR2_RISCV_ABI_LP64D=y -# Patches -BR2_GLOBAL_PATCH_DIR="board/riscv/nommu/patches" - # System BR2_BINFMT_FLAT=y BR2_BINFMT_FLAT_ONE=y @@ -21,7 +18,7 @@ BR2_BINFMT_FLAT_ONE=y # Kernel BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y -BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.18" +BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.19" BR2_LINUX_KERNEL_DEFCONFIG="nommu_k210_sdcard" BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="board/canaan/k210-soc/linux-sdcard.config" BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM=y diff --git a/configs/sipeed_maixduino_defconfig b/configs/sipeed_maixduino_defconfig index 50c59bd4ad..c52adb5db7 100644 --- a/configs/sipeed_maixduino_defconfig +++ b/configs/sipeed_maixduino_defconfig @@ -10,9 +10,6 @@ BR2_RISCV_ISA_CUSTOM_RVC=y # BR2_RISCV_USE_MMU is not set BR2_RISCV_ABI_LP64D=y -# Patches -BR2_GLOBAL_PATCH_DIR="board/riscv/nommu/patches" - # Binary format BR2_BINFMT_FLAT=y BR2_BINFMT_FLAT_ONE=y @@ -21,7 +18,7 @@ BR2_BINFMT_FLAT_ONE=y # Kernel BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y -BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.18" +BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.19" BR2_LINUX_KERNEL_DEFCONFIG="nommu_k210" BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="board/sipeed/maixduino/linux-cpio.config" BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM=y diff --git a/configs/sipeed_maixduino_sdcard_defconfig b/configs/sipeed_maixduino_sdcard_defconfig index 5785d7acf3..baaa2bc7bb 100644 --- a/configs/sipeed_maixduino_sdcard_defconfig +++ b/configs/sipeed_maixduino_sdcard_defconfig @@ -10,9 +10,6 @@ BR2_RISCV_ISA_CUSTOM_RVC=y # BR2_RISCV_USE_MMU is not set BR2_RISCV_ABI_LP64D=y -# Patches -BR2_GLOBAL_PATCH_DIR="board/riscv/nommu/patches" - # System BR2_BINFMT_FLAT=y BR2_BINFMT_FLAT_ONE=y @@ -21,7 +18,7 @@ BR2_BINFMT_FLAT_ONE=y # Kernel BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y -BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.18" +BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.19" BR2_LINUX_KERNEL_DEFCONFIG="nommu_k210_sdcard" BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="board/canaan/k210-soc/linux-sdcard.config" BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM=y