[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wgCrtM7fPd=qmmg6UUDRcw9iq7a7_ypOHH3740xgv6wkQ@mail.gmail.com>
Date: Sun, 28 Apr 2019 10:41:46 -0700
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Waiman Long <longman@...hat.com>
Cc: Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Will Deacon <will.deacon@....com>,
Thomas Gleixner <tglx@...utronix.de>,
Borislav Petkov <bp@...en8.de>,
"H. Peter Anvin" <hpa@...or.com>,
Linux List Kernel Mailing <linux-kernel@...r.kernel.org>,
"the arch/x86 maintainers" <x86@...nel.org>,
Davidlohr Bueso <dave@...olabs.net>,
Tim Chen <tim.c.chen@...ux.intel.com>,
huang ying <huang.ying.caritas@...il.com>,
stable <stable@...r.kernel.org>
Subject: Re: [PATCH-tip v6 01/20] locking/rwsem: Prevent decrement of reader
count before increment
On Sun, Apr 28, 2019 at 8:58 AM Waiman Long <longman@...hat.com> wrote:
>
> +
> + /* 2nd pass */
> + list_for_each_entry(waiter, &wlist, list) {
This is not safe, as far as I can tell.
As this loop walks the list, you do that
smp_store_release(&waiter->task, NULL);
and that very action means that the "waiter" is now released, and you
cannot possibly use it.
HOWEVER.
"list_for_each_entry()" will load "waiter->next" to go forward in the list.
So you absolutely *have* to use "list_for_each_entry_safe()" in this
loop, I think. You should treat that "smp_store_release()" as if you
deleted the list entry, because you cannot trust it after you've done
it, because the sleeper may have gone its own merry ways and released
the on-stack 'waiter' allocation.
It's the *first* loop that you could play games with, because you hold
the lock, and the list is stable during that loop. So the *first* loop
could just walk the list, and then do one list splitting operation
instead of doing that "list_move_tail()" thing for each entry.
But as long as you do "list_move_tail()" in the first loop, you'll
obviously have to use list_for_each_entry_safe() there too, since
right now you change that list as you walk it.
I'm just saying that you *could* optimize that first phase to just
walk it and then perhaps split it with list_cut_before() when you find
the first entry that isn't going to be woken up.
Linus
Powered by blists - more mailing lists