verifying concurrent programs
play

Verifying Concurrent Programs Daniel Kroening 28 May 1 June 2012 - PowerPoint PPT Presentation

Verifying Concurrent Programs Daniel Kroening 28 May 1 June 2012 Outline Shared-Variable Concurrency Predicate Abstraction for Concurrent Programs Boolean Programs with Bounded Replication Boolean Programs with Unbounded Replication D.


  1. Verifying Concurrent Programs Daniel Kroening 28 May – 1 June 2012

  2. Outline Shared-Variable Concurrency Predicate Abstraction for Concurrent Programs Boolean Programs with Bounded Replication Boolean Programs with Unbounded Replication D. Kroening: SSFT12 – Verifying Concurrent Programs 2

  3. J. Alglave A. Donaldson A. Kaiser T. Wahl Soundness of Data Flow Analyses for Weak Memory Models , APLAS 2011 Symmetry-Aware Predicate Abstraction for Shared-Variable Concurrent Programs , CAV 2011 Dynamic Cutoff Detection in Parameterized Concurrent Programs , CAV 2010 Boom: Taking Boolean Program Model Checking One Step Further , TACAS 2010 Symbolic Counter Abstraction for Concurrent Software , CAV 2009 D. Kroening: SSFT12 – Verifying Concurrent Programs 3

  4. Forms of Concurrency ◮ Shared-variable concurrency (Linux pthread library, Win32 thread API, . . . ) ◮ Share all memory ◮ Share OS API (e.g., file descriptors) ◮ Multiple processes on the same machine ◮ Share file system ◮ Can share memory via mmap ◮ Programs on different machines ◮ Can communicate e.g. via UDP or TCP D. Kroening: SSFT12 – Verifying Concurrent Programs 4

  5. Asynchronous vs. Synchronous Concurrency Synchronous Asynchronous Partition state: Transition relation for each S = S 1 × . . . × S n process: T i : S × S i T i : S × S Overall system: Overall system: n � T ( s, s ′ ) ⇐ ⇒ ∃ i.T i ( s, s ′ ) T ( s, s ′ ) ⇐ T i ( s, s ′ ⇒ ( i ) ) i =0 Each process can Only one process perform a step in each performs a step in a transition transition D. Kroening: SSFT12 – Verifying Concurrent Programs 5

  6. Asynchronous Shared-Variable Concurrency ◮ We focus on asynchronous shared-variable concurrency ◮ Motivated by Intel’s multi-core story ◮ Doubling the gate count doubles the power consumption ◮ Increasing the clock speed requires raising voltage, with manifold increase in power! ◮ Scaling micro-processors is easier by replicating CPU cores ◮ CPUs with 100 cores are around D. Kroening: SSFT12 – Verifying Concurrent Programs 6

  7. Thread Interleavings: Example (1) XX Thread 1 Thread 2 Thread 3 x=10; y++; x++; y++; y=20; (end) (end) (end) Current state: x =0, y =0 D. Kroening: SSFT12 – Verifying Concurrent Programs 7

  8. Thread Interleavings: Example (1) XX Thread 1 Thread 2 Thread 3 x=10; y++; x++; y++; y=20; (end) (end) (end) Current state: x =10, y =0 D. Kroening: SSFT12 – Verifying Concurrent Programs 7

  9. Thread Interleavings: Example (1) XX Thread 1 Thread 2 Thread 3 x=10; y++; x++; y++; y=20; (end) (end) (end) Current state: x =10, y =1 D. Kroening: SSFT12 – Verifying Concurrent Programs 7

  10. Thread Interleavings: Example (1) XX Thread 1 Thread 2 Thread 3 x=10; y++; x++; y++; y=20; (end) (end) (end) Current state: x =10, y =20 D. Kroening: SSFT12 – Verifying Concurrent Programs 7

  11. Thread Interleavings: Example (1) XX Thread 1 Thread 2 Thread 3 x=10; y++; x++; y++; y=20; (end) (end) (end) Current state: x =11, y =20 D. Kroening: SSFT12 – Verifying Concurrent Programs 7

  12. Thread Interleavings: Example (1) XX Thread 1 Thread 2 Thread 3 x=10; y++; x++; y++; y=20; (end) (end) (end) Current state: x =11, y =21 D. Kroening: SSFT12 – Verifying Concurrent Programs 7

  13. Thread Interleavings: Example (2) Alternative Schedule Thread 1 Thread 2 Thread 3 x=10; y++; x++; y++; y=20; (end) (end) (end) Current state: x =0, y =0 D. Kroening: SSFT12 – Verifying Concurrent Programs 8

  14. Thread Interleavings: Example (2) Alternative Schedule Thread 1 Thread 2 Thread 3 x=10; y++; x++; y++; y=20; (end) (end) (end) Current state: x =10, y =0 D. Kroening: SSFT12 – Verifying Concurrent Programs 8

  15. Thread Interleavings: Example (2) Alternative Schedule Thread 1 Thread 2 Thread 3 x=10; y++; x++; y++; y=20; (end) (end) (end) Current state: x =11, y =0 D. Kroening: SSFT12 – Verifying Concurrent Programs 8

  16. Thread Interleavings: Example (2) Alternative Schedule Thread 1 Thread 2 Thread 3 x=10; y++; x++; y++; y=20; (end) (end) (end) Current state: x =11, y =1 D. Kroening: SSFT12 – Verifying Concurrent Programs 8

  17. Thread Interleavings: Example (2) Alternative Schedule Thread 1 Thread 2 Thread 3 x=10; y++; x++; y++; y=20; (end) (end) (end) Current state: x =11, y =2 D. Kroening: SSFT12 – Verifying Concurrent Programs 8

  18. Thread Interleavings: Example (2) Alternative Schedule Thread 1 Thread 2 Thread 3 x=10; y++; x++; y++; y=20; (end) (end) (end) Current state: x =11, y =20 D. Kroening: SSFT12 – Verifying Concurrent Programs 8

  19. Races ◮ The example program has a race, i.e., the result depends on the schedule D. Kroening: SSFT12 – Verifying Concurrent Programs 9

  20. Races ◮ The example program has a race, i.e., the result depends on the schedule ◮ This may indicate a program bug, but need not ◮ Locks may help, but need not ◮ Enumerate? Exponential blowup! D. Kroening: SSFT12 – Verifying Concurrent Programs 9

  21. Ordering of Loads/Stores Thread 1 Thread 2 mov [x], 1 mov [y], 1 mov eax , [y] mov ebx , [x] ◮ Suppose x and y are shared and initialized with 0 D. Kroening: SSFT12 – Verifying Concurrent Programs 10

  22. Ordering of Loads/Stores Thread 1 Thread 2 mov [x], 1 mov [y], 1 mov eax , [y] mov ebx , [x] ◮ Suppose x and y are shared and initialized with 0 ◮ Unfortunately, the program may terminate with eax = ebx =0! D. Kroening: SSFT12 – Verifying Concurrent Programs 10

  23. Shared Memory in Hardware ✘ Computer vendors do not guarantee atomicity of loads/stores ◮ Only very special commands are guaranteed to be atomic, e.g., the Compare-and-Swap (CAS) instruction D. Kroening: SSFT12 – Verifying Concurrent Programs 11

  24. Shared Memory in Hardware ✘ Computer vendors do not guarantee atomicity of loads/stores ◮ Only very special commands are guaranteed to be atomic, e.g., the Compare-and-Swap (CAS) instruction ◮ Stores are not even guaranteed to be visible to other threads unless a memory barrier (memory fence) is inserted. ✘ But: memory fences are expensive ( > 100 cycles), so we cannot put them everywhere D. Kroening: SSFT12 – Verifying Concurrent Programs 11

  25. Boolean Programs Let’s look at a Windows device driver example: void DecrementIo(DEVICE OBJECT ∗ DeviceObject) { 1 EXT ∗ ext = (EXT ∗ )DeviceObject − > DeviceExtension; 2 3 int IoIsPending = 4 InterlockedDecrement (&ext − > IoIsPending); 5 6 if (!IoIsPending) { 7 KeSetEvent (&ext − > event, IO NO INCREMENT, FALSE); } 8 } 9 D. Kroening: SSFT12 – Verifying Concurrent Programs 12

  26. Boolean Programs The initial abstraction, without any predicates: void DecrementIo() { 1 InterlockedDecrement(); 2 goto L1,L2; 3 L1: KeSetEvent(); 4 L2: return ; 5 } 6 D. Kroening: SSFT12 – Verifying Concurrent Programs 13

  27. Adding Some Predicates Some predicate refinement scheme computes a set of predicates: b1 � ext == & envext b2 � envext . IoIsPending == 1 b3 � envext . IoIsPending == 2 b4 � IoIsPending == 2 b5 � IoIsPending == 1 b6 � ( ∗ ext ) . IoIsPending == 1 b7 � ( ∗ ext ) . IoIsPending == 2 D. Kroening: SSFT12 – Verifying Concurrent Programs 14

  28. Boolean Programs This results in the following new abstract model: 1 bool b1,b2,b3; // global 2 3 void DecrementIo() { bool b4,b5,b6,b7; // local 4 b1,b6,b7 = ∗ , ∗ , ∗ 5 constrain ((!(b1’ && b2) || b6’) && 6 (!( b1’ && b3) || b7’)); 7 b4,b5 = InterlockedDecrement(b6,b7); 8 goto L1,L2; 9 L1: assume (!b4 && !b5); 10 KeSetEvent(); 11 L2: return; 12 13 } D. Kroening: SSFT12 – Verifying Concurrent Programs 15

  29. Concurrent Boolean Programs Suppose we could dynamically create threads in Boolean Programs: 1 bool b1,b2,b3; // global 2 3 void DecrementIo() { bool b4,b5,b6,b7; // local 4 b1,b6,b7 = ∗ , ∗ , ∗ 5 constrain ((!(b1’ && b2) || b6’) && 6 (!( b1’ && b3) || b7’)); 7 b4,b5 = InterlockedDecrement(b6,b7); 8 start thread L1, L2; 9 L1: assume (!b4 && !b5); 10 KeSetEvent(); 11 L2: return; 12 13 } D. Kroening: SSFT12 – Verifying Concurrent Programs 16

  30. Predicate Abstraction for Concurrent Programs Can we apply our refinement loop to concurrent software? C program 1 . ) Compute 2 . ) Check Abstraction Abstraction [no error] OK 4 . ) Refine 3 . ) Check Predicates Feasibility [feasible] report counterexample D. Kroening: SSFT12 – Verifying Concurrent Programs 17

  31. Predicate Abstraction for Concurrent Programs Claim: Yes, we can! ◮ Abstraction: as before! ◮ Checking ˆ M : use Model Checker for concurrent Boolean programs ◮ Simulation: as before – use thread switches from abstract counterexample ◮ Refinement: as before! D. Kroening: SSFT12 – Verifying Concurrent Programs 18

  32. Example 1 int g; 2 void ∗ t1( void ∗ arg) { 10 void ∗ t2( void ∗ arg) { g=0; 3 g=1; 11 if (g==1) { 4 if (g==2) { 12 g=2; 5 g=3; 13 if (g==3) 6 assert(g!=4); 14 g=4; 7 } 15 } 8 16 } 9 } D. Kroening: SSFT12 – Verifying Concurrent Programs 19

  33. Example 16 int main() { pthread t id1, id2; 17 18 pthread create(&id1, NULL, t1, NULL); 19 pthread create(&id2, NULL, t2, NULL); 20 21 } D. Kroening: SSFT12 – Verifying Concurrent Programs 20

Recommend


More recommend