Skip to contentSkip to conversation

selftests/mm/cow: Modify the incorrect checking parameters

PATCH Superseded Hao Ge 3 participants 6 messages Jan 13, 2025

Subsystems (3)
lore
Share & tools
lore

Hao Ge

author
#0 lore raw

PATCH 1/1 selftests/mm/cow: Modify the incorrect checking parameters

From: Hao Ge <[email protected]>

In the run_with_memfd_hugetlb function, some error handle have passed incorrect parameters.
It should be "smem", but it was mistakenly written as "mem".

Let's fix it.

Fixes baa489fabd01 ("selftests/vm: rename selftests/vm to selftests/mm")
---
 tools/testing/selftests/mm/cow.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/mm/cow.c +2 -2
index 32c6ccc2a6be..7a89680d1566 100644
@@ -1684,7 +1684,7 @@ static void run_with_memfd_hugetlb(non_anon_test_fn fn, const char *desc,
 		goto close;
 	}
 	smem = mmap(NULL, hugetlbsize, PROT_READ, MAP_SHARED, fd, 0);
-	if (mem == MAP_FAILED) {
+	if (smem == MAP_FAILED) {
 		ksft_test_result_fail("mmap() failed\n");
 		goto munmap;
 	}
@@ -1696,7 +1696,7 @@ static void run_with_memfd_hugetlb(non_anon_test_fn fn, const char *desc,
 	fn(mem, smem, hugetlbsize);
 munmap:
 	munmap(mem, hugetlbsize);
-	if (mem != MAP_FAILED)
+	if (smem != MAP_FAILED)
 		munmap(smem, hugetlbsize);
 close:
 	close(fd);
Signature · 1 line
2.25.1
#1 lore raw

Hello Hao,

Quoted 5 lines · Hao Ge

From: Hao Ge <[email protected]>

In the run_with_memfd_hugetlb function, some error handle have passed incorrect parameters.
It should be "smem", but it was mistakenly written as "mem".

I guess there are couple of more instances where the returned address 'smem' is not getting tested for MAP_FAILED. Hence the commit message here needs to be bit more generic rather than run_with_memfd_hugetlb() specific.

tools/testing/selftests/mm/cow.c +2 -2
@@ -1482,7 +1482,7 @@ static void run_with_zeropage(non_anon_test_fn fn, const char *desc)
        }
 
        smem = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0);
-       if (mem == MAP_FAILED) {
+       if (smem == MAP_FAILED) {
                ksft_test_result_fail("mmap() failed\n");
                goto munmap;
        }
@@ -1583,7 +1583,7 @@ static void run_with_memfd(non_anon_test_fn fn, const char *desc)
                goto close;
        }
        smem = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0);
-       if (mem == MAP_FAILED) {
+       if (smem == MAP_FAILED) {
                ksft_test_result_fail("mmap() failed\n");
                goto munmap;
        }
Quoted 4 lines

Let's fix it.

Fixes baa489fabd01 ("selftests/vm: rename selftests/vm to selftests/mm")

This commit just renamed the directory from vm/ to mm/ directory. The following commit introduced the problem instead. Please update the Fixes: tag as required.

f8664f3c4a08f799 ("selftests/vm: cow: basic COW tests for non-anonymous pages")

Quoted 27 lines
---
 tools/testing/selftests/mm/cow.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/mm/cow.c +2 -2
index 32c6ccc2a6be..7a89680d1566 100644
@@ -1684,7 +1684,7 @@ static void run_with_memfd_hugetlb(non_anon_test_fn fn, const char *desc,
 		goto close;
 	}
 	smem = mmap(NULL, hugetlbsize, PROT_READ, MAP_SHARED, fd, 0);
-	if (mem == MAP_FAILED) {
+	if (smem == MAP_FAILED) {
 		ksft_test_result_fail("mmap() failed\n");
 		goto munmap;
 	}
@@ -1696,7 +1696,7 @@ static void run_with_memfd_hugetlb(non_anon_test_fn fn, const char *desc,
 	fn(mem, smem, hugetlbsize);
 munmap:
 	munmap(mem, hugetlbsize);
-	if (mem != MAP_FAILED)
+	if (smem != MAP_FAILED)
 		munmap(smem, hugetlbsize);
 close:
 	close(fd);
author
#2 lore raw

Hi Anshuman

Thanks for your revirew.

Quoted 5 lines · Anshuman Khandual

Hello Hao,

Quoted 2 lines · Hao Ge

From: Hao Ge <[email protected]>

Quoted 7 lines
Quoted 3 lines

In the run_with_memfd_hugetlb function, some error handle have passed incorrect parameters.
It should be "smem", but it was mistakenly written as "mem".

I guess there are couple of more instances where the returned address 'smem' is not getting tested for MAP_FAILED. Hence the commit message here needs to be bit more generic rather than run_with_memfd_hugetlb() specific.

Thank you for bringing it to my attention. Upon reviewing, I confirm that you are correct.

Quoted 23 lines
tools/testing/selftests/mm/cow.c +2 -2
@@ -1482,7 +1482,7 @@ static void run_with_zeropage(non_anon_test_fn fn, const char *desc)
         }
 
         smem = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0);
-       if (mem == MAP_FAILED) {
+       if (smem == MAP_FAILED) {
                 ksft_test_result_fail("mmap() failed\n");
                 goto munmap;
         }
@@ -1583,7 +1583,7 @@ static void run_with_memfd(non_anon_test_fn fn, const char *desc)
                 goto close;
         }
         smem = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0);
