Skip to contentSkip to conversation

Add hugemmap41(Migrating the libhugetlbfs/testcases/slbpacaflush.c test)

PATCH Superseded Shirisha G 2 participants 5 messages Dec 13, 2023 – Apr 16, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Shirisha G

author
#0 lore raw

PATCH 1/1 Add hugemmap41(Migrating the libhugetlbfs/testcases/slbpacaflush.c test)

We are verifying ppc64 kernels prior to 2.6.15-rc5 exhibit a bug in the hugepage SLB flushing path. When opening new hugetlb areas, updating masks in the thread_struct and copying to the PACA only occurs on the CPU where segments are opened, leading to potential stale copies in other CPUs. This bug can be triggered by multiple threads sharing the mm or a single thread migrating between CPUs, particularly evident in a close-to-idle system, as other processes may flush the SLB and prevent the bug from manifesting.

Original test originates from https://github.com/libhugetlbfs/libhugetlbfs/blob/master/tests/slbpacaflush.c

---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap41.c  | 144 ++++++++++++++++++
 3 files changed, 146 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c
runtest/hugetlb +1 -0
index 299c07ac9..d956866ac 100644
@@ -35,6 +35,7 @@ hugemmap29 hugemmap29
 hugemmap30 hugemmap30
 hugemmap31 hugemmap31
 hugemmap32 hugemmap32
+hugemmap41 hugemmap41
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
index c96fe8bfc..b7e108956 100644
@@ -34,6 +34,7 @@
 /hugetlb/hugemmap/hugemmap30
 /hugetlb/hugemmap/hugemmap31
 /hugetlb/hugemmap/hugemmap32
+/hugetlb/hugemmap/hugemmap41
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +144 -0

144 lines not on this page · raw message

Signature · 5 lines
2.39.3


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

Hi Shirisha,

Quoted 1 line

We are verifying ppc64 kernels prior to 2.6.15-rc5 exhibit a bug in the

Test is from 2005, for 2.6.15-rc5. Is it really relevant now?

Quoted 6 lines

hugepage SLB flushing path. When opening new hugetlb areas, updating masks in the thread_struct and copying to the PACA only occurs on the CPU where segments are opened, leading to potential stale copies in other CPUs. This bug can be triggered by multiple threads sharing the mm or a single thread migrating between CPUs, particularly evident in a close-to-idle system, as other processes may flush the SLB and prevent the bug from manifesting.

Please run make check-hugemmap41 in the test directory and fix formatting.

Quoted 15 lines

Original test originates from https://github.com/libhugetlbfs/libhugetlbfs/blob/master/tests/slbpacaflush.c

---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap41.c  | 144 ++++++++++++++++++
 3 files changed, 146 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c
runtest/hugetlb +0 -0
index 299c07ac9..d956866ac 100644

runtest/hugetlb hugemmap29 hugemmap29 · line 38

Quoted 4 lines
runtest/hugetlb +1 -0
@@ -35,6 +35,7 @@ hugemmap29 hugemmap29
 hugemmap30 hugemmap30
 hugemmap31 hugemmap31
 hugemmap32 hugemmap32
+hugemmap41 hugemmap41

nit: Any reason why not add it as hugemmap33? You don't want to clash with other sent test, right?

Quoted 42 lines
runtest/hugetlb +0 -0
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
index c96fe8bfc..b7e108956 100644
@@ -34,6 +34,7 @@
 /hugetlb/hugemmap/hugemmap30
 /hugetlb/hugemmap/hugemmap31
 /hugetlb/hugemmap/hugemmap32
