Re: a few usb issues related to edge cases

From: Andriy Gapon <avg_at_FreeBSD.org>
Date: Mon, 19 Dec 2011 17:06:13 +0200
First replying just to couple of points where there seems to be a misunderstanding.

on 19/12/2011 16:30 Hans Petter Selasky said the following:
>> 2.  Somewhat related to the above.  I think that because the USB subsystem
>> implements the shutdown method and detaches all its drivers, then the ukbd
>> driver won't be able to properly handle the 'shutdown -h' case where the
>> kernel asks to "press any key to reboot" at the end.  Depending on which
>> thread wins the race (the one that executes the mainline shutdown code or
>> the USB explore thread that detaches USB devices) there will either an
>> immediate reboot or a later crash when any key is pressed.
>> This is not critical, but OTOH perhaps the USB subsystem doesn't have to do
>> the shutdown.  As far as I can see a lot of the drivers just do nothing
>> for the shutdown, for better or for worth.
>>
>> A side note: perhaps it would be a good idea to pass the 'how' value as an
>> additional parameter to device_shutdown.
> 
> The shutdown of USB is done to give USB devices at last chance to turn off or 
> reduce their current consumption.
> 
> In the old code the Host controller itself would be disabled, so keyboard 
> wouldn't have worked I believe like you suggest.

I am not sure about the old code, I have never checked it.  But the atkbd
definitely works at this stage.

> BTW: Shutdown should be executed after any "Press any key to reboot." and 
> shutdown should be given time to complete, hence for USB this needs to happen 
> in sync with the rest of the USB system.

Have you actually ever done "shutdown -h"?  In other words do you know what the
"system halt" is? :)
I am not sure if it would be a good idea to declare a system as "halted" before
shutdown_final hooks are executed.  I would rather sacrifice the whole "press a
key" interactivity and simply executed hlt.  That's because I think that the
system halt has a very limited usage, mostly in combination with UPS, where
interactivity via console/keyboard is not very important.

BTW, the reason that I suggested to pass 'how' to device_shutdown is to give
drivers some choice.  E.g. USB could the whole shutdown thing for the cases of
poweroff and reboot, but keep the devices going for halt.

But probably right now we just need to make a decision whether ukbd is going to
support system halt or not.
If not, then I think that usb_shutdown() must wait until the explore_proc
terminates.
If yes, then usb_shutdown() should become a noop.  Or it could become quite
smart to detach/poweroff other devices in such a way that ukbd still stays
usable. But that's probably harder to implement.


[snip]

>> As a side note: we probably need a flag to mark certain things such as e.g.
>> the ukbd driver as "non recoverable", meaning that once those are used in
>> the kdb context then there is no safe way to go back to normal system
>> operation.
> 
> I think you need to do shutdown _after_ the "Press any key to reboot". A flag 
> won't help.

Umm, this suggestion was about entering and exiting KDB/DDB, not about
shutdown/reboot.

P.S.  I've just looked at the code in stable/7 and it seems that it didn't
actually unconfigured USB and detached device drivers.  At least ohci_shutdown
and ohci_shutdown are not called on FreeBSD.


-- 
Andriy Gapon
Received on Mon Dec 19 2011 - 14:06:21 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:22 UTC