Page MenuHomeFreeBSD

eventfd: Add refcounting
Needs ReviewPublic

Authored by dumbbell on Jun 14 2025, 5:22 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Dec 26, 7:02 AM
Unknown Object (File)
Wed, Dec 17, 4:45 AM
Unknown Object (File)
Wed, Dec 17, 4:45 AM
Unknown Object (File)
Tue, Dec 9, 1:18 PM
Unknown Object (File)
Sun, Dec 7, 9:39 AM
Unknown Object (File)
Nov 19 2025, 4:36 AM
Unknown Object (File)
Oct 3 2025, 11:41 AM
Unknown Object (File)
Oct 2 2025, 4:55 PM

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

Repository
rG FreeBSD src repository
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
106

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

Refresh patch after abandonning D50848.

This revision now requires review to proceed.Sat, Dec 13, 9:41 PM
christos added inline comments.
sys/kern/sys_eventfd.c
149

Why is this named "put"? Just curious, because this is just freeing resources.

sys/kern/sys_eventfd.c
149

"put" is a common way to refer to dropping a reference, I guess because it's a natural complement to "get". Similar to hold/release or acquire/release.

dumbbell added inline comments.
sys/kern/sys_eventfd.c
149

Indeed, the functions on Linux are eventfd_ctx_get() and eventfd_ctx_put(). They frequently use this get/put naming convention.

linuxkpi exposes eventfd_ctx_{get,put}(), thus it's possible to use a different naming for FreeBSD. Would you prefer another name?

dumbbell added inline comments.
sys/kern/sys_eventfd.c
106

I will change the type to unsigned int.

sys/kern/sys_eventfd.c
149

Would you prefer another name?

No, I was just curious.