+/hugetlb/hugemmap/hugemmap41
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +21 -0
new file mode 100644
index 000000000..3b3388c68
@@ -0,0 +1,144 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2005-2006 IBM Corporation.
+ * Author: David Gibson & Adam Litke
+ */
+/*\
+ * [Description]
+ *
+ * ppc64 kernels (prior to 2.6.15-rc5) have a bug in the hugepage SLB
+ * flushing path.  After opening new hugetlb areas, we update the
+ * masks in the thread_struct, copy to the PACA, then do slbies on
+ * each CPU.  The trouble is we only copy to the PACA on the CPU where
+ * we're opening the segments, which can leave a stale copy in the
+ * PACAs on other CPUs.
+ *
+ * This can be triggered either with multiple threads sharing the mm,
+ * or with a single thread which is migrated from one CPU, to another
+ * (where the mapping occurs), then back again (where we touch the
+ * stale SLB).  We use the second method in this test, since it's
+ * easier to force (using sched_setaffinity).  However it relies on a
+ * close-to-idle system, if any process other than a kernel thread

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c line 31

Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +10 -0
+ * runs on the first CPU between runs of the test process, the SLB
+ * will be flushed and we won't trigger the bug, hence the
+ * PASS_INCONCLUSIVE().  Obviously, this test won't work on a 1-cpu
+ * system (should get CONFIG() on the sched_setaffinity)
+ *
+ */
+#define _GNU_SOURCE
+#include "hugetlb.h"
+#define SYSFS_CPU_ONLINE_FMT	"/sys/devices/system/cpu/cpu%d/online"
+#define MNTPOINT "hugetlbfs/"

Could you please have these 2 #define above _GNU_SOURCE? (readablility)

Quoted 5 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +5 -0
+
+
+#include <stdio.h>
+#include <sched.h>
+

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c line 46

Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +10 -0
+
+long hpage_size;
+int fd;
+void *p;
+volatile unsigned long *q;
+int online_cpus[2], err;
+cpu_set_t cpu0, cpu1;
+
+
+

Please remove these blank lines above.

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c line 58

Quoted 12 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +12 -0
+void check_online_cpus(int online_cpus[], int nr_cpus_needed)
+{
+	char cpu_state, path_buf[64];
+	int total_cpus, cpu_idx, fd, ret, i;
+
+	total_cpus = get_nprocs_conf();
+	cpu_idx = 0;
+
+	if (get_nprocs() < nr_cpus_needed)
+		tst_res(TFAIL, "Atleast online %d cpus are required", nr_cpus_needed);
+
+	for (i = 0; i < total_cpus && cpu_idx < nr_cpus_needed; i++) {

nit: Maybe just use get_nprocs_conf() directly?

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c line 59

Quoted 1 line
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +1 -0
+		errno = 0;

Is it errno reset really needed?

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c line 70

Quoted 11 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +11 -0
+		sprintf(path_buf, SYSFS_CPU_ONLINE_FMT, i);
+		fd = open(path_buf, O_RDONLY);
+		if (fd < 0) {
+			/* If 'online' is absent, the cpu cannot be offlined */
+			if (errno == ENOENT) {
+				online_cpus[cpu_idx] = i;
+				cpu_idx++;
+				continue;
+			} else {
+				tst_res(TFAIL, "Unable to open %s: %s", path_buf,
+				     strerror(errno));

We have TERRNO:

				tst_res(TFAIL | TERRNO, "Unable to open %s: %s", path_buf);

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c line 77

Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +7 -0
+			}
+		}
+
+		ret = read(fd, &cpu_state, 1);
+		if (ret < 1)
+			tst_res(TFAIL, "Unable to read %s: %s", path_buf,
+			     strerror(errno));

Maybe use SAFE_READ() ?

Quoted 17 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +17 -0
+
+		if (cpu_state == '1') {
+			online_cpus[cpu_idx] = i;
+			cpu_idx++;
+		}
+
+		if (fd >= 0)
+			SAFE_CLOSE(fd);
+	}
+
+	if (cpu_idx < nr_cpus_needed)
+		tst_res(TFAIL, "Atleast %d online cpus were not found", nr_cpus_needed);
+}
+
+
+static void run_test(void)
+{

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c line 104

Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +10 -0
+	check_online_cpus(online_cpus, 2);
+	CPU_ZERO(&cpu0);
+	CPU_SET(online_cpus[0], &cpu0);
+	CPU_ZERO(&cpu1);
+	CPU_SET(online_cpus[1], &cpu1);
+
+	err = sched_setaffinity(getpid(), CPU_SETSIZE/8, &cpu0);
+	if (err != 0)
+		tst_res(TFAIL, "sched_setaffinity(cpu%d): %s", online_cpus[0],
+				strerror(errno));

Again, please use TTERRNO.

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c line 106

Quoted 2 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +2 -0
+
+	err = sched_setaffinity(getpid(), CPU_SETSIZE/8, &cpu1);

Maybe define CPU_SETSIZE/8 at the top?

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c line 118

Quoted 12 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +12 -0
+
+	if (err != 0)
+		tst_res(TFAIL, "sched_setaffinity(cpu%d): %s", online_cpus[1],
+				strerror(errno));
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+
+	err = sched_setaffinity(getpid(), CPU_SETSIZE/8, &cpu0);
+	if (err != 0)
+		tst_res(TFAIL, "sched_setaffinity(cpu%d): %s", online_cpus[0],
+				strerror(errno));
+	q = (volatile unsigned long *)(p + getpagesize());
+	*q = 0xdeadbeef;

Why to set the address before end of testing? (yes, the original does it, but why?). Wouldn't be better to use guarded buffers instead?

https://github.com/linux-test-project/ltp/wiki/C-Test-API#131-guarded-buffers

Kind regards,
Petr

Quoted 26 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +26 -0
+
+	tst_res(TPASS, "Test Passed inconclusive");
+}
+
+static void setup(void)
+{
+	hpage_size = tst_get_hugepage_size();
+	fd = tst_creat_unlinked(MNTPOINT, 0);
+}
+
+void cleanup(void)
+{
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+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 = {1, TST_NEEDS},
+};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
Quoted 5 lines · Petr Vorel

