Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2304189yba; Mon, 15 Apr 2019 08:57:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwMaU74wBT0RZLyAWatlRLViIwhbMNBzMm7XcBUOOP+1nyltzzbdi1YwP7IYGGy4F+CBb1u X-Received: by 2002:a62:1647:: with SMTP id 68mr14406899pfw.113.1555343821035; Mon, 15 Apr 2019 08:57:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555343821; cv=none; d=google.com; s=arc-20160816; b=ArAxGNgYFSiNL1cz5JcarCtkEHFCG4dRSgJrJE52r3Mkr5rVf74LhZsxY2BEgCUYW8 F3ga8t4AKHH2sxDkS8WaWzhhy6xcX63FhhURQbf5uI0BmTWYSwtXv1ShedIR+1LGh7SA wdajh8sZedCdC/DTPmxVnRcSkAfclo7ugIDbg1SiTwL2gMmQBrIipoda1IQXZJfbdmaJ Dppn0YNPuD6P2CiCiWP1Fwl7kYl4jtDWTamPaPAGZQw8oN1dohgJnu/M8SLr3bn0V6k/ lP7LH68X64zOeHn/96hTjmahPixIXUVdVWL6c7mEubpQYiNPO5N8uPCpAzh83BO5JI6k LXpA== 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=DUyfiPdISuYMDKSXiqxy6vs5sjVl1xkCjvsta1qrEew=; b=0UygH0+HueJM6ItlVbUKVCJr4+SrIqMiIKAPoKRHtoJTxf5JX1XvbpVU/YpH6QLuZB rzJrcXQ0UOEMpPTmTVjPhUO2Z6W6LXqESfa0+vQyDeREtVQ3AFj1oUs1zMKaOYlwuLdE nP1ErOAdm5m8lqRqgAzxZ9isEvSFwPgbOQa0pwkLoBdIqbox+HWHsOc+PY3Abyrzyl1a x4GU9mA4rRR4pIWv8SrJ9zmcFHyCBgelPGmDSopKt5RaBrrxnq/2wI8osKsH3EcwoJDb HZgnwKRJ6bUBUPqAWIwCNzpIVAi3Fk4olbWqTJDuyJGc8+HugWk+BfrFvD4025Y6eEdh O0BQ== 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 144si19783747pgf.59.2019.04.15.08.56.44; Mon, 15 Apr 2019 08:57:01 -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 S1727676AbfDOP4G (ORCPT + 99 others); Mon, 15 Apr 2019 11:56:06 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:39620 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726785AbfDOP4G (ORCPT ); Mon, 15 Apr 2019 11:56:06 -0400 Received: (qmail 5451 invoked by uid 2102); 15 Apr 2019 11:56:05 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 15 Apr 2019 11:56:05 -0400 Date: Mon, 15 Apr 2019 11:56:05 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Greg Kroah-Hartman , Raul E Rangel cc: USB list , , Oliver Neukum , , , Sebastian Andrzej Siewior , Martin Blumenstingl , Dmitry Torokhov , Suwan Kim , Kernel development list , "Gustavo A. R. Silva" , Miquel Raynal , Johan Hovold , Mathias Nyman Subject: Re: [PATCH v2] usb/hcd: Send a uevent signaling that the host controller has died In-Reply-To: <20190411185211.235940-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 Thu, 11 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 and it implies the device could > come ONLINE again. > > By notifying user space the appropriate policies can be applied. > i.e., > * Collect error logs. > * Notify the user that USB is no longer functional. > * Perform a graceful reboot. > > Signed-off-by: Raul E Rangel > --- > I wasn't able to find any good examples of other drivers sending a dead > notification. > > Use an EVENT= format > https://github.com/torvalds/linux/blob/master/drivers/acpi/dock.c#L302 > https://github.com/torvalds/linux/blob/master/drivers/net/wireless/ath/wil6210/interrupt.c#L497 > > Uses SDEV_MEDIA_CHANGE= > https://github.com/torvalds/linux/blob/master/drivers/scsi/scsi_lib.c#L2318 > > Uses ERROR=1. > https://chromium.googlesource.com/chromiumos/third_party/kernel/+/7f6d8aec5803aac44192f03dce5637b66cda7abf/drivers/input/touchscreen/atmel_mxt_ts.c#1581 > I'm not a fan because it doesn't signal what the error was. > > We could change the DEAD=1 event to maybe ERROR=1? > > Also where would be a good place to document this? > > Also thanks for the review. This is my first kernel patch so forgive me > if I get the workflow wrong. > > Changes in v2: > - Check that the root hub still exists before sending the uevent. > - Ensure died_work has completed before deallocating. > > drivers/usb/core/hcd.c | 32 ++++++++++++++++++++++++++++++++ > include/linux/usb/hcd.h | 1 + > 2 files changed, 33 insertions(+) Technically this patch looks okay to me. However, Greg KH may have some comments regarding the new uevent this introduces. Acked-by: Alan Stern Alan Stern > diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c > index 975d7c1288e3..7835f1a3647d 100644 > --- a/drivers/usb/core/hcd.c > +++ b/drivers/usb/core/hcd.c > @@ -2343,6 +2343,27 @@ 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); > + > + mutex_lock(&usb_bus_idr_lock); > + > + if (hcd->self.root_hub) > + /* Notify user space that the host controller has died */ > + kobject_uevent_env(&hcd->self.root_hub->dev.kobj, KOBJ_CHANGE, > + (char *[]){ "DEAD=1", NULL }); > + > + mutex_unlock(&usb_bus_idr_lock); > +} > + > /* Workqueue routine for root-hub remote wakeup */ > static void hcd_resume_work(struct work_struct *work) > { > @@ -2488,6 +2509,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 +2583,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 : > @@ -2908,6 +2938,7 @@ int usb_add_hcd(struct usb_hcd *hcd, > #ifdef CONFIG_PM > cancel_work_sync(&hcd->wakeup_work); > #endif > + cancel_work_sync(&hcd->died_work); > mutex_lock(&usb_bus_idr_lock); > usb_disconnect(&rhdev); /* Sets rhdev to NULL */ > mutex_unlock(&usb_bus_idr_lock); > @@ -2968,6 +2999,7 @@ void usb_remove_hcd(struct usb_hcd *hcd) > #ifdef CONFIG_PM > cancel_work_sync(&hcd->wakeup_work); > #endif > + cancel_work_sync(&hcd->died_work); > > mutex_lock(&usb_bus_idr_lock); > usb_disconnect(&rhdev); /* Sets rhdev to NULL */ > 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 >