Skip to contentSkip to conversation

selftests: mm: ksm: Fix incorrect evaluation of parameter

PATCH In review Ayush Jain 2 participants 3 messages Jul 28, 2023 – Aug 8, 2023

Subsystems (3)
lore
Share & tools
lore

Ayush Jain

author
#0 lore raw

PATCH v2 1/2 selftests: mm: ksm: Fix incorrect evaluation of parameter

A missing break in kms_tests leads to kselftest hang when the parameter -s is used.
In current code flow because of missing break in -s, -t parses args spilled from -s and as -t accepts only valid values as 0,1 so any arg in -s >1 or <0, gets in ksm_test failure

This went undetected since, before the addition of option -t, the next case -M would immediately break out of the switch statement but that is no longer the case

Add the missing break statement.

----Before----
./ksm_tests -H -s 100
Invalid merge type

----After----
./ksm_tests -H -s 100

Number of normal pages:    0
Number of huge pages:    50
Total size:    100 MiB
Total time:    0.401732682 s
Average speed:  248.922 MiB/s
Fixes 07115fcc15b4 ("selftests/mm: add new selftests for KSM")

---
v1 -> v2
collect Reviewed-by from David
Updated Fixes tag from commit 9e7cb94ca218 to 07115fcc15b4

 tools/testing/selftests/mm/ksm_tests.c | 1 +
 1 file changed, 1 insertion(+)
tools/testing/selftests/mm/ksm_tests.c +1 -0
index 435acebdc325..380b691d3eb9 100644
@@ -831,6 +831,7 @@ int main(int argc, char *argv[])
 				printf("Size must be greater than 0\n");
 				return KSFT_FAIL;
 			}
+			break;
 		case 't':
 			{
 				int tmp = atoi(optarg);
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 2/2 selftests: mm: add KSM_MERGE_TIME tests

add KSM_MERGE_TIME and KSM_MERGE_TIME_HUGE_PAGES tests with size of 100.

./run_vmtests.sh -t ksm
-----------------------------
running ./ksm_tests -H -s 100
-----------------------------

Number of normal pages:    0
Number of huge pages:    50
Total size:    100 MiB
Total time:    0.399844662 s
Average speed:  250.097 MiB/s

[PASS]
-----------------------------
running ./ksm_tests -P -s 100
-----------------------------

Total size:    100 MiB
Total time:    0.451931496 s
Average speed:  221.272 MiB/s

[PASS]

---
v1 -> v2
collect Reviewed-by from David

 tools/testing/selftests/mm/run_vmtests.sh | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/mm/run_vmtests.sh +4 -0
index 3f26f6e15b2a..ca3738e042c2 100755
@@ -262,6 +262,10 @@ CATEGORY="madv_populate" run_test ./madv_populate
 
 CATEGORY="memfd_secret" run_test ./memfd_secret
 
+# KSM KSM_MERGE_TIME_HUGE_PAGES test with size of 100
+CATEGORY="ksm" run_test ./ksm_tests -H -s 100
+# KSM KSM_MERGE_TIME test with size of 100
+CATEGORY="ksm" run_test ./ksm_tests -P -s 100
 # KSM MADV_MERGEABLE test with 10 identical pages
 CATEGORY="ksm" run_test ./ksm_tests -M -p 10
 # KSM unmerge test
Signature · 1 line
2.34.1
Acked-by on v2 1/2
#2 lore raw
In reply to Ayush Jain
Quoted 41 lines · Ayush Jain

A missing break in kms_tests leads to kselftest hang when the parameter -s is used.
In current code flow because of missing break in -s, -t parses args spilled from -s and as -t accepts only valid values as 0,1 so any arg in -s >1 or <0, gets in ksm_test failure

This went undetected since, before the addition of option -t, the next case -M would immediately break out of the switch statement but that is no longer the case

Add the missing break statement.

----Before----
./ksm_tests -H -s 100
Invalid merge type

----After----
./ksm_tests -H -s 100

Number of normal pages:    0
Number of huge pages:    50
Total size:    100 MiB
Total time:    0.401732682 s
Average speed:  248.922 MiB/s
Fixes 07115fcc15b4 ("selftests/mm: add new selftests for KSM")

---
v1 -> v2
collect Reviewed-by from David
Updated Fixes tag from commit 9e7cb94ca218 to 07115fcc15b4

 tools/testing/selftests/mm/ksm_tests.c | 1 +
 1 file changed, 1 insertion(+)
tools/testing/selftests/mm/ksm_tests.c +0 -0
index 435acebdc325..380b691d3eb9 100644

tools/testing/selftests/mm/ksm_tests.c int main(int argc, char *argv[]) · line 837

Quoted 7 lines
tools/testing/selftests/mm/ksm_tests.c +1 -0
@@ -831,6 +831,7 @@ int main(int argc, char *argv[])
 				printf("Size must be greater than 0\n");
 				return KSFT_FAIL;
 			}
+			break;
 		case 't':
 			{
 				int tmp = atoi(optarg);