Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp19754010ybl; Sat, 4 Jan 2020 08:23:01 -0800 (PST) X-Google-Smtp-Source: APXvYqxWMCdggwlcU63R+ovaxFk3yGCKS4f+nPA332WZAE27w+mtbmDqK2r1J9OyrqA6Cb3gYg0S X-Received: by 2002:a9d:6f07:: with SMTP id n7mr101992831otq.112.1578154981243; Sat, 04 Jan 2020 08:23:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578154981; cv=none; d=google.com; s=arc-20160816; b=OGYRHd4P44DAllnP0Fd9eGGsDtwR7+1/xFucTAoMutWL6Zgzgib+Kfl2iJ0V4c66Mh KItzsGgf1jdzvTfunJBQn5hrqWFWxonNKANuJCCNw56wIh3r1/P4f74m0eLN72VrshyG WiOC7FuCUXjD7aEqd41MKjFZbjIEvMG5OKeK0QoOQgbICR4kuYQ+Nns2lyKaa9AxqH0L Cx+esev9H1EydQ21YaSwzcg52TfDf9UAKkqw7T3oZ39cQGCj2VueW76tTRfVPI7l9knF 90s8icH5n+eH3byTgH+5Fj1yES0jg/G14GHrykCyy4Btnk8qlr78JK4P3tlAnFRm6Q+Q ADxQ== 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=88b8Ar5diJPTq+YAsuw4uCfOo2BirikYovpUz6pLRh4=; b=kwqyEUWiDkhC4Fjx6O8tDu+sluFnzHo+0VupBiXm04u/8Dtur6D2V2Wh/s79xXGX9H JaRkFWtu4Qs/MTek1NbgA30R/mPv5WgGn8s/AWu8BN6wQcwieKbYUaAppAXXY4wbrdQW KVhCHTjTP5HgQX1x9ZWWQWBq38UsR8337f4uSF1oxM8oZo8rDC9/WbPLVQVsrSb7PdcP Ysv/wGa0sCyPTSztfg0Jqe7XFjXFnTf8F736+T+xHpwMvroN5u06C6cXQEqNsCNdm26W Tg8dvSzzFxrpyF+UA5MY4wcfkGDEVcRGJFnqrnIkSHpjRwawtxNwiTuj4NTCcQU5TfTj NkKQ== 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 8si34075346otd.274.2020.01.04.08.22.48; Sat, 04 Jan 2020 08:23:01 -0800 (PST) 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 S1726191AbgADQU7 (ORCPT + 99 others); Sat, 4 Jan 2020 11:20:59 -0500 Received: from netrider.rowland.org ([192.131.102.5]:39433 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726005AbgADQU7 (ORCPT ); Sat, 4 Jan 2020 11:20:59 -0500 Received: (qmail 7682 invoked by uid 500); 4 Jan 2020 11:20:57 -0500 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 4 Jan 2020 11:20:57 -0500 Date: Sat, 4 Jan 2020 11:20:57 -0500 (EST) From: Alan Stern X-X-Sender: stern@netrider.rowland.org To: Kai-Heng Feng cc: Mathias Nyman , , , , Subject: Re: [PATCH 3/3] USB: Disable LPM on WD19's Realtek Hub during setting its ports to U0 In-Reply-To: <97F72C66-8D9B-4316-B096-1993FD18CF56@canonical.com> 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 Sat, 4 Jan 2020, Kai-Heng Feng wrote: > >>>> @@ -3533,9 +3533,17 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) > >>>> } > >>>> > >>>> /* see 7.1.7.7; affects power usage, but not budgeting */ > >>>> - if (hub_is_superspeed(hub->hdev)) > >>>> + if (hub_is_superspeed(hub->hdev)) { > >>>> + if (hub->hdev->quirks & USB_QUIRK_DISABLE_LPM_ON_U0) { > >>>> + usb_lock_device(hub->hdev); > >>>> + usb_unlocked_disable_lpm(hub->hdev); > >>>> + } > >>>> status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U0); > >>>> - else > >>>> + if (hub->hdev->quirks & USB_QUIRK_DISABLE_LPM_ON_U0) { > >>>> + usb_unlocked_enable_lpm(hub->hdev); > >>>> + usb_unlock_device(hub->hdev); > >>> > >>> The locking here seems questionable. Doesn't this code sometimes get > >>> called with the hub already locked? Or with the child device locked > >>> (in which case locking the hub would violate the normal locking order: > >>> parent first, child second)? > > > > I did a little checking. In many cases the child device _will_ be > > locked at this point. > > > >> Maybe introduce a new lock? The lock however will only be used by this specific hub. > >> But I still want the LPM can be enabled for this hub. > > > > Do you really need to lock the hub at all? What would the lock protect > > against? > > There can be multiple usb_port_resume() run at the same time for different ports, so this is to prevent LPM enable/disable race. But there can't really be an LPM enable/disable race, can there? The individual function calls are protected by the bandwidth mutex taken by the usb_unlocked_{en|dis}able_lpm routines, and the overall LPM setting is controlled by the hub device's lpm_disable_counter. So I think you don't need to lock the hub here. Alan Stern