From patchwork Fri Sep 6 12:09:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Tang X-Patchwork-Id: 1981844 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=SrkJxtGM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=66qd=qe=vger.kernel.org=sparclinux+bounces-2207-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X0ZmC16HDz1y1H for ; Fri, 6 Sep 2024 22:09:46 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4X0ZmB5VbBz4wnw for ; Fri, 6 Sep 2024 22:09:46 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4X0ZmB5NgHz4wyh; Fri, 6 Sep 2024 22:09:46 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip=139.178.88.99 arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1725624586; cv=pass; b=ZphK5+1/0FNU86m2IE3NxNi9N8qawbKR6Sgj7qCWPHUiHkaCchId4uJ4d9zXjbwBbwONgDZ7nfGfingH9QQhKcrSERFJO14EnxMZUaShUnCqdQVMjo+dgemfAIcgd0W4XY1md4U7aXiiVRSDDo1NXDxtgOTY9VTU2K+nIvEbKFhsLTWL1C+yWnQbX9/rUhstIhL6kUmBceDT4IsBR9vza2gfDJMex8vmEx+MtYmSDeN4jjk4O8Ci9b+WM76pezRRFuEGQqhCXlIf2KVdXr5c/gG3DPDe0jg6vxIqCzP+AQtDpaqhqNOXRn/66O23zxW9I+nPTQO5TMKcDnjN112LUQ== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1725624586; c=relaxed/relaxed; bh=yT83MQLV5isHTT00xmNespubN4HB8sHhBvbGj/e7WEM=; h=ARC-Authentication-Results:DKIM-Signature:From:To:Cc:Subject:Date: Message-Id:MIME-Version; b=UTD1H8qNBcx8zn5/5TXAgx40v6r1hKFT5tOY7JUZUQ5SYNL/4GId+i+Qk99qUV/rpzT6+zpmsKyAOt4Gty1XhNVWm0qcO8FYCUTbR6TDQ2Y+ManqLhDL9U3vZI2aKQ+yOTrmkps09PxU6SWqplj2vTsGi8KWbSg9eEKT62nTVkKlG6p1hWVa0WJJ1GhERU9cO8orTr93mrx/asWENYSQGZkab1jRGZHI+hfsxi4/eUvyj/0LFO2uoCGiT3rfgrUxLXG0Z/KqAIEXeCfwjvjljpEIlSOCWvskq7bYa+4npNFE+j6AD01jQu4YKXVK3hhEbEvcAjiEq9LJlG8KGoPz+Q== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=intel.com; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=SrkJxtGM; dkim-atps=neutral; spf=pass (client-ip=139.178.88.99; helo=sv.mirrors.kernel.org; envelope-from=sparclinux+bounces-2207-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=SrkJxtGM; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=139.178.88.99; helo=sv.mirrors.kernel.org; envelope-from=sparclinux+bounces-2207-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [139.178.88.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4X0Zm91Q0Sz4wnw for ; Fri, 6 Sep 2024 22:09:45 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id EE9312869C0 for ; Fri, 6 Sep 2024 12:09:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E4641CBEBF; Fri, 6 Sep 2024 12:09:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="SrkJxtGM" X-Original-To: sparclinux@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C97B21CB31D; Fri, 6 Sep 2024 12:09:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725624580; cv=none; b=Kvo5mH0cMGizng3TfmMapE1RH2+f7RGRKPW9nUBZkQWE8M3YcpwtFgCf9+dUwojiyvXCQoDj3obdZ0Dab3qy81AfMQEea9nNxK4BohC/W7OYSVgm2szhCiAWmgfvXefwqoGFC0hLcZI/ND4HgxfSd/nnkzK2Pc7uwgHRvlXCCXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725624580; c=relaxed/simple; bh=5p+4Bl9mqbxouOtptcDfPPmou1wvxYkLSmiClXxVh3c=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=lCfacO7Fbo2HvNMsbrZxMBZWDZhhnBiheSzlRJWAAEa46uqs77XTsy7xMSm0oFnMUa4ylVkrCHsLiLwUoLg5wZh8HDmydi8y59VvYAILgNJzWN7fDS19gpJjdp9SwL7jgzHFbZrwfPa7ZoHSI7SynO37ElmqfGTMu/P2iLiJxDQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=SrkJxtGM; arc=none smtp.client-ip=198.175.65.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725624578; x=1757160578; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=5p+4Bl9mqbxouOtptcDfPPmou1wvxYkLSmiClXxVh3c=; b=SrkJxtGMHPJiX/RwVQt1DklGBHaJAIo8/yuvjl6J9smHuUb+FFRLDV+m SieNzKCj2vScjQ2+aQJtyB46He7Vb0VYUzA17/JX54ogQj4/aCF5KwhMa 63+n4cquFujAImLUp7ctxLVyLlTrNYmqA+rhPlRXBa0q2Zamr17WDDEwO jtHDCmmZawa6vyyKfeXOFaZnqJj2uv0d4bUd9hbjhKhWc+3r9Qrho8IbW G7+Tn2mRfqqgYZTzvGozgb/usnPAYpFkjxMwWsXD/MN3ypPjY5rFg/fMM GvqcCIzZ8HJdvudLj+rGwEG/HxxoI+c5f2Md3cOFCke+coagG1mhncYYf g==; X-CSE-ConnectionGUID: djVm1GvPTJ2W5AHWRNbOHQ== X-CSE-MsgGUID: 12BQj/ELR1Cd1xsskltAYw== X-IronPort-AV: E=McAfee;i="6700,10204,11187"; a="24535761" X-IronPort-AV: E=Sophos;i="6.10,207,1719903600"; d="scan'208";a="24535761" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2024 05:09:38 -0700 X-CSE-ConnectionGUID: HprW+X66SaqXRjfUb/ltHQ== X-CSE-MsgGUID: mTrxtkOGSAKpg0n5x8l8qA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,207,1719903600"; d="scan'208";a="70734766" Received: from feng-clx.sh.intel.com ([10.239.159.50]) by orviesa005.jf.intel.com with ESMTP; 06 Sep 2024 05:09:34 -0700 From: Feng Tang To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , rostedt@goodmis.org, linux-kernel@vger.kernel.org, Andrew Morton , Vlastimil Babka , sparclinux@vger.kernel.org, John Paul Adrian Glaubitz Cc: Feng Tang Subject: [PATCH v3] sched/debug: Dump end of stack when detected corrupted Date: Fri, 6 Sep 2024 20:09:33 +0800 Message-Id: <20240906120933.2176727-1-feng.tang@intel.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: sparclinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When debugging a kernel hang during suspend/resume [1], there were random memory corruptions in different places like being reported by slub_debug+KASAN, or detected by scheduler with error message: "Kernel panic - not syncing: corrupted stack end detected inside scheduler" So dump the corrupted memory around the stack end to give more direct hints about how the memory is corrupted: " Corrupted Stack: ff11000122770000: ff ff ff ff ff ff 14 91 82 3b 78 e8 08 00 45 00 .........;x...E. Corrupted Stack: ff11000122770010: 00 1d 2a ff 40 00 40 11 98 c8 0a ef 30 2c 0a ef ..*.@.@.....0,.. Corrupted Stack: ff11000122770020: 30 ff a2 00 22 3d 00 09 9a 95 2a 00 00 00 00 00 0..."=....*..... ... Kernel panic - not syncing: corrupted stack end detected inside scheduler " And with it, the culprit was quickly identified to be ethernet driver that it frees RX related memory back to kernel in suspend hook, but its HW is not really stopped, and still send RX data to those old buffer through DMA. [1]. https://bugzilla.kernel.org/show_bug.cgi?id=217854 Signed-off-by: Feng Tang Reviewed-by: John Paul Adrian Glaubitz --- Changlog: since v2: * Change code format (Adrian) * Add Reviewed tag from Adrian since v1: * Refine the commit log with more info, and rebase againt 6.8-rc3 kernel/sched/core.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index f3951e4a55e5..0c5cc3bdc02b 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5741,8 +5741,19 @@ static noinline void __schedule_bug(struct task_struct *prev) static inline void schedule_debug(struct task_struct *prev, bool preempt) { #ifdef CONFIG_SCHED_STACK_END_CHECK - if (task_stack_end_corrupted(prev)) + if (task_stack_end_corrupted(prev)) { + unsigned long *ptr = end_of_stack(prev); + + /* Dump 16 ulong words around the corruption point */ +#ifdef CONFIG_STACK_GROWSUP + ptr -= 15; +#endif + print_hex_dump(KERN_ERR, "Corrupted Stack: ", + DUMP_PREFIX_ADDRESS, 16, 1, ptr, + 16 * sizeof(unsigned long), true); + panic("corrupted stack end detected inside scheduler\n"); + } if (task_scs_end_corrupted(prev)) panic("corrupted shadow stack detected inside scheduler\n");