Exclude areas not assigned to Mckernel from direct map of all phys. memory

It's enabled by adding -s to mcreboot.sh.

Cherry-pick of the following commit:

commit b5c13ce51a5a4926c2cf11c817cd0d369ac4402d
Author: Katsuya Horigome <katsuya.horigome.rj@ps.hitachi-solutions.com>
Date:   Mon Nov 20 09:40:41 2017 +0900

    Include measures to prevent memory destruction on Linux side (This is rebase commit for merging to development+hfi)
This commit is contained in:
Katsuya Horigome
2018-02-19 11:59:04 +09:00
committed by Masamichi Takagi
parent 221ce34da2
commit 38c3b2358a
22 changed files with 412 additions and 13 deletions

View File

@ -0,0 +1,100 @@
brk01
clone01
clone03
clone04
clone06
clone07
close01
close02
dup01
dup02
dup03
dup04
dup05
dup06
dup07
fork01
fork02
fork03
fork04
fork07
fork08
fork09
fork10
fork11
mbind01
mem01
mem02
mem03
memcpy01
memfd_create02
memset01
mkdir01
mkdir08
mkdirat01
mknodat01
mmap001
mmap01
mmap02
mmap03
mmap04
mmap06
mmap07
mmap08
mmap09
mmap12
mmapstress02
mmapstress04
mmapstress05
mremap01
mremap05
open01
open03
open04
open06
open07
open09
open13
poll01
posix_fadvise01
read01
read02
read03
read04
sbrk01
sbrk02
sendfile02
sendfile03
sendfile04
sendfile05
sendfile06
sendfile07
sendfile08
sendfile09
semctl01
semctl03
semctl05
socket01
socket02
stream01
stream02
stream03
stream04
stream05
unlink05
unlink06
unlink07
unlink08
vfork01
vfork02
vma01
vmsplice01
vmsplice02
write01
write03
write04
write05
writetest
writev01
writev02
writev07

25
test/mem_dest_prev/README Normal file
View File

@ -0,0 +1,25 @@
===================
Advance preparation
===================
1)Implement patch of test_memtest_destroy.patch
cd mckernel
patch -p0 < test_memtest_destroy.patch
make
make install
2)Compile command execution processing
cd mckernel/test/mem_dest_prev/mcexec_test_proc/
make
3)Write the LTP path to LTP_DIR in the configuration file
vi config
ex) LTP_DIR=$HOME/test/mem_dest_prev/ltp/testcases/bin/
==========
How to run
==========
./go_test_McKernal.sh

13
test/mem_dest_prev/config Normal file
View File

@ -0,0 +1,13 @@
MCMOD_DIR=$HOME/ppos
LTP_DIR=$HOME/test/mem_dest_prev/ltp/testcases/bin/
LTP_TESTCASE_FILE=LTP_testcase.txt
MCRBT_OPT_LTP="-m 3G@0,3G@1 -s"
USR_PROC="mcexec_test_proc/memtest_destroy"
OS_IDX=0
export MCMOD_DIR
export LTP_DIR
export LTP_TESTCASE_FILE
export MCRBT_OPT_LTP
export USR_PROC
export OS_IDX

View File

