[Xenomai-git] Jan Kiszka : cobalt/kernel: Fix mode of mayday syscall

2015-06-26 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 3bde99bb7a84f819f06e3ee2bad219e1b9b1ab55
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=3bde99bb7a84f819f06e3ee2bad219e1b9b1ab55

Author: Jan Kiszka jan.kis...@siemens.com
Date:   Fri Jun 19 15:59:15 2015 +0200

cobalt/kernel: Fix mode of mayday syscall

The oneway mode meant norestart, thus return -EINTR instead of retrying
the syscall after signal processing. But this caused damaged to the
register state of the mayday-interrupted thread, most visible on x86-64
where RAX is holding the RIP.

Fix this by restarting the syscall on signals. The syscall is supposed
to deliver the same result then, including a correct register state.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 kernel/cobalt/posix/syscall.c |6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index e60cea8..c636c0f 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -71,8 +71,6 @@
 #define __xn_exec_nonrestartable (__xn_exec_primary|__xn_exec_norestart)
 /* Shorthand for domain probing syscall */
 #define __xn_exec_probing   (__xn_exec_conforming|__xn_exec_adaptive)
-/* Shorthand for oneway trap - does not return to call site. */
-#define __xn_exec_oneway__xn_exec_norestart
 
 typedef long (*cobalt_syshand)(unsigned long arg1, unsigned long arg2,
   unsigned long arg3, unsigned long arg4,
@@ -251,7 +249,7 @@ static COBALT_SYSCALL(serialdbg, current,
return 0;
 }
 
-static COBALT_SYSCALL(mayday, oneway, (void))
+static COBALT_SYSCALL(mayday, current, (void))
 {
struct pt_regs *regs = task_pt_regs(current);
struct xnthread *cur;
@@ -797,7 +795,7 @@ static const int cobalt_sysmodes[] = {
__COBALT_MODE(extend, lostage),
__COBALT_MODE(trace, current),
__COBALT_MODE(get_current, current),
-   __COBALT_MODE(mayday, oneway),
+   __COBALT_MODE(mayday, current),
__COBALT_MODE(backtrace, current),
__COBALT_MODE(serialdbg, current),
__COBALT_MODE(corectl, probing),


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Simplify mayday processing

2015-06-26 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 1ca1924e0a825e8656fbc63d4147a9734b6a0254
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=1ca1924e0a825e8656fbc63d4147a9734b6a0254

Author: Jan Kiszka jan.kis...@siemens.com
Date:   Sun Jun 21 12:34:08 2015 +0200

cobalt/kernel: Simplify mayday processing

The mayday exist in order to kick a xenomai userspace task into
secondary mode while it is running userspace code. For that we ask
I-pipe to call us back when the task was interrupted and is about to
return to userspace. So far we defer the relaxation from that callback
via a VDSO-like mechanism that triggers a special syscall to the return
path of that syscall. However, that is not desirable because it is a
complex, arch-specific mechanism that may easily break and that destroys
the backtrace of ptraced tasks.

Fortunately, we can fulfill the needs of mayday also by relaxing the
task directly from that mayday callback. Tested successfully on x86-64
and ARM, other archs require validation.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 include/cobalt/kernel/ppd.h|1 -
 kernel/cobalt/arch/arm/Makefile|2 +-
 .../cobalt/arch/arm/include/asm/xenomai/thread.h   |   10 -
 kernel/cobalt/arch/arm/mayday.c|  146 --
 kernel/cobalt/arch/blackfin/Makefile   |2 +-
 .../arch/blackfin/include/asm/xenomai/thread.h |5 -
 kernel/cobalt/arch/blackfin/mayday.c   |  112 ---
 kernel/cobalt/arch/nios2/Makefile  |2 +-
 .../cobalt/arch/nios2/include/asm/xenomai/thread.h |5 -
 kernel/cobalt/arch/nios2/mayday.c  |   95 -
 kernel/cobalt/arch/powerpc/Makefile|2 +-
 .../arch/powerpc/include/asm/xenomai/thread.h  |4 -
 kernel/cobalt/arch/powerpc/mayday.c|   91 -
 kernel/cobalt/arch/sh/Makefile |2 +-
 kernel/cobalt/arch/sh/include/asm/xenomai/thread.h |4 -
 kernel/cobalt/arch/sh/mayday.c |   99 -
 kernel/cobalt/arch/x86/Makefile|2 +-
 .../cobalt/arch/x86/include/asm/xenomai/thread.h   |4 -
 kernel/cobalt/arch/x86/mayday.c|  212 
 kernel/cobalt/include/asm-generic/xenomai/mayday.h |   39 
 kernel/cobalt/posix/process.c  |   47 +
 kernel/cobalt/posix/syscall.c  |   31 ---
 kernel/cobalt/thread.c |1 -
 23 files changed, 8 insertions(+), 910 deletions(-)

diff --git a/include/cobalt/kernel/ppd.h b/include/cobalt/kernel/ppd.h
index 5eabd1d..f0079fe 100644
--- a/include/cobalt/kernel/ppd.h
+++ b/include/cobalt/kernel/ppd.h
@@ -32,7 +32,6 @@ struct cobalt_umm {
 
 struct cobalt_ppd {
struct cobalt_umm umm;
-   unsigned long mayday_tramp;
atomic_t refcnt;
char *exe_path;
struct rb_root fds;
diff --git a/kernel/cobalt/arch/arm/Makefile b/kernel/cobalt/arch/arm/Makefile
index f2e4e20..f182435 100644
--- a/kernel/cobalt/arch/arm/Makefile
+++ b/kernel/cobalt/arch/arm/Makefile
@@ -1,5 +1,5 @@
 obj-$(CONFIG_XENOMAI) += xenomai.o
 
-xenomai-y := machine.o mayday.o thread.o switch.o syscall.o
+xenomai-y := machine.o thread.o switch.o syscall.o
 
 ccflags-y := -Iarch/arm/xenomai/include -Iinclude/xenomai
diff --git a/kernel/cobalt/arch/arm/include/asm/xenomai/thread.h 
b/kernel/cobalt/arch/arm/include/asm/xenomai/thread.h
index 3d8e699..304a059 100644
--- a/kernel/cobalt/arch/arm/include/asm/xenomai/thread.h
+++ b/kernel/cobalt/arch/arm/include/asm/xenomai/thread.h
@@ -37,16 +37,6 @@ struct xnarchtcb {
 #define xnarch_fpu_ptr(tcb) NULL
 #endif
 #endif
-   struct {
-   unsigned long pc;
-   unsigned long r0;
-#ifdef __ARM_EABI__
-   unsigned long r7;
-#endif
-#ifdef CONFIG_ARM_THUMB
-   unsigned long psr;
-#endif
-   } mayday;
 };
 
 #define xnarch_fault_regs(d)   ((d)-regs)
diff --git a/kernel/cobalt/arch/arm/mayday.c b/kernel/cobalt/arch/arm/mayday.c
deleted file mode 100644
index 20e4559..000
--- a/kernel/cobalt/arch/arm/mayday.c
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright (C) 2010 Philippe Gerum r...@xenomai.org.
- *
- * Xenomai is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Xenomai is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Xenomai; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 

[Xenomai-git] Jan Kiszka : cobalt/kernel: Rework thread debugging helpers

2015-06-26 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: a97eceac2e414c6a66f266b38d934c8e0850afd0
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=a97eceac2e414c6a66f266b38d934c8e0850afd0

Author: Jan Kiszka jan.kis...@siemens.com
Date:   Fri Jun 19 09:55:39 2015 +0200

cobalt/kernel: Rework thread debugging helpers

Factor out register/unregister_debugged_thread helpers to have a single
point where tasks related to preparing/cleaning up ptraced-base thread
debugging can be placed. Put all steps under nklock, which is required
anyway for manipulating xnthread::state and fixes a lurking race. The
timer lock counter can then be converted into a non-atomic variable.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 include/cobalt/kernel/clock.h |2 +-
 kernel/cobalt/clock.c |6 +++---
 kernel/cobalt/posix/process.c |   35 ---
 3 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/include/cobalt/kernel/clock.h b/include/cobalt/kernel/clock.h
index 35a07c1..70e1c15 100644
--- a/include/cobalt/kernel/clock.h
+++ b/include/cobalt/kernel/clock.h
@@ -89,7 +89,7 @@ extern struct xnclock nkclock;
 
 extern unsigned long nktimerlat;
 
-extern atomic_t nkclklk;
+extern unsigned int nkclock_lock;
 
 int xnclock_register(struct xnclock *clock);
 
diff --git a/kernel/cobalt/clock.c b/kernel/cobalt/clock.c
index 8b8d992..dfaa79e 100644
--- a/kernel/cobalt/clock.c
+++ b/kernel/cobalt/clock.c
@@ -34,7 +34,7 @@
  */
 unsigned long nktimerlat;
 
-atomic_t nkclklk;
+unsigned int nkclock_lock;
 
 static unsigned long long clockfreq;
 
@@ -471,7 +471,7 @@ void print_core_clock_status(struct xnclock *clock,
 {
const char *tm_status, *wd_status = ;
 
-   tm_status = atomic_read(nkclklk)  0 ? locked : on;
+   tm_status = nkclock_lock  0 ? locked : on;
 #ifdef CONFIG_XENO_OPT_WATCHDOG
wd_status = +watchdog;
 #endif /* CONFIG_XENO_OPT_WATCHDOG */
@@ -715,7 +715,7 @@ void xnclock_tick(struct xnclock *clock)
}
 
/* Check for a locked clock state (i.e. ptracing). */
-   if (unlikely(atomic_read(nkclklk)  0)) {
+   if (unlikely(nkclock_lock  0)) {
if (timer-status  XNTIMER_NOBLCK)
goto fire;
if (timer-status  XNTIMER_PERIODIC)
diff --git a/kernel/cobalt/posix/process.c b/kernel/cobalt/posix/process.c
index 6110da6..828e9e5 100644
--- a/kernel/cobalt/posix/process.c
+++ b/kernel/cobalt/posix/process.c
@@ -984,18 +984,26 @@ static inline void init_hostrt(void) { }
 
 #endif /* !CONFIG_XENO_OPT_HOSTRT */
 
-static inline void lock_timers(void)
+/* called with nklock held */
+static void register_debugged_thread(struct xnthread *thread)
 {
-   /* We are covered by the core lock: no barriers needed. */
-   atomic_inc(nkclklk);
+   nkclock_lock++;
+
+   xnthread_set_state(thread, XNSSTEP);
 }
 
-static inline void unlock_timers(void)
+static void unregister_debugged_thread(struct xnthread *thread)
 {
-   XENO_BUG_ON(COBALT, atomic_read(nkclklk) == 0);
-   smp_mb__before_atomic();
-   atomic_dec(nkclklk);
-   smp_mb__after_atomic();
+   spl_t s;
+
+   xnlock_get_irqsave(nklock, s);
+
+   xnthread_clear_state(thread, XNSSTEP);
+
+   XENO_BUG_ON(COBALT, nkclock_lock == 0);
+   nkclock_lock--;
+
+   xnlock_put_irqrestore(nklock, s);
 }
 
 static int handle_taskexit_event(struct task_struct *p) /* p == current */
@@ -1014,7 +1022,7 @@ static int handle_taskexit_event(struct task_struct *p) 
/* p == current */
trace_cobalt_shadow_unmap(thread);
 
if (xnthread_test_state(thread, XNSSTEP))
-   unlock_timers();
+   unregister_debugged_thread(thread);
 
xnthread_run_handler_stack(thread, exit_thread);
/* Waiters will receive EIDRM */
@@ -1093,8 +1101,7 @@ static int handle_schedule_event(struct task_struct 
*next_task)
sigismember(pending, SIGINT))
goto no_ptrace;
}
-   xnthread_clear_state(next, XNSSTEP);
-   unlock_timers();
+   unregister_debugged_thread(next);
}
 
 no_ptrace:
@@ -1146,10 +1153,8 @@ static int handle_sigwake_event(struct task_struct *p)
 
if (sigismember(pending, SIGTRAP) ||
sigismember(pending, SIGSTOP)
-   || sigismember(pending, SIGINT)) {
-   xnthread_set_state(thread, XNSSTEP);
-   lock_timers();
-   }
+   || sigismember(pending, SIGINT))
+   register_debugged_thread(thread);
}
 
if (xnthread_test_state(thread, XNRELAX)) {


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Fix locking for xnthread info manipulations

2015-06-26 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: 67a64e164b737759cc171d3b04b05770e1450cb6
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=67a64e164b737759cc171d3b04b05770e1450cb6

Author: Jan Kiszka jan.kis...@siemens.com
Date:   Fri Jun 26 15:11:42 2015 +0200

cobalt/kernel: Fix locking for xnthread info manipulations

nklock must be held when manipulating bits of xnthread::info. Not all
callsites of xnthread_set/clear_info follow this rule so far, directly
or indirectly, fix them (and possibly some other races along this).

Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 include/cobalt/kernel/rtdm/driver.h |8 
 kernel/cobalt/posix/syscall.c   |5 +
 kernel/cobalt/synch.c   |2 ++
 kernel/cobalt/thread.c  |5 +
 4 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index c14198b..de476ca 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -553,7 +553,7 @@ static inline void rtdm_lock_get(rtdm_lock_t *lock)
 {
XENO_BUG_ON(COBALT, !spltest());
spin_lock(lock);
-   __xnsched_lock();
+   xnsched_lock();
 }
 
 /**
@@ -566,7 +566,7 @@ static inline void rtdm_lock_get(rtdm_lock_t *lock)
 static inline void rtdm_lock_put(rtdm_lock_t *lock)
 {
spin_unlock(lock);
-   __xnsched_unlock();
+   xnsched_unlock();
 }
 
 /**
@@ -584,7 +584,7 @@ static inline rtdm_lockctx_t 
__rtdm_lock_get_irqsave(rtdm_lock_t *lock)
 
context = ipipe_test_and_stall_head();
spin_lock(lock);
-   __xnsched_lock();
+   xnsched_lock();
 
return context;
 }
@@ -603,7 +603,7 @@ static inline
 void rtdm_lock_put_irqrestore(rtdm_lock_t *lock, rtdm_lockctx_t context)
 {
spin_unlock(lock);
-   __xnsched_unlock();
+   xnsched_unlock();
ipipe_restore_head(context);
 }
 
diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index cf93f07..e60cea8 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -84,6 +84,9 @@ static void prepare_for_signal(struct task_struct *p,
   int sysflags)
 {
int notify = 0;
+   spl_t s;
+
+   xnlock_get_irqsave(nklock, s);
 
if (xnthread_test_info(thread, XNKICKED)) {
if (signal_pending(p)) {
@@ -96,6 +99,8 @@ static void prepare_for_signal(struct task_struct *p,
xnthread_clear_info(thread, XNKICKED);
}
 
+   xnlock_put_irqrestore(nklock, s);
+
xnthread_test_cancel();
 
xnthread_relax(notify, SIGDEBUG_MIGRATE_SIGNAL);
diff --git a/kernel/cobalt/synch.c b/kernel/cobalt/synch.c
index 536e0a7..a1ea4b4 100644
--- a/kernel/cobalt/synch.c
+++ b/kernel/cobalt/synch.c
@@ -441,7 +441,9 @@ redo:
if (likely(h == XN_NO_HANDLE)) {
xnsynch_set_owner(synch, curr);
xnthread_get_resource(curr);
+   xnlock_get_irqsave(nklock, s);
xnthread_clear_info(curr, XNRMID | XNTIMEO | XNBREAK);
+   xnlock_put_irqrestore(nklock, s);
return 0;
}
 
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 5adf44f..22729a8 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -1978,6 +1978,7 @@ void xnthread_relax(int notify, int reason)
struct task_struct *p = current;
int cpu __maybe_unused;
siginfo_t si;
+   spl_t s;
 
primary_mode_only();
 
@@ -2034,7 +2035,9 @@ void xnthread_relax(int notify, int reason)
si.si_int = reason | sigdebug_marker;
send_sig_info(SIGDEBUG, si, p);
}
+   xnlock_get_irqsave(nklock, s);
xnsynch_detect_claimed_relax(thread);
+   xnlock_put_irqrestore(nklock, s);
}
 
/*
@@ -2045,7 +2048,9 @@ void xnthread_relax(int notify, int reason)
 
 #ifdef CONFIG_SMP
if (xnthread_test_info(thread, XNMOVED)) {
+   xnlock_get_irqsave(nklock, s);
xnthread_clear_info(thread, XNMOVED);
+   xnlock_put_irqrestore(nklock, s);
cpu = xnsched_cpu(thread-sched);
set_cpus_allowed(p, cpumask_of_cpu(cpu));
}


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : cobalt/kernel: Fix locking for setting XNFPU

2015-06-26 Thread git repository hosting
Module: xenomai-jki
Branch: for-forge
Commit: c7b68c441fc2a5adca4f89e6716b737ad70da284
URL:
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=c7b68c441fc2a5adca4f89e6716b737ad70da284

Author: Jan Kiszka jan.kis...@siemens.com
Date:   Fri Jun 26 15:55:53 2015 +0200

cobalt/kernel: Fix locking for setting XNFPU

All manipulations of xnthread::state must be protected by nklock. This
is not the case for xnarch_handle_fpu_fault yet, fix it.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com

---

 kernel/cobalt/arch/arm/thread.c |5 +
 kernel/cobalt/arch/x86/thread.c |4 
 2 files changed, 9 insertions(+)

diff --git a/kernel/cobalt/arch/arm/thread.c b/kernel/cobalt/arch/arm/thread.c
index 13d2176..825926c 100644
--- a/kernel/cobalt/arch/arm/thread.c
+++ b/kernel/cobalt/arch/arm/thread.c
@@ -270,6 +270,8 @@ void xnarch_switch_fpu(struct xnthread *from, struct 
xnthread *to)
 int xnarch_handle_fpu_fault(struct xnthread *from, 
struct xnthread *to, struct ipipe_trap_data *d)
 {
+   spl_t s;
+
if (xnthread_test_state(to, XNFPU))
/* FPU is already enabled, probably an exception */
return 0;
@@ -281,7 +283,10 @@ int xnarch_handle_fpu_fault(struct xnthread *from,
return 0;
 #endif
 
+   xnlock_get_irqsave(nklock, s);
xnthread_set_state(to, XNFPU);
+   xnlock_put_irqrestore(nklock, s);
+
xnarch_switch_fpu(from, to);
 
/* Retry faulting instruction */
diff --git a/kernel/cobalt/arch/x86/thread.c b/kernel/cobalt/arch/x86/thread.c
index 2c2574a..0a057ee 100644
--- a/kernel/cobalt/arch/x86/thread.c
+++ b/kernel/cobalt/arch/x86/thread.c
@@ -281,6 +281,7 @@ int xnarch_handle_fpu_fault(struct xnthread *from,
 {
struct xnarchtcb *tcb = xnthread_archtcb(to);
struct task_struct *p = tcb-core.host_task;
+   spl_t s;
 
if (__thread_has_fpu(p))
return 0;
@@ -309,7 +310,10 @@ int xnarch_handle_fpu_fault(struct xnthread *from,
}

__thread_set_has_fpu(p);
+
+   xnlock_get_irqsave(nklock, s);
xnthread_set_state(to, XNFPU);
+   xnlock_put_irqrestore(nklock, s);
 
return 1;
 }


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git