Skip to content

Commit

Permalink
Merge git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-f…
Browse files Browse the repository at this point in the history
…or-linus

* git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus:
  stop_machine: make stop_machine_run more virtualization friendly
  doc: add a chapter about trylock functions [Bug 9011]
  modules: proper cleanup of kobject without CONFIG_SYSFS
  module loading ELF handling: use SELFMAG instead of numeric constant
  • Loading branch information
Linus Torvalds committed May 23, 2008
2 parents 5e2daeb + 3401a61 commit cb61896
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
25 changes: 25 additions & 0 deletions Documentation/DocBook/kernel-locking.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,31 @@
</sect1>
</chapter>

<chapter id="trylock-functions">
<title>The trylock Functions</title>
<para>
There are functions that try to acquire a lock only once and immediately
return a value telling about success or failure to acquire the lock.
They can be used if you need no access to the data protected with the lock
when some other thread is holding the lock. You should acquire the lock
later if you then need access to the data protected with the lock.
</para>

<para>
<function>spin_trylock()</function> does not spin but returns non-zero if
it acquires the spinlock on the first try or 0 if not. This function can
be used in all contexts like <function>spin_lock</function>: you must have
disabled the contexts that might interrupt you and acquire the spin lock.
</para>

<para>
<function>mutex_trylock()</function> does not suspend your task
but returns non-zero if it could lock the mutex on the first try
or 0 if not. This function cannot be safely used in hardware or software
interrupt contexts despite not sleeping.
</para>
</chapter>

<chapter id="Examples">
<title>Common Examples</title>
<para>
Expand Down
18 changes: 15 additions & 3 deletions kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1337,15 +1337,27 @@ int mod_sysfs_setup(struct module *mod,
kobject_put(&mod->mkobj.kobj);
return err;
}
#endif

static void mod_sysfs_fini(struct module *mod)
{
kobject_put(&mod->mkobj.kobj);
}

#else /* CONFIG_SYSFS */

static void mod_sysfs_fini(struct module *mod)
{
}

#endif /* CONFIG_SYSFS */

static void mod_kobject_remove(struct module *mod)
{
module_remove_modinfo_attrs(mod);
module_param_sysfs_remove(mod);
kobject_put(mod->mkobj.drivers_dir);
kobject_put(mod->holders_dir);
kobject_put(&mod->mkobj.kobj);
mod_sysfs_fini(mod);
}

/*
Expand Down Expand Up @@ -1780,7 +1792,7 @@ static struct module *load_module(void __user *umod,

/* Sanity checks against insmoding binaries or wrong arch,
weird elf version */
if (memcmp(hdr->e_ident, ELFMAG, 4) != 0
if (memcmp(hdr->e_ident, ELFMAG, SELFMAG) != 0
|| hdr->e_type != ET_REL
|| !elf_check_arch(hdr)
|| hdr->e_shentsize != sizeof(*sechdrs)) {
Expand Down
7 changes: 4 additions & 3 deletions kernel/stop_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ static int stopmachine(void *cpu)
* help our sisters onto their CPUs. */
if (!prepared && !irqs_disabled)
yield();
else
cpu_relax();
cpu_relax();
}

/* Ack: we are exiting. */
Expand Down Expand Up @@ -106,8 +105,10 @@ static int stop_machine(void)
}

/* Wait for them all to come to life. */
while (atomic_read(&stopmachine_thread_ack) != stopmachine_num_threads)
while (atomic_read(&stopmachine_thread_ack) != stopmachine_num_threads) {
yield();
cpu_relax();
}

/* If some failed, kill them all. */
if (ret < 0) {
Expand Down

0 comments on commit cb61896

Please sign in to comment.