Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3803644ybi; Mon, 29 Jul 2019 12:57:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqzy0L8TumraUP+HkmCQCssd/i2ElnDMm95bRCh2H7oupyr8sQ/B8DiJXtG9lMU3pyo3ZAZu X-Received: by 2002:a17:902:7407:: with SMTP id g7mr112991765pll.214.1564430268764; Mon, 29 Jul 2019 12:57:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430268; cv=none; d=google.com; s=arc-20160816; b=WsYWABXSzdMZczmhxFXBjTItw6XUyyH0t4Mm8z0Ua9R6a0B9nS4sPDnwOiZV171uDx XwLU/3Fr0i3CN5sniJMqK/gnIpuhT16zDsjXsLE4tl1qSNH6SV6tUD5DZwlW1p0f9+rQ PsPRCUcO3MiIzDEU9QQXE6MiDKrYhLj3YOa/Fk0LUhkx+TLVqad+AY+igSGC0xS4qdOt l1NOKB4V4KWsqy5Lv/Y60/Yom5BNS/bgBAy53sGqI5EwcBvhV1F5Ix9flqrCgwpv2Ev2 k6nEHtgxL0J93YzX2BFTk4reJxBuhpJ7vah7wrpSExm3jZ+OBNFQ5JEDRsSs/R2cYyvR yVlA== 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=l3W5WrL6zh8JtJds/LL3wuszZfrTzJ3wlr8FudinvNY=; b=sXfjVisnJTyBlc8jUy3tRub0ii2gEUdFKA2Sl4LWXt/eO682EjYBqwG6m/P0fxLocN x7/d7mZlLzRh0Y9Dx+rYQnmuyFVakiOE/6s6pRjMH6C1o0zQMBiW1VKz13GSwuBb0vEk d0iOvzxcH/R24L0tVQH1ty41MTwjubLjW3+OrjP3kUKtoDFDlRO7TczJ9qQ7gn3E8j7h CJzWuIFGM3g3fsRYSXFf/NXbUYbpxlUhYO3u4wxwy8aTG0Y7xBg8LlDQVSEvAwX7rnzr HBm1UeOrc1qGHYnDcdDBl2pFk8nviCc7vQ29s/RG7nFx+/eLNzhhTK/M4ebXK8NLicSL QrKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NYNFm0tm; 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 j70si27691091pgd.500.2019.07.29.12.57.33; Mon, 29 Jul 2019 12:57:48 -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=NYNFm0tm; 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 S2391069AbfG2T40 (ORCPT + 99 others); Mon, 29 Jul 2019 15:56:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:49258 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390942AbfG2T4W (ORCPT ); Mon, 29 Jul 2019 15:56:22 -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 75255204EC; Mon, 29 Jul 2019 19:56:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564430182; bh=7pjNj236KuNQd2c2Vl4AMO6oZiPl9AEps7lwv3kW6BM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NYNFm0tm1+12ZbDo9u7n4BkYRyLUF0DwyxpgS9MI3oqg1Yykz7cyPHuXTt4ubC3Mg DnEy2sHp2NIlHbClbjSS9ZBS4RQjr+7M0dMgDeqsjKqszhrRJoVP3SKIfhbcz6Emvs 5urmJOqCs4hPf/9tdbOPFJ1+HmeQsmG1KfCacT7E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jane Chu , Erwin Tsaur , Dan Williams Subject: [PATCH 5.2 206/215] libnvdimm/bus: Prevent duplicate device_unregister() calls Date: Mon, 29 Jul 2019 21:23:22 +0200 Message-Id: <20190729190815.715647093@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 8aac0e2338916e273ccbd438a2b7a1e8c61749f5 upstream. 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 Tested-by: Tested-by: Jane Chu Link: https://lore.kernel.org/r/156341207846.292348.10435719262819764054.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams Signed-off-by: Greg Kroah-Hartman --- drivers/nvdimm/bus.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) --- 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;