On Mon, Jan 13, 2020 at 11:34:55AM +0800, zhangfei wrote:Thanks Greg for the kind suggestion.
Hi, GregBut if the "parent" module is to be unloaded, it has to unregister the
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:The refcount here is preventing rmmod "parent" module after fd is opened,
+static int uacce_fops_open(struct inode *inode, struct file *filep)Why are you trying to grab the module reference of the parent device?
+{
+ 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 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?
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
"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?
Yes, I understand, it's my mistake. Will remove it.Release function is called by the driver core which will not touch theYes, this is a mistake.+static void uacce_release(struct device *dev)That line didn't do anything :)
+{
+ struct uacce_device *uacce = to_uacce_device(dev);
+
+ kfree(uacce);
+ uacce = NULL;
It is up to caller to set to NULL to prevent release multi times.
value again.