@ -0,0 +1,101 @@
#!/bin/sh
# read config
source ./config
#logfile="./result/test_result.log"
# mcexec processのkill
./utils/kill_mcexec.sh &> /dev/null
for test_case in `ls -1 ./testcases/*.txt`
do
# read testcase param
source ${test_case}
case_name=`basename ${test_case} .txt`
echo "####################"
echo "Test No:${case_name}"
# Out-of-range address Test(Before correspondence)
echo ">>> Out-of-range address Test(Before correspondence) Start"
# stop mckernel
sudo ${MCMOD_DIR}/sbin/mcstop+release.sh
sleep 1
# boot mckernel
echo "${MCMOD_DIR}/sbin/mcreboot.sh ${MCRBT_OPT_BEFORE%,}"
sudo ${MCMOD_DIR}/sbin/mcreboot.sh ${MCRBT_OPT_BEFORE%,}
sleep 1
echo " ${MCMOD_DIR}/bin/mcexec ${USR_PROC}"
timeout -sKILL 5 ${MCMOD_DIR}/bin/mcexec ${USR_PROC}
STATUS=$?
echo "${MCMOD_DIR}/sbin/ihkosctl ${OS_IDX} kmsg"
sudo ${MCMOD_DIR}/sbin/ihkosctl ${OS_IDX} kmsg
if [ "$STATUS" -ne 21 ];
then
echo ">>> Out-of-range address Test End(Timeout!!!)"
else
echo ">>> Out-of-range address Test End"
fi
# Out-of-range address Test(After correspondence)
echo ">>> Out-of-range address(After correspondence) Test Start"
# stop mckernel
sudo ${MCMOD_DIR}/sbin/mcstop+release.sh
sleep 1
# boot mckernel
echo "${MCMOD_DIR}/sbin/mcreboot.sh ${MCRBT_OPT_AFTER%,}"
sudo ${MCMOD_DIR}/sbin/mcreboot.sh ${MCRBT_OPT_AFTER%,}
sleep 1
echo " ${MCMOD_DIR}/bin/mcexec ${USR_PROC}"
timeout -sKILL 5 ${MCMOD_DIR}/bin/mcexec ${USR_PROC}
STATUS=$?
echo "${MCMOD_DIR}/sbin/ihkosctl ${OS_IDX} kmsg"
sudo ${MCMOD_DIR}/sbin/ihkosctl ${OS_IDX} kmsg
if [ "$STATUS" -ne 21 ];
then
echo ">>> Out-of-range address Test End(Timeout!!!)"
else
echo ">>> Out-of-range address Test End"
fi
done
### LTP START ##################################################
# stop mckernel
sudo ${MCMOD_DIR}/sbin/mcstop+release.sh
sleep 1
# boot mckernel
echo "${MCMOD_DIR}/sbin/mcreboot.sh ${MCRBT_OPT_LTP%,}"
sudo ${MCMOD_DIR}/sbin/mcreboot.sh ${MCRBT_OPT_LTP%,}
sleep 1
if [ ! -e "/dev/mcos0" ]; then
echo "Error: failed to mcreboot"
exit 1
fi
TEST_NUM=`wc -l ${LTP_TESTCASE_FILE} | awk '{print $1}'`
echo ">>> LTP Test Start( $TEST_NUM counts )"
# exec mckernel test program
COUNT=0
while read line
do
((COUNT++))
echo "$COUNT:${MCMOD_DIR}/bin/mcexec ${LTP_DIR}$line"
# ${MCMOD_DIR}/bin/mcexec ${LTP_DIR}$line &>> ${logfile}
${MCMOD_DIR}/bin/mcexec ${LTP_DIR}$line
done < ${LTP_TESTCASE_FILE}
echo ">>> LTP Test End"
### LTP END ####################################################

View File

@ -0,0 +1,7 @@
OBJS = memtest_destroy
all:$(OBJS)
clean:
rm $(OBJS)

View File

@ -0,0 +1,13 @@
#include <stdio.h>
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
main() {
int rst = 0;
rst = syscall(950);
printf("mem_destroy result:%d\n",rst);
return;
}

View File

@ -0,0 +1,50 @@
diff --git arch/x86/kernel/include/syscall_list.h arch/x86/kernel/include/syscall_list.h
index 42d1e2e..f5769b8 100644
--- arch/x86/kernel/include/syscall_list.h
+++ arch/x86/kernel/include/syscall_list.h
@@ -156,5 +156,7 @@ SYSCALL_HANDLED(__NR_profile, profile)
SYSCALL_HANDLED(730, util_migrate_inter_kernel)
SYSCALL_HANDLED(731, util_indicate_clone)
SYSCALL_HANDLED(732, get_system)
+/* McKernel Specific */
+SYSCALL_HANDLED(950, mem_destroy)
/**** End of File ****/
diff --git arch/x86/kernel/syscall.c arch/x86/kernel/syscall.c
index 2260b66..e96776a 100644
--- arch/x86/kernel/syscall.c
+++ arch/x86/kernel/syscall.c
@@ -1887,4 +1887,33 @@ save_uctx(void *uctx, struct x86_user_context *regs)
ctx->fregsize = 0;
}
+
+#define ADD_ADDR_VAL 0x400
+SYSCALL_DECLARE(mem_destroy)
+{
+ int rst = 0;
+ int mem_chunks_num, chunk_id, get_numa_id;
+ unsigned long get_start, get_end;
+ unsigned long *addr;
+
+ mem_chunks_num = ihk_mc_get_nr_memory_chunks();
+ kprintf("%s: memory chunk %d.\n", __FUNCTION__, mem_chunks_num);
+
+ for (chunk_id = 0; chunk_id < mem_chunks_num; chunk_id++) {
+ rst = ihk_mc_get_memory_chunk(chunk_id, &get_start, &get_end, &get_numa_id);
+ kprintf("%s: mem chunk[%d] numa ID(%d)\n"
+ ,__FUNCTION__ ,chunk_id ,get_numa_id);
+ kprintf(" phys(0x%lx - 0x%lx) virt(0x%lx - 0x%lx)\n"
+ ,get_start ,get_end ,phys_to_virt(get_start) ,phys_to_virt(get_end));
+ }
+
+ addr = phys_to_virt(get_end + ADD_ADDR_VAL);
+#if 1
+ *addr = 0x1;
+#endif
+ kprintf("%s: Address out of range 0x%lx(val:%d)\n",__FUNCTION__ ,addr ,*addr);
+
+ return rst;
+}
+
/*** End of File ***/

