Verifying concurrent software using movers in CSPEC
Tej Chajed, Frans Kaashoek, Butler Lampson*, Nickolai Zeldovich MIT CSAIL and *Microsoft
Verifying concurrent software using movers in CSPEC Tej Chajed , - - PowerPoint PPT Presentation
Verifying concurrent software using movers in CSPEC Tej Chajed , Frans Kaashoek, Butler Lampson*, Nickolai Zeldovich MIT CSAIL and *Microsoft Concurrent software is difficult to get right Programmer cannot reason about code in sequence 2
Tej Chajed, Frans Kaashoek, Butler Lampson*, Nickolai Zeldovich MIT CSAIL and *Microsoft
2
Programmer cannot reason about code in sequence…
3
instead, must consider many executions: Programmer cannot reason about code in sequence…
3
instead, must consider many executions: … Programmer cannot reason about code in sequence…
4
5
5
6
time B 3 2 A 1
blue thread green thread
1 2 3 A B
6
has the same effect as movers B 3 2 A 1
blue thread green thread
1 2 3 A B
B 3 2 A 1
6
has the same effect as movers sequential reasoning B 3 2 A 1
blue thread green thread
1 2 3 A B
B 3 2 A 1 B 3 2 A 1
7
CIVL [CAV ’15, CAV ’18] framework relies pen & paper proofs IronFleet [SOSP ’15]
8
8
9
spool file system mbox
10
spool file system # accept def deliver(msg): # spool create(“/spool/$TID”) write(“/spool/$TID”, msg) # store while True: t = time.time() if link(“/spool/$TID”, “/mbox/$t”): break # cleanup unlink(“/spool/$TID”) mbox
1 2 3
11
spool file system msg mbox
1 2 3
# accept def deliver(msg): # spool create(“/spool/$TID”) write(“/spool/$TID”, msg) # store while True: t = time.time() if link(“/spool/$TID”, “/mbox/$t”): break # cleanup unlink(“/spool/$TID”)
12
spool file system mbox
1 2 3
$TID =10 # accept def deliver(msg): # spool create(“/spool/$TID”) write(“/spool/$TID”, msg) # store while True: t = time.time() if link(“/spool/$TID”, “/mbox/$t”): break # cleanup unlink(“/spool/$TID”)
12
spool file system
10
mbox
1 2 3
$TID =10 # accept def deliver(msg): # spool create(“/spool/$TID”) write(“/spool/$TID”, msg) # store while True: t = time.time() if link(“/spool/$TID”, “/mbox/$t”): break # cleanup unlink(“/spool/$TID”)
10
13
spool file system
10
msg mbox
1 2 3
$TID =10 $TID =11 # accept def deliver(msg): # spool create(“/spool/$TID”) write(“/spool/$TID”, msg) # store while True: t = time.time() if link(“/spool/$TID”, “/mbox/$t”): break # cleanup unlink(“/spool/$TID”)
14
spool file system
10
mbox
1 2 3
$TID =10 $TID =11 # accept def deliver(msg): # spool create(“/spool/$TID”) write(“/spool/$TID”, msg) # store while True: t = time.time() if link(“/spool/$TID”, “/mbox/$t”): break # cleanup unlink(“/spool/$TID”)
14
spool file system
10 11
mbox
1 2 3
$TID =10 $TID =11 # accept def deliver(msg): # spool create(“/spool/$TID”) write(“/spool/$TID”, msg) # store while True: t = time.time() if link(“/spool/$TID”, “/mbox/$t”): break # cleanup unlink(“/spool/$TID”)
15
spool file system mbox
1 2 3 4 10 11
link(/spool/11, /mbox/4) # accept def deliver(msg): # spool create(“/spool/$TID”) write(“/spool/$TID”, msg) # store while True: t = time.time() if link(“/spool/$TID”, “/mbox/$t”): break # cleanup unlink(“/spool/$TID”)
16
spool mbox
1 2 3
file system
4 10 11
link(/spool/10, /mbox/4)
EEXISTS ✗
# accept def deliver(msg): # spool create(“/spool/$TID”) write(“/spool/$TID”, msg) # store while True: t = time.time() if link(“/spool/$TID”, “/mbox/$t”): break # cleanup unlink(“/spool/$TID”)
17
spool file system mbox
1 2 3 4 5 10 11
link(/spool/10, /mbox/5) # accept def deliver(msg): # spool create(“/spool/$TID”) write(“/spool/$TID”, msg) # store while True: t = time.time() if link(“/spool/$TID”, “/mbox/$t”): break # cleanup unlink(“/spool/$TID”)
18
spool file system mbox
1 2 3 5 4 10
# accept def deliver(msg): # spool create(“/spool/$TID”) write(“/spool/$TID”, msg) # store while True: t = time.time() if link(“/spool/$TID”, “/mbox/$t”): break # cleanup unlink(“/spool/$TID”)
19
spool file system mbox
1 2 3 4 5
# accept def deliver(msg): # spool create(“/spool/$TID”) write(“/spool/$TID”, msg) # store while True: t = time.time() if link(“/spool/$TID”, “/mbox/$t”): break # cleanup unlink(“/spool/$TID”)
20
file-system spec delivery specification
implementation and proof
CSPEC CSPEC provides supporting definitions and theorems
21
def deliver(msg): create(“/spool/$TID”, msg) while True: t = time.time() if link(“/spool/$TID”, “/mbox/$t”): break unlink(“/spool/$TID”) create( /sp/$TID, msg) ✓ link( /sp/$TID, /mbox/$t)
EEXISTS ✗
link( /sp/$TID, /mbox/$t) ✓ unlink( /sp/$TID) ✓
21
def deliver(msg): create(“/spool/$TID”, msg) while True: t = time.time() if link(“/spool/$TID”, “/mbox/$t”): break unlink(“/spool/$TID”) create( /sp/$TID, msg) ✓ link( /sp/$TID, /mbox/$t)
EEXISTS ✗
link( /sp/$TID, /mbox/$t) ✓ unlink( /sp/$TID) ✓ create(“/spool/$TID”) write(“/spool/$TID”, msg)
collapsed to
22
def deliver(msg): create(“/spool/$TID”, msg) while True: t = time.time() if link(“/spool/$TID”, “/mbox/$t”): break unlink(“/spool/$TID”)
We assume file-system operations are atomic
create( /sp/$TID, msg) ✓ link( /sp/$TID, /mbox/$t)
EEXISTS ✗
link( /sp/$TID, /mbox/$t) ✓ unlink( /sp/$TID) ✓
create
✓
link unlink
23
atomicity: concurrent deliveries appear to execute all at once (in some order)
create
✓
link
✗
link unlink create
✓
link unlink create
✓
link unlink
deliver
create
✓
link
✗
link unlink
deliver
23
atomicity: concurrent deliveries appear to execute all at once (in some order)
create
✓
link
✗
link unlink create
✓
link unlink create
✓
link unlink
deliver
create
✓
link
✗
link unlink
deliver
Step 1: developer identifies commit point
23
atomicity: concurrent deliveries appear to execute all at once (in some order)
create
✓
link
✗
link unlink create
✓
link unlink create
✓
link unlink
deliver
create
✓
link
✗
link unlink
deliver
Step 1: developer identifies commit point Step 2: prove operation occurs logically at commit point
24
create
✓
link
✗
link unlink create
✓
link unlink
24
create
✓
link
✗
link unlink create
✓
link unlink create
✓
link
✗
link unlink create
✓
link unlink
24
create
✓
link
✗
link unlink create
✓
link unlink create
✓
link
✗
link unlink create
✓
link unlink create
✓
link
✗
link unlink create
✓
link unlink
25
A r A r
25
A r A r
left movers are the converse
26
create( /sp/$TID, msg) link( /sp/$TID, /mbox/$t)
EEXISTS ✗
link( /sp/$TID, /mbox/$t) unlink( /sp/$TID) is one of
A r A r
for all green operations , is a right mover if A left movers are the converse
27
Proof sketch (only case):
link
link( /sp/$TID, /mbox/$t) ✓ link( /sp/$TID, /mbox/$t) ✓ link( /sp/$TID, /mbox/$t)
EEXISTS ✗
link( /sp/$TID, /mbox/$t)
EEXISTS ✗
27
Proof sketch (only case):
link
link( /sp/$TID, /mbox/$t) ✓ link( /sp/$TID, /mbox/$t) ✓
$t $t ≠
link( /sp/$TID, /mbox/$t)
EEXISTS ✗
link( /sp/$TID, /mbox/$t)
EEXISTS ✗
✗
link
✓
link
(otherwise then is impossible)
27
Proof sketch (only case):
link
link( /sp/$TID, /mbox/$t) ✓ link( /sp/$TID, /mbox/$t) ✓
$t $t ≠
link( /sp/$TID, /mbox/$t)
EEXISTS ✗
link( /sp/$TID, /mbox/$t)
EEXISTS ✗
✗
link
✓
link
(otherwise then is impossible) link operations are independent
⟹
28
28
link( /sp/$TID, /mbox/$t)
EEXISTS ✗
link( /sp/$TID, /mbox/$t) ✓ link( /sp/$TID, /mbox/$t) ✓ link( /sp/$TID, /mbox/$t)
EEXISTS ✗
if =
$t $t
29
Delivery File system
mover proof?
29
Delivery File system
mover proof?
create( f1, d) create( f2, d) create( f1, d) create( f2, d)
if filenames are identical
30
Delivery File system
Layers limit what operations are available use multiple layers to make operations movers
⟹
31
Delivery File system Restricted file system restrict arguments to include $TID
mover proof ✓
Layers limit what operations are available use multiple layers to make operations movers
⟹
31
Delivery File system Restricted file system upper layers can only use restricted operations
mover proof ✓
Layers limit what operations are available use multiple layers to make operations movers
⟹
32
mover pattern Obligation for developer: movers for each implementation
layer 1 layer 2
A B C D
foo bar
32
mover pattern
A B D C B A C
def foo: def bar: Obligation for developer: movers for each implementation
layer 1 layer 2
A B C D
foo bar
32
mover pattern
A B D C B A C
def foo: def bar: Obligation for developer: movers for each implementation CSPEC theorem: entire layer implementation is atomic
layer 1 layer 2
A B C D
foo bar
33
(see paper for details)
pattern
proof connecting layers
34
file-system spec mail library spec implementation layers patterns
CMAIL (Coq) Coq
CSPEC
auto generated framework
34
file-system spec mail library spec implementation layers patterns
CMAIL (Coq) Coq
calls to file-system SMTP + POP3 extracted implementation
CMAIL (Haskell)
Coq extraction CSPEC
auto generated framework
34
file-system spec mail library spec implementation layers patterns
CMAIL (Coq) Coq
calls to file-system SMTP + POP3 extracted implementation
CMAIL (Haskell)
Coq extraction
GHC
CSPEC executable
auto generated framework
Linux
35
file-system spec mail library spec implementation layers patterns
CMAIL (Coq) Coq
calls to file-system SMTP + POP3 extracted implementation
CMAIL (Haskell)
Coq extraction GHC CSPEC executable
✓
Coq proof checker Linux proven
auto generated
assumed correct
36
file-system spec mail library spec implementation layers patterns
CMAIL (Coq) Coq
calls to file-system SMTP + POP3 extracted implementation
CMAIL (Haskell)
Coq extraction GHC CSPEC executable
✓
Coq proof checker Linux proven
auto generated
assumed correct
37
file-system spec mail library spec implementation layers patterns
CMAIL (Coq) Coq
calls to file-system SMTP + POP3 extracted implementation
CMAIL (Haskell)
Coq extraction GHC CSPEC executable
✓
Coq proof checker Linux proven
auto generated
assumed correct
38
file-system spec mail library spec implementation layers patterns
CMAIL (Coq) Coq
calls to file-system SMTP + POP3 extracted implementation
CMAIL (Haskell)
Coq extraction GHC CSPEC executable
✓
Coq proof checker Linux proven
auto generated
assumed correct
39
40
kreq/s 35 70 105 140 # cores 1 2 3 4 5 6 7 8 9 10 11 12
CMAIL GoMail
41
proof:code ratio CMAIL 11.5x CertiKOS 13.8x IronFleet 7.7x IronClad 4.8x CompCert 4.6x
Took two authors 6 months
concurrent
sequential
42
Three anecdotes of changes to CSPEC: Machine-checked proofs ensure soundness of entire system
42
Three anecdotes of changes to CSPEC: Machine-checked proofs ensure soundness of entire system
42
Three anecdotes of changes to CSPEC: Machine-checked proofs ensure soundness of entire system
42
Three anecdotes of changes to CSPEC: Machine-checked proofs ensure soundness of entire system
github.com/mit-pdos/cspec
43
github.com/mit-pdos/cspec
43
poster #1
44
CMAIL perf experimental setup
45
in-memory file system
process
client
deliver + pickup
CMAIL
core 1
45
…
in-memory file system
process
client
deliver + pickup
CMAIL
core 1
process
client
deliver + pickup
CMAIL
core 2
process
client
deliver + pickup
CMAIL
core 12