From patchwork Tue Mar 19 14:24:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marcin Dziegielewski X-Patchwork-Id: 10859671 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8A68922 for ; Tue, 19 Mar 2019 14:24:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C93F2950E for ; Tue, 19 Mar 2019 14:24:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88D81296CB; Tue, 19 Mar 2019 14:24:52 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 303F72950E for ; Tue, 19 Mar 2019 14:24:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726712AbfCSOYv (ORCPT ); Tue, 19 Mar 2019 10:24:51 -0400 Received: from mga02.intel.com ([134.134.136.20]:45759 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726703AbfCSOYv (ORCPT ); Tue, 19 Mar 2019 10:24:51 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Mar 2019 07:24:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,498,1544515200"; d="scan'208";a="132882483" Received: from mdziegie-mobl.ger.corp.intel.com (HELO localhost.igk.intel.com) ([10.237.142.119]) by fmsmga008.fm.intel.com with ESMTP; 19 Mar 2019 07:24:48 -0700 From: Marcin Dziegielewski To: mb@lightnvm.io, javier@javigon.com, hans.holmberg@cnexlabs.com Cc: linux-block@vger.kernel.org, marcin.dziegielewski@intel.com, igor.j.konopko@intel.com Subject: [PATCH] lightnvm: add a lock to prevent before the race condition on pblk remove Date: Tue, 19 Mar 2019 15:24:44 +0100 Message-Id: <1553005484-10584-1-git-send-email-marcin.dziegielewski@intel.com> X-Mailer: git-send-email 1.8.3.1 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 When we trigger nvm target remove during device hot unplug, we have a chance to hit general protection fault caused by use of nvm_dev which was freed from another (hot unplug) thread (in nvm_unregister function). This patch introduce lock in nvme_ioctl_dev_remove function to prevent us before a situation like described above. Signed-off-by: Marcin Dziegielewski Reviewed-by: Javier González --- drivers/lightnvm/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 5f82036..84f0b9a 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -1335,11 +1335,13 @@ static long nvm_ioctl_dev_remove(struct file *file, void __user *arg) return -EINVAL; } + down_read(&nvm_lock); list_for_each_entry(dev, &nvm_devices, devices) { ret = nvm_remove_tgt(dev, &remove); if (!ret) break; } + up_read(&nvm_lock); return ret; }