From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBC78C31E5B for ; Tue, 18 Jun 2019 15:50:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BD54F20673 for ; Tue, 18 Jun 2019 15:50:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729491AbfFRPuC (ORCPT ); Tue, 18 Jun 2019 11:50:02 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:40226 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1729272AbfFRPuC (ORCPT ); Tue, 18 Jun 2019 11:50:02 -0400 Received: (qmail 5882 invoked by uid 2102); 18 Jun 2019 11:50:01 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 18 Jun 2019 11:50:01 -0400 Date: Tue, 18 Jun 2019 11:50:01 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Mayuresh Kulkarni cc: Greg KH , , , Subject: Re: [PATCH] usb: core: devio: add ioctls for suspend and resume In-Reply-To: <1560866441.8425.8.camel@opensource.cirrus.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org On Tue, 18 Jun 2019, Mayuresh Kulkarni wrote: > > You're right that the program needs to know when the device is about > > to  > > be suspended.  But waiting for an ioctl to return isn't a good way  > > to do it; this needs to be a callback of some sort.  That is, the  > > kernel also needs to know when the program is ready for the suspend. > > > > I don't know what is the best approach. > > This is becoming tricky now. Yes. There probably are mechanisms already in use in other parts of the kernel that would be suitable here, but I don't know what they are. We could try asking some other people for advice. > I think my point is - usbfs driver is actually doing nothing w.r.t USB- > 2.0 L2 state, right? The root-hub's suspend will invoke the USB-2.0 L2 > transitions. This will happen when all the USB devices on that port > report idle to USB-core. > I agree that usually driver's suspend/resume call-back will put the > device in its low power state. But that is not applicable to udev of > usbfs driver, right? It doesn't work quite the way you think. The suspend callback informs the driver that the device is about to enter a low-power state. The callback's job is to make the driver stop trying to communicate with the device, since all such communication attempts will fail once the device is suspended. The suspend callback is _not_ responsible for actually suspending the device; that is handled by the USB subsystem core. These ideas are indeed applicable to programs using usbfs. The kernel needs to have a way to inform the program that the device is about enter (or has just left) a low-power state, so that the program can stop (or start) trying to communicate with the device. And the kernel needs to know when the program is ready for the state change. > So, doesn't it makes sense to tell user-space about actual USB-2.0 L2 > state transitions rather than suspend/resume entry call-backs of device- > driver model of kernel (which are stub in this context)? Yes, that's what we need to figure out. But things have to happen in the right order; otherwise you could encounter a situation where the userspace program's URBs start failing and the program doesn't learn until later that the reason is because the device is being suspended. Alan Stern