Message ID | 20221205132936.493245-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 q4csp2245773wrr; Mon, 5 Dec 2022 05:17:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf6IUyCC5V8sx6ZytX92wo0KSviHWXM1MRvMSNwd5byxhlm3IvRxo0uNXRCQflJsSo5o9Wvj X-Received: by 2002:a17:902:bf41:b0:189:b8a2:27f3 with SMTP id u1-20020a170902bf4100b00189b8a227f3mr17525201pls.146.1670246274516; Mon, 05 Dec 2022 05:17:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670246274; cv=none; d=google.com; s=arc-20160816; b=MBsKVYTujqii2R5nkKD24QQyQ6DDHoV310OTknQFpmcBGV4ZWaVpeT9TQFCeLSk0dU Um411S57+jYK1bQ0c0wC9s9zNaThA2LpGdFHFJTOcSylajebbNW9Er4jSXPOrCglBSd0 7rduqVEZyL4trKaqChQzV08z3K0KzdWTdf/4rbkm+cj7TIsA0nYn8Q4Vm3Wb2cgLSeC0 vSRbOXFFIetoQ2x75FwgzlqRuno69wGYcCrfv7+kFFXYpZPoGg0o4Sz2HFoLlYOa4YDa 9ZKiTT9KWmnGcNr0HFWTOTZK+XLJCcNcyLPtsnSOxtZp6AXwyhqR9FlKr0b5qAQ5/2fh 3bsg== 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=4WIx6RXFlEAV7s89txkbqWA5bsWXttZ2Ds64CxUlZ4c=; b=anIzLkxwxrZV+z2F8TM+lP3N1r7rPMeXAQymDMDkGwFyGK4iiELK3h2qWT2WGKFS9z uJOxHqvi08zAsq2qX+H/Pg0MAkJo/uhEfl8htVWd6svIxf9IMmxQZ31hwFpP8reZPary mxbjuywoYb+yfqHkYjOO0ljVmPYeS2l5PHUs29wI412LHQZrpUl6w8moQIUn8Z6pby+7 gVw0bpeFUgXYkhHgpCrxba6HDcGGv/Tkug1XhIbrv4J88nUTFtKZGxjaKZQITKvCyNSn 68Py3kiyrwadaqukSfLvRqCrAVzBH6pog50SApfbq2Y8pq6IPB31vGA2y/Ny//dQQR1F p3MA== 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 bj2-20020a170902850200b0018929921900si13133806plb.80.2022.12.05.05.17.21; Mon, 05 Dec 2022 05:17:54 -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 S231205AbiLEMmw (ORCPT <rfc822;jaysivo@gmail.com> + 99 others); Mon, 5 Dec 2022 07:42:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231443AbiLEMms (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 5 Dec 2022 07:42:48 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F17C8631B for <linux-kernel@vger.kernel.org>; Mon, 5 Dec 2022 04:42:46 -0800 (PST) Received: from dggpemm100009.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4NQjm432rqzkXrn; Mon, 5 Dec 2022 20:39:16 +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; Mon, 5 Dec 2022 20:42:44 +0800 From: Liu Shixin <liushixin2@huawei.com> To: 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] riscv: stacktrace: Fix missing the first frame Date: Mon, 5 Dec 2022 21:29:36 +0800 Message-ID: <20221205132936.493245-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: dggems704-chm.china.huawei.com (10.3.19.181) 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?1751380157281801628?= |
Series |
riscv: stacktrace: Fix missing the first frame
|
|
Commit Message
Liu Shixin
Dec. 5, 2022, 1:29 p.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. Patch a7c5c7e8ff78 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: a7c5c7e8ff78 ("riscv: eliminate unreliable __builtin_frame_address(1)")
Signed-off-by: Liu Shixin <liushixin2@huawei.com>
---
arch/riscv/kernel/stacktrace.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On Mon, Dec 05, 2022 at 09:29:36PM +0800, 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. Patch a7c5c7e8ff78 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: a7c5c7e8ff78 ("riscv: eliminate unreliable __builtin_frame_address(1)") This fixes tag is not right, did checkpatch not warn about it? The correct fixes tag would be: Fixes: 6a00ef449370 ("riscv: eliminate unreliable __builtin_frame_address(1)") Maybe consider automating the creation of fixes tags, like so: git log -1 --format='Fixes: %h (\"%s\")' Thanks, Conor. > Signed-off-by: Liu Shixin <liushixin2@huawei.com> > --- > arch/riscv/kernel/stacktrace.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > 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 */ > -- > 2.25.1 >
On 2022/12/7 0:15, Conor Dooley wrote: > On Mon, Dec 05, 2022 at 09:29:36PM +0800, 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. Patch a7c5c7e8ff78 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: a7c5c7e8ff78 ("riscv: eliminate unreliable __builtin_frame_address(1)") > This fixes tag is not right, did checkpatch not warn about it? Yes, there are no warn. Maybe it's because I do have this commit in my local repository. I confused the original commit with my local commit. Thanks for your reminder. I'll fix it as soon as possible. > The correct fixes tag would be: > Fixes: 6a00ef449370 ("riscv: eliminate unreliable __builtin_frame_address(1)") > > Maybe consider automating the creation of fixes tags, like so: > git log -1 --format='Fixes: %h (\"%s\")' Thanks, it seems to be convenient. > > Thanks, > Conor. > >> Signed-off-by: Liu Shixin <liushixin2@huawei.com> >> --- >> arch/riscv/kernel/stacktrace.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> 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 */ >> -- >> 2.25.1 >>
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 */