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:   Thu, 20 Apr 2023 15:06:31 -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 2/7] x86/resctrl: Add an interface to add/remove a new info/directory

Extend the resctrl_driver structure so that a driver may request
creation of a directory in the info/ hierarchy and populate it
with files.

Remove that info directory and contents when the resctrl file system is
unmounted, or the driver unregisters.

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

diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 78513edddca0..7847be48edae 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -204,14 +204,24 @@ struct resctrl_schema {
 	u32				num_closid;
 };
 
+struct resctrl_fileinfo {
+	char			*name;
+	struct kernfs_ops	*ops;
+	void			*priv;
+};
+
 /**
  * struct resctrl_driver - interface for driver to attach to resctrl
  * @list:	List of registered drivers
  * @mount:	Callback for mount/unmount
+ * @infodir:	Name of directory to create in resctrl/info.
+ * @infofiles:	Array of files to create under infodir.
  */
 struct resctrl_driver {
 	struct list_head	list;
 	void			(*mount)(bool mount);
+	char			*infodir;
+	struct resctrl_fileinfo	*infofiles;
 };
 
 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 3e6778bde427..4c662e827097 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -2440,16 +2440,75 @@ static int schemata_list_create(void)
 	return ret;
 }
 
+#define F_ACTIVATE	BIT(0)
+#define F_PRIV		BIT(1)
+
+static int addfiles(struct kernfs_node *parent, struct resctrl_fileinfo *files,
+		    int flags, void *priv)
+{
+	struct resctrl_fileinfo *f;
+	struct kernfs_node *kn;
+	umode_t mode;
+	void *p;
+
+	for (f = files; f->name; f++) {
+		mode = (f->ops->write) ? 0644 : 0444;
+		p = (flags & F_PRIV) ? priv : f->priv;
+		kn = __kernfs_create_file(parent, f->name, mode,
+					  GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, 0,
+					  f->ops, p, NULL, NULL);
+		if (IS_ERR(kn))
+			return PTR_ERR(kn);
+		if (flags & F_ACTIVATE)
+			kernfs_activate(kn);
+	}
+
+	return 0;
+}
+
+/*
+ * Add or remove a directory from the resctrl/info directory
+ */
+static int rdtgroup_update_info_dir(char *name, struct resctrl_fileinfo *files)
+{
+	struct kernfs_node *kn_subdir;
+	int ret;
+
+	if (!files) {
+		kn_subdir = kernfs_find_and_get_ns(kn_info, name, NULL);
+		if (kn_subdir)
+			kernfs_remove(kn_subdir);
+		return 0;
+	}
+
+	kn_subdir = kernfs_create_dir(kn_info, name, 0755, NULL);
+	if (IS_ERR(kn_subdir))
+		return PTR_ERR(kn_subdir);
+
+	ret = addfiles(kn_subdir, files, 0, 0);
+
+	if (ret)
+		kernfs_remove(kn_subdir);
+	else
+		kernfs_activate(kn_subdir);
+
+	return ret;
+}
+
 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);
 }
 
 static void driver_down(struct resctrl_driver *d)
 {
 	if (d->mount)
 		d->mount(false);
+	if (d->infodir)
+		rdtgroup_update_info_dir(d->infodir, NULL);
 }
 
 int resctrl_register_driver(struct resctrl_driver *d)
-- 
2.39.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