Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5315353ybi; Wed, 12 Jun 2019 00:04:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkP+RznrMjZgvF02+krQSmw04b2PcOxW6HwiTqy2BM8l4W71KSuOr8Spvo2LS4ZArnhAYZ X-Received: by 2002:a65:60cd:: with SMTP id r13mr23982226pgv.58.1560323042501; Wed, 12 Jun 2019 00:04:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560323042; cv=none; d=google.com; s=arc-20160816; b=KWgdEf7J1u2G4tcV6k/nmE2JgvRQP6AR5FFx/bCjBILw7gvJaPF6u+qI7DHtouolFG z0tnwGEYpCbEfmgUYNvClU6I/1e2pHZnTTSRO8wCLDhj6+EUa7ENDX/qKGMc+MrHW+il RDZ2M+GaH8yEhXrzZXxVUTJ9fjbrFkyzLUbS0j3SDK/k2MreWM8AdnQIdt99fEuKSULZ aShDhqMQWfOResGIqyJau1BDPIfJZXqko6RWIDHRtSt/Lc4mA1HIAmUMKTc01JV2xN9c +tPbRSr8Gh3pBKj68dAijbfq/UcZxqIxkvQcHnCzKbLnFwKEdPGUVyCpdLDc1BUwyFye W9MA== 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=JUG/MGP/v45CNsDoPL+l7scX+b6OVPHlqlUApzLOx74=; b=hIQMnTvNpVZohVkl1zVhwlxTCSobfhkK4xWVUCqIR4yxlhIFITUurZscB1OFmXjBme Xf7DnzXl/Qqqubg3XVRibOsrEWkt+NUt7H7VAvQhvhfsRLE8WWx47H0JZhyMPYTxBX5X N+ESjPd6b6/pWATnwZwat6ekHR5NuCqSNeKgPbIUBPxCEiKkSriAuJM7ykJlb0BFEBFC DZ4de7xFto7J3YJCGCI/+YGD/+Oaw2ilwLjPXSq7L1X/g1NvQi8VRrUd6iGYPxA9h4yz 9muWjoFoj9uIfOWXxr3TI7TC4SMyKnpOllNrKmanufxnSXXr4PAUN9t/DJZrAyktsiHV WYlA== 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 f14si3500401pgf.226.2019.06.12.00.03.36; Wed, 12 Jun 2019 00:04:02 -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 S2408216AbfFKXkO (ORCPT + 99 others); Tue, 11 Jun 2019 19:40:14 -0400 Received: from mga17.intel.com ([192.55.52.151]:43216 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405380AbfFKXkL (ORCPT ); Tue, 11 Jun 2019 19:40:11 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jun 2019 16:40:10 -0700 X-ExtLoop1: 1 Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga005.fm.intel.com with ESMTP; 11 Jun 2019 16:40:10 -0700 Subject: [PATCH 2/6] libnvdimm/bus: Prevent duplicate device_unregister() calls From: Dan Williams To: linux-nvdimm@lists.01.org Cc: Jane Chu , Erwin Tsaur , stable@vger.kernel.org, peterz@infradead.org, vishal.l.verma@intel.com, linux-kernel@vger.kernel.org Date: Tue, 11 Jun 2019 16:25:54 -0700 Message-ID: <156029555412.419799.17084493871021141653.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 A multithreaded namespace creation/destruction stress test currently fails with signatures like the following: sysfs group 'power' not found for kobject 'dax1.1' RIP: 0010:sysfs_remove_group+0x76/0x80 Call Trace: device_del+0x73/0x370 device_unregister+0x16/0x50 nd_async_device_unregister+0x1e/0x30 [libnvdimm] async_run_entry_fn+0x39/0x160 process_one_work+0x23c/0x5e0 worker_thread+0x3c/0x390 BUG: kernel NULL pointer dereference, address: 0000000000000020 RIP: 0010:klist_put+0x1b/0x6c Call Trace: klist_del+0xe/0x10 device_del+0x8a/0x2c9 ? __switch_to_asm+0x34/0x70 ? __switch_to_asm+0x40/0x70 device_unregister+0x44/0x4f nd_async_device_unregister+0x22/0x2d [libnvdimm] async_run_entry_fn+0x47/0x15a process_one_work+0x1a2/0x2eb worker_thread+0x1b8/0x26e Use the kill_device() helper to atomically resolve the race of multiple threads issuing kill, device_unregister(), requests. Reported-by: Jane Chu Reported-by: Erwin Tsaur Fixes: 4d88a97aa9e8 ("libnvdimm, nvdimm: dimm driver and base libnvdimm device-driver...") Cc: Link: https://github.com/pmem/ndctl/issues/96 Signed-off-by: Dan Williams --- drivers/nvdimm/bus.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c index 2dca3034fee0..42713b210f51 100644 --- a/drivers/nvdimm/bus.c +++ b/drivers/nvdimm/bus.c @@ -547,13 +547,38 @@ EXPORT_SYMBOL(nd_device_register); void nd_device_unregister(struct device *dev, enum nd_async_mode mode) { + bool killed; + switch (mode) { case ND_ASYNC: + /* + * In the async case this is being triggered with the + * device lock held and the unregistration work needs to + * be moved out of line iff this is thread has won the + * race to schedule the deletion. + */ + if (!kill_device(dev)) + return; + get_device(dev); async_schedule_domain(nd_async_device_unregister, dev, &nd_async_domain); break; case ND_SYNC: + /* + * In the sync case the device is being unregistered due + * to a state change of the parent. Claim the kill state + * to synchronize against other unregistration requests, + * or otherwise let the async path handle it if the + * unregistration was already queued. + */ + device_lock(dev); + killed = kill_device(dev); + device_unlock(dev); + + if (!killed) + return; + nd_synchronize(); device_unregister(dev); break;