Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5315036ybi; Wed, 12 Jun 2019 00:03:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPF6dfjnWW9nM6XRE2b2JdBVftVfYjFnIRHRgzqqElbamDywMvM4d9nYfKnMpKj74GhGop X-Received: by 2002:a17:902:54d:: with SMTP id 71mr78205610plf.140.1560323023120; Wed, 12 Jun 2019 00:03:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560323023; cv=none; d=google.com; s=arc-20160816; b=LHDW46HLpb3tzbl8I+IpfF1EUiJfVFr8nlxAuVSITl0OCvrJpCl8gN/39Q5ujichMe q3gNPkOr1dqsoDhaBeo0qWTQ77phkj3J1MDmzKzA1MxCibRSEfxUzWS/K3TuQMPG3AOO 3uPuSB9sdpPcNHRUfJ0q9eFLuWMy4Wqqx6qNCEuRKqJ6G9Lm7Xc7sqMk+wxF1Z9kohvl Nn0Oa/hI4VojTx1SnLNlHuS/nEuUDMxg+eJxJUYPqtVU672h5+tItcFQPHR4KHWm+OEG 4AIIydNPGpWFUOQCGV4stPwJ3irCcfFzuxGu6ZmZ+uuqP1dY1V14Am0+FRzM9aZ1pgs8 +fbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject; bh=y//2c1qgGQqFEVlJZ2Jb8/tBCR/amgX9iMWvipDKvhs=; b=bbwQXb56GA6DwRhixyIra7PBDpAR4ILS2r12MSAFWf3dKdQmm+nHrVdSqdeYQxYlQ5 hxVr41i/JWHaWRIxEA3LowQHuKIPmo22hnftwDlqgcAqzivULJhiyut2KU9eeqFEukqT 5nVSQMoOIlvwPOwc9V+OsWKXXoM6mSJO/nyByswtY5pJBn4omMnAa6VBnYzzeYAHP++b K+7SB6CMfSrabdjgINjyzvG+LZrBfSEct+/NmHUfZKyUaA+w9r/Xxeeg6xtaf1qfUPYY vpQR1TKbINwtLCUHYdnC+vAWFuLPREc0Cj/G4GN6BB31Itq9d183mSAL3xA5kgLShqP3 /C5g== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c137si15690643pfb.185.2019.06.12.00.03.17; Wed, 12 Jun 2019 00:03:43 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2408203AbfFKXkH (ORCPT + 99 others); Tue, 11 Jun 2019 19:40:07 -0400 Received: from mga02.intel.com ([134.134.136.20]:26670 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405380AbfFKXkG (ORCPT ); Tue, 11 Jun 2019 19:40:06 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jun 2019 16:40:05 -0700 X-ExtLoop1: 1 Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga003.jf.intel.com with ESMTP; 11 Jun 2019 16:40:05 -0700 Subject: [PATCH 1/6] drivers/base: Introduce kill_device() From: Dan Williams To: linux-nvdimm@lists.01.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , stable@vger.kernel.org, peterz@infradead.org, vishal.l.verma@intel.com, linux-kernel@vger.kernel.org Date: Tue, 11 Jun 2019 16:25:49 -0700 Message-ID: <156029554901.419799.10072666658870843929.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <156029554317.419799.1324389595953183385.stgit@dwillia2-desk3.amr.corp.intel.com> References: <156029554317.419799.1324389595953183385.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The libnvdimm subsystem arranges for devices to be destroyed as a result of a sysfs operation. Since device_unregister() cannot be called from an actively running sysfs attribute of the same device libnvdimm arranges for device_unregister() to be performed in an out-of-line async context. The driver core maintains a 'dead' state for coordinating its own racing async registration / de-registration requests. Rather than add local 'dead' state tracking infrastructure to libnvdimm device objects, export the existing state tracking via a new kill_device() helper. The kill_device() helper simply marks the device as dead, i.e. that it is on its way to device_del(), or returns that the device was already dead. This can be used in advance of calling device_unregister() for subsystems like libnvdimm that might need to handle multiple user threads racing to delete a device. This refactoring does not change any behavior, but it is a pre-requisite for follow-on fixes and therefore marked for -stable. Cc: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" Fixes: 4d88a97aa9e8 ("libnvdimm, nvdimm: dimm driver and base libnvdimm device-driver...") Cc: Signed-off-by: Dan Williams --- drivers/base/core.c | 27 +++++++++++++++++++-------- include/linux/device.h | 1 + 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index fd7511e04e62..eaf3aa0cb803 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2211,6 +2211,24 @@ void put_device(struct device *dev) } EXPORT_SYMBOL_GPL(put_device); +bool kill_device(struct device *dev) +{ + /* + * Require the device lock and set the "dead" flag to guarantee that + * the update behavior is consistent with the other bitfields near + * it and that we cannot have an asynchronous probe routine trying + * to run while we are tearing out the bus/class/sysfs from + * underneath the device. + */ + lockdep_assert_held(&dev->mutex); + + if (dev->p->dead) + return false; + dev->p->dead = true; + return true; +} +EXPORT_SYMBOL_GPL(kill_device); + /** * device_del - delete device from system. * @dev: device. @@ -2230,15 +2248,8 @@ void device_del(struct device *dev) struct kobject *glue_dir = NULL; struct class_interface *class_intf; - /* - * Hold the device lock and set the "dead" flag to guarantee that - * the update behavior is consistent with the other bitfields near - * it and that we cannot have an asynchronous probe routine trying - * to run while we are tearing out the bus/class/sysfs from - * underneath the device. - */ device_lock(dev); - dev->p->dead = true; + kill_device(dev); device_unlock(dev); /* Notify clients of device removal. This call must come diff --git a/include/linux/device.h b/include/linux/device.h index e85264fb6616..0da5c67f6be1 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1373,6 +1373,7 @@ extern int (*platform_notify_remove)(struct device *dev); */ extern struct device *get_device(struct device *dev); extern void put_device(struct device *dev); +extern bool kill_device(struct device *dev); #ifdef CONFIG_DEVTMPFS extern int devtmpfs_create_node(struct device *dev);