Re: [PATCH] stop_machine: Remove cpu swap from stop_two_cpus

From: Sebastian Andrzej Siewior
Date: Wed Jun 27 2018 - 03:16:00 EST


On 2018-06-26 14:28:26 [-0700], Isaac J. Manjarres wrote:
> Remove CPU ID swapping in stop_two_cpus() so that the
> source CPU's stopper thread is added to the wake queue last,
> so that the source CPU's stopper thread is woken up last,
> ensuring that all other threads that it depends on are woken
> up before it runs.

You can't do that because you could deadlock while locking the stoper
lock.
Couldn't you swap cpu1+cpu2 and work1+work2?

> diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
> index f89014a..d10d633 100644
> --- a/kernel/stop_machine.c
> +++ b/kernel/stop_machine.c
> @@ -307,8 +307,6 @@ int stop_two_cpus(unsigned int cpu1, unsigned int cpu2, cpu_stop_fn_t fn, void *
> cpu_stop_init_done(&done, 2);
> set_state(&msdata, MULTI_STOP_PREPARE);
>
> - if (cpu1 > cpu2)
> - swap(cpu1, cpu2);
> if (cpu_stop_queue_two_works(cpu1, &work1, cpu2, &work2))
> return -ENOENT;
>

Sebastian