Skip to contentSkip to conversation

perf top -u <uid> does not seem to be working

DISCUSSION Ingo Molnar 3 participants 4 messages Nov 12, 2013 – Nov 15, 2013 perf events

lore
Share & tools
lore
#0 lore raw

Hm, this is unexpected I think:

hubble:~> perf top --stdio -u mingo
Error:
You may not have permission to collect stats. Consider tweaking /proc/sys/kernel/perf_event_paranoid:
-1 - Not paranoid at all
0 - Disallow raw tracepoint access for unpriv 1 - Disallow cpu events for unpriv
2 - Disallow kernel profiling for unpriv

hubble:~> cat /proc/sys/kernel/perf_event_paranoid -1

hubble:~> perf top --stdio -u
Error: switch `u' requires a value

usage: perf top [<options>]

      -u, --uid <user>      user to profile

(perf is the latest version from tip:perf/core)

Thanks,

Ingo

#1 lore raw

an unrelated bug is a missing newline if the 'uid' is invalid:

  hubble:~> perf top --stdio -u help
  Error:
  Invalid User: helphubble:~> 

Fixed by the patch below.

  comet:~/tip/tools/perf> perf top --stdio -u help
  Error:
  Invalid User: help
  comet:~/tip/tools/perf> 
 tools/perf/builtin-top.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-top.c +2 -2
index b8f8e29..71e6402 100644
@@ -1172,7 +1172,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
 	status = target__validate(target);
 	if (status) {
 		target__strerror(target, status, errbuf, BUFSIZ);
-		ui__warning("%s", errbuf);
+		ui__warning("%s\n", errbuf);
 	}
 
 	status = target__parse_uid(target);
@@ -1180,7 +1180,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
 		int saved_errno = errno;
 
 		target__strerror(target, status, errbuf, BUFSIZ);
-		ui__error("%s", errbuf);
+		ui__error("%s\n", errbuf);
 
 		status = -saved_errno;
 		goto out_delete_evlist;
#3 lore raw
In reply to Ingo Molnar

Em Wed, Nov 13, 2013 at 12:22:49AM +0100, Ingo Molnar escreveu:

Quoted 11 lines

Hm, this is unexpected I think:

hubble:~> perf top --stdio -u mingo
Error:
You may not have permission to collect stats. Consider tweaking /proc/sys/kernel/perf_event_paranoid:
-1 - Not paranoid at all
0 - Disallow raw tracepoint access for unpriv 1 - Disallow cpu events for unpriv
2 - Disallow kernel profiling for unpriv

Quoted 4 lines

hubble:~> cat /proc/sys/kernel/perf_event_paranoid -1

(perf is the latest version from tip:perf/core)

https://lkml.org/lkml/2012/1/26/142

Fell thru the cracks, summary:

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines

+++ b/kernel/events/core.c

(quoted diff) +2 -1
@@ -2636,7 +2636,8 @@ find_lively_task_by_vpid(pid_t vpid)
 	/* Reuse ptrace permission checks for now. */
 	err = -EACCES;
-	if (!ptrace_may_access(task, PTRACE_MODE_READ))
+	if (perf_paranoid_tracepoint_raw() &&
+	    !ptrace_may_access(task, PTRACE_MODE_READ))
 		goto errout;
 	return task;
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

ptrace_may_access(task, PTRACE_MODE_READ) fails for some tasks owned by the user because, IIRC, in __ptrace_may_access:

Which tasks are these, are they privileged in any sense?

IIRC one of them was a child of sshd, that runs as root and then changes the child ownership to the user logging in.

- Arnaldo

#2 lore raw

[tip:perf/urgent] perf top: Add missing newline if the 'uid' is invalid

In reply to Ingo Molnar
perf top: Add missing newline if the 'uid' is invalid
Commit-ID:  ea432a8bb940e6bea2aaeca3c0ff3d931ad81f2e
Gitweb:     http://git.kernel.org/tip/ea432a8bb940e6bea2aaeca3c0ff3d931ad81f2e
Author:     Ingo Molnar <[email protected]>
AuthorDate: Wed, 13 Nov 2013 00:26:09 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 14 Nov 2013 15:59:50 -0300

perf top: Add missing newline if the 'uid' is invalid

Add missing newline if the 'uid' is invalid:

  hubble:~> perf top --stdio -u help
  Error:
  Invalid User: helphubble:~>

Fixed by this patch:

  comet:~/tip/tools/perf> perf top --stdio -u help
  Error:
  Invalid User: help
  comet:~/tip/tools/perf>
---
 tools/perf/builtin-top.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-top.c +2 -2
index b8f8e29..71e6402 100644
@@ -1172,7 +1172,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
 	status = target__validate(target);
 	if (status) {
 		target__strerror(target, status, errbuf, BUFSIZ);
-		ui__warning("%s", errbuf);
+		ui__warning("%s\n", errbuf);
 	}
 
 	status = target__parse_uid(target);
@@ -1180,7 +1180,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
 		int saved_errno = errno;
 
 		target__strerror(target, status, errbuf, BUFSIZ);
-		ui__error("%s", errbuf);
+		ui__error("%s\n", errbuf);
 
 		status = -saved_errno;
 		goto out_delete_evlist;