From patchwork Tue Jun 12 07:34:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 10459527 X-Patchwork-Delegate: jgg@ziepe.ca 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 00984601A0 for ; Tue, 12 Jun 2018 07:34:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E56F428676 for ; Tue, 12 Jun 2018 07:34:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9BFC28680; Tue, 12 Jun 2018 07:34:32 +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 779B72867F for ; Tue, 12 Jun 2018 07:34:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933242AbeFLHe3 (ORCPT ); Tue, 12 Jun 2018 03:34:29 -0400 Received: from mx2.suse.de ([195.135.220.15]:36541 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933243AbeFLHe2 (ORCPT ); Tue, 12 Jun 2018 03:34:28 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 90C80AF96; Tue, 12 Jun 2018 07:34:27 +0000 (UTC) From: Hannes Reinecke To: Moni Shoua Cc: Doug Ledford , Jason Gunthorpe , linux-rdma@vger.kernel.org, Johannes Thumshirn , Hannes Reinecke , Hannes Reinecke Subject: [PATCH 1/2] rxe: do not crash when using module option 'add' Date: Tue, 12 Jun 2018 09:34:19 +0200 Message-Id: <20180612073420.45736-2-hare@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180612073420.45736-1-hare@suse.de> References: <20180612073420.45736-1-hare@suse.de> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When using the module option 'add' during modprobe the module will crash as the option is evaluated before the module itself is initialized. So return an error when rxe_param_set_add() is called before the module is initialized. Signed-off-by: Hannes Reinecke --- drivers/infiniband/sw/rxe/rxe.c | 6 ++++++ drivers/infiniband/sw/rxe/rxe.h | 2 ++ drivers/infiniband/sw/rxe/rxe_sysfs.c | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/drivers/infiniband/sw/rxe/rxe.c b/drivers/infiniband/sw/rxe/rxe.c index 7121e1b1eb89..53279d82e5cc 100644 --- a/drivers/infiniband/sw/rxe/rxe.c +++ b/drivers/infiniband/sw/rxe/rxe.c @@ -39,6 +39,8 @@ MODULE_AUTHOR("Bob Pearson, Frank Zago, John Groves, Kamal Heib"); MODULE_DESCRIPTION("Soft RDMA transport"); MODULE_LICENSE("Dual BSD/GPL"); +bool rxe_init_done = false; + /* free resources for all ports on a device */ static void rxe_cleanup_ports(struct rxe_dev *rxe) { @@ -354,6 +356,8 @@ static int __init rxe_module_init(void) if (err) return err; + rxe_init_done = true; + pr_info("loaded\n"); return 0; } @@ -364,6 +368,8 @@ static void __exit rxe_module_exit(void) rxe_net_exit(); rxe_cache_exit(); + rxe_init_done = false; + pr_info("unloaded\n"); } diff --git a/drivers/infiniband/sw/rxe/rxe.h b/drivers/infiniband/sw/rxe/rxe.h index d9ec2de68738..0cf68bc7aa01 100644 --- a/drivers/infiniband/sw/rxe/rxe.h +++ b/drivers/infiniband/sw/rxe/rxe.h @@ -92,6 +92,8 @@ static inline u32 rxe_crc32(struct rxe_dev *rxe, return retval; } +extern bool rxe_init_done; + void rxe_set_mtu(struct rxe_dev *rxe, unsigned int dev_mtu); int rxe_add(struct rxe_dev *rxe, unsigned int mtu); diff --git a/drivers/infiniband/sw/rxe/rxe_sysfs.c b/drivers/infiniband/sw/rxe/rxe_sysfs.c index d5ed7571128f..bb54992e3ff2 100644 --- a/drivers/infiniband/sw/rxe/rxe_sysfs.c +++ b/drivers/infiniband/sw/rxe/rxe_sysfs.c @@ -77,6 +77,11 @@ static int rxe_param_set_add(const char *val, const struct kernel_param *kp) struct net_device *ndev = NULL; struct rxe_dev *rxe; + if (!rxe_init_done) { + pr_err("add: module not initializes\n"); + err = -EINVAL; + goto err; + } len = sanitize_arg(val, intf, sizeof(intf)); if (!len) { pr_err("add: invalid interface name\n");