linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V3] testing/selftests/mqueue: Fix mq_perf_tests to free the allocated cpu set
@ 2022-04-08  7:24 Athira Rajeev
  2022-04-08 18:30 ` Shuah Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Athira Rajeev @ 2022-04-08  7:24 UTC (permalink / raw)
  To: shuah, linux-kselftest, disgoel
  Cc: acme, jolsa, mpe, linux-perf-users, linuxppc-dev, linux-kernel,
	maddy, kjain, srikar

The selftest "mqueue/mq_perf_tests.c" use CPU_ALLOC to allocate
CPU set. This cpu set is used further in pthread_attr_setaffinity_np
and by pthread_create in the code. But in current code, allocated
cpu set is not freed.

Fix this issue by adding CPU_FREE in the "shutdown" function which
is called in most of the error/exit path for the cleanup. There are
few error paths which exit without using shutdown. Add a common goto
error path with CPU_FREE for these cases.

Fixes: 7820b0715b6f ("tools/selftests: add mq_perf_tests")
Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
---
Changelog:
 From v2 -> v3:
  Addressed review comment from Shuah Khan to add
  common "goto" error path with CPU_FREE for few exit
  cases.
 From v1 -> v2:
  Addressed review comment from Shuah Khan to add
  CPU_FREE in other exit paths where it is needed

 .../testing/selftests/mqueue/mq_perf_tests.c  | 25 +++++++++++++------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/mqueue/mq_perf_tests.c b/tools/testing/selftests/mqueue/mq_perf_tests.c
index b019e0b8221c..84fda3b49073 100644
--- a/tools/testing/selftests/mqueue/mq_perf_tests.c
+++ b/tools/testing/selftests/mqueue/mq_perf_tests.c
@@ -180,6 +180,9 @@ void shutdown(int exit_val, char *err_cause, int line_no)
 	if (in_shutdown++)
 		return;
 
+	/* Free the cpu_set allocated using CPU_ALLOC in main function */
+	CPU_FREE(cpu_set);
+
 	for (i = 0; i < num_cpus_to_pin; i++)
 		if (cpu_threads[i]) {
 			pthread_kill(cpu_threads[i], SIGUSR1);
@@ -551,6 +554,12 @@ int main(int argc, char *argv[])
 		perror("sysconf(_SC_NPROCESSORS_ONLN)");
 		exit(1);
 	}
+
+	if (getuid() != 0)
+		ksft_exit_skip("Not running as root, but almost all tests "
+			"require root in order to modify\nsystem settings.  "
+			"Exiting.\n");
+
 	cpus_online = min(MAX_CPUS, sysconf(_SC_NPROCESSORS_ONLN));
 	cpu_set = CPU_ALLOC(cpus_online);
 	if (cpu_set == NULL) {
@@ -589,7 +598,7 @@ int main(int argc, char *argv[])
 						cpu_set)) {
 					fprintf(stderr, "Any given CPU may "
 						"only be given once.\n");
-					exit(1);
+					goto err_code;
 				} else
 					CPU_SET_S(cpus_to_pin[cpu],
 						  cpu_set_size, cpu_set);
@@ -607,7 +616,7 @@ int main(int argc, char *argv[])
 				queue_path = malloc(strlen(option) + 2);
 				if (!queue_path) {
 					perror("malloc()");
-					exit(1);
+					goto err_code;
 				}
 				queue_path[0] = '/';
 				queue_path[1] = 0;
@@ -622,17 +631,12 @@ int main(int argc, char *argv[])
 		fprintf(stderr, "Must pass at least one CPU to continuous "
 			"mode.\n");
 		poptPrintUsage(popt_context, stderr, 0);
-		exit(1);
+		goto err_code;
 	} else if (!continuous_mode) {
 		num_cpus_to_pin = 1;
 		cpus_to_pin[0] = cpus_online - 1;
 	}
 
-	if (getuid() != 0)
-		ksft_exit_skip("Not running as root, but almost all tests "
-			"require root in order to modify\nsystem settings.  "
-			"Exiting.\n");
-
 	max_msgs = fopen(MAX_MSGS, "r+");
 	max_msgsize = fopen(MAX_MSGSIZE, "r+");
 	if (!max_msgs)
@@ -740,4 +744,9 @@ int main(int argc, char *argv[])
 			sleep(1);
 	}
 	shutdown(0, "", 0);
+
+err_code:
+	CPU_FREE(cpu_set);
+	exit(1);
+
 }
-- 
2.35.1


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

* Re: [PATCH V3] testing/selftests/mqueue: Fix mq_perf_tests to free the allocated cpu set
  2022-04-08  7:24 [PATCH V3] testing/selftests/mqueue: Fix mq_perf_tests to free the allocated cpu set Athira Rajeev
@ 2022-04-08 18:30 ` Shuah Khan
  2022-04-09  6:26   ` Athira Rajeev
  0 siblings, 1 reply; 3+ messages in thread
From: Shuah Khan @ 2022-04-08 18:30 UTC (permalink / raw)
  To: Athira Rajeev, shuah, linux-kselftest, disgoel
  Cc: acme, jolsa, mpe, linux-perf-users, linuxppc-dev, linux-kernel,
	maddy, kjain, srikar, Shuah Khan

On 4/8/22 1:24 AM, Athira Rajeev wrote:
> The selftest "mqueue/mq_perf_tests.c" use CPU_ALLOC to allocate
> CPU set. This cpu set is used further in pthread_attr_setaffinity_np
> and by pthread_create in the code. But in current code, allocated
> cpu set is not freed.
> 
> Fix this issue by adding CPU_FREE in the "shutdown" function which
> is called in most of the error/exit path for the cleanup. There are
> few error paths which exit without using shutdown. Add a common goto
> error path with CPU_FREE for these cases.
> 
> Fixes: 7820b0715b6f ("tools/selftests: add mq_perf_tests")
> Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
> ---
> Changelog:
>   From v2 -> v3:
>    Addressed review comment from Shuah Khan to add
>    common "goto" error path with CPU_FREE for few exit
>    cases.
>   From v1 -> v2:
>    Addressed review comment from Shuah Khan to add
>    CPU_FREE in other exit paths where it is needed
> 

Thank you. I will queue this up for Linux 5.18-rc3

thanks,
-- Shuah

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

* Re: [PATCH V3] testing/selftests/mqueue: Fix mq_perf_tests to free the allocated cpu set
  2022-04-08 18:30 ` Shuah Khan
