Re: [RESEND PATCH] kernfs: Avoid re-adding kernfs_node into kernfs_notify_list.

From: Tejun Heo
Date: Fri Jul 01 2022 - 16:11:47 EST


Hello,

On Sat, Jul 02, 2022 at 01:46:04AM +1000, Imran Khan wrote:
> @@ -992,9 +993,11 @@ void kernfs_notify(struct kernfs_node *kn)
> rcu_read_unlock();
>
> /* schedule work to kick fsnotify */
> - kernfs_get(kn);
> - llist_add(&kn->attr.notify_next, &kernfs_notify_list);
> - schedule_work(&kernfs_notify_work);
> + if (kn->attr.notify_next.next != NULL) {
> + kernfs_get(kn);
> + llist_add(&kn->attr.notify_next, &kernfs_notify_list);
> + schedule_work(&kernfs_notify_work);
> + }

Aren't you just narrowing the race window here? What prevents two
threads simultaneously testing for non NULL and then entering the
addition block together?

Looked at the llist code and it doesn't support multiple producers
trying to add the same node, unfortunately, so I'm not sure llist is
gonna work here. For now, the right thing to do prolly is reverting
it.

Al, is there something I'm missing about llist?

Thanks.

--
tejun