public inbox for patches@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH v3 00/13] x86,fs/resctrl: Improve resctrl quality and consistency
@ 2026-04-07 16:01 Reinette Chatre
  2026-04-07 16:01 ` [PATCH v3 01/13] MAINTAINERS: Update resctrl entry Reinette Chatre
                   ` (12 more replies)
  0 siblings, 13 replies; 19+ messages in thread
From: Reinette Chatre @ 2026-04-07 16:01 UTC (permalink / raw)
  To: tony.luck, james.morse, Dave.Martin, babu.moger, bp, tglx,
	dave.hansen
  Cc: x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches, reinette.chatre

Changes since v2:
- v2: https://lore.kernel.org/lkml/cover.1774043709.git.reinette.chatre@intel.com/
- Rebased on top of tip/master with pending resctrl selftest changes,
  https://lore.kernel.org/lkml/cover.1775266384.git.reinette.chatre@intel.com/,
  applied on top to support testing with latest kernel that has pending resctrl
  changes merged.
- Drop "fs/resctrl: Use stricter checks on input to cpus/cpus_list file"
  that ended up being too strict and removed one use case. (Chris)
- max_threshold_occ_write() switch to guard(). (Chenyu)
- Add more detail to one return value description.
- Add tags.
- No opinions so far on needing to update last_cmd_status on success of all read
  commands. At this time last_cmd_status will continue to return previous
  failure message (if any) after a read command accessing static data succeeds.

Changes since v1:
- v1: https://lore.kernel.org/lkml/cover.1772476561.git.reinette.chatre@intel.com/
- To simplify tracking, include patch to MAINTAINERS submitted separately:
  https://lore.kernel.org/lkml/4274c478922c01f9ceebc805acf991f10a95519f.1771442788.git.reinette.chatre@intel.com/
- Follow recent upstream changes to add reference to tip tree handbook in
  MAINTAINERS entry.
- Use new pattern in resctrl to enable looping over all entries of an enum
  while making adding new enum entries more clear all while avoiding warnings
  when compiling with -Wswitch. (Ben)
- Add another last_cmd_status enhancement that appends "[truncated]" to
  output of info/last_cmd_status if the backing buffer overflowed.
- Please see patch changelogs for details of changes.
- Add tags.

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 (13):
  MAINTAINERS: Update resctrl entry
  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: Change pattern used to track number of entries in enum
  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: Change last_cmd_status custom during input parsing
  fs/resctrl: Communicate resource group deleted error via
    last_cmd_status
  fs/resctrl: Inform user space when status buffer overflowed

 MAINTAINERS                        |   2 +
 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              | 126 ++++++++++++++++++-----------
 include/linux/resctrl.h            |  11 +--
 7 files changed, 180 insertions(+), 115 deletions(-)

-- 
2.50.1


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v3 01/13] MAINTAINERS: Update resctrl entry
  2026-04-07 16:01 [PATCH v3 00/13] x86,fs/resctrl: Improve resctrl quality and consistency Reinette Chatre
@ 2026-04-07 16:01 ` Reinette Chatre
  2026-04-07 16:01 ` [PATCH v3 02/13] fs/resctrl: Add missing return value descriptions Reinette Chatre
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Reinette Chatre @ 2026-04-07 16:01 UTC (permalink / raw)
  To: tony.luck, james.morse, Dave.Martin, babu.moger, bp, tglx,
	dave.hansen
  Cc: x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches, reinette.chatre

The x86 maintainers handle the resctrl filesystem and x86 architectural
resctrl code. Even so, the x86 maintainers are not part of the resctrl
section and not returned when scripts/get_maintainer.pl is run on resctrl
filesystem code. With patches flowing via x86 maintainers resctrl should
also ensure it follows the tip rules.

Add the x86 maintainer alias, x86@kernel.org, to the resctrl section to
ensure x86 maintainers are included in associated resctrl submissions.

Add a reference to the tip tree handbook to make it clear which rules
resctrl follows.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
---
Changes since v1:
- Add reference to tip tree handbook to follow similar change to other
  tip subsystems:
  https://lore.kernel.org/all/20260305212215.3188399-1-dave.hansen@linux.intel.com/
---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index c14718adb2d8..ee218defa5f5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -22157,11 +22157,13 @@ F:	tools/testing/selftests/net/rds/
 RDT - RESOURCE ALLOCATION
 M:	Tony Luck <tony.luck@intel.com>
 M:	Reinette Chatre <reinette.chatre@intel.com>
+M:	x86@kernel.org
 R:	Dave Martin <Dave.Martin@arm.com>
 R:	James Morse <james.morse@arm.com>
 R:	Babu Moger <babu.moger@amd.com>
 L:	linux-kernel@vger.kernel.org
 S:	Supported
