Introduce a test that performs stack writes in recursive calls to exercise
stack watch at a specific recursion depth.

Signed-off-by: Jinchao Wang <[email protected]>
---
 mm/kstackwatch/test.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/mm/kstackwatch/test.c b/mm/kstackwatch/test.c
index 740e3c11b3ef..08e3d37c4c04 100644
--- a/mm/kstackwatch/test.c
+++ b/mm/kstackwatch/test.c
@@ -57,6 +57,20 @@ static void test_canary_overflow(void)
        pr_info("exit of %s\n", __func__);
 }
 
+static void test_recursive_depth(int depth)
+{
+       u64 buffer[BUFFER_SIZE];
+
+       pr_info("entry of %s depth:%d\n", __func__, depth);
+
+       if (depth < MAX_DEPTH)
+               test_recursive_depth(depth + 1);
+
+       buffer[0] = depth;
+       barrier_data(buffer);
+
+       pr_info("exit of %s depth:%d\n", __func__, depth);
+}
 
 static ssize_t test_proc_write(struct file *file, const char __user *buffer,
                               size_t count, loff_t *pos)
@@ -83,6 +97,9 @@ static ssize_t test_proc_write(struct file *file, const char 
__user *buffer,
                case 1:
                        test_canary_overflow();
                        break;
+               case 2:
+                       test_recursive_depth(0);
+                       break;
                default:
                        pr_err("Unknown test number %d\n", test_num);
                        return -EINVAL;
@@ -103,7 +120,8 @@ static ssize_t test_proc_read(struct file *file, char 
__user *buffer,
                                    "Usage:\n"
                                    "echo test{i} > /proc/kstackwatch_test\n"
                                    " test0 - test watch fire\n"
-                                   " test1 - test canary overflow\n";
+                                   " test1 - test canary overflow\n"
+                                   " test2 - test recursive func\n";
 
        return simple_read_from_buffer(buffer, count, pos, usage,
                                       strlen(usage));
-- 
2.43.0


Reply via email to