Re: question: spinlocks and userspace.

Ingo Molnar (mingo@chiara.csoma.elte.hu)
Wed, 10 Nov 1999 11:24:30 +0100 (CET)


On Wed, 10 Nov 1999, Tigran Aivazian wrote:

> walk through some linked list {
> for each element take a bit thereof and append to supplied user buf
> }
>
> If I wished to protect the linked list with a spinlock I need to redesign
> the loop and the only way I can think of is to temporarily store those
> elements in kernel buffer and then copy the lot to userspace. But as the
> size of the acumulated buffers is not known in advance the whole thing is
> not as trivial as it should be.

the problem itself is the nontrivial one. You are trying to take a
spinlock-protected 'snapshot' of an indefinit-length kernel-space object,
and that is a nontrivial concept. The 'easy' solution is to give up
atomicity.

> (in particular, I was thinking about qm_modules() that copies
> module->name to user buffer one at a time and I wanted to protect
> module_list with a rw spinlock, taking read_lock in this case).

do you really need atomicity of the list? There are many places in the
kernel which have a spinlock-protected loop, and once they have the
potential to sleep they drop the lock and restart the loop.
truncate_inode_pages() is one example.

-- mingo

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/