\( \def\sc#1{\dosc#1\csod} \def\dosc#1#2\csod{{\rm #1{\small #2}}} \definecolor{hred}{RGB}{208,28,139} \definecolor{hblue}{RGB}{77,172,38} \definecolor{alert}{RGB}{235,129,27} \definecolor{notgreen}{RGB}{0,163,185} \def\Ret#1.{#1.\;} \def\hoareV#1#2#3#4#5{ {\begin{aligned}[#1] &\left\{{#2}\right\} \\ &\quad{#3} \\ &\left\{{#4}\right\}_{#5} \end{aligned}}% }% \def\hoare#1#2#3#4#5{% \left\{{#2}\right\} \;{#3}\; \left\{{#4}\right\}_{#5} } \newcommand{\fpfnupd}[3]{#1\!\left[#2 \mapsto #3\right]} \def\Fupd#1[#2->#3]{\fpfnupd{#1}{#2}{#3}} \newcommand{\protAt}[3]{\mbox{$ \renewcommand{\arraystretch}{0.8} \begin{array}{|@{}l@{}|@{}l@{}|} %\firsthline% \hline% \;#1 : #2\;\; & \;#3\;\; \\ %\lasthline% \hline% \end{array}$}} \def\Proto[#1:#2|#3]{\protAt{#1}{#2}{#3}}% \newcommand\eqdef{\mathrel{\triangleq}} \newcommand{\always}{\Box{}} \def\implies{\Rightarrow} \)

Strong Logic for Weak Memory

Reasoning About Release-Acquire Consistency in Iris

  1. Jan-Oliver Kaiser
  2. Hoang-Hai Dang
  3. Derek Dreyer
  4. Ori Lahav
  5. Viktor Vafeiadis




http://plv.mpi-sws.org/igps/
Weak Memory is

different threads
observing memory events in
different orders

Weak Behaviour: Store Buffering Example

x := 0; y := 0
x := 1
a := y
y := 1
b := x

Is $\;a = b = 0\;$ allowed?

  • Forbidden in sequentially consistent (SC) models
  • Allowed in (almost) all weak memory models:
    the threads have not observed each other's writes.

Weak Memory Is Ubiquitous

  • All multicore hardware exhibits weak memory behaviors
  • Preserving the fiction of SC requires synchronization barriers
  • Languages now expose weak memory accesses to satisfy programmers' demand for performance (C/C++, Java)


Our Focus: The C/C++11 Memory Model

The C11 Memory Model

— Synchronization →
Non-Atomics
Relaxed
Release-Consume
Release-Acquire
Sequential Consistency
— Performance →

Release-Acquire: Message Passing

x := 0; y := 0
x[na] := 37
y[rel] := 1 
while (y[acq] == 0){}
a := x[na]  // a = 37

alocal variable/register
x[na]non-atomic access
y[rel]atomic release write
y[acq]atomic acquire read

Challenge:
How can we formally reason about programs that use Release-Acquire + Non-Atomics?

Program Logics for C11 RA+NA

  • Relaxed Separation Logic (RSL) OOPSLA'13
  • Ghosts, Protocols, and Separation (GPS) OOPSLA'14


Soundness proofs based on axiomatic semantics

  1. Unable to use standard program logic machinery.
  2. Difficult to add standard features (i.e., ghost state).
  3. Hard to extend, adapt to other models, compose, etc.
  4. No support for mechanized proofs of programs.

What About Using Iris?

We would like to use IrisPOPL'15, ICFP'16, POPL'17, ESOP'17:
  • a framework for deriving advanced concurrent program logics
  • and using them to verify programs in Coq.


However,
  • Iris assumes interleaving semantics…
  • … whereas C11 provides axiomatic semantics

We develop interleaving semantics for C11 Release-Acquire + Non-Atomics

and derive and extend RSL & GPS in Iris

iRSL & iGPS — RSL & GPS on Top of Iris

  1. Simpler soundness proofs:
    • Proofs in standard concurrent separation logic
  2. Free advanced features from Iris (e.g., higher-order ghost state)
  3. Extensible & composable logics:
    • Both logics derived from a common base logic.
  4. Mechanized verification of programs using the Iris Proof Mode

Roadmap

Roadmap

Operational Release-Acquire: Message Passing

x := 0; y := 0
x[na] := 37
y[rel] := 1 
while (y[acq] == 0){}
a := x[na]

  • Write Event
  • Thread #1 View
  • Thread #2 View
$\View \eqdef \Loc \rightarrow \Time$

Roadmap

The Base Logic

Two essential assertions:
  1. Location ownership with write events $\hist$: $\; \lhist\loc\hist$
    (Similar in flavor to $\loc \pointsto \val$ in standard separation logic.)
  2. Thread views: $\seen\thread\view$

Base Logic: Atomic Read

$ %\PSCtx \entails \hoareV{t}{ \seen\thread\view ∗ \lhist\loc\hist %∗ %\init\hist\view }{ a := \eread\acq\loc % \quad {\color{grey} @\;\thread} }{ \begin{array}{l}% %\Ret\val. %\exists \view_1. %\exists \view' \futv \view \sqcup \view_1. %\exists \ts \ge \view(\loc). \exists (\val, \ts, \view_1) \in \hist. a = \val ∗ \ts \ge \view(\loc) \\ \quad{}∗ \seen\thread{\view \sqcup \view_1} ∗ \lhist\loc\hist \end{array} }{} $

(where $\thread$ is the thread performing the read.)

Base Logic: Message Passing

x := 0; y := 0
x[na] := 37
y[rel] := 1 
while (y[acq] == 0) {}
a := x[na]

RSL: Relaxed Separation Logic

RSLOOPSLA'13: Message passing in Release-Acquire with a
single-location invariant ${\color{alert}\pred : \Val \rightarrow \textrm{Prop}}$ .

$\color{notgreen}\Rel\loc\pred$: permission to write to $\loc$ by releasing $\pred(\val)$

$\color{hred}\Acq\loc\pred$: permission to read from $\loc$ and acquire $\pred(\val)$

$$\hoare{}{\top}{\ealloc}{\Ret\loc. {\color{notgreen}\Rel\loc\pred} ∗ {\color{hred}\Acq\loc\pred}}{}$$
$$\hoare{}{{\color{notgreen}\Rel\loc\pred} ∗ \color{alert}\pred(\val)}{\ewrite\rel\loc\val}{{\color{notgreen}\Rel\loc\pred}}{}$$
$$\hoare{}{{\color{hred}\Acq\loc\pred}}{a := \eread\acq\loc}{{{\color{hred}\Acq\loc{{\Fupd\pred[a\! ->\!\top]}}}} ∗ \color{alert}\pred(a)}{}$$

Message Passing in RSL

x := 0; y := 0
$\left\{ {\color{notgreen}\Rel{y}\pred} ∗ x \pointsto 0 \right\}$ x[na] := 37
$\left\{ {\color{notgreen}\Rel{y}\pred} ∗ x \pointsto {\color{hblue}37} \right\}$ y[rel] := 1  $\left\{ %\Rel{y}\pred \top \right\}$
$\left\{ {\color{hred}\Acq{y}\pred} \right\}$ while (y[acq] == 0) {}
$\left\{ %\Acq{y}{{\Fupd\pred[1 -> \top]}} ∗ x \pointsto 37 \right\}$ a := x[na] $\left\{a = 37 % ∗ %\Acq{y}\top ∗ x \pointsto 37 %\ldots \right\}$

$$\hoare{}{{\color{notgreen}\Rel\loc\pred} ∗ \color{alert}\pred(\val)}{\ewrite\rel\loc\val}{{\color{notgreen}\Rel\loc\pred}}{}$$
$$\hoare{}{{\color{hred}\Acq\loc\pred}}{a := \eread\acq\loc}{{{\color{hred}\Acq\loc{{\Fupd\pred[a\! ->\!\top]}}}} ∗ \color{alert}\pred(a)}{}$$

$ {\color{alert}\pred(\val)} = \begin{cases} \top & \mbox{ if } \val = 0 \\ x \pointsto 37 & \mbox{ if } \val = 1 \\ \bot & \mbox{ otherwise } \end{cases}$

Look, no views!

Encoding RSL Assertions

We encode RSL assertions as monotone view predicates in Iris.
  • $\interp{\cdot}({\color{hred}\cdot}) :$ $\textrm{RSLAssertion} \rightarrow {\color{hred}\View} \stackrel{\textrm{mon}}{\rightarrow} \textrm{IrisAssertion}$
  • $\interp{P ∗ Q}({\color{hred}\view_0}) \eqdef \interp{P}({\color{hred}\view_0}) ∗ \interp{Q}({\color{hred}\view_0)}$
  • $\interp{\hoare{}{\pre}{\expr}{\post}{}}({\color{hred}\view_0}) \eqdef\\ \forall \thread, {\color{hred}\view \futv \view_0}. \hoareV{t}{{\seen\thread\view} ∗ \interp\pre(\view)}{\expr, \thread}{{\exists \view' \futv \view. \seen\thread{\view'}} ∗ \interp\post(\view')}{}$

GPSOOPSLA'14

We also encode GPS — with very useful extensions.

Highlight

Very strong write rule for programs without write-write races:
the single-writer rule.

  • Write-write races are very rare in examples.
  • Our rule simplifies proofs dramatically.
  • Iris makes prototyping such rules very easy.

What Else is in the Paper?

  • Model of iRSL/iGPS assertions as monotone view predicates
  • Allocation and Deallocation
  • Additional useful extensions to both RSL and GPS
  • Examples from previous work
    • Circular Buffer, Bounded Ticket Lock, Michael-Scott queue, …
    • Read-Copy-Update algorithm (used in linux kernel)
All verified in Coq

© Lilia Anisimova

Backup Slides

Difference to C11

x := 0
$\ecas\var{0}{1}$ $\ewrite\rel\var{2}$;
$\eread\na\var$

GPS Write Rule

GPS-Write

$\forall \prtst' \futst \prtst. \pre ∗ \prot(\prtst', \_) \implies \prtst'' \futst \prtst'$
$\pre \implies \prot(\prtst'', \val) ∗ \post$
$\{$$\loc$:$\prtst$$\prot$${} ∗ \pre \} \; \ewrite\rel\loc\val \; \{$$\loc$:$\prtst''$$\prot$${} ∗ \post\}$

iGPS-SW-Write

$\pre ∗{}$$\loc$:$\prtst''$$\prot$${}_W$${}∗ \prot(\prtst, \_) \implies \prtst'' \futst \prtst ∗ \prot(\prtst'', \val) ∗ \post$
$\{$$\loc$:$\prtst$$\prot$${}_W$${} ∗ \pre \} \; \ewrite\rel\loc\val \; \{$$\loc$:$\prtst''$$\prot$${}_R$${} ∗ \post\}$