From: Matthew Wilcox <willy@infradead.org>
To: Hillf Danton <hdanton@sina.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
Maria Yu <quic_aiquny@quicinc.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kernel: Introduce a write lock/unlock wrapper for tasklist_lock
Date: Thu, 28 Dec 2023 09:07:18 +0000 [thread overview]
Message-ID: <ZY06xtvaQ4ZJ5dXa@casper.infradead.org> (raw)
In-Reply-To: <20231227110727.1546-1-hdanton@sina.com>
On Wed, Dec 27, 2023 at 07:07:27PM +0800, Hillf Danton wrote:
> Feel free to ignore the following leg works.
>
> /* Set the waiting flag to notify readers that a writer is pending */
> atomic_or(_QW_WAITING, &lock->cnts);
>
> enable irq;
>
> /* When no more readers or writers, set the locked flag */
> do {
> cnts = atomic_cond_read_relaxed(&lock->cnts, VAL == _QW_WAITING);
> } while (!atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED));
>
> int
> atomic_cond_read_acquire(&lock->cnts, !(VAL & _QW_LOCKED));
> deadlock
> disable irq;
That would be a buggy implementation, and would not be what I was
thinking.
> Though the case below is safe, it looks not pretty but clumsy.
>
> /* Set the waiting flag to notify readers that a writer is pending */
> atomic_or(_QW_WAITING, &lock->cnts);
>
> /* When no more readers or writers, set the locked flag */
> do {
> enable irq;
>
> cnts = atomic_cond_read_relaxed(&lock->cnts, VAL == _QW_WAITING);
>
> disable irq;
>
> } while (!atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED));
Why do you think it looks clumsy? It's more or less what I was
thinking.
-void __lockfunc queued_write_lock_slowpath(struct qrwlock *lock)
+void __lockfunc queued_write_lock_slowpath(struct qrwlock *lock, bool irq)
...
do {
+ if (irq)
+ local_irq_enable();
cnts = atomic_cond_read_relaxed(&lock->cnts, VAL == _QW_WAITING);
+ if (irq)
+ local_irq_disable();
} while (!atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED));
next prev parent reply other threads:[~2023-12-28 9:07 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-13 10:17 [PATCH] kernel: Introduce a write lock/unlock wrapper for tasklist_lock Maria Yu
2023-12-13 16:22 ` Matthew Wilcox
2023-12-13 18:27 ` Eric W. Biederman
2023-12-15 5:52 ` Aiqun Yu (Maria)
2023-12-26 10:46 ` Hillf Danton
2023-12-26 20:49 ` Matthew Wilcox
2023-12-27 11:07 ` Hillf Danton
2023-12-28 9:07 ` Matthew Wilcox [this message]
2023-12-27 1:41 ` Aiqun Yu (Maria)
2023-12-27 10:14 ` Matthew Wilcox
2023-12-28 22:20 ` Matthew Wilcox
2023-12-29 11:35 ` kernel test robot
2024-01-02 2:19 ` Aiqun Yu (Maria)
2024-01-02 9:14 ` Matthew Wilcox
2024-01-03 2:58 ` Aiqun Yu (Maria)
2024-01-03 18:18 ` Matthew Wilcox
2024-01-04 0:46 ` Aiqun Yu (Maria)
2024-01-03 6:03 ` kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2023-12-25 8:19 Maria Yu
2023-12-25 8:26 ` Aiqun Yu (Maria)
2024-01-03 14:04 ` Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZY06xtvaQ4ZJ5dXa@casper.infradead.org \
--to=willy@infradead.org \
--cc=ebiederm@xmission.com \
--cc=hdanton@sina.com \
--cc=linux-kernel@vger.kernel.org \
--cc=quic_aiquny@quicinc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.