Understanding and Genera-ng High Quality Patches for Concurrency - - PowerPoint PPT Presentation

understanding and genera ng high quality patches for
SMART_READER_LITE
LIVE PREVIEW

Understanding and Genera-ng High Quality Patches for Concurrency - - PowerPoint PPT Presentation

1 Understanding and Genera-ng High Quality Patches for Concurrency Bugs Haopeng Liu , Yuxi Chen and Shan Lu 2 What are concurrency bugs Synchroniza-on mistakes in mul--threaded programs 3 What are concurrency bugs Synchroniza-on


slide-1
SLIDE 1

1

Understanding and Genera-ng High Quality Patches for Concurrency Bugs

Haopeng Liu, Yuxi Chen and Shan Lu

slide-2
SLIDE 2

2

What are concurrency bugs

  • Synchroniza-on mistakes in mul--threaded

programs

slide-3
SLIDE 3

3

What are concurrency bugs

  • Synchroniza-on mistakes in mul--threaded

programs

//child thread if(…){ unlock(f->mut); return; } //parent thread f->mut = NULL;

slide-4
SLIDE 4

4

What are concurrency bugs

  • Synchroniza-on mistakes in mul--threaded

programs

//child thread if(…){ unlock(f->mut); return; } //parent thread f->mut = NULL;

slide-5
SLIDE 5

5

What are concurrency bugs

  • Synchroniza-on mistakes in mul--threaded

programs

//child thread if(…){ unlock(f->mut); return; } //parent thread f->mut = NULL;

slide-6
SLIDE 6

6

Concurrency bugs need to be fixed

  • Prevalence

– Widely exist in mul--threaded programs

  • Seriousness

– Cause real world disasters

  • Difficulty

– Time-consuming to fix [LuASPLOS’08] – Patches are the most error-prone [YinFSE’11]

  • 2X -mes more oXen to be buggy than memory/seman-c bugs
slide-7
SLIDE 7

7

Concurrency bug automated fixing

  • Observa-on:

– Program is correct in most -ming interleavings.

  • Solu-on:

– Only need to remove some bad -ming.

  • add lock-related synchroniza-on [AFix PLDI’11] [CFix OSDI’12] [Grail

FSE’14].

slide-8
SLIDE 8

8

An automated fixing example

//child thread if(…){ unlock(f->mut); + lock(L); + signal(con); + unlock(L); return; } + lock(L); + signal(con); + unlock(L);

//parent thread + lock(L) + while(…){ + wait(con, L); + } + unlock (L) f->mut = NULL;

  • Overall:

– 9 new synchroniza-ons – 1 new while loop

Reality is even worse!

slide-9
SLIDE 9

9

The manual patch

//child thread if(…){ unlock(f->mut); return; } //parent thread + thread_join(…); f->mut = NULL;

Simpler patch à Easier to read and maintain

  • Overall:

– New sycn.: 1 VS. 9 – New while loop: 0 VS. 1

Can we automa7cally generate such simple patches?

slide-10
SLIDE 10

10

  • Manual patch study

– 77 real-world concurrency bugs – The limita-on of exis-ng techniques – Guidance to design new tools

  • HFix

Contribu-ons

[1] Guoliang Jin etc. AFix. In PLDI’11 [2] Guoliang Jin etc. CFix. In OSDI’12 [3] Peng Liu etc. Grail. In FSE’14

Bug Reports Bug Reports Bug Reports Bug Reports Bug Reports

AFix[1] CFix[2] Grail[3] … HFix

slide-11
SLIDE 11

11

Outline

  • Mo-va-on
  • Manual patch study
  • HFix
  • Evalua-on
  • Conclusion
slide-12
SLIDE 12

12

Research Ques-ons

  • Q1: Do manual patches mostly use lock-

related synchroniza-ons?

  • Q2: Do manual patches mostly disable buggy
  • ming by adding synchroniza-on ops?
slide-13
SLIDE 13

13

Manual patch study methodology[1]

  • Study developer patches & on-line discussion

[1] Threads to validity are listed in paper. [2] Guoliang Jin etc. AFix. In PLDI’11 [3] Guoliang Jin etc. CFix. In OSDI’12 [4] Wei Zhang etc. ConSeq. In ASPLOS’11

