From patchwork Wed Oct 17 23:40:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10646597 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 64DF313A4 for ; Wed, 17 Oct 2018 23:40:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B8272874E for ; Wed, 17 Oct 2018 23:40:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FEBF28897; Wed, 17 Oct 2018 23:40:32 +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 AC264288D7 for ; Wed, 17 Oct 2018 23:40:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727214AbeJRHig (ORCPT ); Thu, 18 Oct 2018 03:38:36 -0400 Received: from com-out001.mailprotect.be ([83.217.72.83]:43695 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726706AbeJRHif (ORCPT ); Thu, 18 Oct 2018 03:38:35 -0400 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=T1+LWYUnF66URgGOVn2NwZGDPo5DEtR1WUhbB0JYqfI=; b=rXVuuAdmeDOw wmX7mkY8T++Y+AlDf13CQqoFbzjhFvOgB5VLRCymxpGbgOfF8zRp5vHwMDqn7y5MSkpLu5F/qCt/X ZUfVtt5ADkWFaIfDhvsIGl/m8ILgJmiSxXw2odCckznkmqsmQzZ9S1HvifMTr+R90h45Styqt6Max 2TzXZezghYDSPeDZ8Ik984TAVcFF1UHzkVBH93AUH0oV4TuGZym3j1FDnsHr31I/3HaGxu/kYelJR ES3A5ZydSEOFN4bYQQroNhYOszibeB47c82F8jpXYTFhimzpmFzcwcw+uBPAAhmir0vMHXzomQvtv fYZDUnvfyuOf5NHymtbH4Q==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gCvQK-000Afw-6E; Thu, 18 Oct 2018 01:40:20 +0200 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 DE332C0859; Thu, 18 Oct 2018 01:40:16 +0200 (CEST) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: Greg Kroah-Hartman , linux-scsi@vger.kernel.org, Bart Van Assche , Lee Duncan , Hannes Reinecke , Luis Chamberlain , Johannes Thumshirn , Christoph Hellwig Subject: [PATCH v2 1/7] drivers/base: Fix a race condition in the device probing code Date: Wed, 17 Oct 2018 16:40:00 -0700 Message-Id: <20181017234006.124251-2-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog In-Reply-To: <20181017234006.124251-1-bvanassche@acm.org> References: <20181017234006.124251-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.06) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5gM+BMusl1fNsTKcwtjBpUR602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTbYPg/zpkSiMTw4RmnfxRCXFU82axTVwUv6v8rWwOPbn8ST Ksl9SxC91yR06AZxhKQie9+9sv+uW/xhFRf3rOAhFEAZ5tLgtxeh4W43PRo1gyVBZhJdB8oBIQVB HyeF+GyojOI3mdswqRrDTMbSijPikzUjpLbYv+k6wc7gZffRufoNd/18byQB0A6J7qtkYo2nkoP/ 7uxT5ANOZNNW1Q/z0yLvsMb+uiAAjdbSeQ5TrAFR//DqOZ7gBtaFV3NEPd9B3ylJDm+BpEBBclKF yxopgN4JfSdG4+vA3R3fKJCA/m/fDy/eqb5U4J5qWPtxGNT8UNjk+0VVJuuJ6UclkUP1yrccvRl7 LodRnoQ8/VwOaw+gz/ZKpG7S9PROnRo5n5UgtCujFgev91YjBSdZpRhe7INkM1D8D0wcffXFPtzu Go+eFJImtabaGYRoWdcAtjCcAuDIQf0tklPcA7SYKMcZaFryuM28yfNoRiP4LXR95v/77cCko/EG 7+7uLxBlLaVvfCJf9c87raNJ3rEEAH2+T1zD59o8cPYKs494BBiYWZDfGiqYJbsV6Bia58mKB6GP R9UyIYODc1wVguED8Bfu31/E3ahF5MMcDI7KdpjQKcwi9Jk69TnSHoh9VM4qIjsvP92yJqFDUMWg YkYfhC80sNoIrLcCnn2MFoRBwXu4i9adXN8QoJkCGUT+/nq62lQ14TiNHZBO9dkjkpbpFG8w6J1f hOzjF0b4LXcjJZ5los8zrNGe+tDeZB+wTvpsxUvvc2Dse4DtQMNd1OJpSyWybRqfHFHrLyjfsdgn 265aK0cV0wEj9itRcd7KH+nVDjFllXn2maRqR4xJOvVleQ85XMfPU/A6Zs85EHjl8kedTQDBddgS itHw/K1calPLDDrKATDDBZ7fFc0FDw0l2bg+z2YoA4glpLgakSw0zRVimCD6xzPYw/AK3RKDkQrn i3PmNNJakcQ7oiAjewX2ETzsyB2oVjwpD0SDGnhQZ7XpT35mKiWY4qyAovTKsLgKiJqTF6ymUAav ae3aV27dM5QN3KVLwP/pKIIHQBh4yd/8+tEyvDkN3AfUBddcu9g0Uhw/YHGGdt5eD9ya81kvI1of 3IOsrfnTjx5M5ZqkPpQBrM2wWVbjHO/cpJpsYlvFhM+mW297Uqw0ZsTjLTJBUO9GfzrLxVhP0uel tSacMfCNTlvBloR44kmvlvy5XDsjxS0= 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 This patch avoids that complaints similar to the following appear in the system log: sysfs: cannot create duplicate filename '/devices/pseudo_0/adapter0/host3/target3:0:0/3:0:0:133/driver' Cc: Lee Duncan Cc: Hannes Reinecke Cc: Luis Chamberlain Cc: Johannes Thumshirn Cc: Christoph Hellwig Cc: Greg Kroah-Hartman Signed-off-by: Bart Van Assche --- drivers/base/dd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index edfc9f0b1180..b4212154a94b 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -645,6 +645,14 @@ int driver_probe_device(struct device_driver *drv, struct device *dev) { int ret = 0; + /* + * Several callers check the driver pointer without holding the + * device mutex. Hence check the driver pointer again while holding + * the device mutex. + */ + if (dev->driver) + return dev->driver == drv; + if (!device_is_registered(dev)) return -ENODEV; From patchwork Wed Oct 17 23:40:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10646599 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 9238C157A for ; Wed, 17 Oct 2018 23:40:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 857E428897 for ; Wed, 17 Oct 2018 23:40:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83B9728884; Wed, 17 Oct 2018 23:40:33 +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 0FEE4288D0 for ; Wed, 17 Oct 2018 23:40:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727246AbeJRHih (ORCPT ); Thu, 18 Oct 2018 03:38:37 -0400 Received: from com-out001.mailprotect.be ([83.217.72.83]:38135 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727196AbeJRHih (ORCPT ); Thu, 18 Oct 2018 03:38:37 -0400 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=IyfC0dGIa2uUhrTB2Pm4I6ZpcGqIqBoAXnCPBpmQqGU=; b=Idb/4AkPk1rF Q683O4779fyN9OcpmZYfgUq3AHDGxnPev9EKZTnHTbQfKFJZcEkDwBg5xQci2opxAIEfH8LhT35+x tStabGP+AI2uvLscjxBZ6/44nxUsRYaMtQHfcQ43ByvLVkN46yTZemKzuyave8mkWsuEmYorefFTn lRwF+OZWXpIZ3sPSxZOHxzNvYc0KNMUzYnjqROspy+vt3HfQwSwKeZ4ZvWNKw77YvZVPkPuPqvRC4 7Ii4y8r8buwjoLpgl5oePMPF8J8jFBsqPPbAT2pBV+dEFqaxVz5HdEpSm68LkK147//ND0FFvPM2V R2O4RpsYjnHr2AXu5cJ51g==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gCvQM-000AgP-F2; Thu, 18 Oct 2018 01:40:23 +0200 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 60FD4C06CF; Thu, 18 Oct 2018 01:40:19 +0200 (CEST) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: Greg Kroah-Hartman , linux-scsi@vger.kernel.org, Bart Van Assche , Lee Duncan , Hannes Reinecke , Luis Chamberlain , Johannes Thumshirn , Christoph Hellwig Subject: [PATCH v2 2/7] drivers/base: Verify struct device locking requirements at runtime Date: Wed, 17 Oct 2018 16:40:01 -0700 Message-Id: <20181017234006.124251-3-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog In-Reply-To: <20181017234006.124251-1-bvanassche@acm.org> References: <20181017234006.124251-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: EX5BVjFpneJeBchSMxfU5vIbrM+d/jFalTtu6ulVlPB602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTbYPg/zpkSiMTw4RmnfxRCXFU82axTVwUv6v8rWwOPbn8ST Ksl9SxC91yR06AZxhKQie9+9sv+uW/xhFRf3rOAhFEAZ5tLgtxeh4W43PRo1gyVBZhJdB8oBIQVB HyeF+GyojOI3mdswqRrDTMbSijPikzUjpLbYv+k6wc7gZffRufoNd/18byQB0A6J7qtkYo2nkoP/ 7uxT5ANOZNNW1Q/z0yLvsMb+uiAAjdbSeQ5TrAFR//DqOZ7gBtaFV3NEPd9B3ylJDm+BpEBBclKF yxopgN4JfSdG4+vA3R3fKJCA/m/fDy/eqb5U4J5qWPtxGNTHZL40IvuMcLdEcWBgYVpZyrccvRl7 LodRnoQ8/VwOaw+gz/ZKpG7S9PROnRo5n5UgtCujFgev91YjBSdZpRhe7INkM1D8D0wcffXFPtzu Go+eFJImtabaGYRoWdcAtjCcAuDIQf0tklPcA7SYKMcZaFryuM28yfNoRiP4LXR95v/77cCko/EG 7+7uLxBlLaVvfCJf9c87raNJ3rEEAH2+T1zD59o8cPYKs494BBiYWZDfGiqYJbsV6Bia58mKB6GP R9UyIYODc1wVguED8Bfu31/E3ahF5MMcDI7KdpjQKcwi9Jk69TnSHoh9VM4qIjsvP92yJqFDUMWg YkYfhC80sNoIrLcCnn2MFoRBwXu4i9adXN8QoJkCGUT+/nq62lQ14TiNHZBO9dkjkpbpFG8w6J1f hOzjF0b4LXcjJZ5los8zrNGe+tDeZB+wTvpsxUvvc2Dse4DtQMNd1OJpSyWys1UCfpu9+z+1+3yu +Wf7WUcV0wEj9itRcd7KH+nVDjFllXn2maRqR4xJOvVleQ85XMfPU/A6Zs85EHjl8kedTQDBddgS itHw/K1calPLDDrKATDDBZ7fFc0FDw0l2bg+z2YoA4glpLgakSw0zRVimOgT1/CexBu0X11IJ9Ie /J4rN6h0fxYceWTXeaH3ckIPyB2oVjwpD0SDGnhQZ7XpT35mKiWY4qyAovTKsLgKiJqTF6ymUAav ae3aV27dM5QN3KVLwP/pKIIHQBh4yd/8+tEyvDkN3AfUBddcu9g0Uhw/YHGGdt5eD9ya81kvI1of 3IOsrfnTjx5M5ZqkPpQBrM2wWVbjHO/cpJpsYlvFhM+mW297Uqw0ZsTjLTJBUO9GfzrLxVhP0uel tSacMfCNTlvBloR44kmvlvy5XDsjxS0= 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 Make sure that a complaint appears in the kernel log if the driver core locking assumptions are violated. Cc: Lee Duncan Cc: Hannes Reinecke Cc: Luis Chamberlain Cc: Johannes Thumshirn Cc: Christoph Hellwig Cc: Greg Kroah-Hartman Signed-off-by: Bart Van Assche --- drivers/base/dd.c | 16 ++++++++++++++++ drivers/base/memory.c | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index b4212154a94b..033382421351 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -315,11 +315,15 @@ __exitcall(deferred_probe_exit); */ bool device_is_bound(struct device *dev) { + lockdep_assert_held(&dev->mutex); + return dev->p && klist_node_attached(&dev->p->knode_driver); } static void driver_bound(struct device *dev) { + lockdep_assert_held(&dev->mutex); + if (device_is_bound(dev)) { printk(KERN_WARNING "%s: device %s already bound\n", __func__, kobject_name(&dev->kobj)); @@ -363,6 +367,8 @@ static int driver_sysfs_add(struct device *dev) { int ret; + lockdep_assert_held(&dev->mutex); + if (dev->bus) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, BUS_NOTIFY_BIND_DRIVER, dev); @@ -421,6 +427,8 @@ int device_bind_driver(struct device *dev) { int ret; + lockdep_assert_held(&dev->mutex); + ret = driver_sysfs_add(dev); if (!ret) driver_bound(dev); @@ -450,6 +458,8 @@ static int really_probe(struct device *dev, struct device_driver *drv) bool test_remove = IS_ENABLED(CONFIG_DEBUG_TEST_DRIVER_REMOVE) && !drv->suppress_bind_attrs; + lockdep_assert_held(&dev->mutex); + if (defer_all_probes) { /* * Value of defer_all_probes can be set only by @@ -589,6 +599,8 @@ static int really_probe_debug(struct device *dev, struct device_driver *drv) ktime_t calltime, delta, rettime; int ret; + lockdep_assert_held(&dev->mutex); + calltime = ktime_get(); ret = really_probe(dev, drv); rettime = ktime_get(); @@ -645,6 +657,8 @@ int driver_probe_device(struct device_driver *drv, struct device *dev) { int ret = 0; + lockdep_assert_held(&dev->mutex); + /* * Several callers check the driver pointer without holding the * device mutex. Hence check the driver pointer again while holding @@ -932,6 +946,8 @@ static void __device_release_driver(struct device *dev, struct device *parent) { struct device_driver *drv; + lockdep_assert_held(&dev->mutex); + drv = dev->driver; if (drv) { if (driver_allows_async_probing(drv)) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index c8a1cb0b6136..41a8454dabb5 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -283,6 +283,8 @@ static int memory_subsys_online(struct device *dev) struct memory_block *mem = to_memory_block(dev); int ret; + lockdep_assert_held(&dev->mutex); + if (mem->state == MEM_ONLINE) return 0; @@ -307,6 +309,8 @@ static int memory_subsys_offline(struct device *dev) { struct memory_block *mem = to_memory_block(dev); + lockdep_assert_held(&dev->mutex); + if (mem->state == MEM_OFFLINE) return 0; From patchwork Wed Oct 17 23:40:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10646601 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 84A8C157A for ; Wed, 17 Oct 2018 23:40:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75891288D0 for ; Wed, 17 Oct 2018 23:40:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6757A288D2; Wed, 17 Oct 2018 23:40:40 +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 E4BDA2886E for ; Wed, 17 Oct 2018 23:40:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727253AbeJRHio (ORCPT ); Thu, 18 Oct 2018 03:38:44 -0400 Received: from com-out001.mailprotect.be ([83.217.72.83]:46441 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727196AbeJRHio (ORCPT ); Thu, 18 Oct 2018 03:38:44 -0400 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=hZy4Y3S5mpmGL40z0C9r2ScWz8pJ+lEmeb8abgmA+kY=; b=R/tg1bgGHRtD 2Zkvf5cNDELTLU2lNh0QfEEB+28/oxky7IToD2dcnBEKksJAh5uwhm5vx7+g/OnTLp6Htkz4AUxXQ M+MCCSn5LYZ4AOkBt6jq9MVB5yidcqgyMCUGCAAteNxkL6t7/ZTeIjzsBZ2XqAtmyC+uW9ZzhhyXk ZESZEPJ2bygKcG+Ef2lIYsgXHavmQMGmALcsPbpHUKDaa2LkFeKTdhS3X8Osg6h2I4IOuqD1lBN3p btoKihIw3rYsctpFxo1QEZkOEx88zzK7rXAal/4kMallcUIKAiDD7WW5aG2JbSmauduUm/YhvrHY6 cjw1bx1gObMFoNB0+JjcrA==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gCvQQ-000Aga-Ij; Thu, 18 Oct 2018 01:40:27 +0200 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 A5272C0859; Thu, 18 Oct 2018 01:40:21 +0200 (CEST) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: Greg Kroah-Hartman , linux-scsi@vger.kernel.org, Bart Van Assche , Lee Duncan , Hannes Reinecke , Luis Chamberlain , Johannes Thumshirn , Christoph Hellwig , Dan Williams Subject: [PATCH v2 3/7] drivers/base: Probe devices concurrently if requested by the driver Date: Wed, 17 Oct 2018 16:40:02 -0700 Message-Id: <20181017234006.124251-4-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog In-Reply-To: <20181017234006.124251-1-bvanassche@acm.org> References: <20181017234006.124251-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: SB/global_tokens (0.00236273624828) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5vdKoF50dk5Pmr2Eh0KaytJ602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTYNm2CNnybH8Z43FgPbC84O3ZxZNfM5cTi57zK3AqpgNfTn 6SdpEMjPgzwhQ7uPL5IWShCfuV9Rj0Jpy9XFzNx6ov8sKpLeOx5g8dQO47i2LXrpjTl5ELep3+hD ATmH03oGH/YYgvV0QgfTypJwMtkIN3mjGmwv78iiqzXU/YxqpUHWFPZYohTsv5o5zESeS7iu6oqd H7oPy0kjzLpNONUeYgyqgWbfkZmQQKCujUCY2mcUbWvyjQKcyyzu8SlpYwh2PnOdSBsvBEyk6oP+ JOZedw05hLdzEHC6+IDGb/v36pUCGeLmhx53FRJAP1Ea5ASiYf7H/yBdfVu6BXKOqolT9GfkLnpI 7Igpgzj0Fi/1kgTJsjWw5+0eZIpQIcK9yrSIoiC5DDnaemEOugg39OcBf2ZkFf0bc6TV99q4yFj4 jO7J//0XCxCMJn8bXo41UD0/WD7BAcwhXN3d5OI6tWyH6CLbyF0Zq4b1/7rjUzETJsEY2Io8tF+w JOqGSVax9Cm77niqGZoB5oiisgnJ8hVNJmO4hZrKar0rT3Fu0bhVQ+HVicDfSEki2HQjIzlgulSP bUMSEuFskSoX1rj3Ja6Rz+WIuiLxESilKevuzi8w8V+7HpiXZfFnrsvPrZTEk0NuHNilgcZwLgpa NcLUv7N+wU0sgWWGfvhiumCReJl2fvxcb3XRuJkRyiZZ6HPi7yzMODodi5MLJiAvrVIiQFNhU2e0 TG7gZrtHlR0mmB20Dn0dxFvNNB6n+asAMTtBlzFO/QhyCWC6YCpHNN+dHzcfet9WYpMedYGCnu86 NSYSBriPncBxOEAOQ+52ichbKZqDvZACTpnyVEv7sKwJuf990SV26BqP2cLMwD5eyGrPr/vYRygQ QDw2W1RvRSdcITq04npcDlKcRm8K6UCxnm/d1MHoSYXOgussFKMYrtx189kFIATR8ubvlbl2kpwD bZ3BRBZgCikvOAMF/4pY8933dflf9ntDT37Pcm6lRUBH+WE2OtkGzrUVx52MHuYfPexSk4m5wK8d LOpEo90vBDAk+W1qXhB/kaRrSe/aWhy/zVLO3HfZT/t5PEHawBxJ5/TDqcigOvSxdRnthmhn8Zn6 y90Pz+6rbRCCi63kWHnKnm/+2uO3if45J37r4Xo66cneNHk15VolAGHS5rCXQKDyo2+ZkN3FA6qI /fawoJjK3LI0q854skGDr1SFWz9TrEYi+VTf4Ti2TC8/avI4GsQ15Vr/WU32hkVKCE63DG45yXMD yokpY5MTUUWEH458+tw= 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 Instead of probing devices sequentially in the PROBE_PREFER_ASYNCHRONOUS mode, scan devices concurrently. This helps when the wall clock time for a single probe is significantly above the CPU time needed for a single probe, e.g. when scanning SCSI LUNs over a storage network. 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 --- drivers/base/bus.c | 3 +-- drivers/base/dd.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 8bfd27ec73d6..18ca1178821f 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -696,8 +696,7 @@ int bus_add_driver(struct device_driver *drv) out_unregister: kobject_put(&priv->kobj); - /* drv->p is freed in driver_release() */ - drv->p = NULL; + out_put_bus: bus_put(bus); return error; diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 033382421351..f8d645aa09be 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "base.h" #include "power/power.h" @@ -691,6 +692,49 @@ int driver_probe_device(struct device_driver *drv, struct device *dev) return ret; } +struct driver_and_dev { + struct device_driver *drv; + struct device *dev; +}; + +static void __driver_probe_device_async(void *data, async_cookie_t cookie) +{ + struct driver_and_dev *dd = data; + struct device_driver *drv = dd->drv; + struct device *dev = dd->dev; + + device_lock(dev); + driver_probe_device(drv, dev); + device_unlock(dev); + kobject_put(&drv->p->kobj); + module_put(drv->owner); + kfree(dd); +} + +static void driver_probe_device_async(struct device_driver *drv, + struct device *dev) +{ + struct driver_and_dev *dd; + + if (!try_module_get(drv->owner)) + return; + dd = kmalloc(sizeof(*dd), GFP_KERNEL); + if (!dd) { + /* If out of memory, scan synchronously. */ + device_lock(dev); + driver_probe_device(drv, dev); + device_unlock(dev); + module_put(drv->owner); + return; + } + *dd = (struct driver_and_dev){ + .drv = drv, + .dev = dev, + }; + kobject_get(&drv->p->kobj); + async_schedule(__driver_probe_device_async, dd); +} + bool driver_allows_async_probing(struct device_driver *drv) { switch (drv->probe_type) { @@ -777,6 +821,11 @@ static int __device_attach_driver(struct device_driver *drv, void *_data) if (data->check_async && async_allowed != data->want_async) return 0; + if (data->check_async) { + driver_probe_device_async(drv, dev); + return 0; + } + return driver_probe_device(drv, dev); } From patchwork Wed Oct 17 23:40:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10646607 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 242D53C13 for ; Wed, 17 Oct 2018 23:40:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15DD5285F2 for ; Wed, 17 Oct 2018 23:40:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07336288CF; Wed, 17 Oct 2018 23:40:55 +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 CEF5428893 for ; Wed, 17 Oct 2018 23:40:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727253AbeJRHi7 (ORCPT ); Thu, 18 Oct 2018 03:38:59 -0400 Received: from out002.mailprotect.be ([83.217.72.86]:40239 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727175AbeJRHi7 (ORCPT ); Thu, 18 Oct 2018 03:38:59 -0400 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=q+qIdieIZ5qyRzkNOTSukKaBqLei9azppFKJUjUGN3c=; b=ZTwXcFrYRm8v pSd1HiDCCxnjlru2YroUzDJKNQmae0lUOgc5kbtvhUz+2jIJjnXJ6ZWGzxSZ37xi/JmH/b2AwG5Sm J/QILgqbb2B+rM0ypwp9LNVIsRmrz0DFlvW9sLJ33MculF9h2tyVAeoU424OCSiHI8Lu6yzCScqqx CcqHprpEysIFlFBak7qlIfBUQaOmwTZzKFCGB8XKvaNIGWLTq6dhvxVWLkU+ghRJhdi2YjNw4phf2 nPpbNWh18rBZTo4/7W6ggDigZhkwQjb1NwJgamOm/41uRrdnF3c44HV/POmztqkiAdPpNSJjNVfRA BmlDZQLhV7S+s1cLGZx82g==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gCvQg-000D3I-G9; Thu, 18 Oct 2018 01:40:43 +0200 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 16188C06B7; Thu, 18 Oct 2018 01:40:23 +0200 (CEST) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: Greg Kroah-Hartman , linux-scsi@vger.kernel.org, Bart Van Assche , Lee Duncan , Hannes Reinecke , Luis Chamberlain , Johannes Thumshirn , Christoph Hellwig Subject: [PATCH v2 4/7] drivers/base, __device_release_driver(): Do not wait for asynchronous probing Date: Wed, 17 Oct 2018 16:40:03 -0700 Message-Id: <20181017234006.124251-5-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog In-Reply-To: <20181017234006.124251-1-bvanassche@acm.org> References: <20181017234006.124251-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.04) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5ml9eUB9DDXe9CT+BJmOD7p602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTbYPg/zpkSiMTw4RmnfxRCXFU82axTVwUv6v8rWwOPbn8ST Ksl9SxC91yR06AZxhKQie9+9sv+uW/xhFRf3rOAhFEAZ5tLgtxeh4W43PRo1gyVBZhJdB8oBIQVB HyeF+GyojOI3mdswqRrDTMbSijPikzUjpLbYv+k6wc7gZffRufoNd/18byQB0A6J7qtkYo2nkoP/ 7uxT5ANOZNNW1Q/z0yLvsMb+uiAAjdbSeQ5TrAFR//DqOZ7gBtaFV3NEPd9B3ylJDm+BpEBBclKF yxopgN4JfSdG4+vA3R3fKJCA/m/fDy/eqb5U4J5qWPtxGNTs+ee45CKjCUs1S8nYM4EQyrccvRl7 LodRnoQ8/VwOaw+gz/ZKpG7S9PROnRo5n5USQWn9OYmU74xfbcEYge/f7INkM1D8D0wcffXFPtzu Go+eFJImtabaGYRoWdcAtjCcAuDIQf0tklPcA7SYKMcZaFryuM28yfNoRiP4LXR95v/77cCko/EG 7+7uLxBlLaVvfCJf9c87raNJ3rEEAH2+T1zD59o8cPYKs494BBiYWZDfGiqYJbsV6Bia58mKB6GP R9UyIYODc1wVguED8Bfu31/E3ahF5MMcDI7KdpjQKcwi9Jk69TnSHoh9VM4qIjsvP92yJqFDUMWg YkYfhC80sNoIrLcCnn2MFoRBwXu4i9adXN8QoJkCGUT+/nq62lQ14TiNHZBO9dkjkpbpFG8w6J1f hOzjF0b4LXcjJZ5loquFk+pkh+w6U8HrQHUPSWrvc2Dse4DtQMNd1OJpSyWyQnh/kQTWargBlegu JyyioEcV0wEj9itRcd7KH+nVDjFllXn2maRqR4xJOvVleQ85XMfPU/A6Zs85EHjl8kedTQDBddgS itHw/K1calPLDDrKATDDBZ7fFc0FDw0l2bg+z2YoA4glpLgakSw0zRVimFZZLnlzJNjoM9o1R1rc vo3QJ+IRuv3GmkX8LPVuVC3UyB2oVjwpD0SDGnhQZ7XpT35mKiWY4qyAovTKsLgKiJqTF6ymUAav ae3aV27dM5QN3KVLwP/pKIIHQBh4yd/8+tEyvDkN3AfUBddcu9g0Uhw/YHGGdt5eD9ya81kvI1of 3IOsrfnTjx5M5ZqkPpQBrM2wWVbjHO/cpJpsYlvFhM+mW297Uqw0ZsTjLTJBUO9GfzrLxVhP0uel tSacMfCNTlvBloR44kmvlvy5XDsjxS0= 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 Since __device_release_driver() is called with the device lock held and since the same device lock is obtained by the functions that perform asynchronous probing (driver_attach_async() and __device_attach_async_helper()), asynchronous probing is already serialized against __device_release_driver(). Remove the async_synchronize_full() call from __device_release_driver() to avoid that a deadlock is triggered. Fixes: 765230b5f084 ("driver-core: add asynchronous probing support for drivers"). Acked-by: Dmitry Torokhov Cc: Lee Duncan Cc: Hannes Reinecke Cc: Luis Chamberlain Cc: Johannes Thumshirn Cc: Christoph Hellwig Cc: Greg Kroah-Hartman Signed-off-by: Bart Van Assche --- drivers/base/dd.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index f8d645aa09be..0a3c9f8702de 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -999,9 +999,6 @@ static void __device_release_driver(struct device *dev, struct device *parent) drv = dev->driver; if (drv) { - if (driver_allows_async_probing(drv)) - async_synchronize_full(); - while (device_links_busy(dev)) { device_unlock(dev); if (parent) From patchwork Wed Oct 17 23:40:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10646603 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 E555913A4 for ; Wed, 17 Oct 2018 23:40:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8E2E28893 for ; Wed, 17 Oct 2018 23:40:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCC812881A; Wed, 17 Oct 2018 23:40:45 +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 45E782888A for ; Wed, 17 Oct 2018 23:40:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727262AbeJRHit (ORCPT ); Thu, 18 Oct 2018 03:38:49 -0400 Received: from com-out001.mailprotect.be ([83.217.72.83]:46427 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727196AbeJRHis (ORCPT ); Thu, 18 Oct 2018 03:38:48 -0400 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=xZWmhAfUjps7peTMTKkpwkFObl7lK0KRmkbAIIF3pUk=; b=mT9prlZ+0oLm u4myS5PDjb3vBm/qmPJEA63N6SaOYBVoXjwNJ9Dm8ZVrlOME/B0KrfahDCrBghUb4LUYCQklXkpBM ZRjhyW1XgO1l3nATc8ND339YqUVSA8EO4M6wK71CrqYYbWxPanH8jddoFTuS02umajMRzt/s2fIsX +ZruIWypU3m0iSBcFVbYSlEwK33eQ3aRCNqdUBvpkOabu1WiYcYsUMWOrqVCWnBtgBcUo61K2MzXj xcV0ah50RzwdfOZgMiKfgoCGeJ4n9WwRnH/L/gKPSefzig2niZi+Bh5FqIfM3I0QM6QKP7sLziXRy 2Eba1D9lJ619khLgIFTwDg==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gCvQT-000AgP-Qp; Thu, 18 Oct 2018 01:40:30 +0200 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 4F721C06CF; Thu, 18 Oct 2018 01:40:26 +0200 (CEST) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: Greg Kroah-Hartman , linux-scsi@vger.kernel.org, Bart Van Assche , Lee Duncan , Hannes Reinecke , Luis Chamberlain , Johannes Thumshirn , Christoph Hellwig , Dan Williams , stable@vger.kernel.org Subject: [PATCH v2 5/7] sd: Avoid that hibernation triggers a kernel warning Date: Wed, 17 Oct 2018 16:40:04 -0700 Message-Id: <20181017234006.124251-6-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog In-Reply-To: <20181017234006.124251-1-bvanassche@acm.org> References: <20181017234006.124251-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: SB/global_tokens (0.009594143917) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5qlBwnhWqtehzElJIgmyQQd602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTYNm2CNnybH8Z43FgPbC84O3ZxZNfM5cTi57zK3AqpgNfTn 6SdpEMjPgzwhQ7uPL5IWShCfuV9Rj0Jpy9XFzNx6ov8sKpLeOx5g8dQO47i2LXrpjTl5ELep3+hD ATmH03oGH/YYgvV0QgfTypJwMtkIN3mjGmwv78iiqzXU/YxqpUHWFPZYohTsv5o5zESeS7iu6oqd H7oPy0kjzLpNONUeYgyqgWbfkZmQQKCujUCY2mcUbWvyjQKcyyzu8SlpYwh2PnOdSBsvBEyk6oP+ JOZedw05hLdzEHC6+IDGb/v36pUCGeLmhx53FRJAP1Ea5ASXozZWvOq7/lzcIrFAbAq19Wrt/oF2 ofKYeezPZTW+uAalYWA4nnQMwa+/md1Jf+J9Ga9nqe5rr63xa7zQu0+0FfVCTEILqGVovccflXpx +fg3CKX09/MzS0rEiVixyzHa6yqyQF+H2As0G8RVWSCOiTaS+9n8WE1Y7K/JLhDDsDYzgnMJz/9H pbKfTERrj+BspFS7A/1PFTncn77/+ZqDoMChHB0S+sP4TQZXFi/lRByWwivjTmT6P1lHM+NIsbhf tOZqtI9cgrR+tgS+RRF4FrkiZ1f0lzZs/vSNj0hOyuhdevnTtDLp/PjSQR66Oi3gTjj2FUsrgVdG LSrx7oPt3FtekKBuIoGwD4N2LqZrB6nqKatjQpXXJ4kbVmWQW1DriHckHGu9Lyf5e/woa/nVTvns qJRjOJfK5cbhn4VPt1DBqSq2/YL3vElg8bQzvJffqjJtNmkHha/oSXJNlTxzxMlHBG/DYARUPbpb cZAOJc7u6MZ0JA+gBrTb8cbNipHb6WeYomLR/aGqZWyMscINMhb84jtK0p6yWNiIzBz7pfNjJPKZ H7A6vJ2MFQnp5x1mGP48AZJt1rFvmbNr7pOhQUae8pUmcVBBoCcOJxc4HUUCX6spe1jbbSG/WuM8 PBsXtzm7aNjCud2so9sFlpfWkybNYmBNw2nvSnaifocwwtEyvDkN3AfUBddcu9g0UhyiCb2MlFyJ Dbr15votsPUsFggZi3EkWTlHrw/XeattdADm3IkHus1KJdLlVEWX697Kep4sbb/eH7sIHDPI7Vhn 4PCr7z8ShfHSk7QkzdXEFjPHPxbEXVO0XLmZkIMU99HKATDDBZ7fFc0FDw0l2bg+uy5d/sAhazOy rD7BKivmVB9+oFMMhiNhviIa1CUp5UOkASe0zzIoSVH5jzhBWWlj91p/N1gxMbxdAh/YOdmDwsA3 9QrhLkqREK5PnlEc5EfmWLNVRopVQ2QSjOQ8Ng3p 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 Although the power management code never calls the system-wide and runtime suspend callbacks concurrently, runtime power state changes can happen while the system is being suspended or resumed. See also the dpm_suspend() and dpm_resume() calls in hibernation_snapshot(). Make sure the sd driver supports this. This patch avoids that the following call trace is reported during system-wide suspend: WARNING: CPU: 0 PID: 701 at drivers/scsi/scsi_lib.c:3047 scsi_device_quiesce+0x4b/0xd0 Workqueue: events_unbound async_run_entry_fn RIP: 0010:scsi_device_quiesce+0x4b/0xd0 Call Trace: scsi_bus_suspend_common+0x71/0xe0 scsi_bus_freeze+0x15/0x20 dpm_run_callback+0x88/0x360 __device_suspend+0x1c4/0x840 async_suspend+0x1f/0xb0 async_run_entry_fn+0x6e/0x2c0 process_one_work+0x4ae/0xa20 worker_thread+0x63/0x5a0 kthread+0x1cf/0x1f0 ret_from_fork+0x24/0x30 Fixes: cd84a62e0078 ("block, scsi: Change the preempt-only flag into a counter") Cc: Lee Duncan Cc: Hannes Reinecke Cc: Luis Chamberlain Cc: Johannes Thumshirn Cc: Christoph Hellwig Cc: Greg Kroah-Hartman Cc: Dan Williams Cc: stable@vger.kernel.org Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_lib.c | 15 ++++++--------- include/scsi/scsi_device.h | 1 - 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 7db3c5fae469..6c18a61176e5 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -3052,11 +3052,12 @@ scsi_device_quiesce(struct scsi_device *sdev) int err; /* - * It is allowed to call scsi_device_quiesce() multiple times from - * the same context but concurrent scsi_device_quiesce() calls are - * not allowed. + * Since all scsi_device_quiesce() and scsi_device_resume() calls + * are serialized it is safe here to check the device state without + * holding the SCSI device state mutex. */ - WARN_ON_ONCE(sdev->quiesced_by && sdev->quiesced_by != current); + if (sdev->sdev_state == SDEV_QUIESCE) + return 0; blk_set_preempt_only(q); @@ -3072,9 +3073,7 @@ scsi_device_quiesce(struct scsi_device *sdev) mutex_lock(&sdev->state_mutex); err = scsi_device_set_state(sdev, SDEV_QUIESCE); - if (err == 0) - sdev->quiesced_by = current; - else + if (err) blk_clear_preempt_only(q); mutex_unlock(&sdev->state_mutex); @@ -3098,8 +3097,6 @@ void scsi_device_resume(struct scsi_device *sdev) * device deleted during suspend) */ mutex_lock(&sdev->state_mutex); - WARN_ON_ONCE(!sdev->quiesced_by); - sdev->quiesced_by = NULL; blk_clear_preempt_only(sdev->request_queue); if (sdev->sdev_state == SDEV_QUIESCE) scsi_device_set_state(sdev, SDEV_RUNNING); diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index 202f4d6a4342..ef86c8adc5d5 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -226,7 +226,6 @@ struct scsi_device { unsigned char access_state; struct mutex state_mutex; enum scsi_device_state sdev_state; - struct task_struct *quiesced_by; unsigned long sdev_data[0]; } __attribute__((aligned(sizeof(unsigned long)))); From patchwork Wed Oct 17 23:40:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10646605 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 7BE3413A4 for ; Wed, 17 Oct 2018 23:40:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F4022886E for ; Wed, 17 Oct 2018 23:40:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63758288EA; Wed, 17 Oct 2018 23:40:48 +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 B1F942886E for ; Wed, 17 Oct 2018 23:40:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727290AbeJRHiw (ORCPT ); Thu, 18 Oct 2018 03:38:52 -0400 Received: from com-out001.mailprotect.be ([83.217.72.83]:51297 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727196AbeJRHiw (ORCPT ); Thu, 18 Oct 2018 03:38:52 -0400 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=nO9hGMcQKRjA6rZZKW6c9ykm9qIsqa8THPIU/n9Jrvg=; b=njRdfKyNEpDo CvpFrCc01W5oNq8p9JtvUnl45w4HmximVICF/amH2E99NkbDw9+yILFs0LqRLXw+pSH9HQZ3fjw2c JDU/1qT+f3m0v9vXT8PnZBwcYVupYa0+2pol4K66hdayEMayfng5h5bou8XMRUjj4TYrbwtBpg0eG ieRkkz7ihdRggPv+1Gnc/yCGIUNCTyu0VhSnbfFYLqR84KmfqpSpNrSfyvwapQGbwTXy9p3vOWGHe pIxRISHms3rJjRd0IuDA35ru0PPsbncETvvxAXP1PaBf+DjnmUwKgG2G8cbDF/f5gNFOl9228qI8+ DLdvKNHlA3qC/StIAVlS9A==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gCvQW-000AhI-80; Thu, 18 Oct 2018 01:40:32 +0200 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 0ED10C0D44; Thu, 18 Oct 2018 01:40:28 +0200 (CEST) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: Greg Kroah-Hartman , linux-scsi@vger.kernel.org, Bart Van Assche , Lee Duncan , Hannes Reinecke , Luis Chamberlain , Johannes Thumshirn , Christoph Hellwig , Dan Williams Subject: [PATCH v2 6/7] sd: Rely on the driver core for asynchronous probing Date: Wed, 17 Oct 2018 16:40:05 -0700 Message-Id: <20181017234006.124251-7-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog In-Reply-To: <20181017234006.124251-1-bvanassche@acm.org> References: <20181017234006.124251-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.02) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5poI8DJzlBnAk/nK8fZda0V602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTYNm2CNnybH8Z43FgPbC84O3ZxZNfM5cTi57zK3AqpgNfTn 6SdpEMjPgzwhQ7uPL5IWShCfuV9Rj0Jpy9XFzNx6ov8sKpLeOx5g8dQO47i2LXrpjTl5ELep3+hD ATmH03oGH/YYgvV0QgfTypJwMtkIN3mjGmwv78iiqzXU/YxqpUHWFPZYohTsv5o5zESeS7iu6oqd H7oPy0kjzLpNONUeYgyqgWbfkZmQQKCujUCY2mcUbWvyjQKcyyzu8SlpYwh2PnOdSBsvBEyk6oP+ JOZedw05hLdzEHC6+IDGb/v36pUCGeLmhx53FRJAP1Ea5ASiYf7H/yBdfVu6BXKOqolTM7KPjFjO plxfo9E/jkjYyATJsjWw5+0eZIpQIcK9yrSIoiC5DDnaemEOugg39OcBf2ZkFf0bc6TV99q4yFj4 jO7J//0XCxCMJn8bXo41UD0/WD7BAcwhXN3d5OI6tWyH6CLbyF0Zq4b1/7rjUzETJsEY2Io8tF+w JOqGSVax9Cm77niqGZoB5oiisgnJ8hVNJmO4hZrKar0rT3Fu0bhVQ+HVicDfSEki2HQjIzlgulSP bUMSEuFskSoX1rj3Ja6RM0MUNRB5UUlg/nVM5yDiAS5BG4T+EAOyAeD+V7jzhS8h0NTR1H9naQeI xvtDOwtIYQ/4lg9Ffvqg9IG0EE8tjOSHlcLdm2dKulDEMTPR6C7iQwUHAL+rG1YY6u9b0QCb2OUM eHyTpNN0eXybX/w7/6KFccwJNTvq+iKXCh0g3vYauvSHTBbiywHlI+JD9ckolRWu/myC9pefMqhc M13fWFTslzf1KnhXRDw6mr5Drq/iEF0D9rez2RHuRFnnxQj65e7iCsnoIGXFTV/TINEoVdSwecyF 4DA8XADDrh0QZbUsptJ0Vo0bpokCyieEKhTugPGxKgiZtZSFSTJua9iBhedKEy7bP5gIt23U7fpA nNNOSPMhkf0/quG9N0n5Pnwg8gvgnGVzE8S4rYKUaxyrp5bArYUTMKtVVfkeNDYwXq3ECq1y9Ps4 MtRhXMXMUla6jCMlrsv11sF1S7MGW8yMRfUf9oDBqtClgM5jH/om1Q5P+UBfxwtWVTRs22VsCW/y aaMGXoow8jwS+vIg0J2DIilC5famIyanggmnEEY1ln4yMyb8PasQ+c0C4IKe30H3mCt4xiI4Gbe/ duNP6eDbFWCz0yfor4324loUDdooDHenVxueaHqkWaGCoq93Iu1JHNnjpligY7PNUfPHGCzvAA== 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 --- 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 fc1356d101b0..1205369ad44f 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 @@ -839,7 +826,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 b44c1bb687a2..f229208bfef3 100644 --- a/drivers/scsi/scsi_pm.c +++ b/drivers/scsi/scsi_pm.c @@ -54,9 +54,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); @@ -149,18 +146,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); @@ -170,11 +156,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 99f1db5e467e..b9fa363b4bbb 100644 --- a/drivers/scsi/scsi_priv.h +++ b/drivers/scsi/scsi_priv.h @@ -175,9 +175,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 b79b366a94f7..52eee36d13fb 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -559,6 +559,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, @@ -3227,12 +3228,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; @@ -3286,7 +3283,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); } /** @@ -3378,8 +3374,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; @@ -3414,8 +3409,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); From patchwork Wed Oct 17 23:40:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10646609 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 EAF601057 for ; Wed, 17 Oct 2018 23:40:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE6892887D for ; Wed, 17 Oct 2018 23:40:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D2264288CF; Wed, 17 Oct 2018 23:40:56 +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 573582887D for ; Wed, 17 Oct 2018 23:40:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727262AbeJRHjA (ORCPT ); Thu, 18 Oct 2018 03:39:00 -0400 Received: from out002.mailprotect.be ([83.217.72.86]:37709 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727175AbeJRHjA (ORCPT ); Thu, 18 Oct 2018 03:39:00 -0400 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=G/eY6OZeEgvRdz/ecentW+Z2nu11rFSTllpakFNV9ok=; b=lg0K7gGiC3Yf joGhsn8gB/L7cPOP9pmECqCTMCNnlQU5r38Vdv6xg3SVeH3jFngLKaf05amIjR8ieCw1n7FKUEMH0 imxmyRj1708nPIvwhK0St6jyXhVU+MTQfwR9uz3Q4J3TH4sUvaFeQ7Kki2cETK7FEoah7UIaWVHS0 dSHO4AGW3zvwRlqvsDmRKcs/CcWpWKEdJ9f5bmgkkuPBkZ5hLyz1Bwfcevrb87paEf/ApAqAn0/ka WMHCAw8Kg8rn7WWnhu/vytR0HThu+ldtnh9WRUUIqk3qVFo6mF91/LmK6avLIMKdzpx1qswVGHEsn +JIM0FygEpZwxmQ7ECB1wQ==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gCvQk-000D3m-2u; Thu, 18 Oct 2018 01:40:46 +0200 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 6DF64C06CF; Thu, 18 Oct 2018 01:40:31 +0200 (CEST) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: Greg Kroah-Hartman , linux-scsi@vger.kernel.org, Bart Van Assche , Lee Duncan , Hannes Reinecke , Luis Chamberlain , Johannes Thumshirn , Christoph Hellwig Subject: [PATCH v2 7/7] sd: Inline sd_probe_part2() Date: Wed, 17 Oct 2018 16:40:06 -0700 Message-Id: <20181017234006.124251-8-bvanassche@acm.org> X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog In-Reply-To: <20181017234006.124251-1-bvanassche@acm.org> References: <20181017234006.124251-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.03) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5op48jggOTN4oc6RjW2SFAN602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTbYPg/zpkSiMTw4RmnfxRCXFU82axTVwUv6v8rWwOPbn8ST Ksl9SxC91yR06AZxhKQie9+9sv+uW/xhFRf3rOAhFEAZ5tLgtxeh4W43PRo1gyVBZhJdB8oBIQVB HyeF+GyojOI3mdswqRrDTMbSijPikzUjpLbYv+k6wc7gZffRufoNd/18byQB0A6J7qtkYo2nkoP/ 7uxT5ANOZNNW1Q/z0yLvsMb+uiAAjdbSeQ5TrAFR//DqOZ7gBtaFV3NEPd9B3ylJDm+BpEBBclKF yxopgN4JfSdG4+vA3R3fKJCA/m/fDy/eqb5U4J5qWPtxGNS+AWt3mmLC0hoFR40CPAMQyrccvRl7 LodRnoQ8/VwOaw+gz/ZKpG7S9PROnRo5n5USQWn9OYmU74xfbcEYge/f7INkM1D8D0wcffXFPtzu Go+eFJImtabaGYRoWdcAtjCcAuDIQf0tklPcA7SYKMcZaFryuM28yfNoRiP4LXR95v/77cCko/EG 7+7uLxBlLaVvfCJf9c87raNJ3rEEAH2+T1zD59o8cPYKs494BBiYWZDfGiqYJbsV6Bia58mKB6GP R9UyIYODc1wVguED8Bfu31/E3ahF5MMcDI7KdpjQKcwi9Jk69TnSHoh9VM4qIjsvP92yJqFDUMWg YkYfhC80sNoIrLcCnn2MFoRBwXu4i9adXN8QoJkCGUT+/nq62lQ14TiNHZBO9dkjkpbpFG8w6J1f hOzjF0b4LXcjJZ5loquFk+pkh+w6U8HrQHUPSWrvc2Dse4DtQMNd1OJpSyWygIcekAmy8mRS31yf rk4trEcV0wEj9itRcd7KH+nVDjFllXn2maRqR4xJOvVleQ85XMfPU/A6Zs85EHjl8kedTQDBddgS itHw/K1calPLDDrKATDDBZ7fFc0FDw0l2bg+z2YoA4glpLgakSw0zRVimP9j4HqbpkLxG/QtLNqg hpj18S1LhMKeGT5NnT/bTxLbyB2oVjwpD0SDGnhQZ7XpT35mKiWY4qyAovTKsLgKiJqTF6ymUAav ae3aV27dM5QN3KVLwP/pKIIHQBh4yd/8+tEyvDkN3AfUBddcu9g0Uhw/YHGGdt5eD9ya81kvI1of 3IOsrfnTjx5M5ZqkPpQBrM2wWVbjHO/cpJpsYlvFhM+mW297Uqw0ZsTjLTJBUO9GfzrLxVhP0uel tSacMfCNTlvBloR44kmvlvy5XDsjxS0= 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 This patch does not change any functionality. Cc: Lee Duncan Cc: Hannes Reinecke Cc: Luis Chamberlain Cc: Johannes Thumshirn Cc: Christoph Hellwig Cc: Greg Kroah-Hartman Signed-off-by: Bart Van Assche --- drivers/scsi/sd.c | 101 ++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 58 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 52eee36d13fb..2a96c2ed1b52 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3228,63 +3228,6 @@ static int sd_format_disk_name(char *prefix, int index, char *buf, int buflen) return 0; } -static void sd_probe_part2(struct scsi_disk *sdkp) -{ - struct scsi_device *sdp; - struct gendisk *gd; - u32 index; - struct device *dev; - - sdp = sdkp->device; - gd = sdkp->disk; - index = sdkp->index; - dev = &sdp->sdev_gendev; - - gd->major = sd_major((index & 0xf0) >> 4); - gd->first_minor = ((index & 0xf) << 4) | (index & 0xfff00); - - gd->fops = &sd_fops; - gd->private_data = &sdkp->driver; - gd->queue = sdkp->device->request_queue; - - /* defaults, until the device tells us otherwise */ - sdp->sector_size = 512; - sdkp->capacity = 0; - sdkp->media_present = 1; - sdkp->write_prot = 0; - sdkp->cache_override = 0; - sdkp->WCE = 0; - sdkp->RCD = 0; - sdkp->ATO = 0; - sdkp->first_scan = 1; - sdkp->max_medium_access_timeouts = SD_MAX_MEDIUM_TIMEOUTS; - - sd_revalidate_disk(gd); - - gd->flags = GENHD_FL_EXT_DEVT; - if (sdp->removable) { - gd->flags |= GENHD_FL_REMOVABLE; - gd->events |= DISK_EVENT_MEDIA_CHANGE; - } - - blk_pm_runtime_init(sdp->request_queue, dev); - device_add_disk(dev, gd); - if (sdkp->capacity) - sd_dif_config_host(sdkp); - - sd_revalidate_disk(gd); - - if (sdkp->security) { - sdkp->opal_dev = init_opal_dev(sdp, &sd_sec_submit); - if (sdkp->opal_dev) - sd_printk(KERN_NOTICE, sdkp, "supports TCG Opal\n"); - } - - sd_printk(KERN_NOTICE, sdkp, "Attached SCSI %sdisk\n", - sdp->removable ? "removable " : ""); - scsi_autopm_put_device(sdp); -} - /** * sd_probe - called during driver initialization and whenever a * new scsi device is attached to the system. It is called once @@ -3374,7 +3317,49 @@ static int sd_probe(struct device *dev) get_device(dev); dev_set_drvdata(dev, sdkp); - sd_probe_part2(sdkp); + gd->major = sd_major((index & 0xf0) >> 4); + gd->first_minor = ((index & 0xf) << 4) | (index & 0xfff00); + + gd->fops = &sd_fops; + gd->private_data = &sdkp->driver; + gd->queue = sdkp->device->request_queue; + + /* defaults, until the device tells us otherwise */ + sdp->sector_size = 512; + sdkp->capacity = 0; + sdkp->media_present = 1; + sdkp->write_prot = 0; + sdkp->cache_override = 0; + sdkp->WCE = 0; + sdkp->RCD = 0; + sdkp->ATO = 0; + sdkp->first_scan = 1; + sdkp->max_medium_access_timeouts = SD_MAX_MEDIUM_TIMEOUTS; + + sd_revalidate_disk(gd); + + gd->flags = GENHD_FL_EXT_DEVT; + if (sdp->removable) { + gd->flags |= GENHD_FL_REMOVABLE; + gd->events |= DISK_EVENT_MEDIA_CHANGE; + } + + blk_pm_runtime_init(sdp->request_queue, dev); + device_add_disk(dev, gd); + if (sdkp->capacity) + sd_dif_config_host(sdkp); + + sd_revalidate_disk(gd); + + if (sdkp->security) { + sdkp->opal_dev = init_opal_dev(sdp, &sd_sec_submit); + if (sdkp->opal_dev) + sd_printk(KERN_NOTICE, sdkp, "supports TCG Opal\n"); + } + + sd_printk(KERN_NOTICE, sdkp, "Attached SCSI %sdisk\n", + sdp->removable ? "removable " : ""); + scsi_autopm_put_device(sdp); return 0;