Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5207358yba; Wed, 10 Apr 2019 13:55:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqzlGsaJjEVPUC/R+Vq+H2/AKjA5mQgPrhz8UeUi5s4NIYqhlDQ0B6pv/aW3nM/ZIrLUouMy X-Received: by 2002:a62:e501:: with SMTP id n1mr22366497pff.17.1554929718489; Wed, 10 Apr 2019 13:55:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554929718; cv=none; d=google.com; s=arc-20160816; b=azSBwVnPEbyYOHYl3kwgIAV7hDohV9Z9iTgYLN5/T7pYgV8dWzNrUx8lnvAjcFI54p nm8Jfz0cKWdwvVdMMFUG2FJAxvI3iRJmwJusoAPtsxfE9ztvHM7I5FVBUH1DB1XxrqEO jUufr/woprj0ZUK/Cfn1d5QQG+eMLPLOTAfcnItH0B2Osqm49pzei8mbqdBkq8m/Up/t MOkCYc9weJP0LnDcZy3bLb7axfG3ic6mo5U7lEDedmz8Ozv5+vrTsFbC3UUJ960AOeF8 DG1sgJVfME691j3mXYwznlwmwSW8s+aC9uXTEE8bo8RMOcClZOxMvyjOKT3LE5RS7DxE coVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=AMtRRq8Yslzu8XRQhXq0OwgPumG0BzaQqmya3Yg867k=; b=LvIshEqk8tL4i1ebiGqVIPBtUEMVj3nYf6LhHza8oIdB5+olyi8RG7Rx/76Py3uTh5 O5zSLowVgrbKobubAZq/zMmivf7ha0Dj2NWNJFfbbR2k2pf66Z2W8xhEj81oc/csXema 44XoCXcb+pvflNsVhmh6QUe2/7XWYQ43jTSKiPDqjCBctsE2XPK/EjzXjqe3WnbTTvPH pBel9Uxk0Aae517uKOAG6t7fR4tsN8VXYQvN8wbXjL6/wjyhMvsctVC2XBB3CGDu99md q7DxUhWBs/EgDoJsoFusWOo7yoGS4hvyBRiWXnoM5ghKwD5Wyd9bSsLhe3A0V3TRIwWw qfHQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12si32381660plt.418.2019.04.10.13.55.02; Wed, 10 Apr 2019 13:55:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726607AbfDJUy1 (ORCPT + 99 others); Wed, 10 Apr 2019 16:54:27 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:50798 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726181AbfDJUy1 (ORCPT ); Wed, 10 Apr 2019 16:54:27 -0400 Received: (qmail 10261 invoked by uid 2102); 10 Apr 2019 16:54:26 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 10 Apr 2019 16:54:26 -0400 Date: Wed, 10 Apr 2019 16:54:26 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Raul E Rangel cc: linux-usb@vger.kernel.org, , , Sebastian Andrzej Siewior , Martin Blumenstingl , Dmitry Torokhov , , "Gustavo A. R. Silva" , Miquel Raynal , Johan Hovold , Greg Kroah-Hartman , Mathias Nyman , Roger Quadros Subject: Re: [PATCH] usb/hcd: Send a uevent signaling that the host controller has died In-Reply-To: <20190410203520.248158-1-rrangel@chromium.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 10 Apr 2019, Raul E Rangel wrote: > This change will send a CHANGE event to udev with the DEAD environment > variable set when the HC dies. I chose this instead of any of the other > udev events because it's representing a state change in the host > controller. The only other event that might have fit was OFFLINE, but > that seems to be used for hot-removal. > > By notifying user space the appropriate policies can be applied. > e.g., > * Collect error logs. > * Notify the user that USB is no longer functional. > * Perform a graceful reboot. > > Signed-off-by: Raul E Rangel One or two problems... See below. > --- > > drivers/usb/core/hcd.c | 25 +++++++++++++++++++++++++ > include/linux/usb/hcd.h | 1 + > 2 files changed, 26 insertions(+) > > diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c > index 975d7c1288e3..b38ad9ce068b 100644 > --- a/drivers/usb/core/hcd.c > +++ b/drivers/usb/core/hcd.c > @@ -2343,6 +2343,22 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg) > return status; > } > > + > +/** > + * hcd_died_work - Workqueue routine for root-hub has died. > + * @hcd: primary host controller for this root hub. > + * > + * Do not call with the shared_hcd. > + * */ > +static void hcd_died_work(struct work_struct *work) > +{ > + struct usb_hcd *hcd = container_of(work, struct usb_hcd, died_work); > + > + /* Notify user space that the host controller has died */ > + kobject_uevent_env(&hcd->self.root_hub->dev.kobj, KOBJ_CHANGE, > + (char *[]){ "DEAD=1", NULL }); How do you know that the root hub hasn't already been deallocated? > +} > + > /* Workqueue routine for root-hub remote wakeup */ > static void hcd_resume_work(struct work_struct *work) > { > @@ -2488,6 +2504,13 @@ void usb_hc_died (struct usb_hcd *hcd) > usb_kick_hub_wq(hcd->self.root_hub); > } > } > + > + /* Handle the case where this function gets called with a shared HCD */ > + if (usb_hcd_is_primary_hcd(hcd)) > + schedule_work(&hcd->died_work); > + else > + schedule_work(&hcd->primary_hcd->died_work); > + > spin_unlock_irqrestore (&hcd_root_hub_lock, flags); > /* Make sure that the other roothub is also deallocated. */ > } > @@ -2555,6 +2578,8 @@ struct usb_hcd *__usb_create_hcd(const struct hc_driver *driver, > INIT_WORK(&hcd->wakeup_work, hcd_resume_work); > #endif > > + INIT_WORK(&hcd->died_work, hcd_died_work); > + > hcd->driver = driver; > hcd->speed = driver->flags & HCD_MASK; > hcd->product_desc = (driver->product_desc) ? driver->product_desc : You forgot to ensure that this work entry won't still be pending when the hcd structure is deallocated. Alan Stern > diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h > index 695931b03684..ae51d5bd1dfc 100644 > --- a/include/linux/usb/hcd.h > +++ b/include/linux/usb/hcd.h > @@ -98,6 +98,7 @@ struct usb_hcd { > #ifdef CONFIG_PM > struct work_struct wakeup_work; /* for remote wakeup */ > #endif > + struct work_struct died_work; /* for dying */ > > /* > * hardware info/state >