Messages in this thread Patch in this message | | | From | Siddh Raman Pant <> | Subject | [PATCH 3/3] kernel/watch_queue: Remove wqueue->defunct and use pipe for clear check | Date | Thu, 4 Aug 2022 19:00:24 +0530 |
| |
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> --- include/linux/watch_queue.h | 3 +-- kernel/watch_queue.c | 14 +++++--------- 2 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/include/linux/watch_queue.h b/include/linux/watch_queue.h index c99c39ec6548..2a3b318db49d 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; diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c index 8999c4e3076d..c63b128818f4 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) == NULL)) { 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
| |