From 82efbd5e6fac82cc0c397943b90b49c6fd3a1c7e Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Wed, 3 Feb 2021 09:34:14 +0900 Subject: [PATCH] sched: group: Fix group_kill_children() for SMP Summary: - During testing iperf -s with lc823450-xgevk:rndis, I noticed that hard fault happens - Finally, I found that group_kill_children() is not not protected by a critical section - This commit fixes this issue Impact: - SMP only Testing: - Tested with iperf with the following configurations - lc823450-xgevk:rndis, spresense:rndis_smp - Tested with ostest with the following configurations - lc823450-xgevk:rndis, esp32-devkitc:smp (QEMU) - sabre-6quad:smp (QEMU), maix-bit:smp (QEMU) - spresense:rndis_smp, sim:smp Signed-off-by: Masayuki Ishikawa --- sched/group/group_killchildren.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sched/group/group_killchildren.c b/sched/group/group_killchildren.c index 86a7bf94cb..e69c500dcc 100644 --- a/sched/group/group_killchildren.c +++ b/sched/group/group_killchildren.c @@ -131,14 +131,26 @@ int group_kill_children(FAR struct tcb_s *tcb) { int ret; +#ifdef CONFIG_SMP + /* NOTE: sched_lock() is not enough for SMP + * because tcb->group will be accessed from the child tasks + */ + + irqstate_t flags = enter_critical_section(); +#else /* Lock the scheduler so that there this thread will not lose priority * until all of its children are suspended. */ sched_lock(); +#endif ret = group_foreachchild(tcb->group, group_kill_children_handler, (FAR void *)((uintptr_t)tcb->pid)); +#ifdef CONFIG_SMP + leave_critical_section(flags); +#else sched_unlock(); +#endif return ret; }