Message ID | 20221207025038.1022045-1-liushixin2@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3162997wrr; Tue, 6 Dec 2022 18:08:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf5w6LB9OVaNIkjPm45DPahfVaKxVe4CZvLrahti43OfPFedtFROmqQ2yLp+yO76Bvr+Rcha X-Received: by 2002:a17:906:aec1:b0:7c0:a04b:6795 with SMTP id me1-20020a170906aec100b007c0a04b6795mr25506229ejb.16.1670378905778; Tue, 06 Dec 2022 18:08:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670378905; cv=none; d=google.com; s=arc-20160816; b=Ceeq+hC/qfcUqNT7ml325KyZdxdH2yidyHee0Sl1kOW+AyWd7DigZ6yWDPd2YKSqci 9MpPSWWb4mVv4urOI/c0na5BD0BILTkcgFBYcYX9yvy7m6TZvkB2K1lRVC0fgAA4quxg 9141ctWDtWwYB99nuUA+4gw7/ltgZ0iL/1uWLVtByiUP9QMS5ZJvPzMe9h6pA7IIZNj9 FxCKji+nPs4McDX/rdvDewdbAN0+ei8t3GCbDbWHkwt+47mXzQjeVnA8vgqnkbEtyRdW 6SC9uvOPQfGePIH3KPFufLb/zXTVI3BS8C9V+zdCmF2T2vTKSh/s1Dh/pVN1Udo0DFt3 9JDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=WmwaaeAxNMBZ4oj/gcB3jpdj2WMTDzXm/ikGsOnDA80=; b=K5IK5n6UOqvkLsDOMCF1XYbWfj59aS1mOWnKqjn8b+1Qk4mFc2xNqWcJAGSXl+D/mO DtpnMMkIPTRzH2GbRL9N2/tmjC4nsKYS34GLj6mneDuSQ2tJ0B47FIQ7tNm62KTkaPWS ZtdoIsRylDM4NZvXumw8hpEZJuXGcKsi37o+RcLtpUo4ah8WBXUH8HY0osov73mjIyoj hejeRZ1EVT5fLUav5Fg+bQesR/r4XhSG39rT69jGbQt46zLhzykCQi9D/uI43pJljC71 QY/ss14trUD3cwkcoThJgCIIKr5T5ytXAS5WBKwKGE0g80ppbKs7rV33rOjeKBIV5nn9 XjCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y6-20020aa7c246000000b0046bce2261e5si2944043edo.471.2022.12.06.18.08.02; Tue, 06 Dec 2022 18:08:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229755AbiLGCDz (ORCPT <rfc822;b08248@gmail.com> + 99 others); Tue, 6 Dec 2022 21:03:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbiLGCDw (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 6 Dec 2022 21:03:52 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5BB3419AB for <linux-kernel@vger.kernel.org>; Tue, 6 Dec 2022 18:03:51 -0800 (PST) Received: from dggpemm100009.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4NRgTv283DzJp7Y; Wed, 7 Dec 2022 10:00:19 +0800 (CST) Received: from huawei.com (10.175.113.32) by dggpemm100009.china.huawei.com (7.185.36.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 7 Dec 2022 10:03:49 +0800 From: Liu Shixin <liushixin2@huawei.com> To: Conor Dooley <conor@kernel.org>, Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu>, Changbin Du <changbin.du@intel.com> CC: <linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org>, Liu Shixin <liushixin2@huawei.com> Subject: [PATCH v2] riscv: stacktrace: Fix missing the first frame Date: Wed, 7 Dec 2022 10:50:38 +0800 Message-ID: <20221207025038.1022045-1-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751380157281801628?= X-GMAIL-MSGID: =?utf-8?q?1751519231369101347?= |
Series |
[v2] riscv: stacktrace: Fix missing the first frame
|
|
Commit Message
Liu Shixin
Dec. 7, 2022, 2:50 a.m. UTC
When running kfence_test, I found some testcases failed like this:
# test_out_of_bounds_read: EXPECTATION FAILED at mm/kfence/kfence_test.c:346
Expected report_matches(&expect) to be true, but is false
not ok 1 - test_out_of_bounds_read
The corresponding call-trace is:
BUG: KFENCE: out-of-bounds read in kunit_try_run_case+0x38/0x84
Out-of-bounds read at 0x(____ptrval____) (32B right of kfence-#10):
kunit_try_run_case+0x38/0x84
kunit_generic_run_threadfn_adapter+0x12/0x1e
kthread+0xc8/0xde
ret_from_exception+0x0/0xc
The kfence_test using the first frame of call trace to check whether the
testcase is succeed or not. Commit 6a00ef449370 ("riscv: eliminate
unreliable __builtin_frame_address(1)") skip first frame for all
case, which results the kfence_test failed. Indeed, we only need to skip
the first frame for case (task==NULL || task==current).
With this patch, the call-trace will be:
BUG: KFENCE: out-of-bounds read in test_out_of_bounds_read+0x88/0x19e
Out-of-bounds read at 0x(____ptrval____) (1B left of kfence-#7):
test_out_of_bounds_read+0x88/0x19e
kunit_try_run_case+0x38/0x84
kunit_generic_run_threadfn_adapter+0x12/0x1e
kthread+0xc8/0xde
ret_from_exception+0x0/0xc
Fixes: 6a00ef449370 ("riscv: eliminate unreliable __builtin_frame_address(1)")
Signed-off-by: Liu Shixin <liushixin2@huawei.com>
---
v1->v2: Fix the incorrect Fixes tag found by Conor.
arch/riscv/kernel/stacktrace.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On 12/6/22 20:50, Liu Shixin wrote: > When running kfence_test, I found some testcases failed like this: > > # test_out_of_bounds_read: EXPECTATION FAILED at mm/kfence/kfence_test.c:346 > Expected report_matches(&expect) to be true, but is false > not ok 1 - test_out_of_bounds_read > > The corresponding call-trace is: > > BUG: KFENCE: out-of-bounds read in kunit_try_run_case+0x38/0x84 > > Out-of-bounds read at 0x(____ptrval____) (32B right of kfence-#10): > kunit_try_run_case+0x38/0x84 > kunit_generic_run_threadfn_adapter+0x12/0x1e > kthread+0xc8/0xde > ret_from_exception+0x0/0xc > > The kfence_test using the first frame of call trace to check whether the > testcase is succeed or not. Commit 6a00ef449370 ("riscv: eliminate > unreliable __builtin_frame_address(1)") skip first frame for all > case, which results the kfence_test failed. Indeed, we only need to skip > the first frame for case (task==NULL || task==current). > > With this patch, the call-trace will be: > > BUG: KFENCE: out-of-bounds read in test_out_of_bounds_read+0x88/0x19e > > Out-of-bounds read at 0x(____ptrval____) (1B left of kfence-#7): > test_out_of_bounds_read+0x88/0x19e > kunit_try_run_case+0x38/0x84 > kunit_generic_run_threadfn_adapter+0x12/0x1e > kthread+0xc8/0xde > ret_from_exception+0x0/0xc > > Fixes: 6a00ef449370 ("riscv: eliminate unreliable __builtin_frame_address(1)") > Signed-off-by: Liu Shixin <liushixin2@huawei.com> > --- > v1->v2: Fix the incorrect Fixes tag found by Conor. > > arch/riscv/kernel/stacktrace.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) Tested-by: Samuel Holland <samuel@sholland.org> Before: WARNING: CPU: 0 PID: 162 at drivers/regulator/core.c:5700 regulator_unregister+0xf0/0x106 ... [<ffffffff803a0794>] devm_rdev_release+0xe/0x16 [<ffffffff80427bac>] release_nodes+0x3c/0x98 [<ffffffff80428cac>] devres_release_all+0x72/0x9e [<ffffffff80424054>] device_unbind_cleanup+0x10/0x4a ... After: WARNING: CPU: 0 PID: 165 at drivers/regulator/core.c:5700 regulator_unregister+0xf0/0x106 ... [<ffffffff8039d194>] regulator_unregister+0xf0/0x106 [<ffffffff803a0798>] devm_rdev_release+0xe/0x16 [<ffffffff80427bb0>] release_nodes+0x3c/0x98 [<ffffffff80428cb0>] devres_release_all+0x72/0x9e [<ffffffff80424058>] device_unbind_cleanup+0x10/0x4a ...
Hello: This patch was applied to riscv/linux.git (fixes) by Palmer Dabbelt <palmer@rivosinc.com>: On Wed, 7 Dec 2022 10:50:38 +0800 you wrote: > When running kfence_test, I found some testcases failed like this: > > # test_out_of_bounds_read: EXPECTATION FAILED at mm/kfence/kfence_test.c:346 > Expected report_matches(&expect) to be true, but is false > not ok 1 - test_out_of_bounds_read > > The corresponding call-trace is: > > [...] Here is the summary with links: - [v2] riscv: stacktrace: Fix missing the first frame https://git.kernel.org/riscv/c/cb80242cc679 You are awesome, thank you!
diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c index 08d11a53f39e..5fe2ae4cf135 100644 --- a/arch/riscv/kernel/stacktrace.c +++ b/arch/riscv/kernel/stacktrace.c @@ -30,6 +30,7 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, fp = (unsigned long)__builtin_frame_address(0); sp = current_stack_pointer; pc = (unsigned long)walk_stackframe; + level = -1; } else { /* task blocked in __switch_to */ fp = task->thread.s[0]; @@ -41,7 +42,7 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, unsigned long low, high; struct stackframe *frame; - if (unlikely(!__kernel_text_address(pc) || (level++ >= 1 && !fn(arg, pc)))) + if (unlikely(!__kernel_text_address(pc) || (level++ >= 0 && !fn(arg, pc)))) break; /* Validate frame pointer */