From: Siddh Raman Pant via Linux-kernel-mentees <linux-kernel-mentees@lists.linuxfoundation.org>
To: code@siddh.me
Cc: ebiggers@kernel.org, corbet@lwn.net, rdunlap@infradead.org,
linux-kernel@vger.kernel.org, dhowells@redhat.com,
edumazet@google.com, christophe.jaillet@wanadoo.fr,
mchehab@kernel.org,
linux-kernel-mentees@lists.linuxfoundation.org
Subject: [PATCH v2 3/3] kernel/watch_queue: Remove wqueue->defunct and use pipe for clear check
Date: Thu, 4 Aug 2022 20:11:52 +0530 [thread overview]
Message-ID: <20220804144152.468916-1-code@siddh.me> (raw)
In-Reply-To: <cd2a10ffd8cb11c79754f43d0d20fd3cd4ba9b7e.1659618705.git.code@siddh.me>
The sole use of wqueue->defunct is for checking if the watch queue has
been cleared, but wqueue->pipe is also NULL'd while clearing.
Thus, wqueue->defunct is superfluous, as wqueue->pipe can be checked
for NULL.
Signed-off-by: Siddh Raman Pant <code@siddh.me>
---
Changes in v2:
- The sent patch had accidentally missed removing the member
from struct, fix that.
- Use !READ_ONCE() instead of == NULL, as said by checkpatch.pl.
include/linux/watch_queue.h | 4 +---
kernel/watch_queue.c | 14 +++++---------
2 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/include/linux/watch_queue.h b/include/linux/watch_queue.h
index c99c39ec6548..88360771c097 100644
--- a/include/linux/watch_queue.h
+++ b/include/linux/watch_queue.h
@@ -55,7 +55,7 @@ struct watch_filter {
*
* @rcu: RCU head
* @filter: Filter on watch_notification::info
- * @pipe: The pipe we're using as a buffer.
+ * @pipe: The pipe we're using as a buffer, NULL when queue is cleared/closed
* @watches: Contributory watches
* @notes: Preallocated notifications
* @notes_bitmap: Allocation bitmap for notes
@@ -63,7 +63,6 @@ struct watch_filter {
* @lock: Spinlock
* @nr_notes: Number of notes
* @nr_pages: Number of pages in notes[]
- * @defunct: True when queues closed
*/
struct watch_queue {
struct rcu_head rcu;
@@ -76,7 +75,6 @@ struct watch_queue {
spinlock_t lock;
unsigned int nr_notes;
unsigned int nr_pages;
- bool defunct;
};
/**
diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c
index 8999c4e3076d..825943cf74b2 100644
--- a/kernel/watch_queue.c
+++ b/kernel/watch_queue.c
@@ -43,7 +43,7 @@ MODULE_LICENSE("GPL");
static inline bool lock_wqueue(struct watch_queue *wqueue)
{
spin_lock_bh(&wqueue->lock);
- if (unlikely(wqueue->defunct)) {
+ if (unlikely(!READ_ONCE(wqueue->pipe))) {
spin_unlock_bh(&wqueue->lock);
return false;
}
@@ -99,15 +99,12 @@ static bool post_one_notification(struct watch_queue *wqueue,
struct watch_notification *n)
{
void *p;
- struct pipe_inode_info *pipe = READ_ONCE(wqueue->pipe);
+ struct pipe_inode_info *pipe = wqueue->pipe;
struct pipe_buffer *buf;
struct page *page;
unsigned int head, tail, mask, note, offset, len;
bool done = false;
- if (!pipe)
- return false;
-
spin_lock_irq(&pipe->rd_wait.lock);
mask = pipe->ring_size - 1;
@@ -603,10 +600,9 @@ void watch_queue_clear(struct watch_queue *wqueue)
rcu_read_lock();
spin_lock_bh(&wqueue->lock);
- /* Prevent new notifications from being stored. */
- wqueue->defunct = true;
-
- /* This pipe will get freed by caller, and we are anyways clearing. */
+ /* This pipe will get freed by the caller free_pipe_info().
+ * Removing this reference also prevents new notifications.
+ */
wqueue->pipe = NULL;
while (!hlist_empty(&wqueue->watches)) {
--
2.35.1
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
next prev parent reply other threads:[~2022-08-04 14:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-04 13:30 [PATCH 0/3] kernel/watch_queue: Clean up some code Siddh Raman Pant via Linux-kernel-mentees
2022-08-04 13:30 ` [PATCH 1/3 v4] kernel/watch_queue: Remove dangling pipe reference while clearing watch_queue Siddh Raman Pant via Linux-kernel-mentees
2022-08-04 13:30 ` [PATCH 2/3] kernel/watch_queue: Improve struct annotation formatting Siddh Raman Pant via Linux-kernel-mentees
2022-08-05 7:22 ` Eric Biggers
2022-08-05 9:35 ` Siddh Raman Pant via Linux-kernel-mentees
2022-08-04 13:30 ` [PATCH 3/3] kernel/watch_queue: Remove wqueue->defunct and use pipe for clear check Siddh Raman Pant via Linux-kernel-mentees
2022-08-04 14:41 ` Siddh Raman Pant via Linux-kernel-mentees [this message]
2022-08-05 7:24 ` [PATCH v2 " Eric Biggers
2022-08-05 9:35 ` Siddh Raman Pant via Linux-kernel-mentees
2022-08-05 18:33 ` Eric Biggers
2022-08-06 7:23 ` Siddh Raman Pant via Linux-kernel-mentees
2022-08-05 7:16 ` [PATCH 0/3] kernel/watch_queue: Clean up some code Eric Biggers
2022-08-05 9:35 ` Siddh Raman Pant via Linux-kernel-mentees
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=20220804144152.468916-1-code@siddh.me \
--to=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=christophe.jaillet@wanadoo.fr \
--cc=code@siddh.me \
--cc=corbet@lwn.net \
--cc=dhowells@redhat.com \
--cc=ebiggers@kernel.org \
--cc=edumazet@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=rdunlap@infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).