Page MenuHomeFreeBSD

eventfd: Add refcounting
AcceptedPublic

Authored by dumbbell on Jun 14 2025, 5:22 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Nov 19, 4:36 AM
Unknown Object (File)
Oct 3 2025, 11:41 AM
Unknown Object (File)
Oct 2 2025, 4:55 PM
Unknown Object (File)
Oct 2 2025, 4:56 AM
Unknown Object (File)
Sep 30 2025, 8:36 AM
Unknown Object (File)
Sep 14 2025, 5:55 AM
Unknown Object (File)
Sep 4 2025, 7:00 PM
Unknown Object (File)
Aug 31 2025, 8:48 AM
Subscribers

Details

Reviewers
markj
Group Reviewers
linuxkpi
Summary

An eventfd file descriptor can be used by drivers such as DRM drivers through linuxkpi. A driver can hold a reference to such a file regardless of the fact it is used by userland or not.

This patch introduces a refcount in struct eventfd_ctx, plus the eventfd_get() and eventfd_put() functions to acquire and release references. These functions will be used by DRM drivers for instance.

This structure is internal to sys/kern/sys_eventfd.c and not used anywhere else. Thus it is safe to add a field without breaking anything.

This is a requirement to the following patch to drm-kmod:
https://github.com/freebsd/drm-kmod/pull/358

Sponsored by: The FreeBSD Foundation

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

markj added a subscriber: markj.

This seems ok. It is kind of weird to have an eventfd that is not attached to a file descriptor, since there's nothing you can do with it. IMO it would be better for the drm drivers+linuxkpi to maintain a reference to the struct file instead, e.g., you could cheat and store a struct file * where drm stores a struct eventfd_ctx *, but that's a bit ugly too, and this is not a very intrusive diff.

sys/kern/sys_eventfd.c
103

It would be better to make it an unsigned int, that's the type used by the refcount(9) interface.

This revision is now accepted and ready to land.Sun, Nov 30, 4:41 PM