lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <1347447685-28513-1-git-send-email-robert.richter@amd.com>
Date:	Wed, 12 Sep 2012 13:01:25 +0200
From:	Robert Richter <robert.richter@....com>
To:	Peter Zijlstra <peterz@...radead.org>
CC:	Ingo Molnar <mingo@...nel.org>,
	Stephane Eranian <eranian@...gle.com>,
	LKML <linux-kernel@...r.kernel.org>,
	Robert Richter <robert.richter@....com>
Subject: [PATCH] perf: Introduce function to report unsupported syscall attribute flags

Often a syscall fails with

   Error: sys_perf_event_open() syscall returned with 95 (Operation not supported).  /bin/dmesg may provide additional information.

but no additional information.

This patch adds some macro magic and a helper function to check and
report unsupported syscall attribute flags:

 has_unsupported_flags(attr1, attr2);
 has_unsupported_flag(attr, flag);
 __has_unsupported_flags(const struct perf_event_attr *attr,
                         u64 notsup);

E.g. dmesg reports the following (checking for the exclude_guest
flag):

 perf: unsupported attribute flags: 0000000000100000

or (checking precise modifier :ppp):

 perf: unsupported attribute flags: 0000000000018000

Signed-off-by: Robert Richter <robert.richter@....com>
---
 arch/x86/kernel/cpu/perf_event.c         |   19 ++++++++++---------
 arch/x86/kernel/cpu/perf_event_amd_ibs.c |    3 ++-
 include/linux/perf_event.h               |   23 +++++++++++++++++++++++
 kernel/events/core.c                     |    2 +-
 4 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 915b876..9ae8676 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -336,7 +336,7 @@ int x86_setup_perfctr(struct perf_event *event)
 			return -EOPNOTSUPP;
 
 		/* BTS is currently only allowed for user-mode. */
-		if (!attr->exclude_kernel)
+		if (has_unsupported_flag(attr, exclude_kernel))
 			return -EOPNOTSUPP;
 	}
 
@@ -389,8 +389,11 @@ int x86_pmu_hw_config(struct perf_event *event)
 				precise++;
 		}
 
-		if (event->attr.precise_ip > precise)
+		if (event->attr.precise_ip > precise) {
+			has_unsupported_flag(&event->attr, precise_ip);
 			return -EOPNOTSUPP;
+		}
+
 		/*
 		 * check that PEBS LBR correction does not conflict with
 		 * whatever the user is asking with attr->branch_sample_type
@@ -398,13 +401,7 @@ int x86_pmu_hw_config(struct perf_event *event)
 		if (event->attr.precise_ip > 1) {
 			u64 *br_type = &event->attr.branch_sample_type;
 
-			if (has_branch_stack(event)) {
-				if (!precise_br_compat(event))
-					return -EOPNOTSUPP;
-
-				/* branch_sample_type is compatible */
-
-			} else {
+			if (!has_branch_stack(event)) {
 				/*
 				 * user did not specify  branch_sample_type
 				 *
@@ -419,7 +416,11 @@ int x86_pmu_hw_config(struct perf_event *event)
 
 				if (!event->attr.exclude_kernel)
 					*br_type |= PERF_SAMPLE_BRANCH_KERNEL;
+			} else if (!precise_br_compat(event)) {
+				has_unsupported_flag(&event->attr, precise_ip);
+				return -EOPNOTSUPP;
 			}
+			/* else: branch_sample_type is compatible */
 		}
 	}
 
diff --git a/arch/x86/kernel/cpu/perf_event_amd_ibs.c b/arch/x86/kernel/cpu/perf_event_amd_ibs.c
index 4af8275..fc145b0 100644
--- a/arch/x86/kernel/cpu/perf_event_amd_ibs.c
+++ b/arch/x86/kernel/cpu/perf_event_amd_ibs.c
@@ -186,6 +186,7 @@ static int perf_ibs_precise_event(struct perf_event *event, u64 *config)
 	case 2:
 		break;
 	default:
+		has_unsupported_flag(&event->attr, precise_ip);
 		return -EOPNOTSUPP;
 	}
 
@@ -243,7 +244,7 @@ static int perf_ibs_init(struct perf_event *event)
 	if (event->pmu != &perf_ibs->pmu)
 		return -ENOENT;
 
-	if (perf_flags(&event->attr) & perf_flags(&ibs_notsupp))
+	if (has_unsupported_flags(&event->attr, &ibs_notsupp))
 		return -EINVAL;
 
 	if (config & ~perf_ibs->config_mask)
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index c36a04f..eb247a5 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -305,6 +305,14 @@ struct perf_event_attr {
 };
 
 #define perf_flags(attr)	(*(&(attr)->read_format + 1))
+#define perf_flags_init(flag) ({					\
+	volatile __u64	flags = 0;					\
+	struct perf_event_attr *attr;					\
+	attr = (void *)((char *)&flags -				\
+			(char *)&perf_flags((struct perf_event_attr *)(0))); \
+	if (!WARN_ON(&perf_flags(attr) != &flags)) 			\
+		attr->flag = ~0;					\
+	flags;})
 
 /*
  * Ioctls that can be done on a perf event fd:
@@ -1208,6 +1216,21 @@ extern int perf_event_overflow(struct perf_event *event,
 				 struct perf_sample_data *data,
 				 struct pt_regs *regs);
 
+static inline bool __has_unsupported_flags(const struct perf_event_attr *attr,
+					   u64 notsup)
+{
+	notsup &= perf_flags(attr);
+	if (notsup)
+		pr_warn("perf: unsupported attribute flags: %016llx\n", notsup);
+	return notsup != 0;
+}
+
+#define has_unsupported_flags(attr1, attr2) \
+	__has_unsupported_flags((attr1), perf_flags(attr2))
+/* flag is the name of the member in struct perf_event_attr: */
+#define has_unsupported_flag(attr, flag) \
+	__has_unsupported_flags((attr), perf_flags_init(flag))
+
 static inline bool is_sampling_event(struct perf_event *event)
 {
 	return event->attr.sample_period != 0;
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 2ba8904..2667ef6 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6291,7 +6291,7 @@ static int perf_copy_attr(struct perf_event_attr __user *uattr,
 	if (ret)
 		return -EFAULT;
 
-	if (attr->__reserved_1)
+	if (has_unsupported_flag(attr, __reserved_1))
 		return -EINVAL;
 
 	if (attr->sample_type & ~(PERF_SAMPLE_MAX-1))
-- 
1.7.8.6


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