hugeshmctl01: Fix reset stat_time when looping with -i n
PATCH 1/1 hugeshmctl01: Fix reset stat_time when looping with -i n
c7a2d296b didn't reset stat_time, thus uninitialized set_shared was assigned to test variable and test got value from a null pointer, which leaded to segfault.
hugeshmctl01.c:279: PASS: shmctl in func_rmid() failed as expected, shared memory appears to be removed tst_checkpoint.c:147: BROK: hugeshmctl01.c:152: tst_checkpoint_wait(0, 10000): ETIMEDOUT (110) mem.c:817: INFO: set nr_hugepages to 0
dmesg:
segfault at 7f73f8c00000 ip 00000000004051e1 sp 00007ffef375f9a0 error 6 in hugeshmctl01.master[404000+13000] addr2line -e hugeshmctl01 -f 00000000004051e1stat_setup
hugeshmctl01.c:139 (discriminator 4)
test = (stat_time == FIRST) ? set_shmat() : set_shared;
/* do an assignement for fun */
*(int *)test = i; // error here
---
Hi Xu,
I'm sorry for introducing a regression.
Thank you for a report and fixing the test.
I'd personally prefer to keep .tcnt = ARRAY_SIZE(tcases), but maybe others will prefer to keep loop in test_hugeshmctl() as it was before my change.
BTW it'd be nice to have something like setup_i() and cleanup_i(), which would be called before/after each run of whole test, when run with -i n.
Kind regards,
Petr
.../mem/hugetlb/hugeshmctl/hugeshmctl01.c | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-)
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c +14 -13
@@ -75,6 +75,20 @@ struct tcase {static void test_hugeshmctl (unsigned int i) { + stat_time =FIRST ; + +/* +* Create a shared memory segment with read and write +* permissions. Do this here instead of in setup() +* so that looping (-i) will work correctly. +*/ +if (i ==0 ) { + shm_id_1 =shmget (shmkey, shm_size, +SHM_HUGETLB |IPC_CREAT |IPC_EXCL |SHM_RW ); +if (shm_id_1 ==-1 ) +tst_brk (TBROK |TERRNO ,"shmget #main" ); + } +/* * if needed, set up any required conditions by * calling the appropriate setup function
@@ -296,19 +310,6 @@ void setup(void) shm_size = hpage_size * hugepages /2 ;update_shm_size (&shm_size); shmkey =getipckey (); - -/* initialize stat_time */ - stat_time =FIRST ; - -/* -* Create a shared memory segment with read and write -* permissions. Do this here instead of in setup() -* so that looping (-i) will work correctly. -*/ - shm_id_1 =shmget (shmkey, shm_size, -SHM_HUGETLB |IPC_CREAT |IPC_EXCL |SHM_RW ); -if (shm_id_1 ==-1 ) -tst_brk (TBROK |TERRNO ,"shmget #main" ); }void cleanup (void )
Signature · 1 line
2.25.1
PATCH 1/1 hugeshmctl01: Fix reset stat_time when looping with -i n
Hi Petr
Quoted 33 lines
c7a2d296bdidn't resetstat_time, thus uninitializedset_sharedwas assigned to test variable and test got value from a null pointer, which leaded to segfault.hugeshmctl01.c:279: PASS: shmctl in
func_rmid()failed as expected, shared memory appears to be removed tst_checkpoint.c:147: BROK: hugeshmctl01.c:152:tst_checkpoint_wait(0, 10000): ETIMEDOUT (110) mem.c:817: INFO: setnr_hugepagesto 0dmesg:
segfault at7f73f8c00000ip00000000004051e1sp00007ffef375f9a0error 6 in hugeshmctl01.master[404000+13000] addr2line -e hugeshmctl01 -f00000000004051e1stat_setup
hugeshmctl01.c:139 (discriminator 4)test = (
stat_time== FIRST) ?set_shmat():set_shared;/* do an assignement for fun */
*(int *)test = i; // error hereFixes c7a2d296b ("hugeshmctl: Use loop from the API")Reported-by Yang Xu <[email protected]>Suggested-by Yang Xu <[email protected]>Signed-off-by Petr Vorel <[email protected]>---
Hi Xu,I'm sorry for introducing a regression.
Thank you for a report and fixing the test.
I'd personally prefer to keep .tcnt =ARRAY_SIZE(tcases), but maybe others will prefer to keep loop intest_hugeshmctl()as it was before my change.
Quoted 3 lines
BTW it'd be nice to have something like
setup_i()andcleanup_i(), which would be called before/after each run of whole test, when run with -i n.
Sub tests have own clean and setup function. They only reused a System V shared memory segment. IMO, this is a question of coupling.
Quoted 12 lines
Kind regards,
Petr.../mem/hugetlb/hugeshmctl/hugeshmctl01.c | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-)testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c +0
-0
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c struct tcase { · line 79
Quoted 5 lines
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c +2
-0@@ -75,6 +75,20 @@ struct tcase {static void test_hugeshmctl (unsigned int i) { + stat_time =FIRST ; +
My description may confuse you. stat_time should not be reseted every time, it only needs to be reseted when next loop. This value will be +1
when call stat_cleanup.
struct tcase {
int cmd;
void (*func_test) (void);
void (*func_setup) (void);
} tcases[] = { {IPC_STAT, func_stat, stat_setup}, //stat_time = FIRST
{IPC_STAT, func_stat, stat_setup}, //stat_time = SECOND
As you do, the first and second case are same. it should be added into the "if == 0".
ps: I personally think old case is more cleaner. Let's hear from others.
Best Regards
Yang Xu
Quoted 36 lines
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c +12
-13+/* +* Create a shared memory segment with read and write +* permissions. Do this here instead of in setup() +* so that looping (-i) will work correctly. +*/ +if (i ==0 ) { + shm_id_1 =shmget (shmkey, shm_size, +SHM_HUGETLB |IPC_CREAT |IPC_EXCL |SHM_RW ); +if (shm_id_1 ==-1 ) +tst_brk (TBROK |TERRNO ,"shmget #main" ); + } +/* * if needed, set up any required conditions by * calling the appropriate setup function @@ -296,19 +310,6 @@ void setup(void) shm_size = hpage_size * hugepages /2 ;update_shm_size (&shm_size); shmkey =getipckey (); - -/* initialize stat_time */ - stat_time =FIRST ; - -/* -* Create a shared memory segment with read and write -* permissions. Do this here instead of in setup() -* so that looping (-i) will work correctly. -*/ - shm_id_1 =shmget (shmkey, shm_size, -SHM_HUGETLB |IPC_CREAT |IPC_EXCL |SHM_RW ); -if (shm_id_1 ==-1 ) -tst_brk (TBROK |TERRNO ,"shmget #main" ); }void cleanup (void )
PATCH 1/1 hugeshmctl01: Fix reset stat_time when looping with -i n
Quoted 12 lines · Yang Xu
Review
Quoted 4 lines
static void
test_hugeshmctl(unsigned int i)
{(quoted diff) +2
-0+ stat_time = FIRST; +My description may confuse you.
stat_timeshould not be reseted every time, it only needs to be reseted when next loop. This value will be +1
when callstat_cleanup.struct tcase { int cmd; void (*func_test) (void); void (*func_setup) (void); } tcases[] = {
Quoted 8 lines
{
IPC_STAT,func_stat,stat_setup}, //stat_time = FIRST
{IPC_STAT,func_stat,stat_setup}, //stat_time = SECONDAs you do, the first and second case are same. it should be added into the "if == 0".
ps: I personally think old case is more cleaner. Let's hear from others.
Hi Petr, Xu
For xu's comment, we can assign 'i' to stat_time and remove "stat_time++;" directly:
----------------------------------------
static void test_hugeshmctl(unsigned int i)
{
+ stat_time = i;
+
...
- stat_time++;
----------------------------------------
Thanks,
Xiao Yang
PATCH 1/1 hugeshmctl01: Fix reset stat_time when looping with -i n
In reply to Yang XuQuoted 57 lines · Yang Xu
Hi Petr
Quoted 5 lines
c7a2d296bdidn't resetstat_time, thus uninitializedset_sharedwas assigned to test variable and test got value from a null pointer, which leaded to segfault.hugeshmctl01.c:279: PASS: shmctl in
func_rmid()failed as expected,shared memory appears to be removed
Quoted 1 line
tst_checkpoint.c:147: BROK: hugeshmctl01.c:152: tst_checkpoint_wait(0,
10000): ETIMEDOUT (110)
Quoted 4 lines
mem.c:817: INFO: set
nr_hugepagesto 0dmesg:
segfault at7f73f8c00000ip00000000004051e1sp00007ffef375f9a0error 6in hugeshmctl01.master[404000+13000]
Quoted 23 lines
addr2line -e hugeshmctl01 -f
00000000004051e1stat_setup
hugeshmctl01.c:139 (discriminator 4)test = (
stat_time== FIRST) ?set_shmat():set_shared;/* do an assignement for fun */
*(int *)test = i; // error hereFixes c7a2d296b ("hugeshmctl: Use loop from the API")Reported-by Yang Xu <[email protected]>Suggested-by Yang Xu <[email protected]>Signed-off-by Petr Vorel <[email protected]>---
Hi Xu,I'm sorry for introducing a regression.
Thank you for a report and fixing the test.
I'd personally prefer to keep .tcnt =ARRAY_SIZE(tcases), but maybe others will prefer to keep loop intest_hugeshmctl()as it was before my change.Quoted 3 lines
BTW it'd be nice to have something like
setup_i()andcleanup_i(), which would be called before/after each run of whole test, when run with -i n.Sub tests have own clean and setup function. They only reused a System V shared memory segment. IMO, this is a question of coupling.
Review
Quoted 8 lines
Kind regards,
Petr.../mem/hugetlb/hugeshmctl/hugeshmctl01.c | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-)(quoted diff) +0
-0
b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.cQuoted 5 lines
index
e6cf8bf09..3b7e14363100644testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c +0
-0@@ -75,6 +75,20 @@ struct tcase {
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c struct tcase { · line 79
Quoted 4 lines
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c +2
-0static void test_hugeshmctl (unsigned int i) { + stat_time =FIRST ; +My description may confuse you.
stat_timeshould not be reseted every time, it only needs to be reseted when next loop. This value will be +1
when callstat_cleanup.
Xu Yang is correct here. If we do reset 'stat_time' to FIRST in each loop then it would be missing the SECOND part in the stat_setup(). We can fix the problem simply to move the 'stat_time' to if-condition as he suggested.
But to be honest, the looping workflow of hugeshmctl01 looks a little bit in disorder that may be the reason makes Petr missed the 'stat_time' value part, I appreciated if someone who can help to refactor the hugeshmctl01:).
Quoted 59 lines
struct tcase { int cmd; void (*func_test) (void); void (*func_setup) (void); } tcases[] = {{
IPC_STAT,func_stat,stat_setup}, //stat_time = FIRST
{IPC_STAT,func_stat,stat_setup}, //stat_time = SECONDAs you do, the first and second case are same. it should be added into the "if == 0".
ps: I personally think old case is more cleaner. Let's hear from others.
Best Regards
Yang Xutestcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c struct tcase {
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c +8
-0+/* +* Create a shared memory segment with read and write +* permissions. Do this here instead of in setup() +* so that looping (-i) will work correctly. +*/ +if (i ==0 ) { + shm_id_1 = shmget(shmkey, shm_size, + SHM_HUGETLB | IPC_CREAT | IPC_EXCL |
SHM_RW);Quoted 18 lines
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c +4
-6+if (shm_id_1 ==-1 ) +tst_brk (TBROK |TERRNO ,"shmget #main" ); + } +/* * if needed, set up any required conditions by * calling the appropriate setup function @@ -296,19 +310,6 @@ void setup(void) shm_size = hpage_size * hugepages /2 ;update_shm_size (&shm_size); shmkey =getipckey (); - -/* initialize stat_time */ - stat_time =FIRST ; - -/* -* Create a shared memory segment with read and write testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c void setup(void) · line 315
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c +0
-7-* permissions. Do this here instead of in setup() -* so that looping (-i) will work correctly. -*/ - shm_id_1 =shmget (shmkey, shm_size, -SHM_HUGETLB |IPC_CREAT |IPC_EXCL |SHM_RW ); -if (shm_id_1 ==-1 ) -tst_brk (TBROK |TERRNO ,"shmget #main" ); }void cleanup (void )--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20200306/4511323d/attachment-0001.htm>
PATCH 1/1 hugeshmctl01: Fix reset stat_time when looping with -i n
Hi
Quoted 81 lines
On Fri, Mar 6, 2020 at 9:53 AM Yang Xu <[email protected] <mailto:[email protected]>> wrote:
Hi Petr > c7a2d296b didn't reset stat_time, thus uninitialized set_shared was > assigned to test variable and test got value from a null pointer, > which leaded to segfault. > > hugeshmctl01.c:279: PASS: shmctl in func_rmid() failed as expected, shared memory appears to be removed > tst_checkpoint.c:147: BROK: hugeshmctl01.c:152: tst_checkpoint_wait(0, 10000): ETIMEDOUT (110) > mem.c:817: INFO: set nr_hugepages to 0 > > dmesg: > segfault at 7f73f8c00000 ip 00000000004051e1 sp 00007ffef375f9a0 error 6 in hugeshmctl01.master[404000+13000] > addr2line -e hugeshmctl01 -f? 00000000004051e1 > stat_setup > hugeshmctl01.c:139 (discriminator 4) > > test = (stat_time == FIRST) ? set_shmat() : set_shared; > > /* do an assignement for fun */ > *(int *)test = i; // error here > > Fixes: c7a2d296b ("hugeshmctl: Use loop from the API") > > Reported-by: Yang Xu <[email protected] <mailto:[email protected]>> > Suggested-by: Yang Xu <[email protected] <mailto:[email protected]>> > Signed-off-by: Petr Vorel <[email protected] <mailto:[email protected]>> > --- > Hi Xu, > > I'm sorry for introducing a regression. > Thank you for a report and fixing the test. > I'd personally prefer to keep .tcnt = ARRAY_SIZE(tcases), > but maybe others will prefer to keep loop in test_hugeshmctl() > as it was before my change. > > BTW it'd be nice to have something like setup_i() and cleanup_i(), > which would be called before/after each run of whole test, when run with > -i n. Sub tests have own clean and setup function. They only reused? a System V shared memory segment. IMO, this is a question of coupling. > > Kind regards, > Petr > >? ?.../mem/hugetlb/hugeshmctl/hugeshmctl01.c? ? ?| 27 ++++++++++--------- >? ?1 file changed, 14 insertions(+), 13 deletions(-) > > diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c > index e6cf8bf09..3b7e14363 100644 > --- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c > +++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c > @@ -75,6 +75,20 @@ struct tcase { > >? ?static void test_hugeshmctl(unsigned int i) >? ?{ > +? ? ?stat_time = FIRST; > + My description may confuse you.? stat_time should not be reseted every time, it only needs to be reseted when next loop. This value will be +1 ? when call stat_cleanup.Xu Yang is correct here. If we do reset '
stat_time' to FIRST in each loop then it would be missing?the SECOND part in thestat_setup(). We can fix the problem simply to move the 'stat_time' to if-condition as he suggested.
Quoted 4 lines
But to be honest, the looping workflow of hugeshmctl01?looks a little bit in disorder that may be the reason makes Petr missed the '
stat_time' value part, I?appreciated?if someone who can help to refactor the hugeshmctl01:).
I guess we can assign value for stat_time directly and remove stat_time++ in stat_cleanup as xiao suggested. Also, to remove the coupling of this four cases, every loop recreating a shared memeory is ok for me. So we can run single test case instead of 4 cases if we add a parameter in the future.
like:
-N Execute the Nth test
-R Random the test
./hugeshmctl01 -N 2
Best Regards
Yang Xu
Quoted 64 lines
struct tcase { ? ? ? ? ?int cmd; ? ? ? ? ?void (*func_test) (void); ? ? ? ? ?void (*func_setup) (void); } tcases[] = { ? ? ? ? ?{IPC_STAT, func_stat, stat_setup},? ?//stat_time = FIRST ? ? ? ? ?{IPC_STAT, func_stat, stat_setup},? ?//stat_time = SECOND As you do, the first and second case are same. it should be added into the "if == 0". ps: I personally think old case is more cleaner. Let's hear from others. Best Regards Yang Xu > +? ? ?/* > +? ? ? * Create a shared memory segment with read and write > +? ? ? * permissions. Do this here instead of in setup() > +? ? ? * so that looping (-i) will work correctly. > +? ? ? */ > +? ? ?if (i == 0) { > +? ? ? ? ? ? ?shm_id_1 = shmget(shmkey, shm_size, > +? ? ? ? ? ? ? ? ? ? ? ? ? ? ?SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW); > +? ? ? ? ? ? ?if (shm_id_1 == -1) > +? ? ? ? ? ? ? ? ? ? ?tst_brk(TBROK | TERRNO, "shmget #main"); > +? ? ?} > + >? ? ? ?/* >? ? ? ? * if needed, set up any required conditions by >? ? ? ? * calling the appropriate setup function > @@ -296,19 +310,6 @@ void setup(void) >? ? ? ?shm_size = hpage_size * hugepages / 2; >? ? ? ?update_shm_size(&shm_size); >? ? ? ?shmkey = getipckey(); > - > -? ? ?/* initialize stat_time */ > -? ? ?stat_time = FIRST; > - > -? ? ?/* > -? ? ? * Create a shared memory segment with read and write > -? ? ? * permissions.? Do this here instead of in setup() > -? ? ? * so that looping (-i) will work correctly. > -? ? ? */ > -? ? ?shm_id_1 = shmget(shmkey, shm_size, > -? ? ? ? ? ? ? ? ? ? ?SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW); > -? ? ?if (shm_id_1 == -1) > -? ? ? ? ? ? ?tst_brk(TBROK | TERRNO, "shmget #main"); >? ?} > >? ?void cleanup(void) > -- Mailing list info: https://lists.linux.it/listinfo/ltpSignature · 2 lines
Regards, Li Wang