Hi Shirisha,

Quoted 2 lines

We are verifying ppc64 kernels prior to 2.6.15-rc5 exhibit a bug in the

Test is from 2005, for 2.6.15-rc5. Is it really relevant now?

yes

Quoted 14 lines
Quoted 13 lines

hugepage SLB flushing path. When opening new hugetlb areas, updating masks
in the thread_struct and copying to the PACA only occurs on the CPU where
segments are opened, leading to potential stale copies in other CPUs.
This bug can be triggered by multiple threads sharing the mm or a single thread
migrating between CPUs, particularly evident in a close-to-idle system,
as other processes may flush the SLB and prevent the bug from manifesting.

Quoted 2 lines

Please run make check-hugemmap41 in the test directory and fix formatting.

will take care in V2

Quoted 16 lines
Quoted 16 lines

Original test originates from
https://github.com/libhugetlbfs/libhugetlbfs/blob/master/tests/slbpacaflush.c

---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap41.c  | 144
++++++++++++++++++
 3 files changed, 146 insertions(+)
 create mode 100644

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c

runtest/hugetlb +0 -0
index 299c07ac9..d956866ac 100644
Quoted 8 lines

runtest/hugetlb hugemmap29 hugemmap29 · line 38

Quoted 5 lines
runtest/hugetlb +1 -0
@@ -35,6 +35,7 @@ hugemmap29 hugemmap29
 hugemmap30 hugemmap30
 hugemmap31 hugemmap31
 hugemmap32 hugemmap32
+hugemmap41 hugemmap41

nit: Any reason why not add it as hugemmap33? You don't want to clash with other
sent test, right?

yes

Quoted 56 lines
Quoted 56 lines
runtest/hugetlb +0 -0
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
index c96fe8bfc..b7e108956 100644
@@ -34,6 +34,7 @@
 /hugetlb/hugemmap/hugemmap30
 /hugetlb/hugemmap/hugemmap31
 /hugetlb/hugemmap/hugemmap32
