Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4094631rwb; Tue, 20 Sep 2022 08:44:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4VEpNETIA3IWJl8Acy11ZTksYW34jqEcRVU0llBaRUIjDv0fOtTftnZEGkJcnc9VKYV8bN X-Received: by 2002:a65:6cce:0:b0:439:49b5:48b8 with SMTP id g14-20020a656cce000000b0043949b548b8mr20936647pgw.514.1663688685991; Tue, 20 Sep 2022 08:44:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663688685; cv=none; d=google.com; s=arc-20160816; b=0ApAv26YMQQ4L3eJp2R+OaW8s5oQ4Vkwn4nKZbynYz6R2WreyJazAaPZdQrkbIeCO/ Ko+gJMZMx70pSRb7P9k9F03bm6zWkY8nZSkwIIEBty1+urtynhfm0XH+2vSdgF+B0ocD RHKKpce9OH+LXueDPvQ2D0PSosAMPKPy+jhNhdGQ1qdc/vYO84zqP++n8MoOqpNAnN50 n7hD2VNjrk6IjkOAMBTKKoLZBJhDgmGMC0mmBWuE3fZpUoysEP/jkORrZVNnNR1GX9CK s4LJ3D+1PTGFjMsLuN19eROzMfqueSN+L67LUB5kCCJcyuP4TRXoOX5sw/dMVeFwPac8 k4NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=NaqSSRpwTKq0k3mcZB3WuZhMuKxvyLsaVW9EFi1setU=; b=BSNACCZB6yqM+IAtY2DQNfWun59p6HDmB9g8P5Ae2je0B0HJI0opeYgrnoiGWsSiAj /AtTsdDs1b8qvLj3aB1CcquCt24Q+HqsZK3qaH8uj7OWtHPptdqCMKRMsKkjMQ+/Nzwf wMso06/v1sNDuaY86jmD2tEx075DSuVDjeQ4VNl8kkxoCjDozpCDRgDqquKwzHH1jI/N Zji4hdEa619eNzmgNQTZAfw7rp51hNZXpPwncEJc1fhQKraZEMI+Tdb8rWes9nENhTAI seHJr5ihaRKCVC30TH1DERO5YmxvBMfZyuyiYurydGDkudf8M5ukEPbyFSEv0aNLsdp4 EM1g== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u12-20020a170903124c00b00178232187e8si142644plh.43.2022.09.20.08.44.33; Tue, 20 Sep 2022 08:44:45 -0700 (PDT) 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 S231398AbiITPQK (ORCPT + 99 others); Tue, 20 Sep 2022 11:16:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231346AbiITPPv (ORCPT ); Tue, 20 Sep 2022 11:15:51 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9872C5EDF0; Tue, 20 Sep 2022 08:15:48 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MX4kJ6pmyzMnFp; Tue, 20 Sep 2022 23:11:04 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 23:15:45 +0800 Received: from ubuntu1804.huawei.com (10.67.175.36) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 20 Sep 2022 23:15:45 +0800 From: Chen Zhongjin To: , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH -next 1/7] riscv: stacktrace: Replace walk_stackframe with arch_stack_walk Date: Tue, 20 Sep 2022 23:11:56 +0800 Message-ID: <20220920151202.180057-2-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220920151202.180057-1-chenzhongjin@huawei.com> References: <20220920151202.180057-1-chenzhongjin@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500013.china.huawei.com (7.185.36.172) 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: X-Mailing-List: linux-kernel@vger.kernel.org walk_stackframe can be all replaced by arch_stack_walk. Since walk_stackframe is only called by arch_stack_walk and their only difference is the argument sequence. Signed-off-by: Chen Zhongjin --- arch/riscv/include/asm/stacktrace.h | 2 -- arch/riscv/kernel/perf_callchain.c | 2 +- arch/riscv/kernel/stacktrace.c | 29 +++++++++++++---------------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/arch/riscv/include/asm/stacktrace.h b/arch/riscv/include/asm/stacktrace.h index 3450c1912afd..b6cd3eddfd38 100644 --- a/arch/riscv/include/asm/stacktrace.h +++ b/arch/riscv/include/asm/stacktrace.h @@ -11,8 +11,6 @@ struct stackframe { unsigned long ra; }; -extern void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, - bool (*fn)(void *, unsigned long), void *arg); extern void dump_backtrace(struct pt_regs *regs, struct task_struct *task, const char *loglvl); diff --git a/arch/riscv/kernel/perf_callchain.c b/arch/riscv/kernel/perf_callchain.c index 3348a61de7d9..c023e0b1eb81 100644 --- a/arch/riscv/kernel/perf_callchain.c +++ b/arch/riscv/kernel/perf_callchain.c @@ -74,5 +74,5 @@ static bool fill_callchain(void *entry, unsigned long pc) void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs) { - walk_stackframe(NULL, regs, fill_callchain, entry); + arch_stack_walk(fill_callchain, entry, NULL, regs); } diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c index 08d11a53f39e..b51e32d50a0e 100644 --- a/arch/riscv/kernel/stacktrace.c +++ b/arch/riscv/kernel/stacktrace.c @@ -16,8 +16,9 @@ #ifdef CONFIG_FRAME_POINTER -void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, - bool (*fn)(void *, unsigned long), void *arg) +noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry, + void *cookie, struct task_struct *task, + struct pt_regs *regs) { unsigned long fp, sp, pc; int level = 0; @@ -29,7 +30,7 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, } else if (task == NULL || task == current) { fp = (unsigned long)__builtin_frame_address(0); sp = current_stack_pointer; - pc = (unsigned long)walk_stackframe; + pc = (unsigned long)arch_stack_walk; } else { /* task blocked in __switch_to */ fp = task->thread.s[0]; @@ -41,7 +42,8 @@ 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++ >= 1 && !consume_entry(cookie, pc)))) break; /* Validate frame pointer */ @@ -66,8 +68,9 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, #else /* !CONFIG_FRAME_POINTER */ -void notrace walk_stackframe(struct task_struct *task, - struct pt_regs *regs, bool (*fn)(void *, unsigned long), void *arg) +noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry, + void *cookie, struct task_struct *task, + struct pt_regs *regs) { unsigned long sp, pc; unsigned long *ksp; @@ -77,7 +80,7 @@ void notrace walk_stackframe(struct task_struct *task, pc = instruction_pointer(regs); } else if (task == NULL || task == current) { sp = current_stack_pointer; - pc = (unsigned long)walk_stackframe; + pc = (unsigned long)arch_stack_walk; } else { /* task blocked in __switch_to */ sp = task->thread.sp; @@ -89,7 +92,7 @@ void notrace walk_stackframe(struct task_struct *task, ksp = (unsigned long *)sp; while (!kstack_end(ksp)) { - if (__kernel_text_address(pc) && unlikely(!fn(arg, pc))) + if (__kernel_text_address(pc) && unlikely(!consume_entry(cookie, pc))) break; pc = (*ksp++) - 0x4; } @@ -108,7 +111,7 @@ static bool print_trace_address(void *arg, unsigned long pc) noinline void dump_backtrace(struct pt_regs *regs, struct task_struct *task, const char *loglvl) { - walk_stackframe(task, regs, print_trace_address, (void *)loglvl); + arch_stack_walk(print_trace_address, (void *)loglvl, task, regs); } void show_stack(struct task_struct *task, unsigned long *sp, const char *loglvl) @@ -133,13 +136,7 @@ unsigned long __get_wchan(struct task_struct *task) if (!try_get_task_stack(task)) return 0; - walk_stackframe(task, NULL, save_wchan, &pc); + arch_stack_walk(save_wchan, &pc, task, NULL); put_task_stack(task); return pc; } - -noinline void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie, - struct task_struct *task, struct pt_regs *regs) -{ - walk_stackframe(task, regs, consume_entry, cookie); -} -- 2.17.1