lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJZ5v0iYtNP54mUFs5VbmHxuXYjTBMrbCZ5CqfaHShnGdd+3Jg@mail.gmail.com>
Date:   Mon, 7 Jun 2021 13:45:43 +0200
From:   "Rafael J. Wysocki" <rafael@...nel.org>
To:     qiang.zhang@...driver.com
Cc:     Rafael Wysocki <rafael.j.wysocki@...el.com>,
        Len Brown <len.brown@...el.com>, Pavel Machek <pavel@....cz>,
        "Paul E. McKenney" <paulmck@...nel.org>,
        Linux PM <linux-pm@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] PM: sleep: Replace read_lock/unlock(tasklist_lock) with rcu_read_lock/unlock()

On Mon, Jun 7, 2021 at 8:57 AM <qiang.zhang@...driver.com> wrote:
>
> From: Zqiang <qiang.zhang@...driver.com>
>
> Using rcu_read_lock/unlock() instead of read_lock/unlock(tasklist_lock),
> the task list can be traversed in parallel to any list additions or
> removals, improve concurrency.
>
> Signed-off-by: Zqiang <qiang.zhang@...driver.com>

This changes the reader side only AFAICS, but what about the writer side?

What exactly is there to ensure that the updates of the list will
remain safe after this change?

> ---
>  kernel/power/process.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/kernel/power/process.c b/kernel/power/process.c
> index 50cc63534486..0f8dee9ee097 100644
> --- a/kernel/power/process.c
> +++ b/kernel/power/process.c
> @@ -48,7 +48,7 @@ static int try_to_freeze_tasks(bool user_only)
>
>         while (true) {
>                 todo = 0;
> -               read_lock(&tasklist_lock);
> +               rcu_read_lock();
>                 for_each_process_thread(g, p) {
>                         if (p == current || !freeze_task(p))
>                                 continue;
> @@ -56,7 +56,7 @@ static int try_to_freeze_tasks(bool user_only)
>                         if (!freezer_should_skip(p))
>                                 todo++;
>                 }
> -               read_unlock(&tasklist_lock);
> +               rcu_read_unlock();
>
>                 if (!user_only) {
>                         wq_busy = freeze_workqueues_busy();
> @@ -97,13 +97,13 @@ static int try_to_freeze_tasks(bool user_only)
>                         show_workqueue_state();
>
>                 if (!wakeup || pm_debug_messages_on) {
> -                       read_lock(&tasklist_lock);
> +                       rcu_read_lock();
>                         for_each_process_thread(g, p) {
>                                 if (p != current && !freezer_should_skip(p)
>                                     && freezing(p) && !frozen(p))
>                                         sched_show_task(p);
>                         }
> -                       read_unlock(&tasklist_lock);
> +                       rcu_read_unlock();
>                 }
>         } else {
>                 pr_cont("(elapsed %d.%03d seconds) ", elapsed_msecs / 1000,
> @@ -206,13 +206,13 @@ void thaw_processes(void)
>
>         cpuset_wait_for_hotplug();
>
> -       read_lock(&tasklist_lock);
> +       rcu_read_lock();
>         for_each_process_thread(g, p) {
>                 /* No other threads should have PF_SUSPEND_TASK set */
>                 WARN_ON((p != curr) && (p->flags & PF_SUSPEND_TASK));
>                 __thaw_task(p);
>         }
> -       read_unlock(&tasklist_lock);
> +       rcu_read_unlock();
>
>         WARN_ON(!(curr->flags & PF_SUSPEND_TASK));
>         curr->flags &= ~PF_SUSPEND_TASK;
> @@ -233,12 +233,12 @@ void thaw_kernel_threads(void)
>
>         thaw_workqueues();
>
> -       read_lock(&tasklist_lock);
> +       rcu_read_lock();
>         for_each_process_thread(g, p) {
>                 if (p->flags & PF_KTHREAD)
>                         __thaw_task(p);
>         }
> -       read_unlock(&tasklist_lock);
> +       rcu_read_unlock();
>
>         schedule();
>         pr_cont("done.\n");
> --
> 2.17.1
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