+/hugetlb/hugemmap/hugemmap41
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +9 -0
new file mode 100644
index 000000000..3b3388c68
@@ -0,0 +1,144 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2005-2006 IBM Corporation.
+ * Author: David Gibson & Adam Litke
+ */
+/*\
+ * [Description]
+ *
+ * ppc64 kernels (prior to 2.6.15-rc5) have a bug in the hugepage

SLB
+ * flushing path. After opening new hugetlb areas, we update the
+ * masks in the thread_struct, copy to the PACA, then do slbies on
+ * each CPU. The trouble is we only copy to the PACA on the CPU where
+ * we're opening the segments, which can leave a stale copy in the
+ * PACAs on other CPUs.
+ *
+ * This can be triggered either with multiple threads sharing the mm,
+ * or with a single thread which is migrated from one CPU, to another
+ * (where the mapping occurs), then back again (where we touch the
+ * stale SLB). We use the second method in this test, since it's
+ * easier to force (using sched_setaffinity). However it relies on a
+ * close-to-idle system, if any process other than a kernel thread
+ * runs on the first CPU between runs of the test process, the SLB
+ * will be flushed and we won't trigger the bug, hence the
+ * PASS_INCONCLUSIVE(). Obviously, this test won't work on a 1- cpu
+ * system (should get CONFIG() on the sched_setaffinity)
+ *

Quoted 8 lines
Quoted 6 lines

+ */

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +3 -0
+#define _GNU_SOURCE
+#include "hugetlb.h"
+#define SYSFS_CPU_ONLINE_FMT	"/sys/devices/system/cpu/cpu%d/

online"
+#define MNTPOINT "hugetlbfs/"

Could you please have these 2 #define above _GNU_SOURCE? (readablility)

will take care in V2

Quoted 8 lines
Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +8 -0
+
+
+#include <stdio.h>
+#include <sched.h>
+
+
+long hpage_size;
+int fd;
Quoted 8 lines

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c line 46

Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +7 -0
+void *p;
+volatile unsigned long *q;
+int online_cpus[2], err;
+cpu_set_t cpu0, cpu1;
+
+
+

Please remove these blank lines above.

Sure.will take care in V2

