Re: [External] Re: [RFC 3/4] vduse: grab the module's references until there is no vduse device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On Tue, Oct 20, 2020 at 12:41 AM Michael S. Tsirkin <mst@xxxxxxxxxx> wrote:
On Mon, Oct 19, 2020 at 11:56:35PM +0800, 谢永吉 wrote:
>
>
>
> On Mon, Oct 19, 2020 at 11:47 PM Michael S. Tsirkin <mst@xxxxxxxxxx> wrote:
>
>     On Mon, Oct 19, 2020 at 11:44:36PM +0800, 谢永吉 wrote:
>     >
>     >
>     > On Mon, Oct 19, 2020 at 11:05 PM Michael S. Tsirkin <mst@xxxxxxxxxx>
>     wrote:
>     >
>     >     On Mon, Oct 19, 2020 at 10:56:22PM +0800, Xie Yongji wrote:
>     >     > The module should not be unloaded if any vduse device exists.
>     >     > So increase the module's reference count when creating vduse
>     >     > device. And the reference count is kept until the device is
>     >     > destroyed.
>     >     >
>     >     > Signed-off-by: Xie Yongji <xieyongji@xxxxxxxxxxxxx>
>     >     > ---
>     >     >  drivers/vdpa/vdpa_user/vduse_dev.c | 2 ++
>     >     >  1 file changed, 2 insertions(+)
>     >     >
>     >     > diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/
>     vdpa_user/
>     >     vduse_dev.c
>     >     > index 6787ba66725c..f04aa02de8c1 100644
>     >     > --- a/drivers/vdpa/vdpa_user/vduse_dev.c
>     >     > +++ b/drivers/vdpa/vdpa_user/vduse_dev.c
>     >     > @@ -887,6 +887,7 @@ static int vduse_destroy_dev(u32 id)
>     >     >       kfree(dev->vqs);
>     >     >       vduse_iova_domain_destroy(dev->domain);
>     >     >       vduse_dev_destroy(dev);
>     >     > +     module_put(THIS_MODULE);
>     >     > 
>     >     >       return 0;
>     >     >  }
>     >     > @@ -931,6 +932,7 @@ static int vduse_create_dev(struct
>     vduse_dev_config
>     >     *config)
>     >     > 
>     >     >       dev->connected = true;
>     >     >       list_add(&dev->list, &vduse_devs);
>     >     > +     __module_get(THIS_MODULE);
>     >     > 
>     >     >       return fd;
>     >     >  err_fd:
>     >
>     >     This kind of thing is usually an indicator of a bug. E.g.
>     >     if the refcount drops to 0 on module_put(THIS_MODULE) it
>     >     will be unloaded and the following return will not run.
>     >
>     >
>     >
>     > Should this happen?  The refcount should be only decreased to 0 after the
>     > misc_device is closed?
>     >
>     > Thanks,
>     > Yongji
>     >
>
>     OTOH if it never drops to 0 anyway then why do you need to increase it?
>
>
>
> To prevent unloading the module in the case that the device is created, but no
> user process using it (e.g. the user process crashed). 
>
> Thanks,
> Yongji

Looks like it can drop to 0 if that is the case then?

Could you give me an example?  In my understanding, vduse_create_dev() should be called only after we open the chardev which will grab the module's reference.

Thanks,
Yongji

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux