SlideShare a Scribd company logo
1 of 60
Download to read offline
Faculty of Computer Science Institute for System Architecture, Operating Systems Group




Memory, IPC, and L4Re

Björn Döbel
What we talked about so far

• Microkernels

• Fiasco.OC

• Threads in Fiasco.OC




TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
Lecture Outline

• Some more Fiasco.OC fundamentals
      – Inter-Process Communication
      – Memory Management

• L4Re Mechanisms to implement clients and
  servers




TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
Communication

• Threads are the basic building blocks of
  Fiasco.OC/L4Re applications.
• Threads need to communicate to achieve their goals:
      –   Data exchange
      –   Synchronization
      –   Sleep
      –   Handle hardware/software interrupts
      –   Grant resource access
• This is all done using the Inter-Process
  Communication (IPC) mechanisms provided by
  Fiasco.OC.
• Jochen Liedtke: “IPC performance is the master.”



TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
IPC: Issues

• How to implement it?

• How to integrate with languages /
  environments?

• How to manage IPC securely?

• How to make it fast?




TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
IPC: Design Decisions

    Asynchronous IPC                          Synchronous IPC
      – Example: Mach                           – Example: L4
      – Pro:                                    – Pros
         • fire&forget                             • No double copy
           messaging                               • No kernel memory
                                                     involved
      – Cons:                                   – Con
         • 2 copies: into kernel                   • Partners need to
           and out of kernel                         synchronize
         • DoS attack possible if
           kernel does not
           manage IPC properly




TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
IPC: Flavors

                   Basics                            Special cases for
                                                     client/server IPC

S                  R     send

                         receive from




                                                                        server
                                                      client
S                  R
                         (closed wait)
                                                                    ?
                         receive any
?                  R
                         (open wait)


                                                  • call := send + recv
                                                    from
                                                  • reply and wait :=
                                                    send + recv any
TU Dresden, 2012-07-20          Fiasco.OC: Fundamental Mechanisms
IPC in Fiasco.OC

• IPC building block: kernel IPC Gate object
• Creation:
  L4::Factory* factory = L4Re::Env::env()->factory();
  l4_msgtag_t tag = factory->create_gate(
                     target_cap, thread_cap, label);




TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
IPC in Fiasco.OC

    • IPC building block: kernel IPC Gate object
    • Creation:
      L4::Factory* factory = L4Re::Env::env()->factory();
      l4_msgtag_t tag = factory->create_gate(
                         target_cap, thread_cap, label);
The factory is a
kernel object to
create new kernel
objects.




    TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
IPC in Fiasco.OC
                                              L4Re::Env::env()
                                              gives a program
• IPC building block: kernel IPC Gate object access to its
• Creation:                                   initial capability
                                              environment.
  L4::Factory* factory = L4Re::Env::env()->factory();
    l4_msgtag_t tag = factory->create_gate(
                       target_cap, thread_cap, label);




TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
IPC in Fiasco.OC

• IPC building block: kernel IPC Gate object
• Creation:
  L4::Factory* factory = L4Re::Env::env()->factory();
  l4_msgtag_t tag = factory->create_gate(
                     target_cap, thread_cap, label);




                                                      A thread may be attached to
                                                      multiple IPC gates. To identify
                                                      through which gate a message
                                                      arrived, every gate may get a
                                                      dedicated “label” assigned.



TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
IPC in Fiasco.OC

• IPC building block: kernel IPC Gate object
• Creation:
  L4::Factory* factory = L4Re::Env::env()->factory();
  l4_msgtag_t tag = factory->create_gate(
                     target_cap, thread_cap, label);




 A free slot in the task's capability
 table. The newly created object is
 referenced by this slot. Usually
 allocated using:
 L4Re::Util::cap_alloc.alloc()


TU Dresden, 2012-07-20     Fiasco.OC: Fundamental Mechanisms
IPC in Fiasco.OC

• IPC building block: kernel IPC Gate object
• Creation:
  L4::Factory* factory = L4Re::Env::env()->factory();
  l4_msgtag_t tag = factory->create_gate(
                     target_cap, thread_cap, label);
• Receiving a message:
   – Open wait using thread's UTCB
   – Unblocks upon message arrival → use label to
     distinguish IPC gates
• Sending a reply:
   – Normally, one would need a capability to send the
     reply to. But we only have the (one-way) IPC gate!
   – Fiasco.OC stores last caller's reply capability
     internally.
       • May be used until next wait() starts.
TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
IPC: The UTCB

• User-level Thread Control Block
• Set of “virtual” registers
• Message Registers                                             Message
   – System call parameters                                     Registers
   – IPC: direct copy to receiver
• Buffer registers
                                                                 Buffer
   – Receive flexpage descriptors
                                                                Registers
• Thread Control Registers
   – Thread-private data                                      Thread Control
   – Preserved, not copied                                      Registers



 TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
IPC: The Message Tag

• Special descriptor that defines which parts of the
  UTCB are valid upon an IPC call.
                  31                                                  16
                                        Protocol
                         Flags          Items                 Words
                  15             12                    6              0
• Protocol: user-defined “message type”
• Words: number of valid items in message
  registers. Directly copied to receiver.
• Items: number of valid items in buffer registers.
  Handled specially by the kernel.



TU Dresden, 2012-07-20           Fiasco.OC: Fundamental Mechanisms
IPC: Special Features

• Timeouts
      – Maximum amount of time to wait for partner to
        become ready.
      – Most common: 0 and NEVER
      – Separate timeouts for send and receive phases

• Exceptions
   – Fiasco.OC can notify an exception handler
     thread of special events that happened to
     another thread
      • Memory management: page faults
      • Virtualization exceptions


TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
Happily writing IPC code...

/* Arguments: 1 integer parameter, 1 char array with size */
int FOO_OP1_call(l4_cap_idx_t dest, int arg1, char *arg2, unsigned 
size) {
    int idx = 0; // index into message registers
    
    // opcode and first arg go into first 2 registers
    l4_utcb_mr()­>mr[idx++] = OP1_opcode;
    l4_utcb_mr()­>mr[idx++] = arg1;

    // tricky: memcpy buffer into registers, adapt idx according
    //           to size (XXX NO BOUNDS CHECK!!!)
    memcpy(&l4_utcb_mr()­>mr[idx], arg2, size);
    idx += round_up(size / sizeof(int));

    // create message tag (prototype, <idx> words, no bufs, no flags)
    l4_msgtag_t tag = l4_msg_tag(PROTO_FOO, idx, 0, 0);
    return l4_error(l4_ipc_call(dest, l4_utcb(), tag, TIMEOUT_NEVER));
}


TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
Happily … ?

