Module: xenomai-3
Branch: next
Commit: b525c0ecc1b609cf69477d39e15c35e2227fd59a
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=b525c0ecc1b609cf69477d39e15c35e2227fd59a

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sat May 12 19:08:59 2018 +0200

cobalt: syscall: don't bark at internal syscalls

Some architectures may define a secondary system call range for
internal operations, fix the consistency check not to warn about them.

---

 .../cobalt/arch/arm/include/asm/xenomai/syscall.h  |   22 ++++++++++++--------
 .../arch/arm64/include/asm/xenomai/syscall.h       |   18 +++++++++-------
 .../arch/blackfin/include/asm/xenomai/syscall.h    |   18 +++++++++-------
 .../arch/powerpc/include/asm/xenomai/syscall.h     |   18 +++++++++-------
 .../cobalt/arch/x86/include/asm/xenomai/syscall.h  |   20 +++++++++++-------
 kernel/cobalt/posix/syscall.c                      |    7 +++----
 6 files changed, 61 insertions(+), 42 deletions(-)

diff --git a/kernel/cobalt/arch/arm/include/asm/xenomai/syscall.h 
b/kernel/cobalt/arch/arm/include/asm/xenomai/syscall.h
index 92afe8d..1207136 100644
--- a/kernel/cobalt/arch/arm/include/asm/xenomai/syscall.h
+++ b/kernel/cobalt/arch/arm/include/asm/xenomai/syscall.h
@@ -33,6 +33,11 @@
 #define __ARM_NR_ipipe (__NR_SYSCALL_BASE + XENO_ARM_SYSCALL)
 #endif
 
+/*
+ * Cobalt syscall numbers can be fetched from ARM_ORIG_r0 with ARM_r7
+ * containing the Xenomai syscall marker, Linux syscalls directly from
+ * ARM_r7 (may require the OABI tweak).
+ */
 #define __xn_reg_sys(__regs)   ((__regs)->ARM_ORIG_r0)
 /* In OABI_COMPAT mode, handle both OABI and EABI userspace syscalls */
 #ifdef CONFIG_OABI_COMPAT
@@ -46,16 +51,15 @@
 #define __xn_syscall(__regs)   (__xn_reg_sys(__regs) & ~__COBALT_SYSCALL_BIT)
 
 /*
- * Returns the syscall number depending on the handling core. Cobalt
- * syscall numbers can be fetched from ARM_ORIG_r0 with ARM_r7
- * containing the Xenomai syscall marker, Linux syscalls directly from
- * ARM_r7 (may require the OABI tweak).
+ * Root syscall number with predicate (valid only if
+ * !__xn_syscall_p(__regs)).
  */
-static inline long __xn_get_syscall_nr(struct pt_regs *regs)
-{
-       return __xn_syscall_p(regs) ? __xn_reg_sys(regs) : 
__xn_abi_decode(regs);
-}
-
+#define __xn_rootcall_p(__regs, __code)                                        
\
+       ({                                                              \
+               *(__code) = __xn_abi_decode(__regs);                    \
+               *(__code) < NR_syscalls || *(__code) >= __ARM_NR_BASE;  \
+       })
+       
 #define __xn_reg_rval(__regs)  ((__regs)->ARM_r0)
 #define __xn_reg_arg1(__regs)  ((__regs)->ARM_r1)
 #define __xn_reg_arg2(__regs)  ((__regs)->ARM_r2)
diff --git a/kernel/cobalt/arch/arm64/include/asm/xenomai/syscall.h 
b/kernel/cobalt/arch/arm64/include/asm/xenomai/syscall.h
index 4b9b987..e345c9a 100644
--- a/kernel/cobalt/arch/arm64/include/asm/xenomai/syscall.h
+++ b/kernel/cobalt/arch/arm64/include/asm/xenomai/syscall.h
@@ -28,6 +28,10 @@
 #include <asm/ptrace.h>
 #include <asm-generic/xenomai/syscall.h>
 
