This document describes how Xkernel obtains Safe Span ranges for each
tunable, and the optional integration with the LLVM-based taint analysis
in the linux-analysis
repository.
A Safe Span (SS) is the forward data-dependency slice rooted at a Critical Span (CS). It covers every instruction window in which a value derived from the perf-const is still live in architectural state. The consistency model uses SS ranges to decide whether a thread is currently inside a region that observes the old constant: a transition is safe only when execution is outside all SSes.
For background, see Sections 4–5 of the paper.
For every tunable, Xkernel resolves its SS using the first source that matches:
-
Inline
[[safe_spans]]in the TOML. The author has already computed the spans (manually or via a prior analysis run) and pasted them into the config. See adding-a-tunable.md. -
Fresh LLVM analysis (only when invoked with
--run-analysis). Xkernel calls into a siblinglinux-analysischeckout and reads the generated*.func_offset.json. See below. -
Auto-SS (fallback). When neither of the above produces a span,
codegen.py:_populate_ss_raw()synthesises a single SS that covers the entire CS function (extents derived from/proc/kcore). This is a conservative over-approximation: every instruction in the function is treated as observing the constant.
If --run-analysis is not passed, step 2 is skipped entirely and the
pipeline goes straight from step 1 to step 3. This is the path taken by
the 30-Second Demo in the top-level README.md.
When you pass --run-analysis to xkernel-tool build:
./xkernel-tool build tunables/my_const.toml --run-analysissrc/config.py:_backfill_safe_spans_from_analysis runs for every
tunable that lacks inline safe_spans:
- Locate the
linux-analysischeckout. - For each such tunable, invoke
bash <linux-analysis>/scripts/ss-gen.sh --tunable <NAME>.ss-gen.shruns the LLVM taint pass on the wllvm-built kernel bitcode, then translates the resulting IR locations into assembly offsets viaobjdump. - Read every
dataset/<NAME>/*.func_offset.jsonfile and convert each entry into a(function, start_offset, end_offset)tuple. Theoffsetfield has the form"0xNN - 0xMM"and is split on" - ". - Deduplicate and splice the result into the
TunableConfigassafe_spans.
If anything in this stage fails (missing checkout, ss-gen.sh non-zero
exit, no JSON produced) Xkernel prints a diagnostic and falls through to
auto-SS. --run-analysis is therefore best-effort: it is never a hard
build dependency.
_linux_analysis_root() returns
<xkernel_parent>/linux-analysis if it contains scripts/ss-gen.sh,
otherwise None. If the checkout is missing, --run-analysis prints
a diagnostic and the pipeline falls back to auto-SS.
Xkernel forwards the following environment variables to ss-gen.sh as
flags when set; otherwise ss-gen.sh's self-relative defaults apply.
None are required for normal use.
| Env var | ss-gen.sh flag |
Default |
|---|---|---|
LINUX_WLLVM |
--linux-wllvm DIR |
$LINUX_WLLVM |
VMLINUX_BC |
--vmlinux-bc PATH |
<linux-wllvm>/vmlinux-xk-dataset.bc |
TAINT_TRACKER_PLUGIN |
--plugin PATH |
<linux-analysis>/passes/build/libTaintTrackerPass.so |
VMLINUX |
--vmlinux PATH |
$VMLINUX, $LINUX_GCC/vmlinux, ~/linux-6.8.0/vmlinux |
MODULES_DIR |
--modules-dir PATH |
/lib/modules/$(uname -r) |
A typical invocation in a freshly-set-up environment looks like:
export LINUX_WLLVM=~/linux-6.8.0-wllvm
./xkernel-tool build tunables/my_const.toml --run-analysisss-gen.sh writes (and reuses) two files per input:
dataset/<NAME>/<N>.output.txt— raw IR-level taint output (stage 1).dataset/<NAME>/<N>.func_offset.json— assembly-offset-translated result (stage 2). This is the file Xkernel actually consumes.
Re-running --run-analysis on a tunable whose dataset is already
populated is therefore cheap: ss-gen.sh re-emits the same JSON
deterministically and Xkernel simply re-parses it.
To force a re-analysis, delete the relevant *.output.txt and
*.func_offset.json files in the dataset.
Each dataset/<NAME>/<N>.input.txt is a small shell-style file pinning
one occurrence of the constant for the taint pass:
SOURCE_FILE=block/blk-core.c
FUNCTION_NAME=blk_start_plug_nr_ios
SOURCE_OP="call"
CONSTANT_VALUE=32
OCCURENCE=1
linux-analysis/dataset/source-occurrence-and-mutation.sh is the
canonical generator that derives these from a TOML mutation list. See
the linux-analysis README for the
full workflow.
A small number of tunables currently time out the LLVM pass on 6.8 IR
(>55 minutes). These are documented in
linux-analysis/dataset/UNSUCCESSFUL.md
and gracefully fall back to auto-SS when --run-analysis is requested.