public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Paul Pluzhnikov <ppluzhnikov@google.com>
To: Vitaly Buka <vitalybuka@google.com>
Cc: GLIBC Devel <libc-alpha@sourceware.org>
Subject: Re: [PATCH] stdlib: Fix data race in __run_exit_handlers
Date: Tue, 20 Apr 2021 16:40:03 -0700	[thread overview]
Message-ID: <CALoOobMYBX+ZXEfiLFSpcLDRoF=Lv--_pPUDz_YHgDor4e+v9A@mail.gmail.com> (raw)
In-Reply-To: <CAPjTjwvXtGUBQri2rtz3xfB5C0FOhhUUMDU=sQYaikwxeZZCyQ@mail.gmail.com>

On Tue, Apr 20, 2021 at 3:51 PM Vitaly Buka <vitalybuka@google.com> wrote:

>> > +static void *cb_arg = NULL;
>> > +static void
>> > +add_handlers (void)
>> > +{
>> > +  int n = 10;
>> > +  for (int i = 0; i < n; ++i)
>> > +    __cxa_atexit (&atexit_cb, ++cb_arg, 0);
>>
>> add_handlers() is called from many threads. This code appears to race on cb_arg.
>
>
> We don't have a data race as add_handlers is called from a single background thread.
> Previous patches had more threads but they didn't help to reproduce the issues.

Thanks.

I think cb_arg can be moved into add_handlers() and doesn't have to be
static anymore (if it were a local, there wouldn't be a question of a
race in the first place).

I've looked at the code and the first data race description at the
start of this thread.
I agree that this is the right fix for it.

I have not yet understood the second interaction (between
__run_exit_handlers and __new_exitfn), but I am not sure I really need
to: the patch seems correct.

One other change I would make is to move the unlock before
PTR_DEMANGLE (since it doesn't use any of the data guarded by this
lock).





--
Paul Pluzhnikov

  reply	other threads:[~2021-04-20 23:40 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-20  9:57 Vitaly Buka
2020-09-20 12:09 ` Vitaly Buka
2020-09-20 20:41   ` Paul Pluzhnikov
2020-09-20 21:26     ` Vitaly Buka
2020-09-20 23:36       ` Vitaly Buka
2020-09-20 23:37         ` Vitaly Buka
2020-09-21  8:31           ` Vitaly Buka
2020-09-30 16:01             ` Joseph Myers
2021-04-17 16:16               ` Vitaly Buka
2021-04-17 17:11                 ` Vitaly Buka
2021-04-17 17:13                   ` Vitaly Buka
2021-04-17 17:22                     ` Vitaly Buka
2021-04-17 18:01                       ` Paul Pluzhnikov
2021-04-20 22:51                         ` Vitaly Buka
2021-04-20 23:40                           ` Paul Pluzhnikov [this message]
2021-04-26 19:20                             ` Vitaly Buka
2021-04-26 19:23                               ` Vitaly Buka
2021-04-26 19:27                                 ` Vitaly Buka
2021-05-13 13:15                                   ` Adhemerval Zanella
2021-05-14  6:50                                     ` Vitaly Buka
2021-04-17 17:36               ` Paul Pluzhnikov
2021-04-17 20:19                 ` Florian Weimer
2021-04-19  2:48                   ` Vitaly Buka
2021-04-19  2:57                     ` Vitaly Buka

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='CALoOobMYBX+ZXEfiLFSpcLDRoF=Lv--_pPUDz_YHgDor4e+v9A@mail.gmail.com' \
    --to=ppluzhnikov@google.com \
    --cc=libc-alpha@sourceware.org \
    --cc=vitalybuka@google.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).