mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Luck, Tony" <tony.luck@intel.com>
To: Reinette Chatre <reinette.chatre@intel.com>
Cc: <james.morse@arm.com>, <Dave.Martin@arm.com>,
	<babu.moger@amd.com>, <bp@alien8.de>, <tglx@linutronix.de>,
	<dave.hansen@linux.intel.com>, <x86@kernel.org>, <hpa@zytor.com>,
	<ben.horgan@arm.com>, <fustini@kernel.org>, <fenghuay@nvidia.com>,
	<peternewman@google.com>, <linux-kernel@vger.kernel.org>,
	<patches@lists.linux.dev>
Subject: Re: [PATCH v4 08/10] fs/resctrl: Change last_cmd_status custom during input parsing
Date: Thu, 28 May 2026 16:38:00 -0700	[thread overview]
Message-ID: <ahjR2CeEwosKXSE9@agluck-desk3> (raw)
In-Reply-To: <4efad346b8e4dde0b84ff3e87c635852b6575aa2.1777419024.git.reinette.chatre@intel.com>

On Wed, Apr 29, 2026 at 08:06:38AM -0700, Reinette Chatre wrote:
> 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");

This is obviously a big improvement over existing failure to provide a
message (or leaving previous stale message). Do you want to go the extra
mile and disambiguate all these "Invalid input" messages?  E.g. here:

		rdt_last_cmd_puts("schemata: Invalid input\n");

It's good to have a grep-able pattern to diagnostics.

All the other patches in this series look great. You can add my

Reviewed-by: Tony Luck <tony.luck@intel.com>

to them all.

-Tony

  reply	other threads:[~2026-05-28 23:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-29 15:06 [PATCH v4 00/10] x86,fs/resctrl: Improve resctrl quality and consistency Reinette Chatre
2026-04-29 15:06 ` [PATCH v4 01/10] fs/resctrl: Use correct format specifier for printing error pointers Reinette Chatre
2026-04-29 15:06 ` [PATCH v4 02/10] x86/resctrl: Protect against bad shift Reinette Chatre
2026-04-29 15:06 ` [PATCH v4 03/10] fs/resctrl: Change pattern used to track number of entries in enum Reinette Chatre
2026-04-29 15:06 ` [PATCH v4 04/10] fs/resctrl: Use accurate type for rdt_resource::rid Reinette Chatre
2026-04-29 15:06 ` [PATCH v4 05/10] fs/resctrl: Pass error reading event through to user space Reinette Chatre
2026-04-29 15:06 ` [PATCH v4 06/10] fs/resctrl: Add last_cmd_status support for writes to max_threshold_occupancy Reinette Chatre
2026-04-29 15:06 ` [PATCH v4 07/10] fs/resctrl: Use accurate and symmetric exit flows Reinette Chatre
2026-04-29 15:06 ` [PATCH v4 08/10] fs/resctrl: Change last_cmd_status custom during input parsing Reinette Chatre
2026-05-28 23:38   ` Luck, Tony [this message]
2026-05-29  3:44     ` Reinette Chatre
2026-04-29 15:06 ` [PATCH v4 09/10] fs/resctrl: Communicate resource group deleted error via last_cmd_status Reinette Chatre
2026-04-29 15:06 ` [PATCH v4 10/10] fs/resctrl: Inform user space when status buffer overflowed Reinette Chatre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ahjR2CeEwosKXSE9@agluck-desk3 \
    --to=tony.luck@intel.com \
    --cc=Dave.Martin@arm.com \
    --cc=babu.moger@amd.com \
    --cc=ben.horgan@arm.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=fenghuay@nvidia.com \
    --cc=fustini@kernel.org \
    --cc=hpa@zytor.com \
    --cc=james.morse@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=peternewman@google.com \
    --cc=reinette.chatre@intel.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®