parisc: Drop strnlen_user() in favour of generic version
Subsystems (3)
Helge Deller
maintainerPATCH 1/4 parisc: Drop strnlen_user() in favour of generic version
As suggested by Arnd Bergmann, drop the parisc version of strnlen_user() and switch to the generic version.
user_addr_max() was wrong too, fix it by using TASK_SIZE.
--- arch/parisc/Kconfig | 1 - arch/parisc/include/asm/uaccess.h | 5 ++--- arch/parisc/kernel/parisc_ksyms.c | 1 - arch/parisc/lib/lusercopy.S | 34 ------------------------------- 4 files changed, 2 insertions(+), 39 deletions(-)
arch/parisc/Kconfig +0 -1
@@ -10,7 +10,6 @@ config PARISC select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_STRICT_KERNEL_RWX select ARCH_HAS_UBSAN_SANITIZE_ALL - select ARCH_HAS_STRNLEN_USER select ARCH_NO_SG_CHAIN select ARCH_SUPPORTS_HUGETLBFS if PA20 select ARCH_SUPPORTS_MEMORY_FAILURE
arch/parisc/include/asm/uaccess.h +2 -3
@@ -201,13 +201,12 @@ struct exception_table_entry {extern long strncpy_from_user (char *,const char __user *,long );extern unsigned lclear_user (void __user *,unsigned long ); -extern long lstrnlen_user (const char __user *,long ); +extern __must_check long strnlen_user (const char __user *src,long n);/* * Complex access routines -- macros */ -#define user_addr_max () (~0UL) +#define user_addr_max () (uaccess_kernel() ? ~0UL : TASK_SIZE) -#define strnlen_user lstrnlen_user#define clear_user lclear_user#define __clear_user lclear_user
arch/parisc/kernel/parisc_ksyms.c +0 -1
@@ -32,7 +32,6 @@ EXPORT_SYMBOL(__xchg64);#include <linux/uaccess.h> EXPORT_SYMBOL (lclear_user); -EXPORT_SYMBOL (lstrnlen_user);#ifndef CONFIG_64BIT /* Needed so insmod can set dp value */
arch/parisc/lib/lusercopy.S +0 -34
@@ -67,40 +67,6 @@ $lclu_done: ENDPROC_CFI(lclear_user) - /* - * long lstrnlen_user(char *s, long n) - * - * Returns 0 if exception before zero byte or reaching N, - * N+1 if N would be exceeded, - * else strlen + 1 (i.e. includes zero byte). - */ - -ENTRY_CFI(lstrnlen_user) - comib,= 0,%r25,$lslen_nzero - copy %r26,%r24 - get_sr -1: ldbs,ma 1(%sr1,%r26),%r1 -$lslen_loop: - comib,=,n 0,%r1,$lslen_done - addib,<> -1,%r25,$lslen_loop -2: ldbs,ma 1(%sr1,%r26),%r1 -$lslen_done: - bv %r0(%r2) - sub %r26,%r24,%r28 - -$lslen_nzero: - b $lslen_done - ldo 1(%r26),%r26 /* special case for N == 0 */ - -3: b $lslen_done - copy %r24,%r26 /* reset r26 so 0 is returned on fault */ - - ASM_EXCEPTIONTABLE_ENTRY(1b,3b) - ASM_EXCEPTIONTABLE_ENTRY(2b,3b) - -ENDPROC_CFI(lstrnlen_user) - - /* * unsigned long pa_memcpy(void *dstp, const void *srcp, unsigned long len) *
--
2.31.1
Helge Deller
maintainerPATCH 2/4 parisc: Drop useless debug info and comments from signal.c
--- arch/parisc/kernel/signal.c | 15 --------------- 1 file changed, 15 deletions(-)
arch/parisc/kernel/signal.c +0 -15
@@ -293,16 +293,6 @@ setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs, &frame->tramp[SIGRESTARTBLOCK_TRAMP+2]); err |=__put_user (INSN_NOP , &frame->tramp[SIGRESTARTBLOCK_TRAMP +3 ]); -#if DEBUG_SIG -/* Assert that we're flushing in the correct space... */ - { -unsigned long sid; - asm ("mfsp %%sr3,%0" :"=r" (sid)); -DBG (1 ,"setup_rt_frame: Flushing 64 bytes at space %#x offset %p\n" , - sid, frame->tramp); - } -#endif - start = (unsigned long ) &frame->tramp[0 ]; end = (unsigned long ) &frame->tramp[TRAMP_SIZE ];flush_user_dcache_range_asm (start, end);
@@ -501,7 +491,6 @@ syscall_restart(struct pt_regs *regs, struct k_sigaction *ka)DBG (1 ,"ERESTARTNOHAND: returning -EINTR\n" ); regs->gr[28 ] = -EINTR ;break ; -case -ERESTARTSYS :if (!(ka->sa.sa_flags &SA_RESTART )) {DBG (1 ,"ERESTARTSYS: putting -EINTR\n" );
@@ -569,10 +558,6 @@ insert_restart_trampoline(struct pt_regs *regs) }/* -* Note that 'init' is a special process: it doesn't get signals it doesn't -* want to handle. Thus you cannot kill init even with a SIGKILL even by -* mistake. -* * We need to be able to restore the syscall arguments (r21-r26) to * restart syscalls. Thus, the syscall path should save them in the * pt_regs structure (it's okay to do so since they are caller-save
--
2.31.1
Helge Deller
maintainerPATCH 3/4 parisc: Check user signal stack trampoline is inside TASK_SIZE
In reply to Helge DellerAdd some additional checks to ensure the signal stack is inside userspace bounds.
--- arch/parisc/kernel/signal.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
arch/parisc/kernel/signal.c +10 -7
@@ -237,18 +237,22 @@ setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs,#endif usp = (regs->gr[30 ] & ~(0x01UL )); + sigframe_size =PARISC_RT_SIGFRAME_SIZE ;#ifdef CONFIG_64BIT if (is_compat_task ()) {/* The gcc alloca implementation leaves garbage in the upper 32 bits of sp */ usp = (compat_uint_t )usp; + sigframe_size =PARISC_RT_SIGFRAME_SIZE32 ; }#endif -/*FIXME: frame_size parameter is unused, remove it. */ - frame =get_sigframe (&ksig->ka, usp,sizeof (*frame)); + frame =get_sigframe (&ksig->ka, usp, sigframe_size);DBG (1 ,"SETUP_RT_FRAME: START\n" );DBG (1 ,"setup_rt_frame: frame %p info %p\n" , frame, ksig->info); + start = (unsigned long ) frame; +if (start >=user_addr_max () - sigframe_size) +return -EFAULT ;#ifdef CONFIG_64BIT
@@ -343,11 +347,6 @@ setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs,/* The syscall return path will create IAOQ values from r31. */ - sigframe_size =PARISC_RT_SIGFRAME_SIZE ; -#ifdef CONFIG_64BIT -if (is_compat_task ()) - sigframe_size =PARISC_RT_SIGFRAME_SIZE32 ; -#endif if (in_syscall) { regs->gr[31 ] = haddr;#ifdef CONFIG_64BIT
@@ -518,6 +517,10 @@ insert_restart_trampoline(struct pt_regs *regs)unsigned long end = (unsigned long ) &usp[5 ];long err =0 ; +/* check that we don't exceed the stack */ +if (A (&usp[0 ]) >=user_addr_max () -5 *sizeof (int )) +return ; +/* Setup a trampoline to restart the syscall * with __NR_restart_syscall *
--
2.31.1
Helge Deller
maintainerPATCH 4/4 parisc: Reduce sigreturn trampoline to 3 instructions
In reply to Helge DellerWe can move the INSN_LDI_R20 instruction into the branch delay slot.
--- arch/parisc/include/asm/rt_sigframe.h | 2 +- arch/parisc/kernel/signal.c | 13 ++++++------- arch/parisc/kernel/signal32.h | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-)
arch/parisc/include/asm/rt_sigframe.h +1 -1
@@ -2,7 +2,7 @@#ifndef _ASM_PARISC_RT_SIGFRAME_H#define _ASM_PARISC_RT_SIGFRAME_H -#define SIGRETURN_TRAMP 4 +#define SIGRETURN_TRAMP 3#define SIGRESTARTBLOCK_TRAMP 5#define TRAMP_SIZE (SIGRETURN_TRAMP + SIGRESTARTBLOCK_TRAMP)
arch/parisc/kernel/signal.c +6 -7
@@ -288,22 +288,21 @@ setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs,already in userspace. The first words of tramp are used to save the previous sigrestartblock trampoline that might be on the stack. We start the sigreturn trampoline at -SIGRESTARTBLOCK_TRAMP+X. */ +SIGRESTARTBLOCK_TRAMP. */ err |=__put_user (in_syscall ?INSN_LDI_R25_1 :INSN_LDI_R25_0 , &frame->tramp[SIGRESTARTBLOCK_TRAMP +0 ]); - err |=__put_user (INSN_LDI_R20 , - &frame->tramp[SIGRESTARTBLOCK_TRAMP +1 ]); err |=__put_user (INSN_BLE_SR2_R0 , + &frame->tramp[SIGRESTARTBLOCK_TRAMP +1 ]); + err |=__put_user (INSN_LDI_R20 , &frame->tramp[SIGRESTARTBLOCK_TRAMP +2 ]); - err |=__put_user (INSN_NOP , &frame->tramp[SIGRESTARTBLOCK_TRAMP +3 ]); - start = (unsigned long ) &frame->tramp[0 ]; - end = (unsigned long ) &frame->tramp[TRAMP_SIZE ]; + start = (unsigned long ) &frame->tramp[SIGRESTARTBLOCK_TRAMP +0 ]; + end = (unsigned long ) &frame->tramp[SIGRESTARTBLOCK_TRAMP +3 ];flush_user_dcache_range_asm (start, end);flush_user_icache_range_asm (start, end);/* TRAMP Words 0-4, Length 5 = SIGRESTARTBLOCK_TRAMP -* TRAMP Words 5-9, Length 4 = SIGRETURN_TRAMP +* TRAMP Words 5-7, Length 3 = SIGRETURN_TRAMP * So the SIGRETURN_TRAMP is at the end of SIGRESTARTBLOCK_TRAMP */ rp = (unsigned long ) &frame->tramp[SIGRESTARTBLOCK_TRAMP ];
arch/parisc/kernel/signal32.h +1 -1
@@ -36,7 +36,7 @@ struct compat_regfile {compat_int_t rf_sar; }; -#define COMPAT_SIGRETURN_TRAMP 4 +#define COMPAT_SIGRETURN_TRAMP 3#define COMPAT_SIGRESTARTBLOCK_TRAMP 5#define COMPAT_TRAMP_SIZE (COMPAT_SIGRETURN_TRAMP + \ COMPAT_SIGRESTARTBLOCK_TRAMP)
--
2.31.1
Re: [PATCH 4/4] parisc: Reduce sigreturn trampoline to 3 instructions
This change breaks signal delivery and causes various glibc tests to fail.
commit 3e4a1aff2a97cb4fd7f0268e4b69e8c9d3641277:
dave@atlas:~/gnu/glibc/objdir$ env GCONV_PATH=/home/dave/gnu/glibc/objdir/iconvdata LOCPATH=/home/dave/gnu/glibc/objdir/localedata LC_ALL=C /home/dave/gnu/glibc/objdir/elf/ld.so.1 --library-path /home/dave/gnu/glibc/objdir:/home/dave/gnu/glibc/objdir/math:/home/dave/gnu/glibc/objdir/elf:/home/dave/gnu/glibc/objdir/dlfcn:/home/dave/gnu/glibc/objdir/nss:/home/dave/gnu/glibc/objdir/nis:/home/dave/gnu/glibc/objdir/rt:/home/dave/gnu/glibc/objdir/resolv:/home/dave/gnu/glibc/objdir/mathvec:/home/dave/gnu/glibc/objdir/support:/home/dave/gnu/glibc/objdir/crypt:/home/dave/gnu/glibc/objdir/nptl /home/dave/gnu/glibc/objdir/nptl/tst-cancelx4 got size 4512 in-time cancel test of 'read' successful in-time cancel test of 'readv' successful in-time cancel test of 'select' successful in-time cancel test of 'pselect' successful in-time cancel test of 'poll' successful in-time cancel test of 'ppoll' successful in-time cancel test of 'write' successful in-time cancel test of 'writev' successful in-time cancel test of 'sleep' successful in-time cancel test of 'usleep' successful in-time cancel test of 'nanosleep' successful in-time cancel test of 'wait' successful in-time cancel test of 'waitid' successful in-time cancel test of 'waitpid' successful in-time cancel test of 'sigpause' successful in-time cancel test of 'sigsuspend' successful in-time cancel test of 'sigwait' successful in-time cancel test of 'sigwaitinfo' successful in-time cancel test of 'sigtimedwait' successful in-time cancel test of 'pause' successful in-time cancel test of 'accept' successful got size 4512 in-time cancel test of 'send' successful in-time cancel test of 'recv' successful in-time cancel test of 'recvfrom' successful in-time cancel test of 'recvmsg' successful in-time cancel test of 'msgrcv' successful early cancel test of 'read' successful early cancel test of 'readv' successful early cancel test of 'select' successful early cancel test of 'pselect' successful early cancel test of 'poll' successful early cancel test of 'ppoll' successful early cancel test of 'write' successful early cancel test of 'writev' successful early cancel test of 'sleep' successful early cancel test of 'usleep' successful early cancel test of 'nanosleep' successful early cancel test of 'wait' successful early cancel test of 'waitid' successful early cancel test of 'waitpid' successful early cancel test of 'sigpause' successful early cancel test of 'sigsuspend' successful early cancel test of 'sigwait' successful early cancel test of 'sigwaitinfo' successful early cancel test of 'sigtimedwait' successful early cancel test of 'pause' successful early cancel test of 'accept' successful got size 4512 early cancel test of 'send' successful early cancel test of 'recv' successful early cancel test of 'recvfrom' successful early cancel test of 'recvmsg' successful early cancel test of 'preadv' successful early cancel test of 'preadv2' successful early cancel test of 'pwritev' successful early cancel test of 'pwritev2' successful early cancel test of 'open' successful early cancel test of 'close' successful early cancel test of 'pread' successful early cancel test of 'pwrite' successful early cancel test of 'fsync' successful early cancel test of 'fdatasync' successful early cancel test of 'msync' successful got size 4512 early cancel test of 'sendto' successful early cancel test of 'sendmsg' successful early cancel test of 'creat' successful early cancel test of 'connect' successful early cancel test of 'tcdrain' successful early cancel test of 'msgrcv' successful early cancel test of 'msgsnd' successful dave@atlas:~/gnu/glibc/objdir$ echo $? 0
commit e4f2006f1287e7ea17660490569cff323772dac4:
dave@atlas:~/gnu/glibc/objdir$ env GCONV_PATH=/home/dave/gnu/glibc/objdir/iconvdata LOCPATH=/home/dave/gnu/glibc/objdir/localedata LC_ALL=C /home/dave/gnu/glibc/objdir/elf/ld.so.1 --library-path /home/dave/gnu/glibc/objdir:/home/dave/gnu/glibc/objdir/math:/home/dave/gnu/glibc/objdir/elf:/home/dave/gnu/glibc/objdir/dlfcn:/home/dave/gnu/glibc/objdir/nss:/home/dave/gnu/glibc/objdir/nis:/home/dave/gnu/glibc/objdir/rt:/home/dave/gnu/glibc/objdir/resolv:/home/dave/gnu/glibc/objdir/mathvec:/home/dave/gnu/glibc/objdir/support:/home/dave/gnu/glibc/objdir/crypt:/home/dave/gnu/glibc/objdir/nptl /home/dave/gnu/glibc/objdir/nptl/tst-cancelx4 got size 4512 cleanup handler not called for 'read' cleanup handler not called for 'readv' cleanup handler not called for 'select' cleanup handler not called for 'pselect' cleanup handler not called for 'poll' cleanup handler not called for 'ppoll' cleanup handler not called for 'write' cleanup handler not called for 'writev' cleanup handler not called for 'sleep' cleanup handler not called for 'usleep' cleanup handler not called for 'nanosleep' cleanup handler not called for 'wait' cleanup handler not called for 'waitid' cleanup handler not called for 'waitpid' cleanup handler not called for 'sigpause' cleanup handler not called for 'sigsuspend' cleanup handler not called for 'sigwait' cleanup handler not called for 'sigwaitinfo' cleanup handler not called for 'sigtimedwait' cleanup handler not called for 'pause' cleanup handler not called for 'accept' got size 4512 cleanup handler not called for 'send' cleanup handler not called for 'recv' cleanup handler not called for 'recvfrom' cleanup handler not called for 'recvmsg' cleanup handler not called for 'msgrcv' early cancel test of 'read' successful early cancel test of 'readv' successful early cancel test of 'select' successful early cancel test of 'pselect' successful early cancel test of 'poll' successful early cancel test of 'ppoll' successful early cancel test of 'write' successful early cancel test of 'writev' successful early cancel test of 'sleep' successful early cancel test of 'usleep' successful early cancel test of 'nanosleep' successful early cancel test of 'wait' successful early cancel test of 'waitid' successful early cancel test of 'waitpid' successful early cancel test of 'sigpause' successful early cancel test of 'sigsuspend' successful early cancel test of 'sigwait' successful early cancel test of 'sigwaitinfo' successful early cancel test of 'sigtimedwait' successful early cancel test of 'pause' successful early cancel test of 'accept' successful got size 4512 early cancel test of 'send' successful early cancel test of 'recv' successful early cancel test of 'recvfrom' successful early cancel test of 'recvmsg' successful early cancel test of 'preadv' successful early cancel test of 'preadv2' successful early cancel test of 'pwritev' successful early cancel test of 'pwritev2' successful early cancel test of 'open' successful early cancel test of 'close' successful early cancel test of 'pread' successful early cancel test of 'pwrite' successful early cancel test of 'fsync' successful early cancel test of 'fdatasync' successful early cancel test of 'msync' successful got size 4512 early cancel test of 'sendto' successful early cancel test of 'sendmsg' successful early cancel test of 'creat' successful early cancel test of 'connect' successful early cancel test of 'tcdrain' successful early cancel test of 'msgrcv' successful early cancel test of 'msgsnd' successful dave@atlas:~/gnu/glibc/objdir$ echo $? 1
Dave
Quoted 71 lines · Helge Deller
We can move the
INSN_LDI_R20instruction into the branch delay slot.Signed-off-by Helge Deller <[email protected]>--- arch/parisc/include/asm/rt_sigframe.h | 2 +- arch/parisc/kernel/signal.c | 13 ++++++------- arch/parisc/kernel/signal32.h | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-)arch/parisc/include/asm/rt_sigframe.h +1
-1@@ -2,7 +2,7 @@#ifndef _ASM_PARISC_RT_SIGFRAME_H#define _ASM_PARISC_RT_SIGFRAME_H -#define SIGRETURN_TRAMP 4 +#define SIGRETURN_TRAMP 3#define SIGRESTARTBLOCK_TRAMP 5#define TRAMP_SIZE (SIGRETURN_TRAMP + SIGRESTARTBLOCK_TRAMP)arch/parisc/kernel/signal.c +6
-7@@ -288,22 +288,21 @@ setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs,already in userspace. The first words of tramp are used to save the previous sigrestartblock trampoline that might be on the stack. We start the sigreturn trampoline at -SIGRESTARTBLOCK_TRAMP+X. */ +SIGRESTARTBLOCK_TRAMP. */ err |=__put_user (in_syscall ?INSN_LDI_R25_1 :INSN_LDI_R25_0 , &frame->tramp[SIGRESTARTBLOCK_TRAMP +0 ]); - err |=__put_user (INSN_LDI_R20 , - &frame->tramp[SIGRESTARTBLOCK_TRAMP +1 ]); err |=__put_user (INSN_BLE_SR2_R0 , + &frame->tramp[SIGRESTARTBLOCK_TRAMP +1 ]); + err |=__put_user (INSN_LDI_R20 , &frame->tramp[SIGRESTARTBLOCK_TRAMP +2 ]); - err |=__put_user (INSN_NOP , &frame->tramp[SIGRESTARTBLOCK_TRAMP +3 ]); - start = (unsigned long ) &frame->tramp[0 ]; - end = (unsigned long ) &frame->tramp[TRAMP_SIZE ]; + start = (unsigned long ) &frame->tramp[SIGRESTARTBLOCK_TRAMP +0 ]; + end = (unsigned long ) &frame->tramp[SIGRESTARTBLOCK_TRAMP +3 ];flush_user_dcache_range_asm (start, end);flush_user_icache_range_asm (start, end);/* TRAMP Words 0-4, Length 5 = SIGRESTARTBLOCK_TRAMP -* TRAMP Words 5-9, Length 4 = SIGRETURN_TRAMP +* TRAMP Words 5-7, Length 3 = SIGRETURN_TRAMP * So the SIGRETURN_TRAMP is at the end of SIGRESTARTBLOCK_TRAMP */ rp = (unsigned long ) &frame->tramp[SIGRESTARTBLOCK_TRAMP ];arch/parisc/kernel/signal32.h +1
-2@@ -36,7 +36,7 @@ struct compat_regfile {compat_int_t rf_sar; }; -#define COMPAT_SIGRETURN_TRAMP 4 +#define COMPAT_SIGRETURN_TRAMP 3#define COMPAT_SIGRESTARTBLOCK_TRAMP 5#define COMPAT_TRAMP_SIZE (COMPAT_SIGRETURN_TRAMP + \ COMPAT_SIGRESTARTBLOCK_TRAMP) --2.31.1
Signature · 1 line
John David Anglin [email protected]
Helge Deller
maintainerRe: [PATCH 4/4] parisc: Reduce sigreturn trampoline to 3 instructions
Dave,
Thanks for tracking this down!
I wonder what's wrong with it.
Based on the outcome I should either completely revert that patch or fix it.
Helge
Quoted 234 lines · John David Anglin
This change breaks signal delivery and causes various glibc tests to fail.
commit
3e4a1aff2a97cb4fd7f0268e4b69e8c9d3641277:dave@atlas:~/gnu/glibc/objdir$ env GCONV_PATH=/home/dave/gnu/glibc/objdir/iconvdata LOCPATH=/home/dave/gnu/glibc/objdir/localedata LC_ALL=C /home/dave/gnu/glibc/objdir/elf/ld.so.1 --library-path /home/dave/gnu/glibc/objdir:/home/dave/gnu/glibc/objdir/math:/home/dave/gnu/glibc/objdir/elf:/home/dave/gnu/glibc/objdir/dlfcn:/home/dave/gnu/glibc/objdir/nss:/home/dave/gnu/glibc/objdir/nis:/home/dave/gnu/glibc/objdir/rt:/home/dave/gnu/glibc/objdir/resolv:/home/dave/gnu/glibc/objdir/mathvec:/home/dave/gnu/glibc/objdir/support:/home/dave/gnu/glibc/objdir/crypt:/home/dave/gnu/glibc/objdir/nptl /home/dave/gnu/glibc/objdir/nptl/tst-cancelx4 got size 4512 in-time cancel test of 'read' successful in-time cancel test of 'readv' successful in-time cancel test of 'select' successful in-time cancel test of 'pselect' successful in-time cancel test of 'poll' successful in-time cancel test of 'ppoll' successful in-time cancel test of 'write' successful in-time cancel test of 'writev' successful in-time cancel test of 'sleep' successful in-time cancel test of 'usleep' successful in-time cancel test of 'nanosleep' successful in-time cancel test of 'wait' successful in-time cancel test of 'waitid' successful in-time cancel test of 'waitpid' successful in-time cancel test of 'sigpause' successful in-time cancel test of 'sigsuspend' successful in-time cancel test of 'sigwait' successful in-time cancel test of 'sigwaitinfo' successful in-time cancel test of 'sigtimedwait' successful in-time cancel test of 'pause' successful in-time cancel test of 'accept' successful got size 4512 in-time cancel test of 'send' successful in-time cancel test of 'recv' successful in-time cancel test of 'recvfrom' successful in-time cancel test of 'recvmsg' successful in-time cancel test of 'msgrcv' successful early cancel test of 'read' successful early cancel test of 'readv' successful early cancel test of 'select' successful early cancel test of 'pselect' successful early cancel test of 'poll' successful early cancel test of 'ppoll' successful early cancel test of 'write' successful early cancel test of 'writev' successful early cancel test of 'sleep' successful early cancel test of 'usleep' successful early cancel test of 'nanosleep' successful early cancel test of 'wait' successful early cancel test of 'waitid' successful early cancel test of 'waitpid' successful early cancel test of 'sigpause' successful early cancel test of 'sigsuspend' successful early cancel test of 'sigwait' successful early cancel test of 'sigwaitinfo' successful early cancel test of 'sigtimedwait' successful early cancel test of 'pause' successful early cancel test of 'accept' successful got size 4512 early cancel test of 'send' successful early cancel test of 'recv' successful early cancel test of 'recvfrom' successful early cancel test of 'recvmsg' successful early cancel test of 'preadv' successful early cancel test of 'preadv2' successful early cancel test of 'pwritev' successful early cancel test of 'pwritev2' successful early cancel test of 'open' successful early cancel test of 'close' successful early cancel test of 'pread' successful early cancel test of 'pwrite' successful early cancel test of 'fsync' successful early cancel test of 'fdatasync' successful early cancel test of 'msync' successful got size 4512 early cancel test of 'sendto' successful early cancel test of 'sendmsg' successful early cancel test of 'creat' successful early cancel test of 'connect' successful early cancel test of 'tcdrain' successful early cancel test of 'msgrcv' successful early cancel test of 'msgsnd' successful dave@atlas:~/gnu/glibc/objdir$ echo $? 0commit
e4f2006f1287e7ea17660490569cff323772dac4:dave@atlas:~/gnu/glibc/objdir$ env GCONV_PATH=/home/dave/gnu/glibc/objdir/iconvdata LOCPATH=/home/dave/gnu/glibc/objdir/localedata LC_ALL=C /home/dave/gnu/glibc/objdir/elf/ld.so.1 --library-path /home/dave/gnu/glibc/objdir:/home/dave/gnu/glibc/objdir/math:/home/dave/gnu/glibc/objdir/elf:/home/dave/gnu/glibc/objdir/dlfcn:/home/dave/gnu/glibc/objdir/nss:/home/dave/gnu/glibc/objdir/nis:/home/dave/gnu/glibc/objdir/rt:/home/dave/gnu/glibc/objdir/resolv:/home/dave/gnu/glibc/objdir/mathvec:/home/dave/gnu/glibc/objdir/support:/home/dave/gnu/glibc/objdir/crypt:/home/dave/gnu/glibc/objdir/nptl /home/dave/gnu/glibc/objdir/nptl/tst-cancelx4 got size 4512 cleanup handler not called for 'read' cleanup handler not called for 'readv' cleanup handler not called for 'select' cleanup handler not called for 'pselect' cleanup handler not called for 'poll' cleanup handler not called for 'ppoll' cleanup handler not called for 'write' cleanup handler not called for 'writev' cleanup handler not called for 'sleep' cleanup handler not called for 'usleep' cleanup handler not called for 'nanosleep' cleanup handler not called for 'wait' cleanup handler not called for 'waitid' cleanup handler not called for 'waitpid' cleanup handler not called for 'sigpause' cleanup handler not called for 'sigsuspend' cleanup handler not called for 'sigwait' cleanup handler not called for 'sigwaitinfo' cleanup handler not called for 'sigtimedwait' cleanup handler not called for 'pause' cleanup handler not called for 'accept' got size 4512 cleanup handler not called for 'send' cleanup handler not called for 'recv' cleanup handler not called for 'recvfrom' cleanup handler not called for 'recvmsg' cleanup handler not called for 'msgrcv' early cancel test of 'read' successful early cancel test of 'readv' successful early cancel test of 'select' successful early cancel test of 'pselect' successful early cancel test of 'poll' successful early cancel test of 'ppoll' successful early cancel test of 'write' successful early cancel test of 'writev' successful early cancel test of 'sleep' successful early cancel test of 'usleep' successful early cancel test of 'nanosleep' successful early cancel test of 'wait' successful early cancel test of 'waitid' successful early cancel test of 'waitpid' successful early cancel test of 'sigpause' successful early cancel test of 'sigsuspend' successful early cancel test of 'sigwait' successful early cancel test of 'sigwaitinfo' successful early cancel test of 'sigtimedwait' successful early cancel test of 'pause' successful early cancel test of 'accept' successful got size 4512 early cancel test of 'send' successful early cancel test of 'recv' successful early cancel test of 'recvfrom' successful early cancel test of 'recvmsg' successful early cancel test of 'preadv' successful early cancel test of 'preadv2' successful early cancel test of 'pwritev' successful early cancel test of 'pwritev2' successful early cancel test of 'open' successful early cancel test of 'close' successful early cancel test of 'pread' successful early cancel test of 'pwrite' successful early cancel test of 'fsync' successful early cancel test of 'fdatasync' successful early cancel test of 'msync' successful got size 4512 early cancel test of 'sendto' successful early cancel test of 'sendmsg' successful early cancel test of 'creat' successful early cancel test of 'connect' successful early cancel test of 'tcdrain' successful early cancel test of 'msgrcv' successful early cancel test of 'msgsnd' successful dave@atlas:~/gnu/glibc/objdir$ echo $? 1Dave
Quoted 71 lines · Helge Deller
We can move the
INSN_LDI_R20instruction into the branch delay slot.Signed-off-by Helge Deller <[email protected]>---
arch/parisc/include/asm/rt_sigframe.h| 2 +- arch/parisc/kernel/signal.c | 13 ++++++------- arch/parisc/kernel/signal32.h | 2 +-3 files changed, 8 insertions(+), 9 deletions(-)arch/parisc/include/asm/rt_sigframe.h +1
-1@@ -2,7 +2,7 @@ #ifndef _ASM_PARISC_RT_SIGFRAME_H #define _ASM_PARISC_RT_SIGFRAME_H -#define SIGRETURN_TRAMP 4 +#define SIGRETURN_TRAMP 3 #define SIGRESTARTBLOCK_TRAMP 5 #define TRAMP_SIZE (SIGRETURN_TRAMP + SIGRESTARTBLOCK_TRAMP)arch/parisc/kernel/signal.c +0
-0@@ -288,22 +288,21 @@ setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs,already in userspace. The first words of tramp are used to save the previous sigrestartblock trampoline that might be on the stack. We start the sigreturn trampoline at
- SIGRESTARTBLOCK_TRAMP+X. */
+SIGRESTARTBLOCK_TRAMP. */
err |=__put_user(in_syscall ? INSN_LDI_R25_1 : INSN_LDI_R25_0, &frame->tramp[SIGRESTARTBLOCK_TRAMP+0]);
- err |= __put_user(INSN_LDI_R20,
- &frame->tramp[SIGRESTARTBLOCK_TRAMP+1]);
err |= __put_user(INSN_BLE_SR2_R0,
+ &frame->tramp[SIGRESTARTBLOCK_TRAMP+1]);
+ err |=__put_user(INSN_LDI_R20, &frame->tramp[SIGRESTARTBLOCK_TRAMP+2]);
- err |=__put_user(INSN_NOP, &frame->tramp[SIGRESTARTBLOCK_TRAMP+3]);- start = (unsigned long) &frame->tramp[0];
- end = (unsigned long) &frame->tramp[TRAMP_SIZE];
+ start = (unsigned long) &frame->tramp[SIGRESTARTBLOCK_TRAMP+0]; + end = (unsigned long) &frame->tramp[SIGRESTARTBLOCK_TRAMP+3];flush_user_dcache_range_asm(start, end);flush_user_icache_range_asm(start, end);/* TRAMP Words 0-4, Length 5 =
SIGRESTARTBLOCK_TRAMP- * TRAMP Words 5-9, Length 4 =SIGRETURN_TRAMP
+ * TRAMP Words 5-7, Length 3 =SIGRETURN_TRAMP
* So theSIGRETURN_TRAMPis at the end ofSIGRESTARTBLOCK_TRAMP*/
rp = (unsigned long) &frame->tramp[SIGRESTARTBLOCK_TRAMP];arch/parisc/kernel/signal32.h +1
-2@@ -36,7 +36,7 @@ struct compat_regfile { compat_int_t rf_sar; }; -#define COMPAT_SIGRETURN_TRAMP 4 +#define COMPAT_SIGRETURN_TRAMP 3 #define COMPAT_SIGRESTARTBLOCK_TRAMP 5 #define COMPAT_TRAMP_SIZE (COMPAT_SIGRETURN_TRAMP + \ COMPAT_SIGRESTARTBLOCK_TRAMP) --2.31.1
Re: [PATCH 4/4] parisc: Reduce sigreturn trampoline to 3 instructions
I found the change with a regression search.
I don't know what's wrong with it. I have reverted it for now.
Here are test results with 5.16.0-rc1+ #1 SMP Mon Nov 15 17:56:32 EST 2021 parisc64:
XPASS: conform/UNIX98/ndbm.h/linknamespace
XPASS: conform/XOPEN2K/ndbm.h/linknamespace
XPASS: conform/XOPEN2K8/ndbm.h/linknamespace
XPASS: conform/XPG42/ndbm.h/linknamespace
FAIL: dirent/tst-readdir64-compat
FAIL: elf/tst-audit2
UNSUPPORTED: io/tst-fallocate
UNSUPPORTED: io/tst-fallocate64
UNSUPPORTED: misc/tst-adjtimex
UNSUPPORTED: misc/tst-adjtimex-time64
UNSUPPORTED: misc/tst-clock_adjtime
UNSUPPORTED: misc/tst-clock_adjtime-time64
UNSUPPORTED: misc/tst-ntp_adjtime
UNSUPPORTED: misc/tst-ntp_adjtime-time64
UNSUPPORTED: misc/tst-pkey
UNSUPPORTED: nptl/test-cond-printers
UNSUPPORTED: nptl/test-condattr-printers
UNSUPPORTED: nptl/test-mutex-printers
UNSUPPORTED: nptl/test-mutexattr-printers
UNSUPPORTED: nptl/test-rwlock-printers
UNSUPPORTED: nptl/test-rwlockattr-printers
FAIL: nptl/tst-cleanupx4
FAIL: nptl/tst-cond25
FAIL: signal/tst-minsigstksz-5
UNSUPPORTED: stdlib/test-bz22786
FAIL: stdlib/tst-setcontext2
FAIL: stdlib/tst-setcontext7
UNSUPPORTED: stdlib/tst-strtod-overflow
UNSUPPORTED: string/tst-memmove-overflow
UNSUPPORTED: time/tst-clock_settime
UNSUPPORTED: time/tst-clock_settime-time64
UNSUPPORTED: time/tst-settimeofday
UNSUPPORTED: time/tst-settimeofday-time64
UNSUPPORTED: time/tst-y2039
Summary of test results:
7 FAIL
4173 PASS
23 UNSUPPORTED
16 XFAIL
4 XPASS
Probably, Iecho $? should investigate why nptl/tst-cleanupx4 fails. Might be another issue with signal delivery.
Dave
Quoted 243 lines · Helge Deller
Dave,
Thanks for tracking this down!
I wonder what's wrong with it.
Based on the outcome I should either completely revert that patch or fix it.Helge
Quoted 233 lines · John David Anglin
This change breaks signal delivery and causes various glibc tests to fail.
commit
3e4a1aff2a97cb4fd7f0268e4b69e8c9d3641277:dave@atlas:~/gnu/glibc/objdir$ env GCONV_PATH=/home/dave/gnu/glibc/objdir/iconvdata LOCPATH=/home/dave/gnu/glibc/objdir/localedata LC_ALL=C /home/dave/gnu/glibc/objdir/elf/ld.so.1 --library-path /home/dave/gnu/glibc/objdir:/home/dave/gnu/glibc/objdir/math:/home/dave/gnu/glibc/objdir/elf:/home/dave/gnu/glibc/objdir/dlfcn:/home/dave/gnu/glibc/objdir/nss:/home/dave/gnu/glibc/objdir/nis:/home/dave/gnu/glibc/objdir/rt:/home/dave/gnu/glibc/objdir/resolv:/home/dave/gnu/glibc/objdir/mathvec:/home/dave/gnu/glibc/objdir/support:/home/dave/gnu/glibc/objdir/crypt:/home/dave/gnu/glibc/objdir/nptl /home/dave/gnu/glibc/objdir/nptl/tst-cancelx4 got size 4512 in-time cancel test of 'read' successful in-time cancel test of 'readv' successful in-time cancel test of 'select' successful in-time cancel test of 'pselect' successful in-time cancel test of 'poll' successful in-time cancel test of 'ppoll' successful in-time cancel test of 'write' successful in-time cancel test of 'writev' successful in-time cancel test of 'sleep' successful in-time cancel test of 'usleep' successful in-time cancel test of 'nanosleep' successful in-time cancel test of 'wait' successful in-time cancel test of 'waitid' successful in-time cancel test of 'waitpid' successful in-time cancel test of 'sigpause' successful in-time cancel test of 'sigsuspend' successful in-time cancel test of 'sigwait' successful in-time cancel test of 'sigwaitinfo' successful in-time cancel test of 'sigtimedwait' successful in-time cancel test of 'pause' successful in-time cancel test of 'accept' successful got size 4512 in-time cancel test of 'send' successful in-time cancel test of 'recv' successful in-time cancel test of 'recvfrom' successful in-time cancel test of 'recvmsg' successful in-time cancel test of 'msgrcv' successful early cancel test of 'read' successful early cancel test of 'readv' successful early cancel test of 'select' successful early cancel test of 'pselect' successful early cancel test of 'poll' successful early cancel test of 'ppoll' successful early cancel test of 'write' successful early cancel test of 'writev' successful early cancel test of 'sleep' successful early cancel test of 'usleep' successful early cancel test of 'nanosleep' successful early cancel test of 'wait' successful early cancel test of 'waitid' successful early cancel test of 'waitpid' successful early cancel test of 'sigpause' successful early cancel test of 'sigsuspend' successful early cancel test of 'sigwait' successful early cancel test of 'sigwaitinfo' successful early cancel test of 'sigtimedwait' successful early cancel test of 'pause' successful early cancel test of 'accept' successful got size 4512 early cancel test of 'send' successful early cancel test of 'recv' successful early cancel test of 'recvfrom' successful early cancel test of 'recvmsg' successful early cancel test of 'preadv' successful early cancel test of 'preadv2' successful early cancel test of 'pwritev' successful early cancel test of 'pwritev2' successful early cancel test of 'open' successful early cancel test of 'close' successful early cancel test of 'pread' successful early cancel test of 'pwrite' successful early cancel test of 'fsync' successful early cancel test of 'fdatasync' successful early cancel test of 'msync' successful got size 4512 early cancel test of 'sendto' successful early cancel test of 'sendmsg' successful early cancel test of 'creat' successful early cancel test of 'connect' successful early cancel test of 'tcdrain' successful early cancel test of 'msgrcv' successful early cancel test of 'msgsnd' successful dave@atlas:~/gnu/glibc/objdir$ echo $? 0commit
e4f2006f1287e7ea17660490569cff323772dac4:dave@atlas:~/gnu/glibc/objdir$ env GCONV_PATH=/home/dave/gnu/glibc/objdir/iconvdata LOCPATH=/home/dave/gnu/glibc/objdir/localedata LC_ALL=C /home/dave/gnu/glibc/objdir/elf/ld.so.1 --library-path /home/dave/gnu/glibc/objdir:/home/dave/gnu/glibc/objdir/math:/home/dave/gnu/glibc/objdir/elf:/home/dave/gnu/glibc/objdir/dlfcn:/home/dave/gnu/glibc/objdir/nss:/home/dave/gnu/glibc/objdir/nis:/home/dave/gnu/glibc/objdir/rt:/home/dave/gnu/glibc/objdir/resolv:/home/dave/gnu/glibc/objdir/mathvec:/home/dave/gnu/glibc/objdir/support:/home/dave/gnu/glibc/objdir/crypt:/home/dave/gnu/glibc/objdir/nptl /home/dave/gnu/glibc/objdir/nptl/tst-cancelx4 got size 4512 cleanup handler not called for 'read' cleanup handler not called for 'readv' cleanup handler not called for 'select' cleanup handler not called for 'pselect' cleanup handler not called for 'poll' cleanup handler not called for 'ppoll' cleanup handler not called for 'write' cleanup handler not called for 'writev' cleanup handler not called for 'sleep' cleanup handler not called for 'usleep' cleanup handler not called for 'nanosleep' cleanup handler not called for 'wait' cleanup handler not called for 'waitid' cleanup handler not called for 'waitpid' cleanup handler not called for 'sigpause' cleanup handler not called for 'sigsuspend' cleanup handler not called for 'sigwait' cleanup handler not called for 'sigwaitinfo' cleanup handler not called for 'sigtimedwait' cleanup handler not called for 'pause' cleanup handler not called for 'accept' got size 4512 cleanup handler not called for 'send' cleanup handler not called for 'recv' cleanup handler not called for 'recvfrom' cleanup handler not called for 'recvmsg' cleanup handler not called for 'msgrcv' early cancel test of 'read' successful early cancel test of 'readv' successful early cancel test of 'select' successful early cancel test of 'pselect' successful early cancel test of 'poll' successful early cancel test of 'ppoll' successful early cancel test of 'write' successful early cancel test of 'writev' successful early cancel test of 'sleep' successful early cancel test of 'usleep' successful early cancel test of 'nanosleep' successful early cancel test of 'wait' successful early cancel test of 'waitid' successful early cancel test of 'waitpid' successful early cancel test of 'sigpause' successful early cancel test of 'sigsuspend' successful early cancel test of 'sigwait' successful early cancel test of 'sigwaitinfo' successful early cancel test of 'sigtimedwait' successful early cancel test of 'pause' successful early cancel test of 'accept' successful got size 4512 early cancel test of 'send' successful early cancel test of 'recv' successful early cancel test of 'recvfrom' successful early cancel test of 'recvmsg' successful early cancel test of 'preadv' successful early cancel test of 'preadv2' successful early cancel test of 'pwritev' successful early cancel test of 'pwritev2' successful early cancel test of 'open' successful early cancel test of 'close' successful early cancel test of 'pread' successful early cancel test of 'pwrite' successful early cancel test of 'fsync' successful early cancel test of 'fdatasync' successful early cancel test of 'msync' successful got size 4512 early cancel test of 'sendto' successful early cancel test of 'sendmsg' successful early cancel test of 'creat' successful early cancel test of 'connect' successful early cancel test of 'tcdrain' successful early cancel test of 'msgrcv' successful early cancel test of 'msgsnd' successful dave@atlas:~/gnu/glibc/objdir$ echo $? 1Dave
Quoted 71 lines · Helge Deller
We can move the
INSN_LDI_R20instruction into the branch delay slot.Signed-off-by Helge Deller <[email protected]>--- arch/parisc/include/asm/rt_sigframe.h | 2 +- arch/parisc/kernel/signal.c | 13 ++++++------- arch/parisc/kernel/signal32.h | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-)arch/parisc/include/asm/rt_sigframe.h +1
-1@@ -2,7 +2,7 @@ #ifndef _ASM_PARISC_RT_SIGFRAME_H #define _ASM_PARISC_RT_SIGFRAME_H -#define SIGRETURN_TRAMP 4 +#define SIGRETURN_TRAMP 3 #define SIGRESTARTBLOCK_TRAMP 5 #define TRAMP_SIZE (SIGRETURN_TRAMP + SIGRESTARTBLOCK_TRAMP)arch/parisc/kernel/signal.c +6
-7@@ -288,22 +288,21 @@ setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs,already in userspace. The first words of tramp are used to save the previous sigrestartblock trampoline that might be on the stack. We start the sigreturn trampoline at -SIGRESTARTBLOCK_TRAMP+X. */ +SIGRESTARTBLOCK_TRAMP. */ err |= __put_user(in_syscall ? INSN_LDI_R25_1 : INSN_LDI_R25_0, &frame->tramp[SIGRESTARTBLOCK_TRAMP+0]); - err |= __put_user(INSN_LDI_R20, - &frame->tramp[SIGRESTARTBLOCK_TRAMP+1]); err |= __put_user(INSN_BLE_SR2_R0, + &frame->tramp[SIGRESTARTBLOCK_TRAMP+1]); + err |= __put_user(INSN_LDI_R20, &frame->tramp[SIGRESTARTBLOCK_TRAMP+2]); - err |= __put_user(INSN_NOP, &frame->tramp[SIGRESTARTBLOCK_TRAMP+3]); - start = (unsigned long) &frame->tramp[0]; - end = (unsigned long) &frame->tramp[TRAMP_SIZE]; + start = (unsigned long) &frame->tramp[SIGRESTARTBLOCK_TRAMP+0]; + end = (unsigned long) &frame->tramp[SIGRESTARTBLOCK_TRAMP+3]; flush_user_dcache_range_asm(start, end); flush_user_icache_range_asm(start, end); /* TRAMP Words 0-4, Length 5 = SIGRESTARTBLOCK_TRAMP - * TRAMP Words 5-9, Length 4 = SIGRETURN_TRAMP + * TRAMP Words 5-7, Length 3 = SIGRETURN_TRAMP * So the SIGRETURN_TRAMP is at the end of SIGRESTARTBLOCK_TRAMP */ rp = (unsigned long) &frame->tramp[SIGRESTARTBLOCK_TRAMP];arch/parisc/kernel/signal32.h +1
-2@@ -36,7 +36,7 @@ struct compat_regfile { compat_int_t rf_sar; }; -#define COMPAT_SIGRETURN_TRAMP 4 +#define COMPAT_SIGRETURN_TRAMP 3 #define COMPAT_SIGRESTARTBLOCK_TRAMP 5 #define COMPAT_TRAMP_SIZE (COMPAT_SIGRETURN_TRAMP + \ COMPAT_SIGRESTARTBLOCK_TRAMP) --2.31.1
Signature · 1 line
John David Anglin [email protected]
Re: [PATCH 4/4] parisc: Reduce sigreturn trampoline to 3 instructions
Quoted 1 line · John David Anglin
I don't know what's wrong with it. I have reverted it for now.
I think problem must be with cache flush range.
Dave
Signature · 1 line
John David Anglin [email protected]
Helge Deller
maintainerRe: [PATCH 4/4] parisc: Reduce sigreturn trampoline to 3 instructions
Quoted 3 lines · John David Anglin
Quoted 1 line · John David Anglin
I don't know what's wrong with it. I have reverted it for now.
I think problem must be with cache flush range.
Not sure. Seems like reverting SIGRETURN_TRAMP back to 4 fixes it.
Anyway, I'll revert the whole patch for now.
Maybe we can fix it in v5.17.
Helge
Re: [PATCH 4/4] parisc: Reduce sigreturn trampoline to 3 instructions
Quoted 4 lines · Helge Deller
Quoted 3 lines · John David Anglin
Quoted 1 line · John David Anglin
I don't know what's wrong with it. I have reverted it for now.
I think problem must be with cache flush range.
Didn't work 🙁
Quoted 3 lines
Not sure. Seems like reverting
SIGRETURN_TRAMPback to 4 fixes it.Anyway, I'll revert the whole patch for now.
Reverting whole patch fixed issue with 5.15.2 and 5.16.0-rc1.
Quoted 1 line
Maybe we can fix it in v5.17.
Dave
Signature · 1 line
John David Anglin [email protected]
Quoted 3 lines · Helge Deller
As suggested by Arnd Bergmann, drop the parisc version of
strnlen_user()and switch to the generic version.
The strnlen_user() removal looks good,
Quoted 1 line
user_addr_max()was wrong too, fix it by usingTASK_SIZE.
Not sure about this part though:
arch/parisc/include/asm/uaccess.h struct exception_table_entry { · line 208
Quoted 5 lines
/*
* Complex access routines -- macros
*/arch/parisc/include/asm/uaccess.h +1
-1-#define user_addr_max () (~0UL) +#define user_addr_max () (uaccess_kernel() ? ~0UL : TASK_SIZE)
We are getting very close to completely removing set_fs()/get_fs(), uaccess_kernel() and some related bits from the kernel, so I think it would be better to the other way here and finish off removing CONFIG_SET_FS from parisc.
I think this will also simplify your asm/uaccess.h a lot, in particular since it has separate address spaces for __get_user() and __get_kernel_nofault(), and without set_fs() you can leave out the runtime conditional to switch between them.
Arnd
Helge Deller
maintainerQuoted 8 lines · Arnd Bergmann
Quoted 3 lines · Helge Deller
As suggested by Arnd Bergmann, drop the parisc version of
strnlen_user()and switch to the generic version.The
strnlen_user()removal looks good,Acked-by Arnd Bergmann <[email protected]>
Good.
Quoted 9 lines
Quoted 1 line
user_addr_max()was wrong too, fix it by usingTASK_SIZE.Not sure about this part though:
arch/parisc/include/asm/uaccess.h struct exception_table_entry { · line 208
Quoted 5 lines
/*
* Complex access routines -- macros
*/arch/parisc/include/asm/uaccess.h +1
-1-#define user_addr_max () (~0UL) +#define user_addr_max () (uaccess_kernel() ? ~0UL : TASK_SIZE)
I noticed that our user_addr_max() was actually wrong.
It's used in the generic strnlen_user() so fixing it seemed appropriate.
Quoted 9 lines
We are getting very close to completely removing set_fs()/get_fs(),
uaccess_kernel()and some related bits from the kernel, so I think it would be better to the other way here and finish off removingCONFIG_SET_FSfrom parisc.I think this will also simplify your
asm/uaccess.ha lot, in particular since it has separate address spaces for__get_user()and__get_kernel_nofault(), and withoutset_fs()you can leave out the runtime conditional to switch between them.
That's a good idea and should probably be done.
Do you have some pointers where to start, e.g. initial commits from other arches ?
Helge
Quoted 9 lines · Helge Deller
Quoted 5 lines · Arnd Bergmann
arch/parisc/include/asm/uaccess.h struct exception_table_entry { · line 208
Quoted 5 lines
/*
* Complex access routines -- macros
*/arch/parisc/include/asm/uaccess.h +1
-1-#define user_addr_max () (~0UL) +#define user_addr_max () (uaccess_kernel() ? ~0UL : TASK_SIZE)I noticed that our
user_addr_max()was actually wrong.
It's used in the genericstrnlen_user()so fixing it seemed appropriate.
The user_addr_max() definition should match what you do in access_ok() for USER_DS though, which is a nop on architectures that have split user address space, so I think the ~0UL was correct here.
No matter what the arguments are, there is no danger of spilling over into kernel space, which is what the user_addr_max() check is trying to prevent on other architectures.
Quoted 5 lines
Quoted 5 lines
We are getting very close to completely removing set_fs()/get_fs(),
uaccess_kernel()and some related bits from the kernel, so I think it would be better to the other way here and finish off removingCONFIG_SET_FSfrom parisc.
Quoted 7 lines
Quoted 4 lines
I think this will also simplify your
asm/uaccess.ha lot, in particular since it has separate address spaces for__get_user()and__get_kernel_nofault(), and withoutset_fs()you can leave out the runtime conditional to switch between them.That's a good idea and should probably be done.
Do you have some pointers where to start, e.g. initial commits from other arches ?
Russell just merged my series for arch/arm in linux-5.15, you can look at that but it's probably easier for parisc.
I think the only part you need to add is __get_kernel_nofault() and __put_kernel_nofault(). You can see in mm/maccess.c what the difference between the two versions in there is.
Once you have those, you define HAVE_GET_KERNEL_NOFAULT and then remove CONFIG_SET_FS, set_fs(), get_fs(), load_sr2(), thread_info->addr_limit, KERNEL_DS, and USER_DS.
Arnd
Helge Deller
maintainer* Arnd Bergmann <[email protected]>:
Quoted 35 lines · Helge Deller
Quoted 9 lines · Arnd Bergmann
Quoted 5 lines
Review
Quoted 5 lines
/*
* Complex access routines -- macros
*/(quoted diff) +1
-1-#define user_addr_max() (~0UL) +#define user_addr_max() (uaccess_kernel() ? ~0UL : TASK_SIZE)I noticed that our
user_addr_max()was actually wrong.
It's used in the genericstrnlen_user()so fixing it seemed appropriate.The
user_addr_max()definition should match what you do inaccess_ok()forUSER_DSthough, which is a nop on architectures that have split user address space, so I think the ~0UL was correct here.No matter what the arguments are, there is no danger of spilling over into kernel space, which is what the
user_addr_max()check is trying to prevent on other architectures.Quoted 5 lines
Quoted 5 lines
We are getting very close to completely removing set_fs()/get_fs(),
uaccess_kernel()and some related bits from the kernel, so I think it would be better to the other way here and finish off removingCONFIG_SET_FSfrom parisc.Quoted 7 lines
Quoted 4 lines
I think this will also simplify your
asm/uaccess.ha lot, in particular since it has separate address spaces for__get_user()and__get_kernel_nofault(), and withoutset_fs()you can leave out the runtime conditional to switch between them.That's a good idea and should probably be done.
Do you have some pointers where to start, e.g. initial commits from other arches ?Russell just merged my series for
arch/armin linux-5.15, you can look at that but it's probably easier for parisc.
Quoted 7 lines
I think the only part you need to add is
__get_kernel_nofault()and__put_kernel_nofault(). You can see inmm/maccess.cwhat the difference between the two versions in there is.Once you have those, you define
HAVE_GET_KERNEL_NOFAULTand then removeCONFIG_SET_FS,set_fs(),get_fs(),load_sr2(),thread_info->addr_limit,KERNEL_DS, andUSER_DS.
Thanks for those hints!
The attached initial patch below seems to work, it boots into systemd. It needs further cleanups though.
I wonder if you should add a workaround for 32-bit kernels to not copy 64bit-wise, see my patch below in copy_from_kernel_nofault():
- copy_from_kernel_nofault_loop(dst, src, size, u64, Efault); + /* avoid 64-bit accesses on 32-bit platforms */ + if (sizeof(unsigned long) > 4)
+ copy_from_kernel_nofault_loop(dst, src, size, u64, Efault);
Helge
---
[PATCH] parisc: Implement __get/put_kernel_nofault()
Add __get_kernel_nofault() and __put_kernel_nofault(), define HAVE_GET_KERNEL_NOFAULT and remove CONFIG_SET_FS, set_fs(), get_fs(), load_sr2(), thread_info->addr_limit, KERNEL_DS, and USER_DS.
arch/parisc/Kconfig +0 -1
@@ -64,7 +64,6 @@ config PARISC select HAVE_KPROBES_ON_FTRACE select HAVE_DYNAMIC_FTRACE_WITH_REGS select HAVE_SOFTIRQ_ON_OWN_STACK if IRQSTACKS - select SET_FS help The PA-RISC microprocessor is designed by Hewlett-Packard and used
arch/parisc/include/asm/processor.h +0 -4
@@ -101,10 +101,6 @@ DECLARE_PER_CPU(struct cpuinfo_parisc, cpu_data);#define CPU_HVERSION ((boot_cpu_data.hversion >> 4) & 0x0FFF) -typedef struct { -int seg; -}mm_segment_t ; -#define ARCH_MIN_TASKALIGN 8struct thread_struct {
arch/parisc/include/asm/thread_info.h +0 -2
@@ -11,7 +11,6 @@struct thread_info {struct task_struct *task;/* main task structure */ unsigned long flags;/* thread_info flags (see TIF_*) */ -mm_segment_t addr_limit;/* user-level address space limit */ __u32 cpu;/* current CPU */ int preempt_count;/* 0=premptable, <0=BUG; will also serve as bh-counter */ };
@@ -21,7 +20,6 @@ struct thread_info { .task = &tsk, \ .flags = 0, \ .cpu = 0, \ - .addr_limit = KERNEL_DS, \ .preempt_count = INIT_PREEMPT_COUNT, \ }
arch/parisc/include/asm/uaccess.h +63 -63
212 lines not on this page · raw message
arch/parisc/kernel/asm-offsets.c +1 -1
@@ -230,7 +230,7 @@ int main(void)DEFINE (TI_TASK , offsetof(struct thread_info , task));DEFINE (TI_FLAGS , offsetof(struct thread_info , flags));DEFINE (TI_CPU , offsetof(struct thread_info , cpu)); -DEFINE (TI_SEGMENT , offsetof(struct thread_info , addr_limit)); +// DEFINE(TI_SEGMENT, offsetof(struct thread_info, addr_limit)); DEFINE (TI_PRE_COUNT , offsetof(struct thread_info , preempt_count));DEFINE (THREAD_SZ ,sizeof (struct thread_info ));/* THREAD_SZ_ALGN includes space for a stack frame. */
arch/parisc/lib/lusercopy.S +4 -4
@@ -34,11 +34,11 @@ */ .macro get_sr - mfctl %cr30,%r1 - ldw TI_SEGMENT(%r1),%r22 +// mfctl %cr30,%r1 +// ldw TI_SEGMENT(%r1),%r22 mfsp %sr3,%r1 - or,<> %r22,%r0,%r0 - copy %r0,%r1 +// or,<> %r22,%r0,%r0 +// copy %r0,%r1 mtsp %r1,%sr1 .endm
mm/maccess.c +6 -2
@@ -28,7 +28,9 @@ long copy_from_kernel_nofault(void *dst, const void *src, size_t size)return -ERANGE ;pagefault_disable (); -copy_from_kernel_nofault_loop (dst, src, size, u64, Efault); +/* avoid 64-bit accesses on 32-bit platforms */ +if (sizeof (unsigned long ) >4 ) +copy_from_kernel_nofault_loop (dst, src, size, u64, Efault);copy_from_kernel_nofault_loop (dst, src, size, u32, Efault);copy_from_kernel_nofault_loop (dst, src, size, u16, Efault);copy_from_kernel_nofault_loop (dst, src, size, u8, Efault);
@@ -51,7 +53,9 @@ EXPORT_SYMBOL_GPL(copy_from_kernel_nofault);long copy_to_kernel_nofault (void *dst,const void *src,size_t size) {pagefault_disable (); -copy_to_kernel_nofault_loop (dst, src, size, u64, Efault); +/* avoid 64-bit accesses on 32-bit platforms */ +if (sizeof (unsigned long ) >4 ) +copy_to_kernel_nofault_loop (dst, src, size, u64, Efault);copy_to_kernel_nofault_loop (dst, src, size, u32, Efault);copy_to_kernel_nofault_loop (dst, src, size, u16, Efault);copy_to_kernel_nofault_loop (dst, src, size, u8, Efault);
Quoted 18 lines · Helge Deller
* Arnd Bergmann <[email protected]>:
Quoted 8 lines
I think the only part you need to add is
__get_kernel_nofault()and__put_kernel_nofault(). You can see inmm/maccess.cwhat the difference between the two versions in there is.Once you have those, you define
HAVE_GET_KERNEL_NOFAULTand then removeCONFIG_SET_FS,set_fs(),get_fs(),load_sr2(),thread_info->addr_limit,KERNEL_DS, andUSER_DS.Thanks for those hints!
The attached initial patch below seems to work, it boots into systemd. It needs further cleanups though.I wonder if you should add a workaround for 32-bit kernels to not copy 64bit-wise, see my patch below in
copy_from_kernel_nofault():
mm/maccess.c long copy_from_kernel_nofault(void *dst, const void *src, size_t size) · line 33
Quoted 4 lines
mm/maccess.c +3
-1-copy_from_kernel_nofault_loop (dst, src, size, u64, Efault); +/* avoid 64-bit accesses on 32-bit platforms */ +if (sizeof (unsigned long ) >4 ) +copy_from_kernel_nofault_loop (dst, src, size, u64, Efault);
I would assume that the 8-byte copy would just turn into two 4-byte accesses here, with exactly the same behavior. Note that this function changed in 5.15 when I added support for architectures without unaligned access. You need to include 132b548af559 ("mm/maccess:
fix unaligned copy_{from,to}_kernel_nofault") here for parsic as well, I assume.
If you prefer to avoid the 8-byte access, this could be done in the 'align = (unsigned long)dst | (unsigned long)src;' statement by masking out that bit.
Quoted 8 lines
[PATCH] parisc: Implement __get/put_kernel_nofault()
Add
__get_kernel_nofault()and__put_kernel_nofault(), defineHAVE_GET_KERNEL_NOFAULTand removeCONFIG_SET_FS,set_fs(),get_fs(),load_sr2(),thread_info->addr_limit,KERNEL_DS, andUSER_DS.Signed-off-by Helge Deller <[email protected]>Suggested-by Arnd Bergmann <[email protected]>
Looks good to me overall, with the missing cleanups added.
You should probably include a TASK_SIZE_MAX definition that matches the old user_addr_max() to avoid looking up the per-task value every time.
Arnd