mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Werner Almesberger <wa@almesberger.net>
To: Bill Davidsen <davidsen@tmr.com>
Cc: Keith Owens <kaos@ocs.com.au>, linux-kernel@vger.kernel.org
Subject: Re: [OKS] Module removal
Date: Thu, 4 Jul 2002 03:29:29 -0300	[thread overview]
Message-ID: <20020704032929.N2295@almesberger.net> (raw)
In-Reply-To: <Pine.LNX.3.96.1020704000434.2248F-100000@gatekeeper.tmr.com>; from davidsen@tmr.com on Thu, Jul 04, 2002 at 12:11:14AM -0400

Bill Davidsen wrote:
> Isn't the right thing to make everything stop using the module before
> ending it, for any definition of ending?

This certainly seems to be the most understandable way, yes. I think
modules follow basically the principle illistrated below (that's case
4b in the taxonomy I posted earlier), where deregistration doesn't
stop everything, but which should be safe except for
return-after-removal:


foo_dispatch(...)
{
    read_lock(global_foo_lock);
    ...
    xxx = find_stuff();
    ...
    xxx->whatever_op(xxx->data);
}

foo_deregister(...)
{
    write_lock(global_foo_lock);
    ...
    write_unlock(global_foo_lock);
}

bar_whatever_op(my_data)
{   
    lock(my_data); /* think MOD_INC_USE_COUNT */
    ...
    read_unlock(global_foo_lock);
    ...
    unlock(my_data); /* think MOD_DEC_USE_COUNT */
    /* return-after-removal race if my_data also protects code,
       not only data ! */
}

bar_main(...)
{
    foo_register(&bar_ops,&bar_data);
    ...
    foo_deregister(&bar_ops);
    ...
    lock(bar_data); /* barrier */
    unlock(bar_data);
    ...
    destroy(&bar_data);
}


/* I'm a lazy bastard for not validating this with something like
   Spin, so there may be races left. */

Now there are quite a few things you can omit, without ever noticing
problems. E.g. the read_unlock from bar_whatever_op could be before
the call to whatever_op in foo_dispatch, and all you get is a tiny
bar_whatever_op vs. destroy race. Likewise, moving the barrier in
bar_main may go unnoticed for a long time. If bar_data is never
destroyed, or synchronized by some other means, most of the locking
is actually superfluous, so in many situations, using this model
without strictly following every single detail is actually okay, at
last as far as data races are concerned.

So I think we need to distinguish the entry-after-removal race and
the return-after-removal race, because the former may also be a data
race, while the latter is typically only a code race. (The latter
becomes a data race if you touch shared data after releasing the
lock, but this would be a fairly obvious mistake.)

