[RFC PATCH 02/13] resctrl: Add prepare, commit and abort hooks for control updates
From: Yunhui Cui
Date: Sun Nov 29 2026 - 21:30:30 EST
A schemata write may update several controllers, and allocating entries
while each controller is programmed can leave a partial update if a
later allocation fails. Add prepare, commit and abort hooks so mapping
backends can reserve all required entries before programming policies,
publish mappings after the updates succeed, and discard reservations on
failure. Identity backends use no-op hooks.
Signed-off-by: Yunhui Cui <cuiyunhui@xxxxxxxxxxxxx>
---
arch/x86/kernel/cpu/resctrl/ctrlmondata.c | 14 +++++++++++++
drivers/resctrl/mpam_resctrl.c | 14 +++++++++++++
fs/resctrl/ctrlmondata.c | 24 +++++++++++++++++++++--
include/linux/resctrl.h | 7 +++++++
4 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
index 1c2b20f623a37..f6ecbf10ca700 100644
--- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
+++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
@@ -104,6 +104,20 @@ int resctrl_arch_update_io_alloc(struct rdt_resource *r, u32 physical_ctrl_id)
return resctrl_arch_update_domains_id(r, physical_ctrl_id);
}
+int resctrl_arch_prepare_ctrl_update(u32 logical_ctrl_id)
+{
+ return 0;
+}
+
+int resctrl_arch_commit_ctrl_update(u32 logical_ctrl_id)
+{
+ return 0;
+}
+
+void resctrl_arch_abort_ctrl_update(u32 logical_ctrl_id)
+{
+}
+
u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_ctrl_domain *d,
u32 closid, enum resctrl_conf_type type)
{
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index 2cb098eaf22a1..9d34b1c214d32 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -1548,6 +1548,20 @@ int resctrl_arch_update_io_alloc(struct rdt_resource *r, u32 physical_ctrl_id)
return resctrl_arch_update_domains_id(r, physical_ctrl_id);
}
+int resctrl_arch_prepare_ctrl_update(u32 logical_ctrl_id)
+{
+ return 0;
+}
+
+int resctrl_arch_commit_ctrl_update(u32 logical_ctrl_id)
+{
+ return 0;
+}
+
+void resctrl_arch_abort_ctrl_update(u32 logical_ctrl_id)
+{
+}
+
void resctrl_arch_reset_all_ctrls(struct rdt_resource *r)
{
struct mpam_resctrl_res *res;
diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c
index eb3248350254b..4e95f5ded87cb 100644
--- a/fs/resctrl/ctrlmondata.c
+++ b/fs/resctrl/ctrlmondata.c
@@ -349,6 +349,12 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
goto out_clear_staged;
}
+ ret = resctrl_arch_prepare_ctrl_update(rdtgrp->closid);
+ if (ret) {
+ rdt_last_cmd_printf("Failed to prepare control update: %d\n", ret);
+ goto out_clear_staged;
+ }
+
list_for_each_entry(s, &resctrl_schema_all, list) {
r = s->res;
@@ -360,8 +366,17 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
continue;
ret = resctrl_arch_update_domains(r, rdtgrp->closid);
- if (ret)
- goto out_clear_staged;
+ if (ret) {
+ rdt_last_cmd_printf("Failed to update resource %s: %d\n",
+ r->name, ret);
+ goto out_abort_update;
+ }
+ }
+
+ ret = resctrl_arch_commit_ctrl_update(rdtgrp->closid);
+ if (ret) {
+ rdt_last_cmd_printf("Failed to commit control update: %d\n", ret);
+ goto out_abort_update;
}
if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
@@ -374,6 +389,11 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
ret = rdtgroup_pseudo_lock_create(rdtgrp);
}
+ goto out_clear_staged;
+
+out_abort_update:
+ resctrl_arch_abort_ctrl_update(rdtgrp->closid);
+
out_clear_staged:
rdt_staged_configs_clear();
out_unlock:
diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index a5e3e4b3fd836..db6558a8f47eb 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -417,6 +417,13 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 logical_ctrl_id);
int resctrl_arch_update_io_alloc(struct rdt_resource *r, u32 physical_ctrl_id);
+/* Failed prepare unwinds its reservations; later failures call abort. */
+int resctrl_arch_prepare_ctrl_update(u32 logical_ctrl_id);
+
+int resctrl_arch_commit_ctrl_update(u32 logical_ctrl_id);
+
+void resctrl_arch_abort_ctrl_update(u32 logical_ctrl_id);
+
bool resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu,
unsigned int binary_bits, void *arch_priv);
--
2.39.2 (Apple Git-143)