From patchwork Thu Jul 7 07:54:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Matias_Bj=C3=B8rling?= X-Patchwork-Id: 9218063 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6A8426048B for ; Thu, 7 Jul 2016 07:57:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EE5C2878F for ; Thu, 7 Jul 2016 07:57:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 539F628791; Thu, 7 Jul 2016 07:57:18 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 CD2242878F for ; Thu, 7 Jul 2016 07:57:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752110AbcGGH5P (ORCPT ); Thu, 7 Jul 2016 03:57:15 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35148 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756626AbcGGHyr (ORCPT ); Thu, 7 Jul 2016 03:54:47 -0400 Received: by mail-wm0-f67.google.com with SMTP id a66so3513886wme.2 for ; Thu, 07 Jul 2016 00:54:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bjorling.me; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=viuRjukXhRKQQQWeo2sp7LVpCeKH048QJs6Kx1ikk98=; b=KTII0Cdy7FjcTBl03VG/41tWCvINE5DKqw9ju5yIs4Mx449HR3QIxv0exFAvUdl+pB MBV6w7ZC8oASiNqU8mn29eW0e1jk4m9aZQNfzYvwi+36igUhuMPo6UK/pEdQlmAt7Vjy ebOIvvKRGv/BAEKDzNE0JwgMpuD4Ls2UQx3YQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=viuRjukXhRKQQQWeo2sp7LVpCeKH048QJs6Kx1ikk98=; b=eTJuqkwhRHt06SinQ0I6jajwIL7DMAVkUEPXy6JyOqOBoUpyaZBkR7kY/89erLAx1b Hwp77vIeKV/tZVN1KFYVq4UQUCYZdrdU8qojs/aICFJueVUxjbWGgQT0Nfr4tGtGZqhd 6ZM6bPyCXFlaplomGYKcpIkax5sqS4C9YaVWIFG48yVZI9wIQMvkJQ623FkOZt1+y52C 5YZF+1mkbRwLk9lb22NKPvwZgbByv7H0iAYfewZWj5uz6COTrDixIzcBR3f49xHB7trl J+tPxrs9cgeolb5FuJQ9/ApTNx+yiQeqpLrpkWJy7hEgNkokSzTJ8MCqWX7fGs5s1hXR 38ig== X-Gm-Message-State: ALyK8tIlLRkLU1ChfEKsNZMDpS9Q/UaTm67b2OblfPqc0z7dfluMvIgzQvsMnMnpD+9NcA== X-Received: by 10.194.18.34 with SMTP id t2mr16740282wjd.14.1467878086085; Thu, 07 Jul 2016 00:54:46 -0700 (PDT) Received: from Macroninja.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id i74sm1654796wmg.21.2016.07.07.00.54.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Jul 2016 00:54:45 -0700 (PDT) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, axboe@fb.com Cc: =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 11/17] lightnvm: remove nested lock conflict with mm Date: Thu, 7 Jul 2016 09:54:17 +0200 Message-Id: <1467878063-22919-12-git-send-email-m@bjorling.me> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1467878063-22919-1-git-send-email-m@bjorling.me> References: <1467878063-22919-1-git-send-email-m@bjorling.me> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If a media manager tries to initialize it targets upon media manager initialization, the media manager will need to know which target types are available in LightNVM. The lists of which managers and target types are available shares the same lock. Therefore, on initialization, the nvm_lock is taken by LightNVM core, which later leads to a deadlock when target types are enumerated by the media manager. Add an exclusive lock for target types to resolve this conflict. Signed-off-by: Matias Bjørling --- drivers/lightnvm/core.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 8afb04c..04469e0 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -28,6 +28,7 @@ #include static LIST_HEAD(nvm_tgt_types); +static DECLARE_RWSEM(nvm_tgtt_lock); static LIST_HEAD(nvm_mgrs); static LIST_HEAD(nvm_devices); static DECLARE_RWSEM(nvm_lock); @@ -37,7 +38,7 @@ struct nvm_tgt_type *nvm_find_target_type(const char *name, int lock) struct nvm_tgt_type *tmp, *tt = NULL; if (lock) - down_write(&nvm_lock); + down_write(&nvm_tgtt_lock); list_for_each_entry(tmp, &nvm_tgt_types, list) if (!strcmp(name, tmp->name)) { @@ -46,7 +47,7 @@ struct nvm_tgt_type *nvm_find_target_type(const char *name, int lock) } if (lock) - up_write(&nvm_lock); + up_write(&nvm_tgtt_lock); return tt; } EXPORT_SYMBOL(nvm_find_target_type); @@ -55,12 +56,12 @@ int nvm_register_tgt_type(struct nvm_tgt_type *tt) { int ret = 0; - down_write(&nvm_lock); + down_write(&nvm_tgtt_lock); if (nvm_find_target_type(tt->name, 0)) ret = -EEXIST; else list_add(&tt->list, &nvm_tgt_types); - up_write(&nvm_lock); + up_write(&nvm_tgtt_lock); return ret; }