+P:	Documentation/process/maintainer-tip.rst
 F:	Documentation/filesystems/resctrl.rst
 F:	arch/x86/include/asm/resctrl.h
 F:	arch/x86/kernel/cpu/resctrl/
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 02/13] fs/resctrl: Add missing return value descriptions
  2026-04-07 16:01 [PATCH v3 00/13] x86,fs/resctrl: Improve resctrl quality and consistency Reinette Chatre
  2026-04-07 16:01 ` [PATCH v3 01/13] MAINTAINERS: Update resctrl entry Reinette Chatre
@ 2026-04-07 16:01 ` Reinette Chatre
  2026-04-07 16:02 ` [PATCH v3 03/13] fs/resctrl: Avoid "may be used uninitialized" warning Reinette Chatre
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Reinette Chatre @ 2026-04-07 16:01 UTC (permalink / raw)
  To: tony.luck, james.morse, Dave.Martin, babu.moger, bp, tglx,
	dave.hansen
  Cc: x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches, reinette.chatre

Using the stricter "./tools/docs/kernel-doc -Wall -v" to verify proper
formatting of documentation comments includes warnings related to return
markup on functions that are omitted during the default verification
checks. This stricter verification reports a couple of missing return
descriptions in resctrl:

    Warning: .../fs/resctrl/rdtgroup.c:1536 No description found for return value of 'rdtgroup_cbm_to_size'
    Warning: .../fs/resctrl/rdtgroup.c:3131 No description found for return value of 'mon_get_kn_priv'
    Warning: .../fs/resctrl/rdtgroup.c:3523 No description found for return value of 'cbm_ensure_valid'
    Warning: .../fs/resctrl/monitor.c:238 No description found for return value of 'resctrl_find_cleanest_closid'

Add the missing return descriptions.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
---
Changes since v2:
- Provide more detail in return value description: "size in bytes" ->
  "Size (in bytes) of cache portion represented by CBM"
---
 fs/resctrl/monitor.c  | 2 ++
 fs/resctrl/rdtgroup.c | 6 ++++++
 2 files changed, 8 insertions(+)

diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 49f3f6b846b2..9fd901c78dc6 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -234,6 +234,8 @@ static struct rmid_entry *resctrl_find_free_rmid(u32 closid)
  *
  * When the CLOSID and RMID are independent numbers, the first free CLOSID will
  * be returned.
+ *
+ * Return: Free CLOSID on success, < 0 on failure.
  */
 int resctrl_find_cleanest_closid(void)
 {
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 5da305bd36c9..5dfdaa6f9d8f 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -1519,6 +1519,8 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
  *
  * @cbm is unsigned long, even if only 32 bits are used to make the
  * bitmap functions work correctly.
+ *
+ * Return: Size (in bytes) of cache portion represented by CBM, 0 on failure.
  */
 unsigned int rdtgroup_cbm_to_size(struct rdt_resource *r,
 				  struct rdt_ctrl_domain *d, unsigned long cbm)
@@ -3102,6 +3104,8 @@ static void rmdir_all_sub(void)
  * @mevt:   The type of event file being created.
  * @do_sum: Whether SNC summing monitors are being created. Only set
  *	    when @rid == RDT_RESOURCE_L3.
+ *
+ * Return: Pointer to mon_data private data of the event, NULL on failure.
  */
 static struct mon_data *mon_get_kn_priv(enum resctrl_res_level rid, int domid,
 					struct mon_evt *mevt,
@@ -3496,6 +3500,8 @@ static int mkdir_mondata_all(struct kernfs_node *parent_kn,
  * resource group is initialized. The user can follow this with a
  * modification to the CBM if the default does not satisfy the
  * requirements.
+ *
+ * Return: A CBM that is valid for resource @r.
  */
 static u32 cbm_ensure_valid(u32 _val, struct rdt_resource *r)
 {
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 03/13] fs/resctrl: Avoid "may be used uninitialized" warning
  2026-04-07 16:01 [PATCH v3 00/13] x86,fs/resctrl: Improve resctrl quality and consistency Reinette Chatre
  2026-04-07 16:01 ` [PATCH v3 01/13] MAINTAINERS: Update resctrl entry Reinette Chatre
  2026-04-07 16:01 ` [PATCH v3 02/13] fs/resctrl: Add missing return value descriptions Reinette Chatre
@ 2026-04-07 16:02 ` Reinette Chatre
  2026-04-07 18:55   ` Borislav Petkov
  2026-04-07 16:02 ` [PATCH v3 04/13] fs/resctrl: Use correct format specifier for printing error pointers Reinette Chatre
                   ` (9 subsequent siblings)
  12 siblings, 1 reply; 19+ messages in thread
From: Reinette Chatre @ 2026-04-07 16:02 UTC (permalink / raw)
  To: tony.luck, james.morse, Dave.Martin, babu.moger, bp, tglx,
	dave.hansen
  Cc: x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches, reinette.chatre

Building resctrl with extra checks ("W=12") produces the following warning:
 .../include/linux/ucopysize.h:22:17: warning: ‘buf’ may be used uninitialized [-Wmaybe-uninitialized]
   22 |                 __check_object_size(ptr, n, to_user);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 .../include/linux/ucopysize.h: In function ‘pseudo_lock_measure_trigger’:
 .../include/linux/ucopysize.h:10:13: note: by argument 1 of type ‘const void *’ to ‘__check_object_size’ declared here
   10 | extern void __check_object_size(const void *ptr, unsigned long n,
      |             ^~~~~~~~~~~~~~~~~~~
 .../fs/resctrl/pseudo_lock.c:754:14: note: ‘buf’ declared here
  754 |         char buf[32];
      |              ^~~

__check_object_size() ensures the provided buffer is within a valid location
but does not read from the uninitialized buffer. Even so, initialize the
buffer to silence the warning to help resctrl have a cleaner build.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
---
 fs/resctrl/pseudo_lock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/resctrl/pseudo_lock.c b/fs/resctrl/pseudo_lock.c
index fa3687d69ebd..e1e9134474f4 100644
--- a/fs/resctrl/pseudo_lock.c
+++ b/fs/resctrl/pseudo_lock.c
@@ -750,8 +750,8 @@ static ssize_t pseudo_lock_measure_trigger(struct file *file,
 					   size_t count, loff_t *ppos)
 {
 	struct rdtgroup *rdtgrp = file->private_data;
+	char buf[32] = {};
 	size_t buf_size;
-	char buf[32];
 	int ret;
 	int sel;
 
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 04/13] fs/resctrl: Use correct format specifier for printing error pointers
  2026-04-07 16:01 [PATCH v3 00/13] x86,fs/resctrl: Improve resctrl quality and consistency Reinette Chatre
                   ` (2 preceding siblings ...)
  2026-04-07 16:02 ` [PATCH v3 03/13] fs/resctrl: Avoid "may be used uninitialized" warning Reinette Chatre
@ 2026-04-07 16:02 ` Reinette Chatre
  2026-04-07 16:02 ` [PATCH v3 05/13] x86/resctrl: Protect against bad shift Reinette Chatre
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Reinette Chatre @ 2026-04-07 16:02 UTC (permalink / raw)
  To: tony.luck, james.morse, Dave.Martin, babu.moger, bp, tglx,
	dave.hansen
  Cc: x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches, reinette.chatre

Use correct format specifier for error pointer as coccinelle suggests:
    .../fs/resctrl/monitor.c:148:8-15: WARNING: Consider using %pe to print PTR_ERR()
    .../fs/resctrl/monitor.c:760:9-16: WARNING: Consider using %pe to print PTR_ERR()

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
---
 fs/resctrl/monitor.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 9fd901c78dc6..8194fdfbea81 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -144,8 +144,8 @@ void __check_limbo(struct rdt_l3_mon_domain *d, bool force_free)
 	arch_priv = mon_event_all[QOS_L3_OCCUP_EVENT_ID].arch_priv;
 	arch_mon_ctx = resctrl_arch_mon_ctx_alloc(r, QOS_L3_OCCUP_EVENT_ID);
 	if (IS_ERR(arch_mon_ctx)) {
-		pr_warn_ratelimited("Failed to allocate monitor context: %ld",
-				    PTR_ERR(arch_mon_ctx));
+		pr_warn_ratelimited("Failed to allocate monitor context: %pe",
+				    arch_mon_ctx);
 		return;
 	}
 
@@ -752,8 +752,8 @@ static void mbm_update_one_event(struct rdt_resource *r, struct rdt_l3_mon_domai
 	} else {
 		rr.arch_mon_ctx = resctrl_arch_mon_ctx_alloc(rr.r, evtid);
 		if (IS_ERR(rr.arch_mon_ctx)) {
-			pr_warn_ratelimited("Failed to allocate monitor context: %ld",
-					    PTR_ERR(rr.arch_mon_ctx));
+			pr_warn_ratelimited("Failed to allocate monitor context: %pe",
+					    rr.arch_mon_ctx);
 			return;
 		}
 	}
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 05/13] x86/resctrl: Protect against bad shift
  2026-04-07 16:01 [PATCH v3 00/13] x86,fs/resctrl: Improve resctrl quality and consistency Reinette Chatre
                   ` (3 preceding siblings ...)
  2026-04-07 16:02 ` [PATCH v3 04/13] fs/resctrl: Use correct format specifier for printing error pointers Reinette Chatre
@ 2026-04-07 16:02 ` Reinette Chatre
  2026-04-08 16:37   ` Reinette Chatre
  2026-04-07 16:02 ` [PATCH v3 06/13] fs/resctrl: Change pattern used to track number of entries in enum Reinette Chatre
                   ` (7 subsequent siblings)
  12 siblings, 1 reply; 19+ messages in thread
From: Reinette Chatre @ 2026-04-07 16:02 UTC (permalink / raw)
  To: tony.luck, james.morse, Dave.Martin, babu.moger, bp, tglx,
	dave.hansen
  Cc: x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches, reinette.chatre

The size of the bandwidth specifier field is enumerated from AMD hardware.
resctrl uses this field width to determine the maximum bandwidth supported
that is stored in resctrl_membw::max_bw to which user space allocation
requests are compared for validity.

resctrl_membw::max_bw is of type u32 while the register containing the
bandwidth specifier field, L3QOS_BW_CONTROL_n, is 64 bits. While not an
issue with current hardware it is theoretically possible that enumeration
of maximum bandwidth may trigger invalid behavior if a future system can
use a bandwidth specifier field larger than 32 bits. Whether this could
ever represent a reasonable bandwidth value is unknown but addressing the
issue will appease static checkers.

Ensure resctrl can accommodate the hardware's bandwidth specifier field
width with an additional check. Switch to BIT() instead of open-coding the
bitshift to avoid signed integer overflow if the number of bits is a
valid 31.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
---
 arch/x86/kernel/cpu/resctrl/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
index 7667cf7c4e94..db787c4dee61 100644
--- a/arch/x86/kernel/cpu/resctrl/core.c
+++ b/arch/x86/kernel/cpu/resctrl/core.c
@@ -246,7 +246,9 @@ static __init bool __rdt_get_mem_config_amd(struct rdt_resource *r)
 
 	cpuid_count(0x80000020, subleaf, &eax, &ebx, &ecx, &edx);
 	hw_res->num_closid = edx + 1;
-	r->membw.max_bw = 1 << eax;
+	if (WARN_ON(BITS_PER_TYPE(r->membw.max_bw) <= eax))
+		return false;
+	r->membw.max_bw = BIT(eax);
 
 	/* AMD does not use delay */
 	r->membw.delay_linear = false;
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 06/13] fs/resctrl: Change pattern used to track number of entries in enum
  2026-04-07 16:01 [PATCH v3 00/13] x86,fs/resctrl: Improve resctrl quality and consistency Reinette Chatre
                   ` (4 preceding siblings ...)
  2026-04-07 16:02 ` [PATCH v3 05/13] x86/resctrl: Protect against bad shift Reinette Chatre
@ 2026-04-07 16:02 ` Reinette Chatre
  2026-04-07 16:02 ` [PATCH v3 07/13] fs/resctrl: Use accurate type for rdt_resource::rid Reinette Chatre
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Reinette Chatre @ 2026-04-07 16:02 UTC (permalink / raw)
  To: tony.luck, james.morse, Dave.Martin, babu.moger, bp, tglx,
	dave.hansen
  Cc: x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches, reinette.chatre

CDP_NUM_TYPES tracks the number of different configuration types that can
be applied to a resource. CDP_NUM_TYPES is required to iterate over the
different configurations but is not a member of enum resctrl_conf_type to
avoid the warning generated with -Wswitch when CDP_NUM_TYPES lacks a case.

Add a new CDP_LAST enum entry used in CDP_NUM_TYPES definition to simplify
adding a new enum entry. Do this to create a cleaner pattern for tracking
the number of enum entries in resctrl in preparation for other enums
needing to do so.

Suggested-by: Ben Horgan <ben.horgan@arm.com>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Ben Horgan <ben.horgan@arm.com>
---
Changes since v2:
- Add Ben's RB tag.
---
 include/linux/resctrl.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 006e57fd7ca5..0b28049378c8 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -69,9 +69,10 @@ enum resctrl_conf_type {
 	CDP_NONE,
 	CDP_CODE,
 	CDP_DATA,
+	CDP_LAST = CDP_DATA
 };
 
-#define CDP_NUM_TYPES	(CDP_DATA + 1)
+#define CDP_NUM_TYPES	(CDP_LAST + 1)
 
 /*
  * struct pseudo_lock_region - pseudo-lock region information
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 07/13] fs/resctrl: Use accurate type for rdt_resource::rid
  2026-04-07 16:01 [PATCH v3 00/13] x86,fs/resctrl: Improve resctrl quality and consistency Reinette Chatre
                   ` (5 preceding siblings ...)
  2026-04-07 16:02 ` [PATCH v3 06/13] fs/resctrl: Change pattern used to track number of entries in enum Reinette Chatre
@ 2026-04-07 16:02 ` Reinette Chatre
  2026-04-07 16:02 ` [PATCH v3 08/13] fs/resctrl: Pass error reading event through to user space Reinette Chatre
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Reinette Chatre @ 2026-04-07 16:02 UTC (permalink / raw)
  To: tony.luck, james.morse, Dave.Martin, babu.moger, bp, tglx,
	dave.hansen
  Cc: x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches, reinette.chatre

Every resctrl resource has a unique ID described by enum resctrl_res_level.
enum resctrl_res_level is used in all resource ID initializations and all
resource ID comparisons. All functions consuming the resource ID expects an
enum resctrl_res_level. Of the four structures that contain a resource ID
(struct mon_data, struct mon_evt, struct rdt_domain_hdr, and struct
 rdt_resource) only struct rdt_resource does not use enum resctrl_res_level.

Switch the type of rdt_resource::rid to be enum resctrl_res_level to make
it obvious what values are valid, match the type everywhere this member is
used, and obtain benefits from tools that can flag any enum misuse.

Move define of RDT_NUM_RESOURCES outside the enum to enable tools to catch
when a switch() on the resource ID does not handle all the resources and
thus help flag which switch statements need an update when a new resource
is added.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Ben Horgan <ben.horgan@arm.com>
---
Changes since v1:
- Use RDT_RESOURCE_LAST = RDT_RESOURCE_PERF_PKG as last entry in enum.(Ben)

Changes since v2:
- Add Ben's RB tag.
---
 include/linux/resctrl.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 0b28049378c8..99a4774735c7 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -54,11 +54,11 @@ enum resctrl_res_level {
 	RDT_RESOURCE_MBA,
 	RDT_RESOURCE_SMBA,
 	RDT_RESOURCE_PERF_PKG,
-
-	/* Must be the last */
-	RDT_NUM_RESOURCES,
+	RDT_RESOURCE_LAST = RDT_RESOURCE_PERF_PKG
 };
 
+#define RDT_NUM_RESOURCES (RDT_RESOURCE_LAST + 1)
+
 /**
  * enum resctrl_conf_type - The type of configuration.
  * @CDP_NONE:	No prioritisation, both code and data are controlled or monitored.
@@ -320,7 +320,7 @@ struct resctrl_mon {
  * @cdp_capable:	Is the CDP feature available on this resource
  */
 struct rdt_resource {
-	int			rid;
+	enum resctrl_res_level	rid;
 	bool			alloc_capable;
 	bool			mon_capable;
 	enum resctrl_scope	ctrl_scope;
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 08/13] fs/resctrl: Pass error reading event through to user space
  2026-04-07 16:01 [PATCH v3 00/13] x86,fs/resctrl: Improve resctrl quality and consistency Reinette Chatre
                   ` (6 preceding siblings ...)
  2026-04-07 16:02 ` [PATCH v3 07/13] fs/resctrl: Use accurate type for rdt_resource::rid Reinette Chatre
@ 2026-04-07 16:02 ` Reinette Chatre
  2026-04-07 16:02 ` [PATCH v3 09/13] fs/resctrl: Add last_cmd_status support for writes to max_threshold_occupancy Reinette Chatre
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Reinette Chatre @ 2026-04-07 16:02 UTC (permalink / raw)
  To: tony.luck, james.morse, Dave.Martin, babu.moger, bp, tglx,
	dave.hansen
  Cc: x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches, reinette.chatre

Reading of event data is managed through populating a struct rmid_read with
properties of event needing to be read. This data is dispatched to an
appropriate CPU and upon completion any error can be found in rmid_read::err,
or on success the event data will be in rmid_read::val.

rmid_read::err is not updated in the unlikely scenario that the reading
of the event was dispatched to a wrong CPU. If this ever occurs due to
a bug in resctrl the user space read will return "success" but the data
reported will be invalid.

Ensure accurate error reporting so that if there may be an issue with
how resctrl picks a CPU it could be learned with an error to user space
instead of silent failure.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Ben Horgan <ben.horgan@arm.com>
---
Changes since v1:
- Add Ben's RB tag.
---
 fs/resctrl/monitor.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 8194fdfbea81..101b2911d582 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -453,8 +453,10 @@ static int __l3_mon_event_count(struct rdtgroup *rdtgrp, struct rmid_read *rr)
 	}
 
 	/* Reading a single domain, must be on a CPU in that domain. */
-	if (!cpumask_test_cpu(cpu, &d->hdr.cpu_mask))
+	if (!cpumask_test_cpu(cpu, &d->hdr.cpu_mask)) {
+		rr->err = -EIO;
 		return -EINVAL;
+	}
 	if (rr->is_mbm_cntr)
 		rr->err = resctrl_arch_cntr_read(rr->r, d, closid, rmid, cntr_id,
 						 rr->evt->evtid, &tval);
@@ -491,8 +493,10 @@ static int __l3_mon_event_count_sum(struct rdtgroup *rdtgrp, struct rmid_read *r
 	}
 
 	/* Summing domains that share a cache, must be on a CPU for that cache. */
-	if (!cpumask_test_cpu(cpu, &rr->ci->shared_cpu_map))
+	if (!cpumask_test_cpu(cpu, &rr->ci->shared_cpu_map)) {
+		rr->err = -EIO;
 		return -EINVAL;
+	}
 
 	/*
 	 * Legacy files must report the sum of an event across all
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 09/13] fs/resctrl: Add last_cmd_status support for writes to max_threshold_occupancy
  2026-04-07 16:01 [PATCH v3 00/13] x86,fs/resctrl: Improve resctrl quality and consistency Reinette Chatre
                   ` (7 preceding siblings ...)
  2026-04-07 16:02 ` [PATCH v3 08/13] fs/resctrl: Pass error reading event through to user space Reinette Chatre
@ 2026-04-07 16:02 ` Reinette Chatre
  2026-04-07 16:02 ` [PATCH v3 10/13] fs/resctrl: Use accurate and symmetric exit flows Reinette Chatre
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Reinette Chatre @ 2026-04-07 16:02 UTC (permalink / raw)
  To: tony.luck, james.morse, Dave.Martin, babu.moger, bp, tglx,
	dave.hansen
  Cc: x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches, reinette.chatre

info/last_cmd_status is intended to contain more information if a write to
any resctrl file fails. Writes to max_threshold_occupancy did not receive
last_cmd_status support during initial last_cmd_status enabling. Add it now.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
---
Changes since v1:
- Add Ben's RB tag.

Changes since v2:
- Switch to guard(). (Chenyu)
- Drop Ben's RB tag due to significant code change.
---
 fs/resctrl/rdtgroup.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 5dfdaa6f9d8f..5e3ea92cc243 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -12,6 +12,7 @@
 
 #define pr_fmt(fmt)	KBUILD_MODNAME ": " fmt
 
+#include <linux/cleanup.h>
 #include <linux/cpu.h>
 #include <linux/debugfs.h>
 #include <linux/fs.h>
@@ -1238,12 +1239,20 @@ static ssize_t max_threshold_occ_write(struct kernfs_open_file *of,
 	unsigned int bytes;
 	int ret;
 
+	guard(mutex)(&rdtgroup_mutex);
+	rdt_last_cmd_clear();
+
 	ret = kstrtouint(buf, 0, &bytes);
-	if (ret)
+	if (ret) {
+		rdt_last_cmd_puts("Invalid input\n");
 		return ret;
+	}
 
-	if (bytes > resctrl_rmid_realloc_limit)
+	if (bytes > resctrl_rmid_realloc_limit) {
+		rdt_last_cmd_printf("Exceeds limit (before adjustment) of %u bytes\n",
+				    resctrl_rmid_realloc_limit);
 		return -EINVAL;
+	}
 
 	resctrl_rmid_realloc_threshold = resctrl_arch_round_mon_val(bytes);
 
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 10/13] fs/resctrl: Use accurate and symmetric exit flows
  2026-04-07 16:01 [PATCH v3 00/13] x86,fs/resctrl: Improve resctrl quality and consistency Reinette Chatre
                   ` (8 preceding siblings ...)
  2026-04-07 16:02 ` [PATCH v3 09/13] fs/resctrl: Add last_cmd_status support for writes to max_threshold_occupancy Reinette Chatre
@ 2026-04-07 16:02 ` Reinette Chatre
  2026-04-07 16:02 ` [PATCH v3 11/13] fs/resctrl: Change last_cmd_status custom during input parsing Reinette Chatre
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Reinette Chatre @ 2026-04-07 16:02 UTC (permalink / raw)
  To: tony.luck, james.morse, Dave.Martin, babu.moger, bp, tglx,
	dave.hansen
  Cc: x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches, reinette.chatre

During schemata file write handling there is one error exit path labeled
"out" that handles all cleanup and unlocking needed on exit. The staged
configs cleared during an error exit may not have been used at the time
of exit making the clearing of the staged configs unnecessary.

Access the exit code using two labels and only clear the staged
configuration if it was in use at the time of exit. Doing so makes the
code flow obvious and simplifies upcoming changes that improve the
handling of failures during early input parsing.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
---
 fs/resctrl/ctrlmondata.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c
index 9a7dfc48cb2e..8a43efe67a95 100644
--- a/fs/resctrl/ctrlmondata.c
+++ b/fs/resctrl/ctrlmondata.c
@@ -331,7 +331,7 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
 	if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
 		ret = -EINVAL;
 		rdt_last_cmd_puts("Resource group is pseudo-locked\n");
-		goto out;
+		goto out_unlock;
 	}
 
 	rdt_staged_configs_clear();
@@ -341,16 +341,16 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
 		if (!tok) {
 			rdt_last_cmd_puts("Missing ':'\n");
 			ret = -EINVAL;
-			goto out;
+			goto out_clear_staged;
 		}
 		if (tok[0] == '\0') {
 			rdt_last_cmd_printf("Missing '%s' value\n", resname);
 			ret = -EINVAL;
-			goto out;
+			goto out_clear_staged;
 		}
 		ret = rdtgroup_parse_resource(resname, tok, rdtgrp);
 		if (ret)
-			goto out;
+			goto out_clear_staged;
 	}
 
 	list_for_each_entry(s, &resctrl_schema_all, list) {
@@ -365,7 +365,7 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
 
 		ret = resctrl_arch_update_domains(r, rdtgrp->closid);
 		if (ret)
-			goto out;
+			goto out_clear_staged;
 	}
 
 	if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
@@ -378,8 +378,9 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
 		ret = rdtgroup_pseudo_lock_create(rdtgrp);
 	}
 
-out:
+out_clear_staged:
 	rdt_staged_configs_clear();
+out_unlock:
 	rdtgroup_kn_unlock(of->kn);
 	return ret ?: nbytes;
 }
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 11/13] fs/resctrl: Change last_cmd_status custom during input parsing
  2026-04-07 16:01 [PATCH v3 00/13] x86,fs/resctrl: Improve resctrl quality and consistency Reinette Chatre
                   ` (9 preceding siblings ...)
  2026-04-07 16:02 ` [PATCH v3 10/13] fs/resctrl: Use accurate and symmetric exit flows Reinette Chatre
@ 2026-04-07 16:02 ` Reinette Chatre
  2026-04-07 16:02 ` [PATCH v3 12/13] fs/resctrl: Communicate resource group deleted error via last_cmd_status Reinette Chatre
  2026-04-07 16:02 ` [PATCH v3 13/13] fs/resctrl: Inform user space when status buffer overflowed Reinette Chatre
  12 siblings, 0 replies; 19+ messages in thread
