Re: [PATCH v9 44/44] kselftest/arm64: Check GCR_EL1 after context switch
From: Alexander Potapenko <glider@google.com>
Date: 2020-11-12 15:59:52
Also in:
linux-mm, lkml
On Tue, Nov 10, 2020 at 11:12 PM Andrey Konovalov [off-list ref] wrote:
From: Vincenzo Frascino <vincenzo.frascino@arm.com> This test is specific to MTE and verifies that the GCR_EL1 register is context switched correctly. It spawn 1024 processes and each process spawns 5 threads. Each thread
Nit: "spawns"
+ srand(time(NULL) ^ (pid << 16) ^ (tid << 16)); + + prctl_tag_mask = rand() % 0xffff;
Nit: if you want values between 0 and 0xffff you probably want to use bitwise AND.
+
+int execute_test(pid_t pid)
+{
+ pthread_t thread_id[MAX_THREADS];
+ int thread_data[MAX_THREADS];
+
+ for (int i = 0; i < MAX_THREADS; i++)
+ pthread_create(&thread_id[i], NULL,
+ execute_thread, (void *)&pid);It might be simpler to call getpid() in execute_thread() instead.
+int mte_gcr_fork_test()
+{
+ pid_t pid[NUM_ITERATIONS];
+ int results[NUM_ITERATIONS];
+ pid_t cpid;
+ int res;
+
+ for (int i = 0; i < NUM_ITERATIONS; i++) {
+ pid[i] = fork();
+
+ if (pid[i] == 0) {pid[i] isn't used anywhere else. Did you want to keep the pids to ensure that all children finished the work? If not, we can probably go with a scalar here.
+ for (int i = 0; i < NUM_ITERATIONS; i++) {
+ wait(&res);
+
+ if(WIFEXITED(res))
+ results[i] = WEXITSTATUS(res);
+ else
+ --i;Won't we get stuck in this loop if fork() returns -1 for one of the processes?
+ } + + for (int i = 0; i < NUM_ITERATIONS; i++) + if (results[i] == KSFT_FAIL) + return KSFT_FAIL; + + return KSFT_PASS; +} +
-- Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Straße, 33 80636 München Geschäftsführer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel