libipt, block: bound block cache filling recursion

We fill the block cache by proceeding one instruction and recursively calling
pt_blk_proceed_no_event_fill_cache() until we find a block cache entry or the
block fills up.  On the way back from the recursion, we fill in entries for the
instructions we skipped that didn't have a block cache entry, yet.

This recursion is bounded by the maximum allowed number of instructions in a
block.  This bound is too high and may lead to stack overflows for large
sequences of instructions.  Add an artificial lower bound to prevent the latter.

When we reach that bound, we insert a trampoline block cache entry to the next
instruction.  This may cause unnecessary extra block cache jumps, especially if
we stop close to a decision point.

We could try to replace those artificial trampoline entries with entries for the
real decision point once we reach it.  Given that we inserted the trampoline
after a long sequence of linear code, we will further insert a fair amount of
further trampolines on our way back due to block cache entry overflows (the
ninsn field).  Such a fixup would remove at most one hop for the long code
sequence.  It really only makes sense if we have other entry points much closer
to the decision point.  A quick hack didn't show any improvement so I'm not
doing it.  It remains an option should we find such cases in the future.

Change-Id: I04b81ba36500cebb7f5346daab899ead1826c5cd
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
3 files changed