Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1184826lqj; Mon, 3 Jun 2024 12:50:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUpyeQqYRx9PeJhm2aSjVZZHz/LwiTqMD5nMl6hJcuiYhYkWjnjsa2ivtsGHICZp0LZN4mQWxM7sRAa9eU2qdrxtu8GS45FFvhvuMDkYw== X-Google-Smtp-Source: AGHT+IF790UbAI0Jw49iyum/cLvpULHHFxf7Xm7tOO2QQ3J1gN+dXvKR6pCGj0Eo7RF25CBhkC7m X-Received: by 2002:a19:430c:0:b0:52a:9db1:9d7a with SMTP id 2adb3069b0e04-52b896d8fc0mr6987754e87.58.1717444240055; Mon, 03 Jun 2024 12:50:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717444240; cv=pass; d=google.com; s=arc-20160816; b=RBCHUTloDa1icb375T07MWFcWuON3DT2VJbLVXJ54WjjNyML/HcrzuRKu0tlFdIrFH EEtIAaQokhJvpaDO+NHG+WPXf8Yu5UZx20jTqY8gxJOf78R1BAtmNSfgfzIgPcdLMWhG kiWTXOiWmPRJ8Tw+w558Dz1HPJou2+yeqLBvhGzLjSlVaV1Tn5ylGwIyVE3Ks/jPQ28x nvh5UcbEpasAabV7bRBx/xhHrJxKfeY3Zq0K3VtZoXJL+tmg4u2HcZFC5tPBne8bklQ0 u7dW1ZXITOmrvJ7A22cyGMV0rAFoAvq0g9bc6T3Od5yoideWP9mazz//sq9TYSaT54fK ihNA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=CcNl2wLW+u3BxX+zMOeX3cCaPpc8vNRqpmlGYM5agek=; fh=fERBXX1akhbeddmw2aT0fKGSBQOaqK9KT2AH82/vlD0=; b=XRPFoQNpKpyWPizWQ/vRXK53jgeItrssNkXQ8L4Z42w4OXJtO10iNICFF3XdZelltd RBOZ9QB0nfnLxJNRh4s+6/PSP0ZWnKYyVxcPPydyeZqMgbm8qpviQNOcsotkxfckq9Bi gTjiF9wgCGhV7TwXMWzThJsR3CDbk07+yHBUoakpUm+mFrEiRh8vX030b1ofFWHtHt8B gU0KXruBXjdf1E4Sf1k6aiS8yJ1eACtIkYyJIPAD7xuAgxjX1FhwAJ6g7dzYfjICKXXF CmMzq7QE27+EUiq4bxHNUXHWq/AiPTF6rGL8FVRfx18SX3qOOCqOpJzIowHCC1reEmdG aisA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=d+fP0GQ4; arc=pass (i=1 spf=pass spfdomain=efficios.com dkim=pass dkdomain=efficios.com dmarc=pass fromdomain=efficios.com); spf=pass (google.com: domain of linux-kernel+bounces-199662-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199662-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a68abd7d45fsi298292566b.89.2024.06.03.12.50.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 12:50:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199662-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=d+fP0GQ4; arc=pass (i=1 spf=pass spfdomain=efficios.com dkim=pass dkdomain=efficios.com dmarc=pass fromdomain=efficios.com); spf=pass (google.com: domain of linux-kernel+bounces-199662-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199662-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 632E11F25968 for ; Mon, 3 Jun 2024 19:50:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9534613A884; Mon, 3 Jun 2024 19:50:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="d+fP0GQ4" Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EF9413B2A9; Mon, 3 Jun 2024 19:50:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=167.114.26.122 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717444221; cv=none; b=bnBFno6oBYh4jlSD1IQNQeOr+oh/ZsL/Nj1YCqvzAZrwBlASzy1hOUCaIL9Pn/+u0fr+41KMvsq+SqGtzaghaqJ6HIKFzx8xcc/pvaswxdCoVUo8xn3Vnb4cBn4pXTIGT/nEXOlT358iJltn9l/KJ7DOcwhIkQdnwXmovF7aMEo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717444221; c=relaxed/simple; bh=IrGXoX934uCRSpDT1wpnKtUAmJ47P6I0zTZYEgLz2K0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=FcOAoMuntTZNqY8DQUywZyaTC0VXaUF2xEaHc0ym+SFS+wNIzrGhYS7NOMfX5GUNxa/Pz4TNCeVQZMfUo+0I1F3uG/ijYXOK4K/5rBL6rn0SWu/U4AOxuNB6oF+yIv2BNkXcPQoUOhGA7JSKnZd7KAGrDQWcm4xFwCxXC+outrs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=d+fP0GQ4; arc=none smtp.client-ip=167.114.26.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1717444209; bh=IrGXoX934uCRSpDT1wpnKtUAmJ47P6I0zTZYEgLz2K0=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=d+fP0GQ4bbpq+dAhoAw8HhLMmuoVB3QqKJGj0KRWPVAVRfIcK0ceBuzPpood8WjkO eoBF72myCGy5NlMssgK0v56T0kLY0juDehQh8D6CHVqge0V1lkRv5FYPUh8L0vl1f4 TTr4syTHgy7JB5SnnDUon39jf/iyZDnjRO7+vk/HLdrAAolzqtMPf0HWnv2LRgiEr7 +PJaRFf30VXcm2JMOiK9chh7TFuIbl0FUvJm8DuaD+Cbm+jjeCGnfwLZhmrqUuLgkp qBlOP2n3JmPTWd6dcE353dzC3XLKs5GE2vD5s1j2Q/mw2K6IVQSm16JFeT+urovB9p /c0vV+P5/6oDA== Received: from [IPV6:2606:6d00:100:4000:cacb:9855:de1f:ded2] (unknown [IPv6:2606:6d00:100:4000:cacb:9855:de1f:ded2]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4VtPTF28zNz12nF; Mon, 3 Jun 2024 15:50:09 -0400 (EDT) Message-ID: Date: Mon, 3 Jun 2024 15:50:55 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/3] tracing/fprobe: Support raw tracepoint events on modules To: "Masami Hiramatsu (Google)" , Steven Rostedt Cc: don , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org References: <171723014778.258703.6731294779199848686.stgit@devnote2> <171723016594.258703.1629777910752596529.stgit@devnote2> Content-Language: en-US From: Mathieu Desnoyers In-Reply-To: <171723016594.258703.1629777910752596529.stgit@devnote2> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024-06-01 04:22, Masami Hiramatsu (Google) wrote: > From: Masami Hiramatsu (Google) > > Support raw tracepoint event on module by fprobe events. > Since it only uses for_each_kernel_tracepoint() to find a tracepoint, > the tracepoints on modules are not handled. Thus if user specified a > tracepoint on a module, it shows an error. > This adds new for_each_module_tracepoint() API to tracepoint subsystem, > and uses it to find tracepoints on modules. Hi Masami, Why prevent module unload when a fprobe tracepoint is attached to a module ? This changes the kernel's behavior significantly just for the sake of instrumentation. As an alternative, LTTng-modules attach/detach to/from modules with the coming/going notifiers, so the instrumentation gets removed when a module is unloaded rather than preventing its unload by holding a module reference count. I would recommend a similar approach for fprobe. Thanks, Mathieu > > Reported-by: don > Closes: https://lore.kernel.org/all/20240530215718.aeec973a1d0bf058d39cb1e3@kernel.org/ > Signed-off-by: Masami Hiramatsu (Google) > --- > Changes in v2: > - Fix build errors with CONFIG_MODULES=y. > --- > kernel/trace/trace_fprobe.c | 46 ++++++++++++++++++++++++++++++++++++------- > 1 file changed, 38 insertions(+), 8 deletions(-) > > diff --git a/kernel/trace/trace_fprobe.c b/kernel/trace/trace_fprobe.c > index 62e6a8f4aae9..1d8a983e1edc 100644 > --- a/kernel/trace/trace_fprobe.c > +++ b/kernel/trace/trace_fprobe.c > @@ -385,6 +385,7 @@ static struct trace_fprobe *alloc_trace_fprobe(const char *group, > const char *event, > const char *symbol, > struct tracepoint *tpoint, > + struct module *mod, > int maxactive, > int nargs, bool is_return) > { > @@ -405,6 +406,7 @@ static struct trace_fprobe *alloc_trace_fprobe(const char *group, > tf->fp.entry_handler = fentry_dispatcher; > > tf->tpoint = tpoint; > + tf->mod = mod; > tf->fp.nr_maxactive = maxactive; > > ret = trace_probe_init(&tf->tp, event, group, false, nargs); > @@ -895,8 +897,23 @@ static struct notifier_block tracepoint_module_nb = { > struct __find_tracepoint_cb_data { > const char *tp_name; > struct tracepoint *tpoint; > + struct module *mod; > }; > > +static void __find_tracepoint_module_cb(struct tracepoint *tp, void *priv) > +{ > + struct __find_tracepoint_cb_data *data = priv; > + > + if (!data->tpoint && !strcmp(data->tp_name, tp->name)) { > + data->tpoint = tp; > + data->mod = __module_text_address((unsigned long)tp->probestub); > + if (!try_module_get(data->mod)) { > + data->tpoint = NULL; > + data->mod = NULL; > + } > + } > +} > + > static void __find_tracepoint_cb(struct tracepoint *tp, void *priv) > { > struct __find_tracepoint_cb_data *data = priv; > @@ -905,14 +922,28 @@ static void __find_tracepoint_cb(struct tracepoint *tp, void *priv) > data->tpoint = tp; > } > > -static struct tracepoint *find_tracepoint(const char *tp_name) > +/* > + * Find a tracepoint from kernel and module. If the tracepoint is in a module, > + * this increments the module refcount to prevent unloading until the > + * trace_fprobe is registered to the list. After registering the trace_fprobe > + * on the trace_fprobe list, the module refcount is decremented because > + * tracepoint_probe_module_cb will handle it. > + */ > +static struct tracepoint *find_tracepoint(const char *tp_name, > + struct module **tp_mod) > { > struct __find_tracepoint_cb_data data = { > .tp_name = tp_name, > + .mod = NULL, > }; > > for_each_kernel_tracepoint(__find_tracepoint_cb, &data); > > + if (!data.tpoint && IS_ENABLED(CONFIG_MODULES)) { > + for_each_module_tracepoint(__find_tracepoint_module_cb, &data); > + *tp_mod = data.mod; > + } > + > return data.tpoint; > } > > @@ -996,6 +1027,7 @@ static int __trace_fprobe_create(int argc, const char *argv[]) > char abuf[MAX_BTF_ARGS_LEN]; > char *dbuf = NULL; > bool is_tracepoint = false; > + struct module *tp_mod = NULL; > struct tracepoint *tpoint = NULL; > struct traceprobe_parse_context ctx = { > .flags = TPARG_FL_KERNEL | TPARG_FL_FPROBE, > @@ -1080,7 +1112,7 @@ static int __trace_fprobe_create(int argc, const char *argv[]) > > if (is_tracepoint) { > ctx.flags |= TPARG_FL_TPOINT; > - tpoint = find_tracepoint(symbol); > + tpoint = find_tracepoint(symbol, &tp_mod); > if (!tpoint) { > trace_probe_log_set_index(1); > trace_probe_log_err(0, NO_TRACEPOINT); > @@ -1110,8 +1142,8 @@ static int __trace_fprobe_create(int argc, const char *argv[]) > goto out; > > /* setup a probe */ > - tf = alloc_trace_fprobe(group, event, symbol, tpoint, maxactive, > - argc, is_return); > + tf = alloc_trace_fprobe(group, event, symbol, tpoint, tp_mod, > + maxactive, argc, is_return); > if (IS_ERR(tf)) { > ret = PTR_ERR(tf); > /* This must return -ENOMEM, else there is a bug */ > @@ -1119,10 +1151,6 @@ static int __trace_fprobe_create(int argc, const char *argv[]) > goto out; /* We know tf is not allocated */ > } > > - if (is_tracepoint) > - tf->mod = __module_text_address( > - (unsigned long)tf->tpoint->probestub); > - > /* parse arguments */ > for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) { > trace_probe_log_set_index(i + 2); > @@ -1155,6 +1183,8 @@ static int __trace_fprobe_create(int argc, const char *argv[]) > } > > out: > + if (tp_mod) > + module_put(tp_mod); > traceprobe_finish_parse(&ctx); > trace_probe_log_clear(); > kfree(new_argv); > -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com