From: Reinette Chatre @ 2026-04-07 16:02 UTC (permalink / raw)
  To: tony.luck, james.morse, Dave.Martin, babu.moger, bp, tglx,
	dave.hansen
  Cc: x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches, reinette.chatre

A pattern of usage of last_cmd_status was introduced during its enabling in
commit

c377dcfbee80 ("x86/intel_rdt: Add diagnostics when writing the schemata file")

and since copied throughout resctrl to result in the following custom:

	..._write()
	{
		/* Early parsing of input, exit on failure. */

		/* Obtain rdtgroup_mutex */
		rdt_last_cmd_clear(); /* Clear last_cmd_status buffer */

		/*
		 * Act on user command, failures result in detail
		 * error message in last_cmd_status buffer via
		 * rdt_last_cmd_puts()/rdt_last_cmd_printf().
		 */

		/* Release rdtgroup_mutex */
	}

If resctrl exits with failure during early parsing of input there are two
possible scenarios:
 - The last_cmd_status buffer is empty and a user's read of
   info/last_cmd_status returns "ok".
 - The last_cmd_status buffer contains details from an earlier ...write()
   failure and a user's read of info/last_cmd_status returns this outdated
   error description.

Writing to a resctrl file is considered a "resctrl command" and the
resctrl documentation states the following about the last_cmd_status file:
   "If the command failed, it will provide more information that can be
    conveyed in the error returns from file operations."
