Cosmo: a concurrent separation logic for Multicore OCaml Glen Mvel , - - PowerPoint PPT Presentation

cosmo a concurrent separation logic for multicore ocaml
SMART_READER_LITE
LIVE PREVIEW

Cosmo: a concurrent separation logic for Multicore OCaml Glen Mvel , - - PowerPoint PPT Presentation

Cosmo: a concurrent separation logic for Multicore OCaml Glen Mvel , Jacques-Henri Jourdan, Franois Pottier August, 2020 ICFP, New York LRI & Inria, Paris, France This talk Our aim: Verifying fine-grained concurrent


slide-1
SLIDE 1

Cosmo: a concurrent separation logic for Multicore OCaml

Glen Mével, Jacques-Henri Jourdan, François Pottier August, 2020 ICFP, “New York”

LRI & Inria, Paris, France

slide-2
SLIDE 2

This talk

Our aim:

  • Verifying
  • fine-grained concurrent programs
  • in the setting of Multicore OCaml’s memory model.

Our contribution: A concurrent separation logic with views.

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

1

slide-3
SLIDE 3

Multicore OCaml

Multicore OCaml: OCaml language with multicore programming. Weak memory model for Multicore OCaml:

  • Formalized in PLDI 2018.
  • Two flavours of locations: “atomic”, “non-atomic”.

(Also at ICFP 2020: Retrofitting Parallelism onto OCaml)

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

2

slide-4
SLIDE 4

In traditional fine-grained concurrent separation logics...

We can assert ownership of a location and specify its value:

{x → 42}

x := 44

{x → 44}

Ownership can be shared between all threads via an invariant: ∃n ∈ N, x → n ∗ n is even ⊢

{True}

x := 44

{True}

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

3

slide-5
SLIDE 5

The challenge: subjectivity

With weak memory, each thread has its own view of memory. Some assertions are subjective:

  • Their validity relies on the thread’s view.

Invariants are objective:

  • They cannot share subjective assertions.

How to keep a simple and powerful enough logic?

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

4

slide-6
SLIDE 6

Key idea: modeling subjectivity with views

A thread knows a subset U of all writes to the memory.

  • Affects how the thread interacts with memory.
  • U is the thread’s view.

New assertions:

  • ↑ U : we have seen U, i.e. we know all writes in U.
  • P @ U : having seen U is objectively enough for P to hold.

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

5

slide-7
SLIDE 7

Key idea: decomposing subjective assertions

Decompose subjective assertions: P ⇐ ⇒ ∃U. P @ U

  • bjective

∗ ↑ U

  • subjective

Share parts via distinct mechanisms:

  • P @ U : via objective invariants, as usual.
  • ↑ U : via synchronization offered by the memory model.

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

6

slide-8
SLIDE 8

Our program logic

slide-9
SLIDE 9

Rules of atomic locations, simplified

x →at v : the atomic location x stores the value v.

  • Sequentially consistent.
  • Objective.
  • Standard rules:

{x →at v}

x :=at v′

{λ(). x →at v′} {x →at v}

!at x

{λv′. v′ = v ∗ x →at v}

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

7

slide-10
SLIDE 10

Rules of non-atomic locations

x → v : we know the latest value v of the non-atomic location x.

  • Relaxed.
  • Subjective — cannot appear in an invariant.
  • Standard rules too!

{x → v}

x := v′

{λ(). x → v′} {x → v}

! x

{λv′. v′ = v ∗ x → v}

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

8

slide-11
SLIDE 11

Example: transferring an assertion through a spin lock

// release lock: lock :=at false // acquire lock: while CAS lock false true = false do () done

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

9

slide-12
SLIDE 12

Example: transferring an assertion through a spin lock

{P} // release lock: lock :=at false // acquire lock: while CAS lock false true = false do () done {P}

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

9

slide-13
SLIDE 13

Example: transferring an assertion through a spin lock

{P} // release lock: lock :=at false // acquire lock: CAS lock false true // CAS succeeds {P}

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

9

slide-14
SLIDE 14

Example: transferring an assertion through a spin lock

{P} {∃U. P @ U ∗ ↑ U} // release lock: lock :=at false // acquire lock: CAS lock false true // CAS succeeds {∃U. P @ U ∗ ↑ U} {P}

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

9

slide-15
SLIDE 15

Example: transferring an assertion through a spin lock

