All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Igor Lubashev <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: ilubashe@akamai.com, mathieu.poirier@linaro.org,
	tglx@linutronix.de, suzuki.poulose@arm.com, peterz@infradead.org,
	mingo@kernel.org, alexey.budankov@linux.intel.com,
	alexander.shishkin@linux.intel.com, linux-kernel@vger.kernel.org,
	hpa@zytor.com, jolsa@kernel.org, namhyung@kernel.org,
	jmorris@namei.org, acme@redhat.com
Subject: [tip:perf/core] tools build: Add capability-related feature detection
Date: Thu, 15 Aug 2019 02:24:40 -0700	[thread overview]
Message-ID: <tip-74d5f3d06f707eb5f7e1908ad88954bde02000ce@git.kernel.org> (raw)
In-Reply-To: <8a1e76cf5c7c9796d0d4d240fbaa85305298aafa.1565188228.git.ilubashe@akamai.com>

Commit-ID:  74d5f3d06f707eb5f7e1908ad88954bde02000ce
Gitweb:     https://git.kernel.org/tip/74d5f3d06f707eb5f7e1908ad88954bde02000ce
Author:     Igor Lubashev <ilubashe@akamai.com>
AuthorDate: Wed, 7 Aug 2019 10:44:14 -0400
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 12 Aug 2019 17:14:14 -0300

tools build: Add capability-related feature detection

Add utilities to help checking capabilities of the running procss.  Make
perf link with libcap, if it is available. If no libcap-dev[el], assume
no capabilities.

Committer testing:

  $ make O=/tmp/build/perf -C tools/perf install-bin
  make: Entering directory '/home/acme/git/perf/tools/perf'
    BUILD:   Doing 'make -j8' parallel build

  Auto-detecting system features:
  <SNIP>
  ...                        libbfd: [ on  ]
  ...                        libcap: [ OFF ]
  ...                        libelf: [ on  ]
  <SNIP>
  Makefile.config:833: No libcap found, disables capability support, please install libcap-devel/libcap-dev
  <SNIP>
  $ grep libcap /tmp/build/perf/FEATURE-DUMP
  feature-libcap=0
  $ cat /tmp/build/perf/feature/test-libcap.make.output
  test-libcap.c:2:10: fatal error: sys/capability.h: No such file or directory
      2 | #include <sys/capability.h>
        |          ^~~~~~~~~~~~~~~~~~
  compilation terminated.
  $

Now install libcap-devel and try again:

  $ make O=/tmp/build/perf -C tools/perf install-bin
  make: Entering directory '/home/acme/git/perf/tools/perf'
    BUILD:   Doing 'make -j8' parallel build
  Warning: Kernel ABI header at 'tools/include/linux/bits.h' differs from latest version at 'include/linux/bits.h'
  diff -u tools/include/linux/bits.h include/linux/bits.h
  Warning: Kernel ABI header at 'tools/arch/x86/include/asm/cpufeatures.h' differs from latest version at 'arch/x86/include/asm/cpufeatures.h'
  diff -u tools/arch/x86/include/asm/cpufeatures.h arch/x86/include/asm/cpufeatures.h

  Auto-detecting system features:
  <SNIP>
  ...                        libbfd: [ on  ]
  ...                        libcap: [ on  ]
  ...                        libelf: [ on  ]
  <SNIP>>
    CC       /tmp/build/perf/jvmti/libjvmti.o
  <SNIP>>
  $ grep libcap /tmp/build/perf/FEATURE-DUMP
  feature-libcap=1
  $ cat /tmp/build/perf/feature/test-libcap.make.output
  $ ldd /tmp/build/perf/feature/test-libcap.make.bin
  ldd: /tmp/build/perf/feature/test-libcap.make.bin: No such file or directory
  $ ldd /tmp/build/perf/feature/test-libcap.bin
  	linux-vdso.so.1 (0x00007ffc35bfe000)
  	libcap.so.2 => /lib64/libcap.so.2 (0x00007ff9c62ff000)
  	libc.so.6 => /lib64/libc.so.6 (0x00007ff9c6139000)
  	/lib64/ld-linux-x86-64.so.2 (0x00007ff9c6326000)
  $

Signed-off-by: Igor Lubashev <ilubashe@akamai.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: James Morris <jmorris@namei.org>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
[ split from a larger patch ]
Link: http://lkml.kernel.org/r/8a1e76cf5c7c9796d0d4d240fbaa85305298aafa.1565188228.git.ilubashe@akamai.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/build/Makefile.feature      |  2 ++
 tools/build/feature/Makefile      |  4 ++++
 tools/build/feature/test-libcap.c | 20 ++++++++++++++++++++
 tools/perf/Makefile.config        | 11 +++++++++++
 tools/perf/Makefile.perf          |  2 ++
 5 files changed, 39 insertions(+)

diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
index 86b793dffbc4..8a19753cc26a 100644
--- a/tools/build/Makefile.feature
+++ b/tools/build/Makefile.feature
@@ -42,6 +42,7 @@ FEATURE_TESTS_BASIC :=                  \
         gtk2-infobar                    \
         libaudit                        \
         libbfd                          \
+        libcap                          \
         libelf                          \
         libelf-getphdrnum               \
         libelf-gelf_getnote             \
@@ -110,6 +111,7 @@ FEATURE_DISPLAY ?=              \
          gtk2                   \
          libaudit               \
          libbfd                 \
+         libcap                 \
          libelf                 \
          libnuma                \
          numa_num_possible_cpus \
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index 0658b8cd0e53..8499385365c0 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -20,6 +20,7 @@ FILES=                                          \
          test-libbfd-liberty.bin                \
          test-libbfd-liberty-z.bin              \
          test-cplus-demangle.bin                \
+         test-libcap.bin			\
          test-libelf.bin                        \
          test-libelf-getphdrnum.bin             \
          test-libelf-gelf_getnote.bin           \
@@ -105,6 +106,9 @@ $(OUTPUT)test-fortify-source.bin:
 $(OUTPUT)test-bionic.bin:
 	$(BUILD)
 
+$(OUTPUT)test-libcap.bin:
+	$(BUILD) -lcap
+
 $(OUTPUT)test-libelf.bin:
 	$(BUILD) -lelf
 
diff --git a/tools/build/feature/test-libcap.c b/tools/build/feature/test-libcap.c
new file mode 100644
index 000000000000..d2a2e152195f
--- /dev/null
+++ b/tools/build/feature/test-libcap.c
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <sys/capability.h>
+#include <linux/capability.h>
+
+int main(void)
+{
+	cap_flag_value_t val;
+	cap_t caps = cap_get_proc();
+
+	if (!caps)
+		return 1;
+
+	if (cap_get_flag(caps, CAP_SYS_ADMIN, CAP_EFFECTIVE, &val) != 0)
+		return 1;
+
+	if (cap_free(caps) != 0)
+		return 1;
+
+	return 0;
+}
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index e4988f49ea79..9a06787fedc6 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -824,6 +824,17 @@ ifndef NO_LIBZSTD
   endif
 endif
 
+ifndef NO_LIBCAP
+  ifeq ($(feature-libcap), 1)
+    CFLAGS += -DHAVE_LIBCAP_SUPPORT
+    EXTLIBS += -lcap
+    $(call detected,CONFIG_LIBCAP)
+  else
+    msg := $(warning No libcap found, disables capability support, please install libcap-devel/libcap-dev);
+    NO_LIBCAP := 1
+  endif
+endif
+
 ifndef NO_BACKTRACE
   ifeq ($(feature-backtrace), 1)
     CFLAGS += -DHAVE_BACKTRACE_SUPPORT
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 67512a12276b..f9807d8c005b 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -88,6 +88,8 @@ include ../scripts/utilities.mak
 #
 # Define NO_LIBBPF if you do not want BPF support
 #
+# Define NO_LIBCAP if you do not want process capabilities considered by perf
+#
 # Define NO_SDT if you do not want to define SDT event in perf tools,
 # note that it doesn't disable SDT scanning support.
 #

  parent reply	other threads:[~2019-08-15  9:25 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-07 14:44 [PATCH v3 0/4] perf: Use capabilities instead of uid and euid Igor Lubashev
2019-08-07 14:44 ` Igor Lubashev
2019-08-07 14:44 ` [PATCH v3 1/4] perf: Add capability-related utilities Igor Lubashev
2019-08-07 14:44   ` Igor Lubashev
2019-08-12 19:43   ` Arnaldo Carvalho de Melo
2019-08-12 19:43     ` Arnaldo Carvalho de Melo
2019-08-15  9:24   ` tip-bot for Igor Lubashev [this message]
2019-08-15  9:25   ` [tip:perf/core] perf tools: Add helpers to use capabilities if present tip-bot for Igor Lubashev
2019-08-07 14:44 ` [PATCH v3 2/4] perf: Use CAP_SYS_ADMIN with perf_event_paranoid checks Igor Lubashev
2019-08-07 14:44   ` Igor Lubashev
2019-08-12 20:01   ` Arnaldo Carvalho de Melo
2019-08-12 20:01     ` Arnaldo Carvalho de Melo
2019-08-12 20:15     ` Arnaldo Carvalho de Melo
2019-08-12 20:15       ` Arnaldo Carvalho de Melo
2019-08-12 22:33       ` Lubashev, Igor
2019-08-12 22:33         ` Lubashev, Igor
2019-08-13 13:20         ` Arnaldo Carvalho de Melo
2019-08-13 13:20           ` Arnaldo Carvalho de Melo
2019-08-07 14:44 ` [PATCH v3 3/4] perf: Use CAP_SYSLOG with kptr_restrict checks Igor Lubashev
2019-08-07 14:44   ` Igor Lubashev
2019-08-14 18:04   ` Mathieu Poirier
2019-08-14 18:04     ` Mathieu Poirier
2019-08-14 18:48     ` Arnaldo Carvalho de Melo
2019-08-14 18:48       ` Arnaldo Carvalho de Melo
2019-08-14 18:52       ` Arnaldo Carvalho de Melo
2019-08-14 18:52         ` Arnaldo Carvalho de Melo
2019-08-14 20:02         ` Lubashev, Igor
2019-08-14 20:02           ` Lubashev, Igor
2019-08-15 15:01           ` Mathieu Poirier
2019-08-15 15:01             ` Mathieu Poirier
2019-08-15 20:16           ` Mathieu Poirier
2019-08-15 20:16             ` Mathieu Poirier
2019-08-15 21:42             ` Arnaldo Carvalho de Melo
2019-08-15 21:42               ` Arnaldo Carvalho de Melo
2019-08-19 16:51               ` Mathieu Poirier
2019-08-19 16:51                 ` Mathieu Poirier
2019-08-19 22:22                 ` Lubashev, Igor
2019-08-19 22:22                   ` Lubashev, Igor
2019-08-20 16:57                   ` Mathieu Poirier
2019-08-20 16:57                     ` Mathieu Poirier
2019-08-20 17:13                   ` Arnaldo Carvalho de Melo
2019-08-20 17:13                     ` Arnaldo Carvalho de Melo
2019-08-27  1:58                     ` Lubashev, Igor
2019-08-27  1:58                       ` Lubashev, Igor
2019-08-15 22:27             ` Lubashev, Igor
2019-08-15 22:27               ` Lubashev, Igor
2019-08-07 14:44 ` [PATCH v3 4/4] perf: Use CAP_SYS_ADMIN instead of euid==0 with ftrace Igor Lubashev
2019-08-07 14:44   ` Igor Lubashev
2019-08-12 20:22   ` Arnaldo Carvalho de Melo
2019-08-12 20:22     ` Arnaldo Carvalho de Melo
2019-08-12 20:27     ` Arnaldo Carvalho de Melo
2019-08-12 20:27       ` Arnaldo Carvalho de Melo
2019-08-12 20:29       ` Arnaldo Carvalho de Melo
2019-08-12 20:29         ` Arnaldo Carvalho de Melo
2019-08-12 21:42         ` Mathieu Poirier
2019-08-12 21:42           ` Mathieu Poirier
2019-08-13 13:23           ` Arnaldo Carvalho de Melo
2019-08-13 13:23             ` Arnaldo Carvalho de Melo
2019-08-13 16:35             ` Mathieu Poirier
2019-08-13 16:35               ` Mathieu Poirier
2019-08-15  9:27   ` [tip:perf/core] perf ftrace: Use CAP_SYS_ADMIN instead of euid==0 tip-bot for Igor Lubashev
2019-08-12  9:13 ` [PATCH v3 0/4] perf: Use capabilities instead of uid and euid Jiri Olsa
2019-08-12  9:13   ` Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-74d5f3d06f707eb5f7e1908ad88954bde02000ce@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=acme@redhat.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexey.budankov@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=ilubashe@akamai.com \
    --cc=jmorris@namei.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=suzuki.poulose@arm.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.