Module: xenomai-gch
Branch: u_mode
Commit: 6b7f363156e6b2e6deb5d968f99feac0578aa62f
URL:    
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=6b7f363156e6b2e6deb5d968f99feac0578aa62f

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sun Jun 19 13:19:01 2011 +0200

nucleus: fix ppd cleanup

During ppd cleanup, current->mm is not necessarily the mm of the process
being cleaned up, this prevents xnshadow_ppd_get from being used during
cleanup. Additionally, current->mm is NULL when executing shadow cleanup
hooks during process exit.

This commit uses an adeos ptd in order to store the mm of a shadow. This
ptd is set upon shadow map to avoid the second issue, and temporarily to
the process executing the mm cleanup to avoid the first one.

---

 ksrc/nucleus/shadow.c    |   20 ++++++++++++++++++--
 ksrc/skins/posix/mutex.c |    4 ----
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/ksrc/nucleus/shadow.c b/ksrc/nucleus/shadow.c
index 679826e..f6e0893 100644
--- a/ksrc/nucleus/shadow.c
+++ b/ksrc/nucleus/shadow.c
@@ -65,6 +65,11 @@ int nkthrptd;
 EXPORT_SYMBOL_GPL(nkthrptd);
 int nkerrptd;
 EXPORT_SYMBOL_GPL(nkerrptd);
+int nkmmptd;
+EXPORT_SYMBOL_GPL(nkmmptd);
+
+#define xnshadow_mmptd(t) ((t)->ptd[nkmmptd])
+#define xnshadow_mm(t) ((struct mm_struct *)xnshadow_mmptd(t))
 
 struct xnskin_slot {
        struct xnskin_props *props;
@@ -1299,6 +1304,8 @@ int xnshadow_map(xnthread_t *thread, xncompletion_t 
__user *u_completion,
         * friends.
         */
        xnshadow_thrptd(current) = thread;
+       xnshadow_mmptd(current) = current->mm;
+
        rthal_enable_notifier(current);
 
        if (xnthread_base_priority(thread) == 0 &&
@@ -2754,7 +2761,15 @@ static void detach_ppd(xnshadow_ppd_t * ppd)
 
 static inline void do_cleanup_event(struct mm_struct *mm)
 {
+       struct task_struct *p = current;
+       struct mm_struct *old;
+
+       old = xnshadow_mm(p);
+       xnshadow_mmptd(p) = mm;
+
        ppd_remove_mm(mm, &detach_ppd);
+
+       xnshadow_mmptd(p) = old;
 }
 
 RTHAL_DECLARE_CLEANUP_EVENT(cleanup_event);
@@ -2920,7 +2935,7 @@ EXPORT_SYMBOL_GPL(xnshadow_unregister_interface);
 xnshadow_ppd_t *xnshadow_ppd_get(unsigned muxid)
 {
        if (xnpod_userspace_p())
-               return ppd_lookup(muxid, current->mm);
+               return ppd_lookup(muxid, xnshadow_mm(current) ?: current->mm);
 
        return NULL;
 }
@@ -2955,8 +2970,9 @@ int xnshadow_mount(void)
        sema_init(&completion_mutex, 1);
        nkthrptd = rthal_alloc_ptdkey();
        nkerrptd = rthal_alloc_ptdkey();
+       nkmmptd = rthal_alloc_ptdkey();
 
-       if (nkthrptd < 0 || nkerrptd < 0) {
+       if (nkthrptd < 0 || nkerrptd < 0 || nkmmptd < 0) {
                printk(KERN_ERR "Xenomai: cannot allocate PTD slots\n");
                return -ENOMEM;
        }
diff --git a/ksrc/skins/posix/mutex.c b/ksrc/skins/posix/mutex.c
index 6ce75e5..cc86852 100644
--- a/ksrc/skins/posix/mutex.c
+++ b/ksrc/skins/posix/mutex.c
@@ -219,10 +219,6 @@ void pse51_mutex_destroy_internal(pse51_mutex_t *mutex,
        xnlock_put_irqrestore(&nklock, s);
 
 #ifdef CONFIG_XENO_FASTSYNCH
-       /* We call xnheap_free even if the mutex is not pshared; when
-          this function is called from pse51_mutexq_cleanup, the
-          sem_heap is destroyed, or not the one to which the fastlock
-          belongs, xnheap will simply return an error. */
        xnheap_free(&xnsys_ppd_get(mutex->attr.pshared)->sem_heap,
                    mutex->synchbase.fastlock);
 #endif /* CONFIG_XENO_FASTSYNCH */


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

Reply via email to