{P} {∃U. P @ U ∗ ↑ U} // release lock: lock :=at false // acquire lock: CAS lock false true // CAS succeeds {∃U. P @ U ∗ ↑ U} {P}

  • P @ U : transferred via objective invariants, as usual.

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

9

slide-16
SLIDE 16

Example: transferring an assertion through a spin lock

{P} {∃U. P @ U ∗ ↑ U} // release lock: lock :=at false // acquire lock: CAS lock false true // CAS succeeds {∃U. P @ U ∗ ↑ U} {P}

  • ↑ U : transferred via synchronization.

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

9

slide-17
SLIDE 17

Example: transferring an assertion through a spin lock

{P} {∃U. P @ U ∗ ↑ U} // release lock: lock :=at false // acquire lock: CAS lock false true // CAS succeeds {∃U. P @ U ∗ ↑ U} {P} happens before

  • ↑ U : transferred via “atomic” accesses.

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

9

slide-18
SLIDE 18

Rules of atomic locations, simplified

x →at v : the atomic location x stores the value v.

  • Sequentially consistent behavior for v.
  • Objective.
  • Rules:

{x →at v}

x :=at v′

{λ(). x →at v′} {x →at v}

!at x

{λv′. v′ = v ∗ x →at v}

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

10

slide-19
SLIDE 19

Rules of atomic locations

x →at (v, U) : the atomic location x stores the value v and a view (at least) U.

  • Sequentially consistent behavior for v.
  • Release/acquire behavior for U.
  • Objective (still).
  • Rules:

{x →at (v, U) ∗ ↑ U′}

x :=at v′

{λ(). x →at (v′, U′)} {x →at (v, U)}

!at x

{λv′. v′ = v ∗ x →at (v, U) ∗ ↑ U}

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

10

slide-20
SLIDE 20

Rules of atomic locations

x →at (v, U) : the atomic location x stores the value v and a view (at least) U.

  • Sequentially consistent behavior for v.
  • Release/acquire behavior for U.
  • Objective (still).
  • Rules:

{x →at (v, U) ∗ ↑ U′}

x :=at v′

{λ(). x →at (v′, U′)} {x →at (v, U)}

!at x

{λv′. v′ = v ∗ x →at (v, U) ∗ ↑ U}

release

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

10

slide-21
SLIDE 21

Rules of atomic locations

x →at (v, U) : the atomic location x stores the value v and a view (at least) U.

  • Sequentially consistent behavior for v.
  • Release/acquire behavior for U.
  • Objective (still).
  • Rules:

{x →at (v, U) ∗ ↑ U′}

x :=at v′

{λ(). x →at (v′, U′)} {x →at (v, U)}

!at x

{λv′. v′ = v ∗ x →at (v, U) ∗ ↑ U}

acquire

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

10

slide-22
SLIDE 22

Application: the spin lock

slide-23
SLIDE 23

The spin lock

A spin lock implements a lock using an atomic boolean variable:

let release lk = lk :={at} false let rec acquire lk = if CAS lk false true then () else acquire lk

Interface: isLock lk P ⊢   

{P} release lk {True} {True} acquire lk {P}

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

11

slide-24
SLIDE 24

The spin lock

A spin lock implements a lock using an atomic boolean variable:

let release lk = lk :={at} false let rec acquire lk = if CAS lk false true then () else acquire lk

Invariant in traditional CSL: lk →at true ∨ ( lk →at false ∗ P) ⊢   

{P} release lk {True} {True} acquire lk {P}

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

11

slide-25
SLIDE 25

The spin lock

A spin lock implements a lock using an atomic boolean variable:

let release lk = lk :={at} false let rec acquire lk = if CAS lk false true then () else acquire lk

Invariant in our logic (where P is subjective!): lk →at true ∨ (∃U. lk →at (false, U) ∗ P @ U) ⊢   

{P} release lk {True} {True} acquire lk {P}

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

11

slide-26
SLIDE 26

Methodology

More case studies:

  • Ticket lock
  • Dekker mutual exclusion algorithm
  • Peterson mutual exclusion algorithm

Method for proving correctness under weak memory:

  • 1. Start with the invariant under sequential consistency;
  • 2. Identify how information flows between threads;
  • i.e. where are the synchronization points;
  • 3. Refine the invariant with corresponding views.

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

12

slide-27
SLIDE 27

Conclusion

slide-28
SLIDE 28

