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

Reply via email to