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;