Quoted 15 lines
Quoted 12 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +10 -0
+void check_online_cpus(int online_cpus[], int nr_cpus_needed)
+{
+	char cpu_state, path_buf[64];
+	int total_cpus, cpu_idx, fd, ret, i;
+
+	total_cpus = get_nprocs_conf();
+	cpu_idx = 0;
+
+	if (get_nprocs() < nr_cpus_needed)
+		tst_res(TFAIL, "Atleast online %d cpus are required",

nr_cpus_needed);

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c

Quoted 2 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +2 -0
+
+	for (i = 0; i < total_cpus && cpu_idx < nr_cpus_needed; i++) {

nit: Maybe just use get_nprocs_conf() directly?

Sure.

Quoted 3 lines

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c line 59

Quoted 2 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +1 -0
+		errno = 0;

Is it errno reset really needed?

Since based on the error number we are failing the testcase so need it

Quoted 17 lines
Quoted 13 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +4 -0
+		sprintf(path_buf, SYSFS_CPU_ONLINE_FMT, i);
+		fd = open(path_buf, O_RDONLY);
+		if (fd < 0) {
+			/* If 'online' is absent, the cpu cannot be

offlined */

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +6 -0
+			if (errno == ENOENT) {
+				online_cpus[cpu_idx] = i;
+				cpu_idx++;
+				continue;
+			} else {
+				tst_res(TFAIL, "Unable to open %s: %s",

path_buf,

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c

Quoted 1 line
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +1 -0
+				     strerror(errno));

We have TERRNO:
tst_res(TFAIL | TERRNO, "Unable to open
%s: %s", path_buf);

will take care in V2

Quoted 9 lines

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c

Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +6 -0
+			}
+		}
+
+		ret = read(fd, &cpu_state, 1);
+		if (ret < 1)
+			tst_res(TFAIL, "Unable to read %s: %s",

path_buf,

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +1 -0
+			     strerror(errno));

Maybe use SAFE_READ() ?

Am using read here because unable to read may potentially indicate a test failure

Quoted 22 lines
Quoted 22 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +12 -0
+
+		if (cpu_state == '1') {
+			online_cpus[cpu_idx] = i;
+			cpu_idx++;
+		}
+
+		if (fd >= 0)
+			SAFE_CLOSE(fd);
+	}
+
+	if (cpu_idx < nr_cpus_needed)
+		tst_res(TFAIL, "Atleast %d online cpus were not found",

nr_cpus_needed);

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +9 -0
+}
+
+
+static void run_test(void)
+{
+	check_online_cpus(online_cpus, 2);
+	CPU_ZERO(&cpu0);
+	CPU_SET(online_cpus[0], &cpu0);
+	CPU_ZERO(&cpu1);
Quoted 8 lines

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c

Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +5 -0
+	CPU_SET(online_cpus[1], &cpu1);
+
+	err = sched_setaffinity(getpid(), CPU_SETSIZE/8, &cpu0);
+	if (err != 0)
+		tst_res(TFAIL, "sched_setaffinity(cpu%d): %s",

online_cpus[0],

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +1 -0
+				strerror(errno));

Again, please use TTERRNO.

Sure. will take care in V2

Quoted 3 lines

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c

Quoted 2 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +2 -0
+
+	err = sched_setaffinity(getpid(), CPU_SETSIZE/8, &cpu1);

Maybe define CPU_SETSIZE/8 at the top?

Sure.will take care in V2

Quoted 19 lines
Quoted 12 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +3 -0
+
+	if (err != 0)
+		tst_res(TFAIL, "sched_setaffinity(cpu%d): %s",

online_cpus[1],

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +2 -0
+				strerror(errno));
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE,

MAP_SHARED, fd, 0);

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +4 -0
+
+	err = sched_setaffinity(getpid(), CPU_SETSIZE/8, &cpu0);
+	if (err != 0)
+		tst_res(TFAIL, "sched_setaffinity(cpu%d): %s",

online_cpus[0],

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c line 118

Quoted 3 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +3 -0
+				strerror(errno));
+	q = (volatile unsigned long *)(p + getpagesize());
+	*q = 0xdeadbeef;

Why to set the address before end of testing? (yes, the original does it, but
why?). Wouldn't be better to use guarded buffers instead?

Quoted 1 line

https://github.com/linux-test-project/ltp/wiki/C-Test-API#131-guarded-buffers

We are trying to access and write into a memory location within the mapped segment by adding the huge page size to the mapped address and casting it to a volatile unsigned long pointer to ensure things work fine.

Quoted 30 lines

Kind regards,
Petr

Quoted 26 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +26 -0
+
+	tst_res(TPASS, "Test Passed inconclusive");
+}
+
+static void setup(void)
+{
+	hpage_size = tst_get_hugepage_size();
+	fd = tst_creat_unlinked(MNTPOINT, 0);
+}
+
+void cleanup(void)
+{
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+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 = {1, TST_NEEDS},
+};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
In reply to Shirisha G