App. Source Descrip7on #. Bugs Apache Lu ASPLOS’08 Web Server 13 Mozilla Browser Suite 41 MySQL Database Server 12 OpenOffice Office Suite 5 Misc Recent papers[2-4] 6 Total 77

slide-14
SLIDE 14

14

Q1: How many patches use lock?

Use Sync. primi7ves?

Yes None

slide-15
SLIDE 15

15

Q1: How many patches use lock?

Use Sync. primi7ves?

Yes None AV patches OV patches

Synchroniza7on primi7ves

Lock/Con. Var Create/Join Misc.

slide-16
SLIDE 16

16

Q1: How many patches use lock?

Use Sync. primi7ves?

Yes None AV patches OV patches

Synchroniza7on primi7ves

Lock/Con. Var Create/Join Misc.

slide-17
SLIDE 17

17

Q1: How many patches use lock?

Use Sync. primi7ves?

Yes None AV patches OV patches

Synchroniza7on primi7ves

Lock/Con. Var Create/Join Misc.

slide-18
SLIDE 18

18

Q1: How many patches use lock?

P R

Threadpc Threadr

C

Use Sync. primi7ves?

Yes None AV patches OV patches

Synchroniza7on primi7ves

Lock/Con. Var Create/Join Misc.

slide-19
SLIDE 19

19

Q1: How many patches use lock?

P R

Threadpc Threadr

C

Use Sync. primi7ves?

Yes None AV patches OV patches

Synchroniza7on primi7ves

Lock/Con. Var Create/Join Misc.

slide-20
SLIDE 20

20

Q1: How many patches use lock?

A B

ThreadA ThreadB

P R

Threadpc Threadr

C

Use Sync. primi7ves?

Yes None AV patches OV patches

Synchroniza7on primi7ves

Lock/Con. Var Create/Join Misc.

slide-21
SLIDE 21

21

Q1: How many patches use lock?

A B

ThreadA ThreadB

P R

Threadpc Threadr

C

Use Sync. primi7ves?

Yes None AV patches OV patches

Synchroniza7on primi7ves

Lock/Con. Var Create/Join Misc.

slide-22
SLIDE 22

22

Q1 implica-on

  • Use non-lock synchroniza-on to fix OV.

AV patches OV patches

Synchroniza7on primi7ves

Lock/Con. Var Create/Join Misc.

slide-23
SLIDE 23

23

Q1 implica-on

  • Use non-lock synchroniza-on to fix OV.

AV patches OV patches

Synchroniza7on primi7ves

Lock/Con. Var Create/Join Misc.

slide-24
SLIDE 24

24

Q2: What are developers’ fix strategy?

Disable Tolerate

slide-25
SLIDE 25

25

Q2: What are developers’ fix strategy?

Disable (Adds)[1-3] Tolerate

[1] Guoliang Jin etc. AFix. In PLDI’11 [2] Guoliang Jin etc. CFix. In OSDI’12 [3] Peng Liu etc. Grail.In FSE’14

slide-26
SLIDE 26

26

Q2: What are developers’ fix strategy?

Disable (Adds) Disable (Data priv.)[1] Tolerate

[1] Jeff Huang etc.Execu-on Priva-za-on of Scheduler-Oblivious Concurrent Programs. In OOPSLA’11

slide-27
SLIDE 27

27

Q2: What are developers’ fix strategy?

Disable (Adds) Disable (Data priv.) Disable (Moves) Tolerate

slide-28
SLIDE 28

28

Q2: What are developers’ fix strategy?

Disable (Adds) Disable (Data priv.) Disable (Moves) Disable (Bypass) Tolerate

slide-29
SLIDE 29

29

Q2 implica-on

  • Add-Sync widely applies, but oXen not best
  • Need to automate:

– Move synchroniza-on – Bypass – Tolerate

  • Different bugs are suitable different strategies

Disable (Adds) Disable (Data priv.) Disable (Moves) Disable (Bypass) Tolerate

slide-30
SLIDE 30

30

Outline

  • Mo-va-on
  • Manual patch studying
  • HFix

– HFixJoin – HFixmove

  • Evalua-on
  • Conclusion
slide-31
SLIDE 31

31

HFix overview

A B

ThdA ThdB

P R

Thdpc Thdr

C

  • Goal:

– Fix bugs with simple patches – Do not introduce new bugs

Code transform Sta-c analysis Code transform Sta-c analysis

HFixJoin HFixMove

HFix

slide-32
SLIDE 32

32

