Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4748707ybp; Mon, 14 Oct 2019 09:24:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxoYKvF1qWL/U23ACZIXyDffke7ENvd555p6jL/IlR0XiGmfvQP2uzssNPGf+UUOcix9mO8 X-Received: by 2002:aa7:d04a:: with SMTP id n10mr29638345edo.14.1571070294616; Mon, 14 Oct 2019 09:24:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571070294; cv=none; d=google.com; s=arc-20160816; b=I8PxcLofgn+1lRSxmICu7PWpUzCnj4biAlDIdhHFEsTa4EuGkJNMJ26KFUw/tzs9PQ 2hFML1W0mCChlKt8BHA0WY/N+ZW8+Myz1AASQyviotxDjjGLgB8DSyzG6/52GaN6EN/Y hoH1yGASXT1qoQrREaOrBku/6uavQCyCfhKSbpn/wOMYei5XYLkH8/OBETNZ+zqc/XiF fAdDag5SW8NQo5rUJ8EM7GjZL3HNLzxpup2vEyHBT5L90Loqu4V8oKuPJWMl4f+r+mYw 78+rIhnazPBnXvQZKkIByxA3KyIbtV4exlAdZSy4+oXA6x5R69o/gsJABGGDwkzk8/R2 pG4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=+d/ANv1Sk5IA8SJFgYWLVzJmUF0sZPRMkbEU6RlJbuU=; b=reFUMSQV1VbtSs+HQK+f1fASlY5u6hy3LkUnI9hSgmXEwsaQnmbqZfACzyif/p4wGw NSX/ZBc6SiSQ6s4z6KIoOmUKRJy2EUY4drMAcFl7+c/F6ehyvCfqBziv6wdtd6lugLy2 +VLLywBKdUzPX0RwZZyYwPcvDSKCHR5cQO3Z+9c59ehI4bzPipak1T3RKdfNgjZ+oOIp s8GN05QPWsOnneytL6nws73V92xNB1Thc4lEzP5jGZnQ6xnZINfq3kpty8OV5/FiKXPR Pq5RIOU78yackG2F8RHaWCgEAidHH1+KGZ93FEz/zKIdvqJtJ74DDyvvcJ5s8nEN33he Xa/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=RbIgsQ3J; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p40si14630728eda.334.2019.10.14.09.24.30; Mon, 14 Oct 2019 09:24:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=RbIgsQ3J; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387834AbfJNPrE (ORCPT + 99 others); Mon, 14 Oct 2019 11:47:04 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:38392 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731070AbfJNPrD (ORCPT ); Mon, 14 Oct 2019 11:47:03 -0400 Received: by mail-oi1-f196.google.com with SMTP id m16so14131547oic.5 for ; Mon, 14 Oct 2019 08:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=+d/ANv1Sk5IA8SJFgYWLVzJmUF0sZPRMkbEU6RlJbuU=; b=RbIgsQ3JeEoO2SUOr8czjyqwoTyu9r8YhfgWisemdpxK2TD1dtv+aT7vlxPqIla1pI HC10AunLc1raT9aMtGsv8cMVAagR08qwBHnCigIE1cpkkHwxDsfvxdLIp05rI+qIS1hU Y7ekzDFMeu+RxKMZwPncW2tvPmij9/iW1nQVTpJlhVclDUl/F99UBtfouYxkJiw7aE1E 7c1p3klAtJjlAxLA7XT3gvqi34CrNTAKfxstdablRwFGe5qKrNAV5qNlctCGjafPirMM dCBbBrDTnm82fyaf3uoxEEJhlyuUK4d1y1NZ4JL5nFUkjYjw1lnxCpVqLo51fya8aPHW Py/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=+d/ANv1Sk5IA8SJFgYWLVzJmUF0sZPRMkbEU6RlJbuU=; b=EukRDUDWa/I/QzkTyWY1/UwvPWkHKwsqjZSW0ApBwF0Jr1uQTj7FG5tJl0zZuu1k/t ahvLNQnNdseTQm83zfZ1N+MfC8QOJK59qGHdw+g1E2b7AjKeL6zmrLSDG9zaerDLCB6X VV7ZIw88HKpO9+EqROerWJqn99EfgCZaJkiNcyug9nsJHPG0Za8644Xlnu+EexuVUcVA F4avS58hS/cfoxlqT8hHELXA6hBPzs8sbDKvRtteyQN9xy5F+CF8WXrUOhgnIZwlH7Zv zgWXz7nQMD2lP4nCeBriUzGdRNGZz7E63FLKF9U6f0BeYdDtbWLojTE0dt+7Ipv878Dt oIIg== X-Gm-Message-State: APjAAAU9GvcRKNa7+aW2Jt9QdQ3f9xP3o67mT2CADQnfGU2/ExNHpAAI 67KSiJI0o6gqo0VGaTIc/w== X-Received: by 2002:aca:5ed7:: with SMTP id s206mr23826167oib.134.1571068022560; Mon, 14 Oct 2019 08:47:02 -0700 (PDT) Received: from serve.minyard.net ([47.184.136.59]) by smtp.gmail.com with ESMTPSA id o23sm5832035ote.67.2019.10.14.08.47.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 08:47:02 -0700 (PDT) Received: from t560.minyard.net (unknown [192.168.27.180]) by serve.minyard.net (Postfix) with ESMTPA id 7FEA1180044; Mon, 14 Oct 2019 15:47:01 +0000 (UTC) From: minyard@acm.org To: tony camuso Cc: openipmi-developer@lists.sourceforge.net, Corey Minyard , linux-kernel@vger.kernel.org, Corey Minyard Subject: [PATCH] ipmi: Don't allow device module unload when in use Date: Mon, 14 Oct 2019 10:46:32 -0500 Message-Id: <20191014154632.11103-1-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191014134141.GA25427@t560> References: <20191014134141.GA25427@t560> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Corey Minyard If something has the IPMI driver open, don't allow the device module to be unloaded. Before it would unload and the user would get errors on use. This change is made on user request, and it makes it consistent with the I2C driver, which has the same behavior. It does change things a little bit with respect to kernel users. If the ACPI or IPMI watchdog (or any other kernel user) has created a user, then the device module cannot be unloaded. Before it could be unloaded, This does not affect hot-plug. If the device goes away (it's on something removable that is removed or is hot-removed via sysfs) then it still behaves as it did before. Reported-by: tony camuso Signed-off-by: Corey Minyard --- Tony, here is a suggested change for this. Can you look it over and see if it looks ok? Thanks, -corey drivers/char/ipmi/ipmi_msghandler.c | 23 ++++++++++++++++------- include/linux/ipmi_smi.h | 12 ++++++++---- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c index 2aab80e19ae0..15680de18625 100644 --- a/drivers/char/ipmi/ipmi_msghandler.c +++ b/drivers/char/ipmi/ipmi_msghandler.c @@ -448,6 +448,8 @@ enum ipmi_stat_indexes { #define IPMI_IPMB_NUM_SEQ 64 struct ipmi_smi { + struct module *owner; + /* What interface number are we? */ int intf_num; @@ -1220,6 +1222,11 @@ int ipmi_create_user(unsigned int if_num, if (rv) goto out_kfree; + if (!try_module_get(intf->owner)) { + rv = -ENODEV; + goto out_kfree; + } + /* Note that each existing user holds a refcount to the interface. */ kref_get(&intf->refcount); @@ -1349,6 +1356,7 @@ static void _ipmi_destroy_user(struct ipmi_user *user) } kref_put(&intf->refcount, intf_free); + module_put(intf->owner); } int ipmi_destroy_user(struct ipmi_user *user) @@ -2459,7 +2467,7 @@ static int __get_device_id(struct ipmi_smi *intf, struct bmc_device *bmc) * been recently fetched, this will just use the cached data. Otherwise * it will run a new fetch. * - * Except for the first time this is called (in ipmi_register_smi()), + * Except for the first time this is called (in ipmi_add_smi()), * this will always return good data; */ static int __bmc_get_device_id(struct ipmi_smi *intf, struct bmc_device *bmc, @@ -3377,10 +3385,11 @@ static void redo_bmc_reg(struct work_struct *work) kref_put(&intf->refcount, intf_free); } -int ipmi_register_smi(const struct ipmi_smi_handlers *handlers, - void *send_info, - struct device *si_dev, - unsigned char slave_addr) +int ipmi_add_smi(struct module *owner, + const struct ipmi_smi_handlers *handlers, + void *send_info, + struct device *si_dev, + unsigned char slave_addr) { int i, j; int rv; @@ -3406,7 +3415,7 @@ int ipmi_register_smi(const struct ipmi_smi_handlers *handlers, return rv; } - + intf->owner = owner; intf->bmc = &intf->tmp_bmc; INIT_LIST_HEAD(&intf->bmc->intfs); mutex_init(&intf->bmc->dyn_mutex); @@ -3514,7 +3523,7 @@ int ipmi_register_smi(const struct ipmi_smi_handlers *handlers, return rv; } -EXPORT_SYMBOL(ipmi_register_smi); +EXPORT_SYMBOL(ipmi_add_smi); static void deliver_smi_err_response(struct ipmi_smi *intf, struct ipmi_smi_msg *msg, diff --git a/include/linux/ipmi_smi.h b/include/linux/ipmi_smi.h index 4dc66157d872..deec18b8944a 100644 --- a/include/linux/ipmi_smi.h +++ b/include/linux/ipmi_smi.h @@ -224,10 +224,14 @@ static inline int ipmi_demangle_device_id(uint8_t netfn, uint8_t cmd, * is called, and the lower layer must get the interface from that * call. */ -int ipmi_register_smi(const struct ipmi_smi_handlers *handlers, - void *send_info, - struct device *dev, - unsigned char slave_addr); +int ipmi_add_smi(struct module *owner, + const struct ipmi_smi_handlers *handlers, + void *send_info, + struct device *dev, + unsigned char slave_addr); + +#define ipmi_register_smi(handlers, send_info, dev, slave_addr) \ + ipmi_add_smi(THIS_MODULE, handlers, send_info, dev, slave_addr) /* * Remove a low-level interface from the IPMI driver. This will -- 2.17.1