All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Helge Deller <deller@gmx.de>
Cc: linux-usb@vger.kernel.org,
	Linux Kernel Development <linux-kernel@vger.kernel.org>
Subject: Re: kernel crash/disc errors when unbinding USB devices
Date: Sun, 23 Jan 2022 13:33:12 +0100	[thread overview]
Message-ID: <Ye1LCATpTIRr/yZt@kroah.com> (raw)
In-Reply-To: <2ce0e792-ac09-a973-6751-6ed187b6fae6@gmx.de>

On Sun, Jan 23, 2022 at 12:59:21PM +0100, Helge Deller wrote:
> On 1/23/22 12:07, Greg Kroah-Hartman wrote:
> > On Sun, Jan 23, 2022 at 11:40:01AM +0100, Helge Deller wrote:
> >> On all kernels 5.15.x and 5.16.x I noticed that resetting
> >> the USB devices with this shell script:
> >>
> >>        for i in $(ls /sys/bus/pci/drivers/ahci/|grep :)
> >>          do
> >>          echo $i
> >>          echo $i >/sys/bus/pci/drivers/ahci/unbind
> >>          sleep 1
> >>          echo $i >/sys/bus/pci/drivers/ahci/bind
> >>         done
> >
> > That is dangerous to do, why do this?  All of your block devices might
> > have disappeard.
> >
> >>         # reseting USB3 ports (if there none you'll get errors)
> >>         for i in $(ls /sys/bus/pci/drivers/xhci_hcd/|grep :)
> >>          do
> >>          echo $i
> >>          echo $i >/sys/bus/pci/drivers/xhci_hcd/unbind
> >>          sleep 1
> >>          echo $i >/sys/bus/pci/drivers/xhci_hcd/bind
> >>         done
> >
> > Again, why do this at all?
> 
> I need to reset some of the USB devices after a suspend/resume cycle.

The devices, or the host controllers?  They are different things.

> The problem is, that some of the USB devices are
> handed over into a running VirtualBox VM and after
> the suspend/resume they need to be virtually plugged out/in
> so that the running Windows VM will reconnect them.

unbind/bind is a very harsh way of doing this.  but do it on the USB
devics, not the host controllers.

> If you search in the internet, you will find many places
> where this unbind/bind process is mentioned, e.g.:
> https://askubuntu.com/questions/645/how-do-you-reset-a-usb-device-from-the-command-line
> This procedure did worked in the past.

Never trust the internet :)

But note, there is a usbreset program mentioned there, which is part of
'usbutils' and should already be installed on your machine.  Why not
just use that?

> I think the main problem is, that it's somehow unexpected that
> the SATA controllers are logically attached to the USB
> controllers.

Huh?  No they are not.

'ahci' is a SATA controller.
'xhci' is a USB controller.

Two totally different things.

> So, if you believe to unbind "just" the USB devices you
> suddenly unbind SATA controllers too.

Again, no, you are unbinding two different things here.  And a USB host
controller is different than individual USB devices as well.

> >> immediately leads to a non-functional system, because the discs
> >> face I/O errors and will switch to read-only mode.
> >
> > Sure, the disks are gone, this is expected.
> 
> Ok.
> 
> >> Effectively I have to reboot the machine.
> >
> > I'm amazed it keeps working at all.
> 
> :-)
> 
> >> It's reproduceable for me on two completely different x86 machines with
> >> different USB devices.
> >
> > What do you expect this to do instead?  You just disabled all block
> > controllers in your system, followed by all USB controllers.  And then
> > attempted to add them back, but given that the old devices still had
> > userspace references on them, the devices will come back with different
> > names and so you need to mount them again.
> >
> > So this looks like it is working as intended.  Just don't do this :)
> 
> Ok, sure, but I think it's unexpected that the SATA ports are listed
> beneath the USB controllers, beside USB devices.

Where are they listed like that?

> If I run "lsusb", the SATA controllers don't show up either.

That is because they are independant and have nothing to do with each
otner.

> They are listed when I run "lspci".
> Shouldn't they maybe show up somewhere else, e.g.
> /sys/bus/pci/drivers/sata/*

The controllers are PCI drivers.  The block devices they create are
scsi devices (through the ata system).  This has nothing to do with USB.

confused,

greg k-h

  parent reply	other threads:[~2022-01-23 12:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-23 10:40 kernel crash/disc errors when unbinding USB devices Helge Deller
2022-01-23 11:07 ` Greg Kroah-Hartman
2022-01-23 11:59   ` Helge Deller
2022-01-23 12:02     ` Helge Deller
2022-01-23 12:33     ` Greg Kroah-Hartman [this message]
2022-01-23 13:07       ` Helge Deller
2022-01-23 13:11         ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Ye1LCATpTIRr/yZt@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=deller@gmx.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.