From 174946c21ba79b8514a679333321ae5616a20413 Mon Sep 17 00:00:00 2001 From: yinyongchen Date: Wed, 6 Mar 2024 17:50:07 +0800 Subject: [PATCH] fix intel-lkvs --- tests/intel-lkvs/install.sh | 101 +++++++++++++++--- tests/intel-lkvs/parse.awk | 34 ++++++ .../patches/add_ASM_EXTABLE_TYPE_REG.patch | 54 ++++++++++ .../intel-lkvs/patches/add__no_profile.patch | 22 ++++ tests/intel-lkvs/run.sh | 67 +++--------- 5 files changed, 209 insertions(+), 69 deletions(-) create mode 100644 tests/intel-lkvs/parse.awk create mode 100644 tests/intel-lkvs/patches/add_ASM_EXTABLE_TYPE_REG.patch create mode 100644 tests/intel-lkvs/patches/add__no_profile.patch diff --git a/tests/intel-lkvs/install.sh b/tests/intel-lkvs/install.sh index 3c4ba5f..a19754f 100644 --- a/tests/intel-lkvs/install.sh +++ b/tests/intel-lkvs/install.sh @@ -1,35 +1,104 @@ GIT_URL="https://github.com/intel/lkvs.git" BRANCH="main" +LIBIPT_URL="http://github.com/intel/libipt.git" +DEP_PKG_LIST="cmake kernel-tools cpuid msr-tools" + +lkvs_dir="lkvs" +libipt_dir="libipt" + +get_kernel_version() +{ + version=$(uname -r |awk -F "-" '{print $1}') + echo ${version%.*} +} + +kernver=$(get_kernel_version) + fetch() { - git_clone $GIT_URL $TONE_BM_CACHE_DIR + git_clone_mirror $GIT_URL $TONE_BM_CACHE_DIR/$lkvs_dir + git_clone_mirror $LIBIPT_URL $TONE_BM_CACHE_DIR/$libipt_dir } -build_component() { - local component=$1 - if [ ! -d "${TONE_BM_CACHE_DIR}/${component}" ]; then - fetch - fi - cd "${TONE_BM_CACHE_DIR}/${component}" || exit 1 +extract_src() +{ + set_git_clone + + git_clone_exec --branch "$BRANCH" "$TONE_BM_CACHE_DIR/$lkvs_dir" "$TONE_BM_BUILD_DIR/$lkvs_dir" + git_clone_exec "$TONE_BM_CACHE_DIR/$libipt_dir" "$TONE_BM_BUILD_DIR/$libipt_dir" +} + +build_libipt() { + [ -d $TONE_BM_BUILD_DIR/$libipt_dir ] || return + cd $TONE_BM_BUILD_DIR/$libipt_dir + cmake . + make install +} + +build_lkvs() { + [ -d $TONE_BM_BUILD_DIR/$lkvs_dir ] || return + + #add_patch + + cd $TONE_BM_BUILD_DIR/$lkvs_dir + + # need change cet_ioctl.c when kernel verison less than 6.3 + echo -e "${kernver}\n6.3" | sort -V | head -1 | grep 6.3 || \ + sed -i "s|cl = class_create(mod_name);|cl = class_create(THIS_MODULE, \"char\");|g" cet/cet_driver/cet_ioctl.c + + # delete 32bit test when os not support + [ -f /usr/include/gnu/stubs-32.h ] || { + sed -i '/gcc telemetry_tests.c -m32 -o telemetry_tests_32/d' telemetry/Makefile + sed -i '/rm -rf telemetry_tests_32/d' telemetry/Makefile + } make + + #restore_patch +} + +add_patch() { + patchdir="$TONE_BM_SUITE_DIR/patches" + ca_h_patch="" + asm_h_patch="" + + # fix compilation error: implicit declaration of function ‘_native_write_cr0’ + ca_h_file="/usr/src/kernels/$(uname -r)/include/linux/compiler_attributes.h" + [ -f "$ca_h_file" ] && { + grep -r "__no_profile" $ca_h_file || { + ca_h_patch="$patchdir/add__no_profile.patch" + [ -f $ca_h_patch ] && patch < $ca_h_patch $ca_h_file + } + } + + # fix compilation error: expected ‘:’ or ‘)’ before ‘_ASM_EXTABLE_TYPE_REG’ + asm_h_file="/usr/src/kernels/$(uname -r)/arch/x86/include/asm/asm.h" + [ $(arch) == "x86_64" ] && [ -f "$asm_h_file" ] && { + grep -r "_ASM_EXTABLE_TYPE_REG" $asm_h_file || { + asm_h_patch="$patchdir/add_ASM_EXTABLE_TYPE_REG.patch" + [ -f $patchpath ] && patch < $asm_h_patch $asm_h_file + } + } +} + +restore_patch() { + [ -n "$ca_h_patch" ] && patch -R < $ca_h_patch $ca_h_file + [ -n "$asm_h_patch" ] && patch -R < $asm_h_patch $asm_h_file } build() { - build_component "xsave" - build_component "pt" - build_component "splitlock" - build_component "umip" - build_component "tdx-compliance" + build_libipt + build_lkvs } install() { + cp -raf $TONE_BM_BUILD_DIR/$lkvs_dir/* $TONE_BM_RUN_DIR + cp -raf $TONE_BM_BUILD_DIR/$lkvs_dir/.env $TONE_BM_RUN_DIR + if lsmod | grep -q "tdx_compliance"; then - $(rmmod tdx_compliance) + $(rmmod tdx_compliance) fi - insmod tdx-compliance.ko - - echo "success in insmod tdx-compliance.ko" + insmod $TONE_BM_RUN_DIR/tdx-compliance/tdx-compliance.ko && echo "success in insmod tdx-compliance.ko" } diff --git a/tests/intel-lkvs/parse.awk b/tests/intel-lkvs/parse.awk new file mode 100644 index 0000000..5d218b1 --- /dev/null +++ b/tests/intel-lkvs/parse.awk @@ -0,0 +1,34 @@ +#!/usr/bin/awk -f + + +/^.+: (PASS|FAIL|SKIP)$/ { + match($0, /^(.+): (PASS|FAIL|SKIP)/, arr) + printf("%s: %s\n", arr[1], arr[2]) +} + +/^[0-9]+:\s*([^:]+):\s*\[(PASS|FAIL)/ { + match($0, /^[0-9]+: ([^[]+): \[(PASS|FAIL)\]/, arr) + printf("%s: %s\n", arr[1], arr[2]) +} + +/\[info\].*\s*Test .*[A-Za-z0-9]$/ { + match($0, /\[info\].*\s*Test ([^[]+)/, arr) + tc_name = arr[1] +} + +/\[(pass|fail)\].*\s*Received expected signal/ { + match($0, /\[(pass|fail)\]/, arr) + tc_ret = arr[1] + printf("%s: %s\n", tc_name, tc_ret) +} + +/^\[RESULT\]\[/ { + if(feature == "xsave" || feature == "umip")exit + match($0, /^\[RESULT\]\[(.+)\]\s+\[(FAIL|NA|BLOCK|PASS)\]/, arr) + tc_name = arr[1] + if(arr[2] == "PASS") + tc_ret="pass" + else + tc_ret="fail" + printf("%s: %s\n", tc_name, tc_ret) +} diff --git a/tests/intel-lkvs/patches/add_ASM_EXTABLE_TYPE_REG.patch b/tests/intel-lkvs/patches/add_ASM_EXTABLE_TYPE_REG.patch new file mode 100644 index 0000000..695fef2 --- /dev/null +++ b/tests/intel-lkvs/patches/add_ASM_EXTABLE_TYPE_REG.patch @@ -0,0 +1,54 @@ +diff -uprN a/../../../../../usr/src/kernels/5.10.134-93.git.b57d10013203.an8.x86_64/arch/x86/include/asm/asm.h b/../../../../../usr/src/kernels/5.10.134-93.git.b57d10013203.an8.x86_64/arch/x86/include/asm/asm.h +--- a/../../../../../usr/src/kernels/5.10.134-93.git.b57d10013203.an8.x86_64/arch/x86/include/asm/asm.h 2024-03-08 11:26:52.984795174 +0800 ++++ b/../../../../../usr/src/kernels/5.10.134-93.git.b57d10013203.an8.x86_64/arch/x86/include/asm/asm.h 2024-03-08 10:45:23.253315940 +0800 +@@ -145,6 +145,33 @@ + + #else /* ! __ASSEMBLY__ */ + ++# define DEFINE_EXTABLE_TYPE_REG \ ++ ".macro extable_type_reg type:req reg:req\n" \ ++ ".set .Lfound, 0\n" \ ++ ".set .Lregnr, 0\n" \ ++ ".irp rs,rax,rcx,rdx,rbx,rsp,rbp,rsi,rdi,r8,r9,r10,r11,r12,r13,r14,r15\n" \ ++ ".ifc \\reg, %%\\rs\n" \ ++ ".set .Lfound, .Lfound+1\n" \ ++ ".long \\type + (.Lregnr << 8)\n" \ ++ ".endif\n" \ ++ ".set .Lregnr, .Lregnr+1\n" \ ++ ".endr\n" \ ++ ".set .Lregnr, 0\n" \ ++ ".irp rs,eax,ecx,edx,ebx,esp,ebp,esi,edi,r8d,r9d,r10d,r11d,r12d,r13d,r14d,r15d\n" \ ++ ".ifc \\reg, %%\\rs\n" \ ++ ".set .Lfound, .Lfound+1\n" \ ++ ".long \\type + (.Lregnr << 8)\n" \ ++ ".endif\n" \ ++ ".set .Lregnr, .Lregnr+1\n" \ ++ ".endr\n" \ ++ ".if (.Lfound != 1)\n" \ ++ ".error \"extable_type_reg: bad register argument\"\n" \ ++ ".endif\n" \ ++ ".endm\n" ++ ++# define UNDEFINE_EXTABLE_TYPE_REG \ ++ ".purgem extable_type_reg\n" ++ + # define _ASM_EXTABLE_TYPE(from, to, type) \ + " .pushsection \"__ex_table\",\"a\"\n" \ + " .balign 4\n" \ +@@ -153,6 +180,16 @@ + " .long " __stringify(type) " \n" \ + " .popsection\n" + ++# define _ASM_EXTABLE_TYPE_REG(from, to, type, reg) \ ++ " .pushsection \"__ex_table\",\"a\"\n" \ ++ " .balign 4\n" \ ++ " .long (" #from ") - .\n" \ ++ " .long (" #to ") - .\n" \ ++ DEFINE_EXTABLE_TYPE_REG \ ++ "extable_type_reg reg=" __stringify(reg) ", type=" __stringify(type) " \n"\ ++ UNDEFINE_EXTABLE_TYPE_REG \ ++ " .popsection\n" ++ + /* For C file, we already have NOKPROBE_SYMBOL macro */ + + /* diff --git a/tests/intel-lkvs/patches/add__no_profile.patch b/tests/intel-lkvs/patches/add__no_profile.patch new file mode 100644 index 0000000..ae2e6fa --- /dev/null +++ b/tests/intel-lkvs/patches/add__no_profile.patch @@ -0,0 +1,22 @@ +diff -uprN a/../../../../../usr/src/kernels/5.10.134-93.git.b57d10013203.an8.x86_64/include/linux/compiler_attributes.h b/../../../../usr/src/kernels/5.10.134-93.git.b57d10013203.an8.x86_64/include/linux/compiler_attributes.h +--- a/../../../../../usr/src/kernels/5.10.134-93.git.b57d10013203.an8.x86_64/include/linux/compiler_attributes.h 2024-03-08 10:59:37.833259443 +0800 ++++ b/../../../../usr/src/kernels/5.10.134-93.git.b57d10013203.an8.x86_64/include/linux/compiler_attributes.h 2024-03-08 10:59:37.833259443 +0800 +@@ -232,6 +232,18 @@ + #endif + + /* ++ * Optional: only supported since GCC >= 7.1, clang >= 13.0. ++ * ++ * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fprofile_005finstrument_005ffunction-function-attribute ++ * clang: https://clang.llvm.org/docs/AttributeReference.html#no-profile-instrument-function ++ */ ++#if __has_attribute(__no_profile_instrument_function__) ++# define __no_profile __attribute__((__no_profile_instrument_function__)) ++#else ++# define __no_profile ++#endif ++ ++/* + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noreturn-function-attribute + * clang: https://clang.llvm.org/docs/AttributeReference.html#noreturn + * clang: https://clang.llvm.org/docs/AttributeReference.html#id1 diff --git a/tests/intel-lkvs/run.sh b/tests/intel-lkvs/run.sh index 65d4bf2..4f1f98a 100644 --- a/tests/intel-lkvs/run.sh +++ b/tests/intel-lkvs/run.sh @@ -6,7 +6,7 @@ setup() if [[ "$feature" == "tdx-compliance" ]]; then if ! lsmod | grep -q "tdx_compliance"; then modprobe $MODULE_NAME || - insmod $TONE_BM_CACHE_DIR/tdx-compliance/tdx-compliance.ko + insmod tdx-compliance/tdx-compliance.ko fi fi } @@ -29,8 +29,8 @@ check_tdvm_version() run() { - if [ ! -d "$TONE_BM_CACHE_DIR" ]; then - echo "Error: Please run the command tone install intel-lkvs first." + if [ ! -f "./runtests" ]; then + echo "Error: runtests not exist, may compile failed, please run the command tone install intel-lkvs and check." exit 1 fi @@ -38,50 +38,18 @@ run() if [[ "$feature" == "tdx-compliance" ]]; then if [[ `check_vm` == "yes" ]]; then echo all 1.0 > /sys/kernel/debug/tdx/tdx-tests - cat /sys/kernel/debug/tdx/tdx-tests + cat /sys/kernel/debug/tdx/tdx-tests && echo "tdx-compliance: PASS" || echo "tdx-compliance: FAIL" else - echo "tdx-compliance SKIP" + echo "tdx-compliance: SKIP" fi - elif [[ "$feature" == "xsave" ]]; then - cd $TONE_BM_CACHE_DIR - ./runtests -f xsave/tests -o ./results_xsave.log -# $TONE_BM_CACHE_DIR/xsave/xstate_64 - elif [[ "$feature" == "pt" ]]; then - cd $TONE_BM_CACHE_DIR - ./runtests -f pt/tests -o ./results_pt.log - elif [[ "$feature" == "splitlock" ]]; then - cd $TONE_BM_CACHE_DIR - ./runtests -f splitlock/tests -o ./results_splitlock.log - elif [[ "$feature" == "umip" ]]; then - cd $TONE_BM_CACHE_DIR - ./runtests -f umip/tests -o ./results_umip.log - elif [[ "$feature" == "ifs" ]]; then - cd $TONE_BM_CACHE_DIR - ./runtests -f ifs/tests -o ./results_ifs.log - elif [[ "$feature" == "isst" ]]; then - cd $TONE_BM_CACHE_DIR - ./runtests -f isst/tests -o ./results_isst.log - elif [[ "$feature" == "pmu" ]]; then - cd $TONE_BM_CACHE_DIR - ./runtests -f pmu/tests -o ./results_pmu.log - elif [[ "$feature" == "sdsi" ]]; then - cd $TONE_BM_CACHE_DIR - ./runtests -f sdsi/tests -o ./results_sdsi.log - elif [[ "$feature" == "ufs" ]]; then - cd $TONE_BM_CACHE_DIR - ./runtests -f ufs/tests -o ./results_ufs.log - elif [[ "$feature" == "cstate" ]]; then - cd $TONE_BM_CACHE_DIR - ./runtests -f cstate/tests-server -o ./results_cstate.log - elif [[ "$feature" == "rapl" ]]; then - cd $TONE_BM_CACHE_DIR - ./runtests -f rapl/tests-server -o ./results_rapl.log - elif [[ "$feature" == "topology" ]]; then - cd $TONE_BM_CACHE_DIR - ./runtests -f topology/tests-server -o ./results_topology.log - elif [[ "$feature" == "thermal" ]]; then - cd $TONE_BM_CACHE_DIR - ./runtests -f thermal/thermal-tests -o ./results_thermal.log + else + testname="tests" + if echo "$feature" | grep -qE "cstate|rapl|topology"; then + testname="tests-server" + elif echo "$feature" | grep -q "thermal"; then + testname="thermal-tests" + fi + ./runtests -f ${feature}/${testname} -o ./results_${feature}.log fi } @@ -98,12 +66,5 @@ teardown() parse() { - awk ' - match($0, /^[0-9]+:\s*([^:]+):\s*(PASS|FAIL)/, arr) { - print arr[1] ":" arr[2] - } - match($0, /^[0-9]+: ([^[]+): \[(PASS|FAIL)\]/, arr) { - print arr[1] ":" arr[2] - } - ' + awk -v feature="$feature" -f $TONE_BM_SUITE_DIR/parse.awk } -- Gitee