Skip to content

Commit b4a0028

Browse files
sjp38torvalds
authored andcommitted
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 db7a347 ("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/[email protected] Signed-off-by: SeongJae Park <[email protected]> Cc: Brendan Higgins <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d85570c commit b4a0028

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
huge_count_read_write

tools/testing/selftests/damon/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# SPDX-License-Identifier: GPL-2.0
22
# Makefile for damon selftests
33

4+
TEST_GEN_FILES += huge_count_read_write
5+
46
TEST_FILES = _chk_dependency.sh
57
TEST_PROGS = debugfs_attrs.sh
68

tools/testing/selftests/damon/debugfs_attrs.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,22 @@ orig_monitor_on=$(cat "$DBGFS/monitor_on")
105105
test_write_fail "$DBGFS/monitor_on" "on" "orig_monitor_on" "empty target ids"
106106
echo "$orig_target_ids" > "$DBGFS/target_ids"
107107

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+
108126
echo "PASS"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Author: SeongJae Park <[email protected]>
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+
}

0 commit comments

Comments
 (0)