This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Async signal safe TLS accesses
- From: Andrew Hunter <ahh at google dot com>
- To: Paul Pluzhnikov <ppluzhnikov at google dot com>
- Cc: "Joseph S. Myers" <joseph at codesourcery dot com>, Rich Felker <dalias at aerifal dot cx>, GNU C Library <libc-alpha at sourceware dot org>, Allan McRae <allan at archlinux dot org>, "Carlos O'Donell" <carlos at redhat dot com>, Adhemerval Zanella <azanella at linux dot vnet dot ibm dot com>
- Date: Fri, 10 Jan 2014 11:32:30 -0800
- Subject: Re: [PATCH] Async signal safe TLS accesses
- Authentication-results: sourceware.org; auth=none
- References: <52C4DC54 dot 4000109 at redhat dot com> <1388689454-1854-1-git-send-email-ahh at google dot com> <CALoOobPio5625ws7dSWepgQbKmqHifvbU3tKWtKFS-tz_zihdQ at mail dot gmail dot com> <CADroS=7BBPbJ5bAUUy5VUWHX+gCrRmrEk17qO-s9zkdVNeFbxA at mail dot gmail dot com> <20140103074522 dot GT24286 at brightrain dot aerifal dot cx> <CADroS=49b8c8KCiNF2cHHRk5nPmy8LzYYF_x=GZfOCCQORkx8A at mail dot gmail dot com> <CALoOobNz=FzbSkJdPMFwqnFdpyNcAy8vDDEftj+vbMT5r8mJAw at mail dot gmail dot com> <Pine dot LNX dot 4 dot 64 dot 1401081752130 dot 1349 at digraph dot polyomino dot org dot uk> <CALoOobM6R+ua_0ffxRdaS_h69oUJ_+CoidxvLi+U_tdvJZY3dg at mail dot gmail dot com> <Pine dot LNX dot 4 dot 64 dot 1401082122230 dot 8625 at digraph dot polyomino dot org dot uk> <CALoOobMWsgbAjupv7Cj0-Xz0ND+TNinj26TquvEwZXM+BjfgiA at mail dot gmail dot com> <Pine dot LNX dot 4 dot 64 dot 1401090233380 dot 8625 at digraph dot polyomino dot org dot uk> <CALoOobOHjd+8guXBEsHuO=FtiPFRED4Zb=qDdTvEHr=01nRwHg at mail dot gmail dot com> <Pine dot LNX dot 4 dot 64 dot 1401091544010 dot 21172 at digraph dot polyomino dot org dot uk> <52CEC6DD dot 9010800 at google dot com> <Pine dot LNX dot 4 dot 64 dot 1401091634520 dot 21172 at digraph dot polyomino dot org dot uk> <CALoOobMW_Bk_vnjGmqfP665FNGwe8zWAm4na0FJk29OH=8KdPA at mail dot gmail dot com>
FWIW that patch looks good to me -- sorry for missing the obvious race
there in the original.
On Fri, Jan 10, 2014 at 10:28 AM, Paul Pluzhnikov
<ppluzhnikov@google.com> wrote:
> On Thu, Jan 9, 2014 at 8:42 AM, Joseph S. Myers <joseph@codesourcery.com> wrote:
>
>> Maybe have the signal handler outside the loaded module call the function
>> from the loaded module, but with sem_post in the function outside the
>> module? I haven't tested whether this fixes the powerpc problem, but it
>> should avoid the identified race with the module being dlclosed while code
>> from it is executing. (There would of course then be the need to have
>> memory barriers to ensure the current pointer obtained from dlsym is
>> available from the thread calling the signal handler - and it would be
>> necessary to ensure that the test does still show up the non-signal-safety
>> if run with older glibc.)
>
> Could you please test attached proposed fix?
>
> It passes on x86_64 (ran 1000 times), and immediately self-deadlocks using
> system (i.e. older) glibc-2.15 like so:
>
> (gdb) bt
> #0 __lll_lock_wait_private () at
> ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:93
> #1 0x00007f2dc9adf231 in _L_lock_10574 () at malloc.c:5241
> #2 0x00007f2dc9adcf87 in __GI___libc_malloc (bytes=139833800392736)
> at malloc.c:2921
> #3 0x00007f2dca23c365 in allocate_and_init (map=0xc78bb0) at dl-tls.c:526
> #4 tls_get_addr_tail (dtv=<optimized out>, the_map=0xc78bb0,
> module=<optimized out>) at dl-tls.c:739
> #5 0x00007f2dca24d5d0 in __tls_get_addr (ti=0x7f2dc524ffb0) at dl-tls.c:764
> #6 0x00007f2dc504f870 in action (signo=<optimized out>,
> info=0x7f2dc9a58b30, ignored=<optimized out>) at tst-tls7mod.c:32
> #7 0x0000000000401913 in action (signo=<optimized out>,
> info=<optimized out>, ignored=<optimized out>) at tst-tls7.c:53
> #8 <signal handler called>
> #9 __memset_sse2 () at ../sysdeps/x86_64/multiarch/../memset.S:44
> #10 0x00007f2dc9ad9f6a in _int_free (av=0x7f2d98000020,
> p=0x7f2d980008b0, have_lock=0) at malloc.c:4101
> #11 0x000000000040174a in spin (ignored=<optimized out>) at tst-tls7.c:37
> #12 0x00007f2dc9e21e9a in start_thread (arg=0x7f2dc9a59700) at
> pthread_create.c:308
> #13 0x00007f2dc9b4e3fd in clone () at
> ../sysdeps/unix/sysv/linux/x86_64/clone.S:112
>
>
> Thanks,
> --
> Paul Pluzhnikov