Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3804639ybi; Mon, 29 Jul 2019 12:59:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxx+i6NTigojTwTe0kl3EEEVcN8VHMoQCS7+9SfTOH85x0BeVEht1gd7lHxEgjA0f/IXzup X-Received: by 2002:a17:902:da4:: with SMTP id 33mr102107454plv.209.1564430345649; Mon, 29 Jul 2019 12:59:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430345; cv=none; d=google.com; s=arc-20160816; b=lORpKfQOo0N50ILQWmQqMaWjSg/LQsSK5a3CRyKNLVXWgBPCj15WlHF8WtoBj3ruys zRABBpEC9+nScfSv2izGafYS9dlepjgEu+WYpmqE86sY4Vl7r14LPAoM5sd8pRmsNhfB SbI9Kv5YZgu++jKrUdlMtUm5FU17z1q2xNY6m/X1slnXYXeWamI8dfcqGKrWWGMx0Q4b pAgRNu46yTM+99ZEQjWilXxupupgnjufAtlcIFCDh7xNpzRxtaim92gR3pksSu+dWbrm WECfH0Xq9hTxsLHx5TEVWfRcIRbWuOhlSs+s7iZBsqCeSqPtYSCU6wj/Lh0X2oKS0Xp6 AbLw== 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:subject:cc:to :from:dkim-signature; bh=je2zBITdQVupVuaYl34WsAn+iy+zP/H2cq7pmofdSGQ=; b=Sv+XdC/OPs9jLdL7lZb7GZnIDT9KDBXDfibOQQyrdVrZ+PiDrxtqWhzZ/K2tsbI6W/ qxWjMSUsbHCtiVm8Tc8nLlDlEYdJ5oJ8fARfh7V9wJgIA1/j/n3Ccz2l3+/8UvOX/K7q 057nfqMqvfWpszLERDDOvDmGUsd4KSsScgzzBBo7yLrpkB7O0NdCKpZ7gjkM/zxEFw6b /iUDAHpFlV5TcAw1RKi8dIlroCtENnaAPQx5to+u9ddniqIgJHwN0QKHOZFXHAGGCdr0 pNVG7pJZEkol7BmtGa1p3q+TFNHpKsZhKTYT1aNRI6NGjYycHucMqm1+5czzbVDLdKEC IajQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mxvnypr0; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j100si24494737pje.52.2019.07.29.12.58.50; Mon, 29 Jul 2019 12:59:05 -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=@kernel.org header.s=default header.b=mxvnypr0; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404057AbfG2T4Y (ORCPT + 99 others); Mon, 29 Jul 2019 15:56:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:49222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391046AbfG2T4T (ORCPT ); Mon, 29 Jul 2019 15:56:19 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C89802054F; Mon, 29 Jul 2019 19:56:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564430178; bh=YEsERD5xobFSAJPCjfPaBybmNjaCjSEANpwFXcPLpkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mxvnypr02/Jqz1kS1QHGYSRJ9lJL2otlsXElopXItzeN1njUa5O00ZXNQZ7eGWrXL 9JaBya1fFVHg/KVkx2ymb8uZ/f+yACOq4dWc3Gk7WhqX6BSOc8+1zTJVpaNigbaMqE 6cKNxeThYqCI9bFAxsBlUuNGkeOeYKSxkvd/y4Lk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Rafael J. Wysocki" , Jane Chu , Dan Williams Subject: [PATCH 5.2 205/215] drivers/base: Introduce kill_device() Date: Mon, 29 Jul 2019 21:23:21 +0200 Message-Id: <20190729190815.590302158@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Williams commit 00289cd87676e14913d2d8492d1ce05c4baafdae upstream. 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: Tested-by: Jane Chu Reviewed-by: Greg Kroah-Hartman Link: https://lore.kernel.org/r/156341207332.292348.14959761496009347574.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 27 +++++++++++++++++++-------- include/linux/device.h | 1 + 2 files changed, 20 insertions(+), 8 deletions(-) --- 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 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1375,6 +1375,7 @@ extern int (*platform_notify_remove)(str */ 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);