[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241228163231.GA19293@redhat.com>
Date: Sat, 28 Dec 2024 17:32:32 +0100
From: Oleg Nesterov <oleg@...hat.com>
To: Manfred Spraul <manfred@...orfullife.com>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>, viro@...iv.linux.org.uk,
brauner@...nel.org, jack@...e.cz, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org, oliver.sang@...el.com,
ebiederm@...ssion.com, colin.king@...onical.com,
josh@...htriplett.org, penberg@...helsinki.fi, mingo@...e.hu,
jes@....com, hch@....de, aia21@...tab.net, arjan@...radead.org,
jgarzik@...ox.com, neukum@...hschaft.cup.uni-muenchen.de,
oliver@...kum.name, dada1@...mosbay.com, axboe@...nel.dk,
axboe@...e.de, nickpiggin@...oo.com.au, dhowells@...hat.com,
nathans@....com, rolandd@...co.com, tytso@....edu, bunk@...sta.de,
pbadari@...ibm.com, ak@...ux.intel.com, ak@...e.de,
davem@...emloft.net, jsipek@...sunysb.edu, jens.axboe@...cle.com,
ramsdell@...re.org, hch@...radead.org, akpm@...ux-foundation.org,
randy.dunlap@...cle.com, efault@....de, rdunlap@...radead.org,
haveblue@...ibm.com, drepper@...hat.com, dm.n9107@...il.com,
jblunck@...e.de, davidel@...ilserver.org,
mtk.manpages@...glemail.com, linux-arch@...r.kernel.org,
vda.linux@...glemail.com, jmorris@...ei.org, serue@...ibm.com,
hca@...ux.ibm.com, rth@...ddle.net, lethal@...ux-sh.org,
tony.luck@...el.com, heiko.carstens@...ibm.com, andi@...stfloor.org,
corbet@....net, crquan@...il.com, mszeredi@...e.cz,
miklos@...redi.hu, peterz@...radead.org, a.p.zijlstra@...llo.nl,
earl_chew@...lent.com, npiggin@...il.com, npiggin@...e.de,
julia@...u.dk, jaxboe@...ionio.com, nikai@...ai.net,
dchinner@...hat.com, davej@...hat.com, npiggin@...nel.dk,
eric.dumazet@...il.com, tim.c.chen@...ux.intel.com,
xemul@...allels.com, tj@...nel.org, serge.hallyn@...onical.com,
gorcunov@...nvz.org, bcrl@...ck.org, alan@...rguk.ukuu.org.uk,
will.deacon@....com, will@...nel.org, zab@...hat.com, balbi@...com,
gregkh@...uxfoundation.org, rusty@...tcorp.com.au,
socketpair@...il.com, penguin-kernel@...ove.sakura.ne.jp,
mhocko@...nel.org, axboe@...com, tglx@...utronix.de,
mcgrof@...nel.org, linux@...inikbrodowski.net, willy@...radead.org,
paulmck@...nel.org, kernel@...force.de,
linux-morello@...lists.linaro.org
Subject: Re: [RESEND PATCH] fs/pipe: Introduce a check to skip sleeping
processes during pipe read/write
On 12/28, Oleg Nesterov wrote:
>
> If nothing else, consider
>
> int CONDITION;
> wait_queue_head_t WQ;
>
> void wake(void)
> {
> CONDITION = 1;
> wake_up(WQ);
> }
>
> void wait(void)
> {
> DEFINE_WAIT_FUNC(entry, woken_wake_function);
>
> add_wait_queue(WQ, entry);
> if (!CONDITION)
> wait_woken(entry, ...);
> remove_wait_queue(WQ, entry);
> }
>
> this code is correct even if LOAD(CONDITION) can leak into the critical
> section in add_wait_queue(), so CPU running wait() can actually do
>
> // add_wait_queue
> spin_lock(WQ->lock);
> LOAD(CONDITION); // false!
> list_add(entry, head);
> spin_unlock(WQ->lock);
>
> if (!false) // result of the LOAD above
> wait_woken(entry, ...);
>
> Now suppose that another CPU executes wake() between LOAD(CONDITION)
> and list_add(entry, head). With your patch wait() will miss the event.
> The same for __pollwait(), I think...
>
> No?
Even simpler,
void wait(void)
{
DEFINE_WAIT(entry);
__set_current_state(XXX);
add_wait_queue(WQ, entry);
if (!CONDITION)
schedule();
remove_wait_queue(WQ, entry);
__set_current_state(TASK_RUNNING);
}
This code is ugly but currently correct unless I am totally confused.
Oleg.
Powered by blists - more mailing lists