Message ID | 1576225834-16389-1-git-send-email-sunguoyun@loongson.cn (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [V2] MIPS: Add get_thread_area syscall | expand |
On Fri, Dec 13, 2019 at 9:30 AM Guoyun Sun <sunguoyun@loongson.cn> wrote: Thanks for fixing the numbers. On second look, I saw another problem: > diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c > index c333e57..20bf4c5 100644 > --- a/arch/mips/kernel/syscall.c > +++ b/arch/mips/kernel/syscall.c > @@ -94,6 +94,16 @@ SYSCALL_DEFINE1(set_thread_area, unsigned long, addr) > return 0; > } > > +SYSCALL_DEFINE1(get_thread_area, unsigned long __user *, u_info) > +{ > + struct thread_info *ti = task_thread_info(current); > + > + if (copy_to_user(u_info, &(ti->tp_value), sizeof(ti->tp_value))) > + return -EFAULT; > + > + return 0; > +} > + This won't work for compat mode, when tp_value is a different size in kernel and user space. You could either add a COMPAT_SYSCALL_DEFINE1() variant, or handle it like if (in_compat_syscall()) return put_user(ti->tp_value, (__u32 *)u_info); return put_user(ti->tp_value, u_info); Arnd
diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c index c333e57..20bf4c5 100644 --- a/arch/mips/kernel/syscall.c +++ b/arch/mips/kernel/syscall.c @@ -94,6 +94,16 @@ SYSCALL_DEFINE1(set_thread_area, unsigned long, addr) return 0; } +SYSCALL_DEFINE1(get_thread_area, unsigned long __user *, u_info) +{ + struct thread_info *ti = task_thread_info(current); + + if (copy_to_user(u_info, &(ti->tp_value), sizeof(ti->tp_value))) + return -EFAULT; + + return 0; +} + static inline int mips_atomic_set(unsigned long addr, unsigned long new) { unsigned long old, tmp; diff --git a/arch/mips/kernel/syscalls/syscall_n32.tbl b/arch/mips/kernel/syscalls/syscall_n32.tbl index e7c5ab3..3aa4858 100644 --- a/arch/mips/kernel/syscalls/syscall_n32.tbl +++ b/arch/mips/kernel/syscalls/syscall_n32.tbl @@ -341,6 +341,8 @@ 330 n32 statx sys_statx 331 n32 rseq sys_rseq 332 n32 io_pgetevents compat_sys_io_pgetevents +333 n32 get_thread_area sys_get_thread_area + # 333 through 402 are unassigned to sync up with generic numbers 403 n32 clock_gettime64 sys_clock_gettime 404 n32 clock_settime64 sys_clock_settime diff --git a/arch/mips/kernel/syscalls/syscall_n64.tbl b/arch/mips/kernel/syscalls/syscall_n64.tbl index 13cd665..14b6796 100644 --- a/arch/mips/kernel/syscalls/syscall_n64.tbl +++ b/arch/mips/kernel/syscalls/syscall_n64.tbl @@ -337,6 +337,8 @@ 326 n64 statx sys_statx 327 n64 rseq sys_rseq 328 n64 io_pgetevents sys_io_pgetevents +329 n64 get_thread_area sys_get_thread_area + # 329 through 423 are reserved to sync up with other architectures 424 n64 pidfd_send_signal sys_pidfd_send_signal 425 n64 io_uring_setup sys_io_uring_setup diff --git a/arch/mips/kernel/syscalls/syscall_o32.tbl b/arch/mips/kernel/syscalls/syscall_o32.tbl index 353539e..bb4e050 100644 --- a/arch/mips/kernel/syscalls/syscall_o32.tbl +++ b/arch/mips/kernel/syscalls/syscall_o32.tbl @@ -380,6 +380,8 @@ 366 o32 statx sys_statx 367 o32 rseq sys_rseq 368 o32 io_pgetevents sys_io_pgetevents_time32 compat_sys_io_pgetevents +369 o32 get_thread_area sys_get_thread_area + # room for arch specific calls 393 o32 semget sys_semget 394 o32 semctl sys_semctl compat_sys_semctl
CRIU(https://criu.org/) tools will dump TLS(Thread Local Storage) by get_thread_area during checkpoint and restore TLS by set_thread_area during restore. without syscall get_thread_area, criu restore will fail on MIPS platform.because a variable with GCC __thread is invalid. The following function will be called when criu restore static inline void restore_tls(tls_t *ptls) { asm volatile( "move $4, %0 \n" "li $2, "__stringify(__NR_set_thread_area)" \n" "syscall \n" : : "r"(*ptls) : "$4","$2","memory"); With this patch, the *ptls can be obtained by get_thread_area on MIPS platform when criu checkpoint. just like this: static inline void arch_get_tls(tls_t *ptls) { asm volatile( "move $4, %0 \n" "li $2, "__stringify(__NR_get_thread_area)" \n" "syscall \n" : : "r"(ptls) : "$4","$2","memory"); } Signed-off-by: Guoyun Sun <sunguoyun@loongson.cn> --- arch/mips/kernel/syscall.c | 10 ++++++++++ arch/mips/kernel/syscalls/syscall_n32.tbl | 2 ++ arch/mips/kernel/syscalls/syscall_n64.tbl | 2 ++ arch/mips/kernel/syscalls/syscall_o32.tbl | 2 ++ 4 files changed, 16 insertions(+)