This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: memcmp-sse4.S EqualHappy bug
- From: Rich Felker <dalias at libc dot org>
- To: Andrea Arcangeli <aarcange at redhat dot com>
- Cc: Szabolcs Nagy <nsz at port70 dot net>, libc-alpha at sourceware dot org, "H.J. Lu" <hongjiu dot lu at intel dot com>
- Date: Thu, 18 Jun 2015 00:46:20 -0400
- Subject: Re: memcmp-sse4.S EqualHappy bug
- Authentication-results: sourceware.org; auth=none
- References: <20150617172903 dot GC4317 at redhat dot com> <20150617185952 dot GE22285 at port70 dot net> <20150617210612 dot GB14955 at redhat dot com>
On Wed, Jun 17, 2015 at 11:06:12PM +0200, Andrea Arcangeli wrote:
> On Wed, Jun 17, 2015 at 08:59:52PM +0200, Szabolcs Nagy wrote:
> > c11 has threads and a memory model that makes concurrency issues
> > observable in standard c.
> >
> > however you have a data race that is undefined behaviour:
> >
> > objects passed to memcmp are not supposed to be modified concurrently
> > without synchronization.
>
> All right, I expected this was not a bug by the standard.
>
> In my initial test code I had a contended pthread mutex at the start
> of the page that was passed to memcmp, I wasn't flipping bits myself,
> but I guess that's still undefined behavior if it's
> pthread_mutex_lock/unlock that are changing the memory passed to memcmp.
>
> > that is unfortunate but i think your test code should be fixed.
>
> That's ok, I already fixed it my test code after realizing the
> problem or it wouldn't run correctly on most x86-64 out there.
>
> > (to avoid the observed behaviour the libc would have to guarantee
> > atomic memcmp which is nontrivial to do)
>
> The end of the memory passed to memcmp is never changing and it is
> always different. I didn't expect an atomic behavior within the part
> of the page that is being changed, full atomicity is not to be
> expected and it was never provided by any version.
This is why undefined behavior is program-global (and in both space
and time). As soon as you invoke undefined behavior anywhere (e.g. a
data race), anything can happen, or can already have happened in the
past relative to point of UB.
Rich