• This is dull and error-prone work!
• It can be automated:
   – Take 1: Interface Definition Language (IDL)
        interface FOO {
            int OP1(int arg1,
                    [size_is(arg2_size)] char *arg2,
                    unsigned arg2_size);
        };
      – IDL Compiler automatically generates IPC code.
         • Worked for older versions of L4(Env):
           Dice – DROPS IDL Compiler

      – Currently out of service. :(


TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
Integrating IPC with C++

• L4Re (and Genode!) use C++ stream operators to
  make IPC fancier.
      – Compiler takes care of serializing basic data types
        into the right place.

• Stream library can abstract from the underlying
  kernel
      – reuse the same IPC code on different kernels
      – heavily used in Genode

• Users work with special IPC Stream objects.

• Good news: This can even be combined with an
  IDL compiler.
TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
L4Re: IPC Streams – Client

int Foo::op1(l4_cap_idx_t dest, int arg1,
             char *arg2, unsigned arg2_size)
   {
       int result = ­1;
       L4_ipc_iostream i(l4_utcb()); // create stream
       i << Foo::Op1               // args → buffer
         << arg1 
         << Buffer(arg2, arg2_size);

          // perform call
          int err = l4_error(i.call(dest);)
          if (!err)
             i >> result;
          return result;
      }

TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
L4Re: IPC Streams – Server

int Foo::dispatch(L4_ipc_iostream& str, l4_msgtag_t tag) {
  // check for invalid invocations
  if (tag.label() != PROTO_FOO)
    return ­L4_ENOSYS;

  int opcode, arg1, retval;
  Buffer argbuf(MAX_BUF_SIZE);

  str >> opcode;
  switch(opcode) {
    case Foo::Op1:
      str >> arg1 >> argbuf;
      // do something clever, calculate retval
      str << retval;
      return L4_EOK;
    // .. more cases ..
  }} 

TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
L4Re: IPC Framework

• L4Re provides IPC framework
      – Implementation (& docs):
        l4/pkg/cxx/lib/ipc/include

      – C++ streams → ipc_stream
            • Marshalling/unmarshalling of basic data types
              (C++ POD, C strings)

      – C++ server framework → ipc_server

• Usage example: l4/pkg/examples/clntsrv




TU Dresden, 2012-07-20    Fiasco.OC: Fundamental Mechanisms
L4Re: Server Infrastructure

• C++ classes to implement servers

      – Basic message reception
         • Optional advanced error handling etc.

      – Handling of server objects
         • Varying types
         • Varying amount of objects




TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
L4Re: Init scripts & connections

• Implements a basic server loop                                    L4::Server
     while (1) {
         m = recv_message();
         ret = dispatch(m.tag(), ios);
         reply(m, ret);
     }

• Users need to provide a dispatch() function.
   – If curious, see L4::Ipc_svr::Direct_dispatch

• Plus: Loop hooks
   – Allows you to specify callbacks for
            • IPC error
            • Timeout
            • Prepare to wait
      – You should get away with L4::Default_look_hooks
TU Dresden, 2012-07-20          Fiasco.OC: Fundamental Mechanisms
Server objects


• Servers may provide                                         L4::Server_object
      – Different services
      – To different clients
      – Through different server objects

• A server object is basically a wrapper for a capability:
  L4::Server_object::obj_cap()

• Server object implementations may vary
      – Need a dedicated dispatch() function per object


• But how does the server decide at runtime which
  function to call?

TU Dresden, 2012-07-20    Fiasco.OC: Fundamental Mechanisms
Object registry


• Server objects are stored in                               L4::Basic_registry
  per-server object registry


• Registry provides a function to find an object by an ID
          L4::Basic_registry::Value 
             L4::Basic_registry::find(l4_umword_t id);

• ID is the label of the IPC gate through which a
  message arrived.

• Basic_registry is basic:
      – No ID management
      – ID is simply interpreted as a pointer to a local object

TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
Advanced object management


• Advanced servers want to bind                              L4::Basic_registry
  objects to
      – IPC gates or
      – Names specified in the Lua init script                   L4Re::Util
                                                              ::Object_registry

• Use object pointer as label for
  IPC gate

    L4::Cap<void> register_obj(L4::Server_object *o,
                               char const *service);

    L4::Cap<void> register_obj(L4::Server_object *o);

    bool unregister_obj(L4::Server_obj *o);



TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
Using Object_registry in a server


• There's a utility class representing a server with an
  object registry:

    L4Re::Util::Registry_server

                L4::Basic_registry                                 L4::Server



                    L4Re::Util         1                         L4Re::Util
                 ::Object_registry                           ::Registry_server


                                                         call dispatch()
                         *
                L4::Server_object
TU Dresden, 2012-07-20         Fiasco.OC: Fundamental Mechanisms
Server Implementation for Beginners


• Declare a server:

    static L4Re::Util::Registry_server<> server;

• Implement a session factory object:

    class MySessionServer 
        : public L4::Server_object
    { .. };

• Implement a dispatch function:

    int MySessionServer::dispatch(l4_umword_t o,
               L4::Ipc_iostream& ios)
    { .. };

TU Dresden, 2012-07-20     Fiasco.OC: Fundamental Mechanisms
Connecting Client & Server

• L4Re setups are usually started using an init
  script → Lua programming language.

• So far, we put a single binary as direct
  parameter to moe:

    roottask moe --init=rom/hello

    → instead of --init, we can pass a Lua script:

    roottask moe rom/hello.lua
    ..
    module hello.lua
TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
Initialization: Lua

• Simple script to start hello:
                                   Import the L4 Lua library
    require(“L4”);
    L4.default_loader:start( {}, “rom/hello” );




TU Dresden, 2012-07-20    Fiasco.OC: Fundamental Mechanisms
Initialization: Lua

 • Simple script to start hello:

     require(“L4”);
     L4.default_loader:start( {}, “rom/hello” );



The default_loader pro-
vides functionality to launch
ELF executables.




 TU Dresden, 2012-07-20         Fiasco.OC: Fundamental Mechanisms
Initialization: Lua

• Simple script to start hello:

    require(“L4”);
    L4.default_loader:start( {}, “rom/hello” );




                                           The start() function takes 2 parameters:

                                           1. An environment for the application.
                                              (More later.)
                                           2. The file name of the binary to launch.




TU Dresden, 2012-07-20    Fiasco.OC: Fundamental Mechanisms
L4/Lua: Connecting Services

• Lua interpreter establishes communication channels an
                                     new_channel() creates
                                     IPC gate. No thread is
  and passes them through the environment. it yet.
                                     bound to

    local ld = L4.default_loader;
    local the_server = ld:new_channel();

    ld:start( { caps = { calc_server = the_server:svr() },
                log = { “server”, “blue” } },
              “rom/server” );

    ld:start( { caps = { calc_server = the_server },
                 log = { “client”, “green” } },
               “rom/client” );



TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
L4/Lua: Connecting Services
caps = {} defines additional capabilities that are passed
to the application on startup. The syntax is
<name> = interpreter establishes communication channels
   • Lua <object>, where name is later used to
query this capability at runtime and object is a reference
       and passes them through the environment.
to an object.

For IPC channels, L4.default_loader;
      local ld = 'object' is the sender side of the
channel, while 'object:svr()' refers to the server/
receiver side. the_server = ld:new_channel();
      local

      ld:start( { caps = { calc_server = the_server:svr() },
                  log = { “server”, “blue” } },
                “rom/server” );

      ld:start( { caps = { calc_server = the_server },
                   log = { “client”, “green” } },
                 “rom/client” );



  TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
L4/Lua: Connecting Services

• Lua interpreter establishes communication channels
  and passes them through the} environment.
                log = { <tag>, <color>
                       configures this application's log output. All log messages
                       will be sent to the serial line by default. Every line for the
    local     ld = L4.default_loader;with “<tag> | “ and will be colored in
                       application will start
    local     the_server respective VT100 terminal color.
                       the = ld:new_channel();


    ld:start( { caps = { calc_server = the_server:svr() },
                log = { “server”, “blue” } },
              “rom/server” );

    ld:start( { caps = { calc_server = the_server },
                 log = { “client”, “green” } },
               “rom/client” );



TU Dresden, 2012-07-20          Fiasco.OC: Fundamental Mechanisms
Requesting an external object

• All objects that are placed in a program's
  capability space can at runtime be requested
  using

    L4::Cap<Foo> cap =
        L4Re::Env::env()->get_cap<Foo>(“name”);

    if (cap.is_valid())
        /* use cap */




TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
That's a lot of information!

• There are examples to try out in l4/pkg/examples!

      – Might not be checked out yet, so go to l4/pkg and do
        $> svn up examples

      – Example code is rather small and demonstrates only one
        feature at a time.




TU Dresden, 2012-07-20    Fiasco.OC: Fundamental Mechanisms
TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
Booting Fiasco.OC

• BIOS initializes platform and then executes boot
  sector.
• Boot loader (e.g., GRUB) loads kernel and
  multiboot modules.
      – We skip this step in QEMU.
• Bootstrap
      – interprets multiboot binaries
      – sets up the kernel info page
      – Launches Fiasco.OC kernel
• Fiasco.OC initializes and then starts
      – Sigma0 (by definition, L4's basic resource manager)
      – Moe (the root task)



TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
Moe starts a new task
4GB
                Kernel Area                              • Thread needs code /
                                                           data / stack to
3GB                                                        execute.
                                                         • Loader retrieves code
                                                           and data from the
                     Stack                                 program binary.
                                                         • Stack is allocated at
                     Code                                  runtime through the
                     Data                                  application's memory
    0                                                      allocator.


                         Moe                                   Sigma0
                    Root Task                                 Root Pager


                                     Fiasco.OC
                                      Microkernel

TU Dresden, 2012-07-20          Fiasco.OC: Fundamental Mechanisms
Moe starts a new task
4GB
                Kernel Area                              • ELF loader determines
                                                           binary entry point
3GB                                                        → EIP
                                                         • ELF loader sets up an
                                             esp           initial stack
                     Stack                                 (containing argv &
                                                           env) → ESP
                     Code                                • Loader creates task
                                             eip
                     Data                                  with initial thread set
    0                                                      to EIP / ESP


                         Moe
                    Root Task




TU Dresden, 2012-07-20          Fiasco.OC: Fundamental Mechanisms
Initial thread raises a page fault

• Initial thread starts
            → accesses first instruction
            → HW finds no valid page table entry
            → page fault!
• Page faults are a CPU exception (#14)
            → delivered in kernel mode
            → kernel needs to have set up an IDT entry
            → IDT entry points to a handler function
              (page fault handler)
• Page fault handler needs to make a decision on how
  the HW page table needs to be modified
            → decision is a policy
                    → should be kept out of the kernel!
            → PT modifications are privileged operations
                    → needs to be handled in kernel!

TU Dresden, 2012-07-20    Fiasco.OC: Fundamental Mechanisms
Fiasco.OC: Page Fault Handling


           Application’s address space


                                                           Every thread has a unique
                                                           user-level page fault handler
                                                           assigned: the pager.

eip

                                                   Page fault




                         Fiasco.OC               Page Fault
                         Microkernel              Handler



TU Dresden, 2012-07-20           Fiasco.OC: Fundamental Mechanisms
Fiasco.OC: Pager


           Application’s address space                        Pager’s address space


                                                                     Pager Memory


                                                                      Pager Code


                                                                     Page Fault Message:




                                                                                           IPC call
                                                                     - faulting address
                                                                     - faulting EIP
                                                                     - read/write access


                         Fiasco.OC               Page Fault
                         Microkernel              Handler



TU Dresden, 2012-07-20           Fiasco.OC: Fundamental Mechanisms
Fiasco.OC: Memory mapping


           Application’s address space                        Pager’s address space


                                                                     Pager Memory


                                                                      Pager Code




                            resume
                            execution                                   map(pages)


                         Fiasco.OC               Page Fault
                         Microkernel              Handler


                                                  adapt page tables
TU Dresden, 2012-07-20           Fiasco.OC: Fundamental Mechanisms
Fiasco.OC: Mapping

• Page fault reflection and mapping are
  implemented using IPC.
   – Pager blocking waits for page fault messages.
   – Range to map from pager to client is described
     in special data structure: flexpage.

                    page address(20)        size(6)     ~(2)       rights(4)



      – The thread's UTCB contains an area that is
        intended to hold flexpages → buffer registers.




TU Dresden, 2012-07-20         Fiasco.OC: Fundamental Mechanisms
User-Level Pagers

• Chicken vs. egg: who resolves page faults for
  sigma0, the initial pager?
      – Fiasco.OC initially maps all memory to sigma0,
        so that it never raises page faults.

• User-level pagers allow implementing
  complex management policies
      – But basic services might only want simple
        management.

• Solution: Pagers can be stacked into pager
  hierarchies.

TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
Pager Hierarchies

                            Application                                    Application




                                    Pager 3                               Disk Driver



                             Pager 1                                  Pager 2




                         Phys. Memory
                         1-to-1 mapped                 Initial Address Space


                                         Fiasco.OC
                                         Microkernel

TU Dresden, 2012-07-20           Fiasco.OC: Fundamental Mechanisms
Pager Hierarchies: A Problem

                            Application                                    Application




                                    Pager 3                               Disk Driver



                             Pager 1                                  Pager 2




                         Phys. Memory
                         1-to-1 mapped                 Initial Address Space


                                         Fiasco.OC
                                         Microkernel

TU Dresden, 2012-07-20           Fiasco.OC: Fundamental Mechanisms
Pager Hierarchies: A Problem

                            Application                                    Application




                                                        How does the kernel know
                                    Pager 3             which pager isDriver
                                                                   Disk responsible

                                                        for handling a fault?
                             Pager 1                                  Pager 2




                         Phys. Memory
                         1-to-1 mapped                 Initial Address Space


                                         Fiasco.OC
                                         Microkernel

TU Dresden, 2012-07-20           Fiasco.OC: Fundamental Mechanisms
Pager Hierarchies: A Problem

                            Application                                    Application




                                                        How does the kernel know
                                    Pager 3             which pager isDriver
                                                                   Disk responsible

                                                        for handling a fault?
                             Pager 1                                  Pager 2
                                                        Every problem in CS can
                                                        be solved by another layer
                         Phys. Memory                   of indirection!
                         1-to-1 mapped                 Initial Address Space


                                         Fiasco.OC
                                         Microkernel

TU Dresden, 2012-07-20           Fiasco.OC: Fundamental Mechanisms
Pager Hierarchies: A Problem

                            Application                                    Application




                                                        How does the kernel know
                                    Pager 3             which pager isDriver
                                                                   Disk responsible

                                                        for handling a fault?
                             Pager 1                                  Pager 2
                                                        Every problem in CS can
                                                        be solved by another layer
                         Phys. Memory                   of indirection!
                         1-to-1 mapped                 Initial Address Space


                                         Fiasco.OC
                                         Microkernel             Region Mapper!
TU Dresden, 2012-07-20           Fiasco.OC: Fundamental Mechanisms
Region Mapper

• Every task has a single pager thread, the
  region mapper (RM).
      – RM is the first thread within an L4Re task.
      – RM maintains a region map:
      Application            VM Region        Pager              Pager 1

       Region Mapper         <start, end>      Pager 1
                             <start, end>      Pager 2
                             <start, end>      Pager 2
           Pager 1                                               Pager Memory


           Pager 2
                                                                  Pager Code
           Pager 2




               Fiasco.OC          Page-Fault
               Microkernel         Handler

TU Dresden, 2012-07-20       Fiasco.OC: Fundamental Mechanisms
Region Mapper and Page Faults

• All threads of a task have the RM assigned as
  their pager.
• Fiasco.OC redirects all page faults to the RM.
• RM then uses synchronous IPC calls to obtain
  “real” memory mappings from the external
  pager responsible for a region.
• This requires a last building block: a generic
  abstraction for mapping memory.

                         → Dataspaces


TU Dresden, 2012-07-20       Fiasco.OC: Fundamental Mechanisms
Dataspaces

• Address spaces may consist of memory from
  different sources
      –   Binary: code/data sections
      –   File system: memory-mapped files
      –   Anonymous memory (stacks)
      –   Network packets
      –   Device MMIO regions

• The RM does not care about the details. It only
  manages regions consisting of pages.
          → generic memory object: dataspace
          → detailed implementation in dedicated memory
            manager

TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
L4Re Dataspace Management

• Application obtains a capability to a
  dataspace
• Application asks its RM to attach this
  dataspace to virtual memory.
      – RM finds free block in virt. AS that fits the DS.
      – RM returns the address of this block.
• The application now uses the dataspace by
  simply accessing memory.
• The RM makes sure that all page faults are
  handled by obtaining mappings from the
  dataspace manager.

TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
Putting things together



Application’s                                                         Dataspace Manager’s
Address Space                                    Dataspaces           Address Space

Dataspace Manager 1
    Dataspace 1                                 ds1


Dataspace Manager 2                             ds2                   Dataspace Manager’s
    Dataspace 1                                                       Memory

Dataspace Manager 2       Region Map
    Dataspace 2           VM Region       Dataspace
                          <start, end>    Dataspace Manager 1, 1
                           <start, end>   Dataspace Manager 2, 1
                           <start, end>   Dataspace Manager 2, 2




 TU Dresden, 2012-07-20           Fiasco.OC: Fundamental Mechanisms
Assignment

• Implement an encryption server based on L4Re
      – For an example, see l4/pkg/examples/clntsrv

      – 2 functions: encrypt and decrypt
         • Encryption: client sends plain text and receives
           encrypted version.
         • Decryption: client sends encrypted text and
           receives plain text.

      – If you fancy learning about dataspaces:
          • initialize session by letting the client pass a
            dataspace to the server
          • The dataspace can then be used to exchange
            plain and encrypted texts
TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms
Further Reading

• N. Feske: “A case study on the cost and benefit of
  dynamic RPC marshalling for low-level system
  components”
    http://os.inf.tu-dresden.de/papers_ps/feske07-dynrpc.pdf
    Using C++ streams for IPC marshalling

• M. Aron: “The SawMill Framework for Virtual Memory
  Diversity”
    http://cgi.cse.unsw.edu.au/~kevine/pubs/acsac01.pdf
    Generic memory management using dataspaces

• G. Hunt: “Singularity – Rethinking the Software Stack”
    http://research.microsoft.com/apps/pubs/?id=69431
    Some very cool ideas on using safe languages for
    implementing operating systems.

TU Dresden, 2012-07-20   Fiasco.OC: Fundamental Mechanisms

More Related Content

What's hot

Fast Start Failover DataGuard
Fast Start Failover DataGuardFast Start Failover DataGuard
Fast Start Failover DataGuardBorsaniya Vaibhav
 
MySQL operator for_kubernetes
MySQL operator for_kubernetesMySQL operator for_kubernetes
MySQL operator for_kubernetesrockplace
 
Volume Encryption In CloudStack
Volume Encryption In CloudStackVolume Encryption In CloudStack
Volume Encryption In CloudStackShapeBlue
 
Presentation data domain advanced features and functions
Presentation   data domain advanced features and functionsPresentation   data domain advanced features and functions
Presentation data domain advanced features and functionsxKinAnx
 
Capacity Planning Your Kafka Cluster | Jason Bell, Digitalis
Capacity Planning Your Kafka Cluster | Jason Bell, DigitalisCapacity Planning Your Kafka Cluster | Jason Bell, Digitalis
Capacity Planning Your Kafka Cluster | Jason Bell, DigitalisHostedbyConfluent
 
Room 1 - 7 - Lê Quốc Đạt - Upgrading network of Openstack to SDN with Tungste...
Room 1 - 7 - Lê Quốc Đạt - Upgrading network of Openstack to SDN with Tungste...Room 1 - 7 - Lê Quốc Đạt - Upgrading network of Openstack to SDN with Tungste...
Room 1 - 7 - Lê Quốc Đạt - Upgrading network of Openstack to SDN with Tungste...Vietnam Open Infrastructure User Group
 
Automating with NX-OS: Let's Get Started!
Automating with NX-OS: Let's Get Started!Automating with NX-OS: Let's Get Started!
Automating with NX-OS: Let's Get Started!Cisco DevNet
 
The Juniper SDN Landscape
The Juniper SDN LandscapeThe Juniper SDN Landscape
The Juniper SDN LandscapeChris Jones
 
Introducing KRaft: Kafka Without Zookeeper With Colin McCabe | Current 2022
Introducing KRaft: Kafka Without Zookeeper With Colin McCabe | Current 2022Introducing KRaft: Kafka Without Zookeeper With Colin McCabe | Current 2022
Introducing KRaft: Kafka Without Zookeeper With Colin McCabe | Current 2022HostedbyConfluent
 
Oracle 12c PDB insights
Oracle 12c PDB insightsOracle 12c PDB insights
Oracle 12c PDB insightsKirill Loifman
 
Flink on Kubernetes operator
Flink on Kubernetes operatorFlink on Kubernetes operator
Flink on Kubernetes operatorEui Heo
 
IBM Spectrum Scale Security
IBM Spectrum Scale Security IBM Spectrum Scale Security
IBM Spectrum Scale Security Sandeep Patil
 
Oracle Cloud Infrastructure:2021年4月度サービス・アップデート
Oracle Cloud Infrastructure:2021年4月度サービス・アップデートOracle Cloud Infrastructure:2021年4月度サービス・アップデート
Oracle Cloud Infrastructure:2021年4月度サービス・アップデートオラクルエンジニア通信
 
[NDC17] Kubernetes로 개발서버 간단히 찍어내기
[NDC17] Kubernetes로 개발서버 간단히 찍어내기[NDC17] Kubernetes로 개발서버 간단히 찍어내기
[NDC17] Kubernetes로 개발서버 간단히 찍어내기SeungYong Oh
 
SQL Server Performance Tuning Essentials
SQL Server Performance Tuning EssentialsSQL Server Performance Tuning Essentials
SQL Server Performance Tuning EssentialsMasaki Hirose
 
IBM Think 2018: IBM MQ High Availability
IBM Think 2018: IBM MQ High AvailabilityIBM Think 2018: IBM MQ High Availability
IBM Think 2018: IBM MQ High AvailabilityJamie Squibb
 
IBM Storwize V7000 — unikátní virtualizační diskové pole
IBM Storwize V7000 — unikátní virtualizační diskové poleIBM Storwize V7000 — unikátní virtualizační diskové pole
IBM Storwize V7000 — unikátní virtualizační diskové poleJaroslav Prodelal
 
Kubernetes Networking - Sreenivas Makam - Google - CC18
Kubernetes Networking - Sreenivas Makam - Google - CC18Kubernetes Networking - Sreenivas Makam - Google - CC18
Kubernetes Networking - Sreenivas Makam - Google - CC18CodeOps Technologies LLP
 

What's hot (20)

Fast Start Failover DataGuard
Fast Start Failover DataGuardFast Start Failover DataGuard
Fast Start Failover DataGuard
 
MySQL operator for_kubernetes
MySQL operator for_kubernetesMySQL operator for_kubernetes
MySQL operator for_kubernetes
 
Volume Encryption In CloudStack
Volume Encryption In CloudStackVolume Encryption In CloudStack
Volume Encryption In CloudStack
 
Presentation data domain advanced features and functions
Presentation   data domain advanced features and functionsPresentation   data domain advanced features and functions
Presentation data domain advanced features and functions
 
Capacity Planning Your Kafka Cluster | Jason Bell, Digitalis
Capacity Planning Your Kafka Cluster | Jason Bell, DigitalisCapacity Planning Your Kafka Cluster | Jason Bell, Digitalis
Capacity Planning Your Kafka Cluster | Jason Bell, Digitalis
 
Room 1 - 7 - Lê Quốc Đạt - Upgrading network of Openstack to SDN with Tungste...
Room 1 - 7 - Lê Quốc Đạt - Upgrading network of Openstack to SDN with Tungste...Room 1 - 7 - Lê Quốc Đạt - Upgrading network of Openstack to SDN with Tungste...
Room 1 - 7 - Lê Quốc Đạt - Upgrading network of Openstack to SDN with Tungste...
 
Automating with NX-OS: Let's Get Started!
Automating with NX-OS: Let's Get Started!Automating with NX-OS: Let's Get Started!
Automating with NX-OS: Let's Get Started!
 
The Juniper SDN Landscape
The Juniper SDN LandscapeThe Juniper SDN Landscape
The Juniper SDN Landscape
 
Introducing KRaft: Kafka Without Zookeeper With Colin McCabe | Current 2022
Introducing KRaft: Kafka Without Zookeeper With Colin McCabe | Current 2022Introducing KRaft: Kafka Without Zookeeper With Colin McCabe | Current 2022
Introducing KRaft: Kafka Without Zookeeper With Colin McCabe | Current 2022
 
UCS Presentation
UCS PresentationUCS Presentation
UCS Presentation
 
Oracle 12c PDB insights
Oracle 12c PDB insightsOracle 12c PDB insights
Oracle 12c PDB insights
 
Flink on Kubernetes operator
Flink on Kubernetes operatorFlink on Kubernetes operator
Flink on Kubernetes operator
 
IBM Spectrum Scale Security
IBM Spectrum Scale Security IBM Spectrum Scale Security
IBM Spectrum Scale Security
 
Oracle Cloud Infrastructure:2021年4月度サービス・アップデート
Oracle Cloud Infrastructure:2021年4月度サービス・アップデートOracle Cloud Infrastructure:2021年4月度サービス・アップデート
Oracle Cloud Infrastructure:2021年4月度サービス・アップデート
 
[NDC17] Kubernetes로 개발서버 간단히 찍어내기
[NDC17] Kubernetes로 개발서버 간단히 찍어내기[NDC17] Kubernetes로 개발서버 간단히 찍어내기
[NDC17] Kubernetes로 개발서버 간단히 찍어내기
 
SQL Server Performance Tuning Essentials
SQL Server Performance Tuning EssentialsSQL Server Performance Tuning Essentials
SQL Server Performance Tuning Essentials
 
IBM Think 2018: IBM MQ High Availability
IBM Think 2018: IBM MQ High AvailabilityIBM Think 2018: IBM MQ High Availability
IBM Think 2018: IBM MQ High Availability
 
IBM Storwize V7000 — unikátní virtualizační diskové pole
IBM Storwize V7000 — unikátní virtualizační diskové poleIBM Storwize V7000 — unikátní virtualizační diskové pole
IBM Storwize V7000 — unikátní virtualizační diskové pole
 
Kubernetes Networking - Sreenivas Makam - Google - CC18
Kubernetes Networking - Sreenivas Makam - Google - CC18Kubernetes Networking - Sreenivas Makam - Google - CC18
Kubernetes Networking - Sreenivas Makam - Google - CC18
 
Multi Stage Docker Build
Multi Stage Docker Build Multi Stage Docker Build
Multi Stage Docker Build
 

Viewers also liked

Сетевая подсистема в L4Re и Genode
Сетевая подсистема в L4Re и GenodeСетевая подсистема в L4Re и Genode
Сетевая подсистема в L4Re и GenodeVasily Sartakov
 
NTP Software Jan 2012 Monthly Meeting IPC Presentation
NTP Software Jan 2012 Monthly Meeting IPC PresentationNTP Software Jan 2012 Monthly Meeting IPC Presentation
NTP Software Jan 2012 Monthly Meeting IPC PresentationMuhamad Hesham
 
IPC Overview
IPC  OverviewIPC  Overview
IPC Overviewpicksa
 
Introduction to Microkernels
Introduction to MicrokernelsIntroduction to Microkernels
Introduction to MicrokernelsVasily Sartakov
 
Inter process communication
Inter process communicationInter process communication
Inter process communicationGift Kaliza
 
Japanese industrial standard
Japanese industrial standardJapanese industrial standard
Japanese industrial standardAlbert Candor
 
IPC in Microkernel Systems, Capabilities
IPC in Microkernel Systems, CapabilitiesIPC in Microkernel Systems, Capabilities
IPC in Microkernel Systems, CapabilitiesMartin Děcký
 
Label Printing Solutions for Manufacturing & Logistics
Label Printing Solutions for Manufacturing & LogisticsLabel Printing Solutions for Manufacturing & Logistics
Label Printing Solutions for Manufacturing & LogisticsPlus Technologies
 

Viewers also liked (9)

Сетевая подсистема в L4Re и Genode
Сетевая подсистема в L4Re и GenodeСетевая подсистема в L4Re и Genode
Сетевая подсистема в L4Re и Genode
 
NTP Software Jan 2012 Monthly Meeting IPC Presentation
NTP Software Jan 2012 Monthly Meeting IPC PresentationNTP Software Jan 2012 Monthly Meeting IPC Presentation
NTP Software Jan 2012 Monthly Meeting IPC Presentation
 
IPC Overview
IPC  OverviewIPC  Overview
IPC Overview
 
Introduction to Microkernels
Introduction to MicrokernelsIntroduction to Microkernels
Introduction to Microkernels
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Pp present on lables
Pp present on lablesPp present on lables
Pp present on lables
 
Japanese industrial standard
Japanese industrial standardJapanese industrial standard
Japanese industrial standard
 
IPC in Microkernel Systems, Capabilities
IPC in Microkernel Systems, CapabilitiesIPC in Microkernel Systems, Capabilities
IPC in Microkernel Systems, Capabilities
 
Label Printing Solutions for Manufacturing & Logistics
Label Printing Solutions for Manufacturing & LogisticsLabel Printing Solutions for Manufacturing & Logistics
Label Printing Solutions for Manufacturing & Logistics
 

Similar to Memory, IPC and L4Re

Advanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONAdvanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONLyon Yang
 
One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...
One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...
One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...Priyanka Aash
 
Scaling the Container Dataplane
Scaling the Container Dataplane Scaling the Container Dataplane
Scaling the Container Dataplane Michelle Holley
 
Dataplane programming with eBPF: architecture and tools
Dataplane programming with eBPF: architecture and toolsDataplane programming with eBPF: architecture and tools
Dataplane programming with eBPF: architecture and toolsStefano Salsano
 
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon YangPractical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon YangLyon Yang
 
Ice Age melting down: Intel features considered usefull!
Ice Age melting down: Intel features considered usefull!Ice Age melting down: Intel features considered usefull!
Ice Age melting down: Intel features considered usefull!Peter Hlavaty
 
High Performance Computing Infrastructure: Past, Present, and Future
High Performance Computing Infrastructure: Past, Present, and FutureHigh Performance Computing Infrastructure: Past, Present, and Future
High Performance Computing Infrastructure: Past, Present, and Futurekarl.barnes
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDKKernel TLV
 
Pysense: wireless sensor computing in Python?
Pysense: wireless sensor computing in Python?Pysense: wireless sensor computing in Python?
Pysense: wireless sensor computing in Python?Davide Carboni
 
英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug
英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug
英文【Xu hao chen xiaobo】find your_own_ios_kernel_bugWang Hao Lee
 
ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!Affan Syed
 
Performance Optimization of SPH Algorithms for Multi/Many-Core Architectures
Performance Optimization of SPH Algorithms for Multi/Many-Core ArchitecturesPerformance Optimization of SPH Algorithms for Multi/Many-Core Architectures
Performance Optimization of SPH Algorithms for Multi/Many-Core ArchitecturesDr. Fabio Baruffa
 
Linux rumpkernel - ABC2018 (AsiaBSDCon 2018)
Linux rumpkernel - ABC2018 (AsiaBSDCon 2018)Linux rumpkernel - ABC2018 (AsiaBSDCon 2018)
Linux rumpkernel - ABC2018 (AsiaBSDCon 2018)Hajime Tazaki
 
Beneath the Linux Interrupt handling
Beneath the Linux Interrupt handlingBeneath the Linux Interrupt handling
Beneath the Linux Interrupt handlingBhoomil Chavda
 
Find your own iOS kernel bug
Find your own iOS kernel bugFind your own iOS kernel bug
Find your own iOS kernel bugGustavo Martinez
 
MattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxMattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxgopikahari7
 

Similar to Memory, IPC and L4Re (20)

Mina2
Mina2Mina2
Mina2
 
Advanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCONAdvanced SOHO Router Exploitation XCON
Advanced SOHO Router Exploitation XCON
 
One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...
One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...
One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...
 
Scaling the Container Dataplane
Scaling the Container Dataplane Scaling the Container Dataplane
Scaling the Container Dataplane
 
Dataplane programming with eBPF: architecture and tools
Dataplane programming with eBPF: architecture and toolsDataplane programming with eBPF: architecture and tools
Dataplane programming with eBPF: architecture and tools
 
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon YangPractical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
 
Ice Age melting down: Intel features considered usefull!
Ice Age melting down: Intel features considered usefull!Ice Age melting down: Intel features considered usefull!
Ice Age melting down: Intel features considered usefull!
 
FPGA workshop
FPGA workshopFPGA workshop
FPGA workshop
 
High Performance Computing Infrastructure: Past, Present, and Future
High Performance Computing Infrastructure: Past, Present, and FutureHigh Performance Computing Infrastructure: Past, Present, and Future
High Performance Computing Infrastructure: Past, Present, and Future
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDK
 
Pysense: wireless sensor computing in Python?
Pysense: wireless sensor computing in Python?Pysense: wireless sensor computing in Python?
Pysense: wireless sensor computing in Python?
 
英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug
英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug
英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug
 
ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!
 
Performance Optimization of SPH Algorithms for Multi/Many-Core Architectures
Performance Optimization of SPH Algorithms for Multi/Many-Core ArchitecturesPerformance Optimization of SPH Algorithms for Multi/Many-Core Architectures
Performance Optimization of SPH Algorithms for Multi/Many-Core Architectures
 
Linux rumpkernel - ABC2018 (AsiaBSDCon 2018)
Linux rumpkernel - ABC2018 (AsiaBSDCon 2018)Linux rumpkernel - ABC2018 (AsiaBSDCon 2018)
Linux rumpkernel - ABC2018 (AsiaBSDCon 2018)
 
Beneath the Linux Interrupt handling
Beneath the Linux Interrupt handlingBeneath the Linux Interrupt handling
Beneath the Linux Interrupt handling
 
Find your own iOS kernel bug
Find your own iOS kernel bugFind your own iOS kernel bug
Find your own iOS kernel bug
 
Tos tutorial
Tos tutorialTos tutorial
Tos tutorial
 
MattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxMattsonTutorialSC14.pptx
MattsonTutorialSC14.pptx
 
05 defense
05 defense05 defense
05 defense
 

More from Vasily Sartakov

Мейнстрим технологии шифрованной памяти
Мейнстрим технологии шифрованной памятиМейнстрим технологии шифрованной памяти
Мейнстрим технологии шифрованной памятиVasily Sartakov
 
RnD Collaborations in Asia-Pacific Region
RnD Collaborations in Asia-Pacific RegionRnD Collaborations in Asia-Pacific Region
RnD Collaborations in Asia-Pacific RegionVasily Sartakov
 
Защита памяти при помощи NX-bit в среде L4Re
Защита памяти при помощи NX-bit в среде L4ReЗащита памяти при помощи NX-bit в среде L4Re
Защита памяти при помощи NX-bit в среде L4ReVasily Sartakov
 
Hardware Errors and the OS
Hardware Errors and the OSHardware Errors and the OS
Hardware Errors and the OSVasily Sartakov
 
Operating Systems Meet Fault Tolerance
Operating Systems Meet Fault ToleranceOperating Systems Meet Fault Tolerance
Operating Systems Meet Fault ToleranceVasily Sartakov
 
Operating Systems Hardening
Operating Systems HardeningOperating Systems Hardening
Operating Systems HardeningVasily Sartakov
 
Особенности Национального RnD
Особенности Национального RnDОсобенности Национального RnD
Особенности Национального RnDVasily Sartakov
 
Применение Fiasco.OC
Применение Fiasco.OCПрименение Fiasco.OC
Применение Fiasco.OCVasily Sartakov
 
Прикладная Информатика 6 (36) 2011
Прикладная Информатика 6 (36) 2011Прикладная Информатика 6 (36) 2011
Прикладная Информатика 6 (36) 2011Vasily Sartakov
 
Разработка встраиваемой операционной системы на базе микроядерной архитектуры...
Разработка встраиваемой операционной системы на базе микроядерной архитектуры...Разработка встраиваемой операционной системы на базе микроядерной архитектуры...
Разработка встраиваемой операционной системы на базе микроядерной архитектуры...Vasily Sartakov
 
Образование, наука, бизнес. Сегодня, завтра, послезавтра
Образование, наука, бизнес. Сегодня, завтра, послезавтраОбразование, наука, бизнес. Сегодня, завтра, послезавтра
Образование, наука, бизнес. Сегодня, завтра, послезавтраVasily Sartakov
 

More from Vasily Sartakov (20)

Мейнстрим технологии шифрованной памяти
Мейнстрим технологии шифрованной памятиМейнстрим технологии шифрованной памяти
Мейнстрим технологии шифрованной памяти
 
RnD Collaborations in Asia-Pacific Region
RnD Collaborations in Asia-Pacific RegionRnD Collaborations in Asia-Pacific Region
RnD Collaborations in Asia-Pacific Region
 
Защита памяти при помощи NX-bit в среде L4Re
Защита памяти при помощи NX-bit в среде L4ReЗащита памяти при помощи NX-bit в среде L4Re
Защита памяти при помощи NX-bit в среде L4Re
 
Hardware Errors and the OS
Hardware Errors and the OSHardware Errors and the OS
Hardware Errors and the OS
 
Operating Systems Meet Fault Tolerance
Operating Systems Meet Fault ToleranceOperating Systems Meet Fault Tolerance
Operating Systems Meet Fault Tolerance
 
Intro
IntroIntro
Intro
 
Genode OS Framework
Genode OS FrameworkGenode OS Framework
Genode OS Framework
 
Operating Systems Hardening
Operating Systems HardeningOperating Systems Hardening
Operating Systems Hardening
 
Особенности Национального RnD
Особенности Национального RnDОсобенности Национального RnD
Особенности Национального RnD
 
Genode Architecture
Genode ArchitectureGenode Architecture
Genode Architecture
 
Genode Components
Genode ComponentsGenode Components
Genode Components
 
Genode Programming
Genode ProgrammingGenode Programming
Genode Programming
 
Genode Compositions
Genode CompositionsGenode Compositions
Genode Compositions
 
Trusted Computing Base
Trusted Computing BaseTrusted Computing Base
Trusted Computing Base
 
System Integrity
System IntegritySystem Integrity
System Integrity
 
Intro
IntroIntro
Intro
 
Применение Fiasco.OC
Применение Fiasco.OCПрименение Fiasco.OC
Применение Fiasco.OC
 
Прикладная Информатика 6 (36) 2011
Прикладная Информатика 6 (36) 2011Прикладная Информатика 6 (36) 2011
Прикладная Информатика 6 (36) 2011
 
Разработка встраиваемой операционной системы на базе микроядерной архитектуры...
Разработка встраиваемой операционной системы на базе микроядерной архитектуры...Разработка встраиваемой операционной системы на базе микроядерной архитектуры...
Разработка встраиваемой операционной системы на базе микроядерной архитектуры...
 
Образование, наука, бизнес. Сегодня, завтра, послезавтра
Образование, наука, бизнес. Сегодня, завтра, послезавтраОбразование, наука, бизнес. Сегодня, завтра, послезавтра
Образование, наука, бизнес. Сегодня, завтра, послезавтра
 

Recently uploaded

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Recently uploaded (20)

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

Memory, IPC and L4Re

  • 1. Faculty of Computer Science Institute for System Architecture, Operating Systems Group Memory, IPC, and L4Re Björn Döbel
  • 2. What we talked about so far • Microkernels • Fiasco.OC • Threads in Fiasco.OC TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 3. Lecture Outline • Some more Fiasco.OC fundamentals – Inter-Process Communication – Memory Management • L4Re Mechanisms to implement clients and servers TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 4. Communication • Threads are the basic building blocks of Fiasco.OC/L4Re applications. • Threads need to communicate to achieve their goals: – Data exchange – Synchronization – Sleep – Handle hardware/software interrupts – Grant resource access • This is all done using the Inter-Process Communication (IPC) mechanisms provided by Fiasco.OC. • Jochen Liedtke: “IPC performance is the master.” TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 5. IPC: Issues • How to implement it? • How to integrate with languages / environments? • How to manage IPC securely? • How to make it fast? TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 6. IPC: Design Decisions Asynchronous IPC Synchronous IPC – Example: Mach – Example: L4 – Pro: – Pros • fire&forget • No double copy messaging • No kernel memory involved – Cons: – Con • 2 copies: into kernel • Partners need to and out of kernel synchronize • DoS attack possible if kernel does not manage IPC properly TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 7. IPC: Flavors Basics Special cases for client/server IPC S R send receive from server client S R (closed wait) ? receive any ? R (open wait) • call := send + recv from • reply and wait := send + recv any TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 8. IPC in Fiasco.OC • IPC building block: kernel IPC Gate object • Creation: L4::Factory* factory = L4Re::Env::env()->factory(); l4_msgtag_t tag = factory->create_gate( target_cap, thread_cap, label); TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 9. IPC in Fiasco.OC • IPC building block: kernel IPC Gate object • Creation: L4::Factory* factory = L4Re::Env::env()->factory(); l4_msgtag_t tag = factory->create_gate( target_cap, thread_cap, label); The factory is a kernel object to create new kernel objects. TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 10. IPC in Fiasco.OC L4Re::Env::env() gives a program • IPC building block: kernel IPC Gate object access to its • Creation: initial capability environment. L4::Factory* factory = L4Re::Env::env()->factory(); l4_msgtag_t tag = factory->create_gate( target_cap, thread_cap, label); TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 11. IPC in Fiasco.OC • IPC building block: kernel IPC Gate object • Creation: L4::Factory* factory = L4Re::Env::env()->factory(); l4_msgtag_t tag = factory->create_gate( target_cap, thread_cap, label); A thread may be attached to multiple IPC gates. To identify through which gate a message arrived, every gate may get a dedicated “label” assigned. TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 12. IPC in Fiasco.OC • IPC building block: kernel IPC Gate object • Creation: L4::Factory* factory = L4Re::Env::env()->factory(); l4_msgtag_t tag = factory->create_gate( target_cap, thread_cap, label); A free slot in the task's capability table. The newly created object is referenced by this slot. Usually allocated using: L4Re::Util::cap_alloc.alloc() TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 13. IPC in Fiasco.OC • IPC building block: kernel IPC Gate object • Creation: L4::Factory* factory = L4Re::Env::env()->factory(); l4_msgtag_t tag = factory->create_gate( target_cap, thread_cap, label); • Receiving a message: – Open wait using thread's UTCB – Unblocks upon message arrival → use label to distinguish IPC gates • Sending a reply: – Normally, one would need a capability to send the reply to. But we only have the (one-way) IPC gate! – Fiasco.OC stores last caller's reply capability internally. • May be used until next wait() starts. TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 14. IPC: The UTCB • User-level Thread Control Block • Set of “virtual” registers • Message Registers Message – System call parameters Registers – IPC: direct copy to receiver • Buffer registers Buffer – Receive flexpage descriptors Registers • Thread Control Registers – Thread-private data Thread Control – Preserved, not copied Registers TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 15. IPC: The Message Tag • Special descriptor that defines which parts of the UTCB are valid upon an IPC call. 31 16 Protocol Flags Items Words 15 12 6 0 • Protocol: user-defined “message type” • Words: number of valid items in message registers. Directly copied to receiver. • Items: number of valid items in buffer registers. Handled specially by the kernel. TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 16. IPC: Special Features • Timeouts – Maximum amount of time to wait for partner to become ready. – Most common: 0 and NEVER – Separate timeouts for send and receive phases • Exceptions – Fiasco.OC can notify an exception handler thread of special events that happened to another thread • Memory management: page faults • Virtualization exceptions TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 17. Happily writing IPC code... /* Arguments: 1 integer parameter, 1 char array with size */ int FOO_OP1_call(l4_cap_idx_t dest, int arg1, char *arg2, unsigned  size) {     int idx = 0; // index into message registers          // opcode and first arg go into first 2 registers     l4_utcb_mr()­>mr[idx++] = OP1_opcode;     l4_utcb_mr()­>mr[idx++] = arg1;     // tricky: memcpy buffer into registers, adapt idx according     //           to size (XXX NO BOUNDS CHECK!!!)     memcpy(&l4_utcb_mr()­>mr[idx], arg2, size);     idx += round_up(size / sizeof(int));     // create message tag (prototype, <idx> words, no bufs, no flags)     l4_msgtag_t tag = l4_msg_tag(PROTO_FOO, idx, 0, 0);     return l4_error(l4_ipc_call(dest, l4_utcb(), tag, TIMEOUT_NEVER)); } TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 18. Happily … ? • This is dull and error-prone work! • It can be automated: – Take 1: Interface Definition Language (IDL) interface FOO { int OP1(int arg1, [size_is(arg2_size)] char *arg2, unsigned arg2_size); }; – IDL Compiler automatically generates IPC code. • Worked for older versions of L4(Env): Dice – DROPS IDL Compiler – Currently out of service. :( TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 19. Integrating IPC with C++ • L4Re (and Genode!) use C++ stream operators to make IPC fancier. – Compiler takes care of serializing basic data types into the right place. • Stream library can abstract from the underlying kernel – reuse the same IPC code on different kernels – heavily used in Genode • Users work with special IPC Stream objects. • Good news: This can even be combined with an IDL compiler. TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 20. L4Re: IPC Streams – Client int Foo::op1(l4_cap_idx_t dest, int arg1,           char *arg2, unsigned arg2_size) {     int result = ­1;     L4_ipc_iostream i(l4_utcb()); // create stream     i << Foo::Op1    // args → buffer       << arg1        << Buffer(arg2, arg2_size);     // perform call     int err = l4_error(i.call(dest);)     if (!err)        i >> result;     return result; } TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 21. L4Re: IPC Streams – Server int Foo::dispatch(L4_ipc_iostream& str, l4_msgtag_t tag) {   // check for invalid invocations   if (tag.label() != PROTO_FOO)     return ­L4_ENOSYS;   int opcode, arg1, retval;   Buffer argbuf(MAX_BUF_SIZE);   str >> opcode;   switch(opcode) {     case Foo::Op1:       str >> arg1 >> argbuf;       // do something clever, calculate retval       str << retval;       return L4_EOK;     // .. more cases ..   }}  TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 22. L4Re: IPC Framework • L4Re provides IPC framework – Implementation (& docs): l4/pkg/cxx/lib/ipc/include – C++ streams → ipc_stream • Marshalling/unmarshalling of basic data types (C++ POD, C strings) – C++ server framework → ipc_server • Usage example: l4/pkg/examples/clntsrv TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 23. L4Re: Server Infrastructure • C++ classes to implement servers – Basic message reception • Optional advanced error handling etc. – Handling of server objects • Varying types • Varying amount of objects TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 24. L4Re: Init scripts & connections • Implements a basic server loop L4::Server while (1) { m = recv_message(); ret = dispatch(m.tag(), ios); reply(m, ret); } • Users need to provide a dispatch() function. – If curious, see L4::Ipc_svr::Direct_dispatch • Plus: Loop hooks – Allows you to specify callbacks for • IPC error • Timeout • Prepare to wait – You should get away with L4::Default_look_hooks TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 25. Server objects • Servers may provide L4::Server_object – Different services – To different clients – Through different server objects • A server object is basically a wrapper for a capability: L4::Server_object::obj_cap() • Server object implementations may vary – Need a dedicated dispatch() function per object • But how does the server decide at runtime which function to call? TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 26. Object registry • Server objects are stored in L4::Basic_registry per-server object registry • Registry provides a function to find an object by an ID L4::Basic_registry::Value  L4::Basic_registry::find(l4_umword_t id); • ID is the label of the IPC gate through which a message arrived. • Basic_registry is basic: – No ID management – ID is simply interpreted as a pointer to a local object TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 27. Advanced object management • Advanced servers want to bind L4::Basic_registry objects to – IPC gates or – Names specified in the Lua init script L4Re::Util ::Object_registry • Use object pointer as label for IPC gate L4::Cap<void> register_obj(L4::Server_object *o,                            char const *service); L4::Cap<void> register_obj(L4::Server_object *o); bool unregister_obj(L4::Server_obj *o); TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 28. Using Object_registry in a server • There's a utility class representing a server with an object registry: L4Re::Util::Registry_server L4::Basic_registry L4::Server L4Re::Util 1 L4Re::Util ::Object_registry ::Registry_server call dispatch() * L4::Server_object TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 29. Server Implementation for Beginners • Declare a server: static L4Re::Util::Registry_server<> server; • Implement a session factory object: class MySessionServer  : public L4::Server_object { .. }; • Implement a dispatch function: int MySessionServer::dispatch(l4_umword_t o, L4::Ipc_iostream& ios) { .. }; TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 30. Connecting Client & Server • L4Re setups are usually started using an init script → Lua programming language. • So far, we put a single binary as direct parameter to moe: roottask moe --init=rom/hello → instead of --init, we can pass a Lua script: roottask moe rom/hello.lua .. module hello.lua TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 31. Initialization: Lua • Simple script to start hello: Import the L4 Lua library require(“L4”); L4.default_loader:start( {}, “rom/hello” ); TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 32. Initialization: Lua • Simple script to start hello: require(“L4”); L4.default_loader:start( {}, “rom/hello” ); The default_loader pro- vides functionality to launch ELF executables. TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 33. Initialization: Lua • Simple script to start hello: require(“L4”); L4.default_loader:start( {}, “rom/hello” ); The start() function takes 2 parameters: 1. An environment for the application. (More later.) 2. The file name of the binary to launch. TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 34. L4/Lua: Connecting Services • Lua interpreter establishes communication channels an new_channel() creates IPC gate. No thread is and passes them through the environment. it yet. bound to local ld = L4.default_loader; local the_server = ld:new_channel(); ld:start( { caps = { calc_server = the_server:svr() }, log = { “server”, “blue” } }, “rom/server” ); ld:start( { caps = { calc_server = the_server }, log = { “client”, “green” } }, “rom/client” ); TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 35. L4/Lua: Connecting Services caps = {} defines additional capabilities that are passed to the application on startup. The syntax is <name> = interpreter establishes communication channels • Lua <object>, where name is later used to query this capability at runtime and object is a reference and passes them through the environment. to an object. For IPC channels, L4.default_loader; local ld = 'object' is the sender side of the channel, while 'object:svr()' refers to the server/ receiver side. the_server = ld:new_channel(); local ld:start( { caps = { calc_server = the_server:svr() }, log = { “server”, “blue” } }, “rom/server” ); ld:start( { caps = { calc_server = the_server }, log = { “client”, “green” } }, “rom/client” ); TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 36. L4/Lua: Connecting Services • Lua interpreter establishes communication channels and passes them through the} environment. log = { <tag>, <color> configures this application's log output. All log messages will be sent to the serial line by default. Every line for the local ld = L4.default_loader;with “<tag> | “ and will be colored in application will start local the_server respective VT100 terminal color. the = ld:new_channel(); ld:start( { caps = { calc_server = the_server:svr() }, log = { “server”, “blue” } }, “rom/server” ); ld:start( { caps = { calc_server = the_server }, log = { “client”, “green” } }, “rom/client” ); TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 37. Requesting an external object • All objects that are placed in a program's capability space can at runtime be requested using L4::Cap<Foo> cap = L4Re::Env::env()->get_cap<Foo>(“name”); if (cap.is_valid()) /* use cap */ TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 38. That's a lot of information! • There are examples to try out in l4/pkg/examples! – Might not be checked out yet, so go to l4/pkg and do $> svn up examples – Example code is rather small and demonstrates only one feature at a time. TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 39. TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 40. Booting Fiasco.OC • BIOS initializes platform and then executes boot sector. • Boot loader (e.g., GRUB) loads kernel and multiboot modules. – We skip this step in QEMU. • Bootstrap – interprets multiboot binaries – sets up the kernel info page – Launches Fiasco.OC kernel • Fiasco.OC initializes and then starts – Sigma0 (by definition, L4's basic resource manager) – Moe (the root task) TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 41. Moe starts a new task 4GB Kernel Area • Thread needs code / data / stack to 3GB execute. • Loader retrieves code and data from the Stack program binary. • Stack is allocated at Code runtime through the Data application's memory 0 allocator. Moe Sigma0 Root Task Root Pager Fiasco.OC Microkernel TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 42. Moe starts a new task 4GB Kernel Area • ELF loader determines binary entry point 3GB → EIP • ELF loader sets up an esp initial stack Stack (containing argv & env) → ESP Code • Loader creates task eip Data with initial thread set 0 to EIP / ESP Moe Root Task TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 43. Initial thread raises a page fault • Initial thread starts → accesses first instruction → HW finds no valid page table entry → page fault! • Page faults are a CPU exception (#14) → delivered in kernel mode → kernel needs to have set up an IDT entry → IDT entry points to a handler function (page fault handler) • Page fault handler needs to make a decision on how the HW page table needs to be modified → decision is a policy → should be kept out of the kernel! → PT modifications are privileged operations → needs to be handled in kernel! TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 44. Fiasco.OC: Page Fault Handling Application’s address space Every thread has a unique user-level page fault handler assigned: the pager. eip Page fault Fiasco.OC Page Fault Microkernel Handler TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 45. Fiasco.OC: Pager Application’s address space Pager’s address space Pager Memory Pager Code Page Fault Message: IPC call - faulting address - faulting EIP - read/write access Fiasco.OC Page Fault Microkernel Handler TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 46. Fiasco.OC: Memory mapping Application’s address space Pager’s address space Pager Memory Pager Code resume execution map(pages) Fiasco.OC Page Fault Microkernel Handler adapt page tables TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 47. Fiasco.OC: Mapping • Page fault reflection and mapping are implemented using IPC. – Pager blocking waits for page fault messages. – Range to map from pager to client is described in special data structure: flexpage. page address(20) size(6) ~(2) rights(4) – The thread's UTCB contains an area that is intended to hold flexpages → buffer registers. TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 48. User-Level Pagers • Chicken vs. egg: who resolves page faults for sigma0, the initial pager? – Fiasco.OC initially maps all memory to sigma0, so that it never raises page faults. • User-level pagers allow implementing complex management policies – But basic services might only want simple management. • Solution: Pagers can be stacked into pager hierarchies. TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 49. Pager Hierarchies Application Application Pager 3 Disk Driver Pager 1 Pager 2 Phys. Memory 1-to-1 mapped Initial Address Space Fiasco.OC Microkernel TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 50. Pager Hierarchies: A Problem Application Application Pager 3 Disk Driver Pager 1 Pager 2 Phys. Memory 1-to-1 mapped Initial Address Space Fiasco.OC Microkernel TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 51. Pager Hierarchies: A Problem Application Application How does the kernel know Pager 3 which pager isDriver Disk responsible for handling a fault? Pager 1 Pager 2 Phys. Memory 1-to-1 mapped Initial Address Space Fiasco.OC Microkernel TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 52. Pager Hierarchies: A Problem Application Application How does the kernel know Pager 3 which pager isDriver Disk responsible for handling a fault? Pager 1 Pager 2 Every problem in CS can be solved by another layer Phys. Memory of indirection! 1-to-1 mapped Initial Address Space Fiasco.OC Microkernel TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 53. Pager Hierarchies: A Problem Application Application How does the kernel know Pager 3 which pager isDriver Disk responsible for handling a fault? Pager 1 Pager 2 Every problem in CS can be solved by another layer Phys. Memory of indirection! 1-to-1 mapped Initial Address Space Fiasco.OC Microkernel Region Mapper! TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 54. Region Mapper • Every task has a single pager thread, the region mapper (RM). – RM is the first thread within an L4Re task. – RM maintains a region map: Application VM Region Pager Pager 1 Region Mapper <start, end> Pager 1 <start, end> Pager 2 <start, end> Pager 2 Pager 1 Pager Memory Pager 2 Pager Code Pager 2 Fiasco.OC Page-Fault Microkernel Handler TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 55. Region Mapper and Page Faults • All threads of a task have the RM assigned as their pager. • Fiasco.OC redirects all page faults to the RM. • RM then uses synchronous IPC calls to obtain “real” memory mappings from the external pager responsible for a region. • This requires a last building block: a generic abstraction for mapping memory. → Dataspaces TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 56. Dataspaces • Address spaces may consist of memory from different sources – Binary: code/data sections – File system: memory-mapped files – Anonymous memory (stacks) – Network packets – Device MMIO regions • The RM does not care about the details. It only manages regions consisting of pages. → generic memory object: dataspace → detailed implementation in dedicated memory manager TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 57. L4Re Dataspace Management • Application obtains a capability to a dataspace • Application asks its RM to attach this dataspace to virtual memory. – RM finds free block in virt. AS that fits the DS. – RM returns the address of this block. • The application now uses the dataspace by simply accessing memory. • The RM makes sure that all page faults are handled by obtaining mappings from the dataspace manager. TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 58. Putting things together Application’s Dataspace Manager’s Address Space Dataspaces Address Space Dataspace Manager 1 Dataspace 1 ds1 Dataspace Manager 2 ds2 Dataspace Manager’s Dataspace 1 Memory Dataspace Manager 2 Region Map Dataspace 2 VM Region Dataspace <start, end> Dataspace Manager 1, 1 <start, end> Dataspace Manager 2, 1 <start, end> Dataspace Manager 2, 2 TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 59. Assignment • Implement an encryption server based on L4Re – For an example, see l4/pkg/examples/clntsrv – 2 functions: encrypt and decrypt • Encryption: client sends plain text and receives encrypted version. • Decryption: client sends encrypted text and receives plain text. – If you fancy learning about dataspaces: • initialize session by letting the client pass a dataspace to the server • The dataspace can then be used to exchange plain and encrypted texts TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms
  • 60. Further Reading • N. Feske: “A case study on the cost and benefit of dynamic RPC marshalling for low-level system components” http://os.inf.tu-dresden.de/papers_ps/feske07-dynrpc.pdf Using C++ streams for IPC marshalling • M. Aron: “The SawMill Framework for Virtual Memory Diversity” http://cgi.cse.unsw.edu.au/~kevine/pubs/acsac01.pdf Generic memory management using dataspaces • G. Hunt: “Singularity – Rethinking the Software Stack” http://research.microsoft.com/apps/pubs/?id=69431 Some very cool ideas on using safe languages for implementing operating systems. TU Dresden, 2012-07-20 Fiasco.OC: Fundamental Mechanisms