Hi Shirisha,

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c line 56

Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +10 -0
+void check_online_cpus(int online_cpus[], int nr_cpus_needed)
+{
+	char cpu_state, path_buf[64];
+	int total_cpus, cpu_idx, fd, ret, i;
+
+	total_cpus = get_nprocs_conf();
+	cpu_idx = 0;
+
+	if (get_nprocs() < nr_cpus_needed)
+		tst_res(TFAIL, "Atleast online %d cpus are required", nr_cpus_needed);

s/Atleast/At least/
(or better: "minimum %d online cpus" ..., but I'm not a native speaker.)

Also test should exit when not enough online CPU, right? (it's a test requirement not a subject of testing). Therefore tst_brk(TCONF, ...) should be used instead of tst_res(TFAIL).

And shouldn't this be a setup function (i.e. run only once, before test starts - test itself can be run more times, eg 3x with -i3).

Quoted 23 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +23 -0
+
+	for (i = 0; i < total_cpus && cpu_idx < nr_cpus_needed; i++) {
+		errno = 0;
+		sprintf(path_buf, SYSFS_CPU_ONLINE_FMT, i);
+		fd = open(path_buf, O_RDONLY);
+		if (fd < 0) {
+			/* If 'online' is absent, the cpu cannot be offlined */
+			if (errno == ENOENT) {
+				online_cpus[cpu_idx] = i;
+				cpu_idx++;
+				continue;
+			} else {
+				tst_res(TFAIL, "Unable to open %s: %s", path_buf,
+				     strerror(errno));
+			}
+		}
+
+		ret = read(fd, &cpu_state, 1);
+		if (ret < 1)
+			tst_res(TFAIL, "Unable to read %s: %s", path_buf,
+			     strerror(errno));
+
+		if (cpu_state == '1') {

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c line 89

Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +10 -0
+			online_cpus[cpu_idx] = i;
+			cpu_idx++;
+		}
+
+		if (fd >= 0)
+			SAFE_CLOSE(fd);
+	}
+
+	if (cpu_idx < nr_cpus_needed)
+		tst_res(TFAIL, "Atleast %d online cpus were not found", nr_cpus_needed);

Also here tst_brk(TCONF, ...)

Quoted 1 line

+}

Kind regards,
Petr

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

Hi Shirisha,

Quoted 11 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +10 -0
+void check_online_cpus(int online_cpus[], int nr_cpus_needed)
+{
+	char cpu_state, path_buf[64];
+	int total_cpus, cpu_idx, fd, ret, i;
+
+	total_cpus = get_nprocs_conf();
+	cpu_idx = 0;
+
+	if (get_nprocs() < nr_cpus_needed)
+		tst_res(TFAIL, "Atleast online %d cpus are required",

nr_cpus_needed);

s/Atleast/At least/
(or better: "minimum %d online cpus" ..., but I'm not a native speaker.)

will take care in V2

Quoted 5 lines

Also test should exit when not enough online CPU, right? (it's a test requirement not a subject of testing). Therefore tst_brk(TCONF, ...) should be
used instead of tst_res(TFAIL).

will take care in V2

Quoted 4 lines

And shouldn't this be a setup function (i.e. run only once, before test starts -
test itself can be run more times, eg 3x with -i3).

I think not because of successive iterations the online cpus state might change

Quoted 31 lines
Quoted 31 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +7 -0
+
+	for (i = 0; i < total_cpus && cpu_idx < nr_cpus_needed; i++) {
+		errno = 0;
+		sprintf(path_buf, SYSFS_CPU_ONLINE_FMT, i);
+		fd = open(path_buf, O_RDONLY);
+		if (fd < 0) {
+			/* If 'online' is absent, the cpu cannot be

offlined */

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +6 -0
+			if (errno == ENOENT) {
+				online_cpus[cpu_idx] = i;
+				cpu_idx++;
+				continue;
+			} else {
+				tst_res(TFAIL, "Unable to open %s: %s",

path_buf,

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +7 -0
+				     strerror(errno));
+			}
+		}
+
+		ret = read(fd, &cpu_state, 1);
+		if (ret < 1)
+			tst_res(TFAIL, "Unable to read %s: %s",

path_buf,

testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +7 -0
+			     strerror(errno));
+
+		if (cpu_state == '1') {
+			online_cpus[cpu_idx] = i;
+			cpu_idx++;
+		}
+
Quoted 8 lines
Quoted 7 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap41.c new file +6 -0
+		if (fd >= 0)
+			SAFE_CLOSE(fd);
+	}
+
+	if (cpu_idx < nr_cpus_needed)
+		tst_res(TFAIL, "Atleast %d online cpus were not found",

nr_cpus_needed);

Also here tst_brk(TCONF, ...)

will take care in V2

Quoted 4 lines
Quoted 1 line

+}

Kind regards,
Petr

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