Skip to contentSkip to conversation

lib: initialize lib|main_pid to zero in the setup_ipc

PATCH In review Li Wang via ltp 3 participants 15 messages May 13, 2025 – May 14, 2025 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 lib: initialize lib|main_pid to zero in the setup_ipc

To get rid of failure from github CI.

CI Test Job: https://github.com/wangli5665/ltp/actions/runs/14988530205

Follow-up-fix: commit b987b8ac5 ("lib: child process exit with error due to uninitialized lib_pid")

---
 lib/tst_test.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
lib/tst_test.c +8 -7
index b666715b9..9f11c1c47 100644
@@ -59,7 +59,6 @@ static const char *tid;
 static int iterations = 1;
 static float duration = -1;
 static float timeout_mul = -1;
-static pid_t lib_pid;
 static int mntpoint_mounted;
 static int ovl_mounted;
 static struct timespec tst_start_time; /* valid only for test pid */
@@ -143,7 +142,9 @@ static void setup_ipc(void)
 		tst_futexes = (char *)results + sizeof(struct results);
 		tst_max_futexes = (size - sizeof(struct results))/sizeof(futex_t);
 	}
-	results->lib_pid = lib_pid;
+
+	results->lib_pid = 0;
+	results->main_pid = 0;
 }
 
 static void cleanup_ipc(void)
@@ -394,7 +395,7 @@ void tst_vbrk_(const char *file, const int lineno, int ttype, const char *fmt,
 	 * If tst_brk() is called from some of the C helpers even before the
 	 * library was initialized, just exit.
 	 */
-	if (!results->lib_pid)
+	if (!results || !results->lib_pid)
 		exit(TTYPE_RESULT(ttype));
 
 	update_results(TTYPE_RESULT(ttype));
@@ -1334,6 +1335,8 @@ static void do_setup(int argc, char *argv[])
 		tst_test->forks_child = 1;
 	}
 
+	setup_ipc();
+
 	if (tst_test->needs_kconfigs && tst_kconfig_check(tst_test->needs_kconfigs))
 		tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
 
@@ -1393,8 +1396,6 @@ static void do_setup(int argc, char *argv[])
 	if (tst_test->hugepages.number)
 		tst_reserve_hugepages(&tst_test->hugepages);
 
-	setup_ipc();
-
 	if (tst_test->bufs)
 		tst_buffers_alloc(tst_test->bufs);
 
@@ -1929,10 +1930,11 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
 	unsigned int test_variants = 1;
 	struct utsname uval;
 
-	lib_pid = getpid();
 	tst_test = self;
 
 	do_setup(argc, argv);
+
+	results->lib_pid = getpid();
 	tst_enable_oom_protection(results->lib_pid);
 
 	SAFE_SIGNAL(SIGALRM, alarm_handler);
@@ -1940,7 +1942,6 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
 
 	tst_res(TINFO, "LTP version: "LTP_VERSION);
 
-
 	uname(&uval);
 	tst_res(TINFO, "Tested kernel: %s %s %s", uval.release, uval.version, uval.machine);
 
Signature · 5 lines
2.49.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH 2/2 dirtyc0w_shmem: set child_needs_reinit

---
 testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem.c | 1 +
 1 file changed, 1 insertion(+)
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem.c +1 -0
index 64b187b35..4b31da831 100644
@@ -104,6 +104,7 @@ static void cleanup(void)
 
 static struct tst_test test = {
 	.needs_checkpoints = 1,
+	.child_needs_reinit =1 ,
 	.forks_child = 1,
 	.needs_root = 1,
 	.runtime = 120,
Signature · 5 lines
2.49.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Re: [LTP] [PATCH 2/2] dirtyc0w_shmem: set child_needs_reinit

Quoted 10 lines · Li Wang
---
 testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem.c | 1 +
 1 file changed, 1 insertion(+)
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem.c +0 -0
index 64b187b35..4b31da831 100644

testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem.c static void cleanup(void) · line 107

Quoted 4 lines
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem.c +1 -0
@@ -104,6 +104,7 @@ static void cleanup(void)
 
 static struct tst_test test = {
 	.needs_checkpoints = 1,
+	.child_needs_reinit =1 ,

s/.child_needs_reinit =1 ,/.child_needs_reinit = 1,/

Do we still need this? Since .needs_checkpoints is already setted.

Quoted 6 lines
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem.c +0 -0
 	.forks_child = 1,
 	.needs_root = 1,
 	.runtime = 120,
Signature · 1 line
2.49.0

Thanks for your quick patchset :)

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] [PATCH 2/2] dirtyc0w_shmem: set child_needs_reinit

