From mboxrd@z Thu Jan 1 00:00:00 1970 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id D7F16C433EF for ; Mon, 27 Jun 2022 05:23:01 +0000 (UTC) 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:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RrfdmqGA3Mq4JG37FPH29LzG+vAOKke9zhl4pKxlykE=; b=kmUYTqQQAH+TDc KbWnQav15dzqbkZcQmKdZ+Jp08aPg6xEAaUZZf2blkOSq+qgiE2/jl1KRM/dQW+p61NKjRUSFq6LE w2xSqbaY2xTPOjixyCmvmnG3mhm6Hz3ajDf3zROijaF3M4ZLoi/UvjFqETpG9mu6Jx/9pJVnwMv9O RWUYszNKzkDSlisflFCY6i/FyR7/sAj8VVEFkd++aiCHm3PEHJZhNQHo9LFR2dMhhSUNpQpcxH7zS Yj4U8uDPyxI6Z+HNpJ/Hy8oFUNzOpTs9BoQehGMBzWJpvduS9BccMlq8mpLNLYgTdQET7PNbY2DxX nrVEiCF63y/iXq9YKaFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o5hBz-00FiG6-6G; Mon, 27 Jun 2022 05:21:47 +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 1o5gxX-00FYVS-IK for linux-arm-kernel@lists.infradead.org; Mon, 27 Jun 2022 05:06:53 +0000 Received: from [192.168.254.32] (unknown [47.189.24.195]) by linux.microsoft.com (Postfix) with ESMTPSA id 2ED8420CD15E; Sun, 26 Jun 2022 22:06:50 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2ED8420CD15E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1656306410; bh=ptE65eWw/KVf5Qv9m3tSe+Guw7shYAImcZXGyiZYlag=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=PcaGdrYf2ecurMB+zVTYzcBYlK1W8lxfYe46xnDkz9Rdk1XDznscP4qL7Dm468bnV achw3aNfsJrb3r/0tj99oH90bMbZvQFgUbTA2bM26K9ui4Te5vY/Fi7PLD33y5Rkm9 kYUZRsIvif3JNe5wFpsFFjCUuN9FQhU1O0UUQ1VA= Message-ID: <8c64f0f4-be71-c462-5b74-34a4236265ae@linux.microsoft.com> Date: Mon, 27 Jun 2022 00:06:49 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH v15 5/6] arm64: Create a list of SYM_CODE functions, check return PC against list Content-Language: en-US To: Mark Rutland Cc: broonie@kernel.org, jpoimboe@redhat.com, ardb@kernel.org, nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com, catalin.marinas@arm.com, will@kernel.org, jamorris@linux.microsoft.com, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220617210717.27126-1-madvenka@linux.microsoft.com> <20220617210717.27126-6-madvenka@linux.microsoft.com> From: "Madhavan T. Venkataraman" In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220626_220651_719160_5CCFD9BD X-CRM114-Status: GOOD ( 24.41 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 6/26/22 03:46, Mark Rutland wrote: > On Fri, Jun 17, 2022 at 04:07:16PM -0500, madvenka@linux.microsoft.com wrote: >> 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_check_reliability() that compares a >> return PC with sym_code_functions[]. If there is a match, then return >> failure. >> >> Signed-off-by: Madhavan T. Venkataraman >> Reviewed-by: Mark Brown >> --- >> arch/arm64/include/asm/linkage.h | 11 +++++++ >> arch/arm64/include/asm/sections.h | 1 + >> arch/arm64/kernel/stacktrace.c | 55 +++++++++++++++++++++++++++++++ >> arch/arm64/kernel/vmlinux.lds.S | 10 ++++++ >> 4 files changed, 77 insertions(+) >> >> diff --git a/arch/arm64/include/asm/linkage.h b/arch/arm64/include/asm/linkage.h >> index 43f8c25b3fda..d4058de4af78 100644 >> --- a/arch/arm64/include/asm/linkage.h >> +++ b/arch/arm64/include/asm/linkage.h >> @@ -39,4 +39,15 @@ >> SYM_START(name, SYM_L_WEAK, SYM_A_NONE) \ >> bti c ; >> >> +/* >> + * 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 40971ac1303f..50cfd1083563 100644 >> --- a/arch/arm64/include/asm/sections.h >> +++ b/arch/arm64/include/asm/sections.h >> @@ -22,6 +22,7 @@ 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 __relocate_new_kernel_start[], __relocate_new_kernel_end[]; >> +extern char __sym_code_functions_start[], __sym_code_functions_end[]; >> >> static inline size_t entry_tramp_text_size(void) >> { >> diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c >> index 5ef2ce217324..eda8581f7dbe 100644 >> --- a/arch/arm64/kernel/stacktrace.c >> +++ b/arch/arm64/kernel/stacktrace.c >> @@ -62,6 +62,31 @@ struct unwind_state { >> bool reliable; >> }; >> >> +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); > > There's no reason to need an initcall for this; we can iterate over this > directly using __sym_code_functions_start and __sym_code_functions_end, like we > do for exception tables today. > > For example: > > static inline bool pc_is_sym_code(unsigned long pc) > { > extern struct code_range *__sym_code_functions_start; > extern struct code_range *__sym_code_functions_end; > > struct code_range *r; > > for (r = __sym_code_functions_start; r < __sym_code_functions_end; r++) { > if (pc >= r->start && pc < r->end) > return true; > } > > return false; > } > OK. However, I have decided to hold off on the reliability checks until we have the right structure in the unwind code. I am also trying to address the question of reliability with a single FP check in my FP validation series. So, for now, I will remove the reliability checks part of the patch series. Thanks for the review though. It will be useful when I revisit this in the future and resend. Thanks. Madhavan _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel