From patchwork Wed Nov 25 12:42:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenwei Tao X-Patchwork-Id: 7698851 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EB152BF90C for ; Wed, 25 Nov 2015 12:43:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1BC93208EA for ; Wed, 25 Nov 2015 12:43:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 30F8320841 for ; Wed, 25 Nov 2015 12:43:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753213AbbKYMn1 (ORCPT ); Wed, 25 Nov 2015 07:43:27 -0500 Received: from mail-pa0-f66.google.com ([209.85.220.66]:33790 "EHLO mail-pa0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751711AbbKYMnZ (ORCPT ); Wed, 25 Nov 2015 07:43:25 -0500 Received: by pagj16 with SMTP id j16so6988492pag.0; Wed, 25 Nov 2015 04:43:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tA1V/ivGxPjtDLyGhM717hNT+upQHIMJ7iFgC7vRolk=; b=m/ot6atHS/z4/NJqyek3CY7XKxY7f3b26bEb1urKwKloyppi3SkbZMH5XHsM5OYxYw 28THIRDkIDhEIKPvRBWMeNcr29J16Qs+3pgIYw+K+J5oAyvwtFPyRYVPcrPheD8Q7KTw 1CI+bt47WLaJIdxEkVjFzLv6cyCVQV/J4tp6NHwgDam8VEnME3mnv5c2glxC4KFDJW54 6PgeixoiHGs9EZuAT0oJ7uZERLry/9hle9EGKEEJq/G4+TfP1h4mU6mbsWDW6+FXwNOS HvXBsAvdePEAJWmdqQHUM2g1PRNW3gFvyEFh282xogWYMSrfwc/N7s9fJv4Z/KsxCWtn I1xA== X-Received: by 10.98.7.193 with SMTP id 62mr31331687pfh.22.1448455405187; Wed, 25 Nov 2015 04:43:25 -0800 (PST) Received: from localhost.localdomain.com ([111.204.49.2]) by smtp.gmail.com with ESMTPSA id c1sm21318930pas.1.2015.11.25.04.43.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Nov 2015 04:43:24 -0800 (PST) From: Wenwei Tao To: mb@lightnvm.io, keith.busch@intel.com, axboe@fb.com Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Subject: [PATCH 1/3] lightnvm: missing nvm_lock acquire Date: Wed, 25 Nov 2015 20:42:54 +0800 Message-Id: <1448455376-5020-2-git-send-email-ww.tao0320@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1448455376-5020-1-git-send-email-ww.tao0320@gmail.com> References: <1448455376-5020-1-git-send-email-ww.tao0320@gmail.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP To avoid race conditions, traverse dev, media manager, and targeet lists and also register, unregister entries to/from them, should be always under the nvm_lock control. Signed-off-by: Wenwei Tao --- drivers/lightnvm/core.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index f659e60..39aec3a 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -333,19 +333,19 @@ EXPORT_SYMBOL(nvm_register); void nvm_unregister(char *disk_name) { + down_write(&nvm_lock); struct nvm_dev *dev = nvm_find_nvm_dev(disk_name); if (!dev) { pr_err("nvm: could not find device %s to unregister\n", disk_name); + up_write(&nvm_lock); return; } - nvm_exit(dev); - - down_write(&nvm_lock); list_del(&dev->devices); up_write(&nvm_lock); + nvm_exit(dev); } EXPORT_SYMBOL(nvm_unregister); @@ -365,12 +365,15 @@ static int nvm_create_target(struct nvm_dev *dev, void *targetdata; int ret = 0; + down_write(&nvm_lock); if (!dev->mt) { /* register with device with a supported NVM manager */ list_for_each_entry(mt, &nvm_mgrs, list) { ret = mt->register_mgr(dev); - if (ret < 0) + if (ret < 0) { + up_write(&nvm_lock); return ret; /* initialization failed */ + } if (ret > 0) { dev->mt = mt; break; /* successfully initialized */ @@ -379,6 +382,7 @@ static int nvm_create_target(struct nvm_dev *dev, if (!ret) { pr_info("nvm: no compatible nvm manager found.\n"); + up_write(&nvm_lock); return -ENODEV; } } @@ -386,10 +390,10 @@ static int nvm_create_target(struct nvm_dev *dev, tt = nvm_find_target_type(create->tgttype); if (!tt) { pr_err("nvm: target type %s not found\n", create->tgttype); + up_write(&nvm_lock); return -EINVAL; } - down_write(&nvm_lock); list_for_each_entry(t, &dev->online_targets, list) { if (!strcmp(create->tgtname, t->disk->disk_name)) { pr_err("nvm: target name already exists.\n"); @@ -472,8 +476,9 @@ static int __nvm_configure_create(struct nvm_ioctl_create *create) { struct nvm_dev *dev; struct nvm_ioctl_create_simple *s; - + down_write(&nvm_lock); dev = nvm_find_nvm_dev(create->dev); + up_write(&nvm_lock); if (!dev) { pr_err("nvm: device not found\n"); return -EINVAL; @@ -532,7 +537,9 @@ static int nvm_configure_show(const char *val) return -EINVAL; } + down_write(&nvm_lock); dev = nvm_find_nvm_dev(devname); + up_write(&nvm_lock); if (!dev) { pr_err("nvm: device not found\n"); return -EINVAL;