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 X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_2 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB027C43219 for ; Wed, 27 Jan 2021 03:35:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90F85206E2 for ; Wed, 27 Jan 2021 03:35:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236507AbhA0De6 (ORCPT ); Tue, 26 Jan 2021 22:34:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:48258 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727688AbhAZVlV (ORCPT ); Tue, 26 Jan 2021 16:41:21 -0500 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 59B6620449; Tue, 26 Jan 2021 21:40:40 +0000 (UTC) Date: Tue, 26 Jan 2021 16:40:38 -0500 From: Steven Rostedt To: Oleg Nesterov Cc: Masami Hiramatsu , Jianlin Lv , mingo@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] tracing: precise log info for kretprobe addr err Message-ID: <20210126164038.566ef8c2@gandalf.local.home> In-Reply-To: <20210126211722.GA23645@redhat.com> References: <20210125160108.2147511-1-Jianlin.Lv@arm.com> <20210125181926.GA10248@redhat.com> <20210125133840.511b1496@gandalf.local.home> <20210126131536.f6e3a737a7b948799084fa7a@kernel.org> <20210126202058.GC12469@redhat.com> <20210126154302.302a3bb0@gandalf.local.home> <20210126211722.GA23645@redhat.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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 26 Jan 2021 22:17:23 +0100 Oleg Nesterov wrote: > On 01/26, Steven Rostedt wrote: > > > > On Tue, 26 Jan 2021 21:20:59 +0100 > > Oleg Nesterov wrote: > > > > > > No, not wrong. Even offset != 0, if the symbol exists in the kernel, > > > > kprobe_on_func_entry() will check it. > > > > > > Yes, but unless I am totally confused... if kprobe_on_func_entry() returns false, > > > then trace_kprobe_create() should fail with BAD_RETPROBE even if offset == 0 ? > > > > From what I understand. kprobe_on_func_entry() can return false if you pass > > in: "MOD:not_yet_loaded_module_func", but this is OK, because when the > > module is loaded, and the "not_yet_loaded_module_func" exists, the > > kretprobe will then be added. > > > > The strchr(symbol,":") check is to see if "MOD:" (or some other ":" command) > > is in the name, and we don't want it to fail if it is. Which is why we > > should have that commented. > > Agreed, this matches my understanding. > > But just in case... not sure I read this code correctly, but I think that > module_kallsyms_lookup_name("not_yet_loaded_module_func") should work even > without the "MOD:" prefix. > > IOW, kprobe_on_func_entry("not_yet_loaded_module_func") can fail, and then > later succeed if you load the module which provides this symbol. > > But even if I am right, I agree with the strchr(symbol,":") check. I see what you are saying. If "MOD" is not loaded yet, the kprobe_on_func_entry() should succeed. kprobe_on_func_entry(name) { _kprobe_addr(name) { _kprobe_lookup_name(name) { kallsyms_lookup_name(name) { module_kallsyms_lookup_name(name) { Which is: unsigned long module_kallsyms_lookup_name(const char *name) { struct module *mod; char *colon; unsigned long ret = 0; /* Don't lock: we're in enough trouble already. */ preempt_disable(); if ((colon = strnchr(name, MODULE_NAME_LEN, ':')) != NULL) { if ((mod = find_module_all(name, colon - name, false)) != NULL) ret = find_kallsyms_symbol_value(mod, colon+1); } else { list_for_each_entry_rcu(mod, &modules, list) { if (mod->state == MODULE_STATE_UNFORMED) continue; if ((ret = find_kallsyms_symbol_value(mod, name)) != 0) break; } } preempt_enable(); return ret; } And if find_module_all() fails, ret isn't updated, and "return ret" will return zero. That is, the ":" check may not be needed, but its at least good to have? -- Steve