aComment : Mining Annotations from Comments and Code to Detect - - PowerPoint PPT Presentation

acomment
SMART_READER_LITE
LIVE PREVIEW

aComment : Mining Annotations from Comments and Code to Detect - - PowerPoint PPT Presentation

aComment : Mining Annotations from Comments and Code to Detect Interrupt-Related Concurrency Bugs Lin Tan , University of Waterloo, lintan@uwaterloo.ca Yuanyuan (YY) Zhou, University of California, San Diego Yoann Padioleau, Facebook Inc. OS


slide-1
SLIDE 1

aComment:

Mining Annotations from Comments and Code to Detect Interrupt-Related Concurrency Bugs

Lin Tan, University of Waterloo, lintan@uwaterloo.ca

Yuanyuan (YY) Zhou, University of California, San Diego Yoann Padioleau, Facebook Inc.

slide-2
SLIDE 2

Lin Tan aComment

OS Concurrency Bugs are a Problem

  • Operating System (OS) concurrency bugs can bring down

all applications running on top of it.

  • OS has a higher percentage of concurrency bugs than

application software. [TanTechReport’11]

  • 19% of OS driver bugs are concurrency bugs. [RyzhykEuroSys’09]

2

  • Concurrency bugs are

pervasive and hard-to-detect.

slide-3
SLIDE 3

Lin Tan aComment

Interrupts Complicate OS Synchronization

3

Thread (T2) Failed Lock Acquisition Lock Acquisition

L L

Lock Release

L

Thread (T1)

slide-4
SLIDE 4

Lin Tan aComment

Interrupts Complicate OS Synchronization

3

Thread (T2)

L

Failed Lock Acquisition Lock Acquisition

L L

Lock Release

L

Thread (T1)

slide-5
SLIDE 5

Lin Tan aComment

Interrupts Complicate OS Synchronization

3

Thread (T2)

L

C

  • n

t e x t S w i t c h Failed Lock Acquisition Lock Acquisition

L L

Lock Release

L

Thread (T1)

slide-6
SLIDE 6

Lin Tan aComment

Interrupts Complicate OS Synchronization

3

Thread (T2)

L

C

  • n

t e x t S w i t c h

L

Failed Lock Acquisition Lock Acquisition

L L

Lock Release

L

Thread (T1)

slide-7
SLIDE 7

Lin Tan aComment

Interrupts Complicate OS Synchronization

3

Thread (T2)

L

C

  • n

t e x t S w i t c h

L

Failed Lock Acquisition Lock Acquisition

L L

Lock Release

L

Thread (T1)

slide-8
SLIDE 8

Lin Tan aComment

Interrupts Complicate OS Synchronization

3

Thread (T2)

L

C

  • n

t e x t S w i t c h

L

Failed Lock Acquisition Lock Acquisition

L L

Lock Release

L

Thread (T1)

slide-9
SLIDE 9

Lin Tan aComment

Interrupts Complicate OS Synchronization

3

Thread (T2)

L

C

  • n

t e x t S w i t c h

L L

Failed Lock Acquisition Lock Acquisition

L L

Lock Release

L

Thread (T1)

slide-10
SLIDE 10

Lin Tan aComment

Interrupts Complicate OS Synchronization

3

Thread (T2)

L

C

  • n

t e x t S w i t c h

L L L

Failed Lock Acquisition Lock Acquisition

L L

Lock Release

L

Thread (T1)

slide-11
SLIDE 11

Lin Tan aComment

4

1

Thread (T1)

Interrupt Handler Thread (TH)

Failed Lock Acquisition Lock Acquisition

L L

Interrupts Complicate OS Synchronization

L

slide-12
SLIDE 12

Lin Tan aComment

4

1

Thread (T1)

Interrupt Handler Thread (TH)

I n t e r r u p t Failed Lock Acquisition Lock Acquisition

L L

Interrupts Complicate OS Synchronization

L

slide-13
SLIDE 13

Lin Tan aComment

4

1

Thread (T1)

Interrupt Handler Thread (TH)

I n t e r r u p t

L

Failed Lock Acquisition Lock Acquisition

L L

Interrupts Complicate OS Synchronization

L

slide-14
SLIDE 14

