fix: madvise changes only the first one of vm_ranges
Change-Id: I83248c1162e28c3c24ca5f6b0933e1a8ca434d6b Fujitsu: POSTK_DEBUG_TEMP_FIX_37 Refs: #1351
This commit is contained in:
74
test/issues/1351/C1351.c
Normal file
74
test/issues/1351/C1351.c
Normal file
@ -0,0 +1,74 @@
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#define MAP_HUGE_SHIFT 26
|
||||
#define MADV_SHOW_ATTR 201 /* for TEST */
|
||||
#define RANGE_NUM 3
|
||||
#define PAGE_NUM 2
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
void *mems[RANGE_NUM];
|
||||
int ret = 0;
|
||||
int i, rc, fd;
|
||||
int fds[RANGE_NUM];
|
||||
int pgnum;
|
||||
size_t pgsize, map_size, def_pgsize = getpagesize();
|
||||
|
||||
if ((fd = open("TestFile", O_RDWR | O_CREAT, 0666)) == -1) {
|
||||
perror("open");
|
||||
return -1;
|
||||
}
|
||||
|
||||
pgsize = getpagesize();
|
||||
map_size = pgsize * PAGE_NUM;
|
||||
|
||||
for (i = 0; i < RANGE_NUM; i++) {
|
||||
mems[i] = mmap(0, map_size, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED, fd, 0);
|
||||
}
|
||||
for (i = 0; i < RANGE_NUM; i++) {
|
||||
if (i > 0) {
|
||||
if (mems[i] != mems[i - 1] + map_size) {
|
||||
printf("maps is not continuous\n");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("** mmap continuous areas: Done\n");
|
||||
|
||||
rc = madvise(mems[0], map_size * RANGE_NUM, MADV_DONTDUMP);
|
||||
if (rc != 0) {
|
||||
perror("madvise MADV_DONTDUMP");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
printf("** madvise MADV_DONTDUMP: Done\n");
|
||||
|
||||
rc = madvise(mems[0], map_size * RANGE_NUM, MADV_SHOW_ATTR);
|
||||
if (rc != 0) {
|
||||
perror("madvise MAD_SHOW_ATTR");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
printf("** madvise MADV_SHOW_ATTR: Done\n");
|
||||
|
||||
munmap(mems[0], map_size * RANGE_NUM);
|
||||
|
||||
out:
|
||||
close(fd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
44
test/issues/1351/C1351.sh
Executable file
44
test/issues/1351/C1351.sh
Executable file
@ -0,0 +1,44 @@
|
||||
#/bin/sh
|
||||
|
||||
USELTP=1
|
||||
USEOSTEST=0
|
||||
|
||||
. ../../common.sh
|
||||
|
||||
issue=1351
|
||||
tid=01
|
||||
|
||||
tname=`printf "C${issue}T%02d" ${tid}`
|
||||
echo "*** ${tname} start *******************************"
|
||||
ng=0
|
||||
${IHKOSCTL} 0 clear_kmsg
|
||||
${MCEXEC} ./C1351
|
||||
|
||||
${IHKOSCTL} 0 kmsg | tee ./${tname}.txt
|
||||
|
||||
line=`grep -e "attr: 0x20731000" ./${tname}.txt | wc -l`
|
||||
|
||||
if [ ${line} -eq 3 ]; then
|
||||
echo "*** ${tname} PASSED ******************************"
|
||||
else
|
||||
echo "*** ${tname} FAILED ******************************"
|
||||
fi
|
||||
let tid++
|
||||
echo ""
|
||||
|
||||
for tp in madvise01 madvise02 madvise03 madvise04
|
||||
do
|
||||
tname=`printf "C${issue}T%02d" ${tid}`
|
||||
echo "*** ${tname} start *******************************"
|
||||
$MCEXEC $LTPBIN/$tp 2>&1 | tee $tp.txt
|
||||
ok=`grep TPASS $tp.txt | wc -l`
|
||||
ng=`grep TFAIL $tp.txt | wc -l`
|
||||
if [ $ng = 0 ]; then
|
||||
echo "*** ${tname} PASSED ($ok)"
|
||||
else
|
||||
echo "*** ${tname} FAILED (ok=$ok ng=%ng)"
|
||||
fi
|
||||
let tid++
|
||||
echo ""
|
||||
done
|
||||
|
||||
11
test/issues/1351/Makefile
Normal file
11
test/issues/1351/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
CFLAGS=-g
|
||||
LDFLAGS=
|
||||
|
||||
TARGET=C1351
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
test: all
|
||||
./C1351.sh
|
||||
clean:
|
||||
rm -f $(TARGET) *.o TestFile* *.txt
|
||||
34
test/issues/1351/README
Normal file
34
test/issues/1351/README
Normal file
@ -0,0 +1,34 @@
|
||||
【Issue#1351 動作確認】
|
||||
□ テスト内容
|
||||
1. 複数のvm_rangeから構成されるメモリ領域に対するmadviseの動作を確認
|
||||
C1351T01:
|
||||
以下の流れでmadviseの設定が複数のvm_rangeに適用されたことを確認
|
||||
1. 複数回のmmapで連続したメモリ領域を確保する
|
||||
2. 1.で確保したメモリ領域にMADV_DODUMPを設定する (初期化)
|
||||
3. 1.で確保したメモリ領域にMADV_DONTDUMPを設定する
|
||||
4. テスト用のmadvise(MADV_SHOW_ATTR) を実行し、
|
||||
すべてのvm_rangeにMADV_DONTDUMPが設定されていることを確認する
|
||||
|
||||
2. LTP を用いてmadviseの既存処理に影響しないことを確認
|
||||
以下のLTPがPASSすることを確認
|
||||
- madvise01
|
||||
- madvise02
|
||||
- madvise03
|
||||
- madvise04
|
||||
|
||||
□ 実行手順
|
||||
1. 下記の手順でテストを実行する
|
||||
$ cd <mckernel>
|
||||
$ patch -p0 < test/issues/1351/show_attr.patch
|
||||
(build mckernel)
|
||||
$ cd test/issues/1351
|
||||
$ make test
|
||||
|
||||
McKernelのインストール先や、OSTEST, LTPの配置場所は、
|
||||
$HOME/.mck_test_config を参照している
|
||||
.mck_test_config は、McKernelをビルドした際に生成されるmck_test_config.sample ファイルを
|
||||
$HOMEにコピーし、適宜編集する
|
||||
|
||||
□ 実行結果
|
||||
x86_64_result.log, aarch64_result.log 参照。
|
||||
すべての項目をPASSしていることを確認。
|
||||
39
test/issues/1351/aarch64_result.log
Normal file
39
test/issues/1351/aarch64_result.log
Normal file
@ -0,0 +1,39 @@
|
||||
*** C1351T01 start *******************************
|
||||
** mmap continuous areas: Done
|
||||
** madvise MADV_DONTDUMP: Done
|
||||
** madvise MADV_SHOW_ATTR: Done
|
||||
[ 0]: range 0x10000017a000 - 0x10000017c000 attr: 0x20731000
|
||||
[ 0]: range 0x10000017c000 - 0x10000017e000 attr: 0x20731000
|
||||
[ 0]: range 0x10000017e000 - 0x100000180000 attr: 0x20731000
|
||||
|
||||
*** C1351T01 PASSED ******************************
|
||||
|
||||
*** C1351T02 start *******************************
|
||||
madvise01 1 TPASS : madvise test for MADV_NORMAL PASSED
|
||||
madvise01 2 TPASS : madvise test for MADV_RANDOM PASSED
|
||||
madvise01 3 TPASS : madvise test for MADV_SEQUENTIAL PASSED
|
||||
madvise01 4 TPASS : madvise test for MADV_WILLNEED PASSED
|
||||
madvise01 5 TPASS : madvise test for MADV_DONTNEED PASSED
|
||||
*** C1351T02 PASSED (5)
|
||||
|
||||
*** C1351T03 start *******************************
|
||||
madvise02 1 TPASS : failed as expected: TEST_ERRNO=EINVAL(22): Invalid argument
|
||||
madvise02 2 TPASS : failed as expected: TEST_ERRNO=EINVAL(22): Invalid argument
|
||||
madvise02 3 TPASS : failed as expected: TEST_ERRNO=EINVAL(22): Invalid argument
|
||||
madvise02 4 TCONF : madvise02.c:216: kernel configured with CONFIG_KSM, skip EINVAL test for MADV_MERGEABLE.
|
||||
madvise02 5 TCONF : madvise02.c:237: kernel configured with CONFIG_KSM, skip EINVAL test for MADV_UNMERGEABLE.
|
||||
madvise02 6 TPASS : failed as expected: TEST_ERRNO=ENOMEM(12): Cannot allocate memory
|
||||
madvise02 7 TPASS : madvise succeeded as expected, see kernel commit 1998cc0 for details.
|
||||
*** C1351T03 PASSED (5)
|
||||
|
||||
*** C1351T04 start *******************************
|
||||
madvise03 1 TPASS : madvise test for MADV_REMOVE PASSED
|
||||
madvise03 2 TPASS : madvise test for MADV_DONTFORK PASSED
|
||||
madvise03 3 TPASS : madvise test for MADV_DOFORK PASSED
|
||||
*** C1351T04 PASSED (3)
|
||||
|
||||
*** C1351T05 start *******************************
|
||||
madvise04 1 TPASS : madvise test for MADV_DONTDUMP PASSED
|
||||
madvise04 2 TPASS : madvise test for MADV_DODUMP PASSED
|
||||
*** C1351T05 PASSED (2)
|
||||
|
||||
54
test/issues/1351/show_attr.patch
Normal file
54
test/issues/1351/show_attr.patch
Normal file
@ -0,0 +1,54 @@
|
||||
diff --git kernel/include/mman.h kernel/include/mman.h
|
||||
index e7d3526..3b8b0f3 100644
|
||||
--- kernel/include/mman.h
|
||||
+++ kernel/include/mman.h
|
||||
@@ -56,6 +56,7 @@
|
||||
#define MADV_DODUMP 17
|
||||
#define MADV_HWPOISON 100
|
||||
#define MADV_SOFT_OFFLINE 101
|
||||
+#define MADV_SHOW_ATTR 201 /* for TEST */
|
||||
|
||||
/*
|
||||
* for mremap()
|
||||
diff --git kernel/syscall.c kernel/syscall.c
|
||||
index 564c103..9e2c56f 100644
|
||||
--- kernel/syscall.c
|
||||
+++ kernel/syscall.c
|
||||
@@ -4651,6 +4651,14 @@ clear_memory_range_flag(struct vm_range *range, unsigned long arg)
|
||||
}
|
||||
|
||||
static int
|
||||
+show_memory_range_flag(struct vm_range *range, unsigned long arg)
|
||||
+{
|
||||
+ kprintf("range 0x%lx - 0x%lx attr: 0x%lx\n",
|
||||
+ range->start, range->end, range->flag);
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int
|
||||
change_attr_process_memory_range(struct process_vm *vm,
|
||||
uintptr_t start, uintptr_t end,
|
||||
int (*change_proc)(struct vm_range *,
|
||||
@@ -4779,6 +4787,7 @@ SYSCALL_DECLARE(madvise)
|
||||
case MADV_REMOVE:
|
||||
case MADV_DONTDUMP:
|
||||
case MADV_DODUMP:
|
||||
+ case MADV_SHOW_ATTR:
|
||||
break;
|
||||
|
||||
case MADV_HWPOISON:
|
||||
@@ -4919,6 +4928,14 @@ SYSCALL_DECLARE(madvise)
|
||||
error = syscall_generic_forwarding(__NR_madvise, ctx);
|
||||
}
|
||||
|
||||
+ if (advice == MADV_SHOW_ATTR) {
|
||||
+ error = change_attr_process_memory_range(thread->vm,
|
||||
+ start, end, show_memory_range_flag, 0);
|
||||
+ if (error) {
|
||||
+ goto out;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
error = 0;
|
||||
out:
|
||||
memory_range_write_unlock(thread->vm, &irqflags);
|
||||
39
test/issues/1351/x86_64_result.log
Normal file
39
test/issues/1351/x86_64_result.log
Normal file
@ -0,0 +1,39 @@
|
||||
*** C1351T01 start *******************************
|
||||
** mmap continuous areas: Done
|
||||
** madvise MADV_DONTDUMP: Done
|
||||
** madvise MADV_SHOW_ATTR: Done
|
||||
[ 0]: range 0x2aaaaade9000 - 0x2aaaaadeb000 attr: 0x20731000
|
||||
[ 0]: range 0x2aaaaadeb000 - 0x2aaaaaded000 attr: 0x20731000
|
||||
[ 0]: range 0x2aaaaaded000 - 0x2aaaaadef000 attr: 0x20731000
|
||||
|
||||
*** C1351T01 PASSED ******************************
|
||||
|
||||
*** C1351T02 start *******************************
|
||||
madvise01 1 TPASS : madvise test for MADV_NORMAL PASSED
|
||||
madvise01 2 TPASS : madvise test for MADV_RANDOM PASSED
|
||||
madvise01 3 TPASS : madvise test for MADV_SEQUENTIAL PASSED
|
||||
madvise01 4 TPASS : madvise test for MADV_WILLNEED PASSED
|
||||
madvise01 5 TPASS : madvise test for MADV_DONTNEED PASSED
|
||||
*** C1351T02 PASSED (5)
|
||||
|
||||
*** C1351T03 start *******************************
|
||||
madvise02 1 TPASS : failed as expected: TEST_ERRNO=EINVAL(22): Invalid argument
|
||||
madvise02 2 TPASS : failed as expected: TEST_ERRNO=EINVAL(22): Invalid argument
|
||||
madvise02 3 TPASS : failed as expected: TEST_ERRNO=EINVAL(22): Invalid argument
|
||||
madvise02 4 TCONF : madvise02.c:216: kernel configured with CONFIG_KSM, skip EINVAL test for MADV_MERGEABLE.
|
||||
madvise02 5 TCONF : madvise02.c:237: kernel configured with CONFIG_KSM, skip EINVAL test for MADV_UNMERGEABLE.
|
||||
madvise02 6 TPASS : failed as expected: TEST_ERRNO=ENOMEM(12): Cannot allocate memory
|
||||
madvise02 7 TPASS : madvise succeeded as expected, see kernel commit 1998cc0 for details.
|
||||
*** C1351T03 PASSED (5)
|
||||
|
||||
*** C1351T04 start *******************************
|
||||
madvise03 1 TPASS : madvise test for MADV_REMOVE PASSED
|
||||
madvise03 2 TPASS : madvise test for MADV_DONTFORK PASSED
|
||||
madvise03 3 TPASS : madvise test for MADV_DOFORK PASSED
|
||||
*** C1351T04 PASSED (3)
|
||||
|
||||
*** C1351T05 start *******************************
|
||||
madvise04 1 TPASS : madvise test for MADV_DONTDUMP PASSED
|
||||
madvise04 2 TPASS : madvise test for MADV_DODUMP PASSED
|
||||
*** C1351T05 PASSED (2)
|
||||
|
||||
Reference in New Issue
Block a user