HFixjoin Intui-on

  • Which kind of bugs can be fixed by HFixjoin?

A

ThreadA ThreadB

B Scre

create

slide-33
SLIDE 33

33

HFixjoin Intui-on

  • Which kind of bugs can be fixed by HFixjoin?

A

ThreadA ThreadB

B Scre

create

slide-34
SLIDE 34

34

HFixjoin

  • Step1: Suitability checking

– Goal: do not introduce new bugs.

  • Step2: Insert join synchroniza-on

– Goal: fix the bug

slide-35
SLIDE 35

35

Suitability checking (sta-c analysis)

  • Is ThreadA a joinable child thread of ThreadB?
  • Only one ThreadB?
  • Is ThreadA already joined?
  • Will there be deadlock/severe performance

slow-down?

A

ThreadA ThreadB

B Scre

create

slide-36
SLIDE 36

36

Suitability checking (sta-c analysis)

  • Is ThreadA a joinable child thread of ThreadB?
  • Only one ThreadB?
  • Is ThreadA already joined?
  • Will there be deadlock/severe performance

slow-down?

//parent thread + thread_join(…); fp = NULL; signal(condV); //child thread fputs(fp,…); wait(condV);

slide-37
SLIDE 37

37

  • Insert join before opera-on B
  • Patch Example

Insert join synchroniza-on

//child thread if(…){ unlock(f->mut); return; } //parent thread pthread_create(&tid,…) ... f->mut = NULL;

slide-38
SLIDE 38

38

  • Insert join before opera-on B
  • Patch Example

Insert join synchroniza-on

//child thread if(…){ unlock(f->mut); return; } //parent thread pthread_create(&tid,…) ... f->mut = NULL; tmp = tid; pthread_join(tmp);

slide-39
SLIDE 39

39

A

HFixmove Intui-on

  • What kind of bugs can be fixed by HFixmove?

ThreadA ThreadB

B Scre

create

(a) Movecreate fixes OV bug move-up A or move-down S

slide-40
SLIDE 40

40

A*

HFixmove Intui-on

  • What kind of bugs can be fixed by HFixmove?

ThreadA ThreadB

B Scre

create

(a) Movecreate fixes OV bug move-up A or move-down S

A

ThreadA ThreadB

B Sjoin

join

(b) Movejoin fixes OV bug move-up S or move-down B

slide-41
SLIDE 41

41

A*

HFixmove Intui-on

  • What kind of bugs can be fixed by HFixmove?

ThreadA ThreadB

B Scre

create

(a) Movecreate fixes OV bug move-up A or move-down S

A

ThreadA ThreadB

Sjoin

join

(b) Movejoin fixes OV bug move-up S or move-down B

p

Threadpc Threadr

r c Sunlock

ck

(c) Moveunlock fixes AV bug move-up c or move-down S

p

Threadpc Threadr

r c Slock

ck

(d) Movelock fixes AV bug move-up S or move-down p

B*

slide-42
SLIDE 42

42

Step1: iden-fy two opera-ons to move

(a) Movecreate fixes OV bug move-up A or move-down S (b) Movejoin fixes OV bug move-up S or move-down B (c) Moveunlock fixes AV bug move-up c or move-down S (d) Movelock fixes AV bug move-up S or move-down p

ThreadA ThreadB

B Scre

create

A

ThreadA ThreadB

Sjoin

join

p

Threadpc Threadr

r Sunlock

ck

Threadpc Threadr

r c Slock

ck

B* C* P* A*

slide-43
SLIDE 43

43

Step1: iden-fy two opera-ons to move

X X Y Y

(a) Movecreate fixes OV bug move-up A or move-down S (b) Movejoin fixes OV bug move-up S or move-down B (c) Moveunlock fixes AV bug move-up c or move-down S (d) Movelock fixes AV bug move-up S or move-down p

ThreadA ThreadB

B Scre

create

A

ThreadA ThreadB

Sjoin

join

p

Threadpc Threadr

r Sunlock

ck

Threadpc Threadr

r c Slock

ck

B* C* P* A*

slide-44
SLIDE 44

44

Step 2: decide the moving des-na-on X*

  • Goal

# of execu-ons of X == # of execu-ons of X*

slide-45
SLIDE 45

45

X* Y Naïve sol

Strawman solu-on doesn’t work

# of execu-ons of X ≠ # of execu-ons of X* 1≠0

