<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/kernel/futex.c, branch linux-2.6.17.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-2.6.17.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-2.6.17.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2006-09-08T21:51:38Z</updated>
<entry>
<title>bug in futex unqueue_me</title>
<updated>2006-09-08T21:51:38Z</updated>
<author>
<name>Christian Borntraeger</name>
</author>
<published>2006-08-30T05:38:11Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=2cd6b01ad38d34b805a0a052725ec3f37e387ecd'/>
<id>urn:sha1:2cd6b01ad38d34b805a0a052725ec3f37e387ecd</id>
<content type='text'>
This patch adds a barrier() in futex unqueue_me to avoid aliasing of two
pointers.

On my s390x system I saw the following oops:

Unable to handle kernel pointer dereference at virtual kernel address
0000000000000000
Oops: 0004 [#1]
CPU:    0    Not tainted
Process mytool (pid: 13613, task: 000000003ecb6ac0, ksp: 00000000366bdbd8)
Krnl PSW : 0704d00180000000 00000000003c9ac2 (_spin_lock+0xe/0x30)
Krnl GPRS: 00000000ffffffff 000000003ecb6ac0 0000000000000000 0700000000000000
           0000000000000000 0000000000000000 000001fe00002028 00000000000c091f
           000001fe00002054 000001fe00002054 0000000000000000 00000000366bddc0
           00000000005ef8c0 00000000003d00e8 0000000000144f91 00000000366bdcb8
Krnl Code: ba 4e 20 00 12 44 b9 16 00 3e a7 84 00 08 e3 e0 f0 88 00 04
Call Trace:
([&lt;0000000000144f90&gt;] unqueue_me+0x40/0xe4)
 [&lt;0000000000145a0c&gt;] do_futex+0x33c/0xc40
 [&lt;000000000014643e&gt;] sys_futex+0x12e/0x144
 [&lt;000000000010bb00&gt;] sysc_noemu+0x10/0x16
 [&lt;000002000003741c&gt;] 0x2000003741c

The code in question is:

static int unqueue_me(struct futex_q *q)
{
        int ret = 0;
        spinlock_t *lock_ptr;

        /* In the common case we don't take the spinlock, which is nice. */
 retry:
        lock_ptr = q-&gt;lock_ptr;
        if (lock_ptr != 0) {
                spin_lock(lock_ptr);
		/*
                 * q-&gt;lock_ptr can change between reading it and
                 * spin_lock(), causing us to take the wrong lock.  This
                 * corrects the race condition.
[...]

and my compiler (gcc 4.1.0) makes the following out of it:

00000000000003c8 &lt;unqueue_me&gt;:
     3c8:       eb bf f0 70 00 24       stmg    %r11,%r15,112(%r15)
     3ce:       c0 d0 00 00 00 00       larl    %r13,3ce &lt;unqueue_me+0x6&gt;
                        3d0: R_390_PC32DBL      .rodata+0x2a
     3d4:       a7 f1 1e 00             tml     %r15,7680
     3d8:       a7 84 00 01             je      3da &lt;unqueue_me+0x12&gt;
     3dc:       b9 04 00 ef             lgr     %r14,%r15
     3e0:       a7 fb ff d0             aghi    %r15,-48
     3e4:       b9 04 00 b2             lgr     %r11,%r2
     3e8:       e3 e0 f0 98 00 24       stg     %r14,152(%r15)
     3ee:       e3 c0 b0 28 00 04       lg      %r12,40(%r11)
		/* write q-&gt;lock_ptr in r12 */
     3f4:       b9 02 00 cc             ltgr    %r12,%r12
     3f8:       a7 84 00 4b             je      48e &lt;unqueue_me+0xc6&gt;
		/* if r12 is zero then jump over the code.... */
     3fc:       e3 20 b0 28 00 04       lg      %r2,40(%r11)
		/* write q-&gt;lock_ptr in r2 */
     402:       c0 e5 00 00 00 00       brasl   %r14,402 &lt;unqueue_me+0x3a&gt;
                        404: R_390_PC32DBL      _spin_lock+0x2
		/* use r2 as parameter for spin_lock */

So the code becomes more or less:
if (q-&gt;lock_ptr != 0) spin_lock(q-&gt;lock_ptr)
instead of
if (lock_ptr != 0) spin_lock(lock_ptr)

Which caused the oops from above.
After adding a barrier gcc creates code without this problem:
[...] (the same)
     3ee:       e3 c0 b0 28 00 04       lg      %r12,40(%r11)
     3f4:       b9 02 00 cc             ltgr    %r12,%r12
     3f8:       b9 04 00 2c             lgr     %r2,%r12
     3fc:       a7 84 00 48             je      48c &lt;unqueue_me+0xc4&gt;
     400:       c0 e5 00 00 00 00       brasl   %r14,400 &lt;unqueue_me+0x38&gt;
                        402: R_390_PC32DBL      _spin_lock+0x2

As a general note, this code of unqueue_me seems a bit fishy. The retry logic
of unqueue_me only works if we can guarantee, that the original value of
q-&gt;lock_ptr is always a spinlock (Otherwise we overwrite kernel memory). We
know that q-&gt;lock_ptr can change. I dont know what happens with the original
spinlock, as I am not an expert with the futex code.

Cc: Martin Schwidefsky &lt;schwidefsky@de.ibm.com&gt;
Cc: Rusty Russell &lt;rusty@rustcorp.com.au&gt;
Acked-by: Ingo Molnar &lt;mingo@redhat.com&gt;
Cc: Thomas Gleixner &lt;tglx@timesys.com&gt;
Signed-off-by: Christian Borntraeger &lt;borntrae@de.ibm.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>[PATCH] futex: check and validate timevals</title>
<updated>2006-03-31T20:18:59Z</updated>
<author>
<name>Thomas Gleixner</name>
</author>
<published>2006-03-31T10:31:32Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9741ef964dc8bfeb6520825df9fed8f538c3336e'/>
<id>urn:sha1:9741ef964dc8bfeb6520825df9fed8f538c3336e</id>
<content type='text'>
The futex timeval is not checked for correctness.  The change does not
break existing applications as the timeval is supplied by glibc (and glibc
always passes a correct value), but the glibc-internal tests for this
functionality fail.

Signed-off-by: Thomas Gleixner &lt;tglx@tglx.de&gt;
Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@osdl.org&gt;
</content>
</entry>
<entry>
<title>[PATCH] lightweight robust futexes updates</title>
<updated>2006-03-27T16:44:49Z</updated>
<author>
<name>Ingo Molnar</name>
</author>
<published>2006-03-27T09:16:27Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=8f17d3a5049d32392b79925c73a0cf99ce6d5af0'/>
<id>urn:sha1:8f17d3a5049d32392b79925c73a0cf99ce6d5af0</id>
<content type='text'>
- fix: initialize the robust list(s) to NULL in copy_process.

- doc update

- cleanup: rename _inuser to _inatomic

- __user cleanups and other small cleanups

Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
Cc: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: Arjan van de Ven &lt;arjan@infradead.org&gt;
Cc: Ulrich Drepper &lt;drepper@redhat.com&gt;
Cc: Andi Kleen &lt;ak@muc.de&gt;
Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@osdl.org&gt;
</content>
</entry>
<entry>
<title>[PATCH] lightweight robust futexes: core</title>
<updated>2006-03-27T16:44:49Z</updated>
<author>
<name>Ingo Molnar</name>
</author>
<published>2006-03-27T09:16:22Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=0771dfefc9e538f077d0b43b6dec19a5a67d0e70'/>
<id>urn:sha1:0771dfefc9e538f077d0b43b6dec19a5a67d0e70</id>
<content type='text'>
Add the core infrastructure for robust futexes: structure definitions, the new
syscalls and the do_exit() based cleanup mechanism.

Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Arjan van de Ven &lt;arjan@infradead.org&gt;
Acked-by: Ulrich Drepper &lt;drepper@redhat.com&gt;
Cc: Michael Kerrisk &lt;mtk-manpages@gmx.net&gt;
Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@osdl.org&gt;
</content>
</entry>
<entry>
<title>[PATCH] FRV: Make futex code compilable on nommu [try #2]</title>
<updated>2006-01-06T16:33:33Z</updated>
<author>
<name>David Howells</name>
</author>
<published>2006-01-06T08:11:44Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7ee1dd3fee22f15728f545d266403fc977e1eb99'/>
<id>urn:sha1:7ee1dd3fee22f15728f545d266403fc977e1eb99</id>
<content type='text'>
Make the futex code compilable and usable on NOMMU by making the attempt to
handle page faults conditional on CONFIG_MMU.  If this is not enabled, then
we can assume that EFAULT returned from futex_atomic_op_inuser() is not
recoverable, and that the address lies outside of valid memory.

handle_mm_fault() is made to BUG if called on NOMMU without attempting to
invoke the actual handler (__handle_mm_fault).

Signed-off-by: David Howells &lt;dhowells@redhat.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@osdl.org&gt;
</content>
</entry>
<entry>
<title>[PATCH] Fix memory ordering problem in wake_futex()</title>
<updated>2005-12-24T20:13:27Z</updated>
<author>
<name>Andrew Morton</name>
</author>
<published>2005-12-24T03:54:46Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=8e31108b9f41069d55cb9b019ac8262c55fd2616'/>
<id>urn:sha1:8e31108b9f41069d55cb9b019ac8262c55fd2616</id>
<content type='text'>
Fix a memory ordering problem that occurs on IA64. The "store" to q-&gt;lock_ptr
in wake_futex() can become visible before wake_up_all() clears the lock in the
futex_q.

Signed-off-by: Jack Steiner &lt;steiner@sgi.com&gt;
Acked-by: Ingo Molnar &lt;mingo@elte.hu&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@osdl.org&gt;
</content>
</entry>
<entry>
<title>[PATCH] mm: unbloat get_futex_key</title>
<updated>2005-11-24T00:08:38Z</updated>
<author>
<name>Hugh Dickins</name>
</author>
<published>2005-11-23T21:37:38Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=cc3327e7dfc16a9a3e164075234c869867a59e45'/>
<id>urn:sha1:cc3327e7dfc16a9a3e164075234c869867a59e45</id>
<content type='text'>
The follow_page changes in get_futex_key have left it with two almost
identical blocks, when handling the rare case of a futex in a nonlinear vma.
get_user_pages will itself do that follow_page, and its additional
find_extend_vma is hardly any overhead since the vma is already cached.  Let's
just delete the follow_page block and let get_user_pages do it.

Signed-off-by: Hugh Dickins &lt;hugh@veritas.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@osdl.org&gt;
</content>
</entry>
<entry>
<title>[PATCH] FUTEX_WAKE_OP: enhanced error handling</title>
<updated>2005-11-07T15:53:38Z</updated>
<author>
<name>David Gibson</name>
</author>
<published>2005-11-07T08:59:33Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=796f8d9b98fc92a5e9aaea8cf932957850332f51'/>
<id>urn:sha1:796f8d9b98fc92a5e9aaea8cf932957850332f51</id>
<content type='text'>
The code for FUTEX_WAKE_OP calls an arch callback,
futex_atomic_op_inuser().  That callback can return an error code, but
currently the caller assumes any error is EFAULT, and will try various
things to resolve the fault before eventually giving up with EFAULT
(regardless of the original error code).  This is not a theoretical case -
arch callbacks currently return -ENOSYS if the opcode they are given is
bogus.

This patch alters the code to detect non-EFAULT errors and return them
directly to the user.

Of course, whether -ENOSYS is the correct return value for the bogus opcode
case, or whether EINVAL would be more appropriate is another question.

Signed-off-by: David Gibson &lt;dwg@au1.ibm.com&gt;
Cc: Rusty Russell &lt;rusty@rustcorp.com.au&gt;
Cc: Ingo Molnar &lt;mingo@elte.hu&gt;
Cc: Jamie Lokier &lt;jamie@shareable.org&gt;
Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@osdl.org&gt;
</content>
</entry>
<entry>
<title>[PATCH] mm: follow_page with inner ptlock</title>
<updated>2005-10-30T04:40:41Z</updated>
<author>
<name>Hugh Dickins</name>
</author>
<published>2005-10-30T01:16:33Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=deceb6cd17e6dfafe4c4f81b1b4153bc41b2cb70'/>
<id>urn:sha1:deceb6cd17e6dfafe4c4f81b1b4153bc41b2cb70</id>
<content type='text'>
Final step in pushing down common core's page_table_lock.  follow_page no
longer wants caller to hold page_table_lock, uses pte_offset_map_lock itself;
and so no page_table_lock is taken in get_user_pages itself.

But get_user_pages (and get_futex_key) do then need follow_page to pin the
page for them: take Daniel's suggestion of bitflags to follow_page.

Need one for WRITE, another for TOUCH (it was the accessed flag before:
vanished along with check_user_page_readable, but surely get_numa_maps is
wrong to mark every page it finds as accessed), another for GET.

And another, ANON to dispose of untouched_anonymous_page: it seems silly for
that to descend a second time, let follow_page observe if there was no page
table and return ZERO_PAGE if so.  Fix minor bug in that: check VM_LOCKED -
make_pages_present ought to make readonly anonymous present.

Give get_numa_maps a cond_resched while we're there.

Signed-off-by: Hugh Dickins &lt;hugh@veritas.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@osdl.org&gt;
</content>
</entry>
<entry>
<title>[PATCH] futex: remove duplicate code</title>
<updated>2005-09-07T23:57:33Z</updated>
<author>
<name>Pekka Enberg</name>
</author>
<published>2005-09-06T22:17:44Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=39ed3fdeec1290dd246dcf1da6b278566987a084'/>
<id>urn:sha1:39ed3fdeec1290dd246dcf1da6b278566987a084</id>
<content type='text'>
This patch cleans up the error path of futex_fd() by removing duplicate
code.

Signed-off-by: Pekka Enberg &lt;penberg@cs.helsinki.fi&gt;
Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@osdl.org&gt;
</content>
</entry>
</feed>
