a resource control model based on deadlock avoidance
play

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


  1. 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 APPSEM’2004

  2. 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 APPSEM’2004

  3. 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 APPSEM’2004

  4. 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 APPSEM’2004

  5. Problem • One limited resource, several applications • Usual contracts: c 1 c 2 δ 2 require c 1 + c 2 . δ 1 and • Could be more sparing: max ( c 1 , c 2 + δ 1 ) A resource-control model based on deadlock avoidance – p. 5/21 APPSEM’2004

  6. 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 APPSEM’2004

  7. 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 APPSEM’2004

  8. Deadlock avoidance A resource-control model based on deadlock avoidance – p. 8/21 APPSEM’2004

  9. Principle of deadlock avoidance • Progress graphs (Dijkstra): thread 2 1 a schedule unreachable area deadlock forbidden area unsafe area 0 thread 1 0 1 A resource-control model based on deadlock avoidance – p. 9/21 APPSEM’2004

  10. Principle of deadlock avoidance • Progress graphs (Dijkstra): thread 2 1 a schedule unreachable area deadlock forbidden area unsafe area 0 thread 1 0 1 → Detect and avoid unsafe areas to avoid deadlocks • Conservative approximations possible, but beware of liveness A resource-control model based on deadlock avoidance – p. 9/21 APPSEM’2004

  11. 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 APPSEM’2004

  12. Theoretical materials A resource-control model based on deadlock avoidance – p. 11/21 APPSEM’2004

  13. Process algebra • Abstract model for the system state: ::= empty process p ǫ | variation x ∈ Z of resource x | ( p 1 p 2 ) sequence | ( p 1 � p 2 ) concurrent execution x • Small-step semantics − → , execution traces l • Safery criterion: enough resource to end def C ( p ) = min C ( l ) ≤ M l − → ǫ p A resource-control model based on deadlock avoidance – p. 12/21 APPSEM’2004

  14. 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 APPSEM’2004

  15. Remaining issues • Wish to use normalized lists for: static analysis, code annotations, contracts. • Semantic quasi-ordering: L ( p 1 ) ⊑ L ( p 2 ) iff C ( C [ p 1 ]) ≤ C ( C [ p 2 ]) 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 APPSEM’2004

  16. Properties of normalized lists • A rich data-structure: − allocations − least upper bound ⊔ − concatenation − greatest lower bound ⊓ − parallel product − least element ⊥ − ordering ⊑ − 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 APPSEM’2004

  17. Practical results A resource-control model based on deadlock avoidance – p. 16/21 APPSEM’2004

  18. Overview • Prototype in Java for Java bytecode, • Abstract scalar resource, • Global architecture: Off Card On Card Thread 1 alloc Resource Static Analysis original .class Thread 2 inter-methods analysis ? (call graph) new thread annotated ? LOADER Thread 3 .class intra-method analysis Resource (backward interpretation) ? Native Methods Server Thread 4 call Signature Java API with thread api Java Runtime Environment A resource-control model based on deadlock avoidance – p. 17/21 APPSEM’2004

  19. 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 [(5,2),(2,1)]; // global contract 4 return null; 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 APPSEM’2004

  20. An example • Simple Java program with two threads Resource 4 Thread 2 one schedule 3 2 1 deadlock detected Time 0 CPU time-sharing Thread 1 Thread 2 Thread 1 - Allocated resource - Progress graph A resource-control model based on deadlock avoidance – p. 19/21 APPSEM’2004

  21. 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 APPSEM’2004

  22. Thank you ! Q&A A resource-control model based on deadlock avoidance – p. 21/21 APPSEM’2004

Recommend


More recommend