Quoted 13 lines · Wei Gao

Review

Quoted 6 lines · Li Wang
---
 testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem.c | 1 +
 1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem.c

Quoted 5 lines

index 64b187b35..4b31da831 100644

testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem.c +0 -0
@@ -104,6 +104,7 @@ static void cleanup(void)
 
Quoted 5 lines

testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem.c static void cleanup(void) · line 107

Quoted 3 lines
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem.c +1 -0
 static struct tst_test test = {
      .needs_checkpoints = 1,
+     .child_needs_reinit =1 ,

s/.child_needs_reinit =1 ,/.child_needs_reinit = 1,/

Good catch. That blank before the comma should be removed.

Quoted 2 lines

Do we still need this? Since .needs_checkpoints is already setted.

I think yes!

While some fields may have overlapping effects, explicitly setting this field
highlights its intended function and enhances the clarity of the code.

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] [PATCH 2/2] dirtyc0w_shmem: set child_needs_reinit

Hi!

Quoted 8 lines
Quoted 2 lines

Do we still need this? Since .needs_checkpoints is already setted.

I think yes!

While some fields may have overlapping effects, explicitly setting this field
highlights its intended function and enhances the clarity of the code.

Exactly.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw
In reply to Li Wang via ltp

Hi!

Quoted 52 lines

To get rid of failure from github CI.

CI Test Job: https://github.com/wangli5665/ltp/actions/runs/14988530205

Follow-up-fix: commit b987b8ac5 ("lib: child process exit with error due to uninitialized lib_pid")

---
 lib/tst_test.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
lib/tst_test.c +6 -3
index b666715b9..9f11c1c47 100644
@@ -59,7 +59,6 @@ static const char *tid;
 static int iterations = 1;
 static float duration = -1;
 static float timeout_mul = -1;
-static pid_t lib_pid;
 static int mntpoint_mounted;
 static int ovl_mounted;
 static struct timespec tst_start_time; /* valid only for test pid */
@@ -143,7 +142,9 @@ static void setup_ipc(void)
 		tst_futexes = (char *)results + sizeof(struct results);
 		tst_max_futexes = (size - sizeof(struct results))/sizeof(futex_t);
 	}
-	results->lib_pid = lib_pid;
+
+	results->lib_pid = 0;
+	results->main_pid = 0;
 }
 
 static void cleanup_ipc(void)
@@ -394,7 +395,7 @@ void tst_vbrk_(const char *file, const int lineno, int ttype, const char *fmt,
 	 * If tst_brk() is called from some of the C helpers even before the
 	 * library was initialized, just exit.
 	 */
-	if (!results->lib_pid)
+	if (!results || !results->lib_pid)
 		exit(TTYPE_RESULT(ttype));
 
 	update_results(TTYPE_RESULT(ttype));
@@ -1334,6 +1335,8 @@ static void do_setup(int argc, char *argv[])
 		tst_test->forks_child = 1;
 	}
 
+	setup_ipc();
+
 	if (tst_test->needs_kconfigs && tst_kconfig_check(tst_test->needs_kconfigs))
 		tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
 

lib/tst_test.c static void do_setup(int argc, char *argv[]) · line 1397

Quoted 5 lines
lib/tst_test.c +0 -2
@@ -1393,8 +1396,6 @@ static void do_setup(int argc, char *argv[])
 	if (tst_test->hugepages.number)
 		tst_reserve_hugepages(&tst_test->hugepages);
 
-	setup_ipc();
-

I suppose that this has to go before the tst_reserve_hugepages() so that we have results->lib_pid defined and properly clean up after the hugepages. However for that to work we have to set the results->lib_pid directly in the setup_ipc().

