From patchwork Wed Jun 29 14:41:51 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: 9205501 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 3FEA9607D8 for ; Wed, 29 Jun 2016 14:45:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3077A28666 for ; Wed, 29 Jun 2016 14:45:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23D4E28669; Wed, 29 Jun 2016 14:45:27 +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 04CD428666 for ; Wed, 29 Jun 2016 14:45:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753190AbcF2Oop (ORCPT ); Wed, 29 Jun 2016 10:44:45 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33106 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752661AbcF2OmX (ORCPT ); Wed, 29 Jun 2016 10:42:23 -0400 Received: by mail-wm0-f66.google.com with SMTP id r201so14878683wme.0 for ; Wed, 29 Jun 2016 07:42:15 -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=JnzRYKeJ2e0khDidwJJvpa4WWNfDLGR/ZdXK88d/CiBKQaTfWfk2JLUXYUrAF3FZC0 Iu+TFSud3NwKvkD6ycNCvWFnTOi3SP8Rf3d6oI8lc503Ap8QC/TUyNGif/frcZRQCTqw eHuoeQOTRQ9QbJWJpQQ9UIjmrcTI39VFU+dLw= 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=Qaun/D92/bTzf27Opyg317lSPgrsHsevKYpkChwv6olWZxo366kiIRA8Z5MfKwbBgL LKDww2yEnYMDEG3s2Ll8W70qEpSmVdshXx7vo4nYr/1TltmtWXfyxEHBfB2EDV00doC+ Ma2JGu1qK2asjVlEckm60PbhRoD9CAaePWbfmiiv4aD/NOhPgmWX92/KiHoP6F1eSAQF Xm42EEdhUFzhk1DxW/oR0xVF6+Zuc9Nv/Zycv3JGbMNBC6T0oBl1UM7NNI5yykq+u7dY gIwItBX7EACBg304mW+oh+gpGmR3PbklZ+gQ3UOTMKTq6GaPZHTW+Yk4B67kQo41bBto 2hAg== X-Gm-Message-State: ALyK8tJT0s0OZWo+iJvngl+toc8U5z7Dylqe+7FqV5UUNO2PJpdOrcwrpc89oQAOfnPtZA== X-Received: by 10.28.158.17 with SMTP id h17mr10062159wme.1.1467211334056; Wed, 29 Jun 2016 07:42:14 -0700 (PDT) Received: from Macroninja.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id t190sm5472766wmt.24.2016.06.29.07.42.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Jun 2016 07:42:13 -0700 (PDT) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [RFC PATCH 06/11] lightnvm: remove nested lock conflict with mm Date: Wed, 29 Jun 2016 16:41:51 +0200 Message-Id: <1467211316-22373-7-git-send-email-m@bjorling.me> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1467211316-22373-1-git-send-email-m@bjorling.me> References: <1467211316-22373-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; }