[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220804144152.468916-1-code@siddh.me>
Date: Thu, 4 Aug 2022 20:11:52 +0530
From: Siddh Raman Pant <code@...dh.me>
To: code@...dh.me
Cc: christophe.jaillet@...adoo.fr, corbet@....net, dhowells@...hat.com,
ebiggers@...nel.org, edumazet@...gle.com,
linux-kernel-mentees@...ts.linuxfoundation.org,
linux-kernel@...r.kernel.org, mchehab@...nel.org,
rdunlap@...radead.org
Subject: [PATCH v2 3/3] kernel/watch_queue: Remove wqueue->defunct and use pipe for clear check
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@...dh.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
Powered by blists - more mailing lists