Subject: Re: [PATCH v4 02/10] fwctl: Basic ioctl dispatch for the character device

From: Jason Gunthorpe <[email-masked]>
Date: Fri, 7 Feb 2025 09:52:59 -0400

On Fri, Feb 07, 2025 at 12:59:15PM +0000, Jonathan Cameron wrote:
> >  static int fwctl_fops_release(struct inode *inode, struct file *filp)
> >  {
> > -	struct fwctl_device *fwctl = filp->private_data;
> > +	struct fwctl_uctx *uctx = filp->private_data;
> > +	struct fwctl_device *fwctl = uctx->fwctl;
> >  
> > +	scoped_guard(rwsem_read, &fwctl->registration_lock) {
> > +		/*
> > +		 * fwctl_unregister() has already removed the driver and
> > +		 * destroyed the uctx.
> 
> Comment is a little odd given it is I think referring to why
> the code that follows wouldn't run. Perhaps just add a 'may'

It is intended to describe the if:

> > +		if (fwctl->ops) {
> > +			guard(mutex)(&fwctl->uctx_list_lock);
> > +			fwctl_destroy_uctx(uctx);
> > +		}

So let's do:

		/*
		 * NULL ops means fwctl_unregister() has already removed the
		 * driver and destroyed the uctx.
		 */
		if (fwctl->ops) {

> > +	fwctl->dev.class = &fwctl_class;
> > +	fwctl->dev.parent = parent;
> 
> Shunt this move back to previous patch?

Yes

> > +/**
> > + * struct fwctl_ops - Driver provided operations
> > + *
> > + * fwctl_unregister() will wait until all excuting ops are completed before it
> > + * returns. Drivers should be mindful to not let their ops run for too long as
> > + * it will block device hot unplug and module unloading.
> 
> A passing comment on this.  Seems likely that at somepoint we'll want an
> abort op to enable cancelling if the particular driver supports it
> (abort background command in CXL).  Anyhow, problem for another day.

Hum, that will be an interesting thing to fit in. abort from userspace
as an ioctl would make sense. auto-abort to hotunplug seems a bit
tricky

Thanks,
Jason