public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] USB: max3421: Fix scheduling while atomic in max3421_remove()
@ 2025-02-10 14:06 Matt Lee
  0 siblings, 0 replies; 4+ messages in thread
From: Matt Lee @ 2025-02-10 14:06 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, matt

A bug in `max3421_remove()` caused a "scheduling while atomic" crash when
`kthread_stop()` was called while holding a spinlock.

This patch ensures that `kthread_stop()` is called outside the spinlock,
fixing the crash and improving system stability when unloading the driver.

Signed-off-by: Matt Lee <matt@oscium.com>
---
 drivers/usb/host/max3421-hcd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/host/max3421-hcd.c b/drivers/usb/host/max3421-hcd.c
index abcdef0..1234567 100644
--- a/drivers/usb/host/max3421-hcd.c
+++ b/drivers/usb/host/max3421-hcd.c
@@ -1936,11 +1945,10 @@ max3421_remove(struct spi_device *spi)
        usb_remove_hcd(hcd);

        spin_lock_irqsave(&max3421_hcd->lock, flags);
+       spin_unlock_irqrestore(&max3421_hcd->lock, flags);

        kthread_stop(max3421_hcd->spi_thread);

-       spin_unlock_irqrestore(&max3421_hcd->lock, flags);
-
        free_irq(spi->irq, hcd);

        usb_put_hcd(hcd);
-- 
2.34.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] USB: max3421: Fix scheduling while atomic in max3421_remove()
       [not found] <CABrMTje0ijdtcO31HmuSufxXFQO2Ay2Rh0_0Qc4FFC3zgqe-pA@mail.gmail.com>
@ 2025-02-10 14:07 ` Greg KH
  2025-02-10 15:42   ` Matt Lee
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2025-02-10 14:07 UTC (permalink / raw)
  To: Matt Lee; +Cc: linux-usb

On Mon, Feb 10, 2025 at 07:48:29AM -0600, Matt Lee wrote:
> A bug in `max3421_remove()` caused a "scheduling while atomic" crash when
> `kthread_stop()` was called while holding a spinlock.
> 
> This patch ensures that `kthread_stop()` is called outside the spinlock,
> fixing the crash and improving system stability when unloading the driver.
> 
> Signed-off-by: Matt Lee <matt@oscium.com>
> ---
>  drivers/usb/host/max3421-hcd.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/host/max3421-hcd.c b/drivers/usb/host/max3421-hcd.c
> index abcdef0..1234567 100644
> --- a/drivers/usb/host/max3421-hcd.c
> +++ b/drivers/usb/host/max3421-hcd.c
> @@ -1936,11 +1945,10 @@ max3421_remove(struct spi_device *spi)
>         usb_remove_hcd(hcd);
> 
>         spin_lock_irqsave(&max3421_hcd->lock, flags);
> +       spin_unlock_irqrestore(&max3421_hcd->lock, flags);
> 
>         kthread_stop(max3421_hcd->spi_thread);
> 
> -       spin_unlock_irqrestore(&max3421_hcd->lock, flags);
> -

So now the lock does nothing?  Are you sure this change is correct?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] USB: max3421: Fix scheduling while atomic in max3421_remove()
  2025-02-10 14:07 ` [PATCH 2/2] USB: max3421: Fix scheduling while atomic in max3421_remove() Greg KH
@ 2025-02-10 15:42   ` Matt Lee
  2025-02-10 15:51     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Matt Lee @ 2025-02-10 15:42 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-usb

The submitted patch fixes a crash we are experiencing on every shutdown.
Perhaps the better solution is to remove the spin_lock_irqsave/restore?

I tested removing the spin_lock completely and the crash issue was eliminated.
Happy to update the patch if this is the preferred method.

Kind regards,

Matt


On Mon, Feb 10, 2025 at 8:12 AM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Mon, Feb 10, 2025 at 07:48:29AM -0600, Matt Lee wrote:
> > A bug in `max3421_remove()` caused a "scheduling while atomic" crash when
> > `kthread_stop()` was called while holding a spinlock.
> >
> > This patch ensures that `kthread_stop()` is called outside the spinlock,
> > fixing the crash and improving system stability when unloading the driver.
> >
> > Signed-off-by: Matt Lee <matt@oscium.com>
> > ---
> >  drivers/usb/host/max3421-hcd.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/drivers/usb/host/max3421-hcd.c b/drivers/usb/host/max3421-hcd.c
> > index abcdef0..1234567 100644
> > --- a/drivers/usb/host/max3421-hcd.c
> > +++ b/drivers/usb/host/max3421-hcd.c
> > @@ -1936,11 +1945,10 @@ max3421_remove(struct spi_device *spi)
> >         usb_remove_hcd(hcd);
> >
> >         spin_lock_irqsave(&max3421_hcd->lock, flags);
> > +       spin_unlock_irqrestore(&max3421_hcd->lock, flags);
> >
> >         kthread_stop(max3421_hcd->spi_thread);
> >
> > -       spin_unlock_irqrestore(&max3421_hcd->lock, flags);
> > -
>
> So now the lock does nothing?  Are you sure this change is correct?
>
> thanks,
>
> greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] USB: max3421: Fix scheduling while atomic in max3421_remove()
  2025-02-10 15:42   ` Matt Lee
@ 2025-02-10 15:51     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2025-02-10 15:51 UTC (permalink / raw)
  To: Matt Lee; +Cc: linux-usb

On Mon, Feb 10, 2025 at 09:42:46AM -0600, Matt Lee wrote:
> The submitted patch fixes a crash we are experiencing on every shutdown.
> Perhaps the better solution is to remove the spin_lock_irqsave/restore?

Please don't top post.

Having a lock/unlock pair without anything in it can be used for
something (it's a gate primitive), but I don't think that it's being
used for that here.

> I tested removing the spin_lock completely and the crash issue was eliminated.
> Happy to update the patch if this is the preferred method.

Ideally fix the root issue in that this lock is needed to protect the
data here, so removing it doesn't actually fix the real problem, only
trade the crash for a race condition, right?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-02-10 15:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CABrMTje0ijdtcO31HmuSufxXFQO2Ay2Rh0_0Qc4FFC3zgqe-pA@mail.gmail.com>
2025-02-10 14:07 ` [PATCH 2/2] USB: max3421: Fix scheduling while atomic in max3421_remove() Greg KH
2025-02-10 15:42   ` Matt Lee
2025-02-10 15:51     ` Greg KH
2025-02-10 14:06 Matt Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox