[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZYs8Yp/7TovnVMLC@casper.infradead.org>
Date: Tue, 26 Dec 2023 20:49:38 +0000
From: Matthew Wilcox <willy@...radead.org>
To: Hillf Danton <hdanton@...a.com>
Cc: "Eric W. Biederman" <ebiederm@...ssion.com>,
Maria Yu <quic_aiquny@...cinc.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] kernel: Introduce a write lock/unlock wrapper for
tasklist_lock
On Tue, Dec 26, 2023 at 06:46:52PM +0800, Hillf Danton wrote:
> On Wed, 13 Dec 2023 12:27:05 -0600 Eric W. Biederman <ebiederm@...ssion.com>
> > Matthew Wilcox <willy@...radead.org> writes:
> > > On Wed, Dec 13, 2023 at 06:17:45PM +0800, Maria Yu wrote:
> > >> +static inline void write_lock_tasklist_lock(void)
> > >> +{
> > >> + while (1) {
> > >> + local_irq_disable();
> > >> + if (write_trylock(&tasklist_lock))
> > >> + break;
> > >> + local_irq_enable();
> > >> + cpu_relax();
> > >
> > > This is a bad implementation though. You don't set the _QW_WAITING flag
> > > so readers don't know that there's a pending writer. Also, I've seen
> > > cpu_relax() pessimise CPU behaviour; putting it into a low-power mode
> > > that takes a while to wake up from.
> > >
> > > I think the right way to fix this is to pass a boolean flag to
> > > queued_write_lock_slowpath() to let it know whether it can re-enable
> > > interrupts while checking whether _QW_WAITING is set.
>
> lock(&lock->wait_lock)
> enable irq
> int
> lock(&lock->wait_lock)
>
> You are adding chance for recursive locking.
Did you bother to read queued_read_lock_slowpath() before writing this
email?
if (unlikely(in_interrupt())) {
/*
* Readers in interrupt context will get the lock immediately
* if the writer is just waiting (not holding the lock yet),
* so spin with ACQUIRE semantics until the lock is available
* without waiting in the queue.
*/
atomic_cond_read_acquire(&lock->cnts, !(VAL & _QW_LOCKED));
return;
Powered by blists - more mailing lists