On Fri, Nov 13, 2020 at 08:27:25PM -0800, Davidlohr Bueso wrote: > The parallel port restore operation currently defers writes > to a tasklet, if it sees a locked disconnect mutex. The > driver goes to a lot of trouble to ensure writes happen > in a non-blocking context, but things can be greatly > simplified if it's done in regular process context and > this is not a system performance critical path. As such, > instead of doing the async state restore writes in irq > context, use a workqueue and just do regular synchronous > writes. > > In addition to the cleanup, this also imposes less on the > overall system as tasklets have been deprecated because > of it's BH implications, potentially blocking a higher > priority task from running. We also get rid of hacks > such as trylocking a mutex in irq, something which does > not play nice with priority boosting in PREEMPT_RT. > > Signed-off-by: Davidlohr Bueso <dbueso@xxxxxxx> > -/* > - * This is the the common top part of all parallel port callback operations that > + * This is the common top part of all parallel port callback operations that > * send synchronous messages to the device. This implements convoluted locking > * that avoids two scenarios: (1) a port operation is called after usbserial > * has called our release function, at which point struct mos7715_parport has This is an unrelated change, but ok. > @@ -641,10 +488,9 @@ static void parport_mos7715_restore_state(struct parport *pp, > } > mos_parport->shadowDCR = s->u.pc.ctr; > mos_parport->shadowECR = s->u.pc.ecr; > - write_parport_reg_nonblock(mos_parport, MOS7720_DCR, > - mos_parport->shadowDCR); > - write_parport_reg_nonblock(mos_parport, MOS7720_ECR, > - mos_parport->shadowECR); > + > + /* defer synchronous writes outside of irq */ This one isn't called in interrupt context, but with interrupts disabled and a spin lock held. > + schedule_work(&mos_parport->work); > spin_unlock(&release_lock); > } > @@ -1869,8 +1712,6 @@ static void mos7720_release(struct usb_serial *serial) > > if (le16_to_cpu(serial->dev->descriptor.idProduct) > == MOSCHIP_DEVICE_ID_7715) { > - struct urbtracker *urbtrack; > - unsigned long flags; > struct mos7715_parport *mos_parport = > usb_get_serial_data(serial); > > @@ -1883,21 +1724,17 @@ static void mos7720_release(struct usb_serial *serial) > if (mos_parport->msg_pending) > wait_for_completion_timeout(&mos_parport->syncmsg_compl, > msecs_to_jiffies(MOS_WDR_TIMEOUT)); > + /* > + * If delayed work is currently scheduled, wait for it to > + * complete. This also implies barriers that ensure the > + * below serial clearing is not hoisted above the ->work. > + */ > + cancel_work_sync(&mos_parport->work); As I mentioned, this needs to be done *after* deregistering the port or you could theoretically end up with the work item being requeued. Yes, the same applies for the "synchronous" requests, but that's a preexisting issue. > parport_remove_port(mos_parport->pp); > usb_set_serial_data(serial, NULL); > mos_parport->serial = NULL; Johan