lib/tst_test.c void tst_run_tcases(int argc, char *argv[], struct tst_test *self) · line 1937

Quoted 13 lines
lib/tst_test.c +2 -1
 	if (tst_test->bufs)
 		tst_buffers_alloc(tst_test->bufs);
 
@@ -1929,10 +1930,11 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
 	unsigned int test_variants = 1;
 	struct utsname uval;
 
-	lib_pid = getpid();
 	tst_test = self;
 
 	do_setup(argc, argv);
+
+	results->lib_pid = getpid();

Setting it here is too late.

Other than that the patch looks good to me.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw
Quoted 57 lines · Cyril Hrubis

Hi!

Quoted 55 lines

To get rid of failure from github CI.

CI Test Job: https://github.com/wangli5665/ltp/actions/runs/14988530205

Follow-up-fix: commit b987b8ac5 ("lib: child process exit with error due to uninitialized lib_pid")

---
 lib/tst_test.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
lib/tst_test.c +6 -3
index b666715b9..9f11c1c47 100644
@@ -59,7 +59,6 @@ static const char *tid;
 static int iterations = 1;
 static float duration = -1;
 static float timeout_mul = -1;
-static pid_t lib_pid;
 static int mntpoint_mounted;
 static int ovl_mounted;
 static struct timespec tst_start_time; /* valid only for test pid */
@@ -143,7 +142,9 @@ static void setup_ipc(void)
              tst_futexes = (char *)results + sizeof(struct results);
              tst_max_futexes = (size - sizeof(struct results))/sizeof(futex_t);
      }
-     results->lib_pid = lib_pid;
+
+     results->lib_pid = 0;
+     results->main_pid = 0;
 }
 
 static void cleanup_ipc(void)
@@ -394,7 +395,7 @@ void tst_vbrk_(const char *file, const int lineno, int ttype, const char *fmt,
       * If tst_brk() is called from some of the C helpers even before the
       * library was initialized, just exit.
       */
-     if (!results->lib_pid)
+     if (!results || !results->lib_pid)
              exit(TTYPE_RESULT(ttype));
 
      update_results(TTYPE_RESULT(ttype));
@@ -1334,6 +1335,8 @@ static void do_setup(int argc, char *argv[])
              tst_test->forks_child = 1;
      }
 
+     setup_ipc();
+
      if (tst_test->needs_kconfigs && tst_kconfig_check(tst_test->needs_kconfigs))
              tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
 
@@ -1393,8 +1396,6 @@ static void do_setup(int argc, char *argv[])
      if (tst_test->hugepages.number)
              tst_reserve_hugepages(&tst_test->hugepages);
 
Quoted 7 lines

lib/tst_test.c static void do_setup(int argc, char *argv[]) · line 1397

Quoted 2 lines
lib/tst_test.c +0 -2
-     setup_ipc();
-

I suppose that this has to go before the tst_reserve_hugepages() so that we have results->lib_pid defined and properly clean up after the hugepages. However for that to work we have to set the results->lib_pid directly in the setup_ipc().

In this patch, setup_ipc() is already moved up before the tst_reserve_hugpages(). I particularly put it after tst_test->runs_scripts, which is mandatory to have .child_needs_reinit initialized first.

And the hugpages cleanup work is completed in tst_sys_conf_restore(0) in the do_cleanup, so that might not be a problem.
I have validated that all hugetlb tests work well.

Also,

Or, did I miss anything?

Quoted 8 lines
Quoted 8 lines
lib/tst_test.c +0 -0
      if (tst_test->bufs)
              tst_buffers_alloc(tst_test->bufs);
 
@@ -1929,10 +1930,11 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
      unsigned int test_variants = 1;
      struct utsname uval;
 
Quoted 8 lines

lib/tst_test.c void tst_run_tcases(int argc, char *argv[], struct tst_test *self) · line 1937

Quoted 6 lines
lib/tst_test.c +2 -1
-     lib_pid = getpid();
      tst_test = self;
 
      do_setup(argc, argv);
+
+     results->lib_pid = getpid();

