A resource-control model based on deadlock avoidance Antoine - - PowerPoint PPT Presentation

a resource control model based on deadlock avoidance
SMART_READER_LITE
LIVE PREVIEW

A resource-control model based on deadlock avoidance Antoine - - PowerPoint PPT Presentation

A resource-control model based on deadlock avoidance Antoine Galland Mathieu Baudet antoine.galland@gemplus.com mathieu.baudet@lsv.ens-cachan.fr Gemplus Research Labs LIP6 ENS Cachan INRIA Futurs A resource-control model based on


slide-1
SLIDE 1

APPSEM’2004

A resource-control model based on deadlock avoidance

Antoine Galland Mathieu Baudet

antoine.galland@gemplus.com mathieu.baudet@lsv.ens-cachan.fr

Gemplus Research Labs – LIP6 ENS Cachan – INRIA Futurs

A resource-control model based on deadlock avoidance – p. 1/21

slide-2
SLIDE 2

APPSEM’2004

Industrial Context

  • Gemplus, world’s leader in smart card manufacturing
  • Smart card applications

− Banking (Debit and credit cards, Electronic purse) − Security & access control (Identity, Biometrics, Pay TV) − Health care cards − SIM cards (GSM/GPRS/UMTS networks) − Multi-applications cards (Multos, Java Card)

A resource-control model based on deadlock avoidance – p. 2/21

slide-3
SLIDE 3

APPSEM’2004

State-of-the-art smart card

  • Embedded system with major hardware constraints
  • post-issuance principle ⇒ mobile code security
  • Next generation: multi-threading, garbage-collection,

IP-networking...

⇒ always more and more reliability:

  • Information protection

– hardware: tamper resistance, software: cryptography

  • Safety of application

– Mobile code verification: Leroy (2002), Casset et al. (2002)

  • Guarantee of execution

– Resource control

A resource-control model based on deadlock avoidance – p. 3/21

slide-4
SLIDE 4

APPSEM’2004

Problem

  • “Contract-based approach”

Problem of trust: verify that the contract is valid (safe)

− runtime : monitoring − loading : code analysis, proof

  • Resource management:

− reserve and lock all the required resource at start-up

(Java Card)

⇒ waste of resource when multiple applets are used

  • Goals:

(1) Guarantee resource availability for a safe execution (2) Optimizing resource usage

A resource-control model based on deadlock avoidance – p. 4/21

slide-5
SLIDE 5

APPSEM’2004

Problem

  • One limited resource, several applications
  • Usual contracts:

c1 δ1 and c2 δ2 require c1 + c2.

  • Could be more sparing:

max(c1, c2 + δ1)

A resource-control model based on deadlock avoidance – p. 5/21

slide-6
SLIDE 6

APPSEM’2004

Our approach

  • Improve contracts and task-scheduling
  • Three ingredients:

− Tasks suspended on impossible allocations − Deadlock-avoidance algorithm − Static analysis to annotate the code and compute

precise contracts

  • Hypothesis:

− Possible to bound (de)allocations statically − Finite execution times (so no starvation) − No other interaction

A resource-control model based on deadlock avoidance – p. 6/21

slide-7
SLIDE 7

APPSEM’2004

Outline

  • Deadlock avoidance
  • Theoretical materials

− Process algebra − Efficient safety criterion − Abstract domain

  • Practical results

− Java bytecode analyzer − Deadlock-avoidance library for Java

A resource-control model based on deadlock avoidance – p. 7/21

slide-8
SLIDE 8

APPSEM’2004

Deadlock avoidance

A resource-control model based on deadlock avoidance – p. 8/21

slide-9
SLIDE 9

APPSEM’2004

Principle of deadlock avoidance

  • Progress graphs (Dijkstra):

1 1 deadlock unsafe area unreachable area forbidden area a schedule thread 2 thread 1

A resource-control model based on deadlock avoidance – p. 9/21

slide-10
SLIDE 10

APPSEM’2004

Principle of deadlock avoidance

  • Progress graphs (Dijkstra):

1 1 deadlock unsafe area unreachable area forbidden area a schedule thread 2 thread 1

→ Detect and avoid unsafe areas to avoid deadlocks

  • Conservative approximations possible, but beware
  • f liveness

A resource-control model based on deadlock avoidance – p. 9/21

slide-11
SLIDE 11

APPSEM’2004

Why new algorithms ?

  • Existing works: Dijkstra (1965), Habermann (1969),

Holt (1972), Gold (1978)

  • Allocations inside real programs: nested forks,

branches, loops, function calls. . .

→ semantic objects.

  • Need to compute contracts from applications, and to

add code annotations

→ static code analysis → “Semantic approach” to deadlock avoidance

A resource-control model based on deadlock avoidance – p. 10/21

slide-12
SLIDE 12

APPSEM’2004

Theoretical materials

A resource-control model based on deadlock avoidance – p. 11/21

slide-13
SLIDE 13

APPSEM’2004

Process algebra

  • Abstract model for the system state:

p ::= ǫ empty process | x variation x ∈ Z of resource | (p1 p2) sequence | (p1 p2) concurrent execution

  • Small-step semantics