@ 2022-04-09  6:26   ` Athira Rajeev
  0 siblings, 0 replies; 3+ messages in thread
From: Athira Rajeev @ 2022-04-09  6:26 UTC (permalink / raw)
  To: Shuah Khan
  Cc: shuah, linux-kselftest, disgoel, Arnaldo Carvalho de Melo,
	Jiri Olsa, Michael Ellerman, linux-perf-users, linuxppc-dev,
	Linux Kernel Mailing List, maddy, kajoljain, Srikar Dronamraju



> On 09-Apr-2022, at 12:00 AM, Shuah Khan <skhan@linuxfoundation.org> wrote:
> 
> On 4/8/22 1:24 AM, Athira Rajeev wrote:
>> The selftest "mqueue/mq_perf_tests.c" use CPU_ALLOC to allocate
>> CPU set. This cpu set is used further in pthread_attr_setaffinity_np
>> and by pthread_create in the code. But in current code, allocated
>> cpu set is not freed.
>> Fix this issue by adding CPU_FREE in the "shutdown" function which
>> is called in most of the error/exit path for the cleanup. There are
>> few error paths which exit without using shutdown. Add a common goto
>> error path with CPU_FREE for these cases.
>> Fixes: 7820b0715b6f ("tools/selftests: add mq_perf_tests")
>> Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
>> ---
>> Changelog:
>>  From v2 -> v3:
>>   Addressed review comment from Shuah Khan to add
>>   common "goto" error path with CPU_FREE for few exit
>>   cases.
>>  From v1 -> v2:
>>   Addressed review comment from Shuah Khan to add
>>   CPU_FREE in other exit paths where it is needed
> 
> Thank you. I will queue this up for Linux 5.18-rc3

Thanks Shuah

Athira
> 
> thanks,
> -- Shuah


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

end of thread, other threads:[~2022-04-09  6:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-08  7:24 [PATCH V3] testing/selftests/mqueue: Fix mq_perf_tests to free the allocated cpu set Athira Rajeev
2022-04-08 18:30 ` Shuah Khan
2022-04-09  6:26   ` Athira Rajeev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).