Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1642062imm; Tue, 22 May 2018 07:13:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrUGBYR7cqIiPvFNQC4vvfuyp4SFUbgVOUph8VOJrYPjKNRM8EN7Gw8uIm8GlDszuipReG7 X-Received: by 2002:a62:fc8:: with SMTP id 69-v6mr24442917pfp.14.1526998396889; Tue, 22 May 2018 07:13:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526998396; cv=none; d=google.com; s=arc-20160816; b=dLgCgLSSPbc39PO0xfSD9WaA+WFzgPCTV8ZqLiBbzvH+Uun64jDItn4FfOF4d29AyK pYN4b8KhsgBjkOuEdRN//TB8dxi7IOzP1N4O362TtqJU7qLBQqFqwqUEe19+XswzpDEq P9CpGxEnpUQGOKTJQPbtA/X8GSnipLRswpIVbZDVqZODfdb3fbDrYfnEW22h367PQdyg +CQxbBh9s5fPJUqIJnnaYFBIFZGoBOCREiiEr0DPX2HrzhT7ccbA8Xm5kyuxW59GtDCd udAzPxSpN0lCjUcyrXbipCxCfjek3hO0jqakWHvL/3axflQzc1W0mgUjwG9WK4hcIMAn 72XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:to:from:date:dkim-signature :arc-authentication-results; bh=YBGnD1U2PPx39XUIUmAlK2mcQzEnO4SGrG749weBrzc=; b=emDnXwVhw2qPGtHzW1D8HrGiCjrJ4LI1QuOG7Sq/P/ua9lTzm+EvO4RAivgPqxFeLp 7Y50GfmSTGuAGYaFRZ4VKSYoaxGXnugNiLeRnESK0fml/jxQtIGpT2RgfG8nKrH+QUMK lgn+jWvEsZ/hW1XmgK90aYFxYbeKtClTvqcGLdImcEyPaDiqe8NRBS0USvhuhNrHNpaG pQQUiD08p0dGssToFxzWLVCaL6mIxKnP9kFJvVyU5DoSFbK73yAQR2HoV+e158HLwMIh smpiVn4KFAUWo5EO6eVI1yzQ2PAgVSCl4bOcrqtzWX0aSX3NIurf1HM1ZewE+GaHEWM0 y/YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Gn8g59jl; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e6-v6si12827585pgt.208.2018.05.22.07.12.57; Tue, 22 May 2018 07:13:16 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=Gn8g59jl; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751801AbeEVOMi (ORCPT + 99 others); Tue, 22 May 2018 10:12:38 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:42045 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751199AbeEVOMd (ORCPT ); Tue, 22 May 2018 10:12:33 -0400 Received: by mail-pl0-f67.google.com with SMTP id u6-v6so10988251pls.9 for ; Tue, 22 May 2018 07:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=YBGnD1U2PPx39XUIUmAlK2mcQzEnO4SGrG749weBrzc=; b=Gn8g59jlv55CAPIgtNqC8ZA71RB5zNUluotbZ/lTBm3HXDXt/J1+302GN8DMzypMkT BXX6NXoBKrC/0uFh5JQB3kEHdOIjPbkRvSxIj/rbb9Zr+hKuNwyV2s/V/YMQ0e2/FiuK 2XsW/yvIT1je710yYo19xbDyUp5EgJnbCUKoik8qa2MTYLKFJNSmsQLYweQ7dXp1ZT6L nAK+bLebcjlBfYG4V13KX6JQ3gFONaXf6kUYOGoI6xj/AZBSeqSlIPMpWSLdIemnN5In 2vVUFHVWl66uEEJ7MMa6z15Olbqk9RhIqby65aYzyHnBO8YLbLdbswhGaHY8wMKUG0+N gx9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=YBGnD1U2PPx39XUIUmAlK2mcQzEnO4SGrG749weBrzc=; b=Eym4+NDgNBZndGBfI1f/9rrquHwVBQr4w3+7lgr9eBF/SW90jgAFGLOqj8MydsEHkG jUyIWz0F5IuVeeL0L8C5a9w5529xK6pQwCE66FuzoHTVEulu3CQVze/p+/UesQiIBRef AOkZMK2COS3bw4QkQX+BP5OSgc58fOuJHn/cd62nYCLW3Znm48uHIJbQw+b+3GN5V7vF qnBOOd1TSxDAEVETBov9fLmMWns4QM1wexHu/4AHtmZw+CF2U6/MWIZG8xB4ac6s6Y3B 5tfEb6JxKhw86UEUvl3L0VLT7GtDdXRUHVZ/B8TZK8sZzQknaut5bRqzNxnRFbdFf+cq 5lvQ== X-Gm-Message-State: ALKqPwfEm19Vq6KnLjUbkgSuWm+IMtvkrv52IW/P9huAncjkpBJdh4yg 1aXOm1dyc51aju/8opi6KOc6ow== X-Received: by 2002:a17:902:82c3:: with SMTP id u3-v6mr24642919plz.83.1526998352436; Tue, 22 May 2018 07:12:32 -0700 (PDT) Received: from google.com ([2401:fa00:fc:202:ac57:d0e0:7094:5]) by smtp.gmail.com with ESMTPSA id g8-v6sm24645520pgc.0.2018.05.22.07.12.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 May 2018 07:12:31 -0700 (PDT) Date: Tue, 22 May 2018 22:12:27 +0800 From: martin_liu To: gregkh@linuxfoundation.org, stern@rowland.harvard.edu, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC] driver core: don't hold dev's parent lock when using async probe Message-ID: <20180522141227.GA118442@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org SOC have internal I/O buses that can't be probed for devices. The devices on the buses can be accessed directly without additinal configuration required. This type of bus is represented as "simple-bus". In some platforms, we name "soc" with "simple-bus" attribute and many devices are hooked under and desribe them in DT (device tree). In commit 'bf74ad5bc417 introduce ("[PATCH] Hold the device's parent's lock during probe and remove")' to solve USB subsystem lock sequence since usb device's characteristic. Thus "soc" needs to be locked whenever a device and driver's probing happen under "soc" bus. During this period, an async driver tries to probe a device which is under the "soc" bus would be blocked until previous driver finish the probing and release "soc" lock. And the next probing under the "soc" bus need to wait for async finish. Because of that, driver's async probe for init time improvement will be shadowed. Since many devices don't have USB devices' characteristic, they actually don't need parent's lock. However, in order to control the risk and minimize the impact, we don't request parent's lock only when a driver requests async probe. Async probe could have more benefit after we have this patch. Signed-off-by: martin_liu --- This RFC is asked to get some feedback since it involed driver core and USB subsystem. I'm not familiar with USB subsystem and not sure if we still need 'bf74ad5bc417 ("[PATCH] Hold the device's parent's lock during probe and remove")' since it has been there over 10 years. If we still need it and hard to fix it , the simple way is to find a place not to allow USB subsystem drivers to have async probe capability. Any suggestion is welcome. drivers/base/bus.c | 19 +++++++++++++------ drivers/base/dd.c | 23 ++++++++++++++++------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index ef6183306b40..6434333995d4 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -181,13 +181,15 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf, struct bus_type *bus = bus_get(drv->bus); struct device *dev; int err = -ENODEV; + bool allow_async; + allow_async = driver_allows_async_probing(drv); dev = bus_find_device_by_name(bus, NULL, buf); if (dev && dev->driver == drv) { - if (dev->parent) /* Needed for USB */ + if (dev->parent && !allow_async)/* Needed for USB */ device_lock(dev->parent); device_release_driver(dev); - if (dev->parent) + if (dev->parent && !allow_async) device_unlock(dev->parent); err = count; } @@ -208,15 +210,17 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf, struct bus_type *bus = bus_get(drv->bus); struct device *dev; int err = -ENODEV; + bool allow_async; + allow_async = driver_allows_async_probing(drv); dev = bus_find_device_by_name(bus, NULL, buf); if (dev && dev->driver == NULL && driver_match_device(drv, dev)) { - if (dev->parent) /* Needed for USB */ + if (dev->parent && !allow_async)/* Needed for USB */ device_lock(dev->parent); device_lock(dev); err = driver_probe_device(drv, dev); device_unlock(dev); - if (dev->parent) + if (dev->parent && !allow_async) device_unlock(dev->parent); if (err > 0) { @@ -769,11 +773,14 @@ EXPORT_SYMBOL_GPL(bus_rescan_devices); */ int device_reprobe(struct device *dev) { + bool allow_async; + if (dev->driver) { - if (dev->parent) /* Needed for USB */ + allow_async = driver_allows_async_probing(dev->driver); + if (dev->parent && !allow_async)/* Needed for USB */ device_lock(dev->parent); device_release_driver(dev); - if (dev->parent) + if (dev->parent && !allow_async) device_unlock(dev->parent); } return bus_rescan_devices_helper(dev, NULL); diff --git a/drivers/base/dd.c b/drivers/base/dd.c index c9f54089429b..36aed1576c58 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -794,6 +794,7 @@ static int __driver_attach(struct device *dev, void *data) { struct device_driver *drv = data; int ret; + bool allow_async; /* * Lock device and try to bind to it. We drop the error @@ -817,13 +818,14 @@ static int __driver_attach(struct device *dev, void *data) return ret; } /* ret > 0 means positive match */ - if (dev->parent) /* Needed for USB */ + allow_async = driver_allows_async_probing(drv); + if (dev->parent && !allow_async)/* Needed for USB */ device_lock(dev->parent); device_lock(dev); if (!dev->driver) driver_probe_device(drv, dev); device_unlock(dev); - if (dev->parent) + if (dev->parent && !allow_async) device_unlock(dev->parent); return 0; @@ -851,19 +853,21 @@ EXPORT_SYMBOL_GPL(driver_attach); static void __device_release_driver(struct device *dev, struct device *parent) { struct device_driver *drv; + bool allow_async; drv = dev->driver; if (drv) { - if (driver_allows_async_probing(drv)) + allow_async = driver_allows_async_probing(drv); + if (allow_async) async_synchronize_full(); while (device_links_busy(dev)) { device_unlock(dev); - if (parent) + if (parent && !allow_async) device_unlock(parent); device_links_unbind_consumers(dev); - if (parent) + if (parent && !allow_async) device_lock(parent); device_lock(dev); @@ -919,7 +923,12 @@ void device_release_driver_internal(struct device *dev, struct device_driver *drv, struct device *parent) { - if (parent) + bool allow_async = false; + + if (drv) + allow_async = driver_allows_async_probing(drv); + + if (parent && !allow_async) device_lock(parent); device_lock(dev); @@ -927,7 +936,7 @@ void device_release_driver_internal(struct device *dev, __device_release_driver(dev, parent); device_unlock(dev); - if (parent) + if (parent && !allow_async) device_unlock(parent); } -- 2.17.0.441.gb46fe60e1d-goog