[RFC PATCH 6/7] x86/resctrl: Allow a device to override an existing schemata entry

From: Tony Luck
Date: Thu Apr 20 2023 - 18:07:19 EST


Remove that entry from the resctrl_schema_all list when driver
is loaded. Put it back again when driver is unloaded.

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

diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 691805214f41..246644f53bde 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -223,6 +223,8 @@ struct resctrl_fileinfo {
* @rmdir: Callback when a resctrl directory is removed.
* @ctrlfiles: Array of files to create in ctrlmon directories.
* @schema: Driver supplied to manage a line in schemata file.
+ * @schema_override: Name of resource in schemata to override.
+ * @save_schema: List to save overridden schema while driver loaded
*/
struct resctrl_driver {
struct list_head list;
@@ -232,6 +234,8 @@ struct resctrl_driver {
int (*rmdir)(int oclos, int ormid, int nclos, int nrmid);
struct resctrl_fileinfo *ctrlfiles;
struct resctrl_schema schema;
+ char *schema_override;
+ struct list_head save_schema;
};

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 cc2292a7435b..4fc12ad56843 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -2547,6 +2547,19 @@ static void rdtgroup_update_ctrl_dir(struct resctrl_fileinfo *files, bool add)
}
}

+static void driver_override(struct resctrl_driver *d)
+{
+ struct resctrl_schema *rs;
+
+ list_for_each_entry(rs, &resctrl_schema_all, list) {
+ if (strncmp(d->schema_override, rs->name, sizeof(rs->name)))
+ continue;
+ INIT_LIST_HEAD(&d->save_schema);
+ list_move(&rs->list, &d->save_schema);
+ break;
+ }
+}
+
static void driver_up(struct resctrl_driver *d)
{
if (d->mount)
@@ -2575,6 +2588,9 @@ int resctrl_register_driver(struct resctrl_driver *d)
if (d->schema.name[0])
list_add(&d->schema.list, &resctrl_schema_all);

+ if (d->schema_override)
+ driver_override(d);
+
if (resctrl_is_mounted)
driver_up(d);
mutex_unlock(&rdtgroup_mutex);
@@ -2592,6 +2608,9 @@ void resctrl_unregister_driver(struct resctrl_driver *d)
if (d->schema.name[0])
list_del(&d->schema.list);

+ if (d->schema_override && !list_empty(&d->save_schema))
+ list_move(d->save_schema.next, &resctrl_schema_all);
+
if (resctrl_is_mounted)
driver_down(d);
mutex_unlock(&rdtgroup_mutex);
--
2.39.2