From nobody Sat Apr 11 02:19:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1F7AC25B08 for ; Wed, 17 Aug 2022 07:45:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233346AbiHQHpg (ORCPT ); Wed, 17 Aug 2022 03:45:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233218AbiHQHpa (ORCPT ); Wed, 17 Aug 2022 03:45:30 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F31F779A55 for ; Wed, 17 Aug 2022 00:45:29 -0700 (PDT) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4M70PJ2YSKzhZ28; Wed, 17 Aug 2022 15:43:16 +0800 (CST) Received: from CHINA (10.175.102.38) by canpemm500009.china.huawei.com (7.192.105.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 17 Aug 2022 15:45:27 +0800 From: Wei Yongjun To: Akinobu Mita , Andrew Morton , Nathan Chancellor , Peter Zijlstra , Kees Cook , Nick Desaulniers , Josh Poimboeuf , Dan Williams , Miguel Ojeda , Isabella Basso , Vlastimil Babka , Rasmus Villemoes CC: Wei Yongjun , Subject: [PATCH 1/4 -next] fault-injection: allow stacktrace filter for x86-64 Date: Wed, 17 Aug 2022 08:03:29 +0000 Message-ID: <20220817080332.1052710-2-weiyongjun1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220817080332.1052710-1-weiyongjun1@huawei.com> References: <20220817080332.1052710-1-weiyongjun1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.102.38] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" FAULT_INJECTION_STACKTRACE_FILTER option was apparently disallowed on x86_64 because of problems with the stack unwinder: commit 6d690dcac92a84f98fd774862628ff871b713660 Author: Akinobu Mita Date: Sat May 12 10:36:53 2007 -0700 fault injection: disable stacktrace filter for x86-64 However, there is no problems whatsoever with this today. Let's allow it again. Signed-off-by: Wei Yongjun --- lib/Kconfig.debug | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 38d259b1d262..c6795f4656d7 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1944,7 +1944,6 @@ config FAIL_SUNRPC config FAULT_INJECTION_STACKTRACE_FILTER bool "stacktrace filter for fault-injection capabilities" depends on FAULT_INJECTION_DEBUG_FS && STACKTRACE_SUPPORT - depends on !X86_64 select STACKTRACE depends on FRAME_POINTER || MIPS || PPC || S390 || MICROBLAZE || ARM || A= RC || X86 help --=20 2.34.1 From nobody Sat Apr 11 02:19:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEF92C25B08 for ; Wed, 17 Aug 2022 07:45:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233417AbiHQHpk (ORCPT ); Wed, 17 Aug 2022 03:45:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233237AbiHQHpb (ORCPT ); Wed, 17 Aug 2022 03:45:31 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9144979EE2 for ; Wed, 17 Aug 2022 00:45:30 -0700 (PDT) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4M70M06Rz8zXdn9; Wed, 17 Aug 2022 15:41:16 +0800 (CST) Received: from CHINA (10.175.102.38) by canpemm500009.china.huawei.com (7.192.105.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 17 Aug 2022 15:45:28 +0800 From: Wei Yongjun To: Akinobu Mita , Andrew Morton , Nathan Chancellor , Peter Zijlstra , Kees Cook , Nick Desaulniers , Josh Poimboeuf , Dan Williams , Miguel Ojeda , Isabella Basso , Vlastimil Babka , Rasmus Villemoes CC: Wei Yongjun , Subject: [PATCH 2/4 -next] fault-injection: skip stacktrace filtering by default Date: Wed, 17 Aug 2022 08:03:30 +0000 Message-ID: <20220817080332.1052710-3-weiyongjun1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220817080332.1052710-1-weiyongjun1@huawei.com> References: <20220817080332.1052710-1-weiyongjun1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.102.38] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If FAULT_INJECTION_STACKTRACE_FILTER is enabled, the depth is default to 32. This means fail_stacktrace() will iter each entry's stacktrace, even if filter is not configured. This patch change to quick return from fail_stacktrace() if stacktrace filter is not set. Signed-off-by: Wei Yongjun --- lib/fault-inject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fault-inject.c b/lib/fault-inject.c index 423784d9c058..515fc5aaf032 100644 --- a/lib/fault-inject.c +++ b/lib/fault-inject.c @@ -74,7 +74,7 @@ static bool fail_stacktrace(struct fault_attr *attr) int n, nr_entries; bool found =3D (attr->require_start =3D=3D 0 && attr->require_end =3D=3D = ULONG_MAX); =20 - if (depth =3D=3D 0) + if (depth =3D=3D 0 || (found && !attr->reject_start && !attr->reject_end)) return found; =20 nr_entries =3D stack_trace_save(entries, depth, 1); --=20 2.34.1 From nobody Sat Apr 11 02:19:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA7ACC25B08 for ; Wed, 17 Aug 2022 07:45:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233489AbiHQHpo (ORCPT ); Wed, 17 Aug 2022 03:45:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233086AbiHQHpc (ORCPT ); Wed, 17 Aug 2022 03:45:32 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B54D79A55 for ; Wed, 17 Aug 2022 00:45:31 -0700 (PDT) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4M70NK59XJzcffs; Wed, 17 Aug 2022 15:42:25 +0800 (CST) Received: from CHINA (10.175.102.38) by canpemm500009.china.huawei.com (7.192.105.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 17 Aug 2022 15:45:28 +0800 From: Wei Yongjun To: Akinobu Mita , Andrew Morton , Nathan Chancellor , Peter Zijlstra , Kees Cook , Nick Desaulniers , Josh Poimboeuf , Dan Williams , Miguel Ojeda , Isabella Basso , Vlastimil Babka , Rasmus Villemoes CC: Wei Yongjun , Subject: [PATCH 3/4 -next] fault-injection: make some stack filter attrs more readable Date: Wed, 17 Aug 2022 08:03:31 +0000 Message-ID: <20220817080332.1052710-4-weiyongjun1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220817080332.1052710-1-weiyongjun1@huawei.com> References: <20220817080332.1052710-1-weiyongjun1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.102.38] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Attributes of stack filter are show as unsigned decimal, such as 'require-start', 'require-end'. This patch change to show them as unsigned hexadecimal for more readable. Before: $ echo 0xffffffffc0257000 > /sys/kernel/debug/failslab/require-start $ cat /sys/kernel/debug/failslab/require-start 18446744072638263296 After: $ echo 0xffffffffc0257000 > /sys/kernel/debug/failslab/require-start $ cat /sys/kernel/debug/failslab/require-start 0xffffffffc0257000 Signed-off-by: Wei Yongjun --- lib/fault-inject.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/fault-inject.c b/lib/fault-inject.c index 515fc5aaf032..deca05e7c9b3 100644 --- a/lib/fault-inject.c +++ b/lib/fault-inject.c @@ -179,6 +179,14 @@ static void debugfs_create_ul(const char *name, umode_= t mode, =20 #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER =20 +DEFINE_SIMPLE_ATTRIBUTE(fops_xl, debugfs_ul_get, debugfs_ul_set, "0x%llx\n= "); + +static void debugfs_create_xl(const char *name, umode_t mode, + struct dentry *parent, unsigned long *value) +{ + debugfs_create_file(name, mode, parent, value, &fops_xl); +} + static int debugfs_stacktrace_depth_set(void *data, u64 val) { *(unsigned long *)data =3D @@ -223,10 +231,10 @@ struct dentry *fault_create_debugfs_attr(const char *= name, #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER debugfs_create_stacktrace_depth("stacktrace-depth", mode, dir, &attr->stacktrace_depth); - debugfs_create_ul("require-start", mode, dir, &attr->require_start); - debugfs_create_ul("require-end", mode, dir, &attr->require_end); - debugfs_create_ul("reject-start", mode, dir, &attr->reject_start); - debugfs_create_ul("reject-end", mode, dir, &attr->reject_end); + debugfs_create_xl("require-start", mode, dir, &attr->require_start); + debugfs_create_xl("require-end", mode, dir, &attr->require_end); + debugfs_create_xl("reject-start", mode, dir, &attr->reject_start); + debugfs_create_xl("reject-end", mode, dir, &attr->reject_end); #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */ =20 attr->dname =3D dget(dir); --=20 2.34.1 From nobody Sat Apr 11 02:19:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BEA2C25B08 for ; Wed, 17 Aug 2022 07:45:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233559AbiHQHps (ORCPT ); Wed, 17 Aug 2022 03:45:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233272AbiHQHpd (ORCPT ); Wed, 17 Aug 2022 03:45:33 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 303D079EE2 for ; Wed, 17 Aug 2022 00:45:32 -0700 (PDT) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4M70PL3qVHzhXWh; Wed, 17 Aug 2022 15:43:18 +0800 (CST) Received: from CHINA (10.175.102.38) by canpemm500009.china.huawei.com (7.192.105.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 17 Aug 2022 15:45:29 +0800 From: Wei Yongjun To: Akinobu Mita , Andrew Morton , Nathan Chancellor , Peter Zijlstra , Kees Cook , Nick Desaulniers , Josh Poimboeuf , Dan Williams , Miguel Ojeda , Isabella Basso , Vlastimil Babka , Rasmus Villemoes CC: Wei Yongjun , Subject: [PATCH 4/4 -next] fault-injection: make stacktrace filter works as expected Date: Wed, 17 Aug 2022 08:03:32 +0000 Message-ID: <20220817080332.1052710-5-weiyongjun1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220817080332.1052710-1-weiyongjun1@huawei.com> References: <20220817080332.1052710-1-weiyongjun1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.102.38] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" stacktrace filter is checked after others, such as fail-nth, interval and probability. This make it doesn't work well as expected. Fix to running stacktrace filter before other filters. It will speed up fault inject testing for driver modules. Signed-off-by: Wei Yongjun --- lib/fault-inject.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/fault-inject.c b/lib/fault-inject.c index deca05e7c9b3..9dd1dd1d2610 100644 --- a/lib/fault-inject.c +++ b/lib/fault-inject.c @@ -105,10 +105,16 @@ static inline bool fail_stacktrace(struct fault_attr = *attr) =20 bool should_fail(struct fault_attr *attr, ssize_t size) { + bool stack_checked =3D false; + if (in_task()) { unsigned int fail_nth =3D READ_ONCE(current->fail_nth); =20 if (fail_nth) { + if (!fail_stacktrace(attr)) + return false; + + stack_checked =3D true; fail_nth--; WRITE_ONCE(current->fail_nth, fail_nth); if (!fail_nth) @@ -128,6 +134,9 @@ bool should_fail(struct fault_attr *attr, ssize_t size) if (atomic_read(&attr->times) =3D=3D 0) return false; =20 + if (!stack_checked && !fail_stacktrace(attr)) + return false; + if (atomic_read(&attr->space) > size) { atomic_sub(size, &attr->space); return false; @@ -142,9 +151,6 @@ bool should_fail(struct fault_attr *attr, ssize_t size) if (attr->probability <=3D prandom_u32() % 100) return false; =20 - if (!fail_stacktrace(attr)) - return false; - fail: fail_dump(attr); =20 --=20 2.34.1