Skip to content
  • Heiko Carstens's avatar
    kprobes: unify insn caches · c802d64a
    Heiko Carstens authored
    
    
    The current kpropes insn caches allocate memory areas for insn slots
    with module_alloc().  The assumption is that the kernel image and module
    area are both within the same +/- 2GB memory area.
    
    This however is not true for s390 where the kernel image resides within
    the first 2GB (DMA memory area), but the module area is far away in the
    vmalloc area, usually somewhere close below the 4TB area.
    
    For new pc relative instructions s390 needs insn slots that are within
    +/- 2GB of each area.  That way we can patch displacements of
    pc-relative instructions within the insn slots just like x86 and
    powerpc.
    
    The module area works already with the normal insn slot allocator,
    however there is currently no way to get insn slots that are within the
    first 2GB on s390 (aka DMA area).
    
    Therefore this patch set modifies the kprobes insn slot cache code in
    order to allow to specify a custom allocator for the insn slot cache
    pages.  In addition architecure can now have private insn slot caches
    withhout the need to modify common code.
    
    Patch 1 unifies and simplifies the current insn and optinsn caches
            implementation. This is a preparation which allows to add more
            insn caches in a simple way.
    
    Patch 2 adds the possibility to specify a custom allocator.
    
    Patch 3 makes s390 use the new insn slot mechanisms and adds support for
            pc-relative instructions with long displacements.
    
    This patch (of 3):
    
    The two insn caches (insn, and optinsn) each have an own mutex and
    alloc/free functions (get_[opt]insn_slot() / free_[opt]insn_slot()).
    
    Since there is the need for yet another insn cache which satifies dma
    allocations on s390, unify and simplify the current implementation:
    
    - Move the per insn cache mutex into struct kprobe_insn_cache.
    - Move the alloc/free functions to kprobe.h so they are simply
      wrappers for the generic __get_insn_slot/__free_insn_slot functions.
      The implementation is done with a DEFINE_INSN_CACHE_OPS() macro
      which provides the alloc/free functions for each cache if needed.
    - move the struct kprobe_insn_cache to kprobe.h which allows to generate
      architecture specific insn slot caches outside of the core kprobes
      code.
    
    Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
    Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
    Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    c802d64a