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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A9A8C43334 for ; Mon, 27 Jun 2022 04:51:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231263AbiF0Ev3 (ORCPT ); Mon, 27 Jun 2022 00:51:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229492AbiF0EvZ (ORCPT ); Mon, 27 Jun 2022 00:51:25 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1EF712705; Sun, 26 Jun 2022 21:51:25 -0700 (PDT) Received: from [192.168.254.32] (unknown [47.189.24.195]) by linux.microsoft.com (Postfix) with ESMTPSA id 231E520CD15B; Sun, 26 Jun 2022 21:51:24 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 231E520CD15B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1656305484; bh=zJFEWu/Ud5uhM7/kCBl+rRwn01K5hofR9WJ1WLBTFIs=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=cwWB26CikCmaS8BVl64CjxUO7fTwCGHagFWS8ri96VfThaXNyXza+foJ8VVL8jiWJ qQcABmATn0wp7cDxRZ7tSdw6piJdA4xnQYugd8CeQNryNabUOmgDOisWYUKATD9Z4G ojWZhIGksU+JBUDi0ZOybg73xYApOErwyYjK4Efg= Message-ID: <0c31a02c-183e-cac6-8826-82330c6fd830@linux.microsoft.com> Date: Sun, 26 Jun 2022 23:51:23 -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 3/6] arm64: Make the unwind loop in unwind() similar to other architectures 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-4-madvenka@linux.microsoft.com> From: "Madhavan T. Venkataraman" In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/26/22 03:21, Mark Rutland wrote: > On Fri, Jun 17, 2022 at 04:07:14PM -0500, madvenka@linux.microsoft.com wrote: >> From: "Madhavan T. Venkataraman" >> >> Change the loop in unwind() >> =========================== >> >> Change the unwind loop in unwind() to: >> >> while (unwind_continue(state, consume_entry, cookie)) >> unwind_next(state); >> >> This is easy to understand and maintain. >> 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 (final frame) 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. > > I'm a bit confused as to why this structure, since AFAICT this doesn't match > other architectures (looking at x86, powerpc, and s390). I note that x86 has: > > * In arch_stack_walk(): > > for (unwind_start(&state, task, regs, NULL); !unwind_done(&state); > unwind_next_frame(&state)) { > ... > if (!consume_entry(...)) > break; > ... > } > > * In arch_stack_walk_reliable(): > > for (unwind_start(&state, task, NULL, NULL); > !unwind_done(&state) && !unwind_error(&state); > unwind_next_frame(&state)) { > ... > if (!consume_entry(...) > return -EINVAL; > } > > ... and back in v6 I suggeted exactly that shape: > > https://lore.kernel.org/linux-arm-kernel/20210728165635.GA47345@C02TD0UTHF1T.local/ > OK. I will take a look at your suggestion and resend this patch. >> >> 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 unwind_state and check the flag in unwind_continue(). > > I'm fine with the concept of moving ghe return value out of unwind_next() (e.g. > if we go with an x86-like structure), but I don't think that we should > centralize the other checks *and* the consumption within unwind_continue(), as > I think those are two separate things. > OK. I will address this in the next version. >> >> Final FP >> ======== >> >> Introduce a new field "final_fp" in "struct unwind_state". Initialize this >> to the final frame of the stack trace: >> >> task_pt_regs(task)->stackframe >> >> This is where the stacktrace must terminate if it is successful. Add an >> explicit comment to that effect. > > Can we please make this change as a preparatory step, as with the 'task' field? > > We can wrap this in a helper like: > > static bool is_final_frame(struct unwind state *state) > { > return state->fp == state->final_fp; > } > > ... and use that in the main loop. > OK. I will make these changes. Thanks. Madhavan 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 57AC6C43334 for ; Mon, 27 Jun 2022 04:52:29 +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=w9LN5jfr90gTk434PTIASYXNBYVJS0Fy7SbJYXHWq28=; b=HnUBDx6oc04/ph 855NCXaf/VGF+QN51TevcKI72Sy0f4xLQZHK2UJtwGeDTB6KlF6VpQnY+Ji7ex5OQoAENUWq5Ckzc LSYfWNOMa4XmUBu4YNhgsUtUR4p+38N+7Wmgu3hc66oA+QZjc1pghPsNBjtxaL2lW2P1mcLX706Eg xG0wvzMH781dLMnlKMQhpDx1z/PXXtMjUJW36AZlja7qeFllReKLkTgwZwZciWERzS6Ztp4Ecvr9J sOt09NMjYoZq16dfTcuHyRf/y5fPYcQ/sLnT1T/zkd5bzDVASIeZLmuvc/5DMPXelwx0SWlmEXQQH iVl0+/ZDJsMcPWWDziVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o5gif-00FQe2-JC; Mon, 27 Jun 2022 04:51:29 +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 1o5gib-00FQcR-FE for linux-arm-kernel@lists.infradead.org; Mon, 27 Jun 2022 04:51:26 +0000 Received: from [192.168.254.32] (unknown [47.189.24.195]) by linux.microsoft.com (Postfix) with ESMTPSA id 231E520CD15B; Sun, 26 Jun 2022 21:51:24 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 231E520CD15B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1656305484; bh=zJFEWu/Ud5uhM7/kCBl+rRwn01K5hofR9WJ1WLBTFIs=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=cwWB26CikCmaS8BVl64CjxUO7fTwCGHagFWS8ri96VfThaXNyXza+foJ8VVL8jiWJ qQcABmATn0wp7cDxRZ7tSdw6piJdA4xnQYugd8CeQNryNabUOmgDOisWYUKATD9Z4G ojWZhIGksU+JBUDi0ZOybg73xYApOErwyYjK4Efg= Message-ID: <0c31a02c-183e-cac6-8826-82330c6fd830@linux.microsoft.com> Date: Sun, 26 Jun 2022 23:51:23 -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 3/6] arm64: Make the unwind loop in unwind() similar to other architectures 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-4-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_215125_621552_AF739001 X-CRM114-Status: GOOD ( 25.23 ) 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:21, Mark Rutland wrote: > On Fri, Jun 17, 2022 at 04:07:14PM -0500, madvenka@linux.microsoft.com wrote: >> From: "Madhavan T. Venkataraman" >> >> Change the loop in unwind() >> =========================== >> >> Change the unwind loop in unwind() to: >> >> while (unwind_continue(state, consume_entry, cookie)) >> unwind_next(state); >> >> This is easy to understand and maintain. >> 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 (final frame) 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. > > I'm a bit confused as to why this structure, since AFAICT this doesn't match > other architectures (looking at x86, powerpc, and s390). I note that x86 has: > > * In arch_stack_walk(): > > for (unwind_start(&state, task, regs, NULL); !unwind_done(&state); > unwind_next_frame(&state)) { > ... > if (!consume_entry(...)) > break; > ... > } > > * In arch_stack_walk_reliable(): > > for (unwind_start(&state, task, NULL, NULL); > !unwind_done(&state) && !unwind_error(&state); > unwind_next_frame(&state)) { > ... > if (!consume_entry(...) > return -EINVAL; > } > > ... and back in v6 I suggeted exactly that shape: > > https://lore.kernel.org/linux-arm-kernel/20210728165635.GA47345@C02TD0UTHF1T.local/ > OK. I will take a look at your suggestion and resend this patch. >> >> 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 unwind_state and check the flag in unwind_continue(). > > I'm fine with the concept of moving ghe return value out of unwind_next() (e.g. > if we go with an x86-like structure), but I don't think that we should > centralize the other checks *and* the consumption within unwind_continue(), as > I think those are two separate things. > OK. I will address this in the next version. >> >> Final FP >> ======== >> >> Introduce a new field "final_fp" in "struct unwind_state". Initialize this >> to the final frame of the stack trace: >> >> task_pt_regs(task)->stackframe >> >> This is where the stacktrace must terminate if it is successful. Add an >> explicit comment to that effect. > > Can we please make this change as a preparatory step, as with the 'task' field? > > We can wrap this in a helper like: > > static bool is_final_frame(struct unwind state *state) > { > return state->fp == state->final_fp; > } > > ... and use that in the main loop. > OK. I will make these changes. Thanks. Madhavan _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel