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 50841C77B7E for ; Tue, 2 May 2023 10:33:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233978AbjEBKd5 (ORCPT ); Tue, 2 May 2023 06:33:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233846AbjEBKdM (ORCPT ); Tue, 2 May 2023 06:33:12 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C731B0 for ; Tue, 2 May 2023 03:31:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=GH048zhY48qE2qrvsMZeea9cypyccO6O5a7sSUk/mms=; b=SDmpfFqwsDVf/GnBOLqxDOuz5o pSf5vkKyK0mrWsgceeXvyPs3cxxV0uUXjvyGmgy91cQ2GxtqGMzsS5ot8NolV6dUG2AH/Qh0K9X3v dh1oxR2ymIewYsdNZ6EWx11zdjKE5HGrkCh1nFw2/r9aYKD91rzErv1Ts8dfxFl/IQjEqa1xI37MN IJ3E4+kzFWoXy7Rt1VsnTGMyBIX07puJBShV80lISVilr4V6ZAQ1V4cbFl6TVoAHd5499PkYrEb5J d/TMAyGvZJCgXI7cGHp77LprHTogTzwAvt1Zyz1nOLAf2C3wJgYL+oRr/XjRT2CGpsLXdCnGg8oJW ECoIPr4A==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1ptnIH-008Dqo-AK; Tue, 02 May 2023 10:31:37 +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) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 15A4F300348; Tue, 2 May 2023 12:31:35 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 98B43265DF89A; Tue, 2 May 2023 12:31:35 +0200 (CEST) Date: Tue, 2 May 2023 12:31:35 +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: <20230502103135.GM1597476@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: > +static int sframe_fre_copy(struct sframe_fre *dst, > + struct sframe_fre *src) > +{ > + if (dst == NULL || src == NULL) > + return SFRAME_ERR; > + > + memcpy(dst, src, sizeof(struct sframe_fre)); > + return 0; > +} > +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)) { > + 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; > + } > + } > + return SFRAME_ERR_FDE_INVAL; > +} What's the purpose of that sframe_fre_copy() thing? Why can't you do: cur_fre = next_fre; ... if (frep) *frep = cur_fre; and call it a day? C is quite capable of writing that memcpy for you.