View File

@ -0,0 +1,2 @@
MCRBT_OPT_BEFORE="-m `./utils/gen_mem_chunks.sh "0 1" 3G 1`"
MCRBT_OPT_AFTER="-m `./utils/gen_mem_chunks.sh "0 1" 3G 1` -s"

View File

@ -0,0 +1,2 @@
MCRBT_OPT_BEFORE="-m `./utils/gen_mem_chunks.sh "0 1" 32M 2`"
MCRBT_OPT_AFTER="-m `./utils/gen_mem_chunks.sh "0 1" 32M 2` -s"

View File

@ -0,0 +1,2 @@
MCRBT_OPT_BEFORE="-m `./utils/gen_mem_chunks.sh "0 1" 32M 4`"
MCRBT_OPT_AFTER="-m `./utils/gen_mem_chunks.sh "0 1" 32M 4` -s"

View File

@ -0,0 +1,2 @@
MCRBT_OPT_BEFORE="-m `./utils/gen_mem_chunks.sh "0 1" 32M 8`"
MCRBT_OPT_AFTER="-m `./utils/gen_mem_chunks.sh "0 1" 32M 8` -s"

View File

@ -0,0 +1,2 @@
MCRBT_OPT_BEFORE="-m `./utils/gen_mem_chunks.sh "0 1" 32M 16`"
MCRBT_OPT_AFTER="-m `./utils/gen_mem_chunks.sh "0 1" 32M 16` -s"

View File

@ -0,0 +1,2 @@
MCRBT_OPT_BEFORE="-m `./utils/gen_mem_chunks.sh "0 1" 32M 32`"
MCRBT_OPT_AFTER="-m `./utils/gen_mem_chunks.sh "0 1" 32M 32` -s"

View File

@ -0,0 +1,2 @@
MCRBT_OPT_BEFORE="-m `./utils/gen_mem_chunks.sh "0 1" 32M 48`"
MCRBT_OPT_AFTER="-m `./utils/gen_mem_chunks.sh "0 1" 32M 48` -s"

View File

@ -0,0 +1,2 @@
MCRBT_OPT_BEFORE="-m `./utils/gen_mem_chunks.sh "0 1" 32M 64`"
MCRBT_OPT_AFTER="-m `./utils/gen_mem_chunks.sh "0 1" 32M 64` -s"

View File

@ -0,0 +1,2 @@
MCRBT_OPT_BEFORE="-m `./utils/gen_mem_chunks.sh "0 1" 32M 96`"
MCRBT_OPT_AFTER="-m `./utils/gen_mem_chunks.sh "0 1" 32M 96` -s"

View File

@ -0,0 +1,2 @@
MCRBT_OPT_BEFORE="-m `./utils/gen_mem_chunks.sh "0 1" 32M 128`"
MCRBT_OPT_AFTER="-m `./utils/gen_mem_chunks.sh "0 1" 32M 128` -s"

View File

@ -0,0 +1,16 @@
#!/bin/sh
NUMAS=$1
MEM_SIZE=$2
REP=$3
CHUNKS=""
for numa in ${NUMAS}
do
for rep in `seq 1 ${REP}`
do
CHUNKS="${CHUNKS}${MEM_SIZE}@${numa},"
done
done
echo ${CHUNKS%,}

View File

@ -0,0 +1,10 @@
#!/bin/sh
count=`pgrep -c -f 'mcexec '`
if [ ${count} -gt 0 ]
then
echo "kill process :" ${count}
pgrep -l -f 'mcexec '
pgrep -f 'mcexec ' | xargs kill -9
fi