diff --git a/lisa/_assets/kmodules/lisa/Makefile b/lisa/_assets/kmodules/lisa/Makefile index 9f19f6d06cd12f8a08618d30a1261147ebace1b0..f1a1937bcfb42941a4e699f2a91bd4464455e30f 100644 --- a/lisa/_assets/kmodules/lisa/Makefile +++ b/lisa/_assets/kmodules/lisa/Makefile @@ -125,48 +125,7 @@ $(VENV): . $(VENV)/bin/activate && python3 -m pip install --upgrade pip setuptools wheel && python3 -m pip install -r $(MODULE_SRC)/requirements.txt $(INTROSPECTION_DATA_H): $(GENERATED) $(KALLSYMS) $(PRIVATE_TYPES_TXT) $(VMLINUX) $(VENV) -# Some options are not upstream (yet) but they have all be published on the -# dwarves mailing list -# -# Options: -# -F btf,dwarf: Use BTF first -# -E: Expand nested type definitions -# --suppress_force_paddings: Remove the "artificial" padding members pahole adds -# to make padding more visible. They are not always valid C syntax and can -# break build -# --skip_missing: Keep going if one of the types is not found -# --expand_types_once (non upstream): Only expand a given type once, to avoid type redefinition -# (C does not care about nesting types, there is a single namespace). -# -# We then post-process the header to add a prefix to each type expanded by -E -# that was not explicitly asked for. This avoids conflicting with type -# definitions that would come from public kernel headers, while still allowing -# easy attribute access. - pahole -F btf,dwarf -E --compile --suppress_force_paddings --show_only_data_members --skip_missing --expand_types_once -C "file://$(PRIVATE_TYPES_TXT)" "$(VMLINUX)" > $(MODULE_OBJ)/_header - -# Create a header with all the types we can for introspection purposes. This -# will not be included in any of the module sources, so all we care about is -# that pycparser can parse it. Specifically, some types may be re-defined with -# incompatible definitions. This is expected as various drivers use the same -# struct names. - pahole -F btf,dwarf -E --expand_types_once --suppress_force_paddings --suppress_aligned_attribute --suppress_packed --show_only_data_members --compile --fixup_silly_bitfields "$(VMLINUX)" > $(MODULE_OBJ)/_full_header - -# Strip comments to avoid matching them with the sed regex. - "$(CC)" -P -E - < $(MODULE_OBJ)/_header > $(MODULE_OBJ)/_header_no_comment -# Create forward declaration of every type to ensure the header can be parsed correctly. - sed -r -n 's/.*(struct|union|enum) ([0-9a-zA-Z_]*) .*/\1 \2;/p' $(MODULE_OBJ)/_header_no_comment | sort -u > $(MODULE_OBJ)/_fwd_decl - -# Rename all the kernel private types we are not directly interested in to avoid any clash - cat $(MODULE_OBJ)/_fwd_decl $(MODULE_OBJ)/_header_no_comment > $(MODULE_OBJ)/_header - . $(VENV)/bin/activate && python3 $(MODULE_SRC)/introspect_header.py --header $(MODULE_OBJ)/_header --type-prefix $(UNUSED_KERNEL_PRIVATE_TYPES_PREFIX) --non-renamed-types $(PRIVATE_TYPES_TXT) > $(MODULE_OBJ)/_renamed_header - -# Create type introspection macros - . $(VENV)/bin/activate && python3 $(MODULE_SRC)/introspect_header.py --header $(MODULE_OBJ)/_full_header --introspect --kallsyms $(KALLSYMS) --kernel-features $(MODULE_SRC)/kernel_features.json >> $(MODULE_OBJ)/_introspection_header - -# Build the final header - printf '#pragma once\n' > $@ - cat $(MODULE_OBJ)/_introspection_header $(MODULE_OBJ)/_renamed_header >> $@ -# cat $@ + sh "$(MODULE_SRC)/make_introspection_header.sh" "$@" "$(MODULE_SRC)" "$(MODULE_OBJ)" "$(VENV)" "$(CC)" "$(PRIVATE_TYPES_TXT)" "$(VMLINUX)" "$(UNUSED_KERNEL_PRIVATE_TYPES_PREFIX)" "$(KALLSYMS)" $(SYMBOLS_LDS): $(GENERATED) $(KALLSYMS) $(VENV) . $(VENV)/bin/activate && python3 $(MODULE_SRC)/introspect_header.py --kallsyms $(KALLSYMS) --symbols-lds >> $@ @@ -188,7 +147,7 @@ $(SYMBOL_NAMESPACES_H): $(GENERATED) $(MODULE_VERSION_H): $(GENERATED) printf '#pragma once\n' > $@ printf "#define LISA_MODULE_VERSION \"" >> $@ - export LC_ALL=C && (cd $(MODULE_SRC) && find -type f '(' -name '*.c' -or -name '*.h' -or -name '*.txt' -or -name '*.json' -or -name '*.py' -or -name '*.lds' -or -name 'Makefile' -or -name 'vmlinux' -or -name 'kallsyms' ')' -and -not -path './generated/*' | xargs sha1sum) | sort | sha1sum | cut -d' ' -f1 | tr -d '\n' >> $@ + export LC_ALL=C && (cd $(MODULE_SRC) && find -type f '(' -name '*.c' -or -name '*.h' -or -name '*.txt' -or -name '*.json' -or -name '*.py' -or -name '*.sh' -or -name '*.lds' -or -name 'Makefile' -or -name 'vmlinux' -or -name 'kallsyms' ')' -and -not -path './generated/*' | xargs sha1sum) | sort | sha1sum | cut -d' ' -f1 | tr -d '\n' >> $@ printf "\"\n" >> $@ diff --git a/lisa/_assets/kmodules/lisa/main.c b/lisa/_assets/kmodules/lisa/main.c index 8e556e6b2fb35c43426a7b76e8acb79f91d843d9..05ec9b2cfcb167a5af51d3aba0a428d9746caca1 100644 --- a/lisa/_assets/kmodules/lisa/main.c +++ b/lisa/_assets/kmodules/lisa/main.c @@ -40,7 +40,7 @@ static int __init modinit(void) { pr_info(" %s: %s\n", kernel_feature_names[i], kernel_feature_values[i] ? "enabled" : "disabled"); } - ret = init_features(features, features_len); + ret = init_features(features_len ? features : NULL , features_len); if (ret) { pr_err("Some errors happened while loading LISA kernel module\n"); diff --git a/lisa/_assets/kmodules/lisa/make_introspection_header.sh b/lisa/_assets/kmodules/lisa/make_introspection_header.sh new file mode 100755 index 0000000000000000000000000000000000000000..2618e6c1d9d14bf6225d1f5f915f19e036a84afb --- /dev/null +++ b/lisa/_assets/kmodules/lisa/make_introspection_header.sh @@ -0,0 +1,55 @@ +#! /bin/sh + +set -e + +OUT=$1 +MODULE_SRC=$2 +MODULE_OBJ=$3 +VENV=$4 +CC=$5 +PRIVATE_TYPES_TXT=$6 +VMLINUX=$7 +UNUSED_KERNEL_PRIVATE_TYPES_PREFIX=$8 +KALLSYMS=$9 + +# Some options are not upstream (yet) but they have all be published on the +# dwarves mailing list +# +# Options: +# -F btf,dwarf: Use BTF first +# -E: Expand nested type definitions +# --suppress_force_paddings: Remove the "artificial" padding members pahole adds +# to make padding more visible. They are not always valid C syntax and can +# break build +# --skip_missing: Keep going if one of the types is not found +# --expand_types_once (non upstream): Only expand a given type once, to avoid type redefinition +# (C does not care about nesting types, there is a single namespace). +# +# We then post-process the header to add a prefix to each type expanded by -E +# that was not explicitly asked for. This avoids conflicting with type +# definitions that would come from public kernel headers, while still allowing +# easy attribute access. +pahole -F btf,dwarf -E --compile --suppress_force_paddings --show_only_data_members --skip_missing --expand_types_once -C "file://$PRIVATE_TYPES_TXT" "$VMLINUX" > "$MODULE_OBJ/_header" + +# Create a header with all the types we can for introspection purposes. This +# will not be included in any of the module sources, so all we care about is +# that pycparser can parse it. Specifically, some types may be re-defined with +# incompatible definitions. This is expected as various drivers use the same +# struct names. +pahole -F btf,dwarf -E --expand_types_once --suppress_force_paddings --suppress_aligned_attribute --suppress_packed --show_only_data_members --compile --fixup_silly_bitfields "$VMLINUX" > "$MODULE_OBJ/_full_header" + +# Strip comments to avoid matching them with the sed regex. +"$CC" -P -E - < "$MODULE_OBJ/_header" > "$MODULE_OBJ/_header_no_comment" +# Create forward declaration of every type to ensure the header can be parsed correctly. +sed -r -n 's/.*(struct|union|enum) ([0-9a-zA-Z_]*) .*/\1 \2;/p' "$MODULE_OBJ/_header_no_comment" | sort -u > "$MODULE_OBJ/_fwd_decl" + +# Rename all the kernel private types we are not directly interested in to avoid any clash +cat "$MODULE_OBJ/_fwd_decl" "$MODULE_OBJ/_header_no_comment" > "$MODULE_OBJ/_header" +. "$VENV/bin/activate" && python3 "$MODULE_SRC/introspect_header.py" --header "$MODULE_OBJ/_header" --type-prefix "$UNUSED_KERNEL_PRIVATE_TYPES_PREFIX" --non-renamed-types "$PRIVATE_TYPES_TXT" > "$MODULE_OBJ/_renamed_header" + +# Create type introspection macros +. "$VENV/bin/activate" && python3 "$MODULE_SRC/introspect_header.py" --header "$MODULE_OBJ/_full_header" --introspect --kallsyms "$KALLSYMS" --kernel-features "$MODULE_SRC/kernel_features.json" >> "$MODULE_OBJ/_introspection_header" + +# Build the final header +printf '#pragma once\n' > "$OUT" +cat "$MODULE_OBJ/_introspection_header" "$MODULE_OBJ/_renamed_header" >> "$OUT" diff --git a/tools/kmodules/lisa/make_introspection_header.sh b/tools/kmodules/lisa/make_introspection_header.sh new file mode 120000 index 0000000000000000000000000000000000000000..f1625b4e6ebad72b5ae3a52f1895b0fa923aeb05 --- /dev/null +++ b/tools/kmodules/lisa/make_introspection_header.sh @@ -0,0 +1 @@ +../../../lisa/_assets/kmodules/lisa/make_introspection_header.sh \ No newline at end of file