Re: [PATCH RFC 35/38] proc: sysctl: don't hold the tables while readdir copies to userspace
From: Christian Brauner
Date: Fri Nov 06 2026 - 09:11:55 EST
On Thu, 5 Nov 2026 13:55:56 +0100, Jan Kara wrote:
> So I didn't really carefully check all the details but overall this looks
> sane to me. Just one thing that was confusing me is: Why is sysctl_dirent
> separate from sysctl_cursor? Wouldn't it be more logical for sysctl_cursor
> itself to start what it needs to pin the entry it wants to restart from?
Because they have different lifetimes. The cursor lives in the file
between two getdents() calls. So nothing in the cursor may be something
that unregistering the sysctl table waits for. So it only remembers the
name of the last entry and the position behind it.
sysctl_dirent is the state of one call. It does hold a grabbed header
which we drop before the call returns.
If the cursor were to hold the header too then every open directory
would keep the table of its last entry pinned until the next getdents()
or close() which is the indefinite delay this patch kills.