+/*
+ * Cobalt and Linux syscall numbers can be fetched from syscallno,
+ * masking out the __COBALT_SYSCALL_BIT marker.
+ */
 #define __xn_reg_sys(__regs)   ((unsigned long)(__regs)->syscallno)
 #define __xn_syscall_p(regs)   ((__xn_reg_sys(regs) & __COBALT_SYSCALL_BIT) != 
0)
 #define __xn_syscall(__regs)   ((unsigned long)(__xn_reg_sys(__regs) & 
~__COBALT_SYSCALL_BIT))
@@ -42,14 +46,14 @@
 #define __xn_reg_sp(__regs)    ((__regs)->sp)
 
 /*
- * Returns the syscall number depending on the handling core. Cobalt
- * and Linux syscall numbers can be fetched from syscallno, masking
- * out the __COBALT_SYSCALL_BIT marker.
+ * Root syscall number with predicate (valid only if
+ * !__xn_syscall_p(__regs)).
  */
-static inline long __xn_get_syscall_nr(struct pt_regs *regs)
-{
-       return __xn_syscall(regs);
-}
+#define __xn_rootcall_p(__regs, __code)                        \
+       ({                                              \
+               *(__code) = __xn_syscall(__regs);       \
+               *(__code) < NR_syscalls;                \
+       })
 
 static inline void __xn_error_return(struct pt_regs *regs, int v)
 {
diff --git a/kernel/cobalt/arch/blackfin/include/asm/xenomai/syscall.h 
b/kernel/cobalt/arch/blackfin/include/asm/xenomai/syscall.h
index a62fa49..3e63f29 100644
--- a/kernel/cobalt/arch/blackfin/include/asm/xenomai/syscall.h
+++ b/kernel/cobalt/arch/blackfin/include/asm/xenomai/syscall.h
@@ -23,6 +23,10 @@
 #include <asm/ptrace.h>
 #include <asm-generic/xenomai/syscall.h>
 
+/*
+ * Cobalt and Linux syscall numbers can be fetched from P0, masking
+ * out the __COBALT_SYSCALL_BIT marker.
+ */
 #define __xn_reg_sys(__regs)   ((__regs)->orig_p0)
 #define __xn_syscall_p(__regs) (__xn_reg_sys(__regs) & __COBALT_SYSCALL_BIT)
 #define __xn_syscall(__regs)   (__xn_reg_sys(__regs) & ~__COBALT_SYSCALL_BIT)
@@ -35,14 +39,14 @@
 #define __xn_reg_arg5(__regs)  ((__regs)->r4)
 
 /*
- * Returns the syscall number depending on the handling core. Cobalt
- * and Linux syscall numbers can be fetched from P0, masking out the
- * __COBALT_SYSCALL_BIT marker.
+ * Root syscall number with predicate (valid only if
+ * !__xn_syscall_p(__regs)).
  */
-static inline long __xn_get_syscall_nr(struct pt_regs *regs)
-{
-       return __xn_syscall(regs);
-}
+#define __xn_rootcall_p(__regs, __code)                        \
+       ({                                              \
+               *(__code) = __xn_syscall(__regs);       \
+               *(__code) < NR_syscalls;                \
+       })
 
 static inline void __xn_error_return(struct pt_regs *regs, int v)
 {
diff --git a/kernel/cobalt/arch/powerpc/include/asm/xenomai/syscall.h 
b/kernel/cobalt/arch/powerpc/include/asm/xenomai/syscall.h
index 2edd5eb..9b166ad 100644
--- a/kernel/cobalt/arch/powerpc/include/asm/xenomai/syscall.h
+++ b/kernel/cobalt/arch/powerpc/include/asm/xenomai/syscall.h
@@ -26,6 +26,10 @@
 #include <linux/ptrace.h>
 #include <asm-generic/xenomai/syscall.h>
 
+/*
+ * Cobalt and Linux syscall numbers can be fetched from GPR0, masking
+ * out the __COBALT_SYSCALL_BIT marker.
+ */
 #define __xn_reg_sys(__regs)   ((__regs)->gpr[0])
 #define __xn_syscall_p(__regs) (__xn_reg_sys(__regs) & __COBALT_SYSCALL_BIT)
 #define __xn_syscall(__regs)   (__xn_reg_sys(__regs) & ~__COBALT_SYSCALL_BIT)
@@ -40,14 +44,14 @@
 #define __xn_reg_sp(__regs)    ((__regs)->gpr[1])
 
 /*
- * Returns the syscall number depending on the handling core. Cobalt
- * and Linux syscall numbers can be fetched from GPR0, masking out the
- * __COBALT_SYSCALL_BIT marker.
+ * Root syscall number with predicate (valid only if
+ * !__xn_syscall_p(__regs)).
  */
-static inline long __xn_get_syscall_nr(struct pt_regs *regs)
-{
-       return __xn_syscall(regs);
-}
+#define __xn_rootcall_p(__regs, __code)                        \
+       ({                                              \
+               *(__code) = __xn_syscall(__regs);       \
+               *(__code) < NR_syscalls;                \
+       })
 
 static inline void __xn_error_return(struct pt_regs *regs, int v)
 {
diff --git a/kernel/cobalt/arch/x86/include/asm/xenomai/syscall.h 
b/kernel/cobalt/arch/x86/include/asm/xenomai/syscall.h
index 86be9f7..992f1cd 100644
--- a/kernel/cobalt/arch/x86/include/asm/xenomai/syscall.h
+++ b/kernel/cobalt/arch/x86/include/asm/xenomai/syscall.h
@@ -23,6 +23,12 @@
 #include <asm/ptrace.h>
 #include <asm-generic/xenomai/syscall.h>
 
+/*
+ * Cobalt and Linux syscall numbers can be fetched from ORIG_AX,
+ * masking out the __COBALT_SYSCALL_BIT marker. Make sure to offset
+ * the number by __COBALT_X32_BASE for Cobalt 32-bit compat syscalls
+ * only.
+ */
 #define __xn_reg_sys(regs)    ((regs)->orig_ax)
 #define __xn_reg_rval(regs)   ((regs)->ax)
 #ifdef __i386__
@@ -50,15 +56,13 @@
 #endif
 
 /*
- * Returns the syscall number depending on the handling core. Cobalt
- * and Linux syscall numbers can be fetched from ORIG_AX, masking out
- * the __COBALT_SYSCALL_BIT marker. Make sure to offset the number by
- * __COBALT_X32_BASE for Cobalt 32-bit compat syscalls only.
+ * Root syscall number with predicate (valid only if
+ * !__xn_syscall_p(__regs)).
  */
-#define __xn_get_syscall_nr(__regs)                                    \
-       ({                                                              \
-               __xn_syscall_p(__regs) ? __xn_syscall(__regs) :         \
-                       (__xn_reg_sys(__regs) & ~__COBALT_SYSCALL_BIT); \
+#define __xn_rootcall_p(__regs, __code)                        \
+       ({                                              \
+               *(__code) = __xn_reg_sys(__regs);       \
+               *(__code) < NR_syscalls;                \
        })
 
 static inline void __xn_error_return(struct pt_regs *regs, int v)
diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index 68700a3..058a828 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -666,10 +666,6 @@ ret_handled:
        return KEVENT_STOP;
 
 linux_syscall:
-       code = __xn_get_syscall_nr(regs);
-       if (code >= NR_syscalls)
-               goto bad_syscall;
-
        if (xnsched_root_p())
                /*
                 * The call originates from the Linux domain, either
@@ -679,6 +675,9 @@ linux_syscall:
                 */
                return KEVENT_PROPAGATE;
 
+       if (!__xn_rootcall_p(regs, &code))
+               goto bad_syscall;
+
        /*
         * We know this is a Cobalt thread since it runs over the head
         * domain, however the current syscall should be handled by


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to