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]
Message-Id: <20230420220636.53527-5-tony.luck@intel.com>
Date:   Thu, 20 Apr 2023 15:06:33 -0700
From:   Tony Luck <tony.luck@...el.com>
To:     Fenghua Yu <fenghua.yu@...el.com>,
        Reinette Chatre <reinette.chatre@...el.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        "H. Peter Anvin" <hpa@...or.com>,
        Shaopeng Tan <tan.shaopeng@...itsu.com>,
        Jamie Iles <quic_jiles@...cinc.com>,
        James Morse <james.morse@....com>,
        Babu Moger <babu.moger@....com>
Cc:     x86@...nel.org, linux-kernel@...r.kernel.org,
        Tony Luck <tony.luck@...el.com>
Subject: [RFC PATCH 4/7] x86/resctrl: Add capability to driver registration to create control files

Add a control file to each ctrlmon directory. Hook into the mkdir()
functions to add the control file to any new directories that are
created.

Signed-off-by: Tony Luck <tony.luck@...el.com>
---
 include/linux/resctrl.h                |  2 +
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 70 ++++++++++++++++++++++++++
 2 files changed, 72 insertions(+)

diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 44dd811cb552..8668480cea51 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -217,6 +217,7 @@ struct resctrl_fileinfo {
  * @infodir:	Name of directory to create in resctrl/info.
  * @infofiles:	Array of files to create under infodir.
  * @rmdir:	Callback when a resctrl directory is removed.
+ * @ctrlfiles:	Array of files to create in ctrlmon directories.
  */
 struct resctrl_driver {
 	struct list_head	list;
@@ -224,6 +225,7 @@ struct resctrl_driver {
 	char			*infodir;
 	struct resctrl_fileinfo	*infofiles;
 	int			(*rmdir)(int oclos, int ormid, int nclos, int nrmid);
+	struct resctrl_fileinfo	*ctrlfiles;
 };
 
 int resctrl_register_driver(struct resctrl_driver *d);
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 8ca3b17bd671..e2fdd5819336 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -2466,6 +2466,18 @@ static int addfiles(struct kernfs_node *parent, struct resctrl_fileinfo *files,
 	return 0;
 }
 
+static void rmfiles(struct kernfs_node *parent, struct resctrl_fileinfo *files)
+{
+	struct resctrl_fileinfo *f;
+	struct kernfs_node *kn;
+
+	for (f = files; f->name; f++) {
+		kn = kernfs_find_and_get_ns(parent, f->name, NULL);
+		if (kn)
+			kernfs_remove(kn);
+	}
+}
+
 /*
  * Add or remove a directory from the resctrl/info directory
  */
@@ -2495,12 +2507,49 @@ static int rdtgroup_update_info_dir(char *name, struct resctrl_fileinfo *files)
 	return ret;
 }
 
+/*
+ * Create/remove a new control file in all current and future control and
+ * monitor groups.
+ */
+static void rdtgroup_update_ctrl_dir(struct resctrl_fileinfo *files, bool add)
+{
+	struct rdtgroup *rdtgrp;
+
+	if (!add) {
+		list_for_each_entry(rdtgrp, &rdt_all_groups, rdtgroup_list) {
+			struct rdtgroup *crg;
+
+			rmfiles(rdtgrp->kn, files);
+
+			list_for_each_entry(crg, &rdtgrp->mon.crdtgrp_list, mon.crdtgrp_list) {
+				rmfiles(crg->kn, files);
+			}
+		}
+
+		return;
+	}
+
+	list_for_each_entry(rdtgrp, &rdt_all_groups, rdtgroup_list) {
+		unsigned long priv = (rdtgrp->closid << 16) | rdtgrp->mon.rmid;
+		struct rdtgroup *crg;
+
+		addfiles(rdtgrp->kn, files, F_PRIV | F_ACTIVATE, (void *)priv);
+
+		list_for_each_entry(crg, &rdtgrp->mon.crdtgrp_list, mon.crdtgrp_list) {
+			priv = (crg->closid << 16) | crg->mon.rmid;
+			addfiles(crg->kn, files, F_PRIV | F_ACTIVATE, (void *)priv);
+		}
+	}
+}
+
 static void driver_up(struct resctrl_driver *d)
 {
 	if (d->mount)
 		d->mount(true);
 	if (d->infodir)
 		rdtgroup_update_info_dir(d->infodir, d->infofiles);
+	if (d->ctrlfiles)
+		rdtgroup_update_ctrl_dir(d->ctrlfiles, true);
 }
 
 static void driver_down(struct resctrl_driver *d)
@@ -2509,6 +2558,8 @@ static void driver_down(struct resctrl_driver *d)
 		d->mount(false);
 	if (d->infodir)
 		rdtgroup_update_info_dir(d->infodir, NULL);
+	if (d->ctrlfiles)
+		rdtgroup_update_ctrl_dir(d->ctrlfiles, false);
 }
 
 int resctrl_register_driver(struct resctrl_driver *d)
@@ -3375,6 +3426,7 @@ static int rdtgroup_mkdir_mon(struct kernfs_node *parent_kn,
 			      const char *name, umode_t mode)
 {
 	struct rdtgroup *rdtgrp, *prgrp;
+	struct resctrl_driver *d;
 	int ret;
 
 	ret = mkdir_rdt_prepare(parent_kn, name, mode, RDTMON_GROUP, &rdtgrp);
@@ -3384,6 +3436,14 @@ static int rdtgroup_mkdir_mon(struct kernfs_node *parent_kn,
 	prgrp = rdtgrp->mon.parent;
 	rdtgrp->closid = prgrp->closid;
 
+	list_for_each_entry(d, &drivers, list) {
+		unsigned long priv = (rdtgrp->closid << 16) | rdtgrp->mon.rmid;
+
+		if (!d->ctrlfiles)
+			continue;
+		addfiles(rdtgrp->kn, d->ctrlfiles, F_PRIV | F_ACTIVATE, (void *)priv);
+	}
+
 	/*
 	 * Add the rdtgrp to the list of rdtgrps the parent
 	 * ctrl_mon group has to track.
@@ -3401,6 +3461,7 @@ static int rdtgroup_mkdir_mon(struct kernfs_node *parent_kn,
 static int rdtgroup_mkdir_ctrl_mon(struct kernfs_node *parent_kn,
 				   const char *name, umode_t mode)
 {
+	struct resctrl_driver *d;
 	struct rdtgroup *rdtgrp;
 	struct kernfs_node *kn;
 	u32 closid;
@@ -3426,6 +3487,15 @@ static int rdtgroup_mkdir_ctrl_mon(struct kernfs_node *parent_kn,
 
 	list_add(&rdtgrp->rdtgroup_list, &rdt_all_groups);
 
+	list_for_each_entry(d, &drivers, list) {
+		unsigned long priv = (rdtgrp->closid << 16) | rdtgrp->mon.rmid;
+
+		if (!d->ctrlfiles)
+			continue;
+
+		addfiles(kn, d->ctrlfiles, F_PRIV | F_ACTIVATE, (void *)priv);
+	}
+
 	if (rdt_mon_capable) {
 		/*
 		 * Create an empty mon_groups directory to hold the subset
-- 
2.39.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