Page MenuHomeFreeBSD

eventfd: Add refcounting
ClosedPublic

Authored by dumbbell on Jun 14 2025, 5:22 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Feb 8, 9:00 PM
Unknown Object (File)
Tue, Feb 3, 6:16 PM
Unknown Object (File)
Tue, Feb 3, 9:20 AM
Unknown Object (File)
Mon, Feb 2, 1:13 PM
Unknown Object (File)
Sat, Jan 31, 12:04 PM
Unknown Object (File)
Sat, Jan 31, 11:30 AM
Unknown Object (File)
Fri, Jan 30, 3:38 AM
Unknown Object (File)
Fri, Jan 30, 1:23 AM

Details

Reviewers
markj
Group Reviewers
linuxkpi
Commits
rG593164975184: eventfd: Add refcounting
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 Not Applicable
Unit
Tests Not Applicable

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.Nov 30 2025, 4:41 PM

Refresh patch after abandonning D50848.

This revision now requires review to proceed.Dec 13 2025, 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.

This revision is now accepted and ready to land.Fri, Jan 23, 2:45 PM
This revision was automatically updated to reflect the committed changes.