Neither of the current scenarios is correct behavior.

Move early input parsing to be done with rdtgroup_mutex held after the
last_cmd_status buffer is cleared. Let info/last_cmd_status be accurate
when an error is encountered during parsing of user command.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Ben Horgan <ben.horgan@arm.com>
---
Changes since v1:
- Add Ben's RB tag.
---
 fs/resctrl/ctrlmondata.c | 54 ++++++++++++++++----------
 fs/resctrl/monitor.c     | 60 +++++++++++++++++------------
 fs/resctrl/rdtgroup.c    | 82 +++++++++++++++++++++++-----------------
 3 files changed, 117 insertions(+), 79 deletions(-)

diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c
index 8a43efe67a95..5d5e844429df 100644
--- a/fs/resctrl/ctrlmondata.c
+++ b/fs/resctrl/ctrlmondata.c
@@ -312,11 +312,6 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
 	char *tok, *resname;
 	int ret = 0;
 
-	/* Valid input requires a trailing newline */
-	if (nbytes == 0 || buf[nbytes - 1] != '\n')
-		return -EINVAL;
-	buf[nbytes - 1] = '\0';
-
 	rdtgrp = rdtgroup_kn_lock_live(of->kn);
 	if (!rdtgrp) {
 		rdtgroup_kn_unlock(of->kn);
@@ -324,6 +319,15 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
 	}
 	rdt_last_cmd_clear();
 
