Skip to contentSkip to conversation

Hugetlb:Migrating the libhugetlbfs tests

PATCH Superseded Tarun Sahu 2 participants 25 messages Dec 1, 2022 – Dec 19, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Tarun Sahu

author
#0 lore raw

cover Hugetlb:Migrating the libhugetlbfs tests

-- resending as a fresh series, [3] was sent mistakenly in reply to [2].

Hi,
This patch series is in continuation to part [1] and part [2] This series include 8 more tests taken from libhugetlbfs.

Background:
Libhugetlbfs is not being maintained actively, and some distro is dropping support for it. There are some tests that are good for testing hugetlb functionality in kernel. These patches include tests from libhugetlbfs.

ref:
1. https://lore.kernel.org/all/[email protected]/
2. https://lore.kernel.org/all/[email protected]/
3. https://lore.kernel.org/all/[email protected]/
Tarun Sahu (8):
Hugetlb: Migrating libhugetlbfs fork-cow
Hugetlb: Migrating libhugetlbfs huge_at_4GB_normal_below
Hugetlb: Migrating libhugetlbfs huge_below_4GB_normal_above
Hugetlb: Migrating libhugetlbfs icache-hygiene
Hugetlb: Migrating libhugetlbfs madvise_reserve
Hugetlb: Migrating libhugetlbfs map_high_truncate_2
Hugetlb: Migrating libhugetlbfs misalign
Hugetlb: Migrating libhugetlbfs misaligned_offset

 runtest/hugetlb                               |   9 +
 testcases/kernel/mem/.gitignore               |   8 +
 .../kernel/mem/hugetlb/hugefork/Makefile      |  10 +
 .../kernel/mem/hugetlb/hugefork/hugefork01.c  | 108 ++++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap13.c  | 122 +++++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap14.c  | 156 ++++++++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap15.c  | 239 ++++++++++++++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap16.c  |  83 ++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap17.c  | 103 ++++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap18.c  | 153 +++++++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap19.c  | 147 +++++++++++
 11 files changed, 1138 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugefork/Makefile
 create mode 100644 testcases/kernel/mem/hugetlb/hugefork/hugefork01.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap16.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap17.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap18.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap19.c
Signature · 5 lines
2.31.1


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

PATCH 1/8 Hugetlb: Migrating libhugetlbfs fork-cow

Migrating the libhugetlbfs/testcases/fork-cow.c test

Test Description: This checks copy-on-write semantics, specifically the semantics of a MAP_PRIVATE mapping across a fork(). Some versions of the powerpc kernel had a bug in huge_ptep_set_wrprotect() which would fail to flush the hash table after setting the write protect bit in the parent's page tables, thus allowing the parent to pollute the child's mapping.

---
 runtest/hugetlb                               |   2 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugefork/Makefile      |  10 ++
 .../kernel/mem/hugetlb/hugefork/hugefork01.c  | 108 ++++++++++++++++++
 4 files changed, 121 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugefork/Makefile
 create mode 100644 testcases/kernel/mem/hugetlb/hugefork/hugefork01.c
runtest/hugetlb +2 -0
index ec1fc2515..4c16e1e7c 100644
@@ -1,6 +1,8 @@
 hugefallocate01 hugefallocate01
 hugefallocate02 hugefallocate02
 
+hugefork01 hugefork01
+
 hugemmap01 hugemmap01
 hugemmap02 hugemmap02
 hugemmap04 hugemmap04
testcases/kernel/mem/.gitignore +1 -0
index c0906f3d3..adea760c7 100644
@@ -1,6 +1,7 @@
 /cpuset/cpuset01
 /hugetlb/hugefallocate/hugefallocate01
 /hugetlb/hugefallocate/hugefallocate02
+/hugetlb/hugefork/hugefork01
 /hugetlb/hugemmap/hugemmap01
 /hugetlb/hugemmap/hugemmap02
 /hugetlb/hugemmap/hugemmap04
testcases/kernel/mem/hugetlb/hugefork/Makefile new file +10 -0
new file mode 100644
index 000000000..77ebb0aef
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
+# Ngie Cooper, July 2009
+
+top_srcdir		?= ../../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(abs_srcdir)/../Makefile.inc
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
+
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +108 -0

108 lines not on this page · raw message

Signature · 5 lines
2.31.1


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

Re: [LTP] [PATCH 1/8] Hugetlb: Migrating libhugetlbfs fork-cow

Hello,

runtest/hugetlb

Quoted 19 lines · Tarun Sahu

Migrating the libhugetlbfs/testcases/fork-cow.c test

Test Description: This checks copy-on-write semantics, specifically the semantics of a MAP_PRIVATE mapping across a fork(). Some versions of the powerpc kernel had a bug in huge_ptep_set_wrprotect() which would fail to flush the hash table after setting the write protect bit in the parent's page tables, thus allowing the parent to pollute the child's mapping.

---
 runtest/hugetlb                               |   2 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugefork/Makefile      |  10 ++
 .../kernel/mem/hugetlb/hugefork/hugefork01.c  | 108 ++++++++++++++++++
 4 files changed, 121 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugefork/Makefile
 create mode 100644 testcases/kernel/mem/hugetlb/hugefork/hugefork01.c
runtest/hugetlb +0 -0

n> index ec1fc2515..4c16e1e7c 100644

Quoted 62 lines
runtest/hugetlb +2 -0
@@ -1,6 +1,8 @@
 hugefallocate01 hugefallocate01
 hugefallocate02 hugefallocate02
 
