From: Greg Kroah-Hartman <gregkh@linuxfoundation.org> To: zhangfei <zhangfei.gao@linaro.org> Cc: Arnd Bergmann <arnd@arndb.de>, Herbert Xu <herbert@gondor.apana.org.au>, jonathan.cameron@huawei.com, dave.jiang@intel.com, grant.likely@arm.com, jean-philippe <jean-philippe@linaro.org>, Jerome Glisse <jglisse@redhat.com>, ilias.apalodimas@linaro.org, francois.ozog@linaro.org, kenneth-lee-2012@foxmail.com, Wangzhou <wangzhou1@hisilicon.com>, "haojian . zhuang" <haojian.zhuang@linaro.org>, guodong.xu@linaro.org, linux-accelerators@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, iommu@lists.linux-foundation.org, Kenneth Lee <liguozhu@hisilicon.com>, Zaibo Xu <xuzaibo@huawei.com> Subject: Re: [PATCH v11 2/4] uacce: add uacce driver Date: Tue, 14 Jan 2020 15:59:34 +0100 [thread overview] Message-ID: <20200114145934.GA1960403@kroah.com> (raw) In-Reply-To: <053ccd05-4f11-5be6-47c2-eee5c2f1fdc4@linaro.org> On Mon, Jan 13, 2020 at 11:34:55AM +0800, zhangfei wrote: > Hi, Greg > > Thanks for the review. > > On 2020/1/12 上午3:40, Greg Kroah-Hartman wrote: > > On Sat, Jan 11, 2020 at 10:48:37AM +0800, Zhangfei Gao wrote: > > > +static int uacce_fops_open(struct inode *inode, struct file *filep) > > > +{ > > > + struct uacce_mm *uacce_mm = NULL; > > > + struct uacce_device *uacce; > > > + struct uacce_queue *q; > > > + int ret = 0; > > > + > > > + uacce = xa_load(&uacce_xa, iminor(inode)); > > > + if (!uacce) > > > + return -ENODEV; > > > + > > > + if (!try_module_get(uacce->parent->driver->owner)) > > > + return -ENODEV; > > Why are you trying to grab the module reference of the parent device? > > Why is that needed and what is that going to help with here? > > > > This shouldn't be needed as the module reference of the owner of the > > fileops for this module is incremented, and the "parent" module depends > > on this module, so how could it be unloaded without this code being > > unloaded? > > > > Yes, if you build this code into the kernel and the "parent" driver is a > > module, then you will not have a reference, but when you remove that > > parent driver the device will be removed as it has to be unregistered > > before that parent driver can be removed from the system, right? > > > > Or what am I missing here? > The refcount here is preventing rmmod "parent" module after fd is opened, > since user driver has mmap kernel memory to user space, like mmio, which may > still in-use. > > With the refcount protection, rmmod "parent" module will fail until > application free the fd. > log like: rmmod: ERROR: Module hisi_zip is in use But if the "parent" module is to be unloaded, it has to unregister the "child" device and that will call the destructor in here and then you will tear everything down and all should be good. There's no need to "forbid" a module from being unloaded, even if it is being used. Look at all networking drivers, they work that way, right? > > > +static void uacce_release(struct device *dev) > > > +{ > > > + struct uacce_device *uacce = to_uacce_device(dev); > > > + > > > + kfree(uacce); > > > + uacce = NULL; > > That line didn't do anything :) > Yes, this is a mistake. > It is up to caller to set to NULL to prevent release multi times. Release function is called by the driver core which will not touch the value again. thanks, greg k-h
WARNING: multiple messages have this Message-ID (diff)
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org> To: zhangfei <zhangfei.gao@linaro.org> Cc: jean-philippe <jean-philippe@linaro.org>, dave.jiang@intel.com, Herbert Xu <herbert@gondor.apana.org.au>, Arnd Bergmann <arnd@arndb.de>, francois.ozog@linaro.org, linux-accelerators@lists.ozlabs.org, ilias.apalodimas@linaro.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Jerome Glisse <jglisse@redhat.com>, grant.likely@arm.com, "haojian . zhuang" <haojian.zhuang@linaro.org>, linux-crypto@vger.kernel.org, Kenneth Lee <liguozhu@hisilicon.com>, guodong.xu@linaro.org, kenneth-lee-2012@foxmail.com Subject: Re: [PATCH v11 2/4] uacce: add uacce driver Date: Tue, 14 Jan 2020 15:59:34 +0100 [thread overview] Message-ID: <20200114145934.GA1960403@kroah.com> (raw) In-Reply-To: <053ccd05-4f11-5be6-47c2-eee5c2f1fdc4@linaro.org> On Mon, Jan 13, 2020 at 11:34:55AM +0800, zhangfei wrote: > Hi, Greg > > Thanks for the review. > > On 2020/1/12 上午3:40, Greg Kroah-Hartman wrote: > > On Sat, Jan 11, 2020 at 10:48:37AM +0800, Zhangfei Gao wrote: > > > +static int uacce_fops_open(struct inode *inode, struct file *filep) > > > +{ > > > + struct uacce_mm *uacce_mm = NULL; > > > + struct uacce_device *uacce; > > > + struct uacce_queue *q; > > > + int ret = 0; > > > + > > > + uacce = xa_load(&uacce_xa, iminor(inode)); > > > + if (!uacce) > > > + return -ENODEV; > > > + > > > + if (!try_module_get(uacce->parent->driver->owner)) > > > + return -ENODEV; > > Why are you trying to grab the module reference of the parent device? > > Why is that needed and what is that going to help with here? > > > > This shouldn't be needed as the module reference of the owner of the > > fileops for this module is incremented, and the "parent" module depends > > on this module, so how could it be unloaded without this code being > > unloaded? > > > > Yes, if you build this code into the kernel and the "parent" driver is a > > module, then you will not have a reference, but when you remove that > > parent driver the device will be removed as it has to be unregistered > > before that parent driver can be removed from the system, right? > > > > Or what am I missing here? > The refcount here is preventing rmmod "parent" module after fd is opened, > since user driver has mmap kernel memory to user space, like mmio, which may > still in-use. > > With the refcount protection, rmmod "parent" module will fail until > application free the fd. > log like: rmmod: ERROR: Module hisi_zip is in use But if the "parent" module is to be unloaded, it has to unregister the "child" device and that will call the destructor in here and then you will tear everything down and all should be good. There's no need to "forbid" a module from being unloaded, even if it is being used. Look at all networking drivers, they work that way, right? > > > +static void uacce_release(struct device *dev) > > > +{ > > > + struct uacce_device *uacce = to_uacce_device(dev); > > > + > > > + kfree(uacce); > > > + uacce = NULL; > > That line didn't do anything :) > Yes, this is a mistake. > It is up to caller to set to NULL to prevent release multi times. Release function is called by the driver core which will not touch the value again. thanks, greg k-h _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2020-01-14 14:59 UTC|newest] Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-01-11 2:48 [PATCH v11 0/4] Add uacce module for Accelerator Zhangfei Gao 2020-01-11 2:48 ` Zhangfei Gao 2020-01-11 2:48 ` [PATCH v11 1/4] uacce: Add documents for uacce Zhangfei Gao 2020-01-11 2:48 ` Zhangfei Gao 2020-01-11 2:48 ` [PATCH v11 2/4] uacce: add uacce driver Zhangfei Gao 2020-01-11 2:48 ` Zhangfei Gao 2020-01-11 19:40 ` Greg Kroah-Hartman 2020-01-11 19:40 ` Greg Kroah-Hartman 2020-01-13 3:34 ` zhangfei 2020-01-13 3:34 ` zhangfei 2020-01-14 14:59 ` Greg Kroah-Hartman [this message] 2020-01-14 14:59 ` Greg Kroah-Hartman 2020-01-15 11:18 ` zhangfei 2020-01-15 11:18 ` zhangfei 2020-01-15 12:02 ` Greg Kroah-Hartman 2020-01-15 12:02 ` Greg Kroah-Hartman 2020-01-15 14:11 ` zhangfei 2020-01-15 14:11 ` zhangfei 2020-01-15 16:43 ` Dave Jiang 2020-01-15 16:43 ` Dave Jiang 2020-01-16 2:11 ` zhangfei 2020-01-16 2:11 ` zhangfei 2020-01-11 2:48 ` [PATCH v11 3/4] crypto: hisilicon - Remove module_param uacce_mode Zhangfei Gao 2020-01-11 2:48 ` Zhangfei Gao 2020-01-11 2:48 ` [PATCH v11 4/4] crypto: hisilicon - register zip engine to uacce Zhangfei Gao 2020-01-11 2:48 ` Zhangfei Gao
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200114145934.GA1960403@kroah.com \ --to=gregkh@linuxfoundation.org \ --cc=arnd@arndb.de \ --cc=dave.jiang@intel.com \ --cc=francois.ozog@linaro.org \ --cc=grant.likely@arm.com \ --cc=guodong.xu@linaro.org \ --cc=haojian.zhuang@linaro.org \ --cc=herbert@gondor.apana.org.au \ --cc=ilias.apalodimas@linaro.org \ --cc=iommu@lists.linux-foundation.org \ --cc=jean-philippe@linaro.org \ --cc=jglisse@redhat.com \ --cc=jonathan.cameron@huawei.com \ --cc=kenneth-lee-2012@foxmail.com \ --cc=liguozhu@hisilicon.com \ --cc=linux-accelerators@lists.ozlabs.org \ --cc=linux-crypto@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=wangzhou1@hisilicon.com \ --cc=xuzaibo@huawei.com \ --cc=zhangfei.gao@linaro.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.