Y X AXer moving, X* does not execute. Originally, X executes once.

slide-46
SLIDE 46

46

Strawman solu-on doesn’t work

Y X X* Y Naïve sol Originally, X executes once. AXer moving, X* executes more than once.

# of execu-ons of X ≠ # of execu-ons of X* 1≠𝑂

slide-47
SLIDE 47

47

HFixmove demonstra-on

Y X

* X and Y are inside the same func-on; neither is in loop

  • Guarantee: X* will execute exactly once before Y.
slide-48
SLIDE 48

48

HFixmove demonstra-on

Y X Y X

* X and Y are inside the same func-on; neither is in loop

  • Guarantee: X* will execute exactly once before Y.
slide-49
SLIDE 49

49

HFixmove demonstra-on

Y X Y X

* X and Y are inside the same func-on; neither is in loop

  • Guarantee: X* will execute exactly once before Y.
slide-50
SLIDE 50

50

HFixmove demonstra-on

Y X Y X Our solu-on Y X* X* X* X*

* X and Y are inside the same func-on; neither is in loop

  • Guarantee: X* will execute exactly once before Y.
slide-51
SLIDE 51

51

HFixmove demonstra-on

Y X Y X Y X Our solu-on Y X* X* X* X*

* X and Y are inside the same func-on; neither is in loop

  • Guarantee: X* will execute exactly once before Y.
slide-52
SLIDE 52

52

HFixmove demonstra-on

Y X Y X Y X Y X Our solu-on Y X* X* Our solu-on Y X* X* X* X*

* X and Y are inside the same func-on; neither is in loop

  • Guarantee: X* will execute exactly once before Y.
slide-53
SLIDE 53

53

  • Does move change local def-use rela-onship?

Step 3: suitability checking

+ gX = m; s_create(…); m = 0; gX = m;

slide-54
SLIDE 54

54

  • Does move change local def-use rela-onship?

Step 3: suitability checking

+ gX = m; s_create(…); m = 0; gX = m;

slide-55
SLIDE 55

55

  • Does move change local def-use rela-onship?

Step 3: suitability checking

+ gX = m; s_create(…); m = 0; gX = m;

slide-56
SLIDE 56

56

  • Does move change local def-use rela-onship?
  • Might move introduce deadlocks?

Step 3: suitability checking

+ gX = m; s_create(…); m = 0;

slide-57
SLIDE 57

57

HFixmove patch example

//child thread assert(h->band); //parent thread pthread_create(…) ... + h->band = bdNew(h);

  • h->band = bdNew(h);
slide-58
SLIDE 58

58

Outline

  • Mo-va-on
  • Manual patch studying
  • HFix
  • Evalua-on

– Methodology – Results

  • Conclusion
slide-59
SLIDE 59

59

Methodology

  • Benchmark Suite

– 13 bugs set up by Cfix [OSDI’12] – All the AV bugs in ASPLOS’08 suite that are fixed through moving synchroniza-on by developers.

slide-60
SLIDE 60

60

Results for OV bugs

App. FFT HTTrack Mozilla PBZIP2 Transmission X264 ZSNES HFix VS. Manual

  • join

join create join create

✗ ✓ ✓ ✓ ✓ ✓

✗ ✗

slide-61
SLIDE 61

61

Results for OV bugs

App. FFT HTTrack Mozilla PBZIP2 Transmission X264 ZSNES HFix Strategy #.Sync 1

  • 1

CFix Strategy #.Sync 5 3 2 5 2 7 3 join join create join create signal/wait signal/wait signal/wait signal/wait signal/wait signal/wait signal/wait

slide-62
SLIDE 62

62

App. Apache Mozilla1 Mozilla2 MySQL1 MySQL2 MySQL3

Results for AV bugs

HFix lock lock unlock unlock unlock

slide-63
SLIDE 63

63

Outline

  • Mo-va-on
  • Manual patch studying
  • HFix
  • Evalua-on
  • Conclusion
slide-64
SLIDE 64

64

Conclusion

  • Manual patch study:

– Add join for OV (HFix) – Move exis-ng sync. (HFix) – Bypass & tolerate (Future work)

  • HFix

– A useful complement. – Generate much simple patches.

Disable (Adds) Disable (Data priv.) Disable (Moves) Disable (Bypass) Tolerate

slide-65
SLIDE 65

65

Thank you! Q&A