+hugefork01 hugefork01
+
 hugemmap01 hugemmap01
 hugemmap02 hugemmap02
 hugemmap04 hugemmap04
testcases/kernel/mem/.gitignore +1 -0
index c0906f3d3..adea760c7 100644
@@ -1,6 +1,7 @@
 /cpuset/cpuset01
 /hugetlb/hugefallocate/hugefallocate01
 /hugetlb/hugefallocate/hugefallocate02
+/hugetlb/hugefork/hugefork01
 /hugetlb/hugemmap/hugemmap01
 /hugetlb/hugemmap/hugemmap02
 /hugetlb/hugemmap/hugemmap04
testcases/kernel/mem/hugetlb/hugefork/Makefile new file +10 -0
new file mode 100644
index 000000000..77ebb0aef
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
+# Ngie Cooper, July 2009
+
+top_srcdir		?= ../../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(abs_srcdir)/../Makefile.inc
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
+
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +17 -0
new file mode 100644
index 000000000..b59c461e3
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2008 David Gibson, IBM Corporation.
+ * Author: David Gibson
+ */
+
+/*\
+ * [Description]
+ *
+ * This checks copy-on-write semantics, specifically the semantics of a
+ * MAP_PRIVATE mapping across a fork().  Some versions of the powerpc
+ * kernel had a bug in huge_ptep_set_wrprotect() which would fail to
+ * flush the hash table after setting the write protect bit in the parent's
+ * page tables, thus allowing the parent to pollute the child's mapping.
+ *
+ */
+

testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 27

Quoted 10 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +10 -0
+#include <sys/wait.h>
+#include <sys/mman.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+#define RANDOM_CONSTANT		0x1234ABCD
+#define OTHER_CONSTANT		0xfeef5678

It seems their are actually 3 constants as "random" is inverted. I'd prefer it if they had names like C1, C2, C3 with no connotations.