The entry-after-removal race is not module specific, and may exist
as a true data race in the kernel. (Didn't search for it - I'm not
happy with the fact that I wouldn't be able to catch it in the act
anyway, so I'd rather play a bit with infrastructure first.)

The return-after-removal race could be solved by not deallocating
module memory, or - probably cheaper, but requiring either code
changes or advanced gcc wizardry - by using decrement_and_return.

By the way, there are cases where MOD_DEC_USE_COUNT is followed by
code other than a direct return, e.g. (arbitrary example) in
drivers/net/aironet4500_core.c

This is correct if we can be sure that the use count never reaches
0 here, but then the whole inc/dec exercise is probably redundant.
("probably" as in "it doesn't have to be, but I'd be surprised if
it isn't"; I'll give an example in a later posting.)

However, if this MOD_DEC_USE_COUNT may ever decrement the count to
zero, we have something worse than the usual return-after-removal
race. This may even be a data race, so such code is suspicious in
any case.

> It seems slightly like that tree falling in the forest, and no one to hear
> it. Much easier to handle removal right than service requests after close. 

I can understand why people don't want to use totally "safe"
deregistration, e.g.

 - locking gets more complex and you may run into hairy deadlock
   scenarios
 - accomplishing timely removal may become more difficult
 - nobody likes patches that change the world

So the entry/return-after-removal issues may still need to be
resolved. I'm mainly worried about entry-after-removal, because
it seems to me that this is likely to imply data races in
non-modules too, so try_inc_mod_count neither sufficient (for it
doesn't help with non-modules) nor required (because fixing the
race would also eliminate entry-after-removal).

I've seen very few reponses to my analysis. Does everybody think
I'm nuts (quite possible :-), or is this worth continuing ?

- Werner

-- 
  _________________________________________________________________________
 / Werner Almesberger, Buenos Aires, Argentina         wa@almesberger.net /
/_http://icapeople.epfl.ch/almesber/_____________________________________/

  reply	other threads:[~2002-07-04  6:23 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-01 20:21 RE2: " Michael Nguyen
2002-07-02  1:40 ` Werner Almesberger
2002-07-02  2:25   ` Keith Owens
2002-07-02  3:11     ` Werner Almesberger
2002-07-02  3:42       ` Keith Owens
2002-07-02  4:11         ` Werner Almesberger
2002-07-02 22:23         ` Alexander Viro
2002-07-09 19:23         ` Russ Lewis
2002-07-02  4:08     ` Brian Gerst
2002-07-02  4:53       ` Keith Owens
2002-07-02  5:43         ` Werner Almesberger
2002-07-02 16:36           ` Werner Almesberger
2002-07-02 16:50             ` Benjamin Herrenschmidt
2002-07-02 18:05               ` Werner Almesberger
2002-07-03  3:50               ` Pavel Machek
2002-07-04  4:11             ` Bill Davidsen
2002-07-04  6:29               ` Werner Almesberger [this message]
2002-07-04  6:50                 ` Werner Almesberger
2002-07-07 21:09                   ` Jamie Lokier
2002-07-07 21:41                     ` Oliver Neukum
2002-07-08  0:31                       ` Jamie Lokier
2002-07-08  6:42                         ` Oliver Neukum
2002-07-08  0:18                     ` Bill Davidsen
2002-07-08  0:46                       ` Jamie Lokier
2002-07-08  6:22                         ` Daniel Phillips
2002-07-08 10:16                           ` Bill Davidsen
2002-07-09  0:07                         ` Werner Almesberger
2002-07-09  0:27                           ` Keith Owens
2002-07-09  3:09                             ` Werner Almesberger
2002-07-09  6:25                             ` Roman Zippel
2002-07-09  8:59                               ` Kai Germaschewski
2002-07-09 11:06                                 ` Roman Zippel
2002-07-04 12:29                 ` Bill Davidsen
2002-07-09  1:50                 ` Kevin O'Connor
2002-07-09  2:37                   ` Werner Almesberger
2002-07-02 23:35         ` Alexander Viro
2002-07-02 22:41       ` RE2: " Alexander Viro
2002-07-02  8:52     ` Helge Hafting
2002-07-02 16:22       ` Werner Almesberger
  -- strict thread matches above, loose matches on Subject: below --
2002-07-02 12:20 Ariel Garcia
2002-07-01 17:48 Bill Davidsen
2002-07-01 18:35 ` Richard B. Johnson
2002-07-01 18:42 ` Jose Luis Domingo Lopez
2002-07-01 18:45   ` Shawn
2002-07-01 19:57 ` Diego Calleja
2002-07-01 20:03   ` Diego Calleja
2002-07-01 22:20   ` Jose Luis Domingo Lopez
2002-07-01 22:56   ` Ryan Anderson
2002-07-02 11:37 ` Stephen C. Tweedie
2002-07-02 12:04   ` Richard B. Johnson
2002-07-02 13:13     ` jlnance
2002-07-02 15:20   ` Bill Davidsen
2002-07-02 15:53     ` Jonathan Corbet
2002-07-02 16:07       ` Oliver Neukum
2002-07-02 17:48         ` Tom Rini
2002-07-02 18:10           ` Oliver Neukum
2002-07-02 21:50             ` Ryan Anderson
2002-07-03 22:26               ` Diego Calleja
2002-07-04  0:00                 ` Keith Owens
2002-07-04  8:04               ` Helge Hafting
2002-07-02 16:08     ` Werner Almesberger
     [not found]   ` <Pine.LNX.3.95.1020702075957.24872A-100000@chaos.analogic.c om>
2002-07-04  8:36     ` Mike Galbraith
2002-07-03  0:09 ` Vojtech Pavlik
2002-07-12 21:51 ` David Lang

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=20020704032929.N2295@almesberger.net \
    --to=wa@almesberger.net \
    --cc=davidsen@tmr.com \
    --cc=kaos@ocs.com.au \
    --cc=linux-kernel@vger.kernel.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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®