diff mbox series

[4/5] selftests/resctrl: Kill the child process before exiting the parent process if an exception occurs

Message ID 20220914015147.3071025-6-tan.shaopeng@jp.fujitsu.com
State New
Headers show
Series selftests/resctrl: Some improvements of resctrl selftest | expand

Commit Message

Shaopeng Tan Sept. 14, 2022, 1:51 a.m. UTC
After creating a child process with fork() in CAT test, if there is
an exception occurs, the parent process will be terminated immediately,
but the child process will not be killed and umount_resctrlfs() will not
be called.

When fork() is used in CMT/MBA/MBM tests.
If an exception occurs, before parent process exiting,
the child process is killed and umount_resctrlfs() is called.

Kill the child process before exiting the parent process
if an exception occurs in CAT test, like in CMT/MBA/MBM tests.

Signed-off-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
---
 tools/testing/selftests/resctrl/cat_test.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

Comments

Reinette Chatre Sept. 22, 2022, 5:47 p.m. UTC | #1
Hi Shaopeng,

On 9/13/2022 6:51 PM, Shaopeng Tan wrote:

...

> @@ -218,11 +219,11 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
>  			}
>  		}
>  		close(pipefd[0]);
> -		kill(bm_pid, SIGKILL);
>  	}
>  
> -	if (bm_pid)
> -		umount_resctrlfs();
> +out:
> +	kill(bm_pid, SIGKILL);
> +	umount_resctrlfs();
>
Shaopeng Tan (Fujitsu) Sept. 27, 2022, 9:02 a.m. UTC | #2
Hi Reinette,

> On 9/13/2022 6:51 PM, Shaopeng Tan wrote:
> 
> ...
> 
> > @@ -218,11 +219,11 @@ int cat_perf_miss_val(int cpu_no, int n, char
> *cache_type)
> >  			}
> >  		}
> >  		close(pipefd[0]);
> > -		kill(bm_pid, SIGKILL);
> >  	}
> >
> > -	if (bm_pid)
> > -		umount_resctrlfs();
> > +out:
> > +	kill(bm_pid, SIGKILL);
> > +	umount_resctrlfs();
> >
> 
> From what I can tell both parent and child will now run this code. So both will
> attempt to unmount resctrl fs and the child will attempt to kill PID 0?

Thanks for your advice. There are problems as you point out.
I think it is complicated if we fix this bug like MBM/MBA/CMT test using sigaction().
It seems this bug cannot be solved easily.
Please give me some time.

Best Regards,
Shaopeng
diff mbox series

Patch

diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c
index d1134f66469f..f62da445acbb 100644
--- a/tools/testing/selftests/resctrl/cat_test.c
+++ b/tools/testing/selftests/resctrl/cat_test.c
@@ -186,11 +186,11 @@  int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
 
 	ret = cat_val(&param);
 	if (ret)
-		return ret;
+		goto out;
 
 	ret = check_results(&param);
 	if (ret)
-		return ret;
+		goto out;
 
 	if (bm_pid == 0) {
 		/* Tell parent that child is ready */
@@ -200,7 +200,8 @@  int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
 		    sizeof(pipe_message)) {
 			close(pipefd[1]);
 			perror("# failed signaling parent process");
-			return errno;
+			ret = errno;
+			goto out;
 		}
 
 		close(pipefd[1]);
@@ -218,11 +219,11 @@  int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
 			}
 		}
 		close(pipefd[0]);
-		kill(bm_pid, SIGKILL);
 	}
 
-	if (bm_pid)
-		umount_resctrlfs();
+out:
+	kill(bm_pid, SIGKILL);
+	umount_resctrlfs();
 
-	return 0;
+	return ret;
 }