Setting it here is too late.

Since I added results exists check in tst_vbrk_(), so it should be safe enough to set lib_pid just after setup_ipc() whatever the cleanup work happen early or later in test lib.

if (!results || !results->lib_pid)

    exit(TTYPE_RESULT(ttype));
Quoted 7 lines

Other than that the patch looks good to me.

--
Cyril Hrubis
[email protected]

Signature · 6 lines
Regards,
Li Wang


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

Hi!

Quoted 16 lines
Quoted 11 lines

lib/tst_test.c static void do_setup(int argc, char *argv[]) · line 1397

Quoted 6 lines
lib/tst_test.c +0 -2
@@ -1393,8 +1396,6 @@ static void do_setup(int argc, char *argv[])
      if (tst_test->hugepages.number)
              tst_reserve_hugepages(&tst_test->hugepages);
 
-     setup_ipc();
-

I suppose that this has to go before the tst_reserve_hugepages() so that we have results->lib_pid defined and properly clean up after the hugepages. However for that to work we have to set the results->lib_pid directly in the setup_ipc().

In this patch, setup_ipc() is already moved up before the tst_reserve_hugpages(). I particularly put it after tst_test->runs_scripts, which is mandatory to have .child_needs_reinit initialized first.

Quoted 7 lines

And the hugpages cleanup work is completed in tst_sys_conf_restore(0) in the do_cleanup, so that might not be a problem.
I have validated that all hugetlb tests work well.

Also,

Or, did I miss anything?

The problem is that no library cleanup will happen unless lib_pid is set, that means that tst_brk() will be triggered anywhere in do_setup() the clanup will not be run because we set the lib_pid after the do_setup() in the patch.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw
Quoted 22 lines · Cyril Hrubis

Hi!

Quoted 20 lines
Quoted 11 lines

Review static void do_setup(int argc, char *argv[]) · line 1397

Quoted 6 lines
(quoted diff) +0 -2
@@ -1393,8 +1396,6 @@ static void do_setup(int argc, char *argv[])
      if (tst_test->hugepages.number)
              tst_reserve_hugepages(&tst_test->hugepages);
 
-     setup_ipc();
-

I suppose that this has to go before the tst_reserve_hugepages() so that we have results->lib_pid defined and properly clean up after the hugepages. However for that to work we have to set the results->lib_pid directly in the setup_ipc().

In this patch, setup_ipc() is already moved up before the tst_reserve_hugpages(). I particularly put it after tst_test->runs_scripts, which is mandatory to have .child_needs_reinit initialized first.

And the hugpages cleanup work is completed in tst_sys_conf_restore(0) in the do_cleanup, so that might not be a problem.
I have validated that all hugetlb tests work well.

Quoted 8 lines
Quoted 3 lines

Also,

Or, did I miss anything?

The problem is that no library cleanup will happen unless lib_pid is set, that means that tst_brk() will be triggered anywhere in do_setup() the clanup will not be run because we set the lib_pid after the do_setup() in the patch.

I see, and you're right we have to set lib_pid before any real setup.

Does this change below make sense (based on the v2 I just sent)?

lib/tst_test.c +2 -0
@@ -144,6 +144,8 @@ static void setup_ipc(void)
        }
 
        memset(results, 0 , size);
+
+       results->lib_pid = getpid();
 }
 
 static void cleanup_ipc(void)
@@ -1933,7 +1935,6 @@ void tst_run_tcases(int argc, char *argv[],

struct tst_test *self)

        do_setup(argc, argv);
-       results->lib_pid = getpid();
        tst_enable_oom_protection(results->lib_pid);

        SAFE_SIGNAL(SIGALRM, alarm_handler);
Signature · 6 lines
Regards,
Li Wang


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw

Hi!

Quoted 23 lines

I see, and you're right we have to set lib_pid before any real setup.

Does this change below make sense (based on the v2 I just sent)?

lib/tst_test.c +2 -1
@@ -144,6 +144,8 @@ static void setup_ipc(void)
        }
 
        memset(results, 0 , size);
+
+       results->lib_pid = getpid();
 }
 
 static void cleanup_ipc(void)
