All of lore.kernel.org
 help / color / mirror / Atom feed
* RTDM module ownership
@ 2020-07-02  8:32 Richard Weinberger
  2020-07-03  6:14 ` Jan Kiszka
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Weinberger @ 2020-07-02  8:32 UTC (permalink / raw)
  To: Xenomai

Hi!

I'm working on a kernel module which is used on plain Linux and
Xenomai (RTDM), while reviewing RTDM to understand refcounting I found
something that is not entirely clear to me.

Why does __rtdm_dev_open() not grab a reference on the RTDM module owner?
This leads to the case where one can rmmod the module while it is in use.
Unloading will block uninterruptible in rtdm_dev_unregister() in the
module's cleanup funktion.

In contrast, on regular Linux rmmod will refuse to unload the module
if the device node is still open because fops_get() or other helpers
gained a reference on the owner.

-- 
Thanks,
//richard


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: RTDM module ownership
  2020-07-02  8:32 RTDM module ownership Richard Weinberger
@ 2020-07-03  6:14 ` Jan Kiszka
  2020-07-03  6:22   ` Richard Weinberger
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Kiszka @ 2020-07-03  6:14 UTC (permalink / raw)
  To: Richard Weinberger, Xenomai

On 02.07.20 10:32, Richard Weinberger via Xenomai wrote:
> Hi!
> 
> I'm working on a kernel module which is used on plain Linux and
> Xenomai (RTDM), while reviewing RTDM to understand refcounting I found
> something that is not entirely clear to me.
> 
> Why does __rtdm_dev_open() not grab a reference on the RTDM module owner?
> This leads to the case where one can rmmod the module while it is in use.
> Unloading will block uninterruptible in rtdm_dev_unregister() in the
> module's cleanup funktion.
> 
> In contrast, on regular Linux rmmod will refuse to unload the module
> if the device node is still open because fops_get() or other helpers
> gained a reference on the owner.
> 

First of all, your driver is apparently not reacting on the close 
request that it receives in that case. This leads the the stall you see.

Still, we could indeed run some module_put/get on open/socket/close. I 
thought we did, but that was once RTnet [1].

Jan

[1] 
https://gitlab.denx.de/Xenomai/xenomai/-/commit/11bbdef0e9486d8f952ea29023882449331af1aa

-- 
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: RTDM module ownership
  2020-07-03  6:14 ` Jan Kiszka
@ 2020-07-03  6:22   ` Richard Weinberger
  2020-07-03  9:10     ` Jan Kiszka
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Weinberger @ 2020-07-03  6:22 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: Richard Weinberger, xenomai

----- Ursprüngliche Mail -----
>> In contrast, on regular Linux rmmod will refuse to unload the module
>> if the device node is still open because fops_get() or other helpers
>> gained a reference on the owner.
>> 
> 
> First of all, your driver is apparently not reacting on the close
> request that it receives in that case. This leads the the stall you see.

Huh? rmmmod triggers close of what?
*confused*
 
> Still, we could indeed run some module_put/get on open/socket/close. I
> thought we did, but that was once RTnet [1].

Yes. Would be nice. :-)

Thanks,
//richard


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: RTDM module ownership
  2020-07-03  6:22   ` Richard Weinberger
@ 2020-07-03  9:10     ` Jan Kiszka
  2020-07-03  9:26       ` Richard Weinberger
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Kiszka @ 2020-07-03  9:10 UTC (permalink / raw)
  To: Richard Weinberger; +Cc: Richard Weinberger, xenomai

On 03.07.20 08:22, Richard Weinberger wrote:
> ----- Ursprüngliche Mail -----
>>> In contrast, on regular Linux rmmod will refuse to unload the module
>>> if the device node is still open because fops_get() or other helpers
>>> gained a reference on the owner.
>>>
>>
>> First of all, your driver is apparently not reacting on the close
>> request that it receives in that case. This leads the the stall you see.
> 
> Huh? rmmmod triggers close of what?
> *confused*
>   

rmmod -> module cleanup -> rtdm_dev_unregister -> rtdm_device_flush_fds

>> Still, we could indeed run some module_put/get on open/socket/close. I
>> thought we did, but that was once RTnet [1].
> 
> Yes. Would be nice. :-)
> 

Just like a patch would be...

Jan

-- 
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: RTDM module ownership
  2020-07-03  9:10     ` Jan Kiszka
@ 2020-07-03  9:26       ` Richard Weinberger
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Weinberger @ 2020-07-03  9:26 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: xenomai

----- Ursprüngliche Mail -----
>>> First of all, your driver is apparently not reacting on the close
>>> request that it receives in that case. This leads the the stall you see.
>> 
>> Huh? rmmmod triggers close of what?
>> *confused*
>>   
> 
> rmmod -> module cleanup -> rtdm_dev_unregister -> rtdm_device_flush_fds

Sure. The driver has a close method where it cleans up everything, of course.
But it can't force userspace to close the fd, Linux has no fd revocation
mechanism.
 
>>> Still, we could indeed run some module_put/get on open/socket/close. I
>>> thought we did, but that was once RTnet [1].
>> 
>> Yes. Would be nice. :-)
>> 
> 
> Just like a patch would be...

Pushed to my TODO...

Thanks,
//richard


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-07-03  9:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-02  8:32 RTDM module ownership Richard Weinberger
2020-07-03  6:14 ` Jan Kiszka
2020-07-03  6:22   ` Richard Weinberger
2020-07-03  9:10     ` Jan Kiszka
2020-07-03  9:26       ` Richard Weinberger

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.