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-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sat, 29 Oct 2016 17:38:02 -0700
From:   David Carrillo-Cisneros <davidcc@...gle.com>
To:     linux-kernel@...r.kernel.org
Cc:     "x86@...nel.org" <x86@...nel.org>, Ingo Molnar <mingo@...hat.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Andi Kleen <ak@...ux.intel.com>,
        Kan Liang <kan.liang@...el.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Vegard Nossum <vegard.nossum@...il.com>,
        Marcelo Tosatti <mtosatti@...hat.com>,
        Nilay Vaish <nilayvaish@...il.com>,
        Borislav Petkov <bp@...e.de>,
        Vikas Shivappa <vikas.shivappa@...ux.intel.com>,
        Ravi V Shankar <ravi.v.shankar@...el.com>,
        Fenghua Yu <fenghua.yu@...el.com>,
        Paul Turner <pjt@...gle.com>,
        Stephane Eranian <eranian@...gle.com>,
        David Carrillo-Cisneros <davidcc@...gle.com>
Subject: [PATCH v3 05/46] perf/x86/intel/cmt: add per-package locks

Per-package locks potentially reduce the contention when compared to the
system-wide approach of the previous CQM/CMT driver.

Lockdep needs lock_class_key's to be statically initialized and/or use
nesting, but nesting is currently hard-coded for up to 8 levels and it's
fragile to depend on lockdep internals.
To circumvent this problem, statically define CMT_MAX_NR_PKGS number of
lock_class_key's.

Additional details in code's comments.

Signed-off-by: David Carrillo-Cisneros <davidcc@...gle.com>
---
 arch/x86/events/intel/cmt.c | 22 ++++++++++++++++++++++
 arch/x86/events/intel/cmt.h |  8 ++++++++
 2 files changed, 30 insertions(+)

diff --git a/arch/x86/events/intel/cmt.c b/arch/x86/events/intel/cmt.c
index 267a9ec..f12a06b 100644
--- a/arch/x86/events/intel/cmt.c
+++ b/arch/x86/events/intel/cmt.c
@@ -7,6 +7,14 @@
 #include "cmt.h"
 #include "../perf_event.h"
 
+/* Increase as needed as Intel CPUs grow. */
+#define CMT_MAX_NR_PKGS		8
+
+#ifdef CONFIG_LOCKDEP
+static struct lock_class_key	mutex_keys[CMT_MAX_NR_PKGS];
+static struct lock_class_key	lock_keys[CMT_MAX_NR_PKGS];
+#endif
+
 static DEFINE_MUTEX(cmt_mutex);
 
 static unsigned int cmt_l3_scale;	/* cmt hw units to bytes. */
@@ -51,6 +59,12 @@ static struct pkg_data *alloc_pkg_data(int cpu)
 	int numa_node = cpu_to_node(cpu);
 	u16 pkgid = topology_logical_package_id(cpu);
 
+	if (pkgid >= CMT_MAX_NR_PKGS) {
+		pr_err("CMT_MAX_NR_PKGS of %d is insufficient for logical packages.\n",
+		       CMT_MAX_NR_PKGS);
+		return ERR_PTR(-ENOSPC);
+	}
+
 	if (c->x86_cache_occ_scale != cmt_l3_scale) {
 		/* 0 scale must have been converted to 1 automatically. */
 		if (c->x86_cache_occ_scale || cmt_l3_scale != 1) {
@@ -65,9 +79,17 @@ static struct pkg_data *alloc_pkg_data(int cpu)
 
 	pkgd->max_rmid = c->x86_cache_max_rmid;
 
+	mutex_init(&pkgd->mutex);
+	raw_spin_lock_init(&pkgd->lock);
+
 	pkgd->work_cpu = cpu;
 	pkgd->pkgid = pkgid;
 
+#ifdef CONFIG_LOCKDEP
+	lockdep_set_class(&pkgd->mutex, &mutex_keys[pkgid]);
+	lockdep_set_class(&pkgd->lock, &lock_keys[pkgid]);
+#endif
+
 	__min_max_rmid = min(__min_max_rmid, pkgd->max_rmid);
 
 	return pkgd;
diff --git a/arch/x86/events/intel/cmt.h b/arch/x86/events/intel/cmt.h
index 8c16797..55416db 100644
--- a/arch/x86/events/intel/cmt.h
+++ b/arch/x86/events/intel/cmt.h
@@ -11,11 +11,16 @@
  * Rules:
  *  - cmt_mutex: Hold for CMT init/terminate, event init/terminate,
  *  cgroup start/stop.
+ *  - Hold pkg->mutex and pkg->lock in _all_ active packages to traverse or
+ *  change the monr hierarchy.
+ *  - pkgd->lock: Hold in current package to access that pkgd's members.
  */
 
 /**
  * struct pkg_data - Per-package CMT data.
  *
+ * @mutex:			Hold when modifying this pkg_data.
+ * @lock:			Hold to protect pmonrs in this pkg_data.
  * @work_cpu:			CPU to run rotation and other batch jobs.
  *				It must be in the package associated to its
  *				instance of pkg_data.
@@ -23,6 +28,9 @@
  * @pkgid:			The logical package id for this pkgd.
  */
 struct pkg_data {
+	struct mutex		mutex;
+	raw_spinlock_t		lock;
+
 	unsigned int		work_cpu;
 	u32			max_rmid;
 	u16			pkgid;
-- 
2.8.0.rc3.226.g39d4020

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