-       if (mem == MAP_FAILED) {
+       if (smem == MAP_FAILED) {
                 ksft_test_result_fail("mmap() failed\n");
                 goto munmap;
         }
Quoted 7 lines
Quoted 3 lines

Let's fix it.

Fixes baa489fabd01 ("selftests/vm: rename selftests/vm to selftests/mm")

This commit just renamed the directory from vm/ to mm/ directory. The following commit introduced the problem instead. Please update the Fixes: tag as required.

f8664f3c4a08f799 ("selftests/vm: cow: basic COW tests for non-anonymous pages")

Yes, I accidentally copied the wrong information. I will resend a v2  to address these issues. Thank you very much

Thanks

Best Regards

Hao

Quoted 27 lines
Quoted 27 lines
---
  tools/testing/selftests/mm/cow.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/mm/cow.c +2 -2
index 32c6ccc2a6be..7a89680d1566 100644
@@ -1684,7 +1684,7 @@ static void run_with_memfd_hugetlb(non_anon_test_fn fn, const char *desc,
  		goto close;
  	}
  	smem = mmap(NULL, hugetlbsize, PROT_READ, MAP_SHARED, fd, 0);
-	if (mem == MAP_FAILED) {
+	if (smem == MAP_FAILED) {
  		ksft_test_result_fail("mmap() failed\n");
  		goto munmap;
  	}
@@ -1696,7 +1696,7 @@ static void run_with_memfd_hugetlb(non_anon_test_fn fn, const char *desc,
  	fn(mem, smem, hugetlbsize);
  munmap:
  	munmap(mem, hugetlbsize);
-	if (mem != MAP_FAILED)
+	if (smem != MAP_FAILED)
  		munmap(smem, hugetlbsize);
  close:
  	close(fd);
author
#3 lore raw

PATCH v2 1/1 selftests/mm/cow: Modify the incorrect checking parameters

From: Hao Ge <[email protected]>

In the cow.c,some error handle have passed incorrect parameters. It should be "smem", but it was mistakenly written as "mem".

Let's fix it.

Fixes f8664f3c4a08 ("selftests/vm: cow: basic COW tests for non-anonymous pages")

---
v2: Anshuman pointed out that the error is not limited to the run_with_memfd_hugetlb function;
there are other places where it occurs as well.
Therefore, let's fix it all together.
Similarly, Update the Fix tag to be accurate.

---
 tools/testing/selftests/mm/cow.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/testing/selftests/mm/cow.c +5 -5
index 32c6ccc2a6be..c52c93996ba1 100644
@@ -1482,7 +1482,7 @@ static void run_with_zeropage(non_anon_test_fn fn, const char *desc)
 	}
 
 	smem = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0);
-	if (mem == MAP_FAILED) {
+	if (smem == MAP_FAILED) {
 		ksft_test_result_fail("mmap() failed\n");
 		goto munmap;
 	}
@@ -1583,7 +1583,7 @@ static void run_with_memfd(non_anon_test_fn fn, const char *desc)
 		goto close;
 	}
 	smem = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0);
-	if (mem == MAP_FAILED) {
+	if (smem == MAP_FAILED) {
 		ksft_test_result_fail("mmap() failed\n");
 		goto munmap;
 	}
@@ -1634,7 +1634,7 @@ static void run_with_tmpfile(non_anon_test_fn fn, const char *desc)
 		goto close;
 	}
 	smem = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0);
-	if (mem == MAP_FAILED) {
+	if (smem == MAP_FAILED) {
 		ksft_test_result_fail("mmap() failed\n");
 		goto munmap;
 	}
@@ -1684,7 +1684,7 @@ static void run_with_memfd_hugetlb(non_anon_test_fn fn, const char *desc,
 		goto close;
 	}
 	smem = mmap(NULL, hugetlbsize, PROT_READ, MAP_SHARED, fd, 0);
-	if (mem == MAP_FAILED) {
+	if (smem == MAP_FAILED) {
 		ksft_test_result_fail("mmap() failed\n");
 		goto munmap;
 	}
@@ -1696,7 +1696,7 @@ static void run_with_memfd_hugetlb(non_anon_test_fn fn, const char *desc,
 	fn(mem, smem, hugetlbsize);
 munmap:
 	munmap(mem, hugetlbsize);
-	if (mem != MAP_FAILED)
+	if (smem != MAP_FAILED)
 		munmap(smem, hugetlbsize);
 close:
 	close(fd);
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#4 lore raw

A small nit.

Please always send a new patch version separately as a new email thread instead - not part of an ongoing discussion.

Quoted 8 lines · Hao Ge

From: Hao Ge <[email protected]>

In the cow.c,some error handle have passed incorrect parameters. It should be "smem", but it was mistakenly written as "mem".

Let's fix it.

Quoted 7 lines
Fixes f8664f3c4a08 ("selftests/vm: cow: basic COW tests for non-anonymous pages")

---
v2: Anshuman pointed out that the error is not limited to the run_with_memfd_hugetlb function;
there are other places where it occurs as well.
Therefore, let's fix it all together.
Similarly, Update the Fix tag to be accurate.

LGTM

Quoted 53 lines
---
 tools/testing/selftests/mm/cow.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/testing/selftests/mm/cow.c +5 -5
index 32c6ccc2a6be..c52c93996ba1 100644
@@ -1482,7 +1482,7 @@ static void run_with_zeropage(non_anon_test_fn fn, const char *desc)
 	}
 
 	smem = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0);
-	if (mem == MAP_FAILED) {
+	if (smem == MAP_FAILED) {
 		ksft_test_result_fail("mmap() failed\n");
 		goto munmap;
 	}
@@ -1583,7 +1583,7 @@ static void run_with_memfd(non_anon_test_fn fn, const char *desc)
 		goto close;
 	}
 	smem = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0);
-	if (mem == MAP_FAILED) {
+	if (smem == MAP_FAILED) {
 		ksft_test_result_fail("mmap() failed\n");
 		goto munmap;
 	}
@@ -1634,7 +1634,7 @@ static void run_with_tmpfile(non_anon_test_fn fn, const char *desc)
 		goto close;
 	}
 	smem = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0);
-	if (mem == MAP_FAILED) {
+	if (smem == MAP_FAILED) {
 		ksft_test_result_fail("mmap() failed\n");
 		goto munmap;
 	}
@@ -1684,7 +1684,7 @@ static void run_with_memfd_hugetlb(non_anon_test_fn fn, const char *desc,
 		goto close;
 	}
 	smem = mmap(NULL, hugetlbsize, PROT_READ, MAP_SHARED, fd, 0);
-	if (mem == MAP_FAILED) {
+	if (smem == MAP_FAILED) {
 		ksft_test_result_fail("mmap() failed\n");
 		goto munmap;
 	}
@@ -1696,7 +1696,7 @@ static void run_with_memfd_hugetlb(non_anon_test_fn fn, const char *desc,
 	fn(mem, smem, hugetlbsize);
 munmap:
 	munmap(mem, hugetlbsize);
-	if (mem != MAP_FAILED)
+	if (smem != MAP_FAILED)
 		munmap(smem, hugetlbsize);
 close:
 	close(fd);
Reviewed-by on v2 1/1
#5 lore raw
In reply to Hao Ge
Quoted 11 lines · Hao Ge

From: Hao Ge <[email protected]>

In the cow.c,some error handle have passed incorrect parameters. It should be "smem", but it was mistakenly written as "mem".

Let's fix it.

Fixes f8664f3c4a08 ("selftests/vm: cow: basic COW tests for non-anonymous pages")

---

You should also CC the person whose code you are changing, in this case, David Hildenbrand.