Quoted 28 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +28 -0
+#define MNTPOINT "hugetlbfs/"
+static int  fd = -1;
+static long hpage_size;
+
+static void run_test(void)
+{
+	int status;
+	volatile unsigned int *p;
+	volatile unsigned int *child_readback;
+	int parent_readback;
+	pid_t pid;
+
+	child_readback = SAFE_MMAP(NULL, getpagesize(), PROT_READ|PROT_WRITE,
+			MAP_SHARED|MAP_ANONYMOUS, -1, 0);
+	*child_readback = 0;
+
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+	*p = RANDOM_CONSTANT;
+
+	pid = SAFE_FORK();
+	if (pid != 0) {
+		*p = ~RANDOM_CONSTANT;
+		TST_CHECKPOINT_WAKE_AND_WAIT(0);
+		parent_readback = *p;
+		TST_CHECKPOINT_WAKE(0);
+	} else {
+		TST_CHECKPOINT_WAIT(0);
+		*child_readback = *p;

testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 65

Quoted 10 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +10 -0
+		*p = OTHER_CONSTANT;
+		TST_CHECKPOINT_WAKE_AND_WAIT(0);
+		exit(0);
+	}
+
+	SAFE_WAITPID(pid, &status, 0);
+	if (WEXITSTATUS(status) != 0) {
+		tst_res(TFAIL, "Child failed: %d", WEXITSTATUS(status));
+		goto cleanup;
+	}

This can be replaced with tst_reap_children();

testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 72

Quoted 7 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +7 -0
+
+	tst_res(TINFO, "child_readback = 0x%x, parent_readback = 0x%x",
+			*child_readback, parent_readback);
+
+	if (*child_readback != RANDOM_CONSTANT) {
+		tst_res(TFAIL, "Child read back 0x%x instead of 0x%x",
+		     *child_readback, RANDOM_CONSTANT);

I think this could be checked at the end of the child and the extra mmap for child_readback removed. The LTP lib already creats some shared memory with children to propagate results.

Assuming that mmap is not needed for the original bug reproducer.

testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 73

Quoted 1 line
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +1 -0
+		goto cleanup;

I don't think this is necessary.

testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 75

Quoted 2 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +2 -0
+	}
+	if (parent_readback != ~RANDOM_CONSTANT) {

These comparisons could be replaced with TST_EXP_EQ_LU or TST_EXP_EXPR.

Signature · 5 lines
Thank you,
Richard.

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

Re: [LTP] [PATCH 1/8] Hugetlb: Migrating libhugetlbfs fork-cow

Hi,
Thanks for reviewing it.

Quoted 4 lines · Richard Palethorpe

Hello,

Tarun Sahu <[email protected]> writes:

Quoted 15 lines

testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 27

Quoted 11 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +11 -0
+
+#include <sys/wait.h>
+#include <sys/mman.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+#define RANDOM_CONSTANT		0x1234ABCD
+#define OTHER_CONSTANT		0xfeef5678

It seems their are actually 3 constants as "random" is inverted. I'd prefer it if they had names like C1, C2, C3 with no connotations.

Yeah, Will be more cleaner, Will update it.

--skip

Quoted 8 lines

testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 65

Quoted 6 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +6 -0
+
+	SAFE_WAITPID(pid, &status, 0);
+	if (WEXITSTATUS(status) != 0) {
+		tst_res(TFAIL, "Child failed: %d", WEXITSTATUS(status));
+		goto cleanup;
+	}

This can be replaced with tst_reap_children();

Ok. I will update it in v2.

Quoted 13 lines

testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 72

Quoted 8 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +7 -0
+
+	tst_res(TINFO, "child_readback = 0x%x, parent_readback = 0x%x",
+			*child_readback, parent_readback);
+
+	if (*child_readback != RANDOM_CONSTANT) {
+		tst_res(TFAIL, "Child read back 0x%x instead of 0x%x",
+		     *child_readback, RANDOM_CONSTANT);

I think this could be checked at the end of the child and the extra mmap for child_readback removed. The LTP lib already creats some shared memory with children to propagate results.

Quoted 2 lines

Assuming that mmap is not needed for the original bug reproducer.

Looking at the fix: 86df86424939d316 ("Correct hash flushing from huge_ptep_set_wrprotect()") seems it can be done. I will look at it and will update it in v2.

Quoted 9 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		goto cleanup;

I don't think this is necessary.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	}
+	if (parent_readback != ~RANDOM_CONSTANT) {

These comparisons could be replaced with TST_EXP_EQ_LU or TST_EXP_EXPR.

Ok. Will update it.

Quoted 6 lines
Signature · 5 lines
Thank you,
Richard.

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

Re: [LTP] [PATCH 1/8] Hugetlb: Migrating libhugetlbfs fork-cow

Hello,

Quoted 47 lines · Tarun Sahu

Hi,
Thanks for reviewing it.

Quoted 4 lines · Richard Palethorpe

Hello,

Tarun Sahu <[email protected]> writes:

Quoted 15 lines

testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 27

Quoted 11 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +11 -0
+
+#include <sys/wait.h>
+#include <sys/mman.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+#define RANDOM_CONSTANT		0x1234ABCD
+#define OTHER_CONSTANT		0xfeef5678

It seems their are actually 3 constants as "random" is inverted. I'd prefer it if they had names like C1, C2, C3 with no connotations.

Yeah, Will be more cleaner, Will update it.

--skip

Quoted 8 lines

testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 65

Quoted 6 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +6 -0
+
+	SAFE_WAITPID(pid, &status, 0);
+	if (WEXITSTATUS(status) != 0) {
+		tst_res(TFAIL, "Child failed: %d", WEXITSTATUS(status));
+		goto cleanup;
+	}

This can be replaced with tst_reap_children();

Ok. I will update it in v2.

Quoted 13 lines

testcases/kernel/mem/hugetlb/hugefork/hugefork01.c line 72

Quoted 8 lines
testcases/kernel/mem/hugetlb/hugefork/hugefork01.c new file +7 -0
+
+	tst_res(TINFO, "child_readback = 0x%x, parent_readback = 0x%x",
+			*child_readback, parent_readback);
+
+	if (*child_readback != RANDOM_CONSTANT) {
+		tst_res(TFAIL, "Child read back 0x%x instead of 0x%x",
+		     *child_readback, RANDOM_CONSTANT);

I think this could be checked at the end of the child and the extra mmap for child_readback removed. The LTP lib already creats some shared memory with children to propagate results.

Quoted 4 lines
Quoted 2 lines

Assuming that mmap is not needed for the original bug reproducer.

Looking at the fix: 86df86424939d316 ("Correct hash flushing from huge_ptep_set_wrprotect()") seems it can be done. I will look at it and will update it in v2.

Thanks and as you have the git commit hash, please add this to the tst_test.tags.

Quoted 16 lines
Quoted 9 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		goto cleanup;

I don't think this is necessary.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	}
+	if (parent_readback != ~RANDOM_CONSTANT) {

These comparisons could be replaced with TST_EXP_EQ_LU or TST_EXP_EXPR.

Ok. Will update it.

Quoted 6 lines
Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Thank you,
Richard.

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

PATCH 2/8 Hugetlb: Migrating libhugetlbfs huge_at_4GB_normal_below

In reply to Tarun Sahu

Migrating the libhugetlbfs/testcases/huge_at_4GB_normal_below.c test

Test Description: Designed to pick up a bug on ppc64 where touches_hugepage_high_range() falsely reported true for ranges reaching below 4GB

---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap13.c  | 122 ++++++++++++++++++
 3 files changed, 124 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c
runtest/hugetlb +1 -0
index 4c16e1e7c..2029ee4b3 100644
@@ -14,6 +14,7 @@ hugemmap09 hugemmap09
 hugemmap10 hugemmap10
 hugemmap11 hugemmap11
 hugemmap12 hugemmap12
+hugemmap13 hugemmap13
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
index adea760c7..5955ed613 100644
@@ -13,6 +13,7 @@
 /hugetlb/hugemmap/hugemmap10
 /hugetlb/hugemmap/hugemmap11
 /hugetlb/hugemmap/hugemmap12
+/hugetlb/hugemmap/hugemmap13
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c new file +122 -0

122 lines not on this page · raw message

Signature · 5 lines
2.31.1


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

Re: [LTP] [PATCH 2/8] Hugetlb: Migrating libhugetlbfs huge_at_4GB_normal_below

Hello,

Quoted 45 lines · Tarun Sahu

Migrating the libhugetlbfs/testcases/huge_at_4GB_normal_below.c test

Test Description: Designed to pick up a bug on ppc64 where touches_hugepage_high_range() falsely reported true for ranges reaching below 4GB

---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap13.c  | 122 ++++++++++++++++++
 3 files changed, 124 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c
runtest/hugetlb +1 -0
index 4c16e1e7c..2029ee4b3 100644
@@ -14,6 +14,7 @@ hugemmap09 hugemmap09
 hugemmap10 hugemmap10
 hugemmap11 hugemmap11
 hugemmap12 hugemmap12
+hugemmap13 hugemmap13
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
index adea760c7..5955ed613 100644
@@ -13,6 +13,7 @@
 /hugetlb/hugemmap/hugemmap10
 /hugetlb/hugemmap/hugemmap11
 /hugetlb/hugemmap/hugemmap12
+/hugetlb/hugemmap/hugemmap13
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c new file +1 -0
new file mode 100644
index 000000000..84a84e074
@@ -0,0 +1,122 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later

testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c line 11

Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c new file +10 -0
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ * Author: David Gibson & Adam Litke
+ */
+
+/*\
+ * [Description]
+ *
+ * Designed to pick up a bug on ppc64 where touches_hugepage_high_range()
+ * falsely reported true for ranges reaching below 4GB

Hhmm seems like the macro no longer exists. This isn't a great test description.

This appers to be the fix for the bug mentioned:
https://lkml.org/lkml/2005/11/23/540

Maybe we could add to this that the test creates a hugepage just above the 32bit memory space and a normal page below it. That on old kernels this would trigger a bug caused by an off-by-one error.

Signature · 5 lines
Thank you,
Richard.

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

Re: [LTP] [PATCH 2/8] Hugetlb: Migrating libhugetlbfs huge_at_4GB_normal_below

Hi Richard,
Thanks for reviewing it.

Quoted 63 lines · Richard Palethorpe

Hello,

Quoted 45 lines · Tarun Sahu

Migrating the libhugetlbfs/testcases/huge_at_4GB_normal_below.c test

Test Description: Designed to pick up a bug on ppc64 where touches_hugepage_high_range() falsely reported true for ranges reaching below 4GB

---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap13.c  | 122 ++++++++++++++++++
 3 files changed, 124 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c
runtest/hugetlb +1 -0
index 4c16e1e7c..2029ee4b3 100644
@@ -14,6 +14,7 @@ hugemmap09 hugemmap09
 hugemmap10 hugemmap10
 hugemmap11 hugemmap11
 hugemmap12 hugemmap12
+hugemmap13 hugemmap13
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
index adea760c7..5955ed613 100644
@@ -13,6 +13,7 @@
 /hugetlb/hugemmap/hugemmap10
 /hugetlb/hugemmap/hugemmap11
 /hugetlb/hugemmap/hugemmap12
+/hugetlb/hugemmap/hugemmap13
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c new file +1 -0
new file mode 100644
index 000000000..84a84e074
@@ -0,0 +1,122 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later

testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c line 11

Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c new file +10 -0
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ * Author: David Gibson & Adam Litke
+ */
+
+/*\
+ * [Description]
+ *
+ * Designed to pick up a bug on ppc64 where touches_hugepage_high_range()
+ * falsely reported true for ranges reaching below 4GB

Hhmm seems like the macro no longer exists. This isn't a great test description.

Quoted 7 lines

This appers to be the fix for the bug mentioned:
https://lkml.org/lkml/2005/11/23/540

Maybe we could add to this that the test creates a hugepage just above the 32bit memory space and a normal page below it. That on old kernels this would trigger a bug caused by an off-by-one error.

Yeah Agree, Will update it in v2.

Quoted 6 lines
Signature · 5 lines
Thank you,
Richard.

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

PATCH 3/8 Hugetlb: Migrating libhugetlbfs huge_below_4GB_normal_above

In reply to Tarun Sahu

Migrating the libhugetlbfs/testcases/huge_below_4GB_normal_above.c test

Test Description: Designed to pick up a bug on ppc64 where touches_hugepage_low_range() could give false positives because of the peculiar (undefined) behaviour of << for large shifts

---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap14.c  | 156 ++++++++++++++++++
 3 files changed, 158 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c
runtest/hugetlb +1 -0
index 2029ee4b3..796ebe7fa 100644
@@ -15,6 +15,7 @@ hugemmap10 hugemmap10
 hugemmap11 hugemmap11
 hugemmap12 hugemmap12
 hugemmap13 hugemmap13
+hugemmap14 hugemmap14
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
index 5955ed613..3106579ce 100644
@@ -14,6 +14,7 @@
 /hugetlb/hugemmap/hugemmap11
 /hugetlb/hugemmap/hugemmap12
 /hugetlb/hugemmap/hugemmap13
+/hugetlb/hugemmap/hugemmap14
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c new file +156 -0

156 lines not on this page · raw message

Signature · 5 lines
2.31.1


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

Re: [LTP] [PATCH 3/8] Hugetlb: Migrating libhugetlbfs huge_below_4GB_normal_above

Hello,

Quoted 50 lines · Tarun Sahu

Migrating the libhugetlbfs/testcases/huge_below_4GB_normal_above.c test

Test Description: Designed to pick up a bug on ppc64 where touches_hugepage_low_range() could give false positives because of the peculiar (undefined) behaviour of << for large shifts

---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap14.c  | 156 ++++++++++++++++++
 3 files changed, 158 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c
runtest/hugetlb +1 -0
index 2029ee4b3..796ebe7fa 100644
@@ -15,6 +15,7 @@ hugemmap10 hugemmap10
 hugemmap11 hugemmap11
 hugemmap12 hugemmap12
 hugemmap13 hugemmap13
+hugemmap14 hugemmap14
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
index 5955ed613..3106579ce 100644
@@ -14,6 +14,7 @@
 /hugetlb/hugemmap/hugemmap11
 /hugetlb/hugemmap/hugemmap12
 /hugetlb/hugemmap/hugemmap13
+/hugetlb/hugemmap/hugemmap14
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c new file +6 -0
new file mode 100644
index 000000000..8ccd141f8
@@ -0,0 +1,156 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ * Author: David Gibson & Adam Litke
+ */
+

testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c line 16

Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c new file +10 -0
+/*\
+ * [Description]
+ *
+ * Designed to pick up a bug on ppc64 where touches_hugepage_low_range()
+ * could give false positives because of the peculiar (undefined)
+ * behaviour of << for large shifts
+ *
+ * WARNING: The offsets and addresses used within are specifically
+ * calculated to trigger the bug as it existed.  Don't mess with them
+ * unless you *really* know what you're doing.

I guess the test is good insofar that I can tell. As with hugemmap13 it would be nice to have a reference to the bugfix though.

testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c line 155

Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c new file +10 -0
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.mntpoint = MNTPOINT,
+	.needs_hugetlbfs = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {2, TST_NEEDS},

If we can find the bugfix commit then it can be referenced in the tags here.

Signature · 5 lines
Thank you,
Richard.

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

Re: [LTP] [PATCH 3/8] Hugetlb: Migrating libhugetlbfs huge_below_4GB_normal_above

Hi,

Thanks for reviewing it.

Quoted 23 lines · Richard Palethorpe

Hello,

Quoted 7 lines · Tarun Sahu

Migrating the libhugetlbfs/testcases/huge_below_4GB_normal_above.c test

Test Description: Designed to pick up a bug on ppc64 where touches_hugepage_low_range() could give false positives because of the peculiar (undefined) behaviour of << for large shifts

Quoted 8 lines

+ *
+ * Designed to pick up a bug on ppc64 where touches_hugepage_low_range()
+ * could give false positives because of the peculiar (undefined)
+ * behaviour of << for large shifts
+ *
+ * WARNING: The offsets and addresses used within are specifically
+ * calculated to trigger the bug as it existed. Don't mess with them
+ * unless you *really* know what you're doing.

I guess the test is good insofar that I can tell. As with hugemmap13 it would be nice to have a reference to the bugfix though.

Quoted 14 lines

testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c line 155

Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c new file +10 -0
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.mntpoint = MNTPOINT,
+	.needs_hugetlbfs = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {2, TST_NEEDS},

If we can find the bugfix commit then it can be referenced in the tags here.

Yeah, Will update the bug-fix references in v2

Quoted 6 lines
Signature · 5 lines
Thank you,
Richard.

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

PATCH 4/8 Hugetlb: Migrating libhugetlbfs icache-hygiene

In reply to Tarun Sahu

Migrating the libhugetlbfs/testcases/icache-hygiene.c test

Test Description: Older ppc64 kernels don't properly flush dcache to icache before giving a cleared page to userspace. With some exceedingly hairy code, this attempts to test for this bug.

This test will never trigger (obviously) on machines with coherent icache and dcache (including x86 and POWER5). On any given run, even on a buggy kernel there's a chance the bug won't trigger - either because we don't get the same physical page back when we remap, or because the icache happens to get flushed in the interim.

---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap15.c  | 239 ++++++++++++++++++
 3 files changed, 241 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c
runtest/hugetlb +1 -0
index 796ebe7fa..0714ed34c 100644
@@ -16,6 +16,7 @@ hugemmap11 hugemmap11
 hugemmap12 hugemmap12
 hugemmap13 hugemmap13
 hugemmap14 hugemmap14
+hugemmap15 hugemmap15
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
index 3106579ce..d59b60fd4 100644
@@ -15,6 +15,7 @@
 /hugetlb/hugemmap/hugemmap12
 /hugetlb/hugemmap/hugemmap13
 /hugetlb/hugemmap/hugemmap14
+/hugetlb/hugemmap/hugemmap15
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c new file +239 -0

239 lines not on this page · raw message

Signature · 5 lines
2.31.1


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

Re: [LTP] [PATCH 4/8] Hugetlb: Migrating libhugetlbfs icache-hygiene

Hello,

Quoted 11 lines · Tarun Sahu

Migrating the libhugetlbfs/testcases/icache-hygiene.c test

Test Description: Older ppc64 kernels don't properly flush dcache to icache before giving a cleared page to userspace. With some exceedingly hairy code, this attempts to test for this bug.

This test will never trigger (obviously) on machines with coherent icache and dcache (including x86 and POWER5). On any given run, even on a buggy kernel there's a chance the bug won't trigger - either because we don't get the same physical page back when we remap, or because the icache happens to get flushed in the interim.

Compiling with Clang 15.0.5 on x86_64 and upstream kernel 6.0.9 in a KVM VM the test fails:

sh-5.2# ./hugemmap15

[13712.044617] hugemmap15 (2118): drop_caches: 3

tst_hugepage.c:83: TINFO: 3 hugepage(s) reserved tst_test.c:1560: TINFO: Timeout per run is 0h 00m 30s hugemmap15.c:191: TFAIL: icache unclean

Quoted 13 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c new file +11 -0
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.mntpoint = MNTPOINT,
+	.needs_hugetlbfs = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {3, TST_NEEDS},
+};
Signature · 1 line
2.31.1

Again, it would be nice to have the git tag(s) of the fix commit(s) if possible.

Signature · 5 lines
Thank you,
Richard.

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

Re: [LTP] [PATCH 4/8] Hugetlb: Migrating libhugetlbfs icache-hygiene

Hi Richard,
Thanks for looking at it.

I am also trying to reproduce the same, In the meantime, I have found the
fix commit for this bug: https://lore.kernel.org/all/[email protected]/

I will update the tag in this and all tests moving forward, Pardon me for missing such crucial details.

Thanks
Taurn

Quoted 48 lines · Richard Palethorpe

Hello,

Quoted 11 lines · Tarun Sahu

Migrating the libhugetlbfs/testcases/icache-hygiene.c test

Test Description: Older ppc64 kernels don't properly flush dcache to icache before giving a cleared page to userspace. With some exceedingly hairy code, this attempts to test for this bug.

This test will never trigger (obviously) on machines with coherent icache and dcache (including x86 and POWER5). On any given run, even on a buggy kernel there's a chance the bug won't trigger - either because we don't get the same physical page back when we remap, or because the icache happens to get flushed in the interim.

Compiling with Clang 15.0.5 on x86_64 and upstream kernel 6.0.9 in a KVM VM the test fails:

sh-5.2# ./hugemmap15

[13712.044617] hugemmap15 (2118): drop_caches: 3

tst_hugepage.c:83: TINFO: 3 hugepage(s) reserved tst_test.c:1560: TINFO: Timeout per run is 0h 00m 30s hugemmap15.c:191: TFAIL: icache unclean

Quoted 13 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c new file +11 -0
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.mntpoint = MNTPOINT,
+	.needs_hugetlbfs = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {3, TST_NEEDS},
+};
Signature · 1 line
2.31.1

Again, it would be nice to have the git tag(s) of the fix commit(s) if possible.

Signature · 5 lines
Thank you,
Richard.

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

Re: [LTP] [PATCH 4/8] Hugetlb: Migrating libhugetlbfs icache-hygiene

On Dec 13 2022, Tarun Sahu wrote:
Hi,

with clang (any version) it even fails on power (with/without VM). while debugging with lldb, I found clang/llvm used an optmization which caused goto *p to be ignored and it just jump to jumplabel. Tunrning off the optimization makes the test work as expected.

I will post the v2 with change in Makefile for this test.

testcases/kernel/mem/hugetlb/hugemmap/Makefile +1 -0
@@ -8,4 +8,5 @@ include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../Makefile.inc
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
 
+hugemmap15: CFLAGS+=-O0
 

Thanks
Tarun

Quoted 63 lines

Hi Richard,
Thanks for looking at it.

I am also trying to reproduce the same, In the meantime, I have found the
fix commit for this bug: https://lore.kernel.org/all/[email protected]/

I will update the tag in this and all tests moving forward, Pardon me for missing such crucial details.

Thanks
Taurn

Quoted 48 lines · Richard Palethorpe

Hello,

Quoted 11 lines · Tarun Sahu

Migrating the libhugetlbfs/testcases/icache-hygiene.c test

Test Description: Older ppc64 kernels don't properly flush dcache to icache before giving a cleared page to userspace. With some exceedingly hairy code, this attempts to test for this bug.

This test will never trigger (obviously) on machines with coherent icache and dcache (including x86 and POWER5). On any given run, even on a buggy kernel there's a chance the bug won't trigger - either because we don't get the same physical page back when we remap, or because the icache happens to get flushed in the interim.

Compiling with Clang 15.0.5 on x86_64 and upstream kernel 6.0.9 in a KVM VM the test fails:

sh-5.2# ./hugemmap15

[13712.044617] hugemmap15 (2118): drop_caches: 3

tst_hugepage.c:83: TINFO: 3 hugepage(s) reserved tst_test.c:1560: TINFO: Timeout per run is 0h 00m 30s hugemmap15.c:191: TFAIL: icache unclean

Quoted 13 lines
(quoted diff) +11 -0
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.mntpoint = MNTPOINT,
+	.needs_hugetlbfs = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {3, TST_NEEDS},
+};
Signature · 1 line
2.31.1

Again, it would be nice to have the git tag(s) of the fix commit(s) if possible.

Signature · 5 lines
Thank you,
Richard.

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

PATCH 5/8 Hugetlb: Migrating libhugetlbfs madvise_reserve

In reply to Tarun Sahu

Migrating the libhugetlbfs/testcases/madvise_reserve.c test

Test Description: madvise() on some kernels can cause the reservation counter to get corrupted. The problem is that the patches are allocated for the reservation but not faulted in at the time of allocation. The counters do not get updated and effectively "leak". This test identifies whether the kernel is vulnerable to the problem or not. It is fixed in kernel by 'commit f2deae9d4e70
("Remove implementation of readpage from the hugetlbfs_aops")'.

---
 runtest/hugetlb                               |  1 +
 testcases/kernel/mem/.gitignore               |  1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap16.c  | 83 +++++++++++++++++++
 3 files changed, 85 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap16.c
runtest/hugetlb +1 -0
index 0714ed34c..1691ce37d 100644
@@ -17,6 +17,7 @@ hugemmap12 hugemmap12
 hugemmap13 hugemmap13
 hugemmap14 hugemmap14
 hugemmap15 hugemmap15
+hugemmap16 hugemmap16
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
index d59b60fd4..eb8e87c40 100644
@@ -16,6 +16,7 @@
 /hugetlb/hugemmap/hugemmap13
 /hugetlb/hugemmap/hugemmap14
 /hugetlb/hugemmap/hugemmap15
+/hugetlb/hugemmap/hugemmap16
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap16.c new file +83 -0

83 lines not on this page · raw message

Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 5/8
#16 lore raw

Re: [LTP] [PATCH 5/8] Hugetlb: Migrating libhugetlbfs madvise_reserve

Hello,

Looks good,

Quoted 133 lines · Tarun Sahu

Migrating the libhugetlbfs/testcases/madvise_reserve.c test

Test Description: madvise() on some kernels can cause the reservation counter to get corrupted. The problem is that the patches are allocated for the reservation but not faulted in at the time of allocation. The counters do not get updated and effectively "leak". This test identifies whether the kernel is vulnerable to the problem or not. It is fixed in kernel by 'commit f2deae9d4e70
("Remove implementation of readpage from the hugetlbfs_aops")'.

---
 runtest/hugetlb                               |  1 +
 testcases/kernel/mem/.gitignore               |  1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap16.c  | 83 +++++++++++++++++++
 3 files changed, 85 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap16.c
runtest/hugetlb +1 -0
index 0714ed34c..1691ce37d 100644
@@ -17,6 +17,7 @@ hugemmap12 hugemmap12
 hugemmap13 hugemmap13
 hugemmap14 hugemmap14
 hugemmap15 hugemmap15
+hugemmap16 hugemmap16
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
index d59b60fd4..eb8e87c40 100644
@@ -16,6 +16,7 @@
 /hugetlb/hugemmap/hugemmap13
 /hugetlb/hugemmap/hugemmap14
 /hugetlb/hugemmap/hugemmap15
+/hugetlb/hugemmap/hugemmap16
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap16.c new file +83 -0
new file mode 100644
index 000000000..ea940e90c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 IBM Corporation.
+ * Author: Eric B Munson and Mel Gorman
+ */
+
+/*\
+ * [Description]
+ *
+ * madvise() on some kernels can cause the reservation counter to get
+ * corrupted. The problem is that the patches are allocated
+ * for the reservation but not faulted in at the time of allocation. The
+ * counters do not get updated and effectively "leak". This test
+ * identifies whether the kernel is vulnerable to the problem or not.
+ * It is fixed in kernel by commit f2deae9d4e70793568ef9e85d227abb7bef5b622
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+#define MNTPOINT "hugetlbfs/"
+static int  fd = -1;
+static long hpage_size;
+
+static void run_test(void)
+{
+	void *p;
+	unsigned long initial_rsvd, map_rsvd, madvise_rsvd, end_rsvd;
+
+	fd = tst_creat_unlinked(MNTPOINT, 0);
+
+	initial_rsvd = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD);
+	tst_res(TINFO, "Reserve count before map: %lu", initial_rsvd);
+
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
+		 fd, 0);
+	map_rsvd = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD);
+	tst_res(TINFO, "Reserve count after map: %lu", map_rsvd);
+
+	if (madvise(p, hpage_size, MADV_WILLNEED) == -1)
+		tst_brk(TBROK|TERRNO, "madvise()");
+	madvise_rsvd = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD);
+	tst_res(TINFO, "Reserve count after madvise: %lu", madvise_rsvd);
+
+	SAFE_MUNMAP(p, hpage_size);
+	SAFE_CLOSE(fd);
+	end_rsvd = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD);
+	tst_res(TINFO, "Reserve count after close(): %lu", end_rsvd);
+
+	TST_EXP_EQ_LU(end_rsvd, initial_rsvd);
+}
+
+static void setup(void)
+{
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.tags = (struct tst_tag[]) {
+		{"linux-git", "f2deae9d4e70"},
+		{}
+	},
+	.needs_root = 1,
+	.mntpoint = MNTPOINT,
+	.needs_hugetlbfs = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {1, TST_NEEDS},
+};
Signature · 1 line
2.31.1
Signature · 5 lines
Thank you,
Richard.

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

PATCH 6/8 Hugetlb: Migrating libhugetlbfs map_high_truncate_2

In reply to Tarun Sahu

Migrating the libhugetlbfs/testcases/map_high_truncate_2.c test

Test Description: At one stage, a misconversion of hugetlb_vmtruncate_list to a prio_tree meant that on 32-bit machines, certain combinations of mapping and truncations could truncate incorrect pages, or overwrite pmds from other VMAs, triggering BUG_ON()s or other wierdness.

Test adapted from an example by Kenneth Chen <[email protected]>

WARNING: The offsets and addresses used within are specifically calculated to trigger the bug as it existed. Don't mess with them unless you *really* know what you're doing.

The kernel bug in question was fixed with
'commit 856fc2950555 ("[PATCH] hugetlb: fix prio_tree unit")'.

---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap17.c  | 103 ++++++++++++++++++
 3 files changed, 105 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap17.c
runtest/hugetlb +1 -0
index 1691ce37d..5fac3481c 100644
@@ -18,6 +18,7 @@ hugemmap13 hugemmap13
 hugemmap14 hugemmap14
 hugemmap15 hugemmap15
 hugemmap16 hugemmap16
+hugemmap17 hugemmap17
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
index eb8e87c40..6aa54f902 100644
@@ -17,6 +17,7 @@
 /hugetlb/hugemmap/hugemmap14
 /hugetlb/hugemmap/hugemmap15
 /hugetlb/hugemmap/hugemmap16
+/hugetlb/hugemmap/hugemmap17
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap17.c new file +103 -0

103 lines not on this page · raw message

Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 6/8
#18 lore raw

Re: [LTP] [PATCH 6/8] Hugetlb: Migrating libhugetlbfs map_high_truncate_2

Hello,

Quoted 10 lines · Tarun Sahu

Migrating the libhugetlbfs/testcases/map_high_truncate_2.c test

Test Description: At one stage, a misconversion of hugetlb_vmtruncate_list to a prio_tree meant that on 32-bit machines, certain combinations of mapping and truncations could truncate incorrect pages, or overwrite pmds from other VMAs, triggering BUG_ON()s or other wierdness.

Test adapted from an example by Kenneth Chen <[email protected]>

Quoted 8 lines

WARNING: The offsets and addresses used within are specifically calculated to trigger the bug as it existed. Don't mess with them unless you *really* know what you're doing.

The kernel bug in question was fixed with
'commit 856fc2950555 ("[PATCH] hugetlb: fix prio_tree unit")'.

Signature · 5 lines
Thank you,
Richard.

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

PATCH 7/8 Hugetlb: Migrating libhugetlbfs misalign

In reply to Tarun Sahu

Migrating the libhugetlbfs/testcases/misalign.c test

Test Description: Just as normal mmap()s can't have an address, length or offset which is not page aligned, so hugepage mmap()s can't have an address, length or offset with is not hugepage aligned.

However, from time to time when the various mmap() / get_unmapped_area() paths are updated, somebody misses one of the necessary checks for the hugepage paths. This testcase ensures that attempted hugepage mappings with parameters which are not correctly hugepage aligned are rejected.

However starting with 3.10-rc1, length passed in mmap() doesn't need to be aligned because 'commit af73e4d9506d
("hugetlbfs: fix mmap failure in unaligned size request")' added ALIGN() to kernel side, in mmap_pgoff(), when mapping huge page files.

---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap18.c  | 153 ++++++++++++++++++
 3 files changed, 155 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap18.c
runtest/hugetlb +1 -0
index 5fac3481c..de76cdaf2 100644
@@ -19,6 +19,7 @@ hugemmap14 hugemmap14
 hugemmap15 hugemmap15
 hugemmap16 hugemmap16
 hugemmap17 hugemmap17
+hugemmap18 hugemmap18
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
index 6aa54f902..daee70586 100644
@@ -18,6 +18,7 @@
 /hugetlb/hugemmap/hugemmap15
 /hugetlb/hugemmap/hugemmap16
 /hugetlb/hugemmap/hugemmap17
+/hugetlb/hugemmap/hugemmap18
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap18.c new file +153 -0

153 lines not on this page · raw message

Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 7/8
#20 lore raw

Re: [LTP] [PATCH 7/8] Hugetlb: Migrating libhugetlbfs misalign

Quoted 12 lines · Tarun Sahu

Migrating the libhugetlbfs/testcases/misalign.c test

Test Description: Just as normal mmap()s can't have an address, length or offset which is not page aligned, so hugepage mmap()s can't have an address, length or offset with is not hugepage aligned.

However, from time to time when the various mmap() / get_unmapped_area() paths are updated, somebody misses one of the necessary checks for the hugepage paths. This testcase ensures that attempted hugepage mappings with parameters which are not correctly hugepage aligned are rejected.

Quoted 6 lines

However starting with 3.10-rc1, length passed in mmap() doesn't need to be aligned because 'commit af73e4d9506d
("hugetlbfs: fix mmap failure in unaligned size request")' added ALIGN() to kernel side, in mmap_pgoff(), when mapping huge page files.

Signature · 5 lines
Thank you,
Richard.

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

PATCH 8/8 Hugetlb: Migrating libhugetlbfs misaligned_offset

In reply to Tarun Sahu

Migrating the libhugetlbfs/testcases/misaligned_offset.c test

Test Name: Misaligned offset

Test Description: At one stage, a misconversion of hugetlb_vmtruncate_list to a prio_tree meant that on 32-bit machines, truncates at or above 4GB could truncate lower pages, resulting in BUG_ON()s.

WARNING: The offsets and addresses used within are specifically calculated to trigger the bug as it existed. Don't mess with them unless you *really* know what you're doing.

The kernel bug in question was fixed with
'commit 856fc2950555 ("[PATCH] hugetlb: fix prio_tree unit")'.

---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap19.c  | 147 ++++++++++++++++++
 3 files changed, 149 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap19.c
runtest/hugetlb +1 -0
index de76cdaf2..4da1525a7 100644
@@ -20,6 +20,7 @@ hugemmap15 hugemmap15
 hugemmap16 hugemmap16
 hugemmap17 hugemmap17
 hugemmap18 hugemmap18
+hugemmap19 hugemmap19
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
index daee70586..b6b3e5ddd 100644
@@ -19,6 +19,7 @@
 /hugetlb/hugemmap/hugemmap16
 /hugetlb/hugemmap/hugemmap17
 /hugetlb/hugemmap/hugemmap18
+/hugetlb/hugemmap/hugemmap19
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap19.c new file +147 -0

147 lines not on this page · raw message

Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 8/8
#22 lore raw

Re: [LTP] [PATCH 8/8] Hugetlb: Migrating libhugetlbfs misaligned_offset

Quoted 8 lines · Tarun Sahu

Migrating the libhugetlbfs/testcases/misaligned_offset.c test

Test Name: Misaligned offset

Test Description: At one stage, a misconversion of hugetlb_vmtruncate_list to a prio_tree meant that on 32-bit machines, truncates at or above 4GB could truncate lower pages, resulting in BUG_ON()s.

Quoted 8 lines

WARNING: The offsets and addresses used within are specifically calculated to trigger the bug as it existed. Don't mess with them unless you *really* know what you're doing.

The kernel bug in question was fixed with
'commit 856fc2950555 ("[PATCH] hugetlb: fix prio_tree unit")'.

Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#23 lore raw
In reply to Tarun Sahu

Hello,

Setting the rest of this patch serious to "changes requested" in patchwork. EVen though I have added reviewed tags to most of the tests, I don't want to merge them out of sequence.

Also please assume that any comments that were made about previous tests may also apply to those left. I did not check these very carefully.

Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#24 lore raw
Quoted 9 lines · Richard Palethorpe

Hello,

Setting the rest of this patch serious to "changes requested" in patchwork. EVen though I have added reviewed tags to most of the tests, I don't want to merge them out of sequence.

Also please assume that any comments that were made about previous tests may also apply to those left. I did not check these very carefully.

Thanks, for reviewing it, Richard.
Sure, Will update and post updated version.

Thanks
Tarun

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