From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 4EA7B2701D8 for ; Mon, 10 Nov 2025 16:38:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762792717; cv=none; b=azew5Gi+ghUWWMFaEmVk3ER3M83WaZ6fsKPQEdiofgVaJsbUf2n4KIrGPpDTxHmY71/MseZey1KfP0zTjKqX/dPIAEC4wcjL8Q3tKENWlc5ymk+70GoQl9/GVY3f+ZW/Rkoubcg0DJYEqeXQiMZqRGsrGwoDwCL4TSfQ5kDvq2U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762792717; c=relaxed/simple; bh=7XtXQ97oCD17IPK7+NK1Mw0M3hjSZXH8IzRrWjOBBJQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tZN+u9MiAAy1xD8uXmcrmsn2e/VBZX/xdyYvntLFs0+o7tAvXdelT74RKzzx4tKyLfplaYocbBaMmGEIfCTMCNPlCT+lqvuqE+80XBaqlVc309Tn3SBeNMiv5Np7ujK+glBPJvlEjc3UhGl1xQzOvj8fFEJ/jxm+78hYM+YDUuM= 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=MtfYJ9ms; arc=none smtp.client-ip=209.85.214.172 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="MtfYJ9ms" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2981f9ce15cso12868275ad.1 for ; Mon, 10 Nov 2025 08:38:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762792714; x=1763397514; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Y3GxOA64nlDPTJib953n4vjoIghnHFGUI3myXADNt+s=; b=MtfYJ9msGxlKiKt2vwibjYrQn9Q7Iem3xQxfw94Y0bjSQQZ2Tpw5CtlvU3vBcRGcDz I+V8r12hwuTjXcrfUHsvDA+j6oUMIcenhVGuzgG7sNYKdMMpMiC8dn9pBqP+NTzxW2cD tuOcqo+wHJlruQ8duXqcZRMidpt1Iy47PSWDEsHUne/izqMhkWNpxv6HrucgufSSApSn 2tuJo2mhUIWceRaWxWTQ175ix0wFd+3gy70Y7Ztz0aMqkupWRn7I7e3kag5ftI/v/hkU wVxuy8Gp6dtov2GwQ1q4ovvEYAwcemIGcFjq/CMkusCJM7sZmJeYstkefeJIpbflcYJL +ERg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762792714; x=1763397514; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Y3GxOA64nlDPTJib953n4vjoIghnHFGUI3myXADNt+s=; b=S9ymbXvNmLBsUp9V7JdcYLRMVybYV02SWmoGcHZ8Xr8MQE4DEyWuJFKcURruLbDdox euTEUcv3OqTN6laB4rfqbwjqZR6tbaAnf4McdfZvXJfvHyPBj7MXikQpKxcdvoLLTGFV ycPu09beyJXwkRLdjpk8mYy3LMkodmm0SwMMJsoIzWnXBAEHCcPOMCj4taF0lS7+5gH8 cBbT7KezqRLRA3W3DifoZWgLmOXctTIIvDVNqWjF5zVNYqrme/OfMw6BoXz2V3GvhlZV vMyAUtp4fNpHfYhvntGHArIVJRUMHr2hFY9cKLl9Xze8vAjJcxc90ovcbvoS8WglOAC1 xy4g== X-Forwarded-Encrypted: i=1; AJvYcCWJovzc27ev6fwjf8vc0ubm7JBAcUuu7oPZ6Nlr7HA7BsaiS+QNw/miolA/b0BCAQRylsR7391dJeg=@vger.kernel.org X-Gm-Message-State: AOJu0YxhON2fNzMW1TNSQRnDPq1YEQhYwYk2J6ywusce4cAczE2zMjgc fQ/eFX61HpvtnXIlK71I3XyuhPxl5yGdo4ZqCNqUVzk9QuU6/X5nDiOP X-Gm-Gg: ASbGncsUfRprIQ3Gw+dkCiUya1UVAacEH8BrLJwGIx6lbMXB/JrSijoIl3hg3fsC96h CvIlJr9jsP15LOImX46xqJGXDEkm4j6XW3s8T+vTGwrCNOsfVix22Cl5IyrdjmuICdr11+9/0K/ cnkhR3408PrKa9VkJm58UTwGntt+JQGpKwZ4FcJWMrZcKdfbV56dXdYew5VdEzMkkeYiNn/vMYT gh8wdOPhoEi2YslZ7fE2KqKP359gnx3XVyVCDprVgUOaGeIdtYSm0eCFKdaeYwyCiptO2J6jsTX oA0df069mnEQNikm0EfGzo4GD33CV55R+9h98R+pPNutJPSGfu1JSn6L3XkDsxgO/q6qGtqvTwV ZGmoDyZg2/gGOf0fe3p5hJYh4SdwZDthejag5VcUbXwl8lGoPrb57EfQJK1eH2hFNhGRnRNzHzr EaeahqaE508ifL/eL7uzdynQ== X-Google-Smtp-Source: AGHT+IHJX8e0VatXnyxoY2Gj4pP23au6Z6EmKSnmcplOP/Vs7kpe6TtUClUvAMyMHtho7bQMYRxkQg== X-Received: by 2002:a17:902:da4b:b0:295:fc0:5a32 with SMTP id d9443c01a7336-297e53e7aa7mr114885545ad.3.1762792714416; Mon, 10 Nov 2025 08:38:34 -0800 (PST) Received: from localhost ([103.88.46.62]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2980c51b8c9sm52389295ad.47.2025.11.10.08.38.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Nov 2025 08:38:33 -0800 (PST) From: Jinchao Wang To: Andrew Morton , "Masami Hiramatsu (Google)" , Peter Zijlstra , Randy Dunlap , Marco Elver , Mike Rapoport , Alexander Potapenko , Adrian Hunter , Alexander Shishkin , Alice Ryhl , Andrey Konovalov , Andrey Ryabinin , Andrii Nakryiko , Ard Biesheuvel , Arnaldo Carvalho de Melo , Ben Segall , Bill Wendling , Borislav Petkov , Catalin Marinas , Dave Hansen , David Hildenbrand , David Kaplan , "David S. Miller" , Dietmar Eggemann , Dmitry Vyukov , "H. Peter Anvin" , Ian Rogers , Ingo Molnar , James Clark , Jinchao Wang , Jinjie Ruan , Jiri Olsa , Jonathan Corbet , Juri Lelli , Justin Stitt , kasan-dev@googlegroups.com, Kees Cook , "Liam R. Howlett" , "Liang Kan" , Linus Walleij , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-perf-users@vger.kernel.org, linux-trace-kernel@vger.kernel.org, llvm@lists.linux.dev, Lorenzo Stoakes , Mark Rutland , Masahiro Yamada , Mathieu Desnoyers , Mel Gorman , Michal Hocko , Miguel Ojeda , Nam Cao , Namhyung Kim , Nathan Chancellor , Naveen N Rao , Nick Desaulniers , Rong Xu , Sami Tolvanen , Steven Rostedt , Suren Baghdasaryan , Thomas Gleixner , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Valentin Schneider , Vincent Guittot , Vincenzo Frascino , Vlastimil Babka , Will Deacon , workflows@vger.kernel.org, x86@kernel.org Subject: [PATCH v8 25/27] tools/ksw: add arch-specific test script Date: Tue, 11 Nov 2025 00:36:20 +0800 Message-ID: <20251110163634.3686676-26-wangjinchao600@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251110163634.3686676-1-wangjinchao600@gmail.com> References: <20251110163634.3686676-1-wangjinchao600@gmail.com> Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add a shell script under tools/kstackwatch to run self-tests such as canary overflow and recursive depth. The script supports both x86_64 and arm64, selecting parameters automatically based on uname -m. Signed-off-by: Jinchao Wang --- tools/kstackwatch/kstackwatch_test.sh | 85 +++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 tools/kstackwatch/kstackwatch_test.sh diff --git a/tools/kstackwatch/kstackwatch_test.sh b/tools/kstackwatch/kstackwatch_test.sh new file mode 100755 index 000000000000..6e83397d3213 --- /dev/null +++ b/tools/kstackwatch/kstackwatch_test.sh @@ -0,0 +1,85 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +echo "IMPORTANT: Before running, make sure you have updated the config values!" + +usage() { + echo "Usage: $0 [0-5]" + echo " 0 - test watch fire" + echo " 1 - test canary overflow" + echo " 2 - test recursive depth" + echo " 3 - test silent corruption" + echo " 4 - test multi-threaded silent corruption" + echo " 5 - test multi-threaded overflow" +} + +run_test_x86_64() { + local test_num=$1 + case "$test_num" in + 0) echo fn=test_watch_fire fo=0x29 ac=1 >/sys/kernel/debug/kstackwatch/config + echo test0 > /sys/kernel/debug/kstackwatch/test + ;; + 1) echo fn=test_canary_overflow fo=0x14 >/sys/kernel/debug/kstackwatch/config + echo test1 >/sys/kernel/debug/kstackwatch/test + ;; + 2) echo fn=test_recursive_depth fo=0x2f dp=3 wl=8 so=0 >/sys/kernel/debug/kstackwatch/config + echo test2 >/sys/kernel/debug/kstackwatch/test + ;; + 3) echo fn=test_mthread_victim fo=0x4c so=64 wl=8 >/sys/kernel/debug/kstackwatch/config + echo test3 >/sys/kernel/debug/kstackwatch/test + ;; + 4) echo fn=test_mthread_victim fo=0x4c so=64 wl=8 >/sys/kernel/debug/kstackwatch/config + echo test4 >/sys/kernel/debug/kstackwatch/test + ;; + 5) echo fn=test_mthread_buggy fo=0x16 so=0x100 wl=8 >/sys/kernel/debug/kstackwatch/config + echo test5 >/sys/kernel/debug/kstackwatch/test + ;; + *) usage + exit 1 ;; + esac + # Reset watch after test + echo >/sys/kernel/debug/kstackwatch/config +} + +run_test_arm64() { + local test_num=$1 + case "$test_num" in + 0) echo fn=test_watch_fire fo=0x50 ac=1 >/sys/kernel/debug/kstackwatch/config + echo test0 > /sys/kernel/debug/kstackwatch/test + ;; + 1) echo fn=test_canary_overflow fo=0x20 so=264 >/sys/kernel/debug/kstackwatch/config + echo test1 >/sys/kernel/debug/kstackwatch/test + ;; + 2) echo fn=test_recursive_depth fo=0x34 dp=3 wl=8 so=8 >/sys/kernel/debug/kstackwatch/config + echo test2 >/sys/kernel/debug/kstackwatch/test + ;; + 3) echo fn=test_mthread_victim fo=0x6c so=0x48 wl=8 >/sys/kernel/debug/kstackwatch/config + echo test3 >/sys/kernel/debug/kstackwatch/test + ;; + 4) echo fn=test_mthread_victim fo=0x6c so=0x48 wl=8 >/sys/kernel/debug/kstackwatch/config + echo test4 >/sys/kernel/debug/kstackwatch/test + ;; + 5) echo fn=test_mthread_buggy fo=0x20 so=264 >/sys/kernel/debug/kstackwatch/config + echo test5 >/sys/kernel/debug/kstackwatch/test + ;; + *) usage + exit 1 ;; + esac + # Reset watch after test + echo >/sys/kernel/debug/kstackwatch/config +} + +# Check root and module +[ "$EUID" -ne 0 ] && echo "Run as root" && exit 1 +for f in /sys/kernel/debug/kstackwatch/config /sys/kernel/debug/kstackwatch/test; do + [ ! -f "$f" ] && echo "$f not found" && exit 1 +done + +# Run +[ -z "$1" ] && { usage; exit 0; } + +arch=$(uname -m) +case "$arch" in + x86_64|aarch64) run_test_${arch} "$1" ;; + *) echo "Unsupported architecture: $arch" && exit 1 ;; +esac -- 2.43.0