Hi Alexander,

thank you for the review.

On 11/12/20 3:59 PM, Alexander Potapenko wrote:
> On Tue, Nov 10, 2020 at 11:12 PM Andrey Konovalov <andreyk...@google.com> 
> wrote:
>>
>> From: Vincenzo Frascino <vincenzo.frasc...@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"
> 

I will fix it in the next iteration.

> 
>> +       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.
> 

The main goal here is to have a good probability of having a different setting
to the GCR_EL1 register. Hence the difference in between 0xffff and 0xffff-1 is
negligible. Anyway I agree that we should aim to cover all the possible
combinations.

> 
>> +
>> +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.
> 

Yes it might, but I would like to avoid another syscall if I can.

>> +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.
> 

Yes, I agree, I had some debug code making use of it, but I removed it in the 
end.

> 
>> +       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?
> 

Yes I agree, I forgot to check a condition. We should abort the test in such a
case returning KSFT_FAIL directly.

>> +       }
>> +
>> +       for (int i = 0; i < NUM_ITERATIONS; i++)
>> +               if (results[i] == KSFT_FAIL)
>> +                       return KSFT_FAIL;
>> +
>> +       return KSFT_PASS;
>> +}
>> +
> 
> 

-- 
Regards,
Vincenzo

Reply via email to