From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5E1A2E0914 for ; Thu, 25 Sep 2025 02:06:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758766011; cv=none; b=N4Uj5CtRoLA8Wig/iV7l5LnnV+W4InE6TIx15PEfB2llccNPljtDxrMm9fajsmTt8E6/G+bNuh3yIFSAyA4VQzfOGKEm5g+p5igvE9kfzzDHL/PTNzaEHTxqaxr4KoPBVMYdxX8rRPxOjmYnV/cRXlT5DcQ5eJBKFLlm9tMwv6c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758766011; c=relaxed/simple; bh=VUaEopFT8QpBRBeRXFpCrrY3LYAx7YydiEUYySF2rP4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cGe2FTD026iRZRMIg50eObEkLUrMNxMhMVPRO6clzsbxT9w4FtkoXC0GZjqr38wiOuEQY5RywW6QjefYAh4pHBbXFExEBanBuGSnukRvi6u4NkJcddGlqVUMVn6rneE1z3mTpFD91bonbeauX2PKzwD//TEpiOVE5JX+CvaT4RU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LNhRhLbl; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LNhRhLbl" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-267fac63459so4236065ad.1 for ; Wed, 24 Sep 2025 19:06:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758766009; x=1759370809; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=TDDNQxOCofAWfoIkXGgKX3OgUnzUt3+cN5qe0WBH0Fk=; b=LNhRhLbloMI2cn+inv/yExr/cRovpGPm4+svrmh6pemCipiiTdza6OcPbhjz+wSIj5 XD9sTST8Ny1FnPEdL+4JR4lXDV5A36e5LgOHCyIJqQSM+vM989bjOS+a2UvEZnlTc19F dXR9RAyrYsGYw33RNUJlbh1lNuexFlk11CzjL1LMEqYx3/APh3cbinJUEH1P89SrTkl5 UbpBCa7SLHb/CaL7aVQXDi12DP5mar0vLqBF8AeJqFbM2HZO12ZfYtkDU5ARA0yTYyzl lYviQBxLu1E6gA32VSQFS1bAjPydax1HKY5J+NS9/vkIML6xfEe/NVwDQFqiXvrkdnPq 9P0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758766009; x=1759370809; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=TDDNQxOCofAWfoIkXGgKX3OgUnzUt3+cN5qe0WBH0Fk=; b=SEt+SQthFyv581KhzfIc4R/Uxiy1416arsLnXr0HFqMHuenKzsVB/nb8ZVPY4u7jYS RCqB6j4in0NMIrdDmDNuaR7PQQINblivJzMDTdt3tSYn1TTjG/6kZtXFeRzSm+TVkD0W Z8hkvfkc96vN8F//9Dt2oYSTV8uSxzXjE3gFyMA3MV7MSBCBxXCFiJnZ5UDyxf+yJnYj djO3Jsdjs2T1v8lYQ7pvIe2+nZecVco5Y0BFGEYfJBV2eCDpPkAxY1WWQM8WCEh0sWLA 5xPbg2eudBNeabPAYFQ/9FH6D5DqGITXQlJ7WX6iI34rFZ6S0AeVdfRxQD+0IRyjDTN2 WjzQ== X-Forwarded-Encrypted: i=1; AJvYcCUir+fulj17yPvXgxU2gt5j6zji3zpa49404o3DNMWO2nX0Dsz19Dmuv/v6jnN5xz/jHsoOhfMtslrlwBTgZZgA+MA=@vger.kernel.org X-Gm-Message-State: AOJu0Yyw0v+j01ZcCQoILeyZtkKgdVbQsRPXv4uDWz7k3habY1ENB6dj hPfuCEpN+bNJDuLniIS2kMyaW7kBHV4DOtXTxsUgwb7Ry03SBQygU+PI X-Gm-Gg: ASbGncvPRytCS2rEXkycZOlvOoKEk44McIXW4X5OwIvmXD0hPSeBpO5fYusVSF2HpY3 /JvVfA/IiQKtSIiTt5zZ34EQFvhlDyDdjE25/D45rYF+CmQIwhk/VJIzWDRk6XZIGqpQDmYif5a lljAH8FPAN8+oun+wQQYGNZma8wEKEOxvz4qFfO9e0GIQRZSNKbVXI9J5TBPyFDptnK7lxJrA6A 3lcusfHU7w1kvYDyCD2+nIa7f9ThWAe/kusg6Z3Xfj/6ZeqeH6pu+FmLFakxuiNA3jP83oGTpbp zrywrZANrlgoT4fyBM0AJsCB0hBHO3Q9Dd4DN78UvIy0V6dZ2rwh/ADASix2yG5IH0aShLPbYJD tI9UTEpxc9BdrjA/at88kFkk= X-Google-Smtp-Source: AGHT+IGmMrm8xksFP6ju22OaumMbD6YwInELL6WKXRm9IlZDS3eIrrfgfG3Q7BtCL53wgsMXve+VwA== X-Received: by 2002:a17:902:f54c:b0:271:479d:3de3 with SMTP id d9443c01a7336-27ed49c7763mr18733235ad.12.1758766009065; Wed, 24 Sep 2025 19:06:49 -0700 (PDT) Received: from localhost ([103.88.46.62]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-27ed66cf181sm6940845ad.28.2025.09.24.19.06.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Sep 2025 19:06:48 -0700 (PDT) Date: Thu, 25 Sep 2025 10:06:44 +0800 From: Jinchao Wang To: Marco Elver Cc: Andrew Morton , Masami Hiramatsu , Peter Zijlstra , Mike Rapoport , Alexander Potapenko , Randy Dunlap , Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Kees Cook , Alice Ryhl , Sami Tolvanen , Miguel Ojeda , Masahiro Yamada , Rong Xu , Naveen N Rao , David Kaplan , Andrii Nakryiko , Jinjie Ruan , Nam Cao , workflows@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-mm@kvack.org, llvm@lists.linux.dev, Andrey Ryabinin , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , kasan-dev@googlegroups.com, "David S. Miller" , Mathieu Desnoyers , linux-trace-kernel@vger.kernel.org Subject: Re: [PATCH v5 17/23] mm/ksw: add test module Message-ID: References: <20250924115124.194940-1-wangjinchao600@gmail.com> <20250924115931.197077-1-wangjinchao600@gmail.com> <20250924115931.197077-2-wangjinchao600@gmail.com> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Wed, Sep 24, 2025 at 10:44:50PM +0200, Marco Elver wrote: > On Wed, 24 Sept 2025 at 14:00, Jinchao Wang wrote: > > > > Introduce a separate test module to validate functionality in controlled > > scenarios. > > > > The module provides a proc interface (/proc/kstackwatch_test) that allows > > triggering specific test cases via simple commands: > > > > echo test0 > /proc/kstackwatch_test > > This should not be in /proc/ - if anything, it should go into debugfs. Thanks, will fix in next version. > > > Test module is built with optimizations disabled to ensure predictable > > behavior. > > > > Signed-off-by: Jinchao Wang > > --- > > mm/Kconfig.debug | 10 ++++ > > mm/kstackwatch/Makefile | 6 ++ > > mm/kstackwatch/test.c | 122 ++++++++++++++++++++++++++++++++++++++++ > > 3 files changed, 138 insertions(+) > > create mode 100644 mm/kstackwatch/test.c > > > > diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug > > index 89be351c0be5..291dd8a78b98 100644 > > --- a/mm/Kconfig.debug > > +++ b/mm/Kconfig.debug > > @@ -317,3 +317,13 @@ config KSTACK_WATCH > > A lightweight real-time debugging tool to detect stack corrupting. > > > > If unsure, say N. > > + > > +config KSTACK_WATCH_TEST > > + tristate "KStackWatch Test Module" > > + depends on KSTACK_WATCH > > + help > > + This module provides controlled stack corruption scenarios to verify > > + the functionality of KStackWatch. It is useful for development and > > + validation of KStackWatch mechanism. > > + > > + If unsure, say N. > > diff --git a/mm/kstackwatch/Makefile b/mm/kstackwatch/Makefile > > index 84a46cb9a766..d007b8dcd1c6 100644 > > --- a/mm/kstackwatch/Makefile > > +++ b/mm/kstackwatch/Makefile > > @@ -1,2 +1,8 @@ > > obj-$(CONFIG_KSTACK_WATCH) += kstackwatch.o > > kstackwatch-y := kernel.o stack.o watch.o > > + > > +obj-$(CONFIG_KSTACK_WATCH_TEST) += kstackwatch_test.o > > +kstackwatch_test-y := test.o > > +CFLAGS_test.o := -fno-inline \ > > + -fno-optimize-sibling-calls \ > > + -fno-pic -fno-pie -O0 -Og > > diff --git a/mm/kstackwatch/test.c b/mm/kstackwatch/test.c > > new file mode 100644 > > index 000000000000..1ed98931cc51 > > --- /dev/null > > +++ b/mm/kstackwatch/test.c > > @@ -0,0 +1,122 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#include "kstackwatch.h" > > + > > +static struct proc_dir_entry *test_proc; > > + > > +#define BUFFER_SIZE 16 > > +#define MAX_DEPTH 6 > > + > > +struct work_node { > > + ulong *ptr; > > + struct completion done; > > + struct list_head list; > > +}; > > + > > +static DECLARE_COMPLETION(work_res); > > +static DEFINE_MUTEX(work_mutex); > > +static LIST_HEAD(work_list); > > + > > +static void test_watch_fire(void) > > +{ > > + u64 buffer[BUFFER_SIZE] = { 0 }; > > + > > + pr_info("entry of %s\n", __func__); > > + ksw_watch_show(); > > + ksw_watch_fire(); > > + pr_info("buf[0]:%lld\n", buffer[0]); > > + > > + barrier_data(buffer); > > + pr_info("exit of %s\n", __func__); > > +} > > + > > + > > +static ssize_t test_proc_write(struct file *file, const char __user *buffer, > > + size_t count, loff_t *pos) > > +{ > > + char cmd[256]; > > + int test_num; > > + > > + if (count >= sizeof(cmd)) > > + return -EINVAL; > > + > > + if (copy_from_user(cmd, buffer, count)) > > + return -EFAULT; > > + > > + cmd[count] = '\0'; > > + strim(cmd); > > + > > + pr_info("received command: %s\n", cmd); > > + > > + if (sscanf(cmd, "test%d", &test_num) == 1) { > > + switch (test_num) { > > + case 0: > > + test_watch_fire(); > > + break; > > + default: > > + pr_err("Unknown test number %d\n", test_num); > > + return -EINVAL; > > + } > > + } else { > > + pr_err("invalid command format. Use 'testN'.\n"); > > + return -EINVAL; > > + } > > + > > + return count; > > +} > > + > > +static ssize_t test_proc_read(struct file *file, char __user *buffer, > > + size_t count, loff_t *pos) > > +{ > > + static const char usage[] = "KStackWatch Simplified Test Module\n" > > + "============ usage ==============\n" > > + "Usage:\n" > > + "echo test{i} > /proc/kstackwatch_test\n" > > + " test0 - test watch fire\n"; > > + > > + return simple_read_from_buffer(buffer, count, pos, usage, > > + strlen(usage)); > > +} > > + > > +static const struct proc_ops test_proc_ops = { > > + .proc_read = test_proc_read, > > + .proc_write = test_proc_write, > > +}; > > + > > +static int __init kstackwatch_test_init(void) > > +{ > > + test_proc = proc_create("kstackwatch_test", 0600, NULL, &test_proc_ops); > > + if (!test_proc) { > > + pr_err("Failed to create proc entry\n"); > > + return -ENOMEM; > > + } > > + pr_info("module loaded\n"); > > + return 0; > > +} > > + > > +static void __exit kstackwatch_test_exit(void) > > +{ > > + if (test_proc) > > + remove_proc_entry("kstackwatch_test", NULL); > > + pr_info("module unloaded\n"); > > +} > > + > > +module_init(kstackwatch_test_init); > > +module_exit(kstackwatch_test_exit); > > + > > +MODULE_AUTHOR("Jinchao Wang"); > > +MODULE_DESCRIPTION("Simple KStackWatch Test Module"); > > +MODULE_LICENSE("GPL"); > > -- > > 2.43.0 > > > > -- > > You received this message because you are subscribed to the Google Groups "kasan-dev" group. > > To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com. > > To view this discussion visit https://groups.google.com/d/msgid/kasan-dev/20250924115931.197077-2-wangjinchao600%40gmail.com. -- Jinchao