Re: [PATCH 1/3] cdev: Finish the cdev api with queued mode support

From: Dan Williams
Date: Wed Jan 20 2021 - 15:44:36 EST

On Wed, Jan 20, 2021 at 11:51 AM Logan Gunthorpe <logang@xxxxxxxxxxxx> wrote:
> On 2021-01-20 12:38 p.m., Dan Williams wrote:
> > ...common reference count handling scenarios were addressed, but the
> > shutdown-synchronization problem was only mentioned as something driver
> > developers need to be aware in the following note:
> >
> > NOTE: This guarantees that associated sysfs callbacks are not running
> > or runnable, however any cdevs already open will remain and their fops
> > will still be callable even after this function returns.
> >
> > Remove that responsibility from driver developers with the concept of a
> > 'queued' mode for cdevs.
> I find the queued name confusing. What's being queued?

Yeah, as I mentioned to Christoph, a bit too much inspiration from
q_usage_count. Perhaps "managed" makes more sense.

> > +static const struct file_operations cdev_queued_fops = {
> > + .owner = THIS_MODULE,
> > + .open = cdev_queued_open,
> > + .unlocked_ioctl = cdev_queued_ioctl,
> > + .compat_ioctl = compat_ptr_ioctl,
> > + .llseek = noop_llseek,
> > +};
> Why do we only protect these fops? I'd find it a bit confusing to have
> ioctl protected from use after del, but not write/read/etc.

More ops can certainly be added over time, I didn't want to go do the
work to wrap all file_operations before getting consensus on the idea
that the cdev core should provide managed ops at all.

The other question I'm posing with cdev_operations is whether the cdev
core should take away some of the flexibility from end drivers in
favor of adding more type safety. For example, mandate that all ioctls
take a pointer argument not an integer argument? The question of
whether wrapping cdev file_operations around a new cdev_operations is
a good idea can be deferred after finalizing a mechanism for managed
cdev file_operations.