+	/* Valid input requires a trailing newline */
+	if (nbytes == 0 || buf[nbytes - 1] != '\n') {
+		rdt_last_cmd_puts("Invalid input\n");
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
+	buf[nbytes - 1] = '\0';
+
 	/*
 	 * No changes to pseudo-locked region allowed. It has to be removed
 	 * and re-created instead.
@@ -466,11 +470,6 @@ ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
 	struct rdtgroup *rdtgrp;
 	int ret = 0;
 
-	/* Valid input requires a trailing newline */
-	if (nbytes == 0 || buf[nbytes - 1] != '\n')
-		return -EINVAL;
-	buf[nbytes - 1] = '\0';
-
 	rdtgrp = rdtgroup_kn_lock_live(of->kn);
 	if (!rdtgrp) {
 		rdtgroup_kn_unlock(of->kn);
@@ -478,6 +477,15 @@ ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
 	}
 	rdt_last_cmd_clear();
 
+	/* Valid input requires a trailing newline */
+	if (nbytes == 0 || buf[nbytes - 1] != '\n') {
+		rdt_last_cmd_puts("Invalid input\n");
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
+	buf[nbytes - 1] = '\0';
+
 	if (!strcmp(buf, "mbm_local_bytes")) {
 		if (resctrl_is_mon_event_enabled(QOS_L3_MBM_LOCAL_EVENT_ID))
 			rdtgrp->mba_mbps_event = QOS_L3_MBM_LOCAL_EVENT_ID;
@@ -495,6 +503,7 @@ ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
 	if (ret)
 		rdt_last_cmd_printf("Unsupported event id '%s'\n", buf);
 
+out_unlock:
 	rdtgroup_kn_unlock(of->kn);
 
 	return ret ?: nbytes;
@@ -854,15 +863,17 @@ ssize_t resctrl_io_alloc_write(struct kernfs_open_file *of, char *buf,
 	bool enable;
 	int ret;
 
-	ret = kstrtobool(buf, &enable);
-	if (ret)
-		return ret;
-
 	cpus_read_lock();
 	mutex_lock(&rdtgroup_mutex);
 
 	rdt_last_cmd_clear();
 
+	ret = kstrtobool(buf, &enable);
+	if (ret) {
+		rdt_last_cmd_puts("Invalid input\n");
+		goto out_unlock;
+	}
+
 	if (!r->cache.io_alloc_capable) {
 		rdt_last_cmd_printf("io_alloc is not supported on %s\n", s->name);
 		ret = -ENODEV;
@@ -1018,16 +1029,19 @@ ssize_t resctrl_io_alloc_cbm_write(struct kernfs_open_file *of, char *buf,
 	u32 io_alloc_closid;
 	int ret = 0;
 
-	/* Valid input requires a trailing newline */
-	if (nbytes == 0 || buf[nbytes - 1] != '\n')
-		return -EINVAL;
-
-	buf[nbytes - 1] = '\0';
-
 	cpus_read_lock();
 	mutex_lock(&rdtgroup_mutex);
 	rdt_last_cmd_clear();
 
+	/* Valid input requires a trailing newline */
+	if (nbytes == 0 || buf[nbytes - 1] != '\n') {
+		rdt_last_cmd_puts("Invalid input\n");
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
+	buf[nbytes - 1] = '\0';
+
 	if (!r->cache.io_alloc_capable) {
 		rdt_last_cmd_printf("io_alloc is not supported on %s\n", s->name);
 		ret = -ENODEV;
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 101b2911d582..1a38f3b6a1f1 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -1112,13 +1112,15 @@ ssize_t resctrl_mbm_assign_on_mkdir_write(struct kernfs_open_file *of, char *buf
 	bool value;
 	int ret;
 
-	ret = kstrtobool(buf, &value);
-	if (ret)
-		return ret;
-
 	mutex_lock(&rdtgroup_mutex);
 	rdt_last_cmd_clear();
 
+	ret = kstrtobool(buf, &value);
+	if (ret) {
+		rdt_last_cmd_puts("Invalid input\n");
+		goto out_unlock;
+	}
+
 	if (!resctrl_arch_mbm_cntr_assign_enabled(r)) {
 		rdt_last_cmd_puts("mbm_event counter assignment mode is not enabled\n");
 		ret = -EINVAL;
@@ -1409,17 +1411,20 @@ ssize_t event_filter_write(struct kernfs_open_file *of, char *buf, size_t nbytes
 	u32 evt_cfg = 0;
 	int ret = 0;
 
-	/* Valid input requires a trailing newline */
-	if (nbytes == 0 || buf[nbytes - 1] != '\n')
-		return -EINVAL;
-
-	buf[nbytes - 1] = '\0';
-
 	cpus_read_lock();
 	mutex_lock(&rdtgroup_mutex);
 
 	rdt_last_cmd_clear();
 
+	/* Valid input requires a trailing newline */
+	if (nbytes == 0 || buf[nbytes - 1] != '\n') {
+		rdt_last_cmd_puts("Invalid input\n");
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
+	buf[nbytes - 1] = '\0';
+
 	r = resctrl_arch_get_resource(mevt->rid);
 	if (!resctrl_arch_mbm_cntr_assign_enabled(r)) {
 		rdt_last_cmd_puts("mbm_event counter assignment mode is not enabled\n");
@@ -1478,17 +1483,20 @@ ssize_t resctrl_mbm_assign_mode_write(struct kernfs_open_file *of, char *buf,
 	int ret = 0;
 	bool enable;
 
-	/* Valid input requires a trailing newline */
-	if (nbytes == 0 || buf[nbytes - 1] != '\n')
-		return -EINVAL;
-
-	buf[nbytes - 1] = '\0';
-
 	cpus_read_lock();
 	mutex_lock(&rdtgroup_mutex);
 
 	rdt_last_cmd_clear();
 
+	/* Valid input requires a trailing newline */
+	if (nbytes == 0 || buf[nbytes - 1] != '\n') {
+		rdt_last_cmd_puts("Invalid input\n");
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
+	buf[nbytes - 1] = '\0';
+
 	if (!strcmp(buf, "default")) {
 		enable = 0;
 	} else if (!strcmp(buf, "mbm_event")) {
@@ -1759,12 +1767,6 @@ ssize_t mbm_L3_assignments_write(struct kernfs_open_file *of, char *buf,
 	char *token, *event;
 	int ret = 0;
 
-	/* Valid input requires a trailing newline */
-	if (nbytes == 0 || buf[nbytes - 1] != '\n')
-		return -EINVAL;
-
-	buf[nbytes - 1] = '\0';
-
 	rdtgrp = rdtgroup_kn_lock_live(of->kn);
 	if (!rdtgrp) {
 		rdtgroup_kn_unlock(of->kn);
@@ -1772,10 +1774,19 @@ ssize_t mbm_L3_assignments_write(struct kernfs_open_file *of, char *buf,
 	}
 	rdt_last_cmd_clear();
 
+	/* Valid input requires a trailing newline */
+	if (nbytes == 0 || buf[nbytes - 1] != '\n') {
+		rdt_last_cmd_puts("Invalid input\n");
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
+	buf[nbytes - 1] = '\0';
+
 	if (!resctrl_arch_mbm_cntr_assign_enabled(r)) {
 		rdt_last_cmd_puts("mbm_event mode is not enabled\n");
-		rdtgroup_kn_unlock(of->kn);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto out_unlock;
 	}
 
 	while ((token = strsep(&buf, "\n")) != NULL) {
@@ -1791,6 +1802,7 @@ ssize_t mbm_L3_assignments_write(struct kernfs_open_file *of, char *buf,
 			break;
 	}
 
+out_unlock:
 	rdtgroup_kn_unlock(of->kn);
 
 	return ret ?: nbytes;
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 5e3ea92cc243..755a46ef5bdb 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -512,38 +512,38 @@ static int cpus_ctrl_write(struct rdtgroup *rdtgrp, cpumask_var_t newmask,
 static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
 				   char *buf, size_t nbytes, loff_t off)
 {
-	cpumask_var_t tmpmask, newmask, tmpmask1;
+	cpumask_var_t tmpmask = CPUMASK_VAR_NULL, newmask = CPUMASK_VAR_NULL;
+	cpumask_var_t tmpmask1 = CPUMASK_VAR_NULL;
 	struct rdtgroup *rdtgrp;
 	int ret;
 
-	if (!buf)
-		return -EINVAL;
-
-	if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL))
-		return -ENOMEM;
-	if (!zalloc_cpumask_var(&newmask, GFP_KERNEL)) {
-		free_cpumask_var(tmpmask);
-		return -ENOMEM;
-	}
-	if (!zalloc_cpumask_var(&tmpmask1, GFP_KERNEL)) {
-		free_cpumask_var(tmpmask);
-		free_cpumask_var(newmask);
-		return -ENOMEM;
-	}
-
 	rdtgrp = rdtgroup_kn_lock_live(of->kn);
 	if (!rdtgrp) {
 		ret = -ENOENT;
-		goto unlock;
+		goto out_unlock;
 	}
 
 	rdt_last_cmd_clear();
 
+	if (!buf) {
+		rdt_last_cmd_puts("Invalid input\n");
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
+	if (!zalloc_cpumask_var(&tmpmask, GFP_KERNEL) ||
+	    !zalloc_cpumask_var(&newmask, GFP_KERNEL) ||
+	    !zalloc_cpumask_var(&tmpmask1, GFP_KERNEL)) {
+		rdt_last_cmd_puts("Kernel allocation failure\n");
+		ret = -ENOMEM;
+		goto out_free;
+	}
+
 	if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED ||
 	    rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
 		ret = -EINVAL;
 		rdt_last_cmd_puts("Pseudo-locking in progress\n");
-		goto unlock;
+		goto out_free;
 	}
 
 	if (is_cpu_list(of))
@@ -553,7 +553,7 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
 
 	if (ret) {
 		rdt_last_cmd_puts("Bad CPU list/mask\n");
-		goto unlock;
+		goto out_free;
 	}
 
 	/* check that user didn't specify any offline cpus */
@@ -561,7 +561,7 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
 	if (!cpumask_empty(tmpmask)) {
 		ret = -EINVAL;
 		rdt_last_cmd_puts("Can only assign online CPUs\n");
-		goto unlock;
+		goto out_free;
 	}
 
 	if (rdtgrp->type == RDTCTRL_GROUP)
@@ -571,11 +571,12 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
 	else
 		ret = -EINVAL;
 
-unlock:
-	rdtgroup_kn_unlock(of->kn);
+out_free:
 	free_cpumask_var(tmpmask);
 	free_cpumask_var(newmask);
 	free_cpumask_var(tmpmask1);
+out_unlock:
+	rdtgroup_kn_unlock(of->kn);
 
 	return ret ?: nbytes;
 }
@@ -1452,11 +1453,6 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
 	enum rdtgrp_mode mode;
 	int ret = 0;
 
-	/* Valid input requires a trailing newline */
-	if (nbytes == 0 || buf[nbytes - 1] != '\n')
-		return -EINVAL;
-	buf[nbytes - 1] = '\0';
-
 	rdtgrp = rdtgroup_kn_lock_live(of->kn);
 	if (!rdtgrp) {
 		rdtgroup_kn_unlock(of->kn);
@@ -1464,6 +1460,14 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
 	}
 
 	rdt_last_cmd_clear();
+	/* Valid input requires a trailing newline */
+	if (nbytes == 0 || buf[nbytes - 1] != '\n') {
+		rdt_last_cmd_puts("Invalid input\n");
+		ret = -EINVAL;
+		goto out;
+	}
+
+	buf[nbytes - 1] = '\0';
 
 	mode = rdtgrp->mode;
 
@@ -1789,19 +1793,23 @@ static ssize_t mbm_total_bytes_config_write(struct kernfs_open_file *of,
 	struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
 	int ret;
 
-	/* Valid input requires a trailing newline */
-	if (nbytes == 0 || buf[nbytes - 1] != '\n')
-		return -EINVAL;
-
 	cpus_read_lock();
 	mutex_lock(&rdtgroup_mutex);
 
 	rdt_last_cmd_clear();
 
+	/* Valid input requires a trailing newline */
+	if (nbytes == 0 || buf[nbytes - 1] != '\n') {
+		rdt_last_cmd_puts("Invalid input\n");
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
 	buf[nbytes - 1] = '\0';
 
 	ret = mon_config_write(r, buf, QOS_L3_MBM_TOTAL_EVENT_ID);
 
+out_unlock:
 	mutex_unlock(&rdtgroup_mutex);
 	cpus_read_unlock();
 
@@ -1815,19 +1823,23 @@ static ssize_t mbm_local_bytes_config_write(struct kernfs_open_file *of,
 	struct rdt_resource *r = rdt_kn_parent_priv(of->kn);
 	int ret;
 
-	/* Valid input requires a trailing newline */
-	if (nbytes == 0 || buf[nbytes - 1] != '\n')
-		return -EINVAL;
-
 	cpus_read_lock();
 	mutex_lock(&rdtgroup_mutex);
 
 	rdt_last_cmd_clear();
 
+	/* Valid input requires a trailing newline */
+	if (nbytes == 0 || buf[nbytes - 1] != '\n') {
+		rdt_last_cmd_puts("Invalid input\n");
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
 	buf[nbytes - 1] = '\0';
 
 	ret = mon_config_write(r, buf, QOS_L3_MBM_LOCAL_EVENT_ID);
 
+out_unlock:
 	mutex_unlock(&rdtgroup_mutex);
 	cpus_read_unlock();
 
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 12/13] fs/resctrl: Communicate resource group deleted error via last_cmd_status
  2026-04-07 16:01 [PATCH v3 00/13] x86,fs/resctrl: Improve resctrl quality and consistency Reinette Chatre
                   ` (10 preceding siblings ...)
  2026-04-07 16:02 ` [PATCH v3 11/13] fs/resctrl: Change last_cmd_status custom during input parsing Reinette Chatre
@ 2026-04-07 16:02 ` Reinette Chatre
  2026-04-07 16:02 ` [PATCH v3 13/13] fs/resctrl: Inform user space when status buffer overflowed Reinette Chatre
  12 siblings, 0 replies; 19+ messages in thread
From: Reinette Chatre @ 2026-04-07 16:02 UTC (permalink / raw)
  To: tony.luck, james.morse, Dave.Martin, babu.moger, bp, tglx,
	dave.hansen
  Cc: x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches, reinette.chatre

User space expects last_cmd_status to contain additional information if
any resctrl command fails.

A resctrl command may be blocked waiting on the rdtgroup_mutex waiting for
another command to finish and find that once the mutex is available that
the resource group has since been deleted. In this scenario the command
will fail while last_cmd_status contains either "ok" if the last_cmd_status
buffer is empty or an outdated error from a previous command failure if
last_cmd_status buffer has content.

Include clearing of last_cmd_status buffer as part of
rdtgroup_kn_lock_live() that is used to obtain access and needed locking
to a resource group before attempting a command on the group. With the
last_cmd_status buffer ready, provide an appropriate message to user space
if the resource group has been deleted.

No last_cmd_status treatment is needed for the remaining failure of
rdtgroup_kn_lock_live() encountering a non-existent resource group since
that could only occur during an attempt to obtain a resource group lock
on a file in info/ which is an invalid usage.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
---
Changes since v1:
- Add snippet about why it is safe to dereference the kn to get
  to resource group name when resource group is deleted.
---
 fs/resctrl/ctrlmondata.c |  3 ---
 fs/resctrl/monitor.c     |  2 --
 fs/resctrl/rdtgroup.c    | 20 +++++++++++---------
 3 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c
index 5d5e844429df..26bbf4ecdbca 100644
--- a/fs/resctrl/ctrlmondata.c
+++ b/fs/resctrl/ctrlmondata.c
@@ -317,7 +317,6 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
 		rdtgroup_kn_unlock(of->kn);
 		return -ENOENT;
 	}
-	rdt_last_cmd_clear();
 
 	/* Valid input requires a trailing newline */
 	if (nbytes == 0 || buf[nbytes - 1] != '\n') {
@@ -434,7 +433,6 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of,
 			}
 		} else if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
 			if (!rdtgrp->plr->d) {
-				rdt_last_cmd_clear();
 				rdt_last_cmd_puts("Cache domain offline\n");
 				ret = -ENODEV;
 			} else {
@@ -475,7 +473,6 @@ ssize_t rdtgroup_mba_mbps_event_write(struct kernfs_open_file *of,
 		rdtgroup_kn_unlock(of->kn);
 		return -ENOENT;
 	}
-	rdt_last_cmd_clear();
 
 	/* Valid input requires a trailing newline */
 	if (nbytes == 0 || buf[nbytes - 1] != '\n') {
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 1a38f3b6a1f1..88f1fa0b9d8d 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -1632,7 +1632,6 @@ int mbm_L3_assignments_show(struct kernfs_open_file *of, struct seq_file *s, voi
 		goto out_unlock;
 	}
 
-	rdt_last_cmd_clear();
 	if (!resctrl_arch_mbm_cntr_assign_enabled(r)) {
 		rdt_last_cmd_puts("mbm_event counter assignment mode is not enabled\n");
 		ret = -EINVAL;
@@ -1772,7 +1771,6 @@ ssize_t mbm_L3_assignments_write(struct kernfs_open_file *of, char *buf,
 		rdtgroup_kn_unlock(of->kn);
 		return -ENOENT;
 	}
-	rdt_last_cmd_clear();
 
 	/* Valid input requires a trailing newline */
 	if (nbytes == 0 || buf[nbytes - 1] != '\n') {
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 755a46ef5bdb..0677e6e4102e 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -360,7 +360,6 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,
 	if (rdtgrp) {
 		if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
 			if (!rdtgrp->plr->d) {
-				rdt_last_cmd_clear();
 				rdt_last_cmd_puts("Cache domain offline\n");
 				ret = -ENODEV;
 			} else {
@@ -523,8 +522,6 @@ static ssize_t rdtgroup_cpus_write(struct kernfs_open_file *of,
 		goto out_unlock;
 	}
 
-	rdt_last_cmd_clear();
-
 	if (!buf) {
 		rdt_last_cmd_puts("Invalid input\n");
 		ret = -EINVAL;
@@ -781,7 +778,6 @@ static ssize_t rdtgroup_tasks_write(struct kernfs_open_file *of,
 		rdtgroup_kn_unlock(of->kn);
 		return -ENOENT;
 	}
-	rdt_last_cmd_clear();
 
 	if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED ||
 	    rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
@@ -1459,7 +1455,6 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
 		return -ENOENT;
 	}
 
-	rdt_last_cmd_clear();
 	/* Valid input requires a trailing newline */
 	if (nbytes == 0 || buf[nbytes - 1] != '\n') {
 		rdt_last_cmd_puts("Invalid input\n");
@@ -1596,7 +1591,6 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
 
 	if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
 		if (!rdtgrp->plr->d) {
-			rdt_last_cmd_clear();
 			rdt_last_cmd_puts("Cache domain offline\n");
 			ret = -ENODEV;
 		} else {
@@ -2634,10 +2628,20 @@ struct rdtgroup *rdtgroup_kn_lock_live(struct kernfs_node *kn)
 
 	cpus_read_lock();
 	mutex_lock(&rdtgroup_mutex);
+	rdt_last_cmd_clear();
 
 	/* Was this group deleted while we waited? */
-	if (rdtgrp->flags & RDT_DELETED)
+	if (rdtgrp->flags & RDT_DELETED) {
+		/*
+		 * It is safe to dereference kn to obtain the resource group's
+		 * name because one extra reference to kn is obtained
+		 * during resource group creation that will be released by
+		 * rdtgroup_remove() called by rdtgroup_kn_put().
+		 */
+		rdt_last_cmd_printf("Resource group %s deleted. No commands possible.\n",
+				    rdt_kn_name(rdtgrp->kn));
 		return NULL;
+	}
 
 	return rdtgrp;
 }
@@ -3760,8 +3764,6 @@ static int mkdir_rdt_prepare(struct kernfs_node *parent_kn,
 		goto out_unlock;
 	}
 
-	rdt_last_cmd_clear();
-
 	/*
 	 * Check that the parent directory for a monitor group is a "mon_groups"
 	 * directory.
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v3 13/13] fs/resctrl: Inform user space when status buffer overflowed
  2026-04-07 16:01 [PATCH v3 00/13] x86,fs/resctrl: Improve resctrl quality and consistency Reinette Chatre
                   ` (11 preceding siblings ...)
  2026-04-07 16:02 ` [PATCH v3 12/13] fs/resctrl: Communicate resource group deleted error via last_cmd_status Reinette Chatre
@ 2026-04-07 16:02 ` Reinette Chatre
  12 siblings, 0 replies; 19+ messages in thread
From: Reinette Chatre @ 2026-04-07 16:02 UTC (permalink / raw)
  To: tony.luck, james.morse, Dave.Martin, babu.moger, bp, tglx,
	dave.hansen
  Cc: x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches, reinette.chatre

resctrl fs commands are becoming more powerful with, for example, a user
able to use syntax like '*' to make broad configuration changes. Such
commands that span multiple domains may result in more than one message
printed to the last_cmd_status buffer with more planned.

Display "[truncated]" to user space when displaying the last_cmd_status
buffer to communicate if it overflowed. Upon encountering this user space
is expected to combine details about the failure found in info/last_cmd_status
with related resctrl files to learn the accurate system state after the
command failure.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Ben Horgan <ben.horgan@arm.com>
---
Changes since v2:
- Add Ben's RB tag.
---
 fs/resctrl/rdtgroup.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 0677e6e4102e..5413a625ff32 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -971,10 +971,13 @@ static int rdt_last_cmd_status_show(struct kernfs_open_file *of,
 
 	mutex_lock(&rdtgroup_mutex);
 	len = seq_buf_used(&last_cmd_status);
-	if (len)
+	if (len) {
 		seq_printf(seq, "%.*s", len, last_cmd_status_buf);
-	else
+		if (seq_buf_has_overflowed(&last_cmd_status))
+			seq_puts(seq, "[truncated]\n");
+	} else {
 		seq_puts(seq, "ok\n");
+	}
 	mutex_unlock(&rdtgroup_mutex);
 	return 0;
 }
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 03/13] fs/resctrl: Avoid "may be used uninitialized" warning
  2026-04-07 16:02 ` [PATCH v3 03/13] fs/resctrl: Avoid "may be used uninitialized" warning Reinette Chatre
@ 2026-04-07 18:55   ` Borislav Petkov
  2026-04-07 20:50     ` Reinette Chatre
  0 siblings, 1 reply; 19+ messages in thread
From: Borislav Petkov @ 2026-04-07 18:55 UTC (permalink / raw)
  To: Reinette Chatre
  Cc: tony.luck, james.morse, Dave.Martin, babu.moger, tglx,
	dave.hansen, x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches

On Tue, Apr 07, 2026 at 09:02:00AM -0700, Reinette Chatre wrote:
> Building resctrl with extra checks ("W=12") produces the following warning:
>  .../include/linux/ucopysize.h:22:17: warning: ‘buf’ may be used uninitialized [-Wmaybe-uninitialized]
>    22 |                 __check_object_size(ptr, n, to_user);
>       |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  .../include/linux/ucopysize.h: In function ‘pseudo_lock_measure_trigger’:
>  .../include/linux/ucopysize.h:10:13: note: by argument 1 of type ‘const void *’ to ‘__check_object_size’ declared here
>    10 | extern void __check_object_size(const void *ptr, unsigned long n,
>       |             ^~~~~~~~~~~~~~~~~~~
>  .../fs/resctrl/pseudo_lock.c:754:14: note: ‘buf’ declared here
>   754 |         char buf[32];
>       |              ^~~
> 
> __check_object_size() ensures the provided buffer is within a valid location
> but does not read from the uninitialized buffer. Even so, initialize the
> buffer to silence the warning to help resctrl have a cleaner build.
> 
> Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
> ---
>  fs/resctrl/pseudo_lock.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/resctrl/pseudo_lock.c b/fs/resctrl/pseudo_lock.c
> index fa3687d69ebd..e1e9134474f4 100644
> --- a/fs/resctrl/pseudo_lock.c
> +++ b/fs/resctrl/pseudo_lock.c
> @@ -750,8 +750,8 @@ static ssize_t pseudo_lock_measure_trigger(struct file *file,
>  					   size_t count, loff_t *ppos)
>  {
>  	struct rdtgroup *rdtgrp = file->private_data;
> +	char buf[32] = {};

AFAIU, you're not leaking any uninitialized stack data from that buffer,
right?

If so, why do you care about some silly build warning and are willing to waste
a 32-byte memset on every function entry?

There's a reason those warnings are behind W= ...

:-)

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 03/13] fs/resctrl: Avoid "may be used uninitialized" warning
  2026-04-07 18:55   ` Borislav Petkov
@ 2026-04-07 20:50     ` Reinette Chatre
  2026-04-07 22:19       ` Borislav Petkov
  0 siblings, 1 reply; 19+ messages in thread
From: Reinette Chatre @ 2026-04-07 20:50 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: tony.luck, james.morse, Dave.Martin, babu.moger, tglx,
	dave.hansen, x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches

Hi Boris,

Thank you very much for taking a look.

On 4/7/26 11:55 AM, Borislav Petkov wrote:
> On Tue, Apr 07, 2026 at 09:02:00AM -0700, Reinette Chatre wrote:
>> Building resctrl with extra checks ("W=12") produces the following warning:
>>  .../include/linux/ucopysize.h:22:17: warning: ‘buf’ may be used uninitialized [-Wmaybe-uninitialized]
>>    22 |                 __check_object_size(ptr, n, to_user);
>>       |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>  .../include/linux/ucopysize.h: In function ‘pseudo_lock_measure_trigger’:
>>  .../include/linux/ucopysize.h:10:13: note: by argument 1 of type ‘const void *’ to ‘__check_object_size’ declared here
>>    10 | extern void __check_object_size(const void *ptr, unsigned long n,
>>       |             ^~~~~~~~~~~~~~~~~~~
>>  .../fs/resctrl/pseudo_lock.c:754:14: note: ‘buf’ declared here
>>   754 |         char buf[32];
>>       |              ^~~
>>
>> __check_object_size() ensures the provided buffer is within a valid location
>> but does not read from the uninitialized buffer. Even so, initialize the
>> buffer to silence the warning to help resctrl have a cleaner build.
>>
>> Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
>> ---
>>  fs/resctrl/pseudo_lock.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/fs/resctrl/pseudo_lock.c b/fs/resctrl/pseudo_lock.c
>> index fa3687d69ebd..e1e9134474f4 100644
>> --- a/fs/resctrl/pseudo_lock.c
>> +++ b/fs/resctrl/pseudo_lock.c
>> @@ -750,8 +750,8 @@ static ssize_t pseudo_lock_measure_trigger(struct file *file,
>>  					   size_t count, loff_t *ppos)
>>  {
>>  	struct rdtgroup *rdtgrp = file->private_data;
>> +	char buf[32] = {};
> 
> AFAIU, you're not leaking any uninitialized stack data from that buffer,
> right?

Right. From what I can tell __check_object_size() just checks that the address
is from a valid region and does not read from the buffer.

> 
> If so, why do you care about some silly build warning and are willing to waste
> a 32-byte memset on every function entry?

I care because I am including a W=12 build as part of checking all resctrl patches
and having this be the one and only warning that always shows up is distracting.
Removing it to accomplish a clean W=12 build does not seem impactful to me.

Of course you are right that this wastes a memset. This function is not on a
hot path though and I do not believe it would be called frequently since it is
intended to demonstrate how successful the setup of a pseudo-lock region was and
successive calls should produce consistent results.

> 
> There's a reason those warnings are behind W= ...

Indeed. This patch is for developer and maintenance convenience and not required for
resctrl health. No problem from me if you find it not to be appropriate. I will just
continue to parse the warning out of the logs.

Reinette

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 03/13] fs/resctrl: Avoid "may be used uninitialized" warning
  2026-04-07 20:50     ` Reinette Chatre
@ 2026-04-07 22:19       ` Borislav Petkov
  2026-04-07 22:56         ` Reinette Chatre
  0 siblings, 1 reply; 19+ messages in thread
From: Borislav Petkov @ 2026-04-07 22:19 UTC (permalink / raw)
  To: Reinette Chatre
  Cc: tony.luck, james.morse, Dave.Martin, babu.moger, tglx,
	dave.hansen, x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches

On Tue, Apr 07, 2026 at 01:50:50PM -0700, Reinette Chatre wrote:
> Indeed. This patch is for developer and maintenance convenience and not required for
> resctrl health. No problem from me if you find it not to be appropriate. I will just
> continue to parse the warning out of the logs.

Oh, your call. I just think it is unnecessary especially because those
warnings are not really worth to care for as they produce a bunch of false
positives and that's why they're not enabled by default.

IOW, I take them with a grain of salt.

In this particular case, I would care about the code not doing any unnecessary
work if it can be helped. And the warning can take a hike... :-)

But I can apply the patch if you prefer.

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 03/13] fs/resctrl: Avoid "may be used uninitialized" warning
  2026-04-07 22:19       ` Borislav Petkov
@ 2026-04-07 22:56         ` Reinette Chatre
  0 siblings, 0 replies; 19+ messages in thread
From: Reinette Chatre @ 2026-04-07 22:56 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: tony.luck, james.morse, Dave.Martin, babu.moger, tglx,
	dave.hansen, x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches

Hi Boris,

On 4/7/26 3:19 PM, Borislav Petkov wrote:
> 
> In this particular case, I would care about the code not doing any unnecessary
> work if it can be helped. And the warning can take a hike... :-)

This is very convincing. 

> But I can apply the patch if you prefer.

I don't. I'm ok for this to be dropped.

Thank you very much.

Reinette

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v3 05/13] x86/resctrl: Protect against bad shift
  2026-04-07 16:02 ` [PATCH v3 05/13] x86/resctrl: Protect against bad shift Reinette Chatre
@ 2026-04-08 16:37   ` Reinette Chatre
  0 siblings, 0 replies; 19+ messages in thread
From: Reinette Chatre @ 2026-04-08 16:37 UTC (permalink / raw)
  To: tony.luck, james.morse, Dave.Martin, babu.moger, bp, tglx,
	dave.hansen
  Cc: x86, hpa, ben.horgan, fustini, fenghuay, peternewman,
	linux-kernel, patches



On 4/7/26 9:02 AM, Reinette Chatre wrote:
> diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
> index 7667cf7c4e94..db787c4dee61 100644
> --- a/arch/x86/kernel/cpu/resctrl/core.c
> +++ b/arch/x86/kernel/cpu/resctrl/core.c
> @@ -246,7 +246,9 @@ static __init bool __rdt_get_mem_config_amd(struct rdt_resource *r)
>  
>  	cpuid_count(0x80000020, subleaf, &eax, &ebx, &ecx, &edx);
>  	hw_res->num_closid = edx + 1;
> -	r->membw.max_bw = 1 << eax;
> +	if (WARN_ON(BITS_PER_TYPE(r->membw.max_bw) <= eax))

sashiko [1] reminded me about not using WARN_ON().
I'll switch this to pr_warn(). 

> +		return false;
> +	r->membw.max_bw = BIT(eax);
>  

Reinette

[1] https://sashiko.dev/#/patchset/cover.1775576382.git.reinette.chatre%40intel.com





^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2026-04-08 16:37 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-07 16:01 [PATCH v3 00/13] x86,fs/resctrl: Improve resctrl quality and consistency Reinette Chatre
2026-04-07 16:01 ` [PATCH v3 01/13] MAINTAINERS: Update resctrl entry Reinette Chatre
2026-04-07 16:01 ` [PATCH v3 02/13] fs/resctrl: Add missing return value descriptions Reinette Chatre
2026-04-07 16:02 ` [PATCH v3 03/13] fs/resctrl: Avoid "may be used uninitialized" warning Reinette Chatre
2026-04-07 18:55   ` Borislav Petkov
2026-04-07 20:50     ` Reinette Chatre
2026-04-07 22:19       ` Borislav Petkov
2026-04-07 22:56         ` Reinette Chatre
2026-04-07 16:02 ` [PATCH v3 04/13] fs/resctrl: Use correct format specifier for printing error pointers Reinette Chatre
2026-04-07 16:02 ` [PATCH v3 05/13] x86/resctrl: Protect against bad shift Reinette Chatre
2026-04-08 16:37   ` Reinette Chatre
2026-04-07 16:02 ` [PATCH v3 06/13] fs/resctrl: Change pattern used to track number of entries in enum Reinette Chatre
2026-04-07 16:02 ` [PATCH v3 07/13] fs/resctrl: Use accurate type for rdt_resource::rid Reinette Chatre
2026-04-07 16:02 ` [PATCH v3 08/13] fs/resctrl: Pass error reading event through to user space Reinette Chatre
2026-04-07 16:02 ` [PATCH v3 09/13] fs/resctrl: Add last_cmd_status support for writes to max_threshold_occupancy Reinette Chatre
2026-04-07 16:02 ` [PATCH v3 10/13] fs/resctrl: Use accurate and symmetric exit flows Reinette Chatre
2026-04-07 16:02 ` [PATCH v3 11/13] fs/resctrl: Change last_cmd_status custom during input parsing Reinette Chatre
2026-04-07 16:02 ` [PATCH v3 12/13] fs/resctrl: Communicate resource group deleted error via last_cmd_status Reinette Chatre
2026-04-07 16:02 ` [PATCH v3 13/13] fs/resctrl: Inform user space when status buffer overflowed Reinette Chatre

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox