[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <841pr6msql.fsf@jogness.linutronix.de>
Date: Thu, 26 Jun 2025 17:29:46 +0206
From: John Ogness <john.ogness@...utronix.de>
To: Nam Cao <namcao@...utronix.de>, Alexander Viro
<viro@...iv.linux.org.uk>, Christian Brauner <brauner@...nel.org>, Jan
Kara <jack@...e.cz>, Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
Clark Williams <clrkwllms@...nel.org>, Steven Rostedt
<rostedt@...dmis.org>, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-rt-devel@...ts.linux.dev,
linux-rt-users@...r.kernel.org, Joe Damato <jdamato@...tly.com>, Martin
Karsten <mkarsten@...terloo.ca>, Jens Axboe <axboe@...nel.dk>
Cc: Nam Cao <namcao@...utronix.de>, Frederic Weisbecker
<frederic@...nel.org>, Valentin Schneider <vschneid@...hat.com>
Subject: Re: [PATCH v3] eventpoll: Fix priority inversion problem
On 2025-05-27, Nam Cao <namcao@...utronix.de> wrote:
> diff --git a/fs/eventpoll.c b/fs/eventpoll.c
> index d4dbffdedd08e..a97a771a459c9 100644
> --- a/fs/eventpoll.c
> +++ b/fs/eventpoll.c
> @@ -137,13 +137,7 @@ struct epitem {
> };
>
> /* List header used to link this structure to the eventpoll ready list */
> - struct list_head rdllink;
> -
> - /*
> - * Works together "struct eventpoll"->ovflist in keeping the
> - * single linked chain of items.
> - */
> - struct epitem *next;
> + struct llist_node rdllink;
>
> /* The file descriptor information this item refers to */
> struct epoll_filefd ffd;
> @@ -191,22 +185,15 @@ struct eventpoll {
> /* Wait queue used by file->poll() */
> wait_queue_head_t poll_wait;
>
> - /* List of ready file descriptors */
> - struct list_head rdllist;
> -
> - /* Lock which protects rdllist and ovflist */
> - rwlock_t lock;
> + /*
> + * List of ready file descriptors. Adding to this list is lockless. Items can be removed
> + * only with eventpoll::mtx
> + */
> + struct llist_head rdllist;
>
> /* RB tree root used to store monitored fd structs */
> struct rb_root_cached rbr;
>
> - /*
> - * This is a single linked list that chains all the "struct epitem" that
> - * happened while transferring ready events to userspace w/out
> - * holding ->lock.
> - */
> - struct epitem *ovflist;
> -
> /* wakeup_source used when ep_send_events or __ep_eventpoll_poll is running */
> struct wakeup_source *ws;
>
> @@ -361,10 +348,14 @@ static inline int ep_cmp_ffd(struct epoll_filefd *p1,
> (p1->file < p2->file ? -1 : p1->fd - p2->fd));
> }
>
> -/* Tells us if the item is currently linked */
> -static inline int ep_is_linked(struct epitem *epi)
> +/*
> + * Add the item to its container eventpoll's rdllist; do nothing if the item is already on rdllist.
> + */
> +static void epitem_ready(struct epitem *epi)
> {
> - return !list_empty(&epi->rdllink);
> + if (&epi->rdllink == cmpxchg(&epi->rdllink.next, &epi->rdllink, NULL))
Perhaps:
if (try_cmpxchg(&epi->rdllink.next, &epi->rdllink, NULL))
> + llist_add(&epi->rdllink, &epi->ep->rdllist);
> +
> }
>
> static inline struct eppoll_entry *ep_pwq_from_wait(wait_queue_entry_t *p)
John Ogness
Powered by blists - more mailing lists