From patchwork Fri Jan 11 00:08:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10757073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3AD80746 for ; Fri, 11 Jan 2019 00:09:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27F4429D45 for ; Fri, 11 Jan 2019 00:09:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C6F729D4B; Fri, 11 Jan 2019 00:09:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5212929D46 for ; Fri, 11 Jan 2019 00:09:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730764AbfAKAJn (ORCPT ); Thu, 10 Jan 2019 19:09:43 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:52049 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730612AbfAKAJn (ORCPT ); Thu, 10 Jan 2019 19:09:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=CF3IJid2qFI0raopVYJxjaEmN/K4qbinFrb4gNjNeVs=; b=b22zYzvjWHh7 WNnZI0wqdnwFPa2t0xQksiQkPR0CErvp13GKxOjgLleFtcsw3t1fmq4yh4+dEIsD+Bxn35NyLfuxM SgmUxdg7GbSce90cl9YLcaccmmB6Iu73C74+wUYuwhG1he0i7FAquBltdOj4tuZKCf9cBnqRRPEWn BhtNB/fCSnVYwB7tvs9SUVWuLETdmQTgmrnHn/OpHdTJxAZUm35GlR21fvRVsMvyZSceHClpeM4fN zDPZtXCNfBu01n9SbQ79SVpi1G43Att/Ba5i5fjK6BqTNvmUATwVDRZyWpCj2SbDLBoP8cqS+mOtM JyVwZRmZBsjs9xStGNA1Pw==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1ghkOA-000Dd4-HZ; Fri, 11 Jan 2019 01:09:31 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 544ABC0C76; Fri, 11 Jan 2019 01:09:12 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Lee Duncan , Hannes Reinecke , Luis Chamberlain , Johannes Thumshirn , Christoph Hellwig , Greg Kroah-Hartman , Dan Williams Subject: [PATCH 1/8] sd: Rely on the driver core for asynchronous probing Date: Thu, 10 Jan 2019 16:08:51 -0800 Message-Id: <20190111000858.76261-2-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog In-Reply-To: <20190111000858.76261-1-bvanassche@acm.org> References: <20190111000858.76261-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.01) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5gcbwrT1n5HtkR7dWmbxuNR602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTYNm2CNnybH8Z43FgPbC84O3ZxZNfM5cTi57zK3AqpgNfTn 6SdpEMjPgzwhQ7uPL5IWShCfuV9Rj0Jpy9XFzNx6ov8sKpLeOx5g8dQO47i2LXrpjTl5ELep3+hD ATmH03oGH/YYgvV0QgfTypJwMtkIN3mjGmwv78iiqzXU/YxqpUHWFPZYohTsv5o5zESeS7iu6oqd H7oPy0kjzLpNONUeYgyqgWbfkZmQQKCujUCY2mcUbWvyjQKcyyzu8SlpYwh2PnOdSBsvBEyk6oP+ JOZedw05hLdzEHC6+IDGb/v36pUCGeLmhx53FRJAP1Ea5ASiYf7H/yBdfVu6BXKOqolT7xAqrDC6 /7DsWhDqWPbuTQTJsjWw5+0eZIpQIcK9yrSIoiC5DDnaemEOugg39OcBf2ZkFf0bc6TV99q4yFj4 jGRbN4cS9m3JKQpYnU+jEOY/WD7BAcwhXN3d5OI6tWyH6CLbyF0Zq4b1/7rjUzETJrWks4pbbQJq 6gWopI3ep45X19ZysgQ+31LcAX8eoFXAhohfegXGH2GIVQVglJFbK4kwHfB1Me6KZ/WZEd2U/PgK EgxQF7G4ajroXShVPl5s3ZFBlbFepFDIto51+D0l4QQ5Ys+fVM3O+MMiWkg2k+zlgTl6fJxyntEf hZCKje4Zr4yT9moj9LtPR5ewAVhSErI0q854skGDr1SFWz9TrEbQkE4CO4OSbq6BZA7tlM3svzio W0HZAy/J9bTIw9vYoi0algc0OEv2hoIHMMc5QHFZbPS/eVNU5HPmLAppMmniIF0L+EiBGSwjTgMJ Uw9gBr7ReBRhKYJF39mBDy0o4yOhuUNrp7FP05vH5VSt+/DeOUnMlFzHRyp04k80JGr6vsX+uFEK tCIOxIcOTnKqCuh6QNSdjxuaKs44aXfT36paehOqCvakOIunt1O8jJ+DX+l+PmxJCFvdxzgiQpci HL52w4Z4I9Sm4CLNexWS7cnKCQ52ET+y56IUaetULmjvMcjHTHbHsXKsD/8CYe6cueWFKTnk5tSD tOkxsWZnqDkrgStYx12aCdmJgllbwzHk4jQiO9qZ8HUvlDGYBjY8NoKnJR0yYYZX++hEKdoNnco5 zDg6HYuTCyYgL61SIkBTYWGbpPi0bx8ISvz9Q9saGF+esC1c5/CkleZr+iPwxlTgLz/dsiahQ1DF oGJGH4QvNFyCBdYIC7jIgUZ9aU8mEM3Y/YwX4HH5Yj6nKMh6HPtLA8eN4O9qHU4jHQlghcMYZg== X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As explained during the LSF/MM session about increasing SCSI disk probing concurrency, the problems with the current probing approach are as follows: - The driver core is unaware of asynchronous SCSI LUN probing. wait_for_device_probe() waits for all asynchronous probes except asynchronous SCSI disk probes. - There is unnecessary serialization between sd_probe() and sd_remove(). This can lead to a deadlock. Hence this patch that modifies the sd driver such that it uses the driver core framework for asynchronous probing. The async domains and get_device()/put_device() pairs that became superfluous due to this change are removed. This patch reduces the time needed for loading the scsi_debug kernel module with parameters delay=0 and max_luns=256 from 0.7s to 0.1s. In other words, this specific test runs about seven times faster. See also commit 3c31b52f96f7 ("scsi: async sd resume"). Cc: Lee Duncan Cc: Hannes Reinecke Cc: Luis Chamberlain Cc: Johannes Thumshirn Cc: Christoph Hellwig Cc: Greg Kroah-Hartman Cc: Dan Williams Signed-off-by: Bart Van Assche Reviewed-by: Hannes Reinecke --- drivers/scsi/scsi.c | 14 -------------- drivers/scsi/scsi_pm.c | 22 ++-------------------- drivers/scsi/scsi_priv.h | 3 --- drivers/scsi/sd.c | 13 +++---------- 4 files changed, 5 insertions(+), 47 deletions(-) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 7675ff0ca2ea..fd040e6ce9c3 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -85,19 +85,6 @@ unsigned int scsi_logging_level; EXPORT_SYMBOL(scsi_logging_level); #endif -/* sd, scsi core and power management need to coordinate flushing async actions */ -ASYNC_DOMAIN(scsi_sd_probe_domain); -EXPORT_SYMBOL(scsi_sd_probe_domain); - -/* - * Separate domain (from scsi_sd_probe_domain) to maximize the benefit of - * asynchronous system resume operations. It is marked 'exclusive' to avoid - * being included in the async_synchronize_full() that is invoked by - * dpm_resume() - */ -ASYNC_DOMAIN_EXCLUSIVE(scsi_sd_pm_domain); -EXPORT_SYMBOL(scsi_sd_pm_domain); - /** * scsi_put_command - Free a scsi command block * @cmd: command block to free @@ -836,7 +823,6 @@ static void __exit exit_scsi(void) scsi_exit_devinfo(); scsi_exit_procfs(); scsi_exit_queue(); - async_unregister_domain(&scsi_sd_probe_domain); } subsys_initcall(init_scsi); diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c index a2b4179bfdf7..46a2746618cc 100644 --- a/drivers/scsi/scsi_pm.c +++ b/drivers/scsi/scsi_pm.c @@ -55,9 +55,6 @@ static int scsi_dev_type_suspend(struct device *dev, const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; int err; - /* flush pending in-flight resume operations, suspend is synchronous */ - async_synchronize_full_domain(&scsi_sd_pm_domain); - err = scsi_device_quiesce(to_scsi_device(dev)); if (err == 0) { err = cb(dev, pm); @@ -150,18 +147,7 @@ static int scsi_bus_resume_common(struct device *dev, if (scsi_is_sdev_device(dev) && pm_runtime_suspended(dev)) blk_set_runtime_active(to_scsi_device(dev)->request_queue); - if (fn) { - async_schedule_domain(fn, dev, &scsi_sd_pm_domain); - - /* - * If a user has disabled async probing a likely reason - * is due to a storage enclosure that does not inject - * staggered spin-ups. For safety, make resume - * synchronous as well in that case. - */ - if (strncmp(scsi_scan_type, "async", 5) != 0) - async_synchronize_full_domain(&scsi_sd_pm_domain); - } else { + if (!fn) { pm_runtime_disable(dev); pm_runtime_set_active(dev); pm_runtime_enable(dev); @@ -171,11 +157,7 @@ static int scsi_bus_resume_common(struct device *dev, static int scsi_bus_prepare(struct device *dev) { - if (scsi_is_sdev_device(dev)) { - /* sd probing uses async_schedule. Wait until it finishes. */ - async_synchronize_full_domain(&scsi_sd_probe_domain); - - } else if (scsi_is_host_device(dev)) { + if (scsi_is_host_device(dev)) { /* Wait until async scanning is finished */ scsi_complete_async_scans(); } diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h index 5f21547b2ad2..b1edf15704c0 100644 --- a/drivers/scsi/scsi_priv.h +++ b/drivers/scsi/scsi_priv.h @@ -174,9 +174,6 @@ static inline int scsi_autopm_get_host(struct Scsi_Host *h) { return 0; } static inline void scsi_autopm_put_host(struct Scsi_Host *h) {} #endif /* CONFIG_PM */ -extern struct async_domain scsi_sd_pm_domain; -extern struct async_domain scsi_sd_probe_domain; - /* scsi_dh.c */ #ifdef CONFIG_SCSI_DH void scsi_dh_add_device(struct scsi_device *sdev); diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index c6ca3d915925..c2ddb697fa90 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -561,6 +561,7 @@ static struct scsi_driver sd_template = { .name = "sd", .owner = THIS_MODULE, .probe = sd_probe, + .probe_type = PROBE_PREFER_ASYNCHRONOUS, .remove = sd_remove, .shutdown = sd_shutdown, .pm = &sd_pm_ops, @@ -3278,12 +3279,8 @@ static int sd_format_disk_name(char *prefix, int index, char *buf, int buflen) return 0; } -/* - * The asynchronous part of sd_probe - */ -static void sd_probe_async(void *data, async_cookie_t cookie) +static void sd_probe_part2(struct scsi_disk *sdkp) { - struct scsi_disk *sdkp = data; struct scsi_device *sdp; struct gendisk *gd; u32 index; @@ -3337,7 +3334,6 @@ static void sd_probe_async(void *data, async_cookie_t cookie) sd_printk(KERN_NOTICE, sdkp, "Attached SCSI %sdisk\n", sdp->removable ? "removable " : ""); scsi_autopm_put_device(sdp); - put_device(&sdkp->dev); } /** @@ -3429,8 +3425,7 @@ static int sd_probe(struct device *dev) get_device(dev); dev_set_drvdata(dev, sdkp); - get_device(&sdkp->dev); /* prevent release before async_schedule */ - async_schedule_domain(sd_probe_async, sdkp, &scsi_sd_probe_domain); + sd_probe_part2(sdkp); return 0; @@ -3465,8 +3460,6 @@ static int sd_remove(struct device *dev) devt = disk_devt(sdkp->disk); scsi_autopm_get_device(sdkp->device); - async_synchronize_full_domain(&scsi_sd_pm_domain); - async_synchronize_full_domain(&scsi_sd_probe_domain); device_del(&sdkp->dev); del_gendisk(sdkp->disk); sd_shutdown(dev);