Atomicity Violation Detection Prof. Moonzoo Kim CS492B Analysis of Concurrent Programs.

Slides:



Advertisements
Similar presentations
Cs4432concurrency control1 CS4432: Database Systems II Lecture #23 Concurrency Control Professor Elke A. Rundensteiner.
Advertisements

Reduction, abstraction, and atomicity: How much can we prove about concurrent programs using them? Serdar Tasiran Koç University Istanbul, Turkey Tayfun.
CS 162 Memory Consistency Models. Memory operations are reordered to improve performance Hardware (e.g., store buffer, reorder buffer) Compiler (e.g.,
Atomizer: A Dynamic Atomicity Checker For Multithreaded Programs Stephen Freund Williams College Cormac Flanagan University of California, Santa Cruz.
Types for Atomicity in Multithreaded Software Shaz Qadeer Microsoft Research (Joint work with Cormac Flanagan)
An Case for an Interleaving Constrained Shared-Memory Multi- Processor CS6260 Biao xiong, Srikanth Bala.
Atomicity in Multi-Threaded Programs Prachi Tiwari University of California, Santa Cruz CMPS 203 Programming Languages, Fall 2004.
/ PSWLAB Atomizer: A Dynamic Atomicity Checker For Multithreaded Programs By Cormac Flanagan, Stephen N. Freund 24 th April, 2008 Hong,Shin.
CS 263 Course Project1 Survey: Type Systems for Race Detection and Atomicity Feng Zhou, 12/3/2003.
Transaction Processing Lecture ACID 2 phase commit.
Concurrency Control 18.1: Schedules By Cancheevaram Kuppuswamy JaiSarvanan ID: 209.
C. FlanaganDynamic Analysis for Atomicity1. C. Flanagan2Dynamic Analysis for Atomicity Atomicity The method inc() is atomic if concurrent threads do not.
©Silberschatz, Korth and Sudarshan15.1Database System ConceptsTransactions Transaction Concept Transaction State Implementation of Atomicity and Durability.
©Silberschatz, Korth and Sudarshan16.1Database System Concepts 3 rd Edition Chapter 16: Concurrency Control Lock-Based Protocols Timestamp-Based Protocols.
C. Flanagan1Atomicity for Reliable Concurrent Software - PLDI'05 Tutorial Atomicity for Reliable Concurrent Software Joint work with Stephen Freund Shaz.
Runtime Atomicity Analysis of Multi-threaded Programs Focus is on the paper: “Atomizer: A Dynamic Atomicity Checker for Multithreaded Programs” by C. Flanagan.
1 Transaction Management Database recovery Concurrency control.
Transactions or Concurrency Control. Introduction A program which operates on a DB performs 2 kinds of operations: –Access to the Database (Read/Write)
Transactions. Definitions Transaction (program): A series of Read/Write operations on items in a Database. Example: Transaction 1 Read(C) Read(A) Write(A)
August 2006Scott Stoller, Stony Brook University1 Research in Formal Methods, Concurrent & Distributed Systems, and Programming Languages at Scott D. Stoller.
Database Management Systems I Alex Coman, Winter 2006
Verifying Commit-Atomicity Using Model Checking Cormac Flanagan University of California, Santa Cruz.
Concurrency Control 18.1 – 18.2 Chiu Luk CS257 Database Systems Principles Spring 2009.
Transactions Amol Deshpande CMSC424. Today Project stuff… Summer Internships 
Cormac Flanagan UC Santa Cruz Velodrome: A Sound and Complete Dynamic Atomicity Checker for Multithreaded Programs Jaeheon Yi UC Santa Cruz Stephen Freund.
Cs4432concurrency control1 CS4432: Database Systems II Concurrency Control.
Concurrency Control. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Transaction Processing.
/ PSWLAB Eraser: A Dynamic Data Race Detector for Multithreaded Programs By Stefan Savage et al 5 th Mar 2008 presented by Hong,Shin Eraser:
Exceptions and Mistakes CSE788 John Eisenlohr. Big Question How can we improve the quality of concurrent software?
C. FlanaganType Systems for Multithreaded Software1 Cormac Flanagan UC Santa Cruz Stephen N. Freund Williams College Shaz Qadeer Microsoft Research.
Chapter 181 Chapter 18: Concurrency Control (Slides by Hector Garcia-Molina,
Solution to Dining Philosophers. Each philosopher I invokes the operations pickup() and putdown() in the following sequence: dp.pickup(i) EAT dp.putdown(i)
Runtime Refinement Checking of Concurrent Data Structures (the VYRD project) Serdar Tasiran Koç University, Istanbul, Turkey Shaz Qadeer Microsoft Research,
Transactions Sylvia Huang CS 157B. Transaction A transaction is a unit of program execution that accesses and possibly updates various data items. A transaction.
TRANSACTIONS. Objectives Transaction Concept Transaction State Concurrent Executions Serializability Recoverability Implementation of Isolation Transaction.
02/23/2005Yan Huang - CSCI5330 Database Implementation – Transaction Transaction.
/ PSWLAB Type-Based Race Detection for J AVA by Cormac Flanagan, Stephen N. Freund 22 nd Feb 2008 presented by Hong,Shin Type-Based.
International Computer Institute, Izmir, Turkey Transactions Asst. Prof. Dr. İlker Kocabaş UBİ502 at
Introduction to Data Management CSE 344 Lecture 23: Transactions CSE Winter
IDA / ADIT Lecture 9: Transactions and concurrency control Jose M. Peña
Concurrency control. Lock-based protocols One way to ensure serializability is to require the data items be accessed in a mutually exclusive manner One.
Chapter 15 Concurrency Control Yonsei University 1 st Semester, 2015 Sanghyun Park.
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
Hint for Assignment#4: Implementing Lockset-Based Data Race Detector Prof. Moonzoo Kim Computer Science, KAIST CS492B Analysis of Concurrent Programs.
DoubleChecker: Efficient Sound and Precise Atomicity Checking Swarnendu Biswas, Jipeng Huang, Aritra Sengupta, and Michael D. Bond The Ohio State University.
Transactions and Concurrency Control Distribuerade Informationssystem, 1DT060, HT 2013 Adapted from, Copyright, Frederik Hermans.
Aritra Sengupta, Swarnendu Biswas, Minjia Zhang, Michael D. Bond and Milind Kulkarni ASPLOS 2015, ISTANBUL, TURKEY Hybrid Static-Dynamic Analysis for Statically.
©Silberschatz, Korth and Sudarshan15.1Database System Concepts Chapter 15: Transactions Transaction Concept Transaction State Implementation of Atomicity.
Random Testing of Concurrent Programs Prof. Moonzoo Kim Computer Science, KAIST CS492B Analysis of Concurrent Programs.
Chapter 15: Transactions Loc Hoang CS 157B. Definition n A transaction is a discrete unit of work that must be completely processed or not processed at.
1 CS542 Concurrency Control: Theory and Protocol Professor Elke A. Rundensteiner.
15.1 Transaction Concept A transaction is a unit of program execution that accesses and possibly updates various data items. E.g. transaction to transfer.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 14: Transactions.
Deadlock Bug Detection Techniques Prof. Moonzoo Kim CS KAIST CS492B Analysis of Concurrent Programs 1.
SHUJAZ IBRAHIM CHAYLASY GNOPHANXAY FIT, KMUTNB JANUARY 05, 2010 Distributed Database Systems | Dr.Nawaporn Wisitpongphan | KMUTNB Based on article by :
Transaction Management Exercises I/O and CPU activities can be and are overlapped to minimize (disk and processor) idle time and to maximize throughput.
Jinze Liu. ACID Atomicity: TX’s are either completely done or not done at all Consistency: TX’s should leave the database in a consistent state Isolation:
Testing Concurrent Programs Sri Teja Basava Arpit Sud CSCI 5535: Fundamentals of Programming Languages University of Colorado at Boulder Spring 2010.
Chapter 14: Transactions
Part- A Transaction Management
Threads and Memory Models Hal Perkins Autumn 2011
March 21st – Transactions
Changing thread semantics
Threads and Memory Models Hal Perkins Autumn 2009
CS162 Operating Systems and Systems Programming Review (II)
Atomic Commit and Concurrency Control
Transaction Management Overview
CPSC-608 Database Systems
Lecture 18: Concurrency Control
Database Systems (資料庫系統)
Presentation transcript:

Atomicity Violation Detection Prof. Moonzoo Kim CS492B Analysis of Concurrent Programs

Data Race Free, Yet Race Bug (1/2) Atomicity Violation Detection, Prof. Moonzoo Kim 2 public class Vector implements Collection { int elementCount ; Object [] elementData ; public Vector(Collection c){ elementCount = c.size() ; elementData = new Object[elementCount] ; c.toArray(elementData) ; } public synchronized int size(){ return elementCount ; } public synchronized Object[] toArray(Object a[]){... System.arraycopy(elementData, 0, a, 0, elementCount) ;... } public synchronized boolean add(Object o) {... elementCount++;...} } Thread 1 Vector v2=new Vector(v1); Thread 2 v1.add(obj); Data race free (protected by this ) Should be executed atomically

Data Race Free, Yet Race Bug (2/2) Atomicity Violation Detection, Prof. Moonzoo Kim 3 Thread 1Thread2 //v1.size() lock(v1) t=v1.elementCount// 10 unlock(v1) v2.elementCount=t v2.elementData=new Object[10] //v1.toArray() lock(v1) System.arraycopy(v1.elementData,0,v2.elementData,0, v1.elementCount) //v1.add() lock(v1) … v1.elementCount++ // 11 … unlock(v1) Array out of bound error

Time-Of-Check to Time-Of-Use (TOCTOU) Attack An attacker can exploit the race condition between the access and open to trick the victim into reading/overwriting an entry in the system password database. Atomicity Violation Detection, Prof. Moonzoo Kim 4 //a program installed setuid root if (access(“/home/attacker/file”,“w”) != 0) exit(1) ; fd = fopen(“/home/attacker/file”, “w+”); // Do something about fd Victim //after the access check symlink(“/etc/passwd”, “/home/attacker/file”); Attacker

Atomicity A code block is atomic if for every interleaved execution, there is an equivalent execution with the same result where the code block is executed serially (i.e., not interleaved with other threads). Programmers often assume the atomicity of a code block to reason its behavior as if it is a sequential code. c.f. atomic block: code block defined as atomic by programmers Atomicity Violation Detection, Prof. Moonzoo Kim 5

Atomicity Violation An atomicity violation (atomicity bug) is a race bug that violates the atomicity of an atomic block defined by programmers Atomicity violation detection techniques check if an observed execution is equivalent to any serial execution (i.e., serializable) – Reduction based technique – Access pattern based technique – Happens-before relation based techniques Atomicity Violation Detection, Prof. Moonzoo Kim 6

Lipton’s Reduction (1/2) An interleaved execution σ can be reduced to an equivalent interleaved execution σ’ by swapping commuting operations. Two operations a and b in σ are commuting if – a and b are executed by different threads, and – a is immediately followed by b, and – their execution orders do not change the resulting state in an execution. Atomicity Violation Detection, Prof. Moonzoo Kim 7 s0s0 s0s0 s2s2 s2s2 t1: lock(m) t2: tmp=0 t1: lock(m) t2: tmp=0 s1s1 s1’s1’ σ’ : σ :σ :

Lipton’s Reduction (2/2) An operation p is right-mover if p commutes with the operation that immediately follows p and executed by another thread An operation p is left-mover if p is commutes with the operation immediately followed by p, executed by another thread An operation p is both-mover if p is right-mover and left-mover at the same time – non-mover if p is neither right-mover nor left-mover. Atomicity Violation Detection, Prof. Moonzoo Kim 8

Atomizer [Flanagan, POPL 04] Atomizer checks if an observed execution σ can be reduced to an equivalent serial execution σ’ – Atomizer assumes that every public methods are atomic blocks – Note that, in a serial execution, executions of atomic blocks do not overlap with each other. Reduction rule Atomicity Violation Detection, Prof. Moonzoo Kim 9 Operation typeRight-mover and/or left-mover lock(m) (i.e., lock m is held by a thread)right-mover unlock(m)left-mover read(v) or write(v) where v is thread-localboth-mover read(v) or write(v) where v is shared, and consistently guarded by a lock both-mover read(v) or write(v) where v is shared, and not consistently guarded by a lock non-mover

Serializable Execution Example Atomicity Violation Detection, Prof. Moonzoo Kim 10 lock(X) write(A) read(A) read(C) write(B) unlock(X) lock(Y) write(C) read(B) unlock(Y) write(tmp) Thread 1Thread 2 lock(X) write(A) read(A) read(C) write(B) unlock(X) lock(Y) write(C) read(B) unlock(Y) write(tmp) Thread 1Thread 2 lock(X) write(A) read(A) read(C) write(B) unlock(X) lock(Y) write(C) read(B) unlock(Y) write(tmp) Thread 1Thread 2 Variable A and B are consistently guarded by lock X and Y, respectively Variable C is not consistently guarded by any lock Equivalent to a serial execution Left Right

Non-serializable Execution Example Atomicity Violation Detection, Prof. Moonzoo Kim 11 lock(X) unlock(X) read(A) read(C) lock(X) unlock(X) lock(Y) write(C) read(B) write(A) write(tmp) Thread 1Thread 2 Variables A and B are consistently guarded by lock X and Y, respectively Variable C is not consistently guarded by any lock unlock(Y) lock(X) unlock(X) read(A) read(C) lock(X) unlock(X) lock(Y) write(C) read(B) write(A) write(tmp) Thread 1Thread 2 unlock(Y) unlock(X) lock(X) Not equivalent to any serial execution Left Right lock(X) unlock(X) read(A) read(C) lock(X) unlock(X) lock(Y) write(C) read(B) write(A) write(tmp) Thread 1Thread 2 unlock(Y)

Atomicity Checking Atomizer’s serializability checking with the reduction is the same as checking if every transaction is in the following pattern: [Right-mover]* [Non-mover] ? [Left-mover] * – e.g: Two-phase locking lock(X) lock(Y) lock(Z) /* data accesses */ unlock(Z) unlock(Y) unlock(X) Atomicity Violation Detection, Prof. Moonzoo Kim 12 Expanding phase Shrinking phase L. Wang and S. D. Stoller: Runtime Analysis of Atomicity for Multithreaded Programs, IEEE TSE, 32(2), 2006

False Positive of Atomizer class Vector { Object [] elementData; int elementCount ; int size(){ 1: synchronized(this){ 2: return elementCount; 3: } } boolean contains(Object x){ //atomic block begins 4: int i=0; 5: while(i < size()){ 6: synchronized(this){ 7: if(elementData[i].equals(x)) 8: return true; 9: } 10: i++; 11: } 12: return false; //atomic block ends } Atomicity Violation Detection, Prof. Moonzoo Kim 13 1:lock(this) 2:read(elementCount) 3:unlock(this) t1: contains(o1) t2: contains(o2) 1:lock(this) 2:read(elementCount) 3:unlock(this) 1:lock(this) 2:read(elementCount) 3:unlock(this) … Detected as atomicity violation, but “semantically” serializable

Unserializable pattern#4 Unserializable pattern#2 Unserializable pattern#3 Access Pattern Based Detection Detect interleaved accesses on a shared variable that match to non-serializable patterns as atomicity violations – Select 4 among total 8 patterns as buggy based on experiences in real-bugs Atomicity Violation Detection, Prof. Moonzoo Kim 14 read(x) write(x) read(x) write(x) read(x) write(x) Unserializable pattern#1 S. Lu et al.: AVIO: Detecting Atomicity Violations via Access Interleaving Invariants, ASPLOS 2006 Unlike serial executions, first and second read operations may see different values Intended data-flow from first write to read operations may be interfered by the second write Read operation may see the data before the update is completed check-and-set in the left thread may be interfered by right thread

False Negative of Access Patterns Thread1(){ //atomic block begins synchronized(X){ a = 0 ; } synchronized(Y){ b = 0 ; } //atomic block ends } Thread2(){ //atomic block begins synchronized(X){ a = 1 ; } synchronized(Y){ b = 1 ; } //atomic block ends } Atomicity Violation Detection, Prof. Moonzoo Kim 15 lock(X) write(a,0) unlock(X) t1: Thread1() t2: Thread2() lock(X) write(a,1) unlock(X) lock(X) write(b,0) unlock(X) lock(X) write(b,1) unlock(X) a:1, b:0

Velodrome [Flanagan, PLDI 08] Velodrome defines happens- before relation over atomic block executions Veldorome detects an inconsistency in the happens- before relation (i.e. cycle) as an atomicity violation Atomicity Violation Detection, Prof. Moonzoo Kim 16

Happens-Before in Transactions (1/3) An execution is a sequence of operations A transaction in an execution is the sequence of operations in a thread, that correspond to an execution of an atomic block – Users can specify where an atomic block starts/ends in code An execution is serial if each transaction’s operation execute contiguously, without interleaving Atomicity Violation Detection, Prof. Moonzoo Kim 17

Happens-Before in Transactions (2/3) Atomicity Violation Detection, Prof. Moonzoo Kim 18

Happens-Before in Transactions (3/3) Atomicity Violation Detection, Prof. Moonzoo Kim 19 * P. A. Bernstein et al., Concurrency Control and Recovery in Database Systems, Addison-Wesley, 1987

Example Atomicity Violation Detection, Prof. Moonzoo Kim 20 lock(X) write(a) unlock(X) t1: Thread1() t2: Thread2() lock(Y) write(b) unlock(Y) lock(Z) read(c) unlock(Z) lock(X) read(a) unlock(X) t3: Thread2() lock(Y) read(b) write(c) unlock(Y) Tr#1 Tr#2 Tr#3 lock(Z) unlock(Z)

False Positive of Velodrome Execution order of write operations on a variable without read operations do not change result states, except for the last one Atomicity Violation Detection, Prof. Moonzoo Kim 21 write(a, 1) t1: Thread1() t2: Thread2() write(a, 11) write(a, 2) write(a, 12) Tr#1 Tr#2 lock(X) unlock(X) lock(X) unlock(X) lock(X) Thread1(){ //atomic block begins synchronized(X){ a = 1} synchronized(X){ a = 2 ; } //atomic block ends } Thread2(){ //atomic block begins synchronized(X){ a = 11 ; a = 12 ; } //atomic block ends }

View-Serializability (1/2) Conflict-serializability (used by Velodrome) An execution is conflict-serializable if there exists a serial execution s.t. (1) two executions have the same operations, and (2) for every pair of conflicting operations, the two operations have the same order in both executions View-serializability * An execution is view-serializable if there exists a serial execution s. t. (1) two executions have the same operations, and (2) each read operation has the same write predecessor in both executions, and - The write-predecessor of a read operation is the last write operation on the variable that the read operation reads in an execution (3) each variable has the same final write operation in both executions Atomicity Violation Detection, Prof. Moonzoo Kim 22 * L. Wang et al.: Accurate and Efficient Runtime Detection of Atomicity Errors in Concurrent Programs, PPoPP 2006

View-Serializability (2/2) We can implement the view-serializability checking by modifying the conflict definition – Two operations p and q in an execution conflict if these access the same variable where – p is writing, and q is reading, or – q is the final write operation on the variable in the execution these operate on the same lock, or these are executed in the same thread Atomicity Violation Detection, Prof. Moonzoo Kim 23