x

− →, execution traces l

  • Safery criterion: enough resource to end

C(p)

def

= min

p

l

− →ǫ C(l) ≤ M

A resource-control model based on deadlock avoidance – p. 12/21

slide-14
SLIDE 14

APPSEM’2004

Efficient computation of C(p)

  • Recursive translation L(p) to normalized lists

(1, −1)(3, −1)(6, 0) (5, 2) (2, 1)

  • Exact computation: C(L(p)) = C(p)
  • Worst-case complexity: O(depth × size)
  • Linear in practice

A resource-control model based on deadlock avoidance – p. 13/21

slide-15
SLIDE 15

APPSEM’2004

Remaining issues

  • Wish to use normalized lists for: static analysis,

code annotations, contracts.

  • Semantic quasi-ordering: L(p1) ⊑ L(p2) iff

C(C[p1]) ≤ C(C[p2]) for every context C

  • Minimal data-structure ? (antisymmetry)
  • How to decide ⊑ ?
  • Existence of a l.u.b. operator ⊔ ?

→ Useful for abstract interpretation (branches,

loops)

A resource-control model based on deadlock avoidance – p. 14/21

slide-16
SLIDE 16

APPSEM’2004

Properties of normalized lists

  • A rich data-structure:

− allocations − concatenation − parallel product − ordering ⊑ − least upper bound ⊔ − greatest lower bound ⊓ − least element ⊥ − greatest element ⊤

  • Linear complexities w.r.t. length.

→ Domain for abstract interpretation

see Galland and Baudet (APLAS 2003)

A resource-control model based on deadlock avoidance – p. 15/21

slide-17
SLIDE 17

APPSEM’2004

Practical results

A resource-control model based on deadlock avoidance – p. 16/21

slide-18
SLIDE 18

APPSEM’2004

Overview

  • Prototype in Java for Java bytecode,
  • Abstract scalar resource,
  • Global architecture:

LOADER

Java Runtime Environment

Off Card

annotated .class Java API with thread api Resource Server Resource

? ? new thread Thread 1 alloc Thread 2 Thread 3 Thread 4 call

On Card

? inter-methods analysis (call graph) intra-method analysis (backward interpretation)

  • riginal

.class Static Analysis Native Methods Signature A resource-control model based on deadlock avoidance – p. 17/21

slide-19
SLIDE 19

APPSEM’2004

Annotations and runtime library

Before After

1 class SimpleExample implements Executable { 1 class SimpleExample implements Executable { 2 2 3 int [] getGlobalAnnotation() { 3 int [] getGlobalAnnotation() { 4 return null; 4 return [(5,2),(2,1)]; // global contract 5 } 5 } 6 6 7 void run(String[] args){ 7 void run(String[] args){ 8 Server.alloc(1) 8 Server.alloc(1,[(4,1)(2,1)]); 9 SimpleThread thread = new SimpleThread(); 9 SimpleThread thread = new SimpleThread(); 10 10 Server.fork([(2,1)], thread, [(4,1)]); 11 thread.start(); 11 thread.start(); 12 12 Server.call([(2,2)], [0,-1]); 13 foo(args); 13 foo(args); 14 14 Server.discard(); 15 Server.alloc(-1); 15 Server.alloc(-1,[]); 16 16 Server.end(); 17 } 17 } 18 18 19 void foo(Object obj) { 19 void foo(Object obj) { 20 if (obj == null) { 20 if (obj == null) { 21 Server.alloc(-2); 21 Server.alloc(-2,[]); 22 } else { 22 } else { 23 Server.alloc(2); 23 Server.alloc(2,[]); 24 } 24 } 25 25 Server.end(); 26 } 26 } 27 27 28 static class SimpleThread extends Thread { 28 static class SimpleThread extends Thread { 29 public void run() { 29 public void run() { 30 Server.alloc(4); 30 Server.alloc(4, [(0,-3)]); 31 Server.alloc(-3); 31 Server.alloc(-3, []); 32 32 Server.end(); 33 } 33 } 34 } 34 }

(5, 2)(2, 1) = L(1) ·( (L(4) · L(−3))

  • × ( (L(−2) ⊔ L(2))
  • · L(−1)

) )

A resource-control model based on deadlock avoidance – p. 18/21

slide-20
SLIDE 20

APPSEM’2004

An example

  • Simple Java program with two threads

1 2 3 4 Resource Time CPU time-sharing Thread 1 Thread 2

  • Allocated resource

Thread 2 Thread 1 deadlock detected

  • ne schedule
  • Progress graph

A resource-control model based on deadlock avoidance – p. 19/21

slide-21
SLIDE 21

APPSEM’2004

Conclusion

  • A more sparing approach to resource control:

− fast deadlock-avoidance algorithm − new abstract domain for static analysis

  • Applied to Java
  • Future works:

− Non-terminating idioms − Contract verification − Many resources − Apply these results to a realistic resource. Why

not memory ? (escape analysis)

A resource-control model based on deadlock avoidance – p. 20/21

slide-22
SLIDE 22

APPSEM’2004

Thank you ! Q&A

A resource-control model based on deadlock avoidance – p. 21/21