Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp944759ybp; Thu, 17 Oct 2019 06:00:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvU4OztCQtX7+QYR+ki8pnZ2EfYFwBCvlDKuV80y0IO+xi71axEJzjyoCfZx9qg0Vm4v5k X-Received: by 2002:a17:906:3009:: with SMTP id 9mr3353514ejz.124.1571317219637; Thu, 17 Oct 2019 06:00:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571317219; cv=none; d=google.com; s=arc-20160816; b=ZubQEnQMDhs0xhUJwPdnaLgBPLlPLK01OcirE4IEUdXYY2/6Re7S3cVUHmKLaCapnT Rx2NA4sA8CUP2NmEO4X82DZ9kZtab36OoG6ABUbI5b5H79hYxZ+oQ0iHBAmhWefad8g6 vyNqNTFr9M+8NKT/YF0EV65Mkcf1L3IeaMDcJp9X47OoTkQt8vvuW9R3mF+XJ9K06TCH 6XAtrTy/JInIJyiXkSSxIq+tOIuVtHyr+j7Y/ZVIfGILR2TenTcxxRw1tFkvmMWyqdGL LPXCVLHrmgk7IpHeR57qhlHjkMhMrL0MmZDYR5gvAIL+MBNjsazrDb8T+RCpKb8pilzy Vd6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=nrWu55OIQ0MlojmewxW5IftP1f1bEnBzJcOau2sWhws=; b=Rnd0LYhXvI/USGS37lRnZhIYBZdkoo9gMgU4EQF3BMC6EZoSt86CkaVxOh1LBy0pSD X8ndQqasniP8+pVvSBz9Tu9FEADSADhp4EDaoYqYsBuzr2nBJEVhvn92Un++mnLAXHyH a+AsBIjRjD9uA8oogBJtisnCBQ5FONKF+Yz2eep7RJMVVBkj/bL9/Aa9l7a5/4vubcfv o6N7tW1K1ik/NZVuOHySj0cDuKZbaojkYrWrwqQefTexJBzii8sargE9pvvpmHI7f+6W IQvMxUCZBqLKe1gPOYdA4IAQgr06jVI2QPYJxTGXYgAjued4Zjr97U40BECOSUtBVnNL NORw== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z7si1527608edb.160.2019.10.17.05.59.56; Thu, 17 Oct 2019 06:00:19 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436758AbfJPTyO (ORCPT + 99 others); Wed, 16 Oct 2019 15:54:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32958 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436685AbfJPTyO (ORCPT ); Wed, 16 Oct 2019 15:54:14 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7FC5118C890F; Wed, 16 Oct 2019 19:54:05 +0000 (UTC) Received: from dhcp-17-182.bos.redhat.com (ovpn-116-165.phx2.redhat.com [10.3.116.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id D88011001925; Wed, 16 Oct 2019 19:54:04 +0000 (UTC) Subject: Re: [PATCH] ipmi: Don't allow device module unload when in use To: minyard@acm.org Cc: openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, Corey Minyard References: <20191014134141.GA25427@t560> <20191014154632.11103-1-minyard@acm.org> <20191016193349.GP14232@t560> From: Tony Camuso Message-ID: Date: Wed, 16 Oct 2019 15:54:04 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.0 MIME-Version: 1.0 In-Reply-To: <20191016193349.GP14232@t560> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.70]); Wed, 16 Oct 2019 19:54:13 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/16/19 3:33 PM, Corey Minyard wrote: > On Wed, Oct 16, 2019 at 03:25:56PM -0400, Tony Camuso wrote: >> 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(-) >> >> Hi Corey. >> >> You changed ipmi_register_ipmi to ipmi_add_ipmi in ipmi_msghandler, but you >> did not change it where it is actually called. >> >> # grep ipmi_register_smi drivers/char/ipmi/*.c >> drivers/char/ipmi/ipmi_powernv.c: rc = ipmi_register_smi(&ipmi_powernv_smi_handlers, ipmi, dev, 0); >> drivers/char/ipmi/ipmi_si_intf.c: rv = ipmi_register_smi(&handlers, >> drivers/char/ipmi/ipmi_ssif.c: rv = ipmi_register_smi(&ssif_info->handlers, >> >> Is there a reason for changing the interface name? Is this something >> that I could do instead of troubling you with it? > > I don't understand. You don't say that anything went wrong, you just > referenced something I changed. > > I changed the name so I could create a macro with that name to pass in > the module name. Pretty standard to do in the kernel. Can't believe I missed that. > Is there a > compile or runtime issue? > > -corey All is well, so far. Haven't finished testing. >> >> Regards, >> Tony >> >> >>> >>> 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 >>> >>