Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp205316ybm; Wed, 22 May 2019 01:35:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWy9Pa4jci16ACwhEIpdQp0oHNLVz1Wz5KT1ZRcdqLrLCXLUgJKap1uhxXjtawW/gCNN0n X-Received: by 2002:aa7:808d:: with SMTP id v13mr62904706pff.198.1558514117350; Wed, 22 May 2019 01:35:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558514117; cv=none; d=google.com; s=arc-20160816; b=xqxXmrF1IwU1NiokQE0GXaX9B/rnR1GukO6ej5jUfecXGtcWmkV9m5u2z1lM1gN7Fb /syK9frUofXbLgcT1kybjaEpt0MaCD0ujQFtofDWt3Iu5r3TbDRp9VM3nKxKgDE9Tvde E3tqhqOPFmgueesIBEx/mIQhog/xPPqm+87Hh5VtQ/+Aby1a2SURFRhRt0Bv3LEhsQXt EIb3n9dc54bI0QiAUaTXDRxk6QQJHpOn8JoABtxwzm6jooKUDN0PYafyf6+3lWJdD0e5 ByvQGHM/vJZOVFtpRBEZCVPX1QgFEWUURedtVWfY7bHL4Dp++HexOUh1GWdU3p7Aqv6a 98RA== 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=caYoAlriFoR/xFcZcimp3XRaWCQhQEMi2C1Y+R79sSc=; b=pHxxns2bGHYfmTDMZo+8Dkhf80VCR0w1SF1CeUtIe5Slxr//qCrC1qAGtW0jw2rKqv KH+IHw5oJiUkYKVPFUefChwiTANm8Wm6jMa0ptjyymxNyZyNxMxvPE62wWnesCL2E2CX C7FpYz8bmgp/6/uOlIB79sjTAT7Flv5qGXafuuPDNztAZ71U/E8iIjluAu4I66Y1AYbv LftG4r2iEi9t1HEhVB/DTFpEr6iY5awNtI221k5nZoFupgDcHpBMia8iAVSUqLhqTU+Y SFMPXl1EY4AKnGQ+U0kETbnU/HfXcd8DltKJYtxlJ0jKctigKL/qmY7khc1q0dLOnrgQ iPkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="toKG0L/w"; 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 i97si25256946plb.173.2019.05.22.01.35.01; Wed, 22 May 2019 01:35:17 -0700 (PDT) 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="toKG0L/w"; 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 S1728876AbfEVIci (ORCPT + 99 others); Wed, 22 May 2019 04:32:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:51392 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728784AbfEVIci (ORCPT ); Wed, 22 May 2019 04:32:38 -0400 Received: from devnote2.wi2.ne.jp (unknown [103.5.140.153]) (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 9027D2173C; Wed, 22 May 2019 08:32:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558513957; bh=bJvqGYw7DNXGDmes2Ibv22SSkaA4f4/0ULWJP8zE9PQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=toKG0L/wd7qRZePBRwvrj3pZFUep0wwi6r2obWchrG5n9Em4fQhvk+n0Kstmi3WrI UGfj0dVqFtGfN13EwHpN0t11NNgEf+fIhkd2WakuXhiTPGnj3WEScGZvAFflvZnH5E vsOmv6fksI4s3nCUvhru+4kfnSVReHrU363p5v30= From: Masami Hiramatsu To: Steven Rostedt Cc: Ingo Molnar , "Naveen N . Rao" , Anil S Keshavamurthy , "David S . Miller" , Masami Hiramatsu , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v2 2/2] tracing/kprobe: Add kprobe_event= boot parameter Date: Wed, 22 May 2019 17:32:35 +0900 Message-Id: <155851395498.15728.830529496248543583.stgit@devnote2> X-Mailer: git-send-email 2.17.1 In-Reply-To: <155851393823.15728.9489409117921369593.stgit@devnote2> References: <155851393823.15728.9489409117921369593.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add kprobe_event= boot parameter to define kprobe events at boot time. The definition syntax is similar to tracefs/kprobe_events interface, but use ',' and ';' instead of ' ' and '\n' respectively. e.g. kprobe_event=p,vfs_read,$arg1,$arg2 This puts a probe on vfs_read with argument1 and 2, and enable the new event. Signed-off-by: Masami Hiramatsu --- Documentation/admin-guide/kernel-parameters.txt | 13 ++++++ Documentation/trace/kprobetrace.rst | 14 ++++++ kernel/trace/trace_kprobe.c | 54 +++++++++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 2b8ee90bb644..96b22db7f763 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2002,6 +2002,19 @@ Built with CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF=y, the default is off. + kprobe_event=[probe-list] + [FTRACE] Add kprobe events and enable at boot time. + The probe-list is a semicolon delimited list of probe + definitions. Each definition is same as kprobe_events + interface, but the parameters are comma delimited. + For example, to add a kprobe event on vfs_read with + arg1 and arg2, add to the command line; + + kprobe_event=p,vfs_read,$arg1,$arg2 + + See also Documentation/trace/kprobetrace.rst "Kernel + Boot Parameter" section. + kpti= [ARM64] Control page table isolation of user and kernel address spaces. Default: enabled on cores which need mitigation. diff --git a/Documentation/trace/kprobetrace.rst b/Documentation/trace/kprobetrace.rst index 235ce2ab131a..5b129215ba33 100644 --- a/Documentation/trace/kprobetrace.rst +++ b/Documentation/trace/kprobetrace.rst @@ -124,6 +124,20 @@ You can check the total number of probe hits and probe miss-hits via The first column is event name, the second is the number of probe hits, the third is the number of probe miss-hits. +Kernel Boot Parameter +--------------------- +You can add and enable new kprobe events when booting up the kernel by +"kprobe_event=" parameter. The parameter accepts a semicolon-delimited +kprobe events, which format is similar to the kprobe_events. +The difference is that the probe definition parameters are comma-delimited +instead of space. For example, adding myprobe event on do_sys_open like below + + p:myprobe do_sys_open dfd=%ax filename=%dx flags=%cx mode=+4($stack) + +should be below for kernel boot parameter (just replace spaces with comma) + + p:myprobe,do_sys_open,dfd=%ax,filename=%dx,flags=%cx,mode=+4($stack) + Usage examples -------------- diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index 7d736248a070..6983435ff017 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c @@ -12,6 +12,8 @@ #include #include +#include /* for COMMAND_LINE_SIZE */ + #include "trace_dynevent.h" #include "trace_kprobe_selftest.h" #include "trace_probe.h" @@ -19,6 +21,17 @@ #define KPROBE_EVENT_SYSTEM "kprobes" #define KRETPROBE_MAXACTIVE_MAX 4096 +#define MAX_KPROBE_CMDLINE_SIZE 1024 + +/* Kprobe early definition from command line */ +static char kprobe_boot_events_buf[COMMAND_LINE_SIZE] __initdata; + +static int __init set_kprobe_boot_events(char *str) +{ + strlcpy(kprobe_boot_events_buf, str, COMMAND_LINE_SIZE); + return 0; +} +__setup("kprobe_event=", set_kprobe_boot_events); static int trace_kprobe_create(int argc, const char **argv); static int trace_kprobe_show(struct seq_file *m, struct dyn_event *ev); @@ -1450,6 +1463,44 @@ void destroy_local_trace_kprobe(struct trace_event_call *event_call) } #endif /* CONFIG_PERF_EVENTS */ +static __init void enable_boot_kprobe_events(void) +{ + struct trace_array *tr = top_trace_array(); + struct trace_event_file *file; + struct trace_kprobe *tk; + struct dyn_event *pos; + + mutex_lock(&event_mutex); + for_each_trace_kprobe(tk, pos) { + list_for_each_entry(file, &tr->events, list) + if (file->event_call == &tk->tp.call) + trace_event_enable_disable(file, 1, 0); + } + mutex_unlock(&event_mutex); +} + +static __init void setup_boot_kprobe_events(void) +{ + char *p, *cmd = kprobe_boot_events_buf; + int ret; + + strreplace(kprobe_boot_events_buf, ',', ' '); + + while (cmd && *cmd != '\0') { + p = strchr(cmd, ';'); + if (p) + *p++ = '\0'; + + ret = trace_run_command(cmd, create_or_delete_trace_kprobe); + if (ret) + pr_warn("Failed to add event(%d): %s\n", ret, cmd); + + cmd = p; + } + + enable_boot_kprobe_events(); +} + /* Make a tracefs interface for controlling probe points */ static __init int init_kprobe_trace(void) { @@ -1481,6 +1532,9 @@ static __init int init_kprobe_trace(void) if (!entry) pr_warn("Could not create tracefs 'kprobe_profile' entry\n"); + + setup_boot_kprobe_events(); + return 0; } fs_initcall(init_kprobe_trace);