Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Reinette Chatre <reinette.chatre@intel.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: fenghua.yu@intel.com, shuah@kernel.org, tony.luck@intel.com,
	peternewman@google.com, babu.moger@amd.com,
	"Maciej Wieczór-Retman" <maciej.wieczor-retman@intel.com>,
	linux-kselftest@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH V3 10/15] selftests/resctrl: Make benchmark parameter passing robust
Date: Fri, 18 Oct 2024 10:34:25 -0700	[thread overview]
Message-ID: <104e159a-80fb-4ad5-ae9e-3e5f549a3535@intel.com> (raw)
In-Reply-To: <63a2f1e4-2934-6d02-4621-2d224b9981cb@linux.intel.com>

Hi Ilpo,

On 10/18/24 2:03 AM, Ilpo Järvinen wrote:
> On Thu, 17 Oct 2024, Reinette Chatre wrote:

>> +/*
>> + * Allocate and initialize a struct fill_buf_param with user provided
>> + * (via "-b fill_buf <fill_buf parameters>") parameters.
>> + *
>> + * Use defaults (that may not be appropriate for all tests) for any
>> + * fill_buf parameters omitted by the user.
>> + *
>> + * Historically it may have been possible for user space to provide
>> + * additional parameters, "operation" ("read" vs "write") in
>> + * benchmark_cmd[3] and "once" (run "once" or until terminated) in
>> + * benchmark_cmd[4]. Changing these parameters have never been
>> + * supported with the default of "read" operation and running until
>> + * terminated built into the tests. Any unsupported values for
>> + * (original) "fill_buf" parameters are treated as failure.
>> + *
>> + * Return: On failure, forcibly exits the test on any parsing failure,
>> + *         returns NULL if no parsing needed (user did not actually provide
>> + *         "-b fill_buf").
>> + *         On success, returns pointer to newly allocated and fully
>> + *         initialized struct fill_buf_param that caller must free.
>> + */
>> +static struct fill_buf_param *alloc_fill_buf_param(struct user_params *uparams)
>> +{
>> +	struct fill_buf_param *fill_param = NULL;
>> +	char *endptr = NULL;
>> +
>> +	if (!uparams->benchmark_cmd[0] || strcmp(uparams->benchmark_cmd[0], "fill_buf"))
>> +		return NULL;
>> +
>> +	fill_param = malloc(sizeof(*fill_param));
>> +	if (!fill_param)
>> +		ksft_exit_skip("Unable to allocate memory for fill_buf parameters.\n");
>> +
>> +	if (uparams->benchmark_cmd[1]) {
>> +		errno = 0;
>> +		fill_param->buf_size = strtoul(uparams->benchmark_cmd[1], &endptr, 10);
>> +		if (errno || *endptr != '\0') {
> 
> Same here as with the patch 2 (and also in the checks below), both empty 
> string and extra character checks are necessary.

Thank you very much. Addressed with fixup below:

@@ -181,7 +181,7 @@ static struct fill_buf_param *alloc_fill_buf_param(struct user_params *uparams)
 	if (!fill_param)
 		ksft_exit_skip("Unable to allocate memory for fill_buf parameters.\n");
 
-	if (uparams->benchmark_cmd[1]) {
+	if (uparams->benchmark_cmd[1] && *uparams->benchmark_cmd[1] != '\0') {
 		errno = 0;
 		fill_param->buf_size = strtoul(uparams->benchmark_cmd[1], &endptr, 10);
 		if (errno || *endptr != '\0') {
@@ -192,7 +192,7 @@ static struct fill_buf_param *alloc_fill_buf_param(struct user_params *uparams)
 		fill_param->buf_size = MINIMUM_SPAN;
 	}
 
-	if (uparams->benchmark_cmd[2]) {
+	if (uparams->benchmark_cmd[2] && *uparams->benchmark_cmd[2] != '\0') {
 		errno = 0;
 		fill_param->memflush = strtol(uparams->benchmark_cmd[2], &endptr, 10) != 0;
 		if (errno || *endptr != '\0') {
@@ -203,14 +203,14 @@ static struct fill_buf_param *alloc_fill_buf_param(struct user_params *uparams)
 		fill_param->memflush = true;
 	}
 
-	if (uparams->benchmark_cmd[3]) {
+	if (uparams->benchmark_cmd[3] && *uparams->benchmark_cmd[3] != '\0') {
 		if (strcmp(uparams->benchmark_cmd[3], "0")) {
 			free(fill_param);
 			ksft_exit_skip("Only read operations supported.\n");
 		}
 	}
 
-	if (uparams->benchmark_cmd[4]) {
+	if (uparams->benchmark_cmd[4] && *uparams->benchmark_cmd[4] != '\0') {
 		if (strcmp(uparams->benchmark_cmd[4], "false")) {
 			free(fill_param);
 			ksft_exit_skip("fill_buf is required to run until termination.\n");

Reinette


  reply	other threads:[~2024-10-18 17:34 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-18  2:33 [PATCH V3 00/15] selftests/resctrl: Support diverse platforms with MBM and MBA tests Reinette Chatre
2024-10-18  2:33 ` [PATCH V3 01/15] selftests/resctrl: Make functions only used in same file static Reinette Chatre
2024-10-18  2:33 ` [PATCH V3 02/15] selftests/resctrl: Print accurate buffer size as part of MBM results Reinette Chatre
2024-10-18  8:46   ` Ilpo Järvinen
2024-10-18 17:34     ` Reinette Chatre
2024-10-18  2:33 ` [PATCH V3 03/15] selftests/resctrl: Fix memory overflow due to unhandled wraparound Reinette Chatre
2024-10-18  2:33 ` [PATCH V3 04/15] selftests/resctrl: Protect against array overrun during iMC config parsing Reinette Chatre
2024-10-18  2:33 ` [PATCH V3 05/15] selftests/resctrl: Protect against array overflow when reading strings Reinette Chatre
2024-10-18  8:53   ` Ilpo Järvinen
2024-10-18  2:33 ` [PATCH V3 06/15] selftests/resctrl: Make wraparound handling obvious Reinette Chatre
2024-10-18  2:33 ` [PATCH V3 07/15] selftests/resctrl: Remove "once" parameter required to be false Reinette Chatre
2024-10-18  8:54   ` Ilpo Järvinen
2024-10-18  2:33 ` [PATCH V3 08/15] selftests/resctrl: Only support measured read operation Reinette Chatre
2024-10-18  8:55   ` Ilpo Järvinen
2024-10-18  2:33 ` [PATCH V3 09/15] selftests/resctrl: Remove unused measurement code Reinette Chatre
2024-10-18  2:33 ` [PATCH V3 10/15] selftests/resctrl: Make benchmark parameter passing robust Reinette Chatre
2024-10-18  9:03   ` Ilpo Järvinen
2024-10-18 17:34     ` Reinette Chatre [this message]
2024-10-18  2:33 ` [PATCH V3 11/15] selftests/resctrl: Ensure measurements skip initialization of default benchmark Reinette Chatre
2024-10-18  2:33 ` [PATCH V3 12/15] selftests/resctrl: Use cache size to determine "fill_buf" buffer size Reinette Chatre
2024-10-18  9:06   ` Ilpo Järvinen
2024-10-18  2:33 ` [PATCH V3 13/15] selftests/resctrl: Do not compare performance counters and resctrl at low bandwidth Reinette Chatre
2024-10-18  2:33 ` [PATCH V3 14/15] selftests/resctrl: Keep results from first test run Reinette Chatre
2024-10-18  2:33 ` [PATCH V3 15/15] selftests/resctrl: Replace magic constants used as array size Reinette Chatre
2024-10-18  9:08   ` Ilpo Järvinen

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=104e159a-80fb-4ad5-ae9e-3e5f549a3535@intel.com \
    --to=reinette.chatre@intel.com \
    --cc=babu.moger@amd.com \
    --cc=fenghua.yu@intel.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=maciej.wieczor-retman@intel.com \
    --cc=peternewman@google.com \
    --cc=shuah@kernel.org \
    --cc=tony.luck@intel.com \
    /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