1. 25 Oct, 2016 40 commits
    • Charlie Jacobsen's avatar
      Except IPC, kliblcd fully tested. Everything is working. · 664628a4
      Charlie Jacobsen authored
      Documentation in Documentation/lcd-domains/...
      
      Loading, mapping, and running a module is working correctly, using
      all of the capability code that interposes on each operation (mapping,
      freeing pages, etc.).
      
      cptr allocation and indexing into cspaces is working correctly.
      
      IPC testing and debugging is coming next.
      664628a4
    • Charlie Jacobsen's avatar
      Muktesh's capabilities fully incorporated. Capsicum-style enter/exit. · 6ee9a51f
      Charlie Jacobsen authored
      Builds, but not fully tested. Good tests for capability subsystem, some tests
      for kliblcd.
      
      Non-isolated kernel threads can "enter" the lcd system by doing
      klcd_enter / klcd_exit. They can create other lcd's, set them up, etc. They
      use the same interface that regular lcd's will use, so such code could be
      moved to an lcd, as we had planned. Will document this in Documentation folder
      tomorrow ( == today ).
      
      Capability system does checks now when a capability is deleted/revoked: for
      example, if it's for a page, the microkernel checks if the page is mapped, and
      unmaps it. If the last capability goes away, the page is freed. Documentation
      is in Documentation/lcd-domains/cap.txt.
      
      IPC code is in place, but not tested yet (pray for me).
      
      Debug is taking some time. Sometimes requires a power cycle which adds an
      extra 5 - 10 minutes. Build is slow the first time after reboot. Give me a user
      level program and I'll debug it in 30 seconds! argc
      
      Main arch-independent files:
      
          include/lcd-domains/kliblcd.h, types.h
      
             This is what non-isolated kernel code should include to use the
             kliblcd interface to the microkernel.
      
          virt/lcd-domains/main.c, kliblcd.c, cap.c, ipc.c, internal.h
      
             The microkernel, broken up into pieces.
      
          virt/lcd-domains/tests/
      
             The tests, in progress.
      
      Some old files are still hanging around in virt/lcd-domains and will be
      incorprated/cleaned up soon.
      
      I couldn't squash over the merge from the decomposition branch, so there's a
      bunch of junk commits coming over. (I should've just copied Muktesh's files.)
      
      Conflicts:
      	drivers/Kconfig
      	drivers/lcd-cspace/test.h
      	include/lcd-domains/cap.h
      	include/lcd-prototype/lcd.h
      	include/lcd/console.h
      	include/lcd/elfnote.h
      	include/linux/init_task.h
      	include/linux/module.h
      	include/linux/sched.h
      	virt/lcd-domains/cap.c
      	virt/lcd-domains/ipc.c
      	virt/lcd-domains/lcd-cspace-tests2.c
      Resolved-by: Vikram Narayanan's avatarVikram Narayanan <vikram186@gmail.com>
      6ee9a51f
    • Charles Jacobsen's avatar
      Works! · b9e42c88
      Charles Jacobsen authored
      b9e42c88
    • Charlie Jacobsen's avatar
    • Charles Jacobsen's avatar
      Wasn't doing a get/put on kthread. · 7ac8a242
      Charles Jacobsen authored
      Still haven't figured out page fault bug.
      7ac8a242
    • Charles Jacobsen's avatar
      Fixed build errors, module init tools. · 0f690a86
      Charles Jacobsen authored
      Getting nasty runtime bugs though.
      0f690a86
    • Charlie Jacobsen's avatar
      Finished the majority of the arch-indep code changes needed. · d71afeb4
      Charlie Jacobsen authored
      Refactored lcd's into lcd and lcd_thread. Still need to test/update
      tests.
      d71afeb4
    • Charles Jacobsen's avatar
      All (simple) lcd arch tests passing. · bee0375b
      Charles Jacobsen authored
      bee0375b
    • Charles Jacobsen's avatar
      3c809a98
    • Charlie Jacobsen's avatar
    • Charles Jacobsen's avatar
    • Charlie Jacobsen's avatar
      Separated lcd into container and thread objects. · dbc4e40c
      Charlie Jacobsen authored
      Updated code. Removed gdt/tss/idt for now. Added doc directory
      and some initial doc.
      dbc4e40c
    • Charles Jacobsen's avatar
    • Charles Jacobsen's avatar
      Switched to a kmem cache for allocating lcd_arch's. · 0f6ce597
      Charles Jacobsen authored
      Was getting bad load/store msr addresses for vm exits.
      Properly detected by the lcd_arch_check code.
      
      In struct lcd_arch, the msr_autoload fields were not
      word aligned in some instances (see requirement
      in Intel SDM V3 26.2.1.2). Even with compiler align
      attributes, if we use kmalloc, proper alignment is
      not guaranteed - we can allocate a struct lcd_arch
      on the wrong byte and it throws off the alignment
      of the entire struct.
      
      kmem cache allows specifying alignment. Appears to be
      working correctly.
      0f6ce597
    • Charlie Jacobsen's avatar
      Basic lcd module create, run, and destroy. · e0193fa4
      Charlie Jacobsen authored
      This code is ugly, but it's working.
      
      Tested with basic module, and appears to be working
      properly. I will soon incorporate the patched
      modprobe into the kernel tree, and then this code
      will be usable by everyone.
      
      The ipc code is still unimplemented. The only
      hypercall handled is yield. Also note that other
      exit conditions (e.g. external interrupt) have not
      been fully tested.
      
      Overview:
      -- kernel code calls lcd_create_as_module with
         the module's name
      -- lcd_create_as_module loads the module using
         request_lcd_module (request_lcd_module calls
         the patched modprobe to load the module, and
         the patched modprobe calls back into the lcd
         driver via the ioctrl interface to load the
         module)
      -- lcd_create_as_module then finds the loaded
         module, spawns a kernel thread and passes off
         the module to it
      -- the kernel thread initializes the lcd and
         maps the module inside it, then suspends itself
      -- lcd_run_as_module wakes up the kernel thread
         and tells it to run
      -- lcd_delete_as_module stops the kernel thread
         and deletes the module from the host kernel
      
      File-by-file details:
      
      arch/x86/include/asm/lcd-domains-arch.h
      arch/x86/lcd-domains/lcd-domains-arch-tests.c
      arch/x86/lcd-domains/lcd-domains-arch.c
      -- lcd was not running in 64-bit mode, and my
         checks had one subtle bug
      -- fixed %cr3 load to properly load vmcs first
      -- fixed set program counter to use guest virtual
         rather than guest physical address
      
      include/linux/sched.h
      -- added struct lcd to task_struct
      
      include/linux/init_task.h
      -- lcd pointer set to null when task_struct is
         initialized
      
      include/linux/module.h
      kernel/module.c
      -- made init_module and delete_module system calls
         callable from kernel code
      -- available in module.h via do_sys_init_module and
         do_sys_delete_module
      -- simply moved the majority of the guts of the
         system calls into a non-system call, exported
         routine
      -- take an extra flag, for_lcd; when set, the init
         code skips over running (and deallocating) the
         module's init code, and the delete code skips
         over running the module exit
      -- system calls from user code set for_lcd = 0; this
         ensures existing code still works
      
      include/linux/kmod.h
      kernel/kmod.c
      kernel/sysctl.c
      -- changed __request_module to __do_request_module; takes
         one extra argument, for_lcd
      -- __request_module   ==>  __do_request_module with for_lcd = 0
      -- request_lcd_module ==>  __do_request_module with for_lcd = 1
      -- call_modprobe conditionally uses lcd_modprobe_path, the path
         to a patched modprobe accessible via sysfs
      
      include/lcd-domains/lcd-domains.h
      -- added lcd status enum; see source code doc
      -- three routines for creating/running/destroying
         lcd's that use modules; see source code doc
      
      include/uapi/linux/lcd-domains.h
      -- added interface defns for patched modprobe to call into
         lcd driver for module init; lcd driver loads
         module (via slightly refactored module.c code) on behalf
         of modprobe
      
      virt/lcd-domains/lcd-domains.c
      -- implementation of routines for modules inside lcd's
      -- implementation of module init / delete for lcd's
         (uses patched module.c code)
      
      virt/lcd-domains/Kconfig
      virt/lcd-domains/Makefile
      virt/lcd-domains/lcd-module-load-test.c
      virt/lcd-domains/lcd-tests.c
      -- added test module for lcd module code
      -- test runs automatically when lcd module is inserted
      e0193fa4
    • Charles Jacobsen's avatar
      Simple blob successfully runs and returns in vmx. · c4fc774c
      Charles Jacobsen authored
      In the process of debugging, major corrections and
      debug checks implemented (this is a big squash):
      -- coded up entry checks documented in Intel SDM
         V3 chp 26 (this should help later if settings
         are changed, make it less risky to experiment
         and give more confidence)
      -- fixed host tr base addr bug (the worst bug! caused
         system to hang and then crash, since the tss
         was erroneous...)
      -- fixed vmx_entry to properly set host rsp before
         entry
      -- setting host sysenter and idt info
      -- fixed cs ar bytes bug
      -- fixed gdt limit bug
      -- fixed tr type bug
      -- extra settings added to cr0 and cr4, but may
         not be needed ... (debug fix attempt)
      -- lstar mstar autoload, may not be needed ...
         (debug fix attempt)
      c4fc774c
    • Anton Burtsev's avatar
      LCD API client and server code · fc2675ff
      Anton Burtsev authored
        -- LCD export an API to its domains that is accessible via
        capability invocations (well, syscalls if you like)
      
        -- Kernel runs a thread that implement this API, e.g. serves
        capability invocations
      fc2675ff
    • Anton Burtsev's avatar
      Simple, list-based capability allocator · 75340d2a
      Anton Burtsev authored
        -- I've split capability allocation and cspaces, this makes much more
           sense -- complex domains can implement custom allocation policies,
           simple domains go with a static set of caps
        -- This is a list-based (zone like) allocator
      75340d2a
    • Charles Jacobsen's avatar
      Fixed build errors, all tests passing. · 78569fe2
      Charles Jacobsen authored
      Fixed (another) nasty casting bug in the
      code that initializes the ept pointer. I
      was using the old way of casting, and overlooking
      that I was storing a host virtual pointer
      inside a host physical pointer. This caused
      invept to fail (invept checks if the eptp is
      valid).
      
      I also fixed invept and invvpid to print an
      error message (like vmload and vmclear), rather
      than generate an invalid opcode exception. It's
      easier to debug and understand the problem.
      
      In the future, we could more carefully parse the
      error returned.
      78569fe2
    • Charles Jacobsen's avatar
      Minor build bug fixes. · f9875eab
      Charles Jacobsen authored
      (Sorry for the barrage of pushes, but I want
      to make sure I push changes in case I crash
      the machine...)
      f9875eab
    • Charles Jacobsen's avatar
      Most build errors fixed. · e6442a9d
      Charles Jacobsen authored
      e6442a9d
    • Charles Jacobsen's avatar
      89d31ccd
    • Charlie Jacobsen's avatar
      364254ba
    • Charlie Jacobsen's avatar
      0b4401a9
    • Charlie Jacobsen's avatar
      Introducing types for each gpa, gva, hva, hpa. · 82aa94ed
      Charlie Jacobsen authored
      Constructors and casting inlines are in arch-dep
      code header.
      82aa94ed
    • Charles Jacobsen's avatar
      e1504369
    • Charles Jacobsen's avatar
      b9f6d8fb
    • Charlie Jacobsen's avatar
      Shifted gpa map / unmap range to arch-dep code. · f9b52a46
      Charlie Jacobsen authored
      Updated tests.
      f9b52a46
    • Charles Jacobsen's avatar
      Fixing up ept destroy to not free mapped mem. · 8a977687
      Charles Jacobsen authored
      Originally, destroying the ept structures also
      freed the mapped host physical memory. This is
      leading to bad double free errors. Instead, I
      will report a potential memory leak if an ept
      pte is present.
      
      Users of the ept should unmap any host phys
      memory before destroying the ept (will shift
      over ept unmap range from arch-indep to
      arch-dep next).
      
      Updated arch test04 to use vmx_free_ept, now
      that it doesn't try to free mapped host phys
      mem.
      8a977687
    • Charles Jacobsen's avatar
      All lcd tests through 5 are passing. · a81d9641
      Charles Jacobsen authored
      Added pgd_pfn to asm/pgtables.h.
      a81d9641
    • Charlie Jacobsen's avatar
      Small fix to arch set pc. · 32c30a68
      Charlie Jacobsen authored
      Need to load vmcs in order to modify it.
      32c30a68
    • Charles Jacobsen's avatar
      Fixed bug in lcd_arch: vmx_init_stack. · dfb4c23b
      Charles Jacobsen authored
      Can't set stack pointer until vmcs is loaded.
      dfb4c23b
    • Charles Jacobsen's avatar
      Fixed build errors for first test. · 8a1846ba
      Charles Jacobsen authored
      Pushing in case of crash ...
      8a1846ba
    • Charles Jacobsen's avatar
      4e95f355
    • Charlie Jacobsen's avatar
      Most guest virtual paging code in place (untested). · fa756550
      Charlie Jacobsen authored
      This was tricky. Unfortunately, since guest physical
      addresses are wrapped in the paging entries, we can't
      use some of the linux macros / routines (e.g.,
      pud_offset). This would allow us to benefit from pud-
      and pmd-folding, making the code more portable. Perhaps
      we'll think of something later...
      
      The code will only work on a linux with 4 paging levels
      (pgd, pud, pmd, page table). lcd_mm_gva_walk is the
      main routine that traverses the hierarchy. Each subroutine
      translates a paging structures guest physical to host
      virtual address, and gets the correct entry.
      
      A simple watermark is used (rather than a bitmap) for
      allocating guest physical memory.
      fa756550
    • Charlie Jacobsen's avatar
      Removed utcb from arch-indep lcd. · c73ae4d4
      Charlie Jacobsen authored
      Changed to use macro accessor in lcd_arch. I think
      this is less confusing and less bug prone. So,
      to access lcd's utcb, do:
      
      struct lcd_utcb *utcb;
      utcb = LCD_ARCH_GET_UTCB(vcpu);
      c73ae4d4
    • Charlie Jacobsen's avatar
      Simple explicit tss, gdt, and stack tear down. · fa05c7bf
      Charlie Jacobsen authored
      (Code before relied on free ept to free memory. But
      this could be confusing and hard to debug in the future...)
      fa05c7bf
    • Charlie Jacobsen's avatar
      Simple unmapping code for ept in arch-dep code. · a6130165
      Charlie Jacobsen authored
      Just clears the ept entry.
      a6130165
    • Charlie Jacobsen's avatar
      More work on blob initialization. · 33d999d6
      Charlie Jacobsen authored
      arch/x86/lcd-domains/...
      -- Fixed program counter and stack pointer initialization
      -- Added guest virtual paging pointer modifier routine
      
      include/lcd-domains/lcd-domains.h
      -- Added the minimum amount of data for guest virtual paging
         setup
      
      virt/lcd-domains/lcd-domains.c
      -- Added general routines for lcd create / destroy.
      -- Moved mm code to this file (to avoid future name clashes and
         be more self contained ... is this why kernel source files are
         so big?)
      -- Added general routine for initializing an lcd's gva.
      -- Re-factored blob initialization to use mm routines. Documented
         memory layout in the source code.
      
      Problem: I'm relying heavily on the ept tear down to free any
      memory mapped in there. But this is getting ugly ... Next step:
      Write quick routines to properly unmap and explicitly free memory.
      33d999d6
    • Charles Jacobsen's avatar
      7934847d