@@ -1933,7 +1935,6 @@ void tst_run_tcases(int argc, char *argv[],
 struct tst_test *self)
 
        do_setup(argc, argv);
 
-       results->lib_pid = getpid();
        tst_enable_oom_protection(results->lib_pid);
 
Quoted 1 line
        SAFE_SIGNAL(SIGALRM, alarm_handler);

Yes, this should fix it.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw
In reply to Cyril Hrubis

Hi all,

...

Quoted 9 lines
Quoted 9 lines

+++ b/lib/tst_test.c

lib/tst_test.c +0 -1
@@ -59,7 +59,6 @@ static const char *tid;
 static int iterations = 1;
 static float duration = -1;
 static float timeout_mul = -1;
-static pid_t lib_pid;
 static int mntpoint_mounted;
 static int ovl_mounted;
 static struct timespec tst_start_time; /* valid only for test pid */
Quoted 8 lines

lib/tst_test.c static void setup_ipc(void) · line 147

Quoted 8 lines
lib/tst_test.c +3 -1
@@ -143,7 +142,9 @@ static void setup_ipc(void)
 		tst_futexes = (char *)results + sizeof(struct results);
 		tst_max_futexes = (size - sizeof(struct results))/sizeof(futex_t);
 	}
-	results->lib_pid = lib_pid;
+
+	results->lib_pid = 0;
+	results->main_pid = 0;

nit: Is it really needed to int them to 0? Because they should be 0 due the default struct value, right?

Quoted 25 lines
Quoted 24 lines
lib/tst_test.c +3 -1
 }
 
 static void cleanup_ipc(void)
@@ -394,7 +395,7 @@ void tst_vbrk_(const char *file, const int lineno, int ttype, const char *fmt,
 	 * If tst_brk() is called from some of the C helpers even before the
 	 * library was initialized, just exit.
 	 */
-	if (!results->lib_pid)
+	if (!results || !results->lib_pid)
 		exit(TTYPE_RESULT(ttype));
 
 	update_results(TTYPE_RESULT(ttype));
@@ -1334,6 +1335,8 @@ static void do_setup(int argc, char *argv[])
 		tst_test->forks_child = 1;
 	}
 
+	setup_ipc();
+
 	if (tst_test->needs_kconfigs && tst_kconfig_check(tst_test->needs_kconfigs))
 		tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
 
@@ -1393,8 +1396,6 @@ static void do_setup(int argc, char *argv[])
 	if (tst_test->hugepages.number)
 		tst_reserve_hugepages(&tst_test->hugepages);
Quoted 6 lines

lib/tst_test.c static void do_setup(int argc, char *argv[]) · line 1397

Quoted 2 lines
lib/tst_test.c +0 -2
-	setup_ipc();
-

I suppose that this has to go before the tst_reserve_hugepages() so that we have results->lib_pid defined and properly clean up after the hugepages.

Why? Is that due possible tst_brk() calls in tst_reserve_hugepages()? (Which uses SAFE_* macros.) That would trigger Because there are tst_brk() calls before.

Also why not assign results->lib_pid = getpid() at the beginning of tst_run_tcases() ?

Kind regards,
Petr

Quoted 20 lines

However for that to work we have to set the
results->lib_pid directly in the setup_ipc().

lib/tst_test.c void tst_run_tcases(int argc, char *argv[], struct tst_test *self) · line 1937

Quoted 13 lines
lib/tst_test.c +2 -1
 	if (tst_test->bufs)
 		tst_buffers_alloc(tst_test->bufs);
 
@@ -1929,10 +1930,11 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
 	unsigned int test_variants = 1;
 	struct utsname uval;
 
-	lib_pid = getpid();
 	tst_test = self;
 
 	do_setup(argc, argv);
+
+	results->lib_pid = getpid();

Setting it here is too late.

Other than that the patch looks good to me.

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#11 lore raw
Quoted 16 lines · Petr Vorel

Hi all,

...

Quoted 12 lines
Quoted 12 lines

+++ b/lib/tst_test.c

lib/tst_test.c +0 -1
@@ -59,7 +59,6 @@ static const char *tid;
 static int iterations = 1;
 static float duration = -1;
 static float timeout_mul = -1;
-static pid_t lib_pid;
 static int mntpoint_mounted;
 static int ovl_mounted;
 static struct timespec tst_start_time; /* valid only for test pid */
@@ -143,7 +142,9 @@ static void setup_ipc(void)
            tst_futexes = (char *)results + sizeof(struct results);
            tst_max_futexes = (size - sizeof(struct results))/sizeof(futex_t);
Quoted 8 lines
Quoted 5 lines

lib/tst_test.c static void setup_ipc(void) · line 147

Quoted 5 lines
lib/tst_test.c +3 -1
    }
-   results->lib_pid = lib_pid;
+
+   results->lib_pid = 0;
+   results->main_pid = 0;

nit: Is it really needed to int them to 0? Because they should be 0 due the default struct value, right?

Right!

I think we need to initialize them, because the test may fail/break just before creating main_pid, then test cleanup work needs to invoke tst_vbrk_ and tst_res_ somewhere that compares pid to invoke the corresponding cleanup work.

Quoted 33 lines
Quoted 26 lines
Quoted 25 lines
lib/tst_test.c +3 -1
 }
 
 static void cleanup_ipc(void)
@@ -394,7 +395,7 @@ void tst_vbrk_(const char *file, const int lineno, int ttype, const char *fmt,
     * If tst_brk() is called from some of the C helpers even before the
     * library was initialized, just exit.
     */
-   if (!results->lib_pid)
+   if (!results || !results->lib_pid)
            exit(TTYPE_RESULT(ttype));
 
    update_results(TTYPE_RESULT(ttype));
@@ -1334,6 +1335,8 @@ static void do_setup(int argc, char *argv[])
            tst_test->forks_child = 1;
    }
 
+   setup_ipc();
+
    if (tst_test->needs_kconfigs && tst_kconfig_check(tst_test->needs_kconfigs))
            tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
 
@@ -1393,8 +1396,6 @@ static void do_setup(int argc, char *argv[])
    if (tst_test->hugepages.number)
            tst_reserve_hugepages(&tst_test->hugepages);
Quoted 6 lines

lib/tst_test.c static void do_setup(int argc, char *argv[]) · line 1397

Quoted 2 lines
lib/tst_test.c +0 -2
-   setup_ipc();
-

I suppose that this has to go before the tst_reserve_hugepages() so that we have results->lib_pid defined and properly clean up after the hugepages.

Quoted 5 lines

Why? Is that due possible tst_brk() calls in tst_reserve_hugepages()? (Which uses SAFE_* macros.) That would trigger Because there are tst_brk() calls before.

Also why not assign results->lib_pid = getpid() at the beginning of tst_run_tcases() ?

No, we can't.

Because we moved the lib_pid in the IPC region, which allocated memory in the setup_ipc() function.

Quoted 25 lines

Kind regards,
Petr

Quoted 20 lines

However for that to work we have to set the
results->lib_pid directly in the setup_ipc().

lib/tst_test.c void tst_run_tcases(int argc, char *argv[], struct tst_test *self) · line 1937

Quoted 13 lines
lib/tst_test.c +2 -1
    if (tst_test->bufs)
            tst_buffers_alloc(tst_test->bufs);
 
@@ -1929,10 +1930,11 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
    unsigned int test_variants = 1;
    struct utsname uval;
 
-   lib_pid = getpid();
    tst_test = self;
 
    do_setup(argc, argv);
+
+   results->lib_pid = getpid();

Setting it here is too late.

Other than that the patch looks good to me.

Signature · 6 lines
Regards,
Li Wang


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#12 lore raw
Quoted 18 lines · Li Wang
Quoted 16 lines · Petr Vorel

Hi all,

...

Quoted 12 lines
Quoted 12 lines

+++ b/lib/tst_test.c

lib/tst_test.c +0 -1
@@ -59,7 +59,6 @@ static const char *tid;
 static int iterations = 1;
 static float duration = -1;
 static float timeout_mul = -1;
