Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp355571rdb; Thu, 2 Nov 2023 05:57:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHYXLoZRIoqMvZPbfE8+oLRVDks+u3iWhBNqWOjLIhy3sznvqUJJRHCC+7ky8etmmnOy+tp X-Received: by 2002:a05:6a20:7289:b0:136:ea0e:d23 with SMTP id o9-20020a056a20728900b00136ea0e0d23mr17427315pzk.11.1698929857256; Thu, 02 Nov 2023 05:57:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698929857; cv=none; d=google.com; s=arc-20160816; b=sOIBas4J6EuuSaTvpULPk0s1U2+ukFABztCRJ0vR+7oEIiC2ooNyQ0Wj2C2R1OzRBU o31TBlTeUPLzCAuLyphGqNjsnaaTEVnqv57TerBrcJx5wYFG3wTRXSz57H8xNItNAZmY xBbjkHliqea0CgYZAHSWOzBwdK4gTGV1sm8Tb2ljsm8UVtnLKzM9nRFOxCgjLfYtnU9a 1vV5nsTJALCFqZAQCewCrrHN2VjV92gNUgjTeoeIk7ykD3U4+zEoX/VA657C3t8+7qZT iSK/RXjdLvjQ4CHyrUaUxgK2yx2lqs4ijMjQwju0tGfXAKFFQRHGg0S+WTa1uVtF8cqD zCmg== 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:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=lmXPUyUM/jM/0/57e2UuFckkajSYsjPidz3sTbvACts=; fh=d3yojaVsD4AI2ibwkdyGlHRoEaWtoDayWCxnQ55Z/QQ=; b=qr96V/rymP5svTQw/xUKGHfzKD6/6Yi7pzecoM2oa7pJx5nIOJvkNyDUOSbNEga0Nc szUurAIuZPxrn5fZI73z+7HESAJwsnr8R/Umm2yP1hAYgzJ+4Ux5dsvwZ2YSIJDUZRll bnIrLl9R9CWwshfzuis5rK+ZVyG7nXkKhiR00iQEW0rDVh4L3c5Vqu+7/neeGCZE0Mgr vi+/DFRwvQKYvv/GPxkxdNiP3w7Jd/a72c9GvvrLav0l8DPtswxPr+FjcH+q5nMTWhel aftfhHh0CaGT6meWRr6PnPxMzL31d/PC47fQo6f6ay97LYpGIiy0CuSCILOhks451hSO DaIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=eK3+MYew; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id a11-20020a170902eccb00b001ca87c9e9d4si5136388plh.598.2023.11.02.05.57.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 05:57:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=eK3+MYew; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 143B0808A912; Thu, 2 Nov 2023 05:57:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229607AbjKBM5Y (ORCPT + 99 others); Thu, 2 Nov 2023 08:57:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229665AbjKBM5W (ORCPT ); Thu, 2 Nov 2023 08:57:22 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 80A30121; Thu, 2 Nov 2023 05:57:17 -0700 (PDT) Received: from pwmachine.localnet (unknown [86.120.35.5]) by linux.microsoft.com (Postfix) with ESMTPSA id 4336E20B74C0; Thu, 2 Nov 2023 05:57:15 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4336E20B74C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1698929836; bh=lmXPUyUM/jM/0/57e2UuFckkajSYsjPidz3sTbvACts=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eK3+MYew1dfqEhbm6caxcWlTBwGqR+jjUFwcWkNPxYbyU3BxLPR1TctUk5nwAdd1p WfXNHb6EecnK9VSXI2KXIwEhu4BOjB/9QVHSJm7hsS/aI1HX3OfmcQsO31iJWaMHs5 JyKhW7g8mWmak42ulD8iq2NrPUjTfWaxFaa0PeQ8= From: Francis Laniel To: Masami Hiramatsu Cc: LKML , Linux trace kernel , Steven Rostedt , Andrii Nakryiko Subject: Re: [PATCH for-next] tracing/kprobes: Add symbol counting check when module loads Date: Thu, 02 Nov 2023 14:57:12 +0200 Message-ID: <5987802.lOV4Wx5bFT@pwmachine> In-Reply-To: <20231101081509.605080231a2736b91331cb85@kernel.org> References: <169854904604.132316.12500381416261460174.stgit@devnote2> <1868732.tdWV9SEqCh@pwmachine> <20231101081509.605080231a2736b91331cb85@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 02 Nov 2023 05:57:35 -0700 (PDT) Hi! Le mercredi 1 novembre 2023, 01:15:09 EET Masami Hiramatsu a =E9crit : > Hi, >=20 > On Tue, 31 Oct 2023 23:24:43 +0200 >=20 > Francis Laniel wrote: > > > @@ -729,17 +744,55 @@ static int count_mod_symbols(void *data, const > > > char > > > *name, unsigned long unused) return 0; > > >=20 > > > } > > >=20 > > > -static unsigned int number_of_same_symbols(char *func_name) > > > +static unsigned int number_of_same_symbols(const char *mod, const ch= ar > > > *func_name) { > > >=20 > > > struct sym_count_ctx ctx =3D { .count =3D 0, .name =3D func_name }; > > >=20 > > > - kallsyms_on_each_match_symbol(count_symbols, func_name, &ctx.count); > > > + if (!mod) > > > + kallsyms_on_each_match_symbol(count_symbols, func_name, > >=20 > > &ctx.count); > >=20 > > > - module_kallsyms_on_each_symbol(NULL, count_mod_symbols, &ctx); > > > + module_kallsyms_on_each_symbol(mod, count_mod_symbols, &ctx); > >=20 > > I may be missing something here or reviewing too quickly. > > Wouldn't this function return count to be 0 if func_name is only part of > > the module named mod? >=20 > No, please read below. >=20 > > Indeed, if the function is not in kernel symbol, > > kallsyms_on_each_match_symbol() will not loop. > > And, by giving mod to module_kallsyms_on_each_symbol(), the correspondi= ng > > module will be skipped, so count_mob_symbols() would not be called. > > Hence, we would have 0 as count, which would lead to ENOENT later. >=20 > Would you mean the case func_name is on the specific module? > If 'mod' is specified, module_kallsyms_on_each_symbol() only loops on > symbols in the module names 'mod'. >=20 > int module_kallsyms_on_each_symbol(const char *modname, > int (*fn)(void *, const char *, unsign= ed > long), void *data) > { > struct module *mod; > unsigned int i; > int ret =3D 0; >=20 > mutex_lock(&module_mutex); > list_for_each_entry(mod, &modules, list) { > struct mod_kallsyms *kallsyms; >=20 > if (mod->state =3D=3D MODULE_STATE_UNFORMED) > continue; >=20 > if (modname && strcmp(modname, mod->name)) > continue; > ... >=20 > So with above change, 'if mod is not specified, search the symbols in ker= nel > and all modules. If mod is sepecified, search the symbol on the specific > module'. >=20 > Thus, "if func_name is only part of the module named mod", the > module_kallsyms_on_each_symbol() will count the 'func_name' in 'mod' modu= le > correctly. Sorry, I looked to quickly and forgot about the return value of strcmp()... =46rom the code, everything seems OK! If I have some time, I will test it and potentially come back with a "Teste= d- by" tag but without any warranty. > Thank you, >=20 >=20 > Thank you, Best regards.