Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp47807rdb; Wed, 31 Jan 2024 23:23:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGkbRAVlx0L6ivYYwI/hW3cId6iYqlkDrHVpo2IVaQt3rnvT5weXoetpF1lEAaHrogr0fUt X-Received: by 2002:ae9:e103:0:b0:784:8531:50f2 with SMTP id g3-20020ae9e103000000b00784853150f2mr1832173qkm.29.1706772235482; Wed, 31 Jan 2024 23:23:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706772235; cv=pass; d=google.com; s=arc-20160816; b=AofK6X/8j5G/YLnydAW8DHyY0bt0JR1gQpjrmicR2pkDL45IH5GrQP1DNGj1XJf5xg Wi8T1/e8RTM3w0lnNcjYsTUhk4xqnCVGfB2UPeca0NAtTeP53yoOv6IS1VjEAz5KIb2C arKU7aA5pCROV5mug6qEPHoTp3cpvONm5TzNlVbi3q55deo1b1h+mJmKo4taO/E6tZ/Q OytyGHyg04vk62mGw4UV+7OTumdh3SW7M4Pj4d/RzDCEaMWmK2rYvoWCxfCEfsoDke0h O/PTpmrkTfR/wP4txljSO40YTFkV8Go3aqs/W4d2+EW5/92bMCH3DRCXnahMZOqaf09m ltdw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=CEHTNo21libmsE7au9AeaAX5BU9TiDgxYF+CMdrd70k=; fh=f17uR5qNJpw4Zazcqc48sMm0asG6inXIzFGfomco5vQ=; b=oVtAR2x9H4Wh/3Gdu0GhpI91IrBQSJ8iGJpzSjLlr3B2+0pdyzUpci10GXyWPym8Yy jJbKg/LrO07uMTSen3dtnVHigJaiIuFCOpyDu2lUB+N3x/IUwgA/uZ7OblUB2gFanadp UtqL243Q9wut/NOSHZa09mkm+1q/iYi4Kj5kPRnbJaqmuPi5vP7Mfy/lPFATHFB4W51Q EERGFdMv/AXxhuKyGqoJkdiVhJEqzjOtNCeGclFzfNsNNTMGBEku+plltTOp17GtIJeQ EfI3dSEUEXSvNY7pygn204awKuyPqYtDD9o0g7niHLT8yo3J3h4ofWs2/8ipQgNtVh4Q +d4Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=FK0P7dK5; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47728-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47728-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCUX+0iK7069r3RCZAUK8bONUzs1hZzOKGiTFd4etOqqDxORREuNp0via7q6igyI3DyYDBCX5RgfDAEapGBiuQbZOXs4ZwigjiKmv+yCgg== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id r15-20020a05620a03cf00b00783d70097f2si12945525qkm.364.2024.01.31.23.23.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 23:23:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47728-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=FK0P7dK5; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47728-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47728-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 2C6601C23DD0 for ; Thu, 1 Feb 2024 07:23:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C8E6815703D; Thu, 1 Feb 2024 07:23:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FK0P7dK5" Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04D18634FF for ; Thu, 1 Feb 2024 07:23:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706772226; cv=none; b=NiQtuSbYUSx2Gg8jaw80+3VNVwb+ngxffE6lk9/aU1811x2NA/iVhTanhNUjUBvY94nMS6zTSPiICagOEQOEMSY9KNdOCTNKUedz7Fk0+HCcAHfS05il4RRn0bejQ2j5gWP4uWE2bfS9CiExCNFAMWs1Dh5QqSFbFfhmlzLYQPM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706772226; c=relaxed/simple; bh=DEN/kHFjqWUd0ytUfrFgKzKqg40sG6kKXfo4lyhtOyg=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=sCPC1ENC1m0DfaPGLlXVPnF2sMjZKna9/3CAk1oALMxjlJpf8LPUwhO08+eNmStQwCTZ5GpBYlfEbaHtt7lGH1lBH1QJpDMPmNLqoqU5wYe2GFyJot0ALpbaIh7Ja6sulr+6ubG18peHt6WZB7PtGJUdbcpsQBkL/ojOevw/F8U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FK0P7dK5; arc=none smtp.client-ip=209.85.208.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-55f85a2a43fso6402a12.1 for ; Wed, 31 Jan 2024 23:23:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706772223; x=1707377023; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=CEHTNo21libmsE7au9AeaAX5BU9TiDgxYF+CMdrd70k=; b=FK0P7dK5QAhdP/JxeOXXLy8C+nRjXO3JD0Nsc6+5CGE6KfbuGWk3sPRSKAQb453Xsq 0HYc2Uj8c1WNkBRn/vSr6ONUMfwB/vs9E3aYSXwdL0DnqZfQk7M/f4YmrUU4o3sO2Mtw cA+gLd0uU6pxXe06HF7IpVkKGiaFPf0OjlXfmVUOXICntz+dNtANM0UJj06nU8vkdW+R YVCdEpFDU8FzQx010i9DehXjfjDoBdqiq27i+UVYSksq8c/EMrVYdKgXjR3r77glDt9m dBqKmWk90qs4+oPqgz3MduQOBNcytdra2QUznIWI+oUHoku9qXAfcrOHd1PNJPcIZheZ P8qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706772223; x=1707377023; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CEHTNo21libmsE7au9AeaAX5BU9TiDgxYF+CMdrd70k=; b=sHbGf7RMnjWk9buEGG4otBq9Aimx4CZ+h5OeQuHCr4RkRvr+mmYYUZELRakMC0XYCy ONdC0Wka3OObqgYRGnsGswUl/4+z/3tiXfvjACx0xYRXwhYaPYt4Ik1SEp76cLDVAwh8 jjbgRMzUGWPvpGpdmQ9Ysbf9BYcun/rhTRLcdBCP50rXyfLXdGZE5BCJ0g8U2ZjXjzFs uw++wZhA15lhjF0pbE8Zh/+y6PVij4mY+EhIynXZ2tpa31omw20C5mmJVAUWEatS21vK 9TwpNMOeNaikRxnsbWxnY6h/QM3jN57c/LFQ85b7KH9cvRupkrdayS4I8INnfHslWbbf JhYg== X-Gm-Message-State: AOJu0YzOmKgDxrx70PhWLIIYclfyfpWYBueEh+NuoUcDTpFxJIEf4tcc yOvo4q4GNCmwZ/Z+59+Pu/2XGiahyRrt/BrpAJ8K3BHf0hd6zYXsLMl6fozIVquwTKq+NUXozHH qfyLRYTcihhuqvvkKI7G13EVkfR7Dkkz/Y27y X-Received: by 2002:a50:cd02:0:b0:55f:a1af:bade with SMTP id z2-20020a50cd02000000b0055fa1afbademr5139edi.4.1706772222937; Wed, 31 Jan 2024 23:23:42 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240130064819.1362642-1-guanyulin@google.com> <2024013056-fidelity-sandy-0353@gregkh> In-Reply-To: <2024013056-fidelity-sandy-0353@gregkh> From: Guan-Yu Lin Date: Thu, 1 Feb 2024 15:22:00 +0800 Message-ID: Subject: Re: [PATCH] [RFC] usb: host: Allow userspace to control usb suspend flows To: Greg KH 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jan 31, 2024 at 12:41=E2=80=AFAM Greg KH wrote: > > 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 shoul= d > > 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/AB= I/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 U= SB devices > > + and their host contorller under this usb bus. The modific= ation of > > + this entry should be done when the system is active to en= sure 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 =3D 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", __fu= nc__); > > 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()? > Thanks for the suggestion. I'll change it to dev_dbg() in the next version. > > > + 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 =3D to_usb_device(dev); > > int status; > > > > + /* > > + * Skip the entire resume process under the same usb bus if its s= ysfs > > + * entry `deprecate_device_pm` is set. > > + */ > > + if (udev->bus->deprecate_device_pm) { > > + dev_vdbg(&udev->dev, "deprecating dev_pm_ops: %s\n", __fu= nc__); > > 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 =3D to_usb_device(dev); > > + int val, rc; > > + > > + if (sscanf(buf, "%d", &val) !=3D 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. > Thanks for the advice. I'll use kstrtobool() in the next version. In additi= on, I'll prepare another patch to update other self-rolled implementations. > > 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