Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new patcher memory hooks #1495

Merged
merged 8 commits into from
Apr 14, 2016
Merged

Add new patcher memory hooks #1495

merged 8 commits into from
Apr 14, 2016

Commits on Apr 13, 2016

  1. opal/memory: add support for patch based memory hooks

    This commit adds support for runtime binary patching. The support is
    broken down into two parts: util/opal_patcher.[ch] which contains the
    functionality for runtime patching of symbols, and mca/memory/patcher
    which patches the various symbols needed to provide support for memory
    hooks. This work is preliminary and is based off work donated by IBM.
    
    The patcher code is disabled if dlopen is disabled.
    
    Signed-off-by: Nathan Hjelm <[email protected]>
    hjelmn committed Apr 13, 2016
    Configuration menu
    Copy the full SHA
    7aa03d6 View commit details
    Browse the repository at this point in the history
  2. opal/memory: update component structure

    This commit makes it possible to set relative priorities for
    components. Before the addition of the patched component there was
    only one component that would run on any system but that is no longer
    the case. When determining which component to open each component's
    query function is called and the one that returns the highest priority
    is opened. The default priority of the patcher component is set
    slightly higher than the old ptmalloc2/ummunotify component.
    
    This commit fixes a long-standing break in the abstration of the
    memory components. ompi_mpi_init.c was referencing the linux malloc
    hook initilize function to ensure the hooks are initialized for
    libmpi.so. The abstraction break has been fixed by adding a memory
    base function that calls the open memory component's malloc hook init
    function if it has one. The code is not yet complete but is intended
    to support ptmalloc in 2.0.0. In that case the base function will
    always call the ptmalloc hook init if exists.
    
    Signed-off-by: Nathan Hjelm <[email protected]>
    hjelmn committed Apr 13, 2016
    4 Configuration menu
    Copy the full SHA
    11e2d78 View commit details
    Browse the repository at this point in the history
  3. opal/patch: add call to check if binary patching is supported

    Signed-off-by: Nathan Hjelm <[email protected]>
    hjelmn committed Apr 13, 2016
    Configuration menu
    Copy the full SHA
    4cac623 View commit details
    Browse the repository at this point in the history
  4. contrib/platform: don't disable dlopen

    The --enable-static gives us what we want: statically linked components.
    
    Signed-off-by: Nathan Hjelm <[email protected]>
    hjelmn committed Apr 13, 2016
    Configuration menu
    Copy the full SHA
    b1670f8 View commit details
    Browse the repository at this point in the history
  5. opal: add code patcher framework

    This commit adds a framework to abstract runtime code patching.
    Components in the new framework can provide functions for either
    patching a named function or a function pointer. The later
    functionality is not being used but may provide a way to allow memory
    hooks when dlopen functionality is disabled.
    
    This commit adds two different flavors of code patching. The first is
    provided by the overwrite component. This component overwrites the
    first several instructions of the target function with code to jump to
    the provided hook function. The hook is expected to provide the full
    functionality of the hooked function.
    
    The linux patcher component is based on the memory hooks in ucx. It
    only works on linux and operates by overwriting function pointers in
    the symbol table. In this case the hook is free to call the original
    function using the function pointer returned by dlsym.
    
    Both components restore the original functions when the patcher
    framework closes.
    
    Changes had to be made to support Power/PowerPC with the Linux
    dynamic loader patcher. Some of the changes:
    
     - Move code necessary for powerpc/power support to the patcher
       base. The code is needed by both the overwrite and linux
       components.
    
     - Move patch structure down to base and move the patch list to
       mca_patcher_base_module_t. The structure has been modified to
       include a function pointer to the function that will unapply the
       patch. This allows the mixing of multiple different types of
       patches in the patch_list.
    
     - Update linux patching code to keep track of the matching between
       got entry and original (unpatched) address. This allows us to
       completely clean up the patch on finalize.
    
    All patchers keep track of the changes they made so that they can be
    reversed when the patcher framework is closed.
    
    At this time there are bugs in the Linux dynamic loader patcher so
    its priority is lower than the overwrite patcher.
    
    Signed-off-by: Nathan Hjelm <[email protected]>
    hjelmn committed Apr 13, 2016
    Configuration menu
    Copy the full SHA
    27f8a4e View commit details
    Browse the repository at this point in the history
  6. opal/memory: remove ptmalloc2

    This commit removes the ptmalloc2 memory hooks. This is necessary in
    order to support lazy registration of memory hooks. A feature that is
    not supported by the ptmalloc hooks but is supported by the new
    patcher hooks.
    
    Signed-off-by: Nathan Hjelm <[email protected]>
    hjelmn committed Apr 13, 2016
    Configuration menu
    Copy the full SHA
    91bcab9 View commit details
    Browse the repository at this point in the history
  7. memory/patcher: updates to memory hooks

    This commit fixes bugs that can cause crashes and memory corruption
    when the mremap hook is called. The problem occurs because of the
    ellipses (...) in the mremap intercept function. The ellipses cover
    the optional new_addr argument on Linux. This commit removes the
    ellipses and adds an explicit 5th argument.
    
    This commit also adds a hook for shmdt. The code only works on Linux
    at the moment as it needs to read /proc/self/maps to determine the
    size of the shared memory segment.
    
    Additionally, this commit removes the mmap hook. There is no
    apparent benefit for detecting mmap(..., PROT_NONE, ...) and it
    seems to cause problems when threads are in use.
    
    Signed-off-by: Nathan Hjelm <[email protected]>
    hjelmn committed Apr 13, 2016
    Configuration menu
    Copy the full SHA
    80ec79c View commit details
    Browse the repository at this point in the history
  8. opal/memory: move initialization to first rcache creation

    Because of the removal of the linux memory component it is no longer
    necessary to initialize the memory component in opal_init(). This
    commit moves the initialization to the creation of the first rcache
    component.
    
    Signed-off-by: Nathan Hjelm <[email protected]>
    hjelmn committed Apr 13, 2016
    Configuration menu
    Copy the full SHA
    c2b6fbb View commit details
    Browse the repository at this point in the history