From patchwork Fri Oct 15 02:34:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhavan T. Venkataraman" X-Patchwork-Id: 12559741 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49480C433F5 for ; Fri, 15 Oct 2021 02:36:12 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 013FC61039 for ; Fri, 15 Oct 2021 02:36:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 013FC61039 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=R7H9TUxKz/1UN/arMbOzL/lJOlRLi4ZLTIpT3we+Zxg=; b=ehB50xKtJ9ToGp h0ASESuQabRI1fLqhlZTXOfQm5IUdYw5RwFAU58ImqUYfyhdgSxywKE8RzkHB7+U31bxGNgClZG1O xlH0aLjyiXhDSrBHw1NSIdtPb1nhxsntICzKtIpQMXZVt2vovDXrtbNz5lIcCOnR8yqZGXZKVgg8Z LYaT8/Z4HQfk0Hw6ySLg+idYzwp5Wvicuiy3+aymG9Gw+quH/U8li3idWlXfyyEXzctd42ijeD+zC EvErxjjDZSUN6fbzsmKF6QN9JPinXZ/jDoUqtJVcIP6uQzNC58BxPU7P08bhU1XeKjZsnJyX+XnoX KketxCvW6QqxEZDHti9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD3i-0054Mo-C8; Fri, 15 Oct 2021 02:34:58 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD3e-0054Kk-E5 for linux-arm-kernel@lists.infradead.org; Fri, 15 Oct 2021 02:34:55 +0000 Received: from x64host.home (unknown [47.187.212.181]) by linux.microsoft.com (Postfix) with ESMTPSA id 122F620B9D1C; Thu, 14 Oct 2021 19:34:52 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 122F620B9D1C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1634265292; bh=0yghf4gyl+zuLPydKc3wkqnxys2UvYghl6oElnkiR2M=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YmRdFOKfO1fiDMo9LVD/3hMDqgHBp2zoxVpbOhW/xoQmvPmzjo5VgkDml4yfpvGa8 PtKUxS8b022gRn4+hBNjDhYfoR/XQfo1HDCVdSYWNbN6WF/EL26Y2V6cXmVO4/CJ6l KYBfncg7SdSf6TdWY/S8BO7EJAXC9YQ5/RF9Ra+A= From: madvenka@linux.microsoft.com To: mark.rutland@arm.com, broonie@kernel.org, jpoimboe@redhat.com, ardb@kernel.org, nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com, catalin.marinas@arm.com, will@kernel.org, jmorris@namei.org, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, madvenka@linux.microsoft.com Subject: [PATCH v9 01/11] arm64: Select STACKTRACE in arch/arm64/Kconfig Date: Thu, 14 Oct 2021 21:34:03 -0500 Message-Id: <20211015023413.16614-2-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211015023413.16614-1-madvenka@linux.microsoft.com> References: <20211015023413.16614-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211014_193454_585697_10DBAC36 X-CRM114-Status: UNSURE ( 7.80 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "Madhavan T. Venkataraman" Currently, there are multiple functions in ARM64 code that walk the stack using start_backtrace() and unwind_frame() or start_backtrace() and walk_stackframe(). They should all be converted to use arch_stack_walk(). This makes maintenance easier. To do that, arch_stack_walk() must always be defined. arch_stack_walk() is within #ifdef CONFIG_STACKTRACE. So, select STACKTRACE in arch/arm64/Kconfig. Signed-off-by: Madhavan T. Venkataraman --- arch/arm64/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index fdcd54d39c1e..bfb0ce60d820 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -35,6 +35,7 @@ config ARM64 select ARCH_HAS_SET_DIRECT_MAP select ARCH_HAS_SET_MEMORY select ARCH_STACKWALK + select STACKTRACE select ARCH_HAS_STRICT_KERNEL_RWX select ARCH_HAS_STRICT_MODULE_RWX select ARCH_HAS_SYNC_DMA_FOR_DEVICE From patchwork Fri Oct 15 02:34:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhavan T. Venkataraman" X-Patchwork-Id: 12559747 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF0B2C433F5 for ; Fri, 15 Oct 2021 02:36:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B90A3610D1 for ; Fri, 15 Oct 2021 02:36:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B90A3610D1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KzSXfdsdQBR4Ojz09sbnj85VbMFjsZCHI0eIgMVQ9/g=; b=ZbEv6p0u8kcpn5 hNfRxvGQfWZUEIQryGuqSEB8u4vW6U7gNe5QLDmEuiDv37dPwgRBt8DgZ5Ya0+sIscbxyQch/ZwAB /+LoIMfvw7eVSun4pxkwv2UVXMAXfHwqwlY/vJuk7Jo3MJt7aVPSQ2OGH+472fhKARQKZ8dR6ifSX 2Df3k4tSQO6Ad8Ef6BEYo+gCYWofZ5UFHM5nFAh+Yf3s0lBz9uQhNzPnIqUVOclGTL5kv1JBifC4Z bP0PsjqJTx2T1Rv4+v5CnYi45XVRGyqhEt+XwlxZF4CFGPHnew0pSSdIyphEW1K92AJAHI5Jwc+Pr t86M0x12/BLZCaqEC1uQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD4Q-0054dU-4F; Fri, 15 Oct 2021 02:35:42 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD3g-0054MR-CT for linux-arm-kernel@lists.infradead.org; Fri, 15 Oct 2021 02:34:57 +0000 Received: from x64host.home (unknown [47.187.212.181]) by linux.microsoft.com (Postfix) with ESMTPSA id 4AAAC20B9D20; Thu, 14 Oct 2021 19:34:55 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4AAAC20B9D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1634265296; bh=FmJbGXiSP+JGonZTp90DkLqCm4FVOelAbFqDoqqHdv4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VwZFmiQp0tA/bogXQs+nNJUxiSpIgDFSq6xS5hehRanndLGGpQ7XPt7Pj64SKCwgd JVikcRCcstvrpHrc8OuQoaCqdWHR6OCevI3gdDEDFhaLoGjSxhGXRVjy+nlHCMsvwR Ton0mwr5oSnVE10tSnnK/4fzZkFYhLJUBurWWX+w= From: madvenka@linux.microsoft.com To: mark.rutland@arm.com, broonie@kernel.org, jpoimboe@redhat.com, ardb@kernel.org, nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com, catalin.marinas@arm.com, will@kernel.org, jmorris@namei.org, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, madvenka@linux.microsoft.com Subject: [PATCH v9 02/11] arm64: Make perf_callchain_kernel() use arch_stack_walk() Date: Thu, 14 Oct 2021 21:34:06 -0500 Message-Id: <20211015023413.16614-5-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211015023413.16614-1-madvenka@linux.microsoft.com> References: <20211015023413.16614-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211014_193456_475030_56D46365 X-CRM114-Status: UNSURE ( 8.73 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "Madhavan T. Venkataraman" Currently, perf_callchain_kernel() in ARM64 code walks the stack using start_backtrace() and walk_stackframe(). Make it use arch_stack_walk() instead. This makes maintenance easier. Signed-off-by: Madhavan T. Venkataraman --- arch/arm64/kernel/perf_callchain.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/perf_callchain.c b/arch/arm64/kernel/perf_callchain.c index 4a72c2727309..f173c448e852 100644 --- a/arch/arm64/kernel/perf_callchain.c +++ b/arch/arm64/kernel/perf_callchain.c @@ -140,22 +140,18 @@ void perf_callchain_user(struct perf_callchain_entry_ctx *entry, static bool callchain_trace(void *data, unsigned long pc) { struct perf_callchain_entry_ctx *entry = data; - perf_callchain_store(entry, pc); - return true; + return perf_callchain_store(entry, pc) == 0; } void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs) { - struct stackframe frame; - if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) { /* We don't support guest os callchain now */ return; } - start_backtrace(&frame, regs->regs[29], regs->pc); - walk_stackframe(current, &frame, callchain_trace, entry); + arch_stack_walk(callchain_trace, entry, current, regs); } unsigned long perf_instruction_pointer(struct pt_regs *regs) From patchwork Fri Oct 15 02:34:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhavan T. Venkataraman" X-Patchwork-Id: 12559751 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C966C433F5 for ; Fri, 15 Oct 2021 02:37:35 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E643B61041 for ; Fri, 15 Oct 2021 02:37:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E643B61041 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=srCU7wspJ+yzFSWzkDJqtj29cveq25mGU2t283zUrWk=; b=sGhpdGqACTPycU w3vMEHlzIheZjS+jZYTlK1zdfANiK/RjOErpnCznojzYTuc37BiIshgj/xYhinMqdhPFBPFl1Cvp9 +S+SsRgiVeXVe0A1WAZQ/yhrZAnTbB8ry1RdPI0f9y6BdXxJ9mVmxPJFR4zrxSyejIEB9UNvDZXAa /ZtAtOWXLYfhM5nZGrr+vkYxLaPpjocqjCfly5UMEcMryNxg7ybBe1J4la91hSm2SUYhQkLXth25u 2e3iRzfZ+ZxLiHggKCl7IDCiYa0fejLibcjTg09l4Ux49BZ3VxFKFOJ8lCWVW1+Cwg0YkKP0v7hJU ikNV6zcxquih375ShaNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD4v-0054rZ-L4; Fri, 15 Oct 2021 02:36:14 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD3h-0054Mz-He for linux-arm-kernel@lists.infradead.org; Fri, 15 Oct 2021 02:34:58 +0000 Received: from x64host.home (unknown [47.187.212.181]) by linux.microsoft.com (Postfix) with ESMTPSA id 5D32620B9D21; Thu, 14 Oct 2021 19:34:56 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5D32620B9D21 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1634265297; bh=g5fdmzSduoUMkjQHmQa/fhtE8jC0SUmUZcxIW9qvvbk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=EOQ4p0HojTauGxaXASPK4GU4vDOJa3UVPC24jbgsqCyZpmxKDiWWo88cajPvWByXK 9drraQdhEYYqc/Dv13E31bHo8IcLxqcMGbDUIwksDgMw9TsJh6HJbQVU38QMBkhmGF /jB/cgQWCOsXURyG6hu7O17Md0lH37cTxD6wpqY4= From: madvenka@linux.microsoft.com To: mark.rutland@arm.com, broonie@kernel.org, jpoimboe@redhat.com, ardb@kernel.org, nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com, catalin.marinas@arm.com, will@kernel.org, jmorris@namei.org, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, madvenka@linux.microsoft.com Subject: [PATCH v9 03/11] arm64: Make get_wchan() use arch_stack_walk() Date: Thu, 14 Oct 2021 21:34:07 -0500 Message-Id: <20211015023413.16614-6-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211015023413.16614-1-madvenka@linux.microsoft.com> References: <20211015023413.16614-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211014_193457_639928_3851326C X-CRM114-Status: UNSURE ( 9.92 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "Madhavan T. Venkataraman" Currently, get_wchan() in ARM64 code walks the stack using start_backtrace() and unwind_frame(). Make it use arch_stack_walk() instead. This makes maintenance easier. Signed-off-by: Madhavan T. Venkataraman --- arch/arm64/kernel/process.c | 38 ++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index c8989b999250..48ed89acce0d 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -544,11 +544,27 @@ __notrace_funcgraph struct task_struct *__switch_to(struct task_struct *prev, return last; } +struct wchan_info { + unsigned long pc; + int count; +}; + +static bool get_wchan_cb(void *arg, unsigned long pc) +{ + struct wchan_info *wchan_info = arg; + + if (!in_sched_functions(pc)) { + wchan_info->pc = pc; + return false; + } + return wchan_info->count++ < 16; +} + unsigned long get_wchan(struct task_struct *p) { - struct stackframe frame; - unsigned long stack_page, ret = 0; - int count = 0; + unsigned long stack_page; + struct wchan_info wchan_info; + if (!p || p == current || task_is_running(p)) return 0; @@ -556,20 +572,12 @@ unsigned long get_wchan(struct task_struct *p) if (!stack_page) return 0; - start_backtrace(&frame, thread_saved_fp(p), thread_saved_pc(p)); + wchan_info.pc = 0; + wchan_info.count = 0; + arch_stack_walk(get_wchan_cb, &wchan_info, p, NULL); - do { - if (unwind_frame(p, &frame)) - goto out; - if (!in_sched_functions(frame.pc)) { - ret = frame.pc; - goto out; - } - } while (count++ < 16); - -out: put_task_stack(p); - return ret; + return wchan_info.pc; } unsigned long arch_align_stack(unsigned long sp) From patchwork Fri Oct 15 02:34:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhavan T. Venkataraman" X-Patchwork-Id: 12559753 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C8E7C433EF for ; Fri, 15 Oct 2021 02:37:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C347D60E09 for ; Fri, 15 Oct 2021 02:37:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C347D60E09 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/5Pd5Fu0lPvs7ZJrg+IJ9l0Tme2dCfW18kT5HsslmBc=; b=gBzH7vhZ5oymeV YMSNXjBl3AJVP3JLzV9EAmUWJd16CPXvh/xgHrcOb59rhNIDotF4EwCsIhpqCbhJiVIIPdwayrjqI BctIxOIxbYLArFM39kOYkYDcXlm55r17obXrQEX2P4cYxd+PuCdL+/RsxgcdQ6Fxc49d6iB+JLowF mH4PDvKT8PnPSLjemf3iroo8lOdCUEhCdFieopV6EPBy7JXiQNuufUA6cGXf2pMHAQlns7iKZDg1b DaN+U4cp3p8R9ylzPjElkb4DDADeS6nHWdgXk7x15n2IjVAXoiqnyy8WCj+kOoTmUp3hsXsDDremG /M64GV3HOqE34Somq0sA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD5I-00554t-Aa; Fri, 15 Oct 2021 02:36:36 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD3i-0054MR-OY for linux-arm-kernel@lists.infradead.org; Fri, 15 Oct 2021 02:35:00 +0000 Received: from x64host.home (unknown [47.187.212.181]) by linux.microsoft.com (Postfix) with ESMTPSA id 6FC9420B9D22; Thu, 14 Oct 2021 19:34:57 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6FC9420B9D22 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1634265298; bh=qZScEFTO+pORG9YKmb/gJbPlBbD1pvru4NrU3/YAom4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fPITtNCJx1AiyMyMCIsYoQM+nzWbH6BwA3I2FM3/ckjWOdtTOfl2VmSkZKZgDZCpG 4FJkaRCfQMXmgBGF74uIlUh6Pw+U0iMGs9a5d//ARcfsgvSL5EscbhKxWdo335GpKt QSDnf+p7GwD71W+nzufJ69xTWYaL4ZlOseUHBWlU= From: madvenka@linux.microsoft.com To: mark.rutland@arm.com, broonie@kernel.org, jpoimboe@redhat.com, ardb@kernel.org, nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com, catalin.marinas@arm.com, will@kernel.org, jmorris@namei.org, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, madvenka@linux.microsoft.com Subject: [PATCH v9 04/11] arm64: Make return_address() use arch_stack_walk() Date: Thu, 14 Oct 2021 21:34:08 -0500 Message-Id: <20211015023413.16614-7-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211015023413.16614-1-madvenka@linux.microsoft.com> References: <20211015023413.16614-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211014_193458_917374_693D898F X-CRM114-Status: UNSURE ( 8.23 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "Madhavan T. Venkataraman" Currently, return_address() in ARM64 code walks the stack using start_backtrace() and walk_stackframe(). Make it use arch_stack_walk() instead. This makes maintenance easier. Signed-off-by: Madhavan T. Venkataraman --- arch/arm64/kernel/return_address.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/arch/arm64/kernel/return_address.c b/arch/arm64/kernel/return_address.c index a6d18755652f..92a0f4d434e4 100644 --- a/arch/arm64/kernel/return_address.c +++ b/arch/arm64/kernel/return_address.c @@ -35,15 +35,11 @@ NOKPROBE_SYMBOL(save_return_addr); void *return_address(unsigned int level) { struct return_address_data data; - struct stackframe frame; data.level = level + 2; data.addr = NULL; - start_backtrace(&frame, - (unsigned long)__builtin_frame_address(0), - (unsigned long)return_address); - walk_stackframe(current, &frame, save_return_addr, &data); + arch_stack_walk(save_return_addr, &data, current, NULL); if (!data.level) return data.addr; From patchwork Fri Oct 15 02:34:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhavan T. Venkataraman" X-Patchwork-Id: 12559755 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7488C433EF for ; Fri, 15 Oct 2021 02:38:21 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9B320610D1 for ; Fri, 15 Oct 2021 02:38:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9B320610D1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6wTw5ZSoYY2zceDm2csSYfobBZaHwJx8MeN1I2/b4ko=; b=j6hyGEOBjVzb9p zU3CCmtXq2/kpim3hJi9uON+CAyFJnQEjHuO/jT0Ub9KeiYCPogw7AeDZfbfLTHMAPu5V232U9kGH LMJ/WXshKZrCJoe4fiIoDCyyyKPqypKrgiyLAR3wHdEIwGKV7hEkoGRnBScCWxLQzIciv23EBVq9w I70bF00SRTURYjmSuVLq6TGHvYyhKS8dpEBAt9G+HrbAwQ8HmRXLiHcCFfjkaKCFgIFzpgiEX4k9/ fJ6IodKUIVJdnT/JtlX3khddmFukozSdw5jeuhT7xLE/xiQ93Od/AXfUB9Qh46zd6fHpcU/6OLsxG YCnRcVjR4fcgJchFYOtw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD5f-0055Hy-UZ; Fri, 15 Oct 2021 02:37:00 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD3j-0054Mz-M3 for linux-arm-kernel@lists.infradead.org; Fri, 15 Oct 2021 02:35:01 +0000 Received: from x64host.home (unknown [47.187.212.181]) by linux.microsoft.com (Postfix) with ESMTPSA id 824C320B9D23; Thu, 14 Oct 2021 19:34:58 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 824C320B9D23 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1634265299; bh=6B7i9QOJfwrh+wxsghOjM0WArHrFBqgVADtSVHWaIEc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=JEZx8dVtEoINgrflaJmkhHWKO0ZsSRX5Gmy+r4YZZV93gj2WWBOEKoAuLSzP3Imp/ EWkP21966a8CsHiUYoTRuc/o1sH8V+lE5jh++puD4WSpT3NpBcDQfGVe5J+7+DbmkW T1mHUCskR0nlTjF9REbZhjEdA1CkVoNyp6Q2xoPU= From: madvenka@linux.microsoft.com To: mark.rutland@arm.com, broonie@kernel.org, jpoimboe@redhat.com, ardb@kernel.org, nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com, catalin.marinas@arm.com, will@kernel.org, jmorris@namei.org, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, madvenka@linux.microsoft.com Subject: [PATCH v9 05/11] arm64: Make dump_stacktrace() use arch_stack_walk() Date: Thu, 14 Oct 2021 21:34:09 -0500 Message-Id: <20211015023413.16614-8-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211015023413.16614-1-madvenka@linux.microsoft.com> References: <20211015023413.16614-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211014_193459_795258_66EA403A X-CRM114-Status: GOOD ( 13.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "Madhavan T. Venkataraman" Currently, dump_stacktrace() in ARM64 code walks the stack using start_backtrace() and unwind_frame(). Make it use arch_stack_walk() instead. This makes maintenance easier. Signed-off-by: Madhavan T. Venkataraman --- arch/arm64/kernel/stacktrace.c | 44 +++++----------------------------- 1 file changed, 6 insertions(+), 38 deletions(-) diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 8982a2b78acf..776c4debb5a7 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -151,24 +151,20 @@ void notrace walk_stackframe(struct task_struct *tsk, struct stackframe *frame, } NOKPROBE_SYMBOL(walk_stackframe); -static void dump_backtrace_entry(unsigned long where, const char *loglvl) +static bool dump_backtrace_entry(void *arg, unsigned long where) { + char *loglvl = arg; printk("%s %pSb\n", loglvl, (void *)where); + return true; } void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk, const char *loglvl) { - struct stackframe frame; - int skip = 0; - pr_debug("%s(regs = %p tsk = %p)\n", __func__, regs, tsk); - if (regs) { - if (user_mode(regs)) - return; - skip = 1; - } + if (regs && user_mode(regs)) + return; if (!tsk) tsk = current; @@ -176,36 +172,8 @@ void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk, if (!try_get_task_stack(tsk)) return; - if (tsk == current) { - start_backtrace(&frame, - (unsigned long)__builtin_frame_address(0), - (unsigned long)dump_backtrace); - } else { - /* - * task blocked in __switch_to - */ - start_backtrace(&frame, - thread_saved_fp(tsk), - thread_saved_pc(tsk)); - } - printk("%sCall trace:\n", loglvl); - do { - /* skip until specified stack frame */ - if (!skip) { - dump_backtrace_entry(frame.pc, loglvl); - } else if (frame.fp == regs->regs[29]) { - skip = 0; - /* - * Mostly, this is the case where this function is - * called in panic/abort. As exception handler's - * stack frame does not contain the corresponding pc - * at which an exception has taken place, use regs->pc - * instead. - */ - dump_backtrace_entry(regs->pc, loglvl); - } - } while (!unwind_frame(tsk, &frame)); + arch_stack_walk(dump_backtrace_entry, (void *)loglvl, tsk, regs); put_task_stack(tsk); } From patchwork Fri Oct 15 02:34:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhavan T. Venkataraman" X-Patchwork-Id: 12559757 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16E31C433EF for ; Fri, 15 Oct 2021 02:38:51 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C6C3360E09 for ; Fri, 15 Oct 2021 02:38:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C6C3360E09 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=v4JfvkRPJCcdczrWnpd9cvDM2iOrAxDX/IyZfGXeFXA=; b=ZGh1vsNB5n6oBB 3H/SYFa2LhBO9lof+EPcGQNPo7NroTCPrsZ/ZD6hM5+cAw387JfygrE1P3DZ3xxJJGHrI6alU12dH ChnpOw7GFOuFoJliIDUB1yCJhiF+9u6p46rFfjBuTF1SZwmlb84TgAQfr60jVt5OrOipGMIQ1FYg0 HhQ2rf3dy2eRd3uwQf1+DogG1AmrQibNzAad4Cn2Xc3cOLvjmNfw9QXd6kbIPhvEceFlhGRkXrGZK 9WHaYy4Ak5eCulHrFchETV2lBuNBwz1IM+k+FyXVtfIFDK/fgWiCxMEZprWuI3SdHqoaQUn+DJRGe VUEawMrVxfyU/2uGoySA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD65-0055Vj-QL; Fri, 15 Oct 2021 02:37:26 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD3k-0054MR-OV for linux-arm-kernel@lists.infradead.org; Fri, 15 Oct 2021 02:35:02 +0000 Received: from x64host.home (unknown [47.187.212.181]) by linux.microsoft.com (Postfix) with ESMTPSA id 94E2720B9D20; Thu, 14 Oct 2021 19:34:59 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 94E2720B9D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1634265300; bh=AbsOg32zRR78sDGzy2GosMMSEjrzSM+M26cFHMLFAG8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=AxuPDl0EUp2jhKj8zy5MtH4Otfmi0NjlrRhtyg44gpP6SeHWkhDCIaxi+1/WG6qMb 5Jan6CTcJFzchLGAEGHOBlKXpoiHfa7xbAONA5ow7bOrmvUNduGEdNbhdZQw6pSZk7 vjQVKoRPHlfprnS3+Rq45Yi+guBCYNfPIL4mNUXs= From: madvenka@linux.microsoft.com To: mark.rutland@arm.com, broonie@kernel.org, jpoimboe@redhat.com, ardb@kernel.org, nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com, catalin.marinas@arm.com, will@kernel.org, jmorris@namei.org, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, madvenka@linux.microsoft.com Subject: [PATCH v9 06/11] arm64: Make profile_pc() use arch_stack_walk() Date: Thu, 14 Oct 2021 21:34:10 -0500 Message-Id: <20211015023413.16614-9-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211015023413.16614-1-madvenka@linux.microsoft.com> References: <20211015023413.16614-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211014_193500_862953_E8D619E1 X-CRM114-Status: UNSURE ( 9.62 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "Madhavan T. Venkataraman" Currently, profile_pc() in ARM64 code walks the stack using start_backtrace() and unwind_frame(). Make it use arch_stack_walk() instead. This makes maintenance easier. Signed-off-by: Madhavan T. Venkataraman --- arch/arm64/kernel/time.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kernel/time.c b/arch/arm64/kernel/time.c index eebbc8d7123e..671b3038a772 100644 --- a/arch/arm64/kernel/time.c +++ b/arch/arm64/kernel/time.c @@ -32,22 +32,26 @@ #include #include +static bool profile_pc_cb(void *arg, unsigned long pc) +{ + unsigned long *prof_pc = arg; + + if (in_lock_functions(pc)) + return true; + *prof_pc = pc; + return false; +} + unsigned long profile_pc(struct pt_regs *regs) { - struct stackframe frame; + unsigned long prof_pc = 0; if (!in_lock_functions(regs->pc)) return regs->pc; - start_backtrace(&frame, regs->regs[29], regs->pc); - - do { - int ret = unwind_frame(NULL, &frame); - if (ret < 0) - return 0; - } while (in_lock_functions(frame.pc)); + arch_stack_walk(profile_pc_cb, &prof_pc, current, regs); - return frame.pc; + return prof_pc; } EXPORT_SYMBOL(profile_pc); From patchwork Fri Oct 15 02:34:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhavan T. Venkataraman" X-Patchwork-Id: 12559759 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6419FC433F5 for ; Fri, 15 Oct 2021 02:39:13 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2F926610D1 for ; Fri, 15 Oct 2021 02:39:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2F926610D1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SR8otQcmol0Z+vRuUxFfq/5QRcVLph5I2TY6vFNc6+M=; b=KsKLurmeW9O6u5 GkI7UGPqO6TzrD//kZ/gJydxX4UFPLDnE7yKrvJukLHvj+3XYgDnN7vtnXCU8CZrYxRZHy3rnaCUT SiVr+0AAa6r0PyFYU9SP2cPKAg+gh+f+VRjXFOF9p0iUTp1U0q2lYZuWSsjieDDbQSCqeSemDFoX+ g0vZ1ca9DtiDbSblLOb7I7oyCx0wii5aY3GuQCzma2fbGrSvkoZEd+e4X7T7rRgGypDJcq7uGKze8 6LrGwT5eTrdRKzmpflGxVWJg4jzuOOflgg6/POEFlR5OPM3CAY3k3kJiuDBorxobXdI3n5V29BwzE R1CLCQIp9MG1lECIeiww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD6Y-0055lU-23; Fri, 15 Oct 2021 02:37:54 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD3l-0054Mz-M2 for linux-arm-kernel@lists.infradead.org; Fri, 15 Oct 2021 02:35:03 +0000 Received: from x64host.home (unknown [47.187.212.181]) by linux.microsoft.com (Postfix) with ESMTPSA id A775820B9D22; Thu, 14 Oct 2021 19:35:00 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A775820B9D22 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1634265301; bh=Sre2VpLzl4RVm2McLfD5iL1Uc+pnLRObb9ujvhfag6U=; h=From:To:Subject:Date:In-Reply-To:References:From; b=b2wt6Eo4tXd7REs0soSvOigcsjVBosSp8D6g2YrtOUCyaz3NHtLoY2jW4vBkSMQFI NSDiqRd72Njsrzac2c3TyfX+OXGOIE8gYOatvph5/eddnpzNvLFmno6gFNB9YPUu9E hSNuDY/7iEOUOmnj+ngsHAalvweFody3YkGoN7OE= From: madvenka@linux.microsoft.com To: mark.rutland@arm.com, broonie@kernel.org, jpoimboe@redhat.com, ardb@kernel.org, nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com, catalin.marinas@arm.com, will@kernel.org, jmorris@namei.org, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, madvenka@linux.microsoft.com Subject: [PATCH v9 07/11] arm64: Call stack_backtrace() only from within walk_stackframe() Date: Thu, 14 Oct 2021 21:34:11 -0500 Message-Id: <20211015023413.16614-10-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211015023413.16614-1-madvenka@linux.microsoft.com> References: <20211015023413.16614-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211014_193501_826504_67D3318E X-CRM114-Status: GOOD ( 14.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "Madhavan T. Venkataraman" Currently, arch_stack_walk() calls start_backtrace() and walk_stackframe() separately. There is no need to do that. Instead, call start_backtrace() from within walk_stackframe(). In other words, walk_stackframe() is the only unwind function a consumer needs to call. Currently, the only consumer is arch_stack_walk(). In the future, arch_stack_walk_reliable() will be another consumer. start_backtrace(), unwind_frame() and walk_stackframe() are only used within arm64/kernel/stacktrace.c. Make them static and remove them from arch/arm64/include/asm/stacktrace.h. Currently, there is a check for a NULL task in unwind_frame(). It is not needed since all current consumers pass a non-NULL task. Use struct stackframe only within the unwind functions. Signed-off-by: Madhavan T. Venkataraman --- arch/arm64/include/asm/stacktrace.h | 6 ---- arch/arm64/kernel/stacktrace.c | 51 ++++++++++++++++------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/arch/arm64/include/asm/stacktrace.h b/arch/arm64/include/asm/stacktrace.h index 8aebc00c1718..c239f357d779 100644 --- a/arch/arm64/include/asm/stacktrace.h +++ b/arch/arm64/include/asm/stacktrace.h @@ -61,9 +61,6 @@ struct stackframe { #endif }; -extern int unwind_frame(struct task_struct *tsk, struct stackframe *frame); -extern void walk_stackframe(struct task_struct *tsk, struct stackframe *frame, - bool (*fn)(void *, unsigned long), void *data); extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk, const char *loglvl); @@ -148,7 +145,4 @@ static inline bool on_accessible_stack(const struct task_struct *tsk, return false; } -void start_backtrace(struct stackframe *frame, unsigned long fp, - unsigned long pc); - #endif /* __ASM_STACKTRACE_H */ diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 776c4debb5a7..7d32cee9ef4b 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -33,8 +33,8 @@ */ -void start_backtrace(struct stackframe *frame, unsigned long fp, - unsigned long pc) +static void start_backtrace(struct stackframe *frame, unsigned long fp, + unsigned long pc) { frame->fp = fp; frame->pc = pc; @@ -63,14 +63,12 @@ void start_backtrace(struct stackframe *frame, unsigned long fp, * records (e.g. a cycle), determined based on the location and fp value of A * and the location (but not the fp value) of B. */ -int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame) +static int notrace unwind_frame(struct task_struct *tsk, + struct stackframe *frame) { unsigned long fp = frame->fp; struct stack_info info; - if (!tsk) - tsk = current; - /* Final frame; nothing to unwind */ if (fp == (unsigned long)task_pt_regs(tsk)->stackframe) return -ENOENT; @@ -136,15 +134,21 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame) } NOKPROBE_SYMBOL(unwind_frame); -void notrace walk_stackframe(struct task_struct *tsk, struct stackframe *frame, - bool (*fn)(void *, unsigned long), void *data) +static void notrace walk_stackframe(struct task_struct *tsk, + unsigned long fp, unsigned long pc, + bool (*fn)(void *, unsigned long), + void *data) { + struct stackframe frame; + + start_backtrace(&frame, fp, pc); + while (1) { int ret; - if (!fn(data, frame->pc)) + if (!fn(data, frame.pc)) break; - ret = unwind_frame(tsk, frame); + ret = unwind_frame(tsk, &frame); if (ret < 0) break; } @@ -190,19 +194,22 @@ noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie, struct task_struct *task, struct pt_regs *regs) { - struct stackframe frame; + unsigned long fp, pc; + + if (regs) { + fp = regs->regs[29]; + pc = regs->pc; + } else if (task == current) { + /* Skip arch_stack_walk() in the stack trace. */ + fp = (unsigned long)__builtin_frame_address(1); + pc = (unsigned long)__builtin_return_address(0); + } else { + /* Caller guarantees that the task is not running. */ + fp = thread_saved_fp(task); + pc = thread_saved_pc(task); + } + walk_stackframe(task, fp, pc, consume_entry, cookie); - if (regs) - start_backtrace(&frame, regs->regs[29], regs->pc); - else if (task == current) - start_backtrace(&frame, - (unsigned long)__builtin_frame_address(1), - (unsigned long)__builtin_return_address(0)); - else - start_backtrace(&frame, thread_saved_fp(task), - thread_saved_pc(task)); - - walk_stackframe(task, &frame, consume_entry, cookie); } #endif From patchwork Fri Oct 15 02:34:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhavan T. Venkataraman" X-Patchwork-Id: 12559761 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA315C433EF for ; Fri, 15 Oct 2021 02:39:41 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B2A8E610D1 for ; Fri, 15 Oct 2021 02:39:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B2A8E610D1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CyPQ0l0/ldhM1hdezxteQ1PcAEz1vVmlFg9syNHwE94=; b=Jh8qmPV5IGWPXp GyfivtSCJsSfzk319Cg3E4TEoNjP+LqBv+flrUNxGvFPl4ARgD2OfLDzsX59+c4hMU7ElSH0lJe+l K6wJMBr0LtN3zhN/9TkJ/A4bbz5Vtt7Wn8RgsMKzrbt3upVflD0G3N7mhSCBCeHkCIudhIIFSVMEb y+y7d7zbW7huvdiYby1ia9eyy8idmpXMJtxzdxvw2z5hrdg5YFtK0zMKdu4+nhO5uk7dK+T4MC8T1 CEtgJatZbRNtj+flK5lzJWxtj8RJGWXD/l2/Pv/RYf1UuuSKBTNp8zhl0q8KtzYqqA1KFCBzkMTIo NVYzWNSt38o8TaLZ9Fzg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD6z-0055zA-D8; Fri, 15 Oct 2021 02:38:21 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD3m-0054MR-Os for linux-arm-kernel@lists.infradead.org; Fri, 15 Oct 2021 02:35:04 +0000 Received: from x64host.home (unknown [47.187.212.181]) by linux.microsoft.com (Postfix) with ESMTPSA id BA0DD20B9D16; Thu, 14 Oct 2021 19:35:01 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com BA0DD20B9D16 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1634265302; bh=6bWkd/ZYo9iwC5D6ljtnqzr8MoO2MeG2exKw7wTf0A8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GVws1lANiCyiwHZ1Cfqa2x0UtsBpNg8ndLPRiI3HawTCH0uUp7LWmAp0wW14EA/fn xXhuXp0880Rs2+9WSAVpUpJRT0zkYoi4+zzKZdnlh6pe/h8x+hWguXAAjr5JgbHuq6 VxHIN8HOn+k8TAh1QLgGAA8oxPtz7kadg3Nqwwvk= From: madvenka@linux.microsoft.com To: mark.rutland@arm.com, broonie@kernel.org, jpoimboe@redhat.com, ardb@kernel.org, nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com, catalin.marinas@arm.com, will@kernel.org, jmorris@namei.org, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, madvenka@linux.microsoft.com Subject: [PATCH v9 08/11] arm64: Rename unwinder functions, prevent them from being traced and kprobed Date: Thu, 14 Oct 2021 21:34:12 -0500 Message-Id: <20211015023413.16614-11-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211015023413.16614-1-madvenka@linux.microsoft.com> References: <20211015023413.16614-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211014_193502_912993_CEA69C2E X-CRM114-Status: GOOD ( 15.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "Madhavan T. Venkataraman" Rename unwinder functions for consistency and better naming. - Rename start_backtrace() to unwind_start(). - Rename unwind_frame() to unwind_next(). - Rename walk_stackframe() to unwind(). Prevent the following unwinder functions from being traced: - unwind_start() - unwind_next() unwind() is already prevented from being traced. Prevent the following unwinder functions from being kprobed: - unwind_start() unwind_next() and unwind() are already prevented from being kprobed. Signed-off-by: Madhavan T. Venkataraman --- arch/arm64/kernel/stacktrace.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 7d32cee9ef4b..f4f3575f71fd 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -33,8 +33,8 @@ */ -static void start_backtrace(struct stackframe *frame, unsigned long fp, - unsigned long pc) +static void notrace unwind_start(struct stackframe *frame, unsigned long fp, + unsigned long pc) { frame->fp = fp; frame->pc = pc; @@ -45,7 +45,7 @@ static void start_backtrace(struct stackframe *frame, unsigned long fp, /* * Prime the first unwind. * - * In unwind_frame() we'll check that the FP points to a valid stack, + * In unwind_next() we'll check that the FP points to a valid stack, * which can't be STACK_TYPE_UNKNOWN, and the first unwind will be * treated as a transition to whichever stack that happens to be. The * prev_fp value won't be used, but we set it to 0 such that it is @@ -56,6 +56,8 @@ static void start_backtrace(struct stackframe *frame, unsigned long fp, frame->prev_type = STACK_TYPE_UNKNOWN; } +NOKPROBE_SYMBOL(unwind_start); + /* * Unwind from one frame record (A) to the next frame record (B). * @@ -63,8 +65,8 @@ static void start_backtrace(struct stackframe *frame, unsigned long fp, * records (e.g. a cycle), determined based on the location and fp value of A * and the location (but not the fp value) of B. */ -static int notrace unwind_frame(struct task_struct *tsk, - struct stackframe *frame) +static int notrace unwind_next(struct task_struct *tsk, + struct stackframe *frame) { unsigned long fp = frame->fp; struct stack_info info; @@ -104,7 +106,7 @@ static int notrace unwind_frame(struct task_struct *tsk, /* * Record this frame record's values and location. The prev_fp and - * prev_type are only meaningful to the next unwind_frame() invocation. + * prev_type are only meaningful to the next unwind_next() invocation. */ frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp)); frame->pc = READ_ONCE_NOCHECK(*(unsigned long *)(fp + 8)); @@ -132,28 +134,30 @@ static int notrace unwind_frame(struct task_struct *tsk, return 0; } -NOKPROBE_SYMBOL(unwind_frame); -static void notrace walk_stackframe(struct task_struct *tsk, - unsigned long fp, unsigned long pc, - bool (*fn)(void *, unsigned long), - void *data) +NOKPROBE_SYMBOL(unwind_next); + +static void notrace unwind(struct task_struct *tsk, + unsigned long fp, unsigned long pc, + bool (*fn)(void *, unsigned long), + void *data) { struct stackframe frame; - start_backtrace(&frame, fp, pc); + unwind_start(&frame, fp, pc); while (1) { int ret; if (!fn(data, frame.pc)) break; - ret = unwind_frame(tsk, &frame); + ret = unwind_next(tsk, &frame); if (ret < 0) break; } } -NOKPROBE_SYMBOL(walk_stackframe); + +NOKPROBE_SYMBOL(unwind); static bool dump_backtrace_entry(void *arg, unsigned long where) { @@ -208,7 +212,7 @@ noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry, fp = thread_saved_fp(task); pc = thread_saved_pc(task); } - walk_stackframe(task, fp, pc, consume_entry, cookie); + unwind(task, fp, pc, consume_entry, cookie); } From patchwork Fri Oct 15 02:34:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhavan T. Venkataraman" X-Patchwork-Id: 12559763 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 102D7C433EF for ; Fri, 15 Oct 2021 02:40:48 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CAC9860E09 for ; Fri, 15 Oct 2021 02:40:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CAC9860E09 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7fYoXjJZjYxPq/XhblBr/5j+TBQS5GyJEwgvR0mscbk=; b=bsqoaOcoZ3oGCK wAO3IBXaiabFcUjwxWQ6MZRgcRcW+Ldt792SCvorKY5Kw1N91AIS6tl0S6D96WBCesutac61grWnS eNuQo3LyBNVuMcaKDV3jEYnpbHVC2tVvjJWp57rroCQhZ7Vdpx8wkW321rtLuAT93wtyBS0LNt3RH E6uED2X7Tu8X7G/38cGhx2/Eq92UpQOXLr/UuVbH1QB6PKJ+Escc3WcNbLD0EN82pit/IqIkp/sWd 1WSdOfqhelKuHi39iLCIuMqUNjY8UMvcaYkdQZO0ABps8bZlIOytDrhIdirYH42TbyW46gVYzftDw xlQINgUoL5UF2cwrgLfg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD7T-0056EN-Af; Fri, 15 Oct 2021 02:38:52 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD3n-0054Mz-RO for linux-arm-kernel@lists.infradead.org; Fri, 15 Oct 2021 02:35:05 +0000 Received: from x64host.home (unknown [47.187.212.181]) by linux.microsoft.com (Postfix) with ESMTPSA id CDA1620B9D1C; Thu, 14 Oct 2021 19:35:02 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com CDA1620B9D1C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1634265303; bh=57BcPNouzyU3TXGJbaeOWDPyH6v6sumOk7RFMlmMA60=; h=From:To:Subject:Date:In-Reply-To:References:From; b=NXvi169aT9nM+JwiUhCgxT0D4mfOcrQKBeiuqNVAxe0SCRcJqYyDu8v3KaseOvRpc OESiXg0go7QR9VWlcVAhkKQtj41EDVdel++VU0O8CD1ajK+enXqtrnUs19amFc8bbk R+7MGXeP1F9MYUoiDPqyOTSPr7++JX0+HBKk4u0Y= From: madvenka@linux.microsoft.com To: mark.rutland@arm.com, broonie@kernel.org, jpoimboe@redhat.com, ardb@kernel.org, nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com, catalin.marinas@arm.com, will@kernel.org, jmorris@namei.org, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, madvenka@linux.microsoft.com Subject: [PATCH v9 09/11] arm64: Make the unwind loop in unwind() similar to other architectures Date: Thu, 14 Oct 2021 21:34:13 -0500 Message-Id: <20211015023413.16614-12-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211015023413.16614-1-madvenka@linux.microsoft.com> References: <20211015023413.16614-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211014_193503_996596_F183BB78 X-CRM114-Status: GOOD ( 20.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "Madhavan T. Venkataraman" Change the loop in unwind() =========================== Change the unwind loop in unwind() to: unwind_start(&frame, fp, pc); while (unwind_continue(tsk, &frame, fn, data)) unwind_next(tsk, &frame); New function unwind_continue() ============================== Define a new function unwind_continue() that is used in the unwind loop to check for conditions that terminate a stack trace. The conditions checked are: - If the bottom of the stack has been reached, terminate. - If the consume_entry() function returns false, the caller of unwind has asked to terminate the stack trace. So, terminate. - If unwind_next() failed for some reason (like stack corruption), terminate. Do not return an error value from unwind_next() =============================================== We want to check for terminating conditions only in unwind_continue() from the unwinder loop. So, do not return an error value from unwind_next(). Simply set a flag in the stackframe and check the flag in unwind_continue(). Signed-off-by: Madhavan T. Venkataraman --- arch/arm64/include/asm/stacktrace.h | 3 ++ arch/arm64/kernel/stacktrace.c | 78 ++++++++++++++++++----------- 2 files changed, 53 insertions(+), 28 deletions(-) diff --git a/arch/arm64/include/asm/stacktrace.h b/arch/arm64/include/asm/stacktrace.h index c239f357d779..ba2180c7d5cd 100644 --- a/arch/arm64/include/asm/stacktrace.h +++ b/arch/arm64/include/asm/stacktrace.h @@ -49,6 +49,8 @@ struct stack_info { * * @graph: When FUNCTION_GRAPH_TRACER is selected, holds the index of a * replacement lr value in the ftrace graph stack. + * + * @failed: Unwind failed. */ struct stackframe { unsigned long fp; @@ -59,6 +61,7 @@ struct stackframe { #ifdef CONFIG_FUNCTION_GRAPH_TRACER int graph; #endif + bool failed; }; extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk, diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index f4f3575f71fd..8e9e6f38c975 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -54,6 +54,7 @@ static void notrace unwind_start(struct stackframe *frame, unsigned long fp, bitmap_zero(frame->stacks_done, __NR_STACK_TYPES); frame->prev_fp = 0; frame->prev_type = STACK_TYPE_UNKNOWN; + frame->failed = false; } NOKPROBE_SYMBOL(unwind_start); @@ -65,24 +66,26 @@ NOKPROBE_SYMBOL(unwind_start); * records (e.g. a cycle), determined based on the location and fp value of A * and the location (but not the fp value) of B. */ -static int notrace unwind_next(struct task_struct *tsk, - struct stackframe *frame) +static void notrace unwind_next(struct task_struct *tsk, + struct stackframe *frame) { unsigned long fp = frame->fp; struct stack_info info; - /* Final frame; nothing to unwind */ - if (fp == (unsigned long)task_pt_regs(tsk)->stackframe) - return -ENOENT; - - if (fp & 0x7) - return -EINVAL; + if (fp & 0x7) { + frame->failed = true; + return; + } - if (!on_accessible_stack(tsk, fp, 16, &info)) - return -EINVAL; + if (!on_accessible_stack(tsk, fp, 16, &info)) { + frame->failed = true; + return; + } - if (test_bit(info.type, frame->stacks_done)) - return -EINVAL; + if (test_bit(info.type, frame->stacks_done)) { + frame->failed = true; + return; + } /* * As stacks grow downward, any valid record on the same stack must be @@ -98,8 +101,10 @@ static int notrace unwind_next(struct task_struct *tsk, * stack. */ if (info.type == frame->prev_type) { - if (fp <= frame->prev_fp) - return -EINVAL; + if (fp <= frame->prev_fp) { + frame->failed = true; + return; + } } else { set_bit(frame->prev_type, frame->stacks_done); } @@ -124,19 +129,44 @@ static int notrace unwind_next(struct task_struct *tsk, * So replace it to an original value. */ ret_stack = ftrace_graph_get_ret_stack(tsk, frame->graph++); - if (WARN_ON_ONCE(!ret_stack)) - return -EINVAL; + if (WARN_ON_ONCE(!ret_stack)) { + frame->failed = true; + return; + } frame->pc = ret_stack->ret; } #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ frame->pc = ptrauth_strip_insn_pac(frame->pc); - - return 0; } NOKPROBE_SYMBOL(unwind_next); +static bool notrace unwind_continue(struct task_struct *task, + struct stackframe *frame, + stack_trace_consume_fn consume_entry, + void *cookie) +{ + if (frame->failed) { + /* PC is suspect. Cannot consume it. */ + return false; + } + + if (!consume_entry(cookie, frame->pc)) { + /* Caller terminated the unwind. */ + frame->failed = true; + return false; + } + + if (frame->fp == (unsigned long)task_pt_regs(task)->stackframe) { + /* Final frame; nothing to unwind */ + return false; + } + return true; +} + +NOKPROBE_SYMBOL(unwind_continue); + static void notrace unwind(struct task_struct *tsk, unsigned long fp, unsigned long pc, bool (*fn)(void *, unsigned long), @@ -145,16 +175,8 @@ static void notrace unwind(struct task_struct *tsk, struct stackframe frame; unwind_start(&frame, fp, pc); - - while (1) { - int ret; - - if (!fn(data, frame.pc)) - break; - ret = unwind_next(tsk, &frame); - if (ret < 0) - break; - } + while (unwind_continue(tsk, &frame, fn, data)) + unwind_next(tsk, &frame); } NOKPROBE_SYMBOL(unwind); From patchwork Fri Oct 15 02:34:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhavan T. Venkataraman" X-Patchwork-Id: 12559743 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65EA2C433EF for ; Fri, 15 Oct 2021 02:36:25 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3206761039 for ; Fri, 15 Oct 2021 02:36:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3206761039 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SOq1lTR1RS6Yll5tqifujr6OsAjxH2sXN7NdDEDOMNo=; b=4Hzrib3b7RSdfP 2ViIslYkWQDNSU7lldYb8F2ZFCu10VUksN2wct9Vq6wLbxK3qvRoPRk5v9ZUSw0Rw9fniwwQ46aXh S+XJHIFL4x9UcRYUlvQpwdQ3DSdWMhpYiyl6uDsTXdByvpSq1fzJ5urYT6/IQcw3czmNhoN0adnZM YwKNysn4WYbBtVmx/DJg3uMyAwjQweYEA+xKBPoQwv6nYx7wgG89XzXHL5L4mDfQqy9m/DnGjO3tr CDP4kZuQY637r9HKU5W1QHmGxw6P4DMJhcxQNEs2+KpoWePJTh5qu6YreWZ0urcdllcrM7ccLESeR glEozIFGFuvAlC/GDFXg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD3w-0054TI-7y; Fri, 15 Oct 2021 02:35:12 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD3e-0054Kw-Ee for linux-arm-kernel@lists.infradead.org; Fri, 15 Oct 2021 02:34:56 +0000 Received: from x64host.home (unknown [47.187.212.181]) by linux.microsoft.com (Postfix) with ESMTPSA id 2595420B9D1D; Thu, 14 Oct 2021 19:34:53 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2595420B9D1D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1634265294; bh=LkJybEj9FMuSQymj/zVROIuX/DLBwHm7LAFTUmAbltw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Jpq9IvPmgK9EWXIiC7A2SrWLIOQ3qVEdf8+lbUrwmEbuZRBb3AoPT0Hk8tRBwX9E9 wEq4TIEQu5OBz4Y1Y3SNHCH+NDyqhrEbM5fViU4BNTOBgarEvMb7iJCTA4DAyxe3pi LIlzDFPoay2BPbmlmFxmZnQ+Bl7VYTgIv0Pfdi/w= From: madvenka@linux.microsoft.com To: mark.rutland@arm.com, broonie@kernel.org, jpoimboe@redhat.com, ardb@kernel.org, nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com, catalin.marinas@arm.com, will@kernel.org, jmorris@namei.org, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, madvenka@linux.microsoft.com Subject: [PATCH v9 10/11] arm64: Introduce stack trace reliability checks in the unwinder Date: Thu, 14 Oct 2021 21:34:04 -0500 Message-Id: <20211015023413.16614-3-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211015023413.16614-1-madvenka@linux.microsoft.com> References: <20211015023413.16614-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211014_193454_592303_821F70FC X-CRM114-Status: GOOD ( 21.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "Madhavan T. Venkataraman" There are some kernel features and conditions that make a stack trace unreliable. Callers may require the unwinder to detect these cases. E.g., livepatch. Introduce a new function called unwind_check_reliability() that will detect these cases and set a flag in the stack frame. Call unwind_check_reliability() for every frame, that is, in unwind_start() and unwind_next(). Introduce the first reliability check in unwind_check_reliability() - If a return PC is not a valid kernel text address, consider the stack trace unreliable. It could be some generated code. Other reliability checks will be added in the future. Let unwind() return a boolean to indicate if the stack trace is reliable. Introduce arch_stack_walk_reliable() for ARM64. This works like arch_stack_walk() except that it returns -EINVAL if the stack trace is not reliable. Until all the reliability checks are in place, arch_stack_walk_reliable() may not be used by livepatch. But it may be used by debug and test code. Signed-off-by: Madhavan T. Venkataraman --- arch/arm64/include/asm/stacktrace.h | 3 ++ arch/arm64/kernel/stacktrace.c | 48 ++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/stacktrace.h b/arch/arm64/include/asm/stacktrace.h index ba2180c7d5cd..ce0710fa3037 100644 --- a/arch/arm64/include/asm/stacktrace.h +++ b/arch/arm64/include/asm/stacktrace.h @@ -51,6 +51,8 @@ struct stack_info { * replacement lr value in the ftrace graph stack. * * @failed: Unwind failed. + * + * @reliable: Stack trace is reliable. */ struct stackframe { unsigned long fp; @@ -62,6 +64,7 @@ struct stackframe { int graph; #endif bool failed; + bool reliable; }; extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk, diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 8e9e6f38c975..142f08ae515f 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -18,6 +18,22 @@ #include #include +/* + * Check the stack frame for conditions that make further unwinding unreliable. + */ +static void notrace unwind_check_reliability(struct stackframe *frame) +{ + /* + * If the PC is not a known kernel text address, then we cannot + * be sure that a subsequent unwind will be reliable, as we + * don't know that the code follows our unwind requirements. + */ + if (!__kernel_text_address(frame->pc)) + frame->reliable = false; +} + +NOKPROBE_SYMBOL(unwind_check_reliability); + /* * AArch64 PCS assigns the frame pointer to x29. * @@ -55,6 +71,8 @@ static void notrace unwind_start(struct stackframe *frame, unsigned long fp, frame->prev_fp = 0; frame->prev_type = STACK_TYPE_UNKNOWN; frame->failed = false; + frame->reliable = true; + unwind_check_reliability(frame); } NOKPROBE_SYMBOL(unwind_start); @@ -138,6 +156,7 @@ static void notrace unwind_next(struct task_struct *tsk, #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ frame->pc = ptrauth_strip_insn_pac(frame->pc); + unwind_check_reliability(frame); } NOKPROBE_SYMBOL(unwind_next); @@ -167,7 +186,7 @@ static bool notrace unwind_continue(struct task_struct *task, NOKPROBE_SYMBOL(unwind_continue); -static void notrace unwind(struct task_struct *tsk, +static bool notrace unwind(struct task_struct *tsk, unsigned long fp, unsigned long pc, bool (*fn)(void *, unsigned long), void *data) @@ -177,6 +196,7 @@ static void notrace unwind(struct task_struct *tsk, unwind_start(&frame, fp, pc); while (unwind_continue(tsk, &frame, fn, data)) unwind_next(tsk, &frame); + return frame.reliable; } NOKPROBE_SYMBOL(unwind); @@ -238,4 +258,30 @@ noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry, } +/* + * arch_stack_walk_reliable() may not be used for livepatch until all of + * the reliability checks are in place in unwind_consume(). However, + * debug and test code can choose to use it even if all the checks are not + * in place. + */ +noinline int notrace arch_stack_walk_reliable(stack_trace_consume_fn consume_fn, + void *cookie, + struct task_struct *task) +{ + unsigned long fp, pc; + + if (task == current) { + /* Skip arch_stack_walk_reliable() in the stack trace. */ + fp = (unsigned long)__builtin_frame_address(1); + pc = (unsigned long)__builtin_return_address(0); + } else { + /* Caller guarantees that the task is not running. */ + fp = thread_saved_fp(task); + pc = thread_saved_pc(task); + } + if (unwind(task, fp, pc, consume_fn, cookie)) + return 0; + return -EINVAL; +} + #endif From patchwork Fri Oct 15 02:34:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhavan T. Venkataraman" X-Patchwork-Id: 12559745 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69203C433EF for ; Fri, 15 Oct 2021 02:36:50 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3257461039 for ; Fri, 15 Oct 2021 02:36:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3257461039 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=AI7pJN/6LOQAhnXRrMRsmtf7Q30WwlXts8Tmeo4OTkc=; b=MMMXX/8Ri2oINx o1FTjwXOoGZbSfXAKu551kD1H31gXdc4zXbS2AnjGQ6TJNU6cuFv8wgdgDhdy/b/a8vZ+CZD7eTAB xCxHZWCV9b1ZmIUXC+tSaFBwYvCViqgAw9yK9Nu3Z+i8qDaEh8tHVThKqlsipGcWd1wbOCDQlfeBA Ruk0PQ8u+WeFyrqyY0sGR7qzE6juSQuwJQgB5SA65h7H3dihxNABQdVAxHByx68FQlCwlCcWbk1HM izpvJHMuS9lAa/JEhNkgyEs7jWtgsraEy6/yAieaN89c2uDsVeEMmc1fvlEgtVN4fNnO5sH6g7kVK gQEqaYS9i35aNkoo/vbw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD4A-0054Xj-OH; Fri, 15 Oct 2021 02:35:26 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mbD3f-0054Lv-JL for linux-arm-kernel@lists.infradead.org; Fri, 15 Oct 2021 02:34:57 +0000 Received: from x64host.home (unknown [47.187.212.181]) by linux.microsoft.com (Postfix) with ESMTPSA id 381C920B9D1E; Thu, 14 Oct 2021 19:34:54 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 381C920B9D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1634265295; bh=kf57gBPyYShD4NkDAxb6KRwdylhexezlNMblj+oE9gY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Owr1a+lwGxT0wdjI1wstYlndxf1K3QtzPWbfk+QbxcgGVtBvQc0XdW7ZF+Geq6Gkk 5XuWju8J2qBJEMAfet6P5XeZHbA5JO+LrkNDTC02Vu4CvKqq6PI+uMAEPMIv88dYKA 4Sr9fgLUDz70xCq7oYEWzGQ2NWw29csRVbGqDd9I= From: madvenka@linux.microsoft.com To: mark.rutland@arm.com, broonie@kernel.org, jpoimboe@redhat.com, ardb@kernel.org, nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com, catalin.marinas@arm.com, will@kernel.org, jmorris@namei.org, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, madvenka@linux.microsoft.com Subject: [PATCH v9 11/11] arm64: Create a list of SYM_CODE functions, check return PC against list Date: Thu, 14 Oct 2021 21:34:05 -0500 Message-Id: <20211015023413.16614-4-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211015023413.16614-1-madvenka@linux.microsoft.com> References: <20211015023413.16614-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211014_193455_716383_F67289B5 X-CRM114-Status: GOOD ( 20.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "Madhavan T. Venkataraman" SYM_CODE functions don't follow the usual calling conventions. Check if the return PC in a stack frame falls in any of these. If it does, consider the stack trace unreliable. Define a special section for unreliable functions ================================================= Define a SYM_CODE_END() macro for arm64 that adds the function address range to a new section called "sym_code_functions". Linker file =========== Include the "sym_code_functions" section under read-only data in vmlinux.lds.S. Initialization ============== Define an early_initcall() to create a sym_code_functions[] array from the linker data. Unwinder check ============== Add a reliability check in unwind_is_reliable() that compares a return PC with sym_code_functions[]. If there is a match, then return failure. Signed-off-by: Madhavan T. Venkataraman --- arch/arm64/include/asm/linkage.h | 12 +++++++ arch/arm64/include/asm/sections.h | 1 + arch/arm64/kernel/stacktrace.c | 55 +++++++++++++++++++++++++++++++ arch/arm64/kernel/vmlinux.lds.S | 10 ++++++ 4 files changed, 78 insertions(+) diff --git a/arch/arm64/include/asm/linkage.h b/arch/arm64/include/asm/linkage.h index 9906541a6861..616bad74e297 100644 --- a/arch/arm64/include/asm/linkage.h +++ b/arch/arm64/include/asm/linkage.h @@ -68,4 +68,16 @@ SYM_FUNC_END_ALIAS(x); \ SYM_FUNC_END_ALIAS(__pi_##x) +/* + * Record the address range of each SYM_CODE function in a struct code_range + * in a special section. + */ +#define SYM_CODE_END(name) \ + SYM_END(name, SYM_T_NONE) ;\ + 99: ;\ + .pushsection "sym_code_functions", "aw" ;\ + .quad name ;\ + .quad 99b ;\ + .popsection + #endif diff --git a/arch/arm64/include/asm/sections.h b/arch/arm64/include/asm/sections.h index e4ad9db53af1..c84c71063d6e 100644 --- a/arch/arm64/include/asm/sections.h +++ b/arch/arm64/include/asm/sections.h @@ -21,5 +21,6 @@ extern char __exittext_begin[], __exittext_end[]; extern char __irqentry_text_start[], __irqentry_text_end[]; extern char __mmuoff_data_start[], __mmuoff_data_end[]; extern char __entry_tramp_text_start[], __entry_tramp_text_end[]; +extern char __sym_code_functions_start[], __sym_code_functions_end[]; #endif /* __ASM_SECTIONS_H */ diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 142f08ae515f..40e5af7e5b1d 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -18,11 +18,40 @@ #include #include +struct code_range { + unsigned long start; + unsigned long end; +}; + +static struct code_range *sym_code_functions; +static int num_sym_code_functions; + +int __init init_sym_code_functions(void) +{ + size_t size = (unsigned long)__sym_code_functions_end - + (unsigned long)__sym_code_functions_start; + + sym_code_functions = (struct code_range *)__sym_code_functions_start; + /* + * Order it so that sym_code_functions is not visible before + * num_sym_code_functions. + */ + smp_mb(); + num_sym_code_functions = size / sizeof(struct code_range); + + return 0; +} +early_initcall(init_sym_code_functions); + /* * Check the stack frame for conditions that make further unwinding unreliable. */ static void notrace unwind_check_reliability(struct stackframe *frame) { + const struct code_range *range; + unsigned long pc; + int i; + /* * If the PC is not a known kernel text address, then we cannot * be sure that a subsequent unwind will be reliable, as we @@ -30,6 +59,32 @@ static void notrace unwind_check_reliability(struct stackframe *frame) */ if (!__kernel_text_address(frame->pc)) frame->reliable = false; + + /* + * Check the return PC against sym_code_functions[]. If there is a + * match, then the consider the stack frame unreliable. + * + * As SYM_CODE functions don't follow the usual calling conventions, + * we assume by default that any SYM_CODE function cannot be unwound + * reliably. + * + * Note that this includes: + * + * - Exception handlers and entry assembly + * - Trampoline assembly (e.g., ftrace, kprobes) + * - Hypervisor-related assembly + * - Hibernation-related assembly + * - CPU start-stop, suspend-resume assembly + * - Kernel relocation assembly + */ + pc = frame->pc; + for (i = 0; i < num_sym_code_functions; i++) { + range = &sym_code_functions[i]; + if (pc >= range->start && pc < range->end) { + frame->reliable = false; + return; + } + } } NOKPROBE_SYMBOL(unwind_check_reliability); diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 709d2c433c5e..2bf769f45b54 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -111,6 +111,14 @@ jiffies = jiffies_64; #define TRAMP_TEXT #endif +#define SYM_CODE_FUNCTIONS \ + . = ALIGN(16); \ + .symcode : AT(ADDR(.symcode) - LOAD_OFFSET) { \ + __sym_code_functions_start = .; \ + KEEP(*(sym_code_functions)) \ + __sym_code_functions_end = .; \ + } + /* * The size of the PE/COFF section that covers the kernel image, which * runs from _stext to _edata, must be a round multiple of the PE/COFF @@ -196,6 +204,8 @@ SECTIONS swapper_pg_dir = .; . += PAGE_SIZE; + SYM_CODE_FUNCTIONS + . = ALIGN(SEGMENT_ALIGN); __init_begin = .; __inittext_begin = .;