[Xenomai-git] Philippe Gerum : cobalt/posix: fix potential race when reclaiming global resources
Module: xenomai-3 Branch: master Commit: 0fd3db3b74ac9290ee0a3937ea609f8ae22326f6 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=0fd3db3b74ac9290ee0a3937ea609f8ae22326f6 Author: Philippe Gerum Date: Tue Mar 24 16:14:01 2015 +0100 cobalt/posix: fix potential race when reclaiming global resources In theory, a Xenomai process on a different CPU might race with the reclaim code if it starts then exits while the global resources are being released on the current CPU. Unlikely, but possible though. Queue the global resources to be reclaimed from the exiting process to a local stash under nklock protection before cleaning them up. --- kernel/cobalt/posix/process.c | 16 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/kernel/cobalt/posix/process.c b/kernel/cobalt/posix/process.c index c2d65f0..3fb644a 100644 --- a/kernel/cobalt/posix/process.c +++ b/kernel/cobalt/posix/process.c @@ -1368,8 +1368,9 @@ static void __reclaim_resource(struct cobalt_process *process, struct list_head *global) { struct cobalt_resnode *node, *tmp; + LIST_HEAD(stash); spl_t s; - + xnlock_get_irqsave(&nklock, s); if (list_empty(global)) @@ -1377,17 +1378,24 @@ static void __reclaim_resource(struct cobalt_process *process, list_for_each_entry_safe(node, tmp, global, next) { if (node->owner == process) { - reclaim(node, s); /* drops lock */ - xnlock_get_irqsave(&nklock, s); + list_del(&node->next); + list_add(&node->next, &stash); } } + list_for_each_entry_safe(node, tmp, &stash, next) { + reclaim(node, s); + xnlock_get_irqsave(&nklock, s); + } + + XENO_BUG_ON(COBALT, !list_empty(&stash)); + flush_local: if (list_empty(local)) goto out; list_for_each_entry_safe(node, tmp, local, next) { - reclaim(node, s); /* drops lock */ + reclaim(node, s); xnlock_get_irqsave(&nklock, s); } out: ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git
[Xenomai-git] Philippe Gerum : cobalt/posix: fix potential race when reclaiming global resources
Module: xenomai-3 Branch: next Commit: 0fd3db3b74ac9290ee0a3937ea609f8ae22326f6 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=0fd3db3b74ac9290ee0a3937ea609f8ae22326f6 Author: Philippe Gerum Date: Tue Mar 24 16:14:01 2015 +0100 cobalt/posix: fix potential race when reclaiming global resources In theory, a Xenomai process on a different CPU might race with the reclaim code if it starts then exits while the global resources are being released on the current CPU. Unlikely, but possible though. Queue the global resources to be reclaimed from the exiting process to a local stash under nklock protection before cleaning them up. --- kernel/cobalt/posix/process.c | 16 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/kernel/cobalt/posix/process.c b/kernel/cobalt/posix/process.c index c2d65f0..3fb644a 100644 --- a/kernel/cobalt/posix/process.c +++ b/kernel/cobalt/posix/process.c @@ -1368,8 +1368,9 @@ static void __reclaim_resource(struct cobalt_process *process, struct list_head *global) { struct cobalt_resnode *node, *tmp; + LIST_HEAD(stash); spl_t s; - + xnlock_get_irqsave(&nklock, s); if (list_empty(global)) @@ -1377,17 +1378,24 @@ static void __reclaim_resource(struct cobalt_process *process, list_for_each_entry_safe(node, tmp, global, next) { if (node->owner == process) { - reclaim(node, s); /* drops lock */ - xnlock_get_irqsave(&nklock, s); + list_del(&node->next); + list_add(&node->next, &stash); } } + list_for_each_entry_safe(node, tmp, &stash, next) { + reclaim(node, s); + xnlock_get_irqsave(&nklock, s); + } + + XENO_BUG_ON(COBALT, !list_empty(&stash)); + flush_local: if (list_empty(local)) goto out; list_for_each_entry_safe(node, tmp, local, next) { - reclaim(node, s); /* drops lock */ + reclaim(node, s); xnlock_get_irqsave(&nklock, s); } out: ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git