Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1129262rdb; Tue, 30 Jan 2024 08:41:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0sryns8yg0RHgRHPZGGgh1b+ezaPCi8gHkmV7RDxA4IkyXDrSvGWH9CcjPaK4RpeZ3Ela X-Received: by 2002:a05:6870:c095:b0:214:b1fc:5730 with SMTP id c21-20020a056870c09500b00214b1fc5730mr8048793oad.8.1706632889451; Tue, 30 Jan 2024 08:41:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706632889; cv=pass; d=google.com; s=arc-20160816; b=AoS6Ynn8dpiS4q+77c+E7wLzEMDwFTn0wXgLU+K//zYUCMH+XzfZZlijKIlzgeVUSR 1rGACNH0a6ZWC76twWaBxzYHiFHQOVEAKyct02qPH/rqXEakvZ8C+xjfSd5rHYCzU37h XVdQylDvPLgmWNcMRFb7Zt9eUkzDQ4ik79AyMyWG28FK/GxnfYhZlWY9AjcgnIJr3F6w CLy326ISMvzHXoNVYBEpG9CWMr+CmFLsRW0fhBWyWMznH6SVBTX4Ko9GW1L89QFPfdb9 rI7XMF5ILobqlK5YlnKEWwgIIxePnV6rHfrwjHVFpI5IRmUilTaBn9WqtIfwvaIrMJMa QroQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=7q7/gja5RkswLz2HZAPOLJufo8NEY63rZZCdQ8xvWLg=; fh=XIlvmRqAHrK2UZVClqdaIiQPFyugaefOVWqn5XMsAzo=; b=wmNTKpsMD6A9bu1pbA5UXM4aav/FDcXX501+zuk/2mswqnQRcM/6Oq8qqbwwow9p52 ZNQqeZQVZgxCz+gk1z9y0CazhhzplEAwIjWhKaIoEozHdsFKvyg0qm0oYkKpAcjUvCpC cAnje/RE6xKs9JQbVVNfBFLetpC5lNJscvMcEaf85X4rmXqve/NkuMkI/ELpFzXX99Do hXTVPZ73jRtCH68jiujvT6sg+UE5kLuXpGyv3z58qBUtaRfZ4KGmnIZm6oBQ3xnFzEG3 YhuFNlD+9plG/TodV7O4X18LrSZB5/aQPefshSnItzh9o+rp1MTNoOuAmsQEqwUXftbv 04nA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dGS3aFMF; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-44965-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44965-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id e21-20020a633715000000b005d8bbf7e78bsi5580951pga.307.2024.01.30.08.41.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 08:41:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44965-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dGS3aFMF; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-44965-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44965-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 59F74286EE8 for ; Tue, 30 Jan 2024 16:41:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 170DC1272A3; Tue, 30 Jan 2024 16:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="dGS3aFMF" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34FB9364D6; Tue, 30 Jan 2024 16:41:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706632867; cv=none; b=WR5BHrTRP7apf1V7JzliOTXBGkbcHG6d/C7gwtvrCcesnsUnMSlDCVRCERm4QBcHZLo1Ef7Na4QU7OoFXY3bUBIwEX3Sc6BPkZyT4r8lyckNCbAAeYc2TZxejBBH6nMAKCHR1bYkuZU5+q7J2U9ajOUHCkGp+h0WS9ViH/U1jq4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706632867; c=relaxed/simple; bh=hw3BLY0wIeEGZGM9UVDCefwxIvj4sbE4suTDvWy8Zm0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=D17r8xG9YtVxaeSzq+UA7TinZtCFn69K3LBliRlkkb+NDjN3n7mowsZqcjNWLJst77n02MBelkDaHwZizF6Xjuc5K5loJnZjzfTeZJTc3QOA51EeUekggL768oWl52u29EGtUOz9sHyNT/T0ikq5bkLJdhEgJa/utwday+eD6Es= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=dGS3aFMF; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2904C433F1; Tue, 30 Jan 2024 16:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1706632866; bh=hw3BLY0wIeEGZGM9UVDCefwxIvj4sbE4suTDvWy8Zm0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dGS3aFMF+w36TIg9TeFxAtSAuXyvBbtnO2F3d9C7yKaZjkRuTBu6+P9gAEscD5MLE 7X8FH6Ij24mVW5Tf9DnxrP8dq7Ts8ezxyg0o7OYUf//cPGA0TfsNLkjrXzJx6XQu/r rx4KZI4T40MQooRy8VfOw9rZiD09KvEO306vYQec= Date: Tue, 30 Jan 2024 08:41:06 -0800 From: Greg KH To: Guan-Yu Lin Cc: mathias.nyman@intel.com, stern@rowland.harvard.edu, royluo@google.com, hadess@hadess.net, benjamin.tissoires@redhat.com, heikki.krogerus@linux.intel.com, oneukum@suse.com, grundler@chromium.org, yajun.deng@linux.dev, dianders@chromium.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, badhri@google.com, albertccwang@google.com, pumahsu@google.com Subject: Re: [PATCH] [RFC] usb: host: Allow userspace to control usb suspend flows Message-ID: <2024013056-fidelity-sandy-0353@gregkh> References: <20240130064819.1362642-1-guanyulin@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240130064819.1362642-1-guanyulin@google.com> On Tue, Jan 30, 2024 at 06:47:13AM +0000, Guan-Yu Lin wrote: > In a system with sub-system engaged, the controllers are controlled by > both the main processor and the co-processor. Chances are when the main > processor decides to suspend the USB device, the USB device might still > be used by the co-processor. In this scenario, we need a way to let > system know whether it can suspend the USB device or not. We introduce a > new sysfs entry "deprecate_device_pm" to allow userspace to control the > device power management functionality on demand. As the userspace should > possess the information of both the main processor and the co-processor, > it should be able to address the conflict mentioned above. > > Signed-off-by: Guan-Yu Lin > --- > Documentation/ABI/testing/sysfs-bus-usb | 10 +++++++++ > drivers/usb/core/driver.c | 18 ++++++++++++++++ > drivers/usb/core/sysfs.c | 28 +++++++++++++++++++++++++ > drivers/usb/host/xhci-plat.c | 20 ++++++++++++++++++ > include/linux/usb.h | 4 ++++ > 5 files changed, 80 insertions(+) > > diff --git a/Documentation/ABI/testing/sysfs-bus-usb b/Documentation/ABI/testing/sysfs-bus-usb > index 2b7108e21977..3f3d6c14201f 100644 > --- a/Documentation/ABI/testing/sysfs-bus-usb > +++ b/Documentation/ABI/testing/sysfs-bus-usb > @@ -19,6 +19,16 @@ Description: > would be authorized by default. > The value can be 1 or 0. It's by default 1. > > +What: /sys/bus/usb/devices/usbX/deprecate_device_pm > +Date: January 2024 > +Contact: Guan-Yu Lin > +Description: > + Deprecates the device power management functionality of USB devices > + and their host contorller under this usb bus. The modification of > + this entry should be done when the system is active to ensure the > + correctness of system power state transitions. > + The value can be 1 or 0. It's by default 0. > + > What: /sys/bus/usb/device/.../authorized > Date: July 2008 > KernelVersion: 2.6.26 > diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c > index e02ba15f6e34..e03cf972160d 100644 > --- a/drivers/usb/core/driver.c > +++ b/drivers/usb/core/driver.c > @@ -1569,6 +1569,15 @@ int usb_suspend(struct device *dev, pm_message_t msg) > struct usb_device *udev = to_usb_device(dev); > int r; > > + /* > + * Skip the entire suspend process under the same usb bus if its sysfs > + * entry `deprecate_device_pm` is set. > + */ > + if (udev->bus->deprecate_device_pm) { > + dev_vdbg(&udev->dev, "deprecating dev_pm_ops: %s\n", __func__); Nit, dev_dbg() already contains __func__ by default, so no need for that at all. And please use dev_dbg(), why are you using dev_vdbg()? > + return 0; > + } > + > unbind_no_pm_drivers_interfaces(udev); > > /* From now on we are sure all drivers support suspend/resume > @@ -1605,6 +1614,15 @@ int usb_resume(struct device *dev, pm_message_t msg) > struct usb_device *udev = to_usb_device(dev); > int status; > > + /* > + * Skip the entire resume process under the same usb bus if its sysfs > + * entry `deprecate_device_pm` is set. > + */ > + if (udev->bus->deprecate_device_pm) { > + dev_vdbg(&udev->dev, "deprecating dev_pm_ops: %s\n", __func__); Same as above. And for all other instances you added. > +static ssize_t deprecate_device_pm_store(struct device *dev, > + struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + struct usb_device *udev = to_usb_device(dev); > + int val, rc; > + > + if (sscanf(buf, "%d", &val) != 1 || val < 0 || val > 1) > + return -EINVAL; Please use the builtin function for determining if a boolean has been written through sysfs, don't roll your own. Note, these are just cosmetic things, I'm not taking the time yet to comment on the contents here, I'll let others do that first :) thanks, greg k-h