Conclusion

Key idea: The logic of views enables concise and natural reasoning about how threads synchronize. In the paper:

  • Model of the logic.
  • A lower-level logic.
  • More case studies.

Fully mechanized in Coq with the Iris framework. Future work:

  • Verify more shared data structures.
  • Allow data races on non-atomics?

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

13

slide-29
SLIDE 29

Questions?

slide-30
SLIDE 30
slide-31
SLIDE 31

Verifying the spin lock

// release lk: { isLock lk P ∗ P} { lk →at _ ∗ P}

  • ∃U. lk →at _

  • ↑ U ∗ P @ U
  • lk :=at false

{∃U. lk →at (false, U) ∗ P @ U} { isLock lk P} // acquire lk: {isLock lk P}

  • (∃U. lk →at (false, U) ∗ P @ U)

∨ lk →at true

  • if CAS lk false true

then

  • ∃U. lk →at true ∗ ↑ U ∗ P @ U
  • {

lk →at _ ∗ P} { isLock lk P ∗ P} else {lk →at true} {isLock lk P} acquire lk {isLock lk P ∗ P}

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

slide-32
SLIDE 32

Model of the logic in Iris

Assertions are predicates on views: vProp view − → iProp ↑ U0 λU. U0 ⊑ U P ∗ Q λU. P U ∗ Q U P − ∗ Q λU . P U − ∗ Q U We equip a language-with-view with an operational semantics: exprWithView expr × view Iris builds a WP calculus for exprWithView in iProp. We derive a WP calculus for expr in vProp and prove adequacy: WP e ϕ λU . valid U − ∗ WP e, U

  • λv, U′. valid U′ ∗ ϕ v U′

where ϕ : val → vProp

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

slide-33
SLIDE 33

Model of the logic in Iris

Assertions are monotonic predicates on views: vProp view

mon

− → iProp ↑ U0 λU. U0 ⊑ U P ∗ Q λU. P U ∗ Q U P − ∗ Q λU1. ∀U ⊒ U1. P U − ∗ Q U We equip a language-with-view with an operational semantics: exprWithView expr × view Iris builds a WP calculus for exprWithView in iProp. We derive a WP calculus for expr in vProp and prove adequacy: WP e ϕ λU1. ∀U ⊒ U1. valid U − ∗ WP e, U

  • λv, U′. valid U′ ∗ ϕ v U′

where ϕ : val → vProp

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

slide-34
SLIDE 34

Model of the logic in Iris

Assertions are monotonic predicates on views: vProp view

mon

− → iProp ↑ U0 λU. U0 ⊑ U P ∗ Q λU. P U ∗ Q U P − ∗ Q λU1. ∀U ⊒ U1. P U − ∗ Q U We equip a language-with-view with an operational semantics: exprWithView expr × view Iris builds a WP calculus for exprWithView in iProp. We derive a WP calculus for expr in vProp and prove adequacy: WP e ϕ λU1. ∀U ⊒ U1. valid U − ∗ WP e, U

  • λv, U′. valid U′ ∗ ϕ v U′

where ϕ : val → vProp

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

slide-35
SLIDE 35

Assertions are monotonic

Subjective assertions are monotonic w.r.t. the thread’s view. One reason is the frame rule:

{x → v ∗ P}

x := v′

{λ(). x → v′ ∗ P}

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

slide-36
SLIDE 36

Assertions are monotonic

Subjective assertions are monotonic w.r.t. the thread’s view. One reason is the frame rule:

{x → v ∗ P — holds at the thread’s current view}

x := v′

{λ(). x → v′ ∗ P — holds at the thread’s now extended view}

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

slide-37
SLIDE 37

Decomposition of subjective assertions

This theorem allows us to decompose a subjective assertion P: P ⇐ ⇒ ∃U. ↑ U

  • subjective

∗ P @ U

  • bjective

We also have: P @ U = ⇒ Objectively(↑ U − ∗ P)

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

slide-38
SLIDE 38

Decomposition of subjective assertions

This theorem allows us to decompose a subjective assertion P: P ⇐ ⇒ ∃U. ↑ U

  • subjective

∗ P @ U

  • bjective

We also have: P @ U ⇐ ⇒ Objectively(↑ U − ∗ P) where Objectively Q ⇐ ⇒ (∀U. Q @ U) ⇐ ⇒ Q @ ∅

Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml