Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp872949ybl; Fri, 10 Jan 2020 08:08:12 -0800 (PST) X-Google-Smtp-Source: APXvYqwKuSHiVaTqOVQIR4E6S2GUFd0aQyY6/U+MPU+fjIIY9YFJ4TXTgmlkizGmiFKbu1dzHa4k X-Received: by 2002:aca:b1d5:: with SMTP id a204mr2697325oif.82.1578672492186; Fri, 10 Jan 2020 08:08:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578672492; cv=none; d=google.com; s=arc-20160816; b=h5Oyl3vqETV/Dl8lXwXJkq/raujfIBQNRsH/7JNkM1zeu+FbxEkpP7b6AIiGoKdyT4 hOXviswWs5VAQGABE0FPhyX3Ksfcvr2Z9nxcd3tRC2Ahw0wxg3IWaWQ7aGxpu/qozB6f /8dUMjJQTU9U3e9HmMzNqOG4RQ1b1ypgmM0cA8djle9IDd7rQBW4ERsDndm5qfSfP3Qm 3ukfe2kLf/UV0OnR90RR/j41JNN0SXvI7haazGanmvhlFVnVIEAC4fXbMNusBhbA3Et+ VwO4T6B/bcjtpOC0aWs7Z29dmhKkNYUFOiLsU4Zk1ek1X6FszJ7Yv2TkcCwO+Jq3MOwi exOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=f2P3fAgfLQR5kMz6sCn5Fd8eR6jQ0mLV9jhfIuwBdlk=; b=nmKWwNjIOEVIrS58yKT8NLXBRy4cxpytCPHVedVjw7w3ZpYZXyRQGORcyN9BCbalsw WI4mNwEMVsXM0BJBC9ljrjTXPonChAEcW/K2l2ya0HVZaNUUjilSBZ2DPyRbq1ac1xV8 +LdKzXHMpSiWrGgWu3xUzpZ4QS0SGw+Rmd23E2tCbVvRlXMJgv/C5MTe/41+ftP9/rHg HOiAsHQPwy/iDBmcB2QuylMSPja4y8GUaRtPc3s4g2YnOjGPdT9pDejyb0LFU6Qffi9e nWTzrZnE24uBi50Gjm7JZphoc7jq2RHXtQm5MIfnefdBVk1E/PscqHboH5iDR8U92bct LuAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZapPQnDh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c12si1582806otn.90.2020.01.10.08.07.55; Fri, 10 Jan 2020 08:08:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZapPQnDh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728868AbgAJQGs (ORCPT + 99 others); Fri, 10 Jan 2020 11:06:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:55246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728475AbgAJQGr (ORCPT ); Fri, 10 Jan 2020 11:06:47 -0500 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 63364206ED; Fri, 10 Jan 2020 16:06:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578672406; bh=EFOCwUoheH+jBKpvdOc2oU4IIlVNeeJsl7UIpCjr5Wk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZapPQnDh7cOn3yKddzVcfzUDMf0D3FePSxLO2HFUL41TrG+5rxbXqtlYHP5CPlsWr 9+9WHIlbwEtH9IhbnNqunTvxG5xcyGtqNEIxRMn5QkMqHVqpan+QVq44bVXD0yub5I MhX9BnvHwI6req1XdZYU5eYaPGTNX1n4bov/Yiqs= From: Masami Hiramatsu To: Steven Rostedt Cc: Ingo Molnar , Frank Rowand , Randy Dunlap , Namhyung Kim , Tim Bird , Jiri Olsa , Arnaldo Carvalho de Melo , Tom Zanussi , Rob Herring , Andrew Morton , Thomas Gleixner , Greg Kroah-Hartman , Alexey Dobriyan , Jonathan Corbet , Linus Torvalds , linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 17/22] tracing/boot Add kprobe event support Date: Sat, 11 Jan 2020 01:06:41 +0900 Message-Id: <157867240104.17873.9712052065426433111.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <157867220019.17873.13377985653744804396.stgit@devnote2> References: <157867220019.17873.13377985653744804396.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add kprobe event support on event node to boot-time tracing. If the group name of event is "kprobes", the boot-time tracing defines new probe event according to "probes" values. - ftrace.event.kprobes.EVENT.probes = PROBE[, PROBE2...] Defines new kprobe event based on PROBEs. It is able to define multiple probes on one event, but those must have same type of arguments. For example, ftrace.events.kprobes.myevent { probes = "vfs_read $arg1 $arg2"; enable; } This will add kprobes:myevent on vfs_read with the 1st and the 2nd arguments. Signed-off-by: Masami Hiramatsu --- kernel/trace/trace_boot.c | 46 +++++++++++++++++++++++++++++++++++++++++++ kernel/trace/trace_kprobe.c | 5 +++++ 2 files changed, 51 insertions(+) diff --git a/kernel/trace/trace_boot.c b/kernel/trace/trace_boot.c index 37524031533e..a11dc60299fb 100644 --- a/kernel/trace/trace_boot.c +++ b/kernel/trace/trace_boot.c @@ -76,6 +76,48 @@ trace_boot_enable_events(struct trace_array *tr, struct xbc_node *node) } } +#ifdef CONFIG_KPROBE_EVENTS +extern int trace_kprobe_run_command(const char *command); + +static int __init +trace_boot_add_kprobe_event(struct xbc_node *node, const char *event) +{ + struct xbc_node *anode; + char buf[MAX_BUF_LEN]; + const char *val; + char *p; + int len; + + len = snprintf(buf, ARRAY_SIZE(buf) - 1, "p:kprobes/%s ", event); + if (len >= ARRAY_SIZE(buf)) { + pr_err("Event name is too long: %s\n", event); + return -E2BIG; + } + p = buf + len; + len = ARRAY_SIZE(buf) - len; + + xbc_node_for_each_array_value(node, "probes", anode, val) { + if (strlcpy(p, val, len) >= len) { + pr_err("Probe definition is too long: %s\n", val); + return -E2BIG; + } + if (trace_kprobe_run_command(buf) < 0) { + pr_err("Failed to add probe: %s\n", buf); + return -EINVAL; + } + } + + return 0; +} +#else +static inline int __init +trace_boot_add_kprobe_event(struct xbc_node *node, const char *event) +{ + pr_err("Kprobe event is not supported.\n"); + return -ENOTSUPP; +} +#endif + static void __init trace_boot_init_one_event(struct trace_array *tr, struct xbc_node *gnode, struct xbc_node *enode) @@ -88,6 +130,10 @@ trace_boot_init_one_event(struct trace_array *tr, struct xbc_node *gnode, group = xbc_node_get_data(gnode); event = xbc_node_get_data(enode); + if (!strcmp(group, "kprobes")) + if (trace_boot_add_kprobe_event(enode, event) < 0) + return; + mutex_lock(&event_mutex); file = find_event_file(tr, group, event); if (!file) { diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 5584405b899d..318a3579a928 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -902,6 +902,11 @@ static int create_or_delete_trace_kprobe(int argc, char **argv) return ret == -ECANCELED ? -EINVAL : ret; } +int trace_kprobe_run_command(const char *command) +{ + return trace_run_command(command, create_or_delete_trace_kprobe); +} + static int trace_kprobe_release(struct dyn_event *ev) { struct trace_kprobe *tk = to_trace_kprobe(ev);