Closed Bug 1158871 Opened 9 years ago Closed 9 years ago

TSan: various data races in cairo (_atomic_fetch, _cairo_surface_allocate_unique_id, etc.)

Categories

(Core :: Graphics, defect)

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla41
Tracking Status
firefox41 --- fixed

People

(Reporter: froydnj, Assigned: lsalzman)

References

(Blocks 1 open bug)

Details

(Whiteboard: [tsan])

Attachments

(1 file)

TSan reports a number of races all related to cairo's atomics support, specifically, this bit:

http://mxr.mozilla.org/mozilla-central/source/gfx/cairo/cairo/src/cairo-atomic-private.h#62

While we do define things appropriately to make cairo use atomic operations in some places, cairo has this secondary ATOMIC_OP_NEEDS_MEMORY_BARRIER check for whether loads need memory barriers prior to the actual load being performed.  ATOMIC_OP_NEEDS_MEMORY_BARRIER is set by cairo's configure, specifically:

http://cgit.freedesktop.org/cairo/tree/build/aclocal.cairo.m4#n203

This hunk seems suspicious to me, as I would have assumed that ARM needs memory barriers since its ordering properties are not as strong as x86.

In any event, even *with* ATOMIC_OP_NEEDS_MEMORY_BARRIER defined, TSan will still be unhappy with the code as-is, because TSan believes the load in:

     __sync_synchronize ();
     return *x;

is still unordered.  TSan really wants to see the load come from a compiler intrinsic, something like:

     return __atomic_load_n(x, __ATOMIC_SEQ_CST);

for recent GCC/Clang.  There is, unfortunately, no equivalently efficient construct with the __sync* family of builtins.  One would have to do something like:

     return __sync_fetch_and_add(x, 0);

I don't know what our policy on patching our local version of cairo is, how willing upstream would be to making ATOMIC_OP_NEEDS_MEMORY_BARRIER go away or fixing the loads under ATOMIC_OP_NEEDS_MEMORY_BARRIER to be observable to TSan.
Assignee: nobody → lsalzman
It would be great if you could file an upstream bug about this issue.
(In reply to Jeff Muizelaar [:jrmuizel] from comment #1)
> It would be great if you could file an upstream bug about this issue.

Is that comment directed at me or at Lee?
Flags: needinfo?(jmuizelaar)
(In reply to Nathan Froyd [:froydnj] [:nfroyd] from comment #2)
> (In reply to Jeff Muizelaar [:jrmuizel] from comment #1)
> > It would be great if you could file an upstream bug about this issue.
> 
> Is that comment directed at me or at Lee?

It was directed at you.
Flags: needinfo?(jmuizelaar)
Looking a little closer, the _freed_pool_get thing is actually its own bug; I'm going to file a new one for that.
Summary: TSan: various data races in cairo (_atomic_fetch, _freed_pool_get, _cairo_surface_allocate_unique_id, etc.) → TSan: various data races in cairo (_atomic_fetch, _cairo_surface_allocate_unique_id, etc.)
I wrote a patch for upstream, we'll see if it gets committed, and then I guess we can backport?
(In reply to Nathan Froyd [:froydnj] [:nfroyd] from comment #5)
> I wrote a patch for upstream, we'll see if it gets committed, and then I
> guess we can backport?

Yes.
The upstream patch has been committed...so now we add it to the ever-growing number of patches in gfx/cairo/, document it in the README, apply the patch, and done?
Flags: needinfo?(jmuizelaar)
(In reply to Nathan Froyd [:froydnj] [:nfroyd] from comment #7)
> The upstream patch has been committed...so now we add it to the ever-growing
> number of patches in gfx/cairo/, document it in the README, apply the patch,
> and done?

Yep.
Flags: needinfo?(jmuizelaar)
Jeff for the cairo part, Ted for the moz.build change.
Attachment #8616004 - Flags: review?(ted)
Attachment #8616004 - Flags: review?(jmuizelaar)
Comment on attachment 8616004 [details] [diff] [review]
use new-style __atomic_* primitives in cairo

Review of attachment 8616004 [details] [diff] [review]:
-----------------------------------------------------------------

I think you could have skipped build peer review for this, but no big deal.
Attachment #8616004 - Flags: review?(ted) → review+
Attachment #8616004 - Flags: review?(jmuizelaar) → review+
https://hg.mozilla.org/mozilla-central/rev/73d75d149938
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla41
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: