Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/damon: test debugfs file reads/writes with huge count

DAMON debugfs interface users were able to trigger warning by writing
some files with arbitrarily large 'count' parameter. The issue is fixed
with commit db7a347b26fe ("mm/damon/dbgfs: use '__GFP_NOWARN' for
user-specified size buffer allocation"). This commit adds a test case
for the issue in DAMON selftests to avoid future regressions.

Link: https://lkml.kernel.org/r/20211201150440.1088-11-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Brendan Higgins <brendanhiggins@google.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

SeongJae Park and committed by
Linus Torvalds
b4a00288 d85570c6

+61
+2
tools/testing/selftests/damon/.gitignore
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + huge_count_read_write
+2
tools/testing/selftests/damon/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 # Makefile for damon selftests 3 3 4 + TEST_GEN_FILES += huge_count_read_write 5 + 4 6 TEST_FILES = _chk_dependency.sh 5 7 TEST_PROGS = debugfs_attrs.sh 6 8
+18
tools/testing/selftests/damon/debugfs_attrs.sh
··· 105 105 test_write_fail "$DBGFS/monitor_on" "on" "orig_monitor_on" "empty target ids" 106 106 echo "$orig_target_ids" > "$DBGFS/target_ids" 107 107 108 + # Test huge count read write 109 + # ========================== 110 + 111 + dmesg -C 112 + 113 + for file in "$DBGFS/"* 114 + do 115 + ./huge_count_read_write "$file" 116 + done 117 + 118 + if dmesg | grep -q WARNING 119 + then 120 + dmesg 121 + exit 1 122 + else 123 + exit 0 124 + fi 125 + 108 126 echo "PASS"
+39
tools/testing/selftests/damon/huge_count_read_write.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Author: SeongJae Park <sj@kernel.org> 4 + */ 5 + 6 + #include <fcntl.h> 7 + #include <stdlib.h> 8 + #include <unistd.h> 9 + #include <stdio.h> 10 + 11 + void write_read_with_huge_count(char *file) 12 + { 13 + int filedesc = open(file, O_RDWR); 14 + char buf[25]; 15 + int ret; 16 + 17 + printf("%s %s\n", __func__, file); 18 + if (filedesc < 0) { 19 + fprintf(stderr, "failed opening %s\n", file); 20 + exit(1); 21 + } 22 + 23 + write(filedesc, "", 0xfffffffful); 24 + perror("after write: "); 25 + ret = read(filedesc, buf, 0xfffffffful); 26 + perror("after read: "); 27 + close(filedesc); 28 + } 29 + 30 + int main(int argc, char *argv[]) 31 + { 32 + if (argc != 2) { 33 + fprintf(stderr, "Usage: %s <file>\n", argv[0]); 34 + exit(1); 35 + } 36 + write_read_with_huge_count(argv[1]); 37 + 38 + return 0; 39 + }