Received: by 10.223.176.5 with SMTP id f5csp1626446wra; Thu, 8 Feb 2018 00:23:57 -0800 (PST) X-Google-Smtp-Source: AH8x227Y8mOgHobsEsKp0CFv9yiWOHeanPmU2Prz6V0aGA2sxuJaVlDt8rM2+MBT4aemN+M8UOQD X-Received: by 10.99.171.69 with SMTP id k5mr4342316pgp.287.1518078236944; Thu, 08 Feb 2018 00:23:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518078236; cv=none; d=google.com; s=arc-20160816; b=e0OSzfAf+GzCCCF3vdOz6RQ6WNQZImtbODMeiO8671SLr0kPHjlO6oSOW5g7isH5K7 edaLa/G8BzPFy5evgWVHX4D/C37qcS6IwO+myaVMRG67nKHmbjnjRpqa6n3vTAqkCioq skSSk0YBihxfE1BRvMdjTmMuWRzDpxuSk3ub1dxMSNwS7xmS+T9afT8ANeyezr6JXF+g 0WmXKbOcBe4WFOWYW5yDYcSaqOrfLT0C/eLEDsY7jxMaaAlSg6VduyVxleO+0/15Lx7G HYt1qOLdkeM2tEtucYdRW6zR4kLC6PK0a9ZFWMZkNXJBLBqJH472znGWIdhdN5E02WJj DhiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=cjtuYfkKaQ/FYwruAB/SpqdqfDsPygcwCptobGz68b4=; b=yb+1/qC4rxo67xeCHYXsXn2fhil2+qXt+Ig3AkPajAcAyB/UVWm9W5ruQCEMenvnfy JBU4Py0iMrlEG20wFsFmYMm13zhvX0dgXWDXCkYnyWNYUy7KDQ+9sx+SKCqcPwriNiIT aRFXCS6bnhLsieo7u8txfBCzNTFFl1bjzqWHpBZ4fI1NqUorsns5F/aU7wB07pWSspg8 XoDsFqANQMlCwsSZV+OZY+An4e1IOG7bSLs6n4AMt4uXNoMBGwCNf9y9UqXOxnDxpjnO R5/OWPjxvI9/sJDvbw/pxsOfKn0JQrJogfCuojG5RaNgHXqDLoZ8n8T35jZt7nLGC3a7 PyXg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e8-v6si2476171pls.595.2018.02.08.00.23.31; Thu, 08 Feb 2018 00:23:56 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751424AbeBHIWa (ORCPT + 99 others); Thu, 8 Feb 2018 03:22:30 -0500 Received: from mga02.intel.com ([134.134.136.20]:20671 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750986AbeBHIW2 (ORCPT ); Thu, 8 Feb 2018 03:22:28 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Feb 2018 00:22:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,477,1511856000"; d="scan'208";a="33063165" Received: from gvt-dell.bj.intel.com (HELO gvt-dell-host.bj.intel.com) ([10.238.154.59]) by orsmga002.jf.intel.com with ESMTP; 08 Feb 2018 00:22:25 -0800 From: changbin.du@intel.com To: jolsa@redhat.com Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Changbin Du Subject: [PATCH v2] perf ftrace: Fix the buffer size in __write_tracing_file Date: Thu, 8 Feb 2018 16:13:20 +0800 Message-Id: <1518077600-19615-1-git-send-email-changbin.du@intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Changbin Du The terminal character '\0' should take into account into size of the string buffer. Without this fix, the '--graph-funcs', '--nograph-funcs' and '--trace-funcs' options didn't work as expected when the doesn't exist. If usersapce writes a non-terminated string, the kernel side will always return success but actually no filter applied. As discussed before, the kernel now support '\0' to mark the end of string: https://lkml.org/lkml/2018/1/16/116 After this fix in userspace, the perf will report correct error state. Also let it print an error if reset_tracing_files() fails. The problem: $ sudo ./perf ftrace -a --graph-depth 1 --graph-funcs abcdefg 0) 0.140 us | rcu_all_qs(); 3) 0.304 us | mutex_unlock(); 0) 0.153 us | find_vma(); 3) 0.088 us | __fsnotify_parent(); 0) 6.145 us | handle_mm_fault(); 3) 0.089 us | fsnotify(); 3) 0.161 us | __sb_end_write(); 3) 0.710 us | SyS_close(); 3) 7.848 us | exit_to_usermode_loop(); On above example, I specified function filter 'abcdefg' but all functions are enabled. The expected error is hidden. Signed-off-by: Changbin Du --- tools/perf/builtin-ftrace.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index 25a42ac..a87e9b3 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -69,7 +69,7 @@ static int __write_tracing_file(const char *name, const char *val, bool append) { char *file; int fd, ret = -1; - ssize_t size = strlen(val); + ssize_t size = strlen(val) + 1; int flags = O_WRONLY; char errbuf[512]; @@ -280,8 +280,10 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv) signal(SIGCHLD, sig_handler); signal(SIGPIPE, sig_handler); - if (reset_tracing_files(ftrace) < 0) + if (reset_tracing_files(ftrace) < 0) { + pr_err("failed to reset ftrace\n"); goto out; + } /* reset ftrace buffer */ if (write_tracing_file("trace", "0") < 0) -- 2.7.4