Browse Source

fix: log store only if it actually happened

Since 92e4f02 moved logging logic into store_slow_path function it has
been logging stores even if actually_store parameter is false. Because
of that logging is broken for all atomic instructions. Function "amo" calls
store_slow_path with nullptr argument and actually_store equal to false
while callee uses reg_from_bytes independently from actually_store value
All of that causes dereferencing of nullptr. This commit logs memory
access only if it actually happened
pull/1995/head
Alexander Romanov 10 months ago
parent
commit
7d43d38e4a
  1. 20
      ci-tests/atomics.c
  2. 10
      ci-tests/create-ci-binary-tarball
  3. 1
      ci-tests/test-spike
  4. 2
      riscv/mmu.cc

20
ci-tests/atomics.c

@ -0,0 +1,20 @@
#include <stdio.h>
#include <stdatomic.h>
atomic_int acnt = 0;
atomic_int bcnt = 0;
int foo() {
for(int n = 0; n < 1000; ++n) {
++acnt;
if(acnt % 10 == 0)
++bcnt;
}
return acnt;
}
int main(void) {
int acnt = foo();
printf("First atomic counter is %u, second is %u\n", acnt, bcnt);
return 0;
}

10
ci-tests/create-ci-binary-tarball

@ -20,10 +20,16 @@ mkdir -p build/dummycsr && cd "$_"
riscv64-unknown-elf-gcc -O2 -o customcsr `git rev-parse --show-toplevel`/ci-tests/customcsr.c
cd -
mkdir -p build/atomics && cd "$_"
riscv64-unknown-elf-gcc -O2 -o atomics `git rev-parse --show-toplevel`/ci-tests/atomics.c
cd -
mv build/pk/pk .
mv build/hello/hello .
mv build/dummy-slliuw/dummy-slliuw .
mv build/dummycsr/customcsr .
tar -cf spike-ci.tar pk hello dummy-slliuw customcsr
mv build/atomics/atomics .
tar -cf spike-ci.tar pk hello dummy-slliuw customcsr atomics
rm pk hello dummy-slliuw customcsr
rm pk hello dummy-slliuw customcsr atomics

1
ci-tests/test-spike

@ -11,6 +11,7 @@ cd run
wget https://github.com/riscv-software-src/riscv-isa-sim/releases/download/dummy-tag-for-ci-storage/spike-ci.tar
tar xf spike-ci.tar
time ../install/bin/spike --isa=rv64gc pk hello | grep "Hello, world! Pi is approximately 3.141588."
../install/bin/spike --log-commits --isa=rv64gc pk atomics | grep "First atomic counter is 1000, second is 100"
# check that including sim.h in an external project works
g++ -std=c++2a -I../install/include -L../install/lib $DIR/testlib.cc -lriscv -o test-libriscv

2
riscv/mmu.cc

@ -369,7 +369,7 @@ void mmu_t::store_slow_path(reg_t original_addr, reg_t len, const uint8_t* bytes
store_slow_path_intrapage(len, bytes, access_info, actually_store);
}
if (proc && unlikely(proc->get_log_commits_enabled()))
if (actually_store && proc && unlikely(proc->get_log_commits_enabled()))
proc->state.log_mem_write.push_back(std::make_tuple(original_addr, reg_from_bytes(len, bytes), len));
}

Loading…
Cancel
Save