-static pid_t lib_pid;
 static int mntpoint_mounted;
 static int ovl_mounted;
 static struct timespec tst_start_time; /* valid only for test pid */
@@ -143,7 +142,9 @@ static void setup_ipc(void)
            tst_futexes = (char *)results + sizeof(struct results);
            tst_max_futexes = (size - sizeof(struct results))/sizeof(futex_t);
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

lib/tst_test.c static void setup_ipc(void) · line 147

Quoted 5 lines
lib/tst_test.c +3 -1
    }
-   results->lib_pid = lib_pid;
+
+   results->lib_pid = 0;
+   results->main_pid = 0;

nit: Is it really needed to int them to 0? Because they should be 0 due the default struct value, right?

The results structure memory was dynamically allocated via mmap so the default value might not be zero. Unless we do explicitly call memset(, 0, ...).

Signature · 6 lines
Regards,
Li Wang


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#13 lore raw
Quoted 28 lines · Li Wang
Quoted 18 lines · Petr Vorel
Quoted 16 lines

Hi all,

...

Quoted 12 lines
Quoted 12 lines

+++ b/lib/tst_test.c

lib/tst_test.c +0 -1
@@ -59,7 +59,6 @@ static const char *tid;
 static int iterations = 1;
 static float duration = -1;
 static float timeout_mul = -1;
-static pid_t lib_pid;
 static int mntpoint_mounted;
 static int ovl_mounted;
 static struct timespec tst_start_time; /* valid only for test pid */
@@ -143,7 +142,9 @@ static void setup_ipc(void)
            tst_futexes = (char *)results + sizeof(struct results);
            tst_max_futexes = (size - sizeof(struct results))/sizeof(futex_t);
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

lib/tst_test.c static void setup_ipc(void) · line 147

Quoted 5 lines
lib/tst_test.c +3 -1
    }
-   results->lib_pid = lib_pid;
+
+   results->lib_pid = 0;
+   results->main_pid = 0;

nit: Is it really needed to int them to 0? Because they should be 0 due the default struct value, right?

Quoted 3 lines

The results structure memory was dynamically allocated via mmap so the default value might not be zero. Unless we do explicitly call memset(, 0, ...).

Thanks for info. Or just use {} instead of memset?

struct results saved_results = {};

Tiny detail, just it's more readable to me.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#14 lore raw
Quoted 29 lines · Petr Vorel
Quoted 28 lines · Li Wang
Quoted 26 lines · Petr Vorel
Quoted 24 lines

Hi all,

...

Quoted 9 lines
Quoted 9 lines

+++ b/lib/tst_test.c

lib/tst_test.c +0 -1
@@ -59,7 +59,6 @@ static const char *tid;
 static int iterations = 1;
 static float duration = -1;
 static float timeout_mul = -1;
-static pid_t lib_pid;
 static int mntpoint_mounted;
 static int ovl_mounted;
 static struct timespec tst_start_time; /* valid only for test pid */
Quoted 8 lines

lib/tst_test.c static void setup_ipc(void) · line 147

Quoted 8 lines
lib/tst_test.c +3 -1
@@ -143,7 +142,9 @@ static void setup_ipc(void)
            tst_futexes = (char *)results + sizeof(struct results);
            tst_max_futexes = (size - sizeof(struct results))/sizeof(futex_t);
    }
-   results->lib_pid = lib_pid;
+
+   results->lib_pid = 0;
+   results->main_pid = 0;

nit: Is it really needed to int them to 0? Because they should be 0 due the default struct value, right?

Quoted 5 lines
Quoted 3 lines

The results structure memory was dynamically allocated via mmap so the default value might not be zero. Unless we do explicitly call memset(, 0, ...).

Thanks for info. Or just use {} instead of memset?

This only applies to automatic (stack) or static allocation. As we're dealing with dynamically allocated memory via mmap(), we still need memset() or manually initialize it.

In setup_ipc():

results = SAFE_MMAP(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, ipc_fd, 0);

Quoted 8 lines

struct results saved_results = {};

Tiny detail, just it's more readable to me.

Kind regards,
Petr

Signature · 6 lines
Regards,
Li Wang


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp