From 851b820dc5fa97d0e539f979a46de69e97def04a Mon Sep 17 00:00:00 2001 From: Yan Yue <1131531947@qq.com> Date: Tue, 7 Jan 2025 14:29:49 +0800 Subject: [PATCH 1/2] cpu-o3: fetch: fix memory invalid read if numBr equals 6, getShuffleBrIndex may return 7, cause invalid read in tage entry: tageTable[i][tmp_index][phyBrIdx] find it using valgrind. Change-Id: I129c3be8e08959e051408486b0598db39f140cd4 --- src/cpu/pred/ftb/ftb_tage.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cpu/pred/ftb/ftb_tage.cc b/src/cpu/pred/ftb/ftb_tage.cc index 56fd4385b6..9211476698 100644 --- a/src/cpu/pred/ftb/ftb_tage.cc +++ b/src/cpu/pred/ftb/ftb_tage.cc @@ -150,6 +150,7 @@ FTBTAGE::lookupHelper(Addr startAddr, for (int b = 0; b < numBr; b++) { // make main prediction int phyBrIdx = getShuffledBrIndex(startAddr, b); + assert(phyBrIdx >= 0 && phyBrIdx < numBr); int provider_counts = 0; for (int i = numPredictors - 1; i >= 0; --i) { Addr tmp_index = getTageIndex(startAddr, i); @@ -575,7 +576,8 @@ FTBTAGE::getBrIndexUnshuffleBits(Addr pc) Addr FTBTAGE::getShuffledBrIndex(Addr pc, int brIdxToShuffle) { - return getBrIndexUnshuffleBits(pc) ^ brIdxToShuffle; + // make sure the result is in the range of [0, numBr-1] + return (getBrIndexUnshuffleBits(pc) ^ brIdxToShuffle) & (numBr - 1); } From 49504c2b4b6e021db12d8fb804859119c6226c4c Mon Sep 17 00:00:00 2001 From: Yan Yue <1131531947@qq.com> Date: Tue, 7 Jan 2025 15:36:06 +0800 Subject: [PATCH 2/2] util: CI: add valgrind check for ideal config use coremark to run valgrind Change-Id: I42770e1121f0149ac57d397600b9de56fc48608d --- .github/workflows/gem5.yml | 24 ++++++++++++++ util/memory_check/run-xs-with-valgrind.sh | 39 ++++++++++++----------- 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/.github/workflows/gem5.yml b/.github/workflows/gem5.yml index c536c34ba7..da764c935b 100644 --- a/.github/workflows/gem5.yml +++ b/.github/workflows/gem5.yml @@ -31,6 +31,30 @@ jobs: bash util/memory_check/run-xs-with-valgrind.sh cd $GEM5_HOME + valgrind_memory_check_ideal: + runs-on: self-hosted + continue-on-error: false + name: XS-GEM5 - Check memory corruption with ideal-kmhv3 + steps: + - uses: actions/checkout@v2 + - name: Build DRAMSim + run: | + export GEM5_HOME=$(pwd) + cd ext/dramsim3 + git clone https://github.com/umd-memsys/DRAMsim3.git DRAMsim3 + cd DRAMsim3 && mkdir -p build + cd build + cmake .. + make -j 48 + cd $GEM5_HOME + - name: Build GEM5 debug + run: CC=gcc CXX=g++ scons build/RISCV/gem5.debug --linker=gold -j64 + - name: Memory check + run: | + export GEM5_HOME=$(pwd) + bash util/memory_check/run-xs-with-valgrind.sh ideal + cd $GEM5_HOME + new_sim_script_test_gcb: runs-on: self-hosted continue-on-error: false diff --git a/util/memory_check/run-xs-with-valgrind.sh b/util/memory_check/run-xs-with-valgrind.sh index 798b4b8cd4..a00c89f053 100644 --- a/util/memory_check/run-xs-with-valgrind.sh +++ b/util/memory_check/run-xs-with-valgrind.sh @@ -1,32 +1,33 @@ set -x gem5_home=$(pwd) -gcpt_restore_path=/nfs/home/share/gem5_shared_tools/normal-gcb-restorer.bin -ref_so_path=/nfs-nvme/home/share/zhenhao/ref-h/build/riscv64-nemu-interpreter-so -test_cpt=/nfs/home/share/jiaxiaoyu/simpoint_checkpoint_archive/spec06_rv64gcb_O3_20m_gcc12.2.0-intFpcOff-jeMalloc/checkpoint-0-0-0/GemsFDTD/30385/_30385_0.268180_.gz +ref_so_path=/nfs/home/share/gem5_ci/ref/normal/riscv64-nemu-interpreter-so +export GCBV_REF_SO=$ref_so_path -export NEMU_HOME=$ref_so_path # dummy +raw_cpt=/nfs/home/share/gem5_ci/checkpoints/coremark-riscv64-xs.bin +# ideal config, $1 means ideal-kmhv3 +IDEAL_CONFIG="" +if [ "$1" ]; then + IDEAL_CONFIG="--ideal-kmhv3" +fi +echo "IDEAL_CONFIG: $IDEAL_CONFIG" mkdir -p $gem5_home/valgrind-test cd $gem5_home/valgrind-test valgrind -s --track-origins=yes --log-file=valgrind-out.txt --error-limit=no \ --suppressions=$gem5_home/util/valgrind-suppressions \ - $gem5_home/build/RISCV/gem5.debug $gem5_home/configs/example/fs.py \ - --xiangshan-system --cpu-type=DerivO3CPU --mem-size=8GB --caches --cacheline_size=64 \ - --l1i_size=64kB --l1i_assoc=8 --l1d_size=64kB --l1d_assoc=8 \ - --l1d-hwp-type=XSCompositePrefetcher --short-stride-thres=0 \ - --l2cache --l2_size=1MB --l2_assoc=8 \ - --l3cache --l3_size=16MB --l3_assoc=16 \ - --l1-to-l2-pf-hint --l2-hwp-type=CompositeWithWorkerPrefetcher \ - --l2-to-l3-pf-hint --l3-hwp-type=WorkerPrefetcher \ - --mem-type=DRAMsim3 \ - --dramsim3-ini=$gem5_home/ext/dramsim3/xiangshan_configs/xiangshan_DDR4_8Gb_x8_3200_2ch.ini \ - --bp-type=DecoupledBPUWithFTB --enable-loop-predictor \ - --enable-difftest --difftest-ref-so=$ref_so_path \ - --generic-rv-cpt=$test_cpt \ - --gcpt-restorer=$gcpt_restore_path \ - --warmup-insts-no-switch=40000 --maxinsts=80000 + $gem5_home/build/RISCV/gem5.debug \ + $gem5_home/configs/example/xiangshan.py \ + $IDEAL_CONFIG \ + --raw-cpt \ + --generic-rv-cpt=$raw_cpt + +# if $? != 0, exit +if [ $? -ne 0 ]; then + echo "Valgrind test failed" + exit 1 +fi python3 $gem5_home/util/memory_check/check-memory-error.py $gem5_home/valgrind-test/valgrind-out.txt