Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp437691pxa; Wed, 19 Aug 2020 05:51:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSaIChZK5SJ5zmEmhzqsMF5Q9DANq0WCLtQG/nrZje3W94wk7a2o2yy/GWxWM3FXfjRiwB X-Received: by 2002:a17:906:5452:: with SMTP id d18mr25797391ejp.163.1597841502356; Wed, 19 Aug 2020 05:51:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597841502; cv=none; d=google.com; s=arc-20160816; b=XqrzxvuY/F72wTkcwo7Ye0Xbg28oipOcqwPNqbRztaFtVPxowUclPOFobsIzacobQG QsL1Lz+GD61Re7OuCLJ2mfi9gYKcjXhKA3PSGBa/0kwhjC+41tdyfsljKisXFvBx3T29 vA6MtgEUE3r6rtn/HiZS9hZuN5JFAyWmt8PXB/XszF7rMXtbg1XHwvQSoYtVq6C6oRH9 NCyY7gVR6XbPMAr1i8cYKSnlaVcBkhXJUTt3gYTPOvMexVOLDif2yRKY2JUWAiA77RP1 XGRwbgx2piccuAgBbI+MfBF8qZ0feTyiG3pN/jGcOk1t3srkO0WKVfGeOB1LHQGInztC fbzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lbTVYWVTE0IKwEIjWrzQehaTr83LaZ5r2MALV+IRB3o=; b=IVeSH3ktqIgn0rd8VNNGNenHW2gtUkX3nuaVoM3qtJiWAnD9ja5WMLIKpXGud8nnyW l7Wzl7jLFxCn4jfX+kDpPqz3ioUbnDrcoLkVZHk6i44yB2Uh/oySYNxq6bM6Z8Q7zdMM PSJXPy9dIC5NhtNt1UM9M+E8teB4lSzOcKYQldYVHYt0z9PxcB2K8qJbpvw2/agg4kMv iwL7h2bjjadtwP9BBg3Ex0ROE9fG0DPpfq9jYyK4PFab1AxNfMjV3nioZu6JKw95FJZn soUHwrLfrztiqYZANSJbpYuyydTsA5fq6TKZsLsBxRKyrc5lbF4lh7qHn9JgR+3xKTQR MwaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=K6Q4Gwdu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a20si20147204edj.133.2020.08.19.05.51.18; Wed, 19 Aug 2020 05:51:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=K6Q4Gwdu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728324AbgHSMuj (ORCPT + 99 others); Wed, 19 Aug 2020 08:50:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:36874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727903AbgHSMuL (ORCPT ); Wed, 19 Aug 2020 08:50:11 -0400 Received: from localhost (fw-tnat.cambridge.arm.com [217.140.96.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 499A52076E; Wed, 19 Aug 2020 12:50:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597841410; bh=2R5NjFBDYVtCErOgu/HmS4nfZ6UUJZq0QSSmV+zVHlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K6Q4GwdujH7YJo+xRo8v5OcNatKxrC5LNS5ZdJyUCvFZcrcR0KndpVSpwRSYAU5HB +5P4QTzu7+o52lC53W5IYvjqczR1/nrR3KQ+ePR0VK2idoKrgnTHerRyFUjTXcOiJ5 zm9JTMRBKToC92/EsRl3t5AJmIANiaidqIhHZho4= From: Mark Brown To: Catalin Marinas , Will Deacon , Vasily Gorbik , Heiko Carstens , Borislav Petkov , Thomas Gleixner , "H. Peter Anvin" Cc: Christian Borntraeger , Ingo Molnar , Jiri Slaby , x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Miroslav Benes , Mark Brown Subject: [PATCH v2 3/3] arm64: stacktrace: Convert to ARCH_STACKWALK Date: Wed, 19 Aug 2020 13:49:13 +0100 Message-Id: <20200819124913.37261-4-broonie@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200819124913.37261-1-broonie@kernel.org> References: <20200819124913.37261-1-broonie@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Historically architectures have had duplicated code in their stack trace implementations for filtering what gets traced. In order to avoid this duplication some generic code has been provided using a new interface arch_stack_walk(), enabled by selecting ARCH_STACKWALK in Kconfig, which factors all this out into the generic stack trace code. Convert arm64 to use this common infrastructure. Signed-off-by: Mark Brown --- arch/arm64/Kconfig | 1 + arch/arm64/kernel/stacktrace.c | 79 ++++------------------------------ 2 files changed, 9 insertions(+), 71 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 6d232837cbee..d1ba52e4b976 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -29,6 +29,7 @@ config ARM64 select ARCH_HAS_SETUP_DMA_OPS select ARCH_HAS_SET_DIRECT_MAP select ARCH_HAS_SET_MEMORY + select ARCH_STACKWALK select ARCH_HAS_STRICT_KERNEL_RWX select ARCH_HAS_STRICT_MODULE_RWX select ARCH_HAS_SYNC_DMA_FOR_DEVICE diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 743cf11fbfca..a33fba048954 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -133,82 +133,19 @@ void notrace walk_stackframe(struct task_struct *tsk, struct stackframe *frame, NOKPROBE_SYMBOL(walk_stackframe); #ifdef CONFIG_STACKTRACE -struct stack_trace_data { - struct stack_trace *trace; - unsigned int no_sched_functions; - unsigned int skip; -}; -static bool save_trace(void *d, unsigned long addr) +void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie, + struct task_struct *task, struct pt_regs *regs) { - struct stack_trace_data *data = d; - struct stack_trace *trace = data->trace; - - if (data->no_sched_functions && in_sched_functions(addr)) - return false; - if (data->skip) { - data->skip--; - return false; - } - - trace->entries[trace->nr_entries++] = addr; - - return trace->nr_entries >= trace->max_entries; -} - -void save_stack_trace_regs(struct pt_regs *regs, struct stack_trace *trace) -{ - struct stack_trace_data data; - struct stackframe frame; - - data.trace = trace; - data.skip = trace->skip; - data.no_sched_functions = 0; - - start_backtrace(&frame, regs->regs[29], regs->pc); - walk_stackframe(current, &frame, save_trace, &data); -} -EXPORT_SYMBOL_GPL(save_stack_trace_regs); - -static noinline void __save_stack_trace(struct task_struct *tsk, - struct stack_trace *trace, unsigned int nosched) -{ - struct stack_trace_data data; struct stackframe frame; - if (!try_get_task_stack(tsk)) - return; + if (regs) + start_backtrace(&frame, regs->regs[29], regs->pc); + else + start_backtrace(&frame, thread_saved_fp(task), + thread_saved_pc(task)); - data.trace = trace; - data.skip = trace->skip; - data.no_sched_functions = nosched; - - if (tsk != current) { - start_backtrace(&frame, thread_saved_fp(tsk), - thread_saved_pc(tsk)); - } else { - /* We don't want this function nor the caller */ - data.skip += 2; - start_backtrace(&frame, - (unsigned long)__builtin_frame_address(0), - (unsigned long)__save_stack_trace); - } - - walk_stackframe(tsk, &frame, save_trace, &data); - - put_task_stack(tsk); -} - -void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) -{ - __save_stack_trace(tsk, trace, 1); -} -EXPORT_SYMBOL_GPL(save_stack_trace_tsk); - -void save_stack_trace(struct stack_trace *trace) -{ - __save_stack_trace(current, trace, 0); + walk_stackframe(task, &frame, consume_entry, cookie); } -EXPORT_SYMBOL_GPL(save_stack_trace); #endif -- 2.20.1