linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roman Zippel <zippel@linux-m68k.org>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: Werner Almesberger <wa@almesberger.net>, <kuznet@ms2.inr.ac.ru>,
	<davem@redhat.com>, <kronos@kronoz.cjb.net>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [RFC] Migrating net/sched to new module interface
Date: Fri, 14 Feb 2003 12:16:54 +0100 (CET)	[thread overview]
Message-ID: <Pine.LNX.4.44.0302141035270.1336-100000@serv> (raw)
In-Reply-To: <20030214020901.22E6C2C002@lists.samba.org>

Hi,

On Fri, 14 Feb 2003, Rusty Russell wrote:

> When you have an object which may vanish, the linux kernel idiom runs
> something like this:
> 
> 	write_lock()
> 	find available object in list
> 	inc object refcount
> 	write_unlock()
> 
> The writelock protects the infrastructure, the refcount protects the
> object.  Deleting is done in two stages (mark deleted and drop
> refcount, then whoever drops the refcount to 0 actually does the
> free).  Usually "mark deleted" means simply remove from the list, but
> not always.
> 
> The current module code uses exactly the same idiom for the code
> itself: we use a heavily read-optimized lock, but that's an
> implementation detail.

It's not the same, please see: 
http://marc.theaimsgroup.com/?l=linux-kernel&m=104284223130775&w=2
I explained why the current module locking is more complex and why it's 
actually a three stage delete.

Let's take an example: procfs entries. That's a more interesting example, 
because these can be dynamically created, but they also include pointers 
to the module.
To keep it simple we create/remove an entry from a nonmodular kernel (so 
module functions are dummies):

	foo_entry = create_proc_entry();
	foo_entry->data = kmalloc();
	foo_entry->read_proc = foo_read;
	foo_entry->write_proc = foo_write;

Problem 1: If the user opens that new proc entry, he must be prepared that 
the new entry is not fully initialized yet.
Problem 2: There are no memory barriers, that means it's undefined in 
which order the data, read_proc, write_proc members arrive at another 
cpu, so it's possible that foo_read/foo_write can be called with a NULL 
data pointer.

Now let's remove it again:

	data = foo_entry->data;
	remove_proc_entry();
	kfree(data);

Problem: Should the entry still be busy, procfs just prints a warning, 
delays cleanup and returns immediately, so the data can be accessed after 
it was freed.

Now we do the same from a module but not from module_init/module_exit, 
that means we dynamically want to create/remove entries during the module 
life time. When we create the entry we also initialize the owner member, 
but this doesn't help with any of the above problems. The only thing 
module locking changes is that we know that it's safe to free the data at 
the time module_exit is called, but this might happen in the distant 
future or even never.

Rusty, above are real problems, the module locking fixes these problems 
during module_init/module_exit, but how can these problems fixed in the 
other cases and how does the module locking help?

bye, Roman


  parent reply	other threads:[~2003-02-14 11:07 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-02 22:50 [RFC] Migrating net/sched to new module interface Kronos
2003-01-03  5:10 ` Rusty Russell
2003-01-03  8:37   ` David S. Miller
2003-01-04  6:09     ` Rusty Russell
2003-01-04 16:21       ` Kronos
2003-01-13 22:32   ` kuznet
2003-01-13 23:23     ` Max Krasnyansky
2003-01-14 17:49     ` Kronos
2003-01-15  0:21       ` Roman Zippel
2003-01-15  1:19         ` kuznet
2003-01-15  7:31           ` Werner Almesberger
2003-01-15  8:16             ` Rusty Russell
2003-01-15  9:33               ` Werner Almesberger
2003-01-16  1:12                 ` Rusty Russell
2003-01-16  2:42                   ` Werner Almesberger
2003-01-16  3:31                     ` Rusty Russell
2003-01-16  4:20                       ` Werner Almesberger
2003-01-16  4:25                       ` David S. Miller
2003-01-16  4:49                         ` Werner Almesberger
2003-01-16 16:05                         ` Roman Zippel
2003-01-16 18:15                     ` Roman Zippel
2003-01-16 18:58                       ` Werner Almesberger
2003-01-16 23:53                         ` Roman Zippel
2003-01-17  1:04                           ` Greg KH
2003-01-17  2:27                     ` Rusty Russell
2003-01-17 21:40                       ` Roman Zippel
2003-02-13 23:16                       ` Werner Almesberger
2003-02-14  1:57                         ` Rusty Russell
2003-02-14  3:44                           ` Werner Almesberger
2003-02-14 11:16                           ` Roman Zippel [this message]
2003-02-14 12:04                             ` Rusty Russell
2003-02-14 12:49                               ` Roman Zippel
2003-02-17  1:59                                 ` Rusty Russell
2003-02-17 10:53                                   ` Roman Zippel
2003-02-17 23:31                                     ` Rusty Russell
2003-02-18 12:26                                       ` Roman Zippel
2003-02-14 13:21                               ` Roman Zippel
2003-02-14 13:53                                 ` Werner Almesberger
2003-02-14 14:24                                   ` Roman Zippel
2003-02-14 18:30                                     ` Werner Almesberger
2003-02-14 20:09                                       ` Roman Zippel
2003-02-15  0:12                                         ` Werner Almesberger
2003-02-15  0:51                                           ` Roman Zippel
2003-02-15  2:28                                             ` Werner Almesberger
2003-02-15 23:20                                               ` Roman Zippel
2003-02-17 17:04                                                 ` Werner Almesberger
2003-02-17 23:09                                                   ` [RFC] Is an alternative module interface needed/possible? Roman Zippel
2003-02-18  1:18                                                     ` Werner Almesberger
2003-02-18  4:54                                                       ` Rusty Russell
2003-02-18  7:20                                                         ` Werner Almesberger
2003-02-18 12:06                                                           ` Roman Zippel
2003-02-18 14:12                                                             ` Werner Almesberger
2003-02-18 12:45                                                               ` Thomas Molina
2003-02-18 17:22                                                               ` Werner Almesberger
2003-02-19  3:30                                                                 ` Rusty Russell
2003-02-19  4:11                                                                   ` Werner Almesberger
2003-02-19 23:38                                                                     ` Rusty Russell
2003-02-20  9:46                                                                       ` Roman Zippel
2003-02-20  0:40                                                                 ` Roman Zippel
2003-02-20  2:17                                                                   ` Werner Almesberger
2003-02-23 16:02                                                                     ` Roman Zippel
2003-02-26 23:26                                                                       ` Werner Almesberger
2003-02-27 12:34                                                                         ` Roman Zippel
2003-02-27 13:20                                                                           ` Werner Almesberger
2003-02-27 14:33                                                                             ` Roman Zippel
2003-02-23 23:34                                                                 ` Kevin O'Connor
2003-02-24 12:14                                                                   ` Roman Zippel
2003-02-18 12:35                                                           ` Roman Zippel
2003-02-18 14:14                                                             ` Werner Almesberger
2003-02-19  1:48                                                       ` Roman Zippel
2003-02-19  2:27                                                         ` Werner Almesberger
2003-01-16 13:44                   ` [RFC] Migrating net/sched to new module interface Roman Zippel
2003-01-15 17:04               ` Roman Zippel

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=Pine.LNX.4.44.0302141035270.1336-100000@serv \
    --to=zippel@linux-m68k.org \
    --cc=davem@redhat.com \
    --cc=kronos@kronoz.cjb.net \
    --cc=kuznet@ms2.inr.ac.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=wa@almesberger.net \
    /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;
as well as URLs for NNTP newsgroup(s).