From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 4EBE0240611 for ; Fri, 10 Oct 2025 07:58:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760083093; cv=none; b=UosVZdKa4JJ1CCPy2qYZhEZ0us/G5KKtlLOnqUH2GOR2068w8kamfZ4z+ibrDGtGxmqwPKfvrBdCrN/fPOa7HOx1RLJq2RZtfsud3D36e/ctKp98+BQP6GDOGtAc4Y8LFRSpIxEnvurG1Jw/O/qvauFHNElNGoFIUenFkyI0iHc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760083093; c=relaxed/simple; bh=/EqQHNRDCS2YqzBq0RkItK1pvs5vi0KLmvOMTFqnmTo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fzL+xLt/tl8sT9UAo9VBAl4K2jKWoXdVgWbOT1itYUxCA96Zkn5xX+UP0ptzEwGepPhSf1aTUaZc/qRrZ2HtlEHJEwjecPFT+BGdGH9+0FZMvv2eOmY54p2IM94Tib97IegAaPDdJjyu/WoVJaoF4FyYVmsUcEsRPiTO/ShWDIg= 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=LnpTac5Z; arc=none smtp.client-ip=209.85.214.170 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="LnpTac5Z" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-28e8c5d64d8so16987575ad.1 for ; Fri, 10 Oct 2025 00:58:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1760083091; x=1760687891; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=2Nucw4E7LkwzxjCbFb3F737DKijbeBN9zMwZ0PDOoZQ=; b=LnpTac5ZvTS/UYEVB7W5KdB+cWLKdYtewYzALu7433gOuYAcGX1oFy0Q19ip8xcFCa VPvqP8SCUx+/XjNgHL8vB33TujuA0mC2YoXnFFaGf/K6hmYJQSStvsPkmYHDHvwWGBB9 H25tihr2gvHnD9+QUe7VqDsb4j4ikRlvsXp8WF71t3vbG8l1ehFojIQi9pYHpBP7W6/A vqU5elROKHmEcCx+LOrpJDHvz4jqYqj6ZObpvjQ2rw6SyAsHiWwVY1K5mSEmwywqFgpO xN/78d3SCni1185cDyOSCn+FmZXFwCwbuKfofh82uNWMtcsHZ4vfgd8JPfiDTxs1PC8C 1iDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760083091; x=1760687891; h=in-reply-to:content-transfer-encoding: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=2Nucw4E7LkwzxjCbFb3F737DKijbeBN9zMwZ0PDOoZQ=; b=XD25VdiRVaGOUCCslDY0q1h5gya04UYujrIJPFF4ZGNuYHDoHVJdEPlgDrvL55/SxV Uy3oc6EawbO0M9mkpeLNmbg6DSeKcKQH2MjW8U8uDU/koLmYooEEco3nBihUrHnhxmOY ZZIi6ldcTDQ9xbdTq5lgdjwuFZM10dZVVIKJOTXCytk2/IoMMhFbbruhlCoqJDK/Qpeh 0ZipIo6d+P4Ti/6GchP7J97lzydt6geX0lQbVWNChNNP33/NVlbzt8IjXhtV0bH2y3IW hRgB/ozlci1iigVCxqEBnCz+oYKsfzCAzaaWoNJNhDpmWEZ0RjyEH5lWIlBImjX9Vst3 9pEQ== X-Forwarded-Encrypted: i=1; AJvYcCW0JMoSdDh/Ykn3mbkYjU5tbr1hF4bekYNI9KqR+O9GfV9ujJfxoRd/Yj46Mztgz8c1YZsn5ALleSU=@vger.kernel.org X-Gm-Message-State: AOJu0YwAVQnEM9WQK22xMPPJ0x4efe1AqGshtrZdKfXGnJKxRzSrgYvF H21/mqcMsz2rppybsfbGIvngvZCU39y/dEfWcbUEmb2fZnd1RXmfRAAB X-Gm-Gg: ASbGncvuUghMpt3YWBFEsSVdkizly7w5AwuszE99WJMcMcuwemIs1d2IlVXh0a1eoWK TZ02OoYpGqCXC60f2kJinWFaWY4CzVuY1RadBb5DV6c+0vUm6uG3bC6UrWIfhIq42e1AXSMZJf6 kzA8SZkoBId3kEnqu1c+nC+cvmmpIPa/LDYNm3SwFgJoOBhBXJmQZYYYxcKhJDXsZQmDBDQHzVf SMG3e3xkPHKne/1kiCByhRmaOCdZWrbwFF8EOKZdks3ABTFl0mSp33zntwDw+B4QkEj20rrdY+5 p3TzssTve7b9Qxr+SgTw0rAC8tgeLJxDPNtQEmV5CRXWqYNQ6nwmgsBLiaQDBw4wHzCzBOO9Ckd iGvhPxduTWkHBVnFJqJsysNTY70z1P4hZUHm7keaYME8/4R13+ui3AeVdo1AlBRxfN58= X-Google-Smtp-Source: AGHT+IFeywA6gB4/SQbmJGvT2KY5YTMhXWywBtcaIqaAsauF4r7EzLqcGRXLsSas3aRqscvIRrL6Qg== X-Received: by 2002:a17:903:298e:b0:28e:756c:7082 with SMTP id d9443c01a7336-29027374b38mr134966335ad.15.1760083090502; Fri, 10 Oct 2025 00:58:10 -0700 (PDT) Received: from localhost ([103.121.208.62]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29034f070ecsm49587725ad.60.2025.10.10.00.58.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Oct 2025 00:58:09 -0700 (PDT) Date: Fri, 10 Oct 2025 15:58:03 +0800 From: Jinchao Wang To: Andrew Morton Cc: Masami Hiramatsu , Peter Zijlstra , Mike Rapoport , Alexander Potapenko , Randy Dunlap , Marco Elver , 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 v7 00/23] mm/ksw: Introduce real-time KStackWatch debugging tool Message-ID: References: <20251009105650.168917-1-wangjinchao600@gmail.com> <20251009175107.ee07228e3253afca5b487316@linux-foundation.org> Precedence: bulk X-Mailing-List: workflows@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20251009175107.ee07228e3253afca5b487316@linux-foundation.org> On Thu, Oct 09, 2025 at 05:51:07PM -0700, Andrew Morton wrote: > On Thu, 9 Oct 2025 18:55:36 +0800 Jinchao Wang wrote: > > > This patch series introduces KStackWatch, a lightweight debugging tool to detect > > kernel stack corruption in real time. It installs a hardware breakpoint > > (watchpoint) at a function's specified offset using `kprobe.post_handler` and > > removes it in `fprobe.exit_handler`. This covers the full execution window and > > reports corruption immediately with time, location, and a call stack. > > > > The motivation comes from scenarios where corruption occurs silently in one > > function but manifests later in another, without a direct call trace linking > > the two. Such bugs are often extremely hard to debug with existing tools. > > These scenarios are demonstrated in test 3–5 (silent corruption test, patch 20). > > > > ... > > > > 20 files changed, 1809 insertions(+), 62 deletions(-) > > It's obviously a substantial project. We need to decide whether to add > this to Linux. > > There are some really important [0/N] changelog details which I'm not > immediately seeing: Thanks for the review and questions. > > Am I correct in thinking that it's x86-only? If so, what's involved in > enabling other architectures? Is there any such work in progress? Currently yes. There are two architecture-specific dependencies: - Hardware breakpoint (HWPB) modification in atomic context. This has been implemented for x86 in patches 1–3. I think it is not a big problem for other architectures. - Stack canary locating mechanism, which does not work on parisc: - Automatic canary discovery scans from the stack base to high memory. - This feature is optional; a stack offset address can be provided instead. Future work could include enabling support for other architectures such as arm64 and riscv once their hardware breakpoint implementations allow safe modification in atomic context. I do not currently have the environment to test those architectures, but the framework was designed to be generic and can be extended by contributors familiar with them. > What motivated the work? Was there some particular class of failures > which you were persistently seeing and wished to fix more efficiently? > > Has this code (or something like it) been used in production systems? > If so, by whom and with what results? The motivation came from silent stack corruption issues. They occur rarely but are extremely difficult to debug. I personally encountered two such bugs which each took weeks to isolate, and I know similar issues exist in other environments. KStackWatch was developed as a result of those debugging efforts. It has been used mainly in my own debugging environment and verified with controlled test cases (patches 17–21). If it had existed earlier, similar bugs could have been resolved much faster. > > Has it actually found some kernel bugs yet? If so, details please. It was designed to help diagnose bugs whose existence was already known but whose root cause was difficult to locate. So far it has been used in my personal environment and can be validated with controlled test cases in patches 17–21. > > Can this be enabled on production systems? If so, what is the > measured runtime overhead? I believe it can. The overhead is summarized below. Without watching: - Per-task context: 2 * sizeof(ulong) + 4 bytes (≈20 bytes on x86_64) With watching: - Same per-task context as above - One or more preallocated HWBPs (configurable, at least one) - Small additional memory for managing HWBP and context state - Runtime overhead (measured on x86_64): Type | Time (ns) | Cycles ----------------------------------------------- entry with watch | 10892 | 32620 entry without watch | 159 | 466 exit with watch | 12541 | 37556 exit without watch | 124 | 369 Would you prefer that I include the measurement code (used to collect the timing and cycle statistics shown above) in the next version of the patch set, or submit it separately as an additional patch? -- Jinchao