ipc/msg: add msgsnd_timed and msgrcv_timed syscall for system V message queue
Subsystems (16)
PATCH 1/1 ipc/msg: add msgsnd_timed and msgrcv_timed syscall for system V message queue
sometimes, we need the msgsnd or msgrcv syscall can return after a limited time, so that the business thread do not be blocked here all the time. In this case, I add the msgsnd_timed and msgrcv_timed syscall that with time parameter, which has a unit of ms.
--- arch/alpha/kernel/syscalls/syscall.tbl | 2 + arch/arm/tools/syscall.tbl | 2 + arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 4 ++ arch/ia64/kernel/syscalls/syscall.tbl | 2 + arch/m68k/kernel/syscalls/syscall.tbl | 2 + arch/microblaze/kernel/syscalls/syscall.tbl | 2 + arch/mips/kernel/syscalls/syscall_n32.tbl | 2 + arch/mips/kernel/syscalls/syscall_n64.tbl | 2 + arch/mips/kernel/syscalls/syscall_o32.tbl | 2 + arch/parisc/kernel/syscalls/syscall.tbl | 2 + arch/powerpc/kernel/syscalls/syscall.tbl | 2 + arch/s390/kernel/syscalls/syscall.tbl | 2 + arch/sh/kernel/syscalls/syscall.tbl | 2 + arch/sparc/kernel/syscalls/syscall.tbl | 2 + arch/x86/entry/syscalls/syscall_32.tbl | 2 + arch/x86/entry/syscalls/syscall_64.tbl | 2 + arch/xtensa/kernel/syscalls/syscall.tbl | 2 + include/linux/compat.h | 4 ++ include/linux/syscalls.h | 4 ++ include/uapi/asm-generic/unistd.h | 6 +- ipc/msg.c | 87 ++++++++++++++++++++++++++--- kernel/sys_ni.c | 4 ++ 23 files changed, 133 insertions(+), 10 deletions(-)
arch/alpha/kernel/syscalls/syscall.tbl +2 -0
@@ -482,3 +482,5 @@ 550 common process_madvise sys_process_madvise 551 common epoll_pwait2 sys_epoll_pwait2 552 common mount_setattr sys_mount_setattr +553 common msgrcv_timed sys_msgrcv_timed +554 common msgsnd_timed sys_msgsnd_timed
arch/arm/tools/syscall.tbl +2 -0
@@ -456,3 +456,5 @@ 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 442 common mount_setattr sys_mount_setattr +443 common msgrcv_timed sys_msgrcv_timed +444 common msgsnd_timed sys_msgsnd_timed
arch/arm64/include/asm/unistd.h +1 -1
@@ -38,7 +38,7 @@#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)#define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 443 +#define __NR_compat_syscalls 445#endif #define __ARCH_WANT_SYS_CLONE
arch/arm64/include/asm/unistd32.h +4 -0
@@ -893,6 +893,10 @@ __SYSCALL(__NR_process_madvise, sys_process_madvise) __SYSCALL(__NR_epoll_pwait2, compat_sys_epoll_pwait2)#define __NR_mount_setattr 442 __SYSCALL(__NR_mount_setattr, sys_mount_setattr) +#define __NR_msgrcv_timed 443 +__SYSCALL(__NR_msgrcv_timed, sys_msgrcv_timed) +#define __NR_msgsnd_timed 444 +__SYSCALL (__NR_msgsnd_timed, sys_msgsnd_timed)/* * Please add new compat syscalls above this comment and update
arch/ia64/kernel/syscalls/syscall.tbl +2 -0
@@ -363,3 +363,5 @@ 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 442 common mount_setattr sys_mount_setattr +443 common msgrcv_timed sys_msgrcv_timed +444 common msgsnd_timed sys_msgsnd_timed
arch/m68k/kernel/syscalls/syscall.tbl +2 -0
@@ -442,3 +442,5 @@ 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 442 common mount_setattr sys_mount_setattr +443 common msgrcv_timed sys_msgrcv_timed +444 common msgsnd_timed sys_msgsnd_timed
arch/microblaze/kernel/syscalls/syscall.tbl +2 -0
@@ -448,3 +448,5 @@ 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 442 common mount_setattr sys_mount_setattr +443 common msgrcv_timed sys_msgrcv_timed +444 common msgsnd_timed sys_msgsnd_timed
arch/mips/kernel/syscalls/syscall_n32.tbl +2 -0
@@ -381,3 +381,5 @@ 440 n32 process_madvise sys_process_madvise 441 n32 epoll_pwait2 compat_sys_epoll_pwait2 442 n32 mount_setattr sys_mount_setattr +443 n32 msgrcv_timed sys_msgrcv_timed +444 n32 msgsnd_timed sys_msgsnd_timed
arch/mips/kernel/syscalls/syscall_n64.tbl +2 -0
@@ -357,3 +357,5 @@ 440 n64 process_madvise sys_process_madvise 441 n64 epoll_pwait2 sys_epoll_pwait2 442 n64 mount_setattr sys_mount_setattr +443 n64 msgrcv_timed sys_msgrcv_timed +444 n64 msgsnd_timed sys_msgsnd_timed
arch/mips/kernel/syscalls/syscall_o32.tbl +2 -0
@@ -430,3 +430,5 @@ 440 o32 process_madvise sys_process_madvise 441 o32 epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2 442 o32 mount_setattr sys_mount_setattr +443 o32 msgrcv_timed sys_msgrcv_timed +444 o32 msgsnd_timed sys_msgsnd_timed
arch/parisc/kernel/syscalls/syscall.tbl +2 -0
@@ -440,3 +440,5 @@ 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2 442 common mount_setattr sys_mount_setattr +443 common msgrcv_timed sys_msgrcv_timed compat_sys_msgrcv_timed +444 common msgsnd_timed sys_msgsnd_timed compat_sys_msgsnd_timed
arch/powerpc/kernel/syscalls/syscall.tbl +2 -0
@@ -522,3 +522,5 @@ 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2 442 common mount_setattr sys_mount_setattr +443 common msgrcv_timed sys_msgrcv_timed compat_sys_msgrcv_timed +444 common msgsnd_timed sys_msgsnd_timed compat_sys_msgsnd_timed
arch/s390/kernel/syscalls/syscall.tbl +2 -0
@@ -445,3 +445,5 @@ 440 common process_madvise sys_process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2 442 common mount_setattr sys_mount_setattr sys_mount_setattr +443 common msgrcv_timed sys_msgrcv_timed compat_sys_msgrcv_timed +444 common msgsnd_timed sys_msgsnd_timed compat_sys_msgsnd_timed
arch/sh/kernel/syscalls/syscall.tbl +2 -0
@@ -445,3 +445,5 @@ 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 442 common mount_setattr sys_mount_setattr +443 common msgrcv_timed sys_msgrcv_timed +444 common msgsnd_timed sys_msgsnd_timed
arch/sparc/kernel/syscalls/syscall.tbl +2 -0
@@ -488,3 +488,5 @@ 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2 442 common mount_setattr sys_mount_setattr +443 common msgrcv_timed sys_msgrcv_timed compat_sys_msgrcv_timed +444 common msgsnd_timed sys_msgsnd_timed compat_sys_msgsnd_timed
arch/x86/entry/syscalls/syscall_32.tbl +2 -0
@@ -447,3 +447,5 @@ 440 i386 process_madvise sys_process_madvise 441 i386 epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2 442 i386 mount_setattr sys_mount_setattr +443 i386 msgrcv_timed sys_msgrcv_timed compat_sys_msgrcv_timed +444 i386 msgsnd_timed sys_msgsnd_timed compat_sys_msgsnd_timed
arch/x86/entry/syscalls/syscall_64.tbl +2 -0
@@ -364,6 +364,8 @@ 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 442 common mount_setattr sys_mount_setattr +443 common msgrcv_timed sys_msgrcv_timed +444 common msgsnd_timed sys_msgsnd_timed # # Due to a historical design error, certain syscalls are numbered differently
arch/xtensa/kernel/syscalls/syscall.tbl +2 -0
@@ -413,3 +413,5 @@ 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 442 common mount_setattr sys_mount_setattr +443 common msgrcv_timed sys_msgrcv_timed +444 common msgsnd_timed sys_msgsnd_timed
include/linux/compat.h +4 -0
@@ -743,6 +743,10 @@ asmlinkage long compat_sys_msgrcv(int msqid, compat_uptr_t msgp, compat_ssize_t msgsz, compat_long_t msgtyp, int msgflg);asmlinkage long compat_sys_msgsnd (int msqid,compat_uptr_t msgp,compat_ssize_t msgsz,int msgflg); +asmlinkage long compat_sys_msgrcv_timed (int msqid,compat_uptr_t msgp, +compat_ssize_t msgsz,compat_long_t msgtyp,int msgflg,compat_long_t timeoutms); +asmlinkage long compat_sys_msgsnd_timed (int msqid,compat_uptr_t msgp, +compat_ssize_t msgsz,int msgflg,compat_long_t timeoutms);/* ipc/sem.c */ asmlinkage long compat_sys_semctl (int semid,int semnum,int cmd,int arg);
include/linux/syscalls.h +4 -0
@@ -808,6 +808,10 @@ asmlinkage long sys_msgrcv(int msqid, struct msgbuf __user *msgp, size_t msgsz, long msgtyp, int msgflg);asmlinkage long sys_msgsnd (int msqid,struct msgbuf __user *msgp,size_t msgsz,int msgflg); +asmlinkage long sys_msgrcv_timed (int msqid,struct msgbuf __user *msgp, +size_t msgsz,long msgtyp,int msgflg,long timeoutms); +asmlinkage long sys_msgsnd_timed (int msqid,struct msgbuf __user *msgp, +size_t msgsz,int msgflg,long timeoutms);/* ipc/sem.c */ asmlinkage long sys_semget (key_t key,int nsems,int semflg);
include/uapi/asm-generic/unistd.h +5 -1
@@ -561,6 +561,10 @@ __SC_COMP(__NR_msgctl, sys_msgctl, compat_sys_msgctl) __SC_COMP(__NR_msgrcv, sys_msgrcv, compat_sys_msgrcv)#define __NR_msgsnd 189 __SC_COMP(__NR_msgsnd, sys_msgsnd, compat_sys_msgsnd) +#define __NR_msgrcv_timed 443 +__SC_COMP(__NR_msgrcv_timed, sys_msgrcv_timed, compat_sys_msgrcv_timed) +#define __NR_msgsnd_timed 444 +__SC_COMP (__NR_msgsnd_timed, sys_msgsnd_timed, compat_sys_msgsnd_timed) /* ipc/sem.c */#define __NR_semget 190
@@ -865,7 +869,7 @@ __SC_COMP(__NR_epoll_pwait2, sys_epoll_pwait2, compat_sys_epoll_pwait2) __SYSCALL(__NR_mount_setattr, sys_mount_setattr)#undef __NR_syscalls -#define __NR_syscalls 443 +#define __NR_syscalls 445/* * 32 bit systems traditionally used different
ipc/msg.c +79 -8
183 lines not on this page · raw message
kernel/sys_ni.c +4 -0
@@ -212,6 +212,10 @@ COND_SYSCALL(msgrcv);COND_SYSCALL_COMPAT (msgrcv);COND_SYSCALL (msgsnd);COND_SYSCALL_COMPAT (msgsnd); +COND_SYSCALL (msgrcv_timed); +COND_SYSCALL_COMPAT (msgrcv_timed); +COND_SYSCALL (msgsnd_timed); +COND_SYSCALL_COMPAT (msgsnd_timed);/* ipc/sem.c */ COND_SYSCALL (semget);
Signature · 1 line
2.7.4
Quoted 7 lines · Eric Gao
sometimes, we need the msgsnd or msgrcv syscall can return after a limited time, so that the business thread do not be blocked here all the time. In this case, I add the
msgsnd_timedandmsgrcv_timedsyscall that with time parameter, which has a unit of ms.Signed-off-by Eric Gao <[email protected]>
I have no opinion on whether we want or need this, but I'll have a look at the implementation, to see if the ABI makes sense.
Quoted 14 lines
index 8fd8c17..42b7db5 100644
arch/mips/kernel/syscalls/syscall_n32.tbl +2
-0@@ -381,3 +381,5 @@ 440 n32 process_madvise sys_process_madvise 441 n32 epoll_pwait2 compat_sys_epoll_pwait2 442 n32 mount_setattr sys_mount_setattr +443 n32 msgrcv_timed sys_msgrcv_timed +444 n32 msgsnd_timed sys_msgsnd_timedarch/mips/kernel/syscalls/syscall_o32.tbl +0
-0
arch/mips/kernel/syscalls/syscall_o32.tbl line 434
Quoted 5 lines
arch/mips/kernel/syscalls/syscall_o32.tbl +2
-0@@ -430,3 +430,5 @@ 440 o32 process_madvise sys_process_madvise 441 o32 epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2 442 o32 mount_setattr sys_mount_setattr +443 o32 msgrcv_timed sys_msgrcv_timed +444 o32 msgsnd_timed sys_msgsnd_timed
I think mips n32 and o32 both need to use the compat version when running on a 64-bit kernel, while your patch makes them use the native version.
Quoted 4 lines
arch/mips/kernel/syscalls/syscall_o32.tbl +0
-0@@ -905,7 +906,15 @@ static long do_msgsnd(int msqid, long mtype, void __user *mtext, ipc_unlock_object(&msq->q_perm); rcu_read_unlock();
arch/mips/kernel/syscalls/syscall_o32.tbl static long do_msgsnd(int msqid, long mtype, void __user *mtext, · line 917
Quoted 10 lines
arch/mips/kernel/syscalls/syscall_o32.tbl +9
-1- schedule(); + + /* sometimes, we need msgsnd syscall return after a given time */ + if (timeoutms <= 0) { + schedule(); + } else { + timeoutms = schedule_timeout(timeoutms); + if (timeoutms == 0) + timeoutflag = true; + }
I wonder if this should be schedule_timeout_interruptible() or at least schedule_timeout_killable() instead of schedule_timeout(). If it should, this should probably be done as a separate change.
arch/mips/kernel/syscalls/syscall_o32.tbl static long do_msgsnd(int msqid, long mtype, void __user *mtext,
Quoted 13 lines
arch/mips/kernel/syscalls/syscall_o32.tbl +13
-0+COMPAT_SYSCALL_DEFINE5(msgsnd_timed, int, msqid, compat_uptr_t, msgp, + compat_ssize_t, msgsz, int, msgflg, compat_long_t, timeoutms) +{ + struct compat_msgbuf __user *up = compat_ptr(msgp); + compat_long_t mtype; + + timeoutms = (timeoutms + 9) / 10; + + if (get_user(mtype, &up->mtype)) + return -EFAULT; + + return do_msgsnd(msqid, mtype, up->mtext, (ssize_t)msgsz, msgflg, (long)timeoutms); +}
My preference would be to simplify both the timed and non-timed version by moving the get_user() into do_msgsnd() and using in_compat_task() to pick the right type. Same for the receive side of course. If you do this, watch out for
x32 support, which uses the 64-bit version.
Arnd