From patchwork Fri Oct 13 12:45:50 2017 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: 10004437 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 E514760216 for ; Fri, 13 Oct 2017 12:47:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6BEA28FD4 for ; Fri, 13 Oct 2017 12:47:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB9D729037; Fri, 13 Oct 2017 12:47:12 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 A50B12905E for ; Fri, 13 Oct 2017 12:47:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757449AbdJMMrK (ORCPT ); Fri, 13 Oct 2017 08:47:10 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:51262 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753354AbdJMMrI (ORCPT ); Fri, 13 Oct 2017 08:47:08 -0400 Received: by mail-wm0-f65.google.com with SMTP id f4so21572221wme.0 for ; Fri, 13 Oct 2017 05:47:07 -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=lrGzbnfGE6g4LwyeCzUx0i6Zh+sT7sbB/Bcn+JiZRzU=; b=lYCzfCMUlubGj2Mh3qVgNz9XcF9zT9sGYryQZr7lYZS98cnvupDmhsn0AykBJaIJv+ vzG2r0lBoNye6hE2AjoeYihIgoSBmWN51Z7TFaS8sC1BaZQF8OhOOSSzleQO49IeN/Ek 4aiBFT4N0HXRi0pZMV2mfm/lxwV8QTMh9dkUs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lrGzbnfGE6g4LwyeCzUx0i6Zh+sT7sbB/Bcn+JiZRzU=; b=go7TgEvExZI8+bQbwWOtYetKWok6uBXByKNFvywFynbedBRNG1/fsKemjhBYB5VVcg lu7GdtIXSMCyZZP0EkwOa3B8P+KqwTok3SDYWTltJUzyk46bJVk48TwFA7Gp6Wk5qbTS F7LJIFvevBI5crRnu/MEGcFEQbL4dKePr7dtZu7cziPzPKBLBmBbzdsfcxFo4wS1M78Y fNEYgz2kA4FLg/WGjDvgOC+goQmHvCIHnz+VoD83yyZHMvFga14LtEEe6NtCIYDt8+vd REqsgU0Snv1UFpOs1Nu880ak1tZIaBVW/Voit8lx0rcCiXbepqrOXcfabIc3IRusc6tt pkXw== X-Gm-Message-State: AMCzsaW3FgQmS+QVDjToOj5zf33AGnYvsyxWVyFV67NyfpqYpngYvpsM 9Mnym2f9cNk5Aa/OZu3chQ7ypg== X-Google-Smtp-Source: AOwi7QA7atFMJk753BNRtXEDHvX2SZewVMPVTBvubSO/V9fVfIHT7sDoLDpHhVrYqxgI1Jh47uHhMA== X-Received: by 10.80.139.65 with SMTP id l59mr2055730edl.187.1507898827238; Fri, 13 Oct 2017 05:47:07 -0700 (PDT) Received: from skyninja.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id p91sm735012edp.69.2017.10.13.05.47.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Oct 2017 05:47:06 -0700 (PDT) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: axboe@fb.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Rakesh Pandit , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [GIT PULL 01/58] lightnvm: prevent target type module removal when in use Date: Fri, 13 Oct 2017 14:45:50 +0200 Message-Id: <20171013124647.32668-2-m@bjorling.me> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20171013124647.32668-1-m@bjorling.me> References: <20171013124647.32668-1-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 From: Rakesh Pandit If target type module e.g. pblk here is unloaded (rmmod) while module is in use (after creating target) system crashes. We fix this by using module API refcnt. Signed-off-by: Rakesh Pandit Signed-off-by: Matias Bjørling --- drivers/lightnvm/core.c | 4 ++++ drivers/lightnvm/pblk-init.c | 1 + include/linux/lightnvm.h | 1 + 3 files changed, 6 insertions(+) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index ddae430..60e163b 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -316,6 +317,8 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) list_add_tail(&t->list, &dev->targets); mutex_unlock(&dev->mlock); + __module_get(tt->owner); + return 0; err_sysfs: if (tt->exit) @@ -351,6 +354,7 @@ static void __nvm_remove_target(struct nvm_target *t) nvm_remove_tgt_dev(t->dev, 1); put_disk(tdisk); + module_put(t->type->owner); list_del(&t->list); kfree(t); diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c index 1b0f612..6df65d1 100644 --- a/drivers/lightnvm/pblk-init.c +++ b/drivers/lightnvm/pblk-init.c @@ -1044,6 +1044,7 @@ static struct nvm_tgt_type tt_pblk = { .sysfs_init = pblk_sysfs_init, .sysfs_exit = pblk_sysfs_exit, + .owner = THIS_MODULE, }; static int __init pblk_module_init(void) diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index 7dfa56e..7b80ac9 100644 --- a/include/linux/lightnvm.h +++ b/include/linux/lightnvm.h @@ -460,6 +460,7 @@ struct nvm_tgt_type { /* For internal use */ struct list_head list; + struct module *owner; }; extern struct nvm_tgt_type *nvm_find_target_type(const char *, int);