Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1944418ima; Thu, 25 Oct 2018 07:22:34 -0700 (PDT) X-Google-Smtp-Source: AJdET5fexJfFoMcB/3s6fECQf4cF3Y3iGxEzkZs+GCXmm8Ya8su++E92YU36gVUlhEtlvcwzZzJt X-Received: by 2002:a17:902:9a44:: with SMTP id x4-v6mr1691372plv.121.1540477354495; Thu, 25 Oct 2018 07:22:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540477354; cv=none; d=google.com; s=arc-20160816; b=IqVTa83GN/g+WXksWqKQDW/GSnLiQYlpru5A8SJDt5cMwVjKeqJ1FptoPgTj7I04Zj kh6XhNR0xcvrcUSVoLnXIxo6Px0Rceik8nJRSltgJXYuM0uF9AioVZbNJH/6dLoIY/iy medIg3FKSzNFbl9d2U/43IBHZ5rmVuxiqtuTY6+5k/6aQnVHXwNyFFfqObKbl0c/UK6O X3Cu421TVyTzmY+5tdfXVUndWZ98wimOJO7lbJCXF19eAI2OlVrrnd2wIcbfstDmI+Ne RQ1A0r2F8zzQKs6hcGn9UTS/eYkkyUd5r/CSvQiyUzEiupRNmy2xM4Cn3ZXFswF4qsGH hmrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=Hx/W1f+2ycqGmUYza3aLDQQrwNQirzA7hqz1Dnz51Cg=; b=NS3wQLyO5dqvdBkU5jq6V1BjxKZJOki8xn4SYXY25Mi5UzeeqqCrwzexqGAMPPEQQT SjQqkFP9dDB2ppH93bhqOWAxwLx9wNUoFNauTHa0LcCJOj6j7/BcWFXx+XbmqkIDWfK9 qvTe6J1pN1yPs3llWX1ucDbdOzGyrmLV410IBPzRu584V8NDh6xXgb23Xz+75/K7j05N zs/yQ4O/OMttTEjoAyNPKbfFlWGhsTtkjVdJKRtqQ1oqkJWQjSzsx3X7Z5+MIoJYqenL AOTGn8pryH/jN30x0XPDvFiBpkEzkupHAE8PsFRfn5nd//lx2WZHF/yip68VCSVVBSSe tg0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XZuFlNqm; 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 n73-v6si8572753pfh.96.2018.10.25.07.21.54; Thu, 25 Oct 2018 07:22:34 -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=XZuFlNqm; 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 S1730818AbeJYWw5 (ORCPT + 99 others); Thu, 25 Oct 2018 18:52:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:35178 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730693AbeJYWwy (ORCPT ); Thu, 25 Oct 2018 18:52:54 -0400 Received: from sasha-vm.mshome.net (unknown [167.98.65.38]) (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 2C06F2085B; Thu, 25 Oct 2018 14:19:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1540477196; bh=mc5sAZh2dZ39zYMDPO+bEe+o2jmvrArx7+M2pTI7+q4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XZuFlNqmEP2npLOCkaUMeNIT1Fkq9kVVU56kheBdqvRmXX1TUcqkVa4a7/o8r3DjH hr+gO64uMRP1A558nZzrl6qV85GvnmVoH21umVy1caCCDnZpkoAdgo0YFowzf+j/e7 1w1VoFnA5segBXt+u0sKdU9b/vacYL8RJnRWdcAI= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Steven Rostedt (Red Hat)" , Sasha Levin Subject: [PATCH AUTOSEL 3.18 42/98] tracing: Fix enabling of syscall events on the command line Date: Thu, 25 Oct 2018 10:17:57 -0400 Message-Id: <20181025141853.214051-42-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025141853.214051-1-sashal@kernel.org> References: <20181025141853.214051-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Steven Rostedt (Red Hat)" [ Upstream commit ce1039bd3a89e99e4f624e75fb1777fc92d76eb3 ] Commit 5f893b2639b2 "tracing: Move enabling tracepoints to just after rcu_init()" broke the enabling of system call events from the command line. The reason was that the enabling of command line trace events was moved before PID 1 started, and the syscall tracepoints require that all tasks have the TIF_SYSCALL_TRACEPOINT flag set. But the swapper task (pid 0) is not part of that. Since the swapper task is the only task that is running at this early in boot, no task gets the flag set, and the tracepoint never gets reached. Instead of setting the swapper task flag (there should be no reason to do that), re-enabled trace events again after the init thread (PID 1) has been started. It requires disabling all command line events and re-enabling them, as just enabling them again will not reset the logic to set the TIF_SYSCALL_TRACEPOINT flag, as the syscall tracepoint will be fooled into thinking that it was already set, and wont try setting it again. For this reason, we must first disable it and re-enable it. Link: http://lkml.kernel.org/r/1421188517-18312-1-git-send-email-mpe@ellerman.id.au Link: http://lkml.kernel.org/r/20150115040506.216066449@goodmis.org Reported-by: Michael Ellerman Signed-off-by: Steven Rostedt Signed-off-by: Sasha Levin --- kernel/trace/trace_events.c | 69 +++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index 51c47bc832d4..edf6ab4d8650 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -2400,12 +2400,39 @@ static __init int event_trace_memsetup(void) return 0; } +static __init void +early_enable_events(struct trace_array *tr, bool disable_first) +{ + char *buf = bootup_event_buf; + char *token; + int ret; + + while (true) { + token = strsep(&buf, ","); + + if (!token) + break; + if (!*token) + continue; + + /* Restarting syscalls requires that we stop them first */ + if (disable_first) + ftrace_set_clr_event(tr, token, 0); + + ret = ftrace_set_clr_event(tr, token, 1); + if (ret) + pr_warn("Failed to enable trace event: %s\n", token); + + /* Put back the comma to allow this to be called again */ + if (buf) + *(buf - 1) = ','; + } +} + static __init int event_trace_enable(void) { struct trace_array *tr = top_trace_array(); struct ftrace_event_call **iter, *call; - char *buf = bootup_event_buf; - char *token; int ret; if (!tr) @@ -2427,18 +2454,7 @@ static __init int event_trace_enable(void) */ __trace_early_add_events(tr); - while (true) { - token = strsep(&buf, ","); - - if (!token) - break; - if (!*token) - continue; - - ret = ftrace_set_clr_event(tr, token, 1); - if (ret) - pr_warn("Failed to enable trace event: %s\n", token); - } + early_enable_events(tr, false); trace_printk_start_comm(); @@ -2449,6 +2465,31 @@ static __init int event_trace_enable(void) return 0; } +/* + * event_trace_enable() is called from trace_event_init() first to + * initialize events and perhaps start any events that are on the + * command line. Unfortunately, there are some events that will not + * start this early, like the system call tracepoints that need + * to set the TIF_SYSCALL_TRACEPOINT flag of pid 1. But event_trace_enable() + * is called before pid 1 starts, and this flag is never set, making + * the syscall tracepoint never get reached, but the event is enabled + * regardless (and not doing anything). + */ +static __init int event_trace_enable_again(void) +{ + struct trace_array *tr; + + tr = top_trace_array(); + if (!tr) + return -ENODEV; + + early_enable_events(tr, true); + + return 0; +} + +early_initcall(event_trace_enable_again); + static __init int event_trace_init(void) { struct trace_array *tr; -- 2.17.1