Hexagon build/syscall/etc fixes
Subsystems (2)
Brian Cain
maintainercover Hexagon build/syscall/etc fixes
While working on the qemu boot configuration, several issues were uncovered, this series contains fixes for the bugs that were found.
Brian Cain (7):
hexagon: disable the LLVM packetizer
hexagon: define ELF_CORE_EFLAGS for V4-and-later architectures
hexagon: stop passing -mv${CONFIG_HEXAGON_ARCH_VERSION} to the linker
hexagon: read the thread-info register with a volatile asm
hexagon: let do_work_pending return without pending work
hexagon: set the user stack pointer in start_thread
hexagon: return -ENOSYS for unimplemented syscalls
arch/hexagon/Makefile | 7 +++++-- arch/hexagon/include/asm/elf.h | 2 +- arch/hexagon/include/asm/thread_info.h | 12 +++++++++--- arch/hexagon/kernel/process.c | 10 +++------- arch/hexagon/kernel/traps.c | 13 +++++++++---- 5 files changed, 27 insertions(+), 17 deletions(-)
Signature · 1 line
2.34.1
Brian Cain
maintainerPATCH 1/7 hexagon: disable the LLVM packetizer
The Hexagon packetizer can emit invalid instruction packets at runtime.
There's multiple distinct bugs. We'll re-evaluate after 23.1.0 to see if this can be version-gated in the future.
Disable the packetizer and new-value jumps unconditionally.
--- arch/hexagon/Makefile | 5 +++++ 1 file changed, 5 insertions(+)
arch/hexagon/Makefile +5 -0
@@ -7,6 +7,11 @@ KBUILD_DEFCONFIG = comet_defconfig KBUILD_CFLAGS += -G0 LDFLAGS_vmlinux += -G0 +# Workaround for the packetizer generating invalid instruction encodings: +# https://github.com/llvm/llvm-project/issues/178338 +# https://github.com/llvm/llvm-project/issues/218083 +KBUILD_CFLAGS += -mllvm --disable-packetizer -mllvm -disable-nvjump + # Do not use single-byte enums; these will overflow. KBUILD_CFLAGS += -fno-short-enums
Signature · 1 line
2.34.1
Brian Cain
maintainerPATCH 2/7 hexagon: define ELF_CORE_EFLAGS for V4-and-later architectures
In reply to Brian CainELF_CORE_EFLAGS was only defined for CONFIG_HEXAGON_ARCH_VERSION values of exactly 2, 3, or 4, unlike CS_COPYREGS just above it, which already treats V4 as a ">= 4" floor rather than an exact match. Any version newer than V4 left ELF_CORE_EFLAGS undefined and ptrace.c's use of it in the hexagon_user_view initializer failed to build. Extend the V4 case to match V4 and later, using the same core-dump e_flags value V4 used.
--- arch/hexagon/include/asm/elf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/hexagon/include/asm/elf.h +1 -1
@@ -168,7 +168,7 @@ do { \#define ELF_CORE_EFLAGS 0x2#endif -#if CONFIG_HEXAGON_ARCH_VERSION ==4 +#if CONFIG_HEXAGON_ARCH_VERSION >=4 #define ELF_CORE_EFLAGS 0x3#endif
Signature · 1 line
2.34.1
Re: [PATCH 2/7] hexagon: define ELF_CORE_EFLAGS for V4-and-later architectures
Quoted 8 lines · Brian Cain
ELF_CORE_EFLAGSwas only defined forCONFIG_HEXAGON_ARCH_VERSIONvalues of exactly 2, 3, or 4, unlikeCS_COPYREGSjust above it, which already treats V4 as a ">= 4" floor rather than an exact match. Any version newer than V4 leftELF_CORE_EFLAGSundefined and ptrace.c's use of it in thehexagon_user_viewinitializer failed to build. Extend the V4 case to match V4 and later, using the same core-dumpe_flagsvalue V4 used.
Quoted 4 lines
Signed-off-by Brian Cain <[email protected]>--- arch/hexagon/include/asm/elf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Brian Cain
maintainerPATCH 3/7 hexagon: stop passing -mv${CONFIG_HEXAGON_ARCH_VERSION} to the linker
In reply to Brian Cainldflags-y is probed with cc-option, which checks whether the compiler accepts the flag, then the result is appended to KBUILD_LDFLAGS, which is passed straight to $(LD) -- the linker, not the compiler. This presumed the linker was ld.qcld (aka ld.eld), which does accept the -mvNN flags. ld.lld does not: it parses "-mvNN" as "-m vNN", i.e. a request for an emulation named "vNN", which does not exist, and fails with "unknown emulation: vNN".
--- arch/hexagon/Makefile | 2 -- 1 file changed, 2 deletions(-)
arch/hexagon/Makefile +0 -2
@@ -26,11 +26,9 @@ KBUILD_CFLAGS_MODULE += -mlong-calls cflags-y += $(call cc-option,-mv${CONFIG_HEXAGON_ARCH_VERSION}) aflags-y += $(call cc-option,-mv${CONFIG_HEXAGON_ARCH_VERSION}) -ldflags-y += $(call cc-option,-mv${CONFIG_HEXAGON_ARCH_VERSION}) KBUILD_CFLAGS += $(cflags-y) KBUILD_AFLAGS += $(aflags-y) -KBUILD_LDFLAGS += $(ldflags-y) # Thread-info register will be r19. This value is not configureable; # it is hard-coded in several files.
Signature · 1 line
2.34.1
Re: [PATCH 3/7] hexagon: stop passing -mv${CONFIG_HEXAGON_ARCH_VERSION} to the linker
Quoted 8 lines · Brian Cain
ldflags-y is probed with cc-option, which checks whether the compiler accepts the flag, then the result is appended to
KBUILD_LDFLAGS, which is passed straight to $(LD) -- the linker, not the compiler. This presumed the linker was ld.qcld (aka ld.eld), which does accept the -mvNN flags. ld.lld does not: it parses "-mvNN" as "-m vNN", i.e. a request for an emulation named "vNN", which does not exist, and fails with "unknown emulation: vNN".
Quoted 4 lines
Signed-off-by Brian Cain <[email protected]>--- arch/hexagon/Makefile | 2 -- 1 file changed, 2 deletions(-)
Brian Cain
maintainerPATCH 4/7 hexagon: read the thread-info register with a volatile asm
In reply to Brian Caincurrent_thread_info() was a global register variable. Replace it with an explicit read of the same register, marked volatile: the register changes under us at every context switch, so the read must not be treated as a pure expression the compiler is free to hoist out of a loop or reuse across a call to switch_to().
--- arch/hexagon/include/asm/thread_info.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
arch/hexagon/include/asm/thread_info.h +8 -2
@@ -70,8 +70,14 @@ struct thread_info {#define qstr (s) #s#define QUOTED_THREADINFO_REG qqstr(THREADINFO_REG) -register struct thread_info *__current_thread_info asm(QUOTED_THREADINFO_REG); -#define current_thread_info () __current_thread_info +static inline struct thread_info *current_thread_info (void ) +{ +struct thread_info *ti; + + asmvolatile ("%0 = " QUOTED_THREADINFO_REG :"=r" (ti)); + +return ti; +}#endif /* __ASSEMBLY__ */
Signature · 1 line
2.34.1
Brian Cain
maintainerPATCH 5/7 hexagon: let do_work_pending return without pending work
In reply to Brian Caindo_work_pending() panicked if it was entered with no work bit set, but the event exit path re-checks flags after enabling interrupts, so a signal that has since been handled legitimately leaves nothing to do. Return zero instead, and stop treating single-step as pending work.
--- arch/hexagon/include/asm/thread_info.h | 2 +- arch/hexagon/kernel/process.c | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-)
arch/hexagon/include/asm/thread_info.h +1 -1
@@ -107,7 +107,7 @@ static inline struct thread_info *current_thread_info(void)#define _TIF_NOTIFY_SIGNAL (1 << TIF_NOTIFY_SIGNAL)/* work to do on interrupt/exception return - All but TIF_SYSCALL_TRACE */ -#define _TIF_WORK_MASK (0x0000FFFF & ~_TIF_SYSCALL_TRACE) +#define _TIF_WORK_MASK (0x0000FFFF & ~_TIF_SYSCALL_TRACE & ~_TIF_SINGLESTEP)/* work to do on any return to u-space */ #define _TIF_ALLWORK_MASK 0x0000FFFF
arch/hexagon/kernel/process.c +1 -7
@@ -156,10 +156,6 @@ unsigned long __get_wchan(struct task_struct *p)int do_work_pending (struct pt_regs *regs,u32 thread_info_flags);int do_work_pending (struct pt_regs *regs,u32 thread_info_flags) { -if (!(thread_info_flags & _TIF_WORK_MASK)) { -return 0 ; - }/* shortcut -- no work to be done */ -local_irq_enable ();if (thread_info_flags & _TIF_NEED_RESCHED) {
@@ -177,7 +173,5 @@ int do_work_pending(struct pt_regs *regs, u32 thread_info_flags)return 1 ; } -/* Should not even reach here */ -panic ("%s: bad thread_info flags 0x%08x\n" , __func__, - thread_info_flags); +return 0 ; }
Signature · 1 line
2.34.1
Brian Cain
maintainerPATCH 6/7 hexagon: set the user stack pointer in start_thread
In reply to Brian Cainstart_thread() set only the stack pointer that vmrte restores on the way back to user mode, leaving the copy in pt_regs holding whatever the previous thread had. A ptrace stop between execve() and the first return to user mode therefore reported a stale r29. Set both.
--- arch/hexagon/kernel/process.c | 2 ++ 1 file changed, 2 insertions(+)
arch/hexagon/kernel/process.c +2 -0
@@ -16,6 +16,7 @@#include <linux/uaccess.h> #include <linux/slab.h> #include <linux/resume_user_mode.h> +#include <asm/hexagon_vm.h> /* * Program thread launch. Often defined as a macro in processor.h,
@@ -33,6 +34,7 @@ void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)/* We might want to also zero all Processor registers here */ pt_set_usermode (regs);pt_set_elr (regs, pc); + regs->r29 = sp;pt_set_rte_sp (regs, sp); }
Signature · 1 line
2.34.1
Brian Cain
maintainerPATCH 7/7 hexagon: return -ENOSYS for unimplemented syscalls
In reply to Brian CainAn out-of-range syscall number returned -1 (-EPERM) and a NULL entry in the table was called anyway, crashing the kernel. Return -ENOSYS for both.
--- arch/hexagon/kernel/traps.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
arch/hexagon/kernel/traps.c +9 -4
@@ -372,13 +372,18 @@ void do_trap0(struct pt_regs *regs) regs->restart_r0 = regs->r00;if ((unsigned long ) regs->syscall_nr >= __NR_syscalls) { - regs->r00 =-1 ; + regs->r00 = -ENOSYS ; }else { syscall = (syscall_fn) (sys_call_table[regs->syscall_nr]); - regs->r00 =syscall (regs->r00, regs->r01, - regs->r02, regs->r03, - regs->r04, regs->r05); + +if (!syscall) { + regs->r00 = -ENOSYS ; + }else { + regs->r00 =syscall (regs->r00, regs->r01, + regs->r02, regs->r03, + regs->r04, regs->r05); + } }/* allow strace to get the syscall return state */
Signature · 1 line
2.34.1
LGTM
Quoted 23 lines · Brian Cain
While working on the qemu boot configuration, several issues were uncovered, this series contains fixes for the bugs that were found.
Brian Cain (7):
hexagon: disable the LLVM packetizer
hexagon: defineELF_CORE_EFLAGSfor V4-and-later architectures
hexagon: stop passing -mv${CONFIG_HEXAGON_ARCH_VERSION} to the linker
hexagon: read the thread-info register with a volatile asm
hexagon: letdo_work_pendingreturn without pending work
hexagon: set the user stack pointer instart_thread
hexagon: return-ENOSYSfor unimplemented syscallsarch/hexagon/Makefile | 7 +++++-- arch/hexagon/include/asm/elf.h | 2 +- arch/hexagon/include/asm/thread_info.h | 12 +++++++++--- arch/hexagon/kernel/process.c | 10 +++------- arch/hexagon/kernel/traps.c | 13 +++++++++---- 5 files changed, 27 insertions(+), 17 deletions(-)--
2.34.1