[PATCH 00/11] x86,fs/resctrl: Improve resctrl quality and consistency

Reinette Chatre posted 11 patches 6 hours ago
arch/x86/kernel/cpu/resctrl/core.c |   4 +-
fs/resctrl/ctrlmondata.c           |  70 +++++++++-------
fs/resctrl/monitor.c               |  80 +++++++++++--------
fs/resctrl/pseudo_lock.c           |   2 +-
fs/resctrl/rdtgroup.c              | 124 ++++++++++++++++++-----------
include/linux/resctrl.h            |   8 +-
6 files changed, 173 insertions(+), 115 deletions(-)
[PATCH 00/11] x86,fs/resctrl: Improve resctrl quality and consistency
Posted by Reinette Chatre 6 hours ago
Hi Everybody,

This is a collection of resctrl cleanups assembled together for convenience
and simpler tracking. I'd be happy to split them up if it makes review and/or
handling easier.

Summary of changes:

- Let resctrl pass stricter checks from various tools to provide a cleaner
  baseline with the goal to promote healthier contributions:
  - ./tools/docs/kernel-doc -Wall -v <files>
  - Build with W=12
  - ./scripts/coccicheck
  - Static checkers

- Use accurate and consistent type for all uses of resource ID.

- In the unlikely scenario that resctrl picked a wrong CPU to read an event
  from, pass the error through to user space instead of claiming to succeed
  and returning a (wrong) result.

- Since inception of last_cmd_status feature there have been mismatches
  between resctrl file operation failures and the contents of
  info/last_cmd_status. This pattern keeps propagating with each new resctrl
  feature. Establish a new baseline with a new pattern that ensures
  info/last_cmd_status contains an accurate failure description that matches
  the most recent resctrl file operation failure.

One potential open:

There remains an inconsistency between resctrl file operations that do/can
_not_ fail and the contents of info/last_cmd_status. If a resctrl
file operation fails and an informational error is printed to last_cmd_status
then a subsequent reading of a resctrl file (specifically most of the files
found in info/) may succeed while info/last_cmd_status may or may not return
the error from previous failure.

Ensuring last_cmd_status is reset on every read carries the cost of taking
rdtgroup_mutex on several more user space initiated paths and thus increase
contention on rdtgroup_mutex. I opted to not make this change and instead
focus this work on ensuring that last_cmd_status is accurate whenever there is
a failure during any resctrl file operation. Please let me know if you have
opinions in this regard.

Any feedback is appreciated.

Regards,

Reinette


Reinette Chatre (11):
  fs/resctrl: Add missing return value descriptions
  fs/resctrl: Avoid "may be used uninitialized" warning
  fs/resctrl: Use correct format specifier for printing error pointers
  x86/resctrl: Protect against bad shift
  fs/resctrl: Use accurate type for rdt_resource::rid
  fs/resctrl: Pass error reading event through to user space
  fs/resctrl: Add last_cmd_status support for writes to
    max_threshold_occupancy
  fs/resctrl: Use accurate and symmetric exit flows
  fs/resctrl: Use stricter checks on input to cpus/cpus_list file
  fs/resctrl: Change last_cmd_status custom during input parsing
  fs/resctrl: Communicate resource group deleted error via
    last_cmd_status

 arch/x86/kernel/cpu/resctrl/core.c |   4 +-
 fs/resctrl/ctrlmondata.c           |  70 +++++++++-------
 fs/resctrl/monitor.c               |  80 +++++++++++--------
 fs/resctrl/pseudo_lock.c           |   2 +-
 fs/resctrl/rdtgroup.c              | 124 ++++++++++++++++++-----------
 include/linux/resctrl.h            |   8 +-
 6 files changed, 173 insertions(+), 115 deletions(-)

-- 
2.50.1
Re: [PATCH 00/11] x86,fs/resctrl: Improve resctrl quality and consistency
Posted by Luck, Tony an hour ago
On Mon, Mar 02, 2026 at 10:46:06AM -0800, Reinette Chatre wrote:
> Hi Everybody,
> 
> This is a collection of resctrl cleanups assembled together for convenience
> and simpler tracking. I'd be happy to split them up if it makes review and/or
> handling easier.

If it is time for spring cleaning in the rescctrl code, maybe fix some
bad fir tree declarations too?

Note resctrl_arch_pseudo_lock_fn() needs help too, but complicated by
having #ifdef CONFIG_KASAN mixed in with declarations. It might need
to remain an exception.

-Tony


From dd9c2ad1a1361b34e25fc10d18d3ceb3ba57fb92 Mon Sep 17 00:00:00 2001
From: Tony Luck <tony.luck@intel.com>
Date: Mon, 2 Mar 2026 15:28:36 -0800
Subject: [PATCH] fs/resctrl: Clean up some bad "fir tree" declarations

Sort local variables by length (longest first) per TIP tree.

Signed-off-by: Tony Luck <tony.luck@intel.com>
---
 fs/resctrl/pseudo_lock.c | 2 +-
 fs/resctrl/rdtgroup.c    | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/resctrl/pseudo_lock.c b/fs/resctrl/pseudo_lock.c
index e1e9134474f4..cd57d862e0cf 100644
--- a/fs/resctrl/pseudo_lock.c
+++ b/fs/resctrl/pseudo_lock.c
@@ -797,10 +797,10 @@ static const struct file_operations pseudo_measure_fops = {
 int rdtgroup_pseudo_lock_create(struct rdtgroup *rdtgrp)
 {
 	struct pseudo_lock_region *plr = rdtgrp->plr;
+	char *kn_name __free(kfree) = NULL;
 	struct task_struct *thread;
 	unsigned int new_minor;
 	struct device *dev;
-	char *kn_name __free(kfree) = NULL;
 	int ret;
 
 	ret = pseudo_lock_region_alloc(plr);
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 0e93cecf6f30..b2ca6394714a 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -3423,8 +3423,8 @@ static int mkdir_mondata_subdir(struct kernfs_node *parent_kn,
 static void mkdir_mondata_subdir_allrdtgrp(struct rdt_resource *r,
 					   struct rdt_domain_hdr *hdr)
 {
-	struct kernfs_node *parent_kn;
 	struct rdtgroup *prgrp, *crgrp;
+	struct kernfs_node *parent_kn;
 	struct list_head *head;
 
 	list_for_each_entry(prgrp, &rdt_all_groups, rdtgroup_list) {
@@ -3559,9 +3559,9 @@ static int __init_one_rdt_domain(struct rdt_ctrl_domain *d, struct resctrl_schem
 	struct resctrl_staged_config *cfg;
 	struct rdt_resource *r = s->res;
 	u32 used_b = 0, unused_b = 0;
+	u32 peer_ctl, ctrl_val;
 	unsigned long tmp_cbm;
 	enum rdtgrp_mode mode;
-	u32 peer_ctl, ctrl_val;
 	int i;
 
 	cfg = &d->staged_config[t];
-- 
2.53.0