Lin Tan aComment

4

1

Thread (T1)

Interrupt Handler Thread (TH)

I n t e r r u p t

L

Failed Lock Acquisition Lock Acquisition

L L

Interrupts Complicate OS Synchronization

L

slide-15
SLIDE 15

Lin Tan aComment

4

1

Thread (T1)

Interrupt Handler Thread (TH)

I n t e r r u p t

L

Failed Lock Acquisition Lock Acquisition

L L

Interrupts Complicate OS Synchronization

L

slide-16
SLIDE 16

Lin Tan aComment

4

1

Thread (T1)

Interrupt Handler Thread (TH)

I n t e r r u p t

L

Deadlock

Failed Lock Acquisition Lock Acquisition

L L

Interrupts Complicate OS Synchronization

L

slide-17
SLIDE 17

Lin Tan aComment

D

4

1

Thread (T1)

Interrupt Handler Thread (TH)

I n t e r r u p t

L

Deadlock

Failed Lock Acquisition Lock Acquisition

L L

Should disable interrupts

Interrupts Complicate OS Synchronization

L

slide-18
SLIDE 18

Lin Tan aComment

D

  • Interrupts can also cause other concurrency bugs.
  • Hard to reason about interrupts because
  • Interrupts can happen at anytime.
  • Interrupts are relatively infrequent.
  • OS contains many interrupt handlers.

4

1

Thread (T1)

Interrupt Handler Thread (TH)

I n t e r r u p t

L

Deadlock

Failed Lock Acquisition Lock Acquisition

L L

Should disable interrupts

Interrupts Complicate OS Synchronization

L

slide-19
SLIDE 19

Lin Tan aComment

State-of-Art & Our Solution

  • Most effective concurrency bug detection tools [SavageTOCS’97,

ChoiPLDI’02, LuASPLOS’06, LuSOSP’07, HammerICSE’08, JulaOSDI’08, NaikICSE’09, BurnimICSE’10, LaiICSE’10]

  • do not consider interrupts
  • are dynamic tools designed for user-level applications.
  • Dynamic approaches are cumbersome for OS:
  • difficult to instrument OS, low level, many drivers, large code

sizes, complexity, ...

5

slide-20
SLIDE 20

Lin Tan aComment

State-of-Art & Our Solution

  • Most effective concurrency bug detection tools [SavageTOCS’97,

ChoiPLDI’02, LuASPLOS’06, LuSOSP’07, HammerICSE’08, JulaOSDI’08, NaikICSE’09, BurnimICSE’10, LaiICSE’10]

  • do not consider interrupts
  • are dynamic tools designed for user-level applications.
  • Dynamic approaches are cumbersome for OS:
  • difficult to instrument OS, low level, many drivers, large code

sizes, complexity, ...

5

  • Our Solution: Static approach with interrupts in mind
slide-21
SLIDE 21

Lin Tan aComment

Goal

  • Infer
  • Precondition: If interrupts should have already been

disabled or enabled upon entry to a function, and

  • Postcondition: If interrupts should have already been

disabled or enabled upon exit from the function

6

slide-22
SLIDE 22

Lin Tan aComment

Goal

  • Infer
  • Precondition: If interrupts should have already been

disabled or enabled upon entry to a function, and

  • Postcondition: If interrupts should have already been

disabled or enabled upon exit from the function

6

{

Annotations

slide-23
SLIDE 23

Lin Tan aComment

Goal

  • Infer
  • Precondition: If interrupts should have already been

disabled or enabled upon entry to a function, and

  • Postcondition: If interrupts should have already been

disabled or enabled upon exit from the function

6

{

Annotations

  • From comments and code
slide-24
SLIDE 24

Lin Tan aComment

Goal

  • Infer
  • Precondition: If interrupts should have already been

disabled or enabled upon entry to a function, and

  • Postcondition: If interrupts should have already been

disabled or enabled upon exit from the function

6

{

Annotations

  • From comments and code
  • Detect violations to these annotations

statically

slide-25
SLIDE 25

Lin Tan aComment

Inferring Annotations from Comments & Code

7

linux/kernel/time/tick-oneshot.c: /* … Called with interrupts disabled. */ int tick_init_highres(void) {…}

slide-26
SLIDE 26

Lin Tan aComment

Inferring Annotations from Comments & Code

7

linux/kernel/time/tick-oneshot.c: /* … Called with interrupts disabled. */ int tick_init_highres(void) {…}

/*@IRQ(D, X)*/

slide-27
SLIDE 27

Lin Tan aComment

Inferring Annotations from Comments & Code

7

linux/kernel/time/tick-oneshot.c: /* … Called with interrupts disabled. */ int tick_init_highres(void) {…}

/*@IRQ(D, X)*/

linux/kernel/posix-cpu-timers.c: void run_posix_cpu_timers(…) { BUG_ON(!irqs_disabled()); … }

slide-28
SLIDE 28

Lin Tan aComment

Inferring Annotations from Comments & Code

7

linux/kernel/time/tick-oneshot.c: /* … Called with interrupts disabled. */ int tick_init_highres(void) {…}

/*@IRQ(D, X)*/

linux/kernel/posix-cpu-timers.c: void run_posix_cpu_timers(…) { BUG_ON(!irqs_disabled()); … }

/*@IRQ(D, X)*/

slide-29
SLIDE 29

Lin Tan aComment

Our Contributions

✦ Feasible to extract annotations from comments & code

  • Designed new interrupt-related annotations
  • Generated 96,821 interrupt-related annotations &

automatically detected 9 true bugs in the Linux kernel

  • These annotations can help developers avoid bugs.

✦ Combining comments & code help extract more annotations and detect more bugs than using comments or code alone.

8

slide-30
SLIDE 30

Lin Tan aComment

Outline

  • Motivation & Contributions
  • Annotation Design
  • Annotation Extraction
  • From comments
  • From code
  • Annotation Propagation & Bug Detection
  • Results: Bug Detection & Annotation Extraction
  • Related Work
  • Conclusions

9

slide-31
SLIDE 31

Lin Tan aComment

Annotation Language Design

10

@IRQ (Precondition, Postcondition)

slide-32
SLIDE 32

Lin Tan aComment

Annotation Language Design

10

@IRQ ( D/E/X , D/E/X )

Read our paper for the meaning of value ‘P’.

slide-33
SLIDE 33

Lin Tan aComment

Annotation Language Design

10

Value Meaning D

Interrupts are disabled.

E

Interrupts are enabled.

X

Donʼt care

@IRQ ( D/E/X , D/E/X )

Read our paper for the meaning of value ‘P’.

slide-34
SLIDE 34

Lin Tan aComment

Annotation Language Design

10

Value Meaning D

Interrupts are disabled.

E

Interrupts are enabled.

X

Donʼt care

@IRQ ( D/E/X , D/E/X )

Example Meaning @IRQ (D, D) Interrupts are disabled on entry and remain disabled on exit. @IRQ (X, E)

Don’t-care on entry and interrupts are enabled on exit.

@IRQ (X, X)

Our design choice: Either @IRQ (D, D) or @IRQ (E, E)

Read our paper for the meaning of value ‘P’.

slide-35
SLIDE 35

Lin Tan aComment

Annotation Extraction From Comments

11

Software LOC Sentence IRQSent Linux 5.2M 1,024,624 23,662 FreeBSD 2.4M 420,013 11,117 NetBSD 3.3M 680,650 23,942 OpenSolaris 3.7M 535,073 8,074 Total 14.6M 2,660,360 66,795

  • Millions of lines of comments exist in OSs.
  • We analyze comments as is: No need to rewrite comments.
slide-36
SLIDE 36

Lin Tan aComment

Annotation Extraction From Comments

12

  • /* Neither are the interrupt status bits */ (Linux)
  • /* Called with interrupts disabled. */ (OpenSolaris)
  • /* Disables interrupts before calling this function */ (NetBSD)
  • /* Must be called with interrupts locked out */ (FreeBSD)
slide-37
SLIDE 37

Lin Tan aComment

Annotation Extraction From Comments

12

  • /* Neither are the interrupt status bits */ (Linux)
  • /* Called with interrupts disabled. */ (OpenSolaris)
  • /* Disables interrupts before calling this function */ (NetBSD)
  • /* Must be called with interrupts locked out */ (FreeBSD)

Contains no annotations

slide-38
SLIDE 38

Lin Tan aComment

Annotation Extraction From Comments

12

ID Heuristics 1 <call> & <with> & <interrupt> (ordered) 2 <before> & <disable/enable> & <interrupt> (orderless) 3 <assume> & <disable/enable> & <interrupt> (orderless)

  • /* Neither are the interrupt status bits */ (Linux)
  • /* Called with interrupts disabled. */ (OpenSolaris)
  • /* Disables interrupts before calling this function */ (NetBSD)
  • /* Must be called with interrupts locked out */ (FreeBSD)

Contains no annotations

slide-39
SLIDE 39

Lin Tan aComment

Annotation Extraction From Comments

12

ID Heuristics 1 <call> & <with> & <interrupt> (ordered) 2 <before> & <disable/enable> & <interrupt> (orderless) 3 <assume> & <disable/enable> & <interrupt> (orderless)

  • /* Neither are the interrupt status bits */ (Linux)
  • /* Called with interrupts disabled. */ (OpenSolaris)
  • /* Disables interrupts before calling this function */ (NetBSD)
  • /* Must be called with interrupts locked out */ (FreeBSD)

“disable”, “turn off”, “block”, “lock out”, ...

Contains no annotations

slide-40
SLIDE 40

Lin Tan aComment

Annotation Extraction From Comments

12

ID Heuristics 1 <call> & <with> & <interrupt> (ordered) 2 <before> & <disable/enable> & <interrupt> (orderless) 3 <assume> & <disable/enable> & <interrupt> (orderless)

  • /* Neither are the interrupt status bits */ (Linux)
  • /* Called with interrupts disabled. */ (OpenSolaris)
  • /* Disables interrupts before calling this function */ (NetBSD)
  • /* Must be called with interrupts locked out */ (FreeBSD)
  • Automatically extract function names and the

preconditions (D or E). “disable”, “turn off”, “block”, “lock out”, ...

Contains no annotations

slide-41
SLIDE 41

Lin Tan aComment

linux/kernel/posix-cpu-timers.c: void run_posix_cpu_timers(…) { BUG_ON(!irqs_disabled()); … }

/*@IRQ(D, X)*/

Annotation Extraction From Code Assertions

  • Learn from dynamic assertions
  • Can learn invariants from the majority of code

[ErnstICSE’00], [EnglerSOSP’01], [HangalICSE’02], [LiFSE’05], [LivshitsFSE’05], [TanSecurity’08] ... 13

slide-42
SLIDE 42

Lin Tan aComment

linux/kernel/posix-cpu-timers.c: void run_posix_cpu_timers(…) { BUG_ON(!irqs_disabled()); … }

/*@IRQ(D, X)*/

Annotation Extraction From Code Assertions

  • Learn from dynamic assertions
  • Can learn invariants from the majority of code

[ErnstICSE’00], [EnglerSOSP’01], [HangalICSE’02], [LiFSE’05], [LivshitsFSE’05], [TanSecurity’08] ... 13

Seed function

slide-43
SLIDE 43

Lin Tan aComment

linux/kernel/posix-cpu-timers.c: void run_posix_cpu_timers(…) { BUG_ON(!irqs_disabled()); … }

/*@IRQ(D, X)*/

Annotation Extraction From Code Assertions

  • Learn from dynamic assertions
  • Can learn invariants from the majority of code

[ErnstICSE’00], [EnglerSOSP’01], [HangalICSE’02], [LiFSE’05], [LivshitsFSE’05], [TanSecurity’08] ... 13

Seed function

  • We directly extract annotations from seed functions’

code and comments.

  • Challenge: Scarceness of seed functions
slide-44
SLIDE 44

Lin Tan aComment

Annotation Propagation

14

linux/kernel/timer.c: 1 void update_process_times(int user_tick) 2 { 3 struct task_struct p = get_current(); 4 ... 5 6 account_process_tick(p, user_tick); 7 run_local_timers(); 8 if (rcu_pending(cpu)) 9 rcu_check_callbacks(cpu, user_tick); 10 scheduler_tick(); 11 run_posix_cpu_timers(p); 12 }

slide-45
SLIDE 45

Lin Tan aComment

Annotation Propagation

14

linux/kernel/timer.c: 1 void update_process_times(int user_tick) 2 { 3 struct task_struct p = get_current(); 4 ... 5 6 account_process_tick(p, user_tick); 7 run_local_timers(); 8 if (rcu_pending(cpu)) 9 rcu_check_callbacks(cpu, user_tick); 10 scheduler_tick(); 11 run_posix_cpu_timers(p); 12 }

@IRQ(X, X) @IRQ(D, D) @IRQ(D, D) @IRQ(D, D) @IRQ(X, X) @IRQ(X, X) @IRQ(D, D)

slide-46
SLIDE 46

Lin Tan aComment

Annotation Propagation

14

linux/kernel/timer.c: 1 void update_process_times(int user_tick) 2 { 3 struct task_struct p = get_current(); 4 ... 5 6 account_process_tick(p, user_tick); 7 run_local_timers(); 8 if (rcu_pending(cpu)) 9 rcu_check_callbacks(cpu, user_tick); 10 scheduler_tick(); 11 run_posix_cpu_timers(p); 12 }

@IRQ(X, X) @IRQ(D, D) @IRQ(D, D) @IRQ(D, D) @IRQ(X, X) @IRQ(X, X) @IRQ(D, D) @IRQ(D, D)

slide-47
SLIDE 47

Lin Tan aComment

Annotation Propagation

14

linux/kernel/timer.c: 1 void update_process_times(int user_tick) 2 { 3 struct task_struct p = get_current(); 4 ... 5 6 account_process_tick(p, user_tick); 7 run_local_timers(); 8 if (rcu_pending(cpu)) 9 rcu_check_callbacks(cpu, user_tick); 10 scheduler_tick(); 11 run_posix_cpu_timers(p); 12 }

@IRQ(X, X) @IRQ(D, D) @IRQ(D, D) @IRQ(D, D) @IRQ(X, X) @IRQ(X, X) @IRQ(D, D) (X, X) @IRQ(D, D)

slide-48
SLIDE 48

Lin Tan aComment

Annotation Propagation

14

linux/kernel/timer.c: 1 void update_process_times(int user_tick) 2 { 3 struct task_struct p = get_current(); 4 ... 5 6 account_process_tick(p, user_tick); 7 run_local_timers(); 8 if (rcu_pending(cpu)) 9 rcu_check_callbacks(cpu, user_tick); 10 scheduler_tick(); 11 run_posix_cpu_timers(p); 12 }

@IRQ(X, X) @IRQ(D, D) @IRQ(D, D) @IRQ(D, D) @IRQ(X, X) @IRQ(X, X) @IRQ(D, D) (X, X) (D, D) @IRQ(D, D)

slide-49
SLIDE 49

Lin Tan aComment

Annotation Propagation

14

linux/kernel/timer.c: 1 void update_process_times(int user_tick) 2 { 3 struct task_struct p = get_current(); 4 ... 5 6 account_process_tick(p, user_tick); 7 run_local_timers(); 8 if (rcu_pending(cpu)) 9 rcu_check_callbacks(cpu, user_tick); 10 scheduler_tick(); 11 run_posix_cpu_timers(p); 12 }

@IRQ(X, X) @IRQ(D, D) @IRQ(D, D) @IRQ(D, D) @IRQ(X, X) @IRQ(X, X) @IRQ(D, D) (D, D) @IRQ(D, D) ( , D)

slide-50
SLIDE 50

Lin Tan aComment

Annotation Propagation

14

linux/kernel/timer.c: 1 void update_process_times(int user_tick) 2 { 3 struct task_struct p = get_current(); 4 ... 5 6 account_process_tick(p, user_tick); 7 run_local_timers(); 8 if (rcu_pending(cpu)) 9 rcu_check_callbacks(cpu, user_tick); 10 scheduler_tick(); 11 run_posix_cpu_timers(p); 12 }

@IRQ(X, X) @IRQ(D, D) @IRQ(D, D) @IRQ(D, D) @IRQ(X, X) @IRQ(X, X) @IRQ(D, D) (D, D) (D, D) @IRQ(D, D)

slide-51
SLIDE 51

Lin Tan aComment

Annotation Propagation

14

linux/kernel/timer.c: 1 void update_process_times(int user_tick) 2 { 3 struct task_struct p = get_current(); 4 ... 5 6 account_process_tick(p, user_tick); 7 run_local_timers(); 8 if (rcu_pending(cpu)) 9 rcu_check_callbacks(cpu, user_tick); 10 scheduler_tick(); 11 run_posix_cpu_timers(p); 12 }

@IRQ(X, X) @IRQ(D, D) @IRQ(D, D) @IRQ(D, D) @IRQ(X, X) @IRQ(X, X) @IRQ(D, D) (D, D) (D, D) (D, D) (D, D) (D, D) (D, D) (D, D) @IRQ(D, D)

slide-52
SLIDE 52

Lin Tan aComment

Annotation Propagation

14

linux/kernel/timer.c: 1 void update_process_times(int user_tick) 2 { 3 struct task_struct p = get_current(); 4 ... 5 6 account_process_tick(p, user_tick); 7 run_local_timers(); 8 if (rcu_pending(cpu)) 9 rcu_check_callbacks(cpu, user_tick); 10 scheduler_tick(); 11 run_posix_cpu_timers(p); 12 }

@IRQ(X, X) @IRQ(D, D) @IRQ(D, D) @IRQ(D, D) @IRQ(X, X) @IRQ(X, X) @IRQ(D, D) (D, D) (D, D) (D, D) (D, D) (D, D) (D, D) (D, D) @IRQ(D, D)

  • Initialize
  • only 8 IRQ functions (e.g., local_irq_disable) with (X, E), (X, D), etc.
  • seed functions with annotations extracted from comments and code
slide-53
SLIDE 53

Lin Tan aComment

Bug Detection - Unsatisfiable Annotations

15

linux//arch/x86/mm/pageattr.c: static void /* @IRQ (E, E) */ cpa_flush_array(…) { … BUG_ON(irqs_disabled()); … }

Seed function

slide-54
SLIDE 54

Lin Tan aComment

Bug Detection - Unsatisfiable Annotations

15

drivers/ssb/pcmcia.c: static void ssb_pcmcia_write16(…) { … spin_lock_irqsave(…); err = select_core_and_segment(…); … } linux//arch/x86/mm/pageattr.c: static void /* @IRQ (E, E) */ cpa_flush_array(…) { … BUG_ON(irqs_disabled()); … }

Call*

Seed function

slide-55
SLIDE 55

Lin Tan aComment

/* @IRQ (X, D)*/ /* @IRQ (E, E)*/

Bug Detection - Unsatisfiable Annotations

15

drivers/ssb/pcmcia.c: static void ssb_pcmcia_write16(…) { … spin_lock_irqsave(…); err = select_core_and_segment(…); … } linux//arch/x86/mm/pageattr.c: static void /* @IRQ (E, E) */ cpa_flush_array(…) { … BUG_ON(irqs_disabled()); … }

Call*

Seed function

slide-56
SLIDE 56

Lin Tan aComment

/* @IRQ (X, D)*/ /* @IRQ (E, E)*/

Bug Detection - Unsatisfiable Annotations

15

drivers/ssb/pcmcia.c: static void ssb_pcmcia_write16(…) { … spin_lock_irqsave(…); err = select_core_and_segment(…); … } linux//arch/x86/mm/pageattr.c: static void /* @IRQ (E, E) */ cpa_flush_array(…) { … BUG_ON(irqs_disabled()); … }

}

Violation! A real bug in the Linux kernel

Call*

Seed function

slide-57
SLIDE 57

Lin Tan aComment

Bug Detection - Root Function Annotations

16

linux/kernel/posix-cpu-timers.c: void /*@IRQ (D, D)*/ run_posix_cpu_timers(…) { ... BUG_ON(!irqs_disabled()); ... }

Seed function

slide-58
SLIDE 58

Lin Tan aComment

Bug Detection - Root Function Annotations

16

linux/arch/alpha/kernel/irq_alpha.c asmlinkage /* @IRQ (D, D) */ void do_entInt(…) { … smp_percpu_timer_interrupt(…); … } linux/kernel/posix-cpu-timers.c: void /*@IRQ (D, D)*/ run_posix_cpu_timers(…) { ... BUG_ON(!irqs_disabled()); ... }

Call*

Seed function

slide-59
SLIDE 59

Lin Tan aComment

Bug Detection - Root Function Annotations

  • Root function do_entInt has no callers within a module.
  • No guaranteed that external callers will disable interrupts.

16

linux/arch/alpha/kernel/irq_alpha.c asmlinkage /* @IRQ (D, D) */ void do_entInt(…) { … smp_percpu_timer_interrupt(…); … } linux/kernel/posix-cpu-timers.c: void /*@IRQ (D, D)*/ run_posix_cpu_timers(…) { ... BUG_ON(!irqs_disabled()); ... }

Call*

Seed function

slide-60
SLIDE 60

Lin Tan aComment

Bug Detection - Root Function Annotations

  • Root function do_entInt has no callers within a module.
  • No guaranteed that external callers will disable interrupts.

16

linux/arch/alpha/kernel/irq_alpha.c asmlinkage /* @IRQ (D, D) */ void do_entInt(…) { … smp_percpu_timer_interrupt(…); … } linux/kernel/posix-cpu-timers.c: void /*@IRQ (D, D)*/ run_posix_cpu_timers(…) { ... BUG_ON(!irqs_disabled()); ... }

Violation! Forgot to call local_irq_disable(); A real bug in the Linux kernel

Call*

Seed function

slide-61
SLIDE 61

Lin Tan aComment

Outline

  • Motivation & Contributions
  • Annotation Design
  • Annotation Extraction
  • From comments
  • From code
  • Annotation Propagation & Bug Detection
  • Results: Bug Detection & Annotation Extraction
  • Related Work
  • Conclusions

17

slide-62
SLIDE 62

Lin Tan aComment

Overall Results On Linux

  • Annotations can help detect and avoid bugs.
  • Comments and code complement each other for

annotation extraction and bug detection.

  • We propagate seed annotations to generate 96,821

annotations.

18

Source Seed Annotation Comment 226 Assertion 24 Total 245

slide-63
SLIDE 63

Lin Tan aComment

Overall Results On Linux

  • Annotations can help detect and avoid bugs.
  • Comments and code complement each other for

annotation extraction and bug detection.

  • We propagate seed annotations to generate 96,821

annotations.

18

Source Seed Annotation Seed Checked Comment 226 119 Assertion 24 17 Total 245 133

slide-64
SLIDE 64

Lin Tan aComment

Overall Results On Linux

  • Annotations can help detect and avoid bugs.
  • Comments and code complement each other for

annotation extraction and bug detection.

  • We propagate seed annotations to generate 96,821

annotations.

18

Source Seed Annotation Seed Checked True Bugs False Positives Comment 226 119 7 2 Assertion 24 17 3 1 Total 245 133 9 3

slide-65
SLIDE 65

Lin Tan aComment

Annotation Extraction Results

  • Reduce the # of annotations to be manually read

from 66,795 to 682.

  • The annotation generation accuracy is 90-100%.

19

Software LOC Sentence IRQSent Linux 5.2M 1,024,624 23,662 FreeBSD 2.4M 420,013 11,117 NetBSD 3.3M 680,650 23,942 OpenSolaris 3.7M 535,073 8,074 Total 14.6M 2,660,360 66,795 HeuSent Annotation 423 226 80 43 108 62 71 24 682 355

slide-66
SLIDE 66

Lin Tan aComment

Limitations & Future Work

  • Automatically learn paraphrases, e.g., “disable” = “block”
  • Promising preliminary results [LinNLE’01, GlickmanRANLP’03, HillMSR’08]
  • Consider different types of interrupts, different interrupt

context, and conditional annotations

  • Send annotations to developers for confirmation
  • To detect annotations extracted from outdated comments

20

slide-67
SLIDE 67

Lin Tan aComment

Conclusions

✦ Feasible to extract annotations from comments & code

  • Generated 96,821 interrupt-related annotations &

automatically detected 9 bugs in the Linux kernel

  • These annotations can help developers avoid bugs.

✦ Combining comments & code help extract more annotations and detect more bugs than using comments or code alone.

  • Apply to non-OS code and for extracting other types
  • f annotations

21