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 91426C77B7E for ; Tue, 2 May 2023 09:28:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232197AbjEBJ20 (ORCPT ); Tue, 2 May 2023 05:28:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231608AbjEBJ2Z (ORCPT ); Tue, 2 May 2023 05:28:25 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9293649FD for ; Tue, 2 May 2023 02:28:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ymeGyQcQ5L6pzQfIN9yTyCN3fMPxDHp/QtchOuiZ5+w=; b=dOFwjQ6fVaXYuKWYYBS4aFBVZ5 a4XDX8m3SDnVGRdZF+5VNMdexc6I77iPejaL7F58eSg5p4VlfezIRbU5wMysnETTySsc4Gm0nazN9 kidy6lvVqf7o/k0fyzNurJG1qA5zA2MQiuJFKKOJZR4l4rPg3mPCbCPqNNVQth1P4CccvIGeMnGsO HaMT5BbritUQgBJV/CC2jJg800PkTXkFxawfAI+GduVFrojHPZ6a9rJJkoO8uYwlITtxTYOzeb6qB issCIVVkTtSXe7/BfVbxg8WC/3ecF6F/XMdmakO+pBFocw9be5t8MgR2iAdsIiWnwZRuxvRUY35mJ KkoHWwOw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1ptmIt-00GGpc-1a; Tue, 02 May 2023 09:28:11 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 82860300348; Tue, 2 May 2023 11:28:10 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 66A6023C5C34D; Tue, 2 May 2023 11:28:10 +0200 (CEST) Date: Tue, 2 May 2023 11:28:10 +0200 From: Peter Zijlstra To: Indu Bhagat Cc: linux-toolchains@vger.kernel.org, daandemeyer@meta.com, andrii@kernel.org, rostedt@goodmis.org, kris.van.hees@oracle.com, elena.zannoni@oracle.com, nick.alcock@oracle.com Subject: Re: [POC 3/5] sframe: add new SFrame library Message-ID: <20230502092810.GK1597476@hirez.programming.kicks-ass.net> References: <20230501200410.3973453-1-indu.bhagat@oracle.com> <20230501200410.3973453-4-indu.bhagat@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230501200410.3973453-4-indu.bhagat@oracle.com> Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.org On Mon, May 01, 2023 at 01:04:08PM -0700, Indu Bhagat wrote: > +int sframe_sec_find_fre(struct sframe_sec *sfsec, int32_t pc, > + struct sframe_fre *frep) > +{ > + struct sframe_func_desc_entry *fdep; > + uint32_t start_address, i; > + struct sframe_fre cur_fre, next_fre; > + unsigned char *fres; > + unsigned int fre_type, fde_type; > + size_t esz; > + int err = 0; > + size_t size = 0; > + /* > + * For regular FDEs(i.e. fde_type SFRAME_FDE_TYPE_PCINC), > + * where the start address in the FRE is an offset from start pc, > + * use a bitmask with all bits set so that none of the address bits are > + * ignored. In this case, we need to return the FRE where > + * (PC >= FRE_START_ADDR). > + */ > + uint64_t bitmask = 0xffffffff; > + > + if ((sfsec == NULL) || (frep == NULL)) > + return SFRAME_ERR_INVAL; > + > + /* Find the FDE which contains the PC, then scan its FRE entries. */ > + fdep = sframe_sec_find_fde(sfsec, pc, &err); > + if (fdep == NULL || sfsec->fres == NULL) > + return SFRAME_ERR_INIT_INVAL; > + > + fre_type = sframe_get_fre_type(fdep); > + fde_type = sframe_get_fde_type(fdep); > + > + /* > + * For FDEs for repetitive pattern of insns, we need to return the FRE > + * such that(PC & FRE_START_ADDR_AS_MASK >= FRE_START_ADDR_AS_MASK). > + * so, update the bitmask to the start address. > + */ > + /* FIXME - the bitmask. */ > + if (fde_type == SFRAME_FDE_TYPE_PCMASK) > + bitmask = 0xff; > + > + fres = (unsigned char *)sfsec->fres + fdep->func_start_fre_off; > + for (i = 0; i < fdep->func_num_fres; i++) { > + err = sframe_sec_read_fre((const char *)fres, &next_fre, > + fre_type, &esz); > + start_address = next_fre.start_ip_offset; > + > + if (((fdep->func_start_address > + + (int32_t)start_address) & bitmask) <= (pc & bitmask)) { What's the purpose of that int32_t cast? > + sframe_fre_copy(&cur_fre, &next_fre); > + > + /* Get the next FRE in sequence. */ > + if (i < fdep->func_num_fres - 1) { > + fres += esz; > + err = sframe_sec_read_fre((const char *)fres, > + &next_fre, > + fre_type, &esz); > + > + /* Sanity check the next FRE. */ > + if (!sframe_fre_sanity_check_p(&next_fre)) > + return SFRAME_ERR_FRE_INVAL; > + > + size = next_fre.start_ip_offset; > + } else { > + size = fdep->func_size; > + } > + > + if (((fdep->func_start_address > + + (int32_t)size) & bitmask) > (pc & bitmask)) { > + /* Cur FRE contains the PC, return it. */ > + sframe_fre_copy(frep, &cur_fre); > + return 0; > + } > + } else { > + return SFRAME_ERR_FRE_INVAL; > + } Or, you could've done: start_address += fdep->func_start_address; if ((start_address & bitmask) > (pc & bitmask)) return SFRAME_ERR_FRE_INVAL; ...and saved yourself an indent level and an unreadable linebreak... > + } > + return SFRAME_ERR_FDE_INVAL; > +}