Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4601844ioa; Wed, 27 Apr 2022 07:17:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/hprDDcK6un19hCaMIXn/edhqXNmijbDGAYma1Qyly98R8bAZULDrfVqSIMzxyF3t+FnV X-Received: by 2002:a05:6830:1656:b0:605:4aec:24 with SMTP id h22-20020a056830165600b006054aec0024mr10089452otr.108.1651069026473; Wed, 27 Apr 2022 07:17:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651069026; cv=none; d=google.com; s=arc-20160816; b=tfbSnb9QIn7Ue3auxj3PG5pPrmZcgyrg415Cdu3Zfmp5ZqxL8jZiL4QRHTKBybHcr0 MYwpzi4DeKEqz7l8WdbP7cgapZglIBJFQSS9I84H7feJzmA9/wS2YOpEYadKxIaUBMD8 MePyeR3pHCqBi9k/feA+rRmsEiAoaE7TGu1ZSQrmTON0wX2Z1zAApZ5jR/PZ+egG9UiC Q/+PUdSZtqeHlURBQc/AtchsnsoKYh9JIw1stDvKcFJnqnR4aefYco9S/YZPz1ttKYgc f91HNutqIPCuCpapz5TRygF1HfijxT/eFV3S+A4dKHWWWj2tZJKzEs9LHRm9kH1FQgC8 TYmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=QijtuPXSOKtzP+aW8M7nlb7XXEeZxdwMCeh5ksr+kPc=; b=AXZBbhfDBZLCNsnpz1Q4wmyywLONmBitJhwsexRhDDI8M3igm4bRNnXib0LNDDjbux y67q5KdybvT6e8MUSZc5XW6DgTEeQ2+/nMyOn0aX5msFBcHB7ndFY0YKV0CphOqDG7dM caIhDENCMoqfwsUR976F5JJHuHqNTwyNaK0894EfW8CKoD+syfyFqHu64HueowA4s9rn uNWMlj+rHxN8FXv3yyVdJ0bPfjJxnzm6oeGD93po2tEaMDrsa9etXLJl0wD4WCIrbtnO zwPFcrpvdSsy0xVyzn2RYnay/rsFG0myohRBQ3fTlSuCgYaqV9EylFHjcyMZG+ADokaX CHhg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id r33-20020a05687017a100b000e94234693esi850786oae.301.2022.04.27.07.17.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 07:17:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2D5C32857DC; Wed, 27 Apr 2022 06:47:12 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236436AbiD0NuQ (ORCPT + 99 others); Wed, 27 Apr 2022 09:50:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236380AbiD0NuP (ORCPT ); Wed, 27 Apr 2022 09:50:15 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B12A0404AC3 for ; Wed, 27 Apr 2022 06:47:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6F4EFB82767 for ; Wed, 27 Apr 2022 13:47:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 714F6C385A9; Wed, 27 Apr 2022 13:47:00 +0000 (UTC) Date: Wed, 27 Apr 2022 09:46:58 -0400 From: Steven Rostedt To: "Naveen N. Rao" Cc: Michael Ellerman , Nathan Chancellor , Nick Desaulniers , , , llvm@lists.linux.dev Subject: Re: [PATCH 1/2] ftrace: Drop duplicate mcount locations Message-ID: <20220427094658.502fcaee@gandalf.local.home> In-Reply-To: <9b1b816cff1f479c8de0e9baa5a6ac680b84e17e.1651047542.git.naveen.n.rao@linux.vnet.ibm.com> References: <9b1b816cff1f479c8de0e9baa5a6ac680b84e17e.1651047542.git.naveen.n.rao@linux.vnet.ibm.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 27 Apr 2022 15:01:21 +0530 "Naveen N. Rao" wrote: > In the absence of section symbols [1], objtool (today) and recordmcount > (with a subsequent patch) generate __mcount_loc relocation records with > weak symbols as the base. This works fine as long as those weak symbols > are not overridden, but if they are, these can result in duplicate > entries in the final vmlinux mcount location table. This will cause > ftrace to fail when trying to patch the same location twice. Fix this by > dropping duplicate locations during ftrace init. > > [1] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d1bcae833b32f1 > > Signed-off-by: Naveen N. Rao > --- > kernel/trace/ftrace.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c > index 4f1d2f5e726341..8bc4f282bb3ff4 100644 > --- a/kernel/trace/ftrace.c > +++ b/kernel/trace/ftrace.c > @@ -6496,7 +6496,7 @@ static int ftrace_process_locs(struct module *mod, > struct dyn_ftrace *rec; > unsigned long count; > unsigned long *p; > - unsigned long addr; > + unsigned long addr, prev_addr = 0; > unsigned long flags = 0; /* Shut up gcc */ > int ret = -ENOMEM; > > @@ -6550,6 +6550,16 @@ static int ftrace_process_locs(struct module *mod, > while (p < end) { > unsigned long end_offset; > addr = ftrace_call_adjust(*p++); > + > + /* > + * Drop duplicate entries, which can happen when weak > + * functions are overridden, and __mcount_loc relocation > + * records were generated against function names due to > + * absence of non-weak section symbols > + */ > + if (addr == prev_addr) > + addr = 0; Please don't use the side effect of addr == 0 causing the loop to continue for this logic. The two are not related. Simply call continue. if (addr == prev_addr) continue; -- Steve > + > /* > * Some architecture linkers will pad between > * the different mcount_loc sections of different > @@ -6569,6 +6579,7 @@ static int ftrace_process_locs(struct module *mod, > > rec = &pg->records[pg->index++]; > rec->ip = addr; > + prev_addr = addr; > } > > /* We should have used all pages */