Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Issue 2753203002: Annotate the benign race in ScriptForbiddenScope::isScriptForbidden(). (Closed)

Created:
3 years, 9 months ago by esprehn
Modified:
3 years, 9 months ago
CC:
blink-reviews, chromium-reviews, kinuko+watch
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Annotate the benign race in ScriptForbiddenScope::isScriptForbidden(). BUG=700713

Patch Set 1 #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+4 lines, -0 lines) Patch
M third_party/WebKit/Source/platform/ScriptForbiddenScope.h View 2 chunks +4 lines, -0 lines 2 comments Download

Messages

Total messages: 12 (6 generated)
esprehn
3 years, 9 months ago (2017-03-17 03:51:09 UTC) #4
inferno
+cc Alex, our TSAN expert who can review this.
3 years, 9 months ago (2017-03-17 04:05:17 UTC) #6
Alexander Potapenko
Not lgtm https://codereview.chromium.org/2753203002/diff/1/third_party/WebKit/Source/platform/ScriptForbiddenScope.h File third_party/WebKit/Source/platform/ScriptForbiddenScope.h (right): https://codereview.chromium.org/2753203002/diff/1/third_party/WebKit/Source/platform/ScriptForbiddenScope.h#newcode56 third_party/WebKit/Source/platform/ScriptForbiddenScope.h:56: WTF_ANNOTATE_BENIGN_RACE(&s_scriptForbiddenCount, Please no. WTF_ANNOTATE_BENIGN_RACE is a beast ...
3 years, 9 months ago (2017-03-17 10:14:50 UTC) #9
Alexander Potapenko
For the record, I've filed https://crbug.com/702558 to remove all benign race annotations from the codebase.
3 years, 9 months ago (2017-03-17 10:41:26 UTC) #10
esprehn
Explain why this is not safe? In all the common cases this value is zero. ...
3 years, 9 months ago (2017-03-17 12:48:34 UTC) #11
Alexander Potapenko
3 years, 9 months ago (2017-03-17 13:05:57 UTC) #12
On 2017/03/17 12:48:34, esprehn wrote:
> Explain why this is not safe?
Because this is undefined behavior from the C++ Standard point of view.
The compiler is free to assume your program does not have races, and break it
otherwise.
And compilers are only getting smarter these days.

> In all the common cases this value is zero. If
> it's not zero we only care about it on the main thread. Reading a value has no
> side effects on the underlying memory so I'm not sure why this wouldn't be
safe.
This would've been true if you were writing in assembly, where you control every
memory access and their ordering, but not in C++.
Some of the consequences are described in
http://static.usenix.org/event/hotpar11/tech/final_files/Boehm.pdf and
https://software.intel.com/en-us/blogs/2013/01/06/benign-data-races-what-coul...

> I swapped these on purpose to avoid the TLS lookup on main which is important.
> There's no way to only read it on main, the script execution code is the same
on
> all threads.
If you really want to read this variable every time, you can use relaxed atomics
(they are called nobarrier in base::subtle).
If s_scriptForbiddenCount has state associated with it (probably it hasn't), you
need acquire/release atomics instead.

Powered by Google App Engine
This is Rietveld 408576698