Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp5912714ybg; Tue, 22 Oct 2019 10:09:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxt8AyuBEAj/Uwf86vnuv7Ethncd9L92vdjIx22F3rnd+JEk7z0vR2NrptK9xyvy0NyNWKB X-Received: by 2002:a17:906:f249:: with SMTP id gy9mr7580591ejb.216.1571764188917; Tue, 22 Oct 2019 10:09:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571764188; cv=none; d=google.com; s=arc-20160816; b=M5hbiyhV9H6jV1x/RXS1DfzgCL6KqSvQMk7CSuNJAwPjl0WfqwvnbPrw9lIE55i18v HgEPbOz+jCG/VCy3uaqAErKxxGbj5fCnI/hIUslmiopsLh3qGu8MGcjKq2ik2ORMwv1t v7L/LbYi6RDfjKmFWujzRG1FsBqluM1hUmshepZjtUL7AnU8U9WT1drSPap8my/R//u3 PyeHlE1WQeS/sz+aZrrFteNQrwalmZNAWUdCPN5D9LvTXkHm8Gx5mjkZ9OrYby/VB8to lfdLKCcd6eIYtQe/+9mTHGElQKhC6mKGer7k31T8kstIq0McR/kdLNEE7ckwwmE+BOpQ DN0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=nT+qu+mK4nExh9asL6QEuobL9f44sXZzjJ8OGH3zTLs=; b=f0jK9JbBciKxBrIMkAwYpR1+5BFSI6rp8UwL88aexsWKTPsH4kYj7dZawzEwk9znyl L3xUxKri3FzXpDeANnO1tpf/lCj6nd1Dj7FA/qm/ylXpEwk81LBQQOxJb8y0J+Rekn6e IVqBhVniGxEQ2V6H2hKLmRlluMMMEbFElEEAt4RL/x9kS6xyTr2qV3pzawjz/GhfZ20M 4ifu36xTtH21WNAxq+oH5+DO6sXQB0IAFE4CwFkEPu6c0G9EQYk4WKyCIKhOiCWrJv26 ISWigns996d6Z9FlGRvsNMj0es2mLS2jf3w8eUIHCocPHbO2f1CsydXsOUOWyJ9FFZYu u48w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=jiPaNGgo; 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 rh23si10624787ejb.75.2019.10.22.10.09.24; Tue, 22 Oct 2019 10:09:48 -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=jiPaNGgo; 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 S2388969AbfJVP4e (ORCPT + 99 others); Tue, 22 Oct 2019 11:56:34 -0400 Received: from mail-oi1-f195.google.com ([209.85.167.195]:36219 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388930AbfJVP4d (ORCPT ); Tue, 22 Oct 2019 11:56:33 -0400 Received: by mail-oi1-f195.google.com with SMTP id k20so14622264oih.3 for ; Tue, 22 Oct 2019 08:56:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:reply-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=nT+qu+mK4nExh9asL6QEuobL9f44sXZzjJ8OGH3zTLs=; b=jiPaNGgo/CgQHcG9hfGwIIOkxf9tMHIdDesTkpbw5BbUzbEqEV6xfyrtz4XCd9lRzQ mmIzdQDOE1drZYsdxFVBmGEVPkM8Kcr0cWpt8ptN3i9XLbDJ1i+xYPJXhNdNQ/wGAByX lS1ah5yqFODjchjAYkMNETyQQ/h4dT73uNZKi4TDjGcZcPPqQuE2g7Hpy+nj8svXQvK/ rajQmCMj3kS5Dpw6BSbWmSaT53Ik0aealOGhGh9fX5zX7LEDLS/B9UtECrLH9lvlYeMa GvJ1TDuHHY869jclQ3MrlN+4qVb7IFKHupanLxHUhvL/tk/GK/DxSvX9z1hOevFxRcgh y1Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :reply-to:references:mime-version:content-disposition:in-reply-to :user-agent; bh=nT+qu+mK4nExh9asL6QEuobL9f44sXZzjJ8OGH3zTLs=; b=V1wswbbzpm9MbvQ60w8/xN9jJUgdc1DPYTCaaCsfzjWs/jVhni7/P5Tky1AEtP3pM5 dWISXJTong8MYJJloScXSgajeViCIwDGdEQjRDE5kTK6uO8ROpuvGO7dQYPSC4OTr2q2 18EiaKG4gnWrtAU425nujuOln+k5IDtWLFN+tmuWQZgfR100ICMl942fG1y1NGoP7mgX JrvOPWbg2vaj+m3HDgWagqncVA51rxx7CxgcYqaIiwe7wiFPvTpC7kxsPGzPVW6U/LEg f+1ku4CFh6pLWCol7EjxvJRHhZmHtWPE3JYR1gIFvXtQc/XnSduRIHP663+MPABcHX1Z EOew== X-Gm-Message-State: APjAAAUAO4KkQtYJhXHdOpivcrmERyKFtjDMqOjlAvksflW4ssw+h3AY OfzkVIYb6SjfnPTNnhSdPA== X-Received: by 2002:aca:f1d7:: with SMTP id p206mr3671009oih.97.1571759792068; Tue, 22 Oct 2019 08:56:32 -0700 (PDT) Received: from serve.minyard.net ([47.184.136.59]) by smtp.gmail.com with ESMTPSA id s1sm5145646otd.49.2019.10.22.08.56.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2019 08:56:31 -0700 (PDT) Received: from t560 (unknown [192.168.27.180]) by serve.minyard.net (Postfix) with ESMTPSA id EAB7B180044; Tue, 22 Oct 2019 15:56:30 +0000 (UTC) Date: Tue, 22 Oct 2019 10:56:29 -0500 From: Corey Minyard To: Tony Camuso Cc: openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, Corey Minyard Subject: Re: [PATCH] ipmi: Don't allow device module unload when in use Message-ID: <20191022155629.GU14232@t560> Reply-To: minyard@acm.org References: <20191014134141.GA25427@t560> <20191014154632.11103-1-minyard@acm.org> <28065598-c638-07eb-d966-0e85ce62c37f@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <28065598-c638-07eb-d966-0e85ce62c37f@redhat.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 22, 2019 at 10:29:12AM -0400, Tony Camuso wrote: > Corey, > > Testing shows that this patch works as expected. Thanks, I'll add a Tested-by for you. It's queued for the next merge window. -corey > > Regards, > Tony > > > On 10/14/19 11:46 AM, minyard@acm.org wrote: > > 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 > > >