mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Keith Owens <kaos@ocs.com.au>
To: Thunder from the hill <thunder@ngforever.de>
Cc: Patrick Mochel <mochel@osdl.org>, linux-kernel@vger.kernel.org
Subject: Re: Driverfs updates
Date: Tue, 09 Jul 2002 10:09:37 +1000	[thread overview]
Message-ID: <22049.1026173377@ocs3.intra.ocs.com.au> (raw)
In-Reply-To: Your message of "Mon, 08 Jul 2002 17:52:13 CST." <Pine.LNX.4.44.0207081745150.10105-100000@hawkeye.luckynet.adm>

On Mon, 8 Jul 2002 17:52:13 -0600 (MDT), 
Thunder from the hill <thunder@ngforever.de> wrote:
>Hi,
>
>On Tue, 9 Jul 2002, Keith Owens wrote:
>> struct device_driver * get_driver(struct device_driver * drv)
>> {
> +        struct device_driver *ret = NULL;
> +
> +        if (!drv)
> +                goto out;
> +        lock_somehow(drv->lock);
> +        if (drv->owner)
>>                 if (!try_inc_mod_count(drv->owner))
> +                        goto out;
> +
> +        ret = drv;
> + out:
> +        unlock_somehow(drv->lock);
> +        return ret;
>> }
>> 
>> I suggest you add a global driverfs_lock.
>
>Better than locking all kernel threads, isn't it?

What protects drv in that code?  drv is a dynamically registered object
and can be dynamically unregistered and freed at any time from another
cpu, or even the same cpu with preempt.  Any reference to drv without
an external lock or a reference count on the module that registered drv
is racy.  In particular, you cannot use drv->anything to protect drv!

The global driverfs_lock is required to protect the bus/drv list
against changes while you are processing an entry on the list AND that
entry is in a module with a use count of 0.  In that state, you have an
uncounted reference to module data which must be protected until you
can set the use count, at which point the use count will take over and
protect the structure.

Did I mention that this method is complex and fragile?


  reply	other threads:[~2002-07-09  0:07 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-08 18:41 Patrick Mochel
2002-07-08 23:33 ` Keith Owens
2002-07-08 23:52   ` Thunder from the hill
2002-07-09  0:09     ` Keith Owens [this message]
2002-07-09  8:30     ` Oliver Neukum
2002-07-09 11:08       ` Thunder from the hill
2002-07-09 11:45         ` Richard B. Johnson
2002-07-09 12:20           ` David D. Hagood
2002-07-09 12:33             ` Thunder from the hill
2002-07-09 14:43             ` jbradford
2002-07-10  7:15             ` jw schultz
2002-07-09 17:05         ` Oliver Neukum
2002-07-10  0:43         ` Pavel Machek
2002-07-09 16:56   ` Patrick Mochel
2002-07-09 23:29     ` Keith Owens
2002-07-10 20:02       ` Patrick Mochel
2002-07-11  0:40     ` John Alvord
2002-07-18 18:11 driverfs updates Patrick Mochel
2002-07-18 18:33 ` Greg KH
2002-07-18 19:57   ` Patrick Mochel

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=22049.1026173377@ocs3.intra.ocs.com.au \
    --to=kaos@ocs.com.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mochel@osdl.org \
    --cc=thunder@ngforever.de \
    /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®