Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1512699ybi; Wed, 17 Jul 2019 16:51:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqyhskm/oJqbmSgeHYmXcgOF46McJVFYM2h4jhp+M7jIOROi5ZrOU6OFKmz7Q4s4zAaA+OWF X-Received: by 2002:a63:ec03:: with SMTP id j3mr17272759pgh.325.1563407464992; Wed, 17 Jul 2019 16:51:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563407464; cv=none; d=google.com; s=arc-20160816; b=Hj2uZ0JhedGhpdkKMuoQeNozVfSAaabmO1wdJB0O5ShzB4vdAw3Cn5X28vnADCIKQv XB7OrVvQrOfrgTMAV7HpUalIQvADm8wMCKA3hSAR9cmWc3+vDVnU21esHFAdjzA9aKDj r7AKkASxw3+LwGiBeBFNyHBJlc7J1U6w+TuWnWjhnQHlVdV6YVCEL06IDPGbpFcMyMfb eVrS0xWaNiy2/1KKC+EWUGZ7kRgOTvP2r6vQ3ZACzw6DCHwA0/qreBQUblDiKobPyK6D Tk25FZlW9kc8wcLNwXhARrfzfAZlWDLZqL8fWXiFJvJw18dw1z85ZZg0MU9JG17nixr3 L7EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=zMchTV0CYGbg84sqbUscTEiGoh4ZNOfQBOF6+rYvMvM=; b=xvLY++7ChyRD6ufaGCZyMeKD2CsOqL4/rMcvOda1gBXdWJkI3p0kigo349yw4TmagO VUmq4jxotLmqVB2VnTGsTiQMyyiD2aZkw9D6l/5tBMHT2bef3KoM/BCX21NwuEILUXZA 0pZW/lGdh+V+I6UXy3n/oqi6o4JgI4eKgFByJHyrzQwtuO1YFrr0EmI6Y0CCE0KL8ck3 kuC3CjGd8Vj1OZYMY7XTkKaisvMah6+Kw71EoMwV23N/EeYux7zVLOIX01BFX+gFsfaQ S89uYgHJqrWaYh7iE1ipTigZTIe9NoyRaaxrMShcogDoT6SPdgtTRlRs7CLi7HQcJqOg WxcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VgBhx7Sj; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t135si249234pfc.251.2019.07.17.16.50.48; Wed, 17 Jul 2019 16:51:04 -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=@gmail.com header.s=20161025 header.b=VgBhx7Sj; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729489AbfGQXss (ORCPT + 99 others); Wed, 17 Jul 2019 19:48:48 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:44428 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727883AbfGQXss (ORCPT ); Wed, 17 Jul 2019 19:48:48 -0400 Received: by mail-qt1-f195.google.com with SMTP id 44so25200387qtg.11 for ; Wed, 17 Jul 2019 16:48:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=zMchTV0CYGbg84sqbUscTEiGoh4ZNOfQBOF6+rYvMvM=; b=VgBhx7SjnU3aZWxmPPQ2OoUR9AH7Ta3hf+GdlK3DVLa2MW+A0jF0E2jD69VmSHpxPv lL82mFXM7Qwr+KqED4MQHbVdf36MgHttYMYWfpGU0+uWWf4gx6EbKz/NlD0xhdtpwdkV DdbF+5BarySc6ilWcFeO0g35W58aj7t8yBh/tvvpU/kZ8GKVa10uv/Aba+8e4AYEvTOR daqWQh2Wd0xc6UzedoxtaSO7uzNR2oybC28KnGQDEyGzcyjkVaT3CgWUO9Cv2GiGh7pQ 0B8RFd7cDzjrJKMoWDfc7413dzcnwPdjVBTsLL3+hI436TV9jAIvMbDKC4sA14yr8K3L RU4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=zMchTV0CYGbg84sqbUscTEiGoh4ZNOfQBOF6+rYvMvM=; b=brxZYrVSNGtdVfufzxEc8ODvTdJ+DOrJtmACiDo8CPqM3tjCsOCDfeByu2N8brbmlj X5iHZaLXTQUeY8wsky0/mnoiLUebbL3xLASJvFSWgjRjwD3HnoE6jXAjektqkbEjWpBe VblKQfqWckVgzg4JrfFL5LPgAYGGaqs1lYK57hQw/C/6D/47t/Rp/nfVjhhL/WEamZcI hLk+JrdesRnwI/RhYuwdlzzn6kF1H+jFcWCybNXGpqWFGL+1jR8tiz3yxTRpQyEpY3+y agkGjGrDjS5DgIww0KQ2IAb55PE5S5HTxMwVFZbZ4qXZNvdaSFE30RWrZWg0TYls7CHS q9QQ== X-Gm-Message-State: APjAAAU1Dr6Q2iR+Ucb+oQcyaNbrc8RNBXfa8BIfpwGQ69cEPqEZaaQb LakSGetJ3rO+8jkGXVpKz9E= X-Received: by 2002:ac8:2379:: with SMTP id b54mr30357888qtb.168.1563407326563; Wed, 17 Jul 2019 16:48:46 -0700 (PDT) Received: from quaco.ghostprotocols.net ([179.97.35.11]) by smtp.gmail.com with ESMTPSA id t6sm11477750qkh.129.2019.07.17.16.48.45 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 17 Jul 2019 16:48:45 -0700 (PDT) From: Arnaldo Carvalho de Melo X-Google-Original-From: Arnaldo Carvalho de Melo Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 4BD6C40340; Wed, 17 Jul 2019 20:48:43 -0300 (-03) Date: Wed, 17 Jul 2019 20:48:43 -0300 To: Igor Lubashev Cc: Jiri Olsa , linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Mathieu Poirier , Alexander Shishkin , Namhyung Kim , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, James Morris Subject: Re: [PATCH 1/3] perf: Add capability-related utilities Message-ID: <20190717234843.GK3624@kernel.org> References: <1562112605-6235-1-git-send-email-ilubashe@akamai.com> <1562112605-6235-2-git-send-email-ilubashe@akamai.com> <20190716084643.GA22317@krava> <20190717210551.GI3624@kernel.org> <20190717234652.GJ3624@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190717234652.GJ3624@kernel.org> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.12.0 (2019-05-25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, Jul 17, 2019 at 08:46:52PM -0300, Arnaldo Carvalho de Melo escreveu: > I'll do it if there is any difficulty, just not right now as I'm busy > and want to get a pull req out of the door. Also please find the first patch fixed up wrt a conflict with the pythong binding, please use it instead as that is what applies to my current perf/core branch. It has the ack from Alexey and one I think Jiri would provide, judging from his positive tone to the patches :) - Arnaldo commit 8048a0884a3f98bae2434d141711d72382b784b0 Author: Igor Lubashev Date: Wed Jul 17 20:39:03 2019 -0300 perf tools: Add capability-related utilities Add utilities to help checking capabilities of the running process. Make perf link with libcap. Signed-off-by: Igor Lubashev Acked-by: Alexey Budankov Acked-by: Jiri Olsa CC: Alexander Shishkin Cc: James Morris Cc: Mathieu Poirier Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Suzuki K Poulose Link: https://lkml.kernel.org/r/1562112605-6235-2-git-send-email-ilubashe@akamai.com Signed-off-by: Arnaldo Carvalho de Melo diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index 89ac5a1f1550..b9cf084f32d7 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -259,7 +259,7 @@ CXXFLAGS += -Wno-strict-aliasing # adding assembler files missing the .GNU-stack linker note. LDFLAGS += -Wl,-z,noexecstack -EXTLIBS = -lpthread -lrt -lm -ldl +EXTLIBS = -lpthread -lrt -lm -ldl -lcap ifeq ($(FEATURES_DUMP),) include $(srctree)/tools/build/Makefile.feature diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 14f812bb07a7..61ed1a3005d4 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -1,6 +1,7 @@ perf-y += annotate.o perf-y += block-range.o perf-y += build-id.o +perf-y += cap.o perf-y += config.o perf-y += ctype.o perf-y += db-export.o diff --git a/tools/perf/util/cap.c b/tools/perf/util/cap.c new file mode 100644 index 000000000000..c42ea32663cf --- /dev/null +++ b/tools/perf/util/cap.c @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Capability utilities + */ +#include "cap.h" +#include +#include + +bool perf_cap__capable(cap_value_t cap) +{ + cap_flag_value_t val; + cap_t caps = cap_get_proc(); + + if (!caps) + return false; + + if (cap_get_flag(caps, cap, CAP_EFFECTIVE, &val) != 0) + val = CAP_CLEAR; + + if (cap_free(caps) != 0) + return false; + + return val == CAP_SET; +} diff --git a/tools/perf/util/cap.h b/tools/perf/util/cap.h new file mode 100644 index 000000000000..5521de78b228 --- /dev/null +++ b/tools/perf/util/cap.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __PERF_CAP_H +#define __PERF_CAP_H + +#include +#include + +bool perf_cap__capable(cap_value_t cap); + +#endif /* __PERF_CAP_H */ diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index 1f1da6082806..b4128f72f2e8 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h @@ -851,6 +851,7 @@ void cpu_map_data__synthesize(struct cpu_map_data *data, struct cpu_map *map, void event_attr_init(struct perf_event_attr *attr); int perf_event_paranoid(void); +bool perf_event_paranoid_check(int max_level); extern int sysctl_perf_event_max_stack; extern int sysctl_perf_event_max_contexts_per_stack; diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources index ceb8afdf9a89..afba10684b65 100644 --- a/tools/perf/util/python-ext-sources +++ b/tools/perf/util/python-ext-sources @@ -9,6 +9,7 @@ util/python.c ../lib/ctype.c util/evlist.c util/evsel.c +util/cap.c util/cpumap.c util/memswap.c util/mmap.c diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index a61535cf1bca..4f0da8a03697 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -16,10 +16,12 @@ #include #include #include +#include #include #include #include #include +#include "cap.h" #include "strlist.h" #include "string2.h" @@ -443,6 +445,13 @@ int perf_event_paranoid(void) return value; } + +bool perf_event_paranoid_check(int max_level) +{ + return perf_cap__capable(CAP_SYS_ADMIN) || + perf_event_paranoid() <= max_level; +} + static int fetch_ubuntu_kernel_version(unsigned int *puint) {