All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests
@ 2022-10-16 12:57 Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge Tarun Sahu
                   ` (29 more replies)
  0 siblings, 30 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Hi,
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.

As per previous dicussion in RFC[1], Here, this patch series consists
of hugetlb tests taken from libhugetlbfs modified to work in ltp
environment. This series do not include all the tests, I
will post another series for the remaining tests soon.

ref:
1: https://lore.kernel.org/all/20220908173947.17956-1-tsahu@linux.ibm.com/

Tarun Sahu (29):
  Hugetlb: Migrating libhugetlbfs brk_near_huge
  Hugetlb: Migrating libhugetlbfs chunk-overcommit
  Hugetlb: Migrating libhugetlbfs corrupt-by-cow-opt
  Hugetlb: Migrating libhugetlbfs counters
  Hugetlb: Migrating libhugetlbfs directio
  Hugetlb: Migrating libhugetlbfs fadvise_reserve
  Hugetlb: Migrating libhugetlbfs fallocate_align
  Hugetlb: Migrating libhugetlbfs fallocate_basic
  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
  Hugetlb: Migrating libhugetlbfs mlock
  Hugetlb: Migrating libhugetlbfs mmap-cow
  Hugetlb: Migrating libhugetlbfs mmap-gettest
  Hugetlb: Migrating libhugetlbfs mprotect
  Hugetlb: Migrating libhugetlbfs mremap-fixed-huge-near-normal
  Hugetlb: Migrating libhugetlbfs mremap-fixed-normal-near-huge
  Hugetlb: Migrating libhugetlbfs noresv-reserve-resv-page
  Hugetlb: Migrating libhugetlbfs noresv-regarded-as-resv
  Hugetlb: Migrating libhugetlbfs private
  Hugetlb: Migrating libhugetlbfs readahead_reserve
  Hugetlb: Migrating libhugetlbfs readback
  Hugetlb: Migrating libhugetlbfs shared
  Hugetlb: Migrating libhugetlbfs shm-fork

 runtest/hugetlb                               |  31 ++
 testcases/kernel/mem/.gitignore               |  29 ++
 .../kernel/mem/hugetlb/hugefallocate/Makefile |  10 +
 .../hugetlb/hugefallocate/hugefallocate01.c   | 187 +++++++
 .../hugetlb/hugefallocate/hugefallocate02.c   | 116 +++++
 .../kernel/mem/hugetlb/hugefork/Makefile      |  10 +
 .../kernel/mem/hugetlb/hugefork/hugefork01.c  | 220 ++++++++
 .../kernel/mem/hugetlb/hugefork/hugefork02.c  | 196 ++++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap07.c  | 163 ++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap08.c  | 173 +++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap09.c  | 102 ++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap10.c  | 475 ++++++++++++++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap11.c  | 111 ++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap12.c  | 114 +++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap13.c  | 160 ++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap14.c  | 204 ++++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap15.c  | 250 +++++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap16.c  | 112 +++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap17.c  | 126 +++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap18.c  | 173 +++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap19.c  | 166 ++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap20.c  | 108 ++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap21.c  | 222 ++++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap22.c  | 170 +++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap23.c  | 283 +++++++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap25.c  | 168 +++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap26.c  | 148 ++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap27.c  | 166 ++++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap28.c  | 107 ++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap29.c  | 129 +++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap30.c  | 120 +++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap31.c  |  98 ++++
 .../kernel/mem/hugetlb/hugemmap/hugemmap32.c  | 104 ++++
 testcases/kernel/mem/hugetlb/lib/hugetlb.c    |  75 +++
 testcases/kernel/mem/hugetlb/lib/hugetlb.h    |   5 +
 35 files changed, 5031 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/Makefile
 create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate01.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c
 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/hugefork/hugefork02.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.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
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap25.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap27.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap28.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap30.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap31.c
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.c

-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-17  9:30   ` Cyril Hrubis
  2022-10-17 10:20   ` Li Wang
  2022-10-16 12:57 ` [LTP] [PATCH 02/29] Hugetlb: Migrating libhugetlbfs chunk-overcommit Tarun Sahu
                   ` (28 subsequent siblings)
  29 siblings, 2 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/brk_near_huge.c test

Test Description:
Certain kernels have a bug where brk() does not perform the same checks
that a MAP_FIXED mmap() will, allowing brk() to create a normal page VMA in
a hugepage only address region. This can lead to oopses or other badness.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap07.c  | 163 ++++++++++++++++++
 testcases/kernel/mem/hugetlb/lib/hugetlb.c    |  75 ++++++++
 testcases/kernel/mem/hugetlb/lib/hugetlb.h    |   5 +
 5 files changed, 245 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index f719217ab..f7ff81cb3 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -3,6 +3,7 @@ hugemmap02 hugemmap02
 hugemmap04 hugemmap04
 hugemmap05 hugemmap05
 hugemmap06 hugemmap06
+hugemmap07 hugemmap07
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index ff2910533..df5256ec8 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -4,6 +4,7 @@
 /hugetlb/hugemmap/hugemmap04
 /hugetlb/hugemmap/hugemmap05
 /hugetlb/hugemmap/hugemmap06
+/hugetlb/hugemmap/hugemmap07
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c
new file mode 100644
index 000000000..06fd0b86c
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c
@@ -0,0 +1,163 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ *
+ * Test Name: brk near hugepage
+ *
+ * Test Description: Certain kernels have a bug where brk() does not perform
+ * the same checks that a MAP_FIXED mmap() will, allowing brk() to create a
+ * normal page VMA in a hugepage only address region. This can lead to oopses
+ * or other badness.
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+#include "tst_safe_stdio.h"
+
+static char *verbose;
+static int  fd = -1;
+static char hfile[MAXPATHLEN];
+static long hpage_size;
+
+static int arch_has_slice_support(void)
+{
+#ifdef __powerpc64__
+	char mmu_type[16];
+	FILE *fp;
+
+	fp = SAFE_POPEN("cat /proc/cpuinfo | grep MMU | awk '{ print $3}'", "r");
+	if (fscanf(fp, "%s", mmu_type) < 0)
+		tst_brk(TBROK, "Failed to determine MMU type");
+
+	pclose(fp);
+	return strcmp(mmu_type, "Hash") == 0;
+#elif defined(__powerpc__) && !defined(PPC_NO_SEGMENTS)
+	return 1;
+#else
+	return 0;
+#endif
+}
+
+#ifdef __powerpc64__
+static void *next_chunk(void *addr)
+{
+	if (!arch_has_slice_support())
+		return PALIGN(addr, SAFE_READ_MEMINFO("Hugepagesize:")*1024);
+
+	if ((unsigned long)addr < 0x100000000UL)
+		/* 256M segments below 4G */
+		return PALIGN(addr, 0x10000000UL);
+	/* 1TB segments above */
+	return PALIGN(addr, 0x10000000000UL);
+}
+#elif defined(__powerpc__) && !defined(PPC_NO_SEGMENTS)
+static void *next_chunk(void *addr)
+{
+	return PALIGN(addr, 0x10000000UL);
+}
+#elif defined(__ia64__)
+static void *next_chunk(void *addr)
+{
+	return PALIGN(addr, 0x8000000000000000UL);
+}
+#else
+static void *next_chunk(void *addr)
+{
+	return PALIGN(addr, SAFE_READ_MEMINFO("Hugepagesize:")*1024);
+}
+#endif
+
+static void run_test(void)
+{
+	void *brk0, *hugemap_addr, *newbrk;
+	char *p;
+	int err;
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	brk0 = sbrk(0);
+	if (verbose)
+		tst_res(TINFO, "Initial break at %p", brk0);
+
+	hugemap_addr = next_chunk(brk0) + hpage_size;
+
+	p = SAFE_MMAP(hugemap_addr, hpage_size, PROT_READ|PROT_WRITE,
+			MAP_PRIVATE|MAP_FIXED, fd, 0);
+	if (p != hugemap_addr) {
+		tst_res(TFAIL, "mmap() at unexpected address %p instead of %p\n", p,
+		     hugemap_addr);
+		goto fail;
+	}
+
+	err = test_addr_huge((void *)p);
+	if (err != 1) {
+		tst_res(TFAIL, "Mapped address is not hugepage");
+		goto fail;
+	}
+
+	newbrk = next_chunk(brk0) + getpagesize();
+	err = brk((void *)newbrk);
+	if (err == -1) {
+		/* Failing the brk() is an acceptable kernel response */
+		tst_res(TPASS, "Failing the brk is an acceptable response");
+	} else {
+		/* Suceeding the brk() is acceptable iff the new memory is
+		 * properly accesible and we don't have a kernel blow up when
+		 * we touch it.
+		 */
+		memset(brk0, 0, newbrk-brk0);
+		tst_res(TPASS, "Succeding brk is acceptable, as memset confirms that "
+				"new memory is properly accessible without kernel blow up");
+	}
+	SAFE_MUNMAP(p, hpage_size);
+	SAFE_CLOSE(fd);
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 1)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {1, TST_REQUEST},
+};
diff --git a/testcases/kernel/mem/hugetlb/lib/hugetlb.c b/testcases/kernel/mem/hugetlb/lib/hugetlb.c
index 1204f21d2..d215c69dd 100644
--- a/testcases/kernel/mem/hugetlb/lib/hugetlb.c
+++ b/testcases/kernel/mem/hugetlb/lib/hugetlb.c
@@ -29,15 +29,19 @@
  *	getipckey()
  *	getuserid()
  *	rm_shm()
+ *	read_maps()
+ *	test_addr_huge()
  */
 
 #define TST_NO_DEFAULT_MAIN
+#define _GNU_SOURCE
 #include <sys/types.h>
 #include <sys/ipc.h>
 #include <sys/shm.h>
 #include <sys/time.h>
 #include <pwd.h>
 #include "hugetlb.h"
+#include "tst_safe_stdio.h"
 
 key_t shmkey;
 
@@ -111,3 +115,74 @@ void rm_shm(int shm_id)
 		tst_res(TINFO, "id = %d", shm_id);
 	}
 }
+
+#define MAPS_BUF_SZ 4096
+#define HUGETLBFS_MAGIC 0x958458f6
+
+int read_maps(unsigned long addr, char *buf)
+{
+	FILE *f;
+	char line[MAPS_BUF_SZ];
+	char *tmp;
+
+	f = SAFE_FOPEN("/proc/self/maps", "r");
+
+	while (1) {
+		unsigned long start, end, off, ino;
+		int ret;
+
+		tmp = fgets(line, MAPS_BUF_SZ, f);
+		if (!tmp)
+			break;
+
+		buf[0] = '\0';
+		ret = sscanf(line, "%lx-%lx %*s %lx %*s %ld %255s",
+			     &start, &end, &off, &ino,
+			     buf);
+		if ((ret < 4) || (ret > 5)) {
+			tst_res(TWARN, "Couldn't parse /proc/self/maps line: %s\n",
+			      line);
+			SAFE_FCLOSE(f);
+			return -1;
+		}
+
+		if ((start <= addr) && (addr < end)) {
+			SAFE_FCLOSE(f);
+			return 1;
+		}
+	}
+
+	SAFE_FCLOSE(f);
+	return 0;
+}
+
+int test_addr_huge(void *p)
+{
+	char name[256];
+	char *dirend;
+	int ret;
+	struct statfs64 sb;
+
+	ret = read_maps((unsigned long)p, name);
+	if (ret < 0)
+		return ret;
+	if (ret == 0) {
+		tst_res(TWARN, "Couldn't find address %p in /proc/self/maps\n", p);
+		return -1;
+	}
+
+	/* looks like a filename? */
+	if (name[0] != '/')
+		return 0;
+
+	/* Truncate the filename portion */
+	dirend = strrchr(name, '/');
+	if (dirend && dirend > name)
+		*dirend = '\0';
+
+	ret = statfs64(name, &sb);
+	if (ret)
+		return -1;
+
+	return (sb.f_type == HUGETLBFS_MAGIC);
+}
diff --git a/testcases/kernel/mem/hugetlb/lib/hugetlb.h b/testcases/kernel/mem/hugetlb/lib/hugetlb.h
index f75109f3e..c522314eb 100644
--- a/testcases/kernel/mem/hugetlb/lib/hugetlb.h
+++ b/testcases/kernel/mem/hugetlb/lib/hugetlb.h
@@ -20,6 +20,9 @@
 #include "old_tmpdir.h"
 #include "mem.h"
 
+#define ALIGN(x, a)	(((x) + (a) - 1) & ~((a) - 1))
+#define PALIGN(p, a) ((void *)ALIGN((unsigned long)(p), (a)))
+
 #define SHM_RD	0400
 #define SHM_WR	0200
 #define SHM_RW	(SHM_RD|SHM_WR)
@@ -39,5 +42,7 @@ extern key_t shmkey;			/* an IPC key generated by ftok() */
 int getipckey(void);
 int getuserid(char *user);
 void rm_shm(int shm_id);
+int test_addr_huge(void *p);
+int read_maps(unsigned long addr, char *buf);
 
 #endif /* hugetlb.h */
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 02/29] Hugetlb: Migrating libhugetlbfs chunk-overcommit
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-17 11:09   ` Cyril Hrubis
  2022-10-16 12:57 ` [LTP] [PATCH 03/29] Hugetlb: Migrating libhugetlbfs corrupt-by-cow-opt Tarun Sahu
                   ` (27 subsequent siblings)
  29 siblings, 1 reply; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/chunk-overcommit.c test

Test Description: Some kernel versions after hugepage demand allocation was
added used a dubious heuristic to check if there was enough hugepage space
available for a given mapping.  The number of not-already-instantiated
pages in the mapping was compared against the total hugepage free pool. It
was very easy to confuse this heuristic into overcommitting by allocating
hugepage memory in chunks, each less than the total available pool size but
together more than available.  This would generally lead to OOM SIGKILLs of
one process or another when it tried to instantiate pages beyond the
available pool.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap08.c  | 173 ++++++++++++++++++
 3 files changed, 175 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index f7ff81cb3..664f18827 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -4,6 +4,7 @@ hugemmap04 hugemmap04
 hugemmap05 hugemmap05
 hugemmap06 hugemmap06
 hugemmap07 hugemmap07
+hugemmap08 hugemmap08
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index df5256ec8..003ce422b 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -5,6 +5,7 @@
 /hugetlb/hugemmap/hugemmap05
 /hugetlb/hugemmap/hugemmap06
 /hugetlb/hugemmap/hugemmap07
+/hugetlb/hugemmap/hugemmap08
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c
new file mode 100644
index 000000000..63a731e09
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c
@@ -0,0 +1,173 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ *
+ * Test Name: Chunk Overcommit
+ *
+ * Test Description: Some kernel versions after hugepage demand allocation was
+ * added used a dubious heuristic to check if there was enough hugepage space
+ * available for a given mapping.  The number of not-already-instantiated pages
+ * in the mapping was compared against the total hugepage free pool. It was
+ * very easy to confuse this heuristic into overcommitting by allocating
+ * hugepage memory in chunks, each less than the total available pool size but
+ * together more than available.  This would generally lead to OOM SIGKILLs of
+ * one process or another when it tried to instantiate pages beyond the
+ * available pool.
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
+
+#include "hugetlb.h"
+
+#define PROC_OVERCOMMIT "/proc/sys/vm/nr_overcommit_hugepages"
+#define WITH_OVERCOMMIT 0
+#define WITHOUT_OVERCOMMIT 1
+
+static char *verbose;
+static char hfile[MAXPATHLEN];
+static int fd = -1;
+static long hpage_size;
+
+static void test_chunk_overcommit(void)
+{
+	unsigned long totpages, chunk1, chunk2;
+	void *p, *q;
+	pid_t child;
+	int status;
+
+	totpages = SAFE_READ_MEMINFO("HugePages_Free:");
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	chunk1 = (totpages / 2) + 1;
+	chunk2 = totpages - chunk1 + 1;
+
+	if (verbose)
+		tst_res(TINFO, "overcommit: %ld hugepages available: "
+		       "chunk1=%ld chunk2=%ld", totpages, chunk1, chunk2);
+
+	p = SAFE_MMAP(NULL, chunk1*hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
+		 fd, 0);
+
+	/* Can't use SAFE_MMAP here, as test needs to process the output of mmap */
+	q = mmap(NULL, chunk2*hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
+		 fd, chunk1*hpage_size);
+	if (q == MAP_FAILED) {
+		if (errno != ENOMEM) {
+			tst_res(TFAIL | TERRNO, "mmap() chunk2");
+			goto fail;
+		} else {
+			tst_res(TPASS, "Successful without overcommit pages");
+			goto pass;
+		}
+	}
+
+	if (verbose)
+		tst_res(TINFO, "Looks like we've overcommitted, testing...");
+	/* Looks like we're overcommited, but we need to confirm that
+	 * this is bad.  We touch it all in a child process because an
+	 * overcommit will generally lead to a SIGKILL which we can't
+	 * handle, of course.
+	 */
+	child = SAFE_FORK();
+
+	if (child == 0) {
+		memset(p, 0, chunk1*hpage_size);
+		memset(q, 0, chunk2*hpage_size);
+		exit(0);
+	}
+
+	SAFE_WAITPID(child, &status, 0);
+
+	if (WIFSIGNALED(status)) {
+		tst_res(TFAIL, "Killed by signal \"%s\" due to overcommit",
+		     strsignal(WTERMSIG(status)));
+		goto fail;
+	}
+
+	tst_res(TPASS, "Successful with overcommit pages");
+
+pass:
+	SAFE_MUNMAP(p, chunk1*hpage_size);
+	if (q && q != MAP_FAILED)
+		SAFE_MUNMAP(q, chunk2*hpage_size);
+	SAFE_CLOSE(fd);
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+}
+
+static void run_test(unsigned int test_type)
+{
+	long saved_oc_hugepages;
+
+	SAFE_FILE_LINES_SCANF(PROC_OVERCOMMIT, "%ld", &saved_oc_hugepages);
+	switch (test_type) {
+	case WITH_OVERCOMMIT:
+		if (saved_oc_hugepages > 0)
+			SAFE_FILE_PRINTF(PROC_OVERCOMMIT, "%d", 0);
+		break;
+	case WITHOUT_OVERCOMMIT:
+		if (saved_oc_hugepages < 0)
+			tst_brk(TCONF, "Kernel appears to lack dynamic hugetlb pool "
+					"support");
+		else if (saved_oc_hugepages == 0)
+			SAFE_FILE_PRINTF(PROC_OVERCOMMIT, "%d", 2);
+		break;
+	default:
+		tst_brk(TCONF, "Not a proper test type");
+		break;
+	}
+	test_chunk_overcommit();
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 3)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_huetlbfile%d", Hopt, getpid());
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.forks_child = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.tcnt = 2,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = run_test,
+	.hugepages = {5, TST_REQUEST},
+};
+
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 03/29] Hugetlb: Migrating libhugetlbfs corrupt-by-cow-opt
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 02/29] Hugetlb: Migrating libhugetlbfs chunk-overcommit Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-17 11:46   ` Cyril Hrubis
  2022-10-16 12:57 ` [LTP] [PATCH 04/29] Hugetlb: Migrating libhugetlbfs counters Tarun Sahu
                   ` (26 subsequent siblings)
  29 siblings, 1 reply; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/corrupt-by-cow-opt.c test

Test Description: Test sanity of cow optimization on page cache. If a page
in page cache has only 1 ref count, it is mapped for a private mapping
directly and is overwritten freely, so next time we access the page, we
can see corrupt data.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap09.c  | 102 ++++++++++++++++++
 3 files changed, 104 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 664f18827..e2ada7a97 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -5,6 +5,7 @@ hugemmap05 hugemmap05
 hugemmap06 hugemmap06
 hugemmap07 hugemmap07
 hugemmap08 hugemmap08
+hugemmap09 hugemmap09
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 003ce422b..1a242ffe0 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -6,6 +6,7 @@
 /hugetlb/hugemmap/hugemmap06
 /hugetlb/hugemmap/hugemmap07
 /hugetlb/hugemmap/hugemmap08
+/hugetlb/hugemmap/hugemmap09
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c
new file mode 100644
index 000000000..eeacf68a2
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2013 Joonsoo Kim, LG Electronics.
+ *
+ * Test Name: Corrupt by COW optimization
+ *
+ * Test Description: Test sanity of cow optimization on page cache. If a page
+ * in page cache has only 1 ref count, it is mapped for a private mapping
+ * directly and is overwritten freely, so next time we access the page, we
+ * can see corrupt data.
+ *
+ * HISTORY
+ *  Written by Joonsoo Kim
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+static char *verbose;
+static int  fd = -1;
+static char hfile[MAXPATHLEN];
+static long hpage_size;
+
+static void run_test(void)
+{
+	char *p;
+	char c;
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+	*p = 's';
+	if (verbose)
+		tst_res(TINFO, "Write %c to %p via shared mapping", *p, p);
+	SAFE_MUNMAP(p, hpage_size);
+
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+	*p = 'p';
+	if (verbose)
+		tst_res(TINFO, "Write %c to %p via private mapping", *p, p);
+	SAFE_MUNMAP(p, hpage_size);
+
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+	c = *p;
+	if (verbose)
+		tst_res(TINFO, "Read %c from %p via shared mapping", *p, p);
+	SAFE_MUNMAP(p, hpage_size);
+
+	/* Direct write from huge page */
+	if (c != 's') {
+		tst_res(TFAIL, "Data got corrupted.");
+		goto fail;
+	}
+	tst_res(TPASS, "Successful");
+	SAFE_CLOSE(fd);
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 2)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {2, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 04/29] Hugetlb: Migrating libhugetlbfs counters
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (2 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 03/29] Hugetlb: Migrating libhugetlbfs corrupt-by-cow-opt Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-17 12:02   ` Cyril Hrubis
  2022-10-18  3:38   ` Li Wang
  2022-10-16 12:57 ` [LTP] [PATCH 05/29] Hugetlb: Migrating libhugetlbfs directio Tarun Sahu
                   ` (25 subsequent siblings)
  29 siblings, 2 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/counters.c test

Test Description: This Test perform mmap and unmap and write operation on
hugetlb file based mapping. Mapping can be shared or private. and it
checks for Hugetlb counter (Total, Free, Reserve, Surplus) in /proc/meminfo
and compare them with expected (calculated) value. if all checks are
successful, the test passes.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap10.c  | 475 ++++++++++++++++++
 3 files changed, 477 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index e2ada7a97..8a56d52a3 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -6,6 +6,7 @@ hugemmap06 hugemmap06
 hugemmap07 hugemmap07
 hugemmap08 hugemmap08
 hugemmap09 hugemmap09
+hugemmap10 hugemmap10
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 1a242ffe0..e7def68cb 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -7,6 +7,7 @@
 /hugetlb/hugemmap/hugemmap07
 /hugetlb/hugemmap/hugemmap08
 /hugetlb/hugemmap/hugemmap09
+/hugetlb/hugemmap/hugemmap10
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c
new file mode 100644
index 000000000..107add669
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c
@@ -0,0 +1,475 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2007 David Gibson & Adam Litke, IBM Corporation.
+ *
+ * Test Name: Counters
+ *
+ * Test Description: This Test perform mmap and unmap and write operation on
+ * hugetlb file based mapping. Mapping can be shared or private. and it checks
+ * for Hugetlb counter (Total, Free, Reserve, Surplus) in /proc/meminfo and
+ * compare them with expected (calculated) value. if all checks are successful,
+ * the test passes.
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *
+ */
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+
+/* Global test configuration */
+#define PROC_NR_HUGEPAGES "/proc/sys/vm/nr_hugepages"
+#define PROC_OVERCOMMIT "/proc/sys/vm/nr_overcommit_hugepages"
+static long saved_nr_hugepages = -1;
+static long saved_oc_hugepages = -1;
+static long hpage_size;
+static int private_resv;
+static char *verbose;
+
+/* State arrays for our mmaps */
+#define NR_SLOTS	2
+#define SL_SETUP	0
+#define SL_TEST		1
+static char hfile[NR_SLOTS][MAXPATHLEN];
+static int map_fd[NR_SLOTS];
+static char *map_addr[NR_SLOTS];
+static unsigned long map_size[NR_SLOTS];
+static unsigned int touched[NR_SLOTS];
+
+/* Keep track of expected counter values */
+static long prev_total;
+static long prev_free;
+static long prev_resv;
+static long prev_surp;
+
+#define min(a, b) (((a) < (b)) ? (a) : (b))
+#define max(a, b) (((a) > (b)) ? (a) : (b))
+
+static void read_meminfo_huge(long *total, long *free, long *resv, long *surp)
+{
+	*total = SAFE_READ_MEMINFO("HugePages_Total:");
+	*free = SAFE_READ_MEMINFO("HugePages_Free:");
+	*resv = SAFE_READ_MEMINFO("HugePages_Rsvd:");
+	*surp = SAFE_READ_MEMINFO("HugePages_Surp:");
+}
+
+static int kernel_has_private_reservations(void)
+{
+	int fd;
+	long t, f, r, s;
+	long nt, nf, nr, ns;
+	void *map;
+
+	/* Read pool counters */
+	read_meminfo_huge(&t, &f, &r, &s);
+
+	fd = SAFE_OPEN(hfile[0], O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile[0]);
+	map = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+
+	/* Recheck the counters */
+	read_meminfo_huge(&nt, &nf, &nr, &ns);
+
+	SAFE_MUNMAP(map, hpage_size);
+	SAFE_CLOSE(fd);
+
+	/*
+	 * There are only three valid cases:
+	 * 1) If a surplus page was allocated to create a reservation, all
+	 *    four pool counters increment
+	 * 2) All counters remain the same except for Hugepages_Rsvd, then
+	 *    a reservation was created using an existing pool page.
+	 * 3) All counters remain the same, indicates that no reservation has
+	 *    been created
+	 */
+	if ((nt == t + 1) && (nf == f + 1) && (ns == s + 1) && (nr == r + 1)) {
+		return 1;
+	} else if ((nt == t) && (nf == f) && (ns == s)) {
+		if (nr == r + 1)
+			return 1;
+		else if (nr == r)
+			return 0;
+	} else {
+		tst_brk(TCONF, "%s: bad counter state - "
+		      "T:%li F:%li R:%li S:%li -> T:%li F:%li R:%li S:%li\n",
+			__func__, t, f, r, s, nt, nf, nr, ns);
+	}
+	return -1;
+}
+
+static void bad_value(int line, const char *name, long expect, long actual)
+{
+	tst_res(TFAIL, "Failure Line %i: Bad %s: expected %li, actual %li",
+			line, name, expect, actual);
+	tst_brk(TBROK, "Breaking.. as once one of counter is not expected, "
+			"it will cause other failure anyway");
+}
+
+static void verify_counters(int line, long et, long ef, long er, long es)
+{
+	long t, f, r, s;
+
+	/* Read pool counters */
+	read_meminfo_huge(&t, &f, &r, &s);
+
+	if (f < r)
+		tst_res(TWARN, "HugePages_Free < HugePages_Rsvd");
+
+	/* Check actual values against expected values */
+	if (t != et)
+		bad_value(line, "HugePages_Total", et, t);
+
+	if (f != ef)
+		bad_value(line, "HugePages_Free", ef, f);
+
+	if (r != er)
+		bad_value(line, "HugePages_Rsvd", er, r);
+
+	if (s != es)
+		bad_value(line, "HugePages_Surp", es, s);
+
+	/* Everything's good.  Update counters */
+	prev_total = t;
+	prev_free = f;
+	prev_resv = r;
+	prev_surp = s;
+}
+
+/* Memory operations:
+ * Each of these has a predefined effect on the counters
+ */
+#define persistent_huge_pages (et - es)
+static void _set_nr_hugepages(long count, int line)
+{
+	long min_size;
+	long et, ef, er, es;
+
+	SAFE_FILE_PRINTF(PROC_NR_HUGEPAGES, "%lu", count);
+
+	/* The code below is based on set_max_huge_pages in mm/hugetlb.c */
+	es = prev_surp;
+	et = prev_total;
+	ef = prev_free;
+	er = prev_resv;
+
+	/*
+	 * Increase the pool size
+	 * First take pages out of surplus state.  Then make up the
+	 * remaining difference by allocating fresh huge pages.
+	 */
+	while (es && count > persistent_huge_pages)
+		es--;
+	while (count > persistent_huge_pages) {
+		et++;
+		ef++;
+	}
+	if (count >= persistent_huge_pages)
+		goto out;
+
+	/*
+	 * Decrease the pool size
+	 * First return free pages to the buddy allocator (being careful
+	 * to keep enough around to satisfy reservations).  Then place
+	 * pages into surplus state as needed so the pool will shrink
+	 * to the desired size as pages become free.
+	 */
+	min_size = MAX(count, er + et - ef);
+	while (min_size < persistent_huge_pages) {
+		ef--;
+		et--;
+	}
+	while (count < persistent_huge_pages)
+		es++;
+
+out:
+	verify_counters(line, et, ef, er, es);
+}
+#define set_nr_hugepages(c) _set_nr_hugepages(c, __LINE__)
+
+static void _map(int s, int hpages, int flags, int line)
+{
+	long et, ef, er, es;
+
+	map_fd[s] = SAFE_OPEN(hfile[s], O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile[s]);
+	map_size[s] = hpages * hpage_size;
+	map_addr[s] = SAFE_MMAP(NULL, map_size[s], PROT_READ|PROT_WRITE, flags,
+				map_fd[s], 0);
+	touched[s] = 0;
+
+	et = prev_total;
+	ef = prev_free;
+	er = prev_resv;
+	es = prev_surp;
+
+	/*
+	 * When using MAP_SHARED, a reservation will be created to guarantee
+	 * pages to the process.  If not enough pages are available to
+	 * satisfy the reservation, surplus pages are added to the pool.
+	 * NOTE: This code assumes that the whole mapping needs to be
+	 * reserved and hence, will not work with partial reservations.
+	 *
+	 * If the kernel supports private reservations, then MAP_PRIVATE
+	 * mappings behave like MAP_SHARED at mmap time.  Otherwise,
+	 * no counter updates will occur.
+	 */
+	if ((flags & MAP_SHARED) || private_resv) {
+		unsigned long shortfall = 0;
+
+		if (hpages + prev_resv > prev_free)
+			shortfall = hpages - prev_free + prev_resv;
+		et += shortfall;
+		ef = prev_free + shortfall;
+		er = prev_resv + hpages;
+		es = prev_surp + shortfall;
+	}
+
+	verify_counters(line, et, ef, er, es);
+}
+#define map(s, h, f) _map(s, h, f, __LINE__)
+
+static void _unmap(int s, int hpages, int flags, int line)
+{
+	long et, ef, er, es;
+	unsigned long i;
+
+	SAFE_MUNMAP(map_addr[s], map_size[s]);
+	SAFE_CLOSE(map_fd[s]);
+	map_addr[s] = NULL;
+	map_size[s] = 0;
+
+	et = prev_total;
+	ef = prev_free;
+	er = prev_resv;
+	es = prev_surp;
+
+	/*
+	 * When a VMA is unmapped, the instantiated (touched) pages are
+	 * freed.  If the pool is in a surplus state, pages are freed to the
+	 * buddy allocator, otherwise they go back into the hugetlb pool.
+	 * NOTE: This code assumes touched pages have only one user.
+	 */
+	for (i = 0; i < touched[s]; i++) {
+		if (es) {
+			et--;
+			es--;
+		} else
+			ef++;
+	}
+
+	/*
+	 * mmap may have created some surplus pages to accommodate a
+	 * reservation.  If those pages were not touched, then they will
+	 * not have been freed by the code above.  Free them here.
+	 */
+	if ((flags & MAP_SHARED) || private_resv) {
+		int unused_surplus = MIN(hpages - touched[s], es);
+
+		et -= unused_surplus;
+		ef -= unused_surplus;
+		er -= hpages - touched[s];
+		es -= unused_surplus;
+	}
+
+	verify_counters(line, et, ef, er, es);
+}
+#define unmap(s, h, f) _unmap(s, h, f, __LINE__)
+
+static void _touch(int s, int hpages, int flags, int line)
+{
+	long et, ef, er, es;
+	int nr;
+	char *c;
+
+	for (c = map_addr[s], nr = hpages;
+			hpages && c < map_addr[s] + map_size[s];
+			c += hpage_size, nr--)
+		*c = (char) (nr % 2);
+	/*
+	 * Keep track of how many pages were touched since we can't easily
+	 * detect that from user space.
+	 * NOTE: Calling this function more than once for a mmap may yield
+	 * results you don't expect.  Be careful :)
+	 */
+	touched[s] = MAX(touched[s], hpages);
+
+	/*
+	 * Shared (and private when supported) mappings and consume resv pages
+	 * that were previously allocated. Also deduct them from the free count.
+	 *
+	 * Unreserved private mappings may need to allocate surplus pages to
+	 * satisfy the fault.  The surplus pages become part of the pool
+	 * which could elevate total, free, and surplus counts.  resv is
+	 * unchanged but free must be decreased.
+	 */
+	if (flags & MAP_SHARED || private_resv) {
+		et = prev_total;
+		ef = prev_free - hpages;
+		er = prev_resv - hpages;
+		es = prev_surp;
+	} else {
+		if (hpages + prev_resv > prev_free)
+			et = prev_total + (hpages - prev_free + prev_resv);
+		else
+			et = prev_total;
+		er = prev_resv;
+		es = prev_surp + et - prev_total;
+		ef = prev_free - hpages + et - prev_total;
+	}
+	verify_counters(line, et, ef, er, es);
+}
+#define touch(s, h, f) _touch(s, h, f, __LINE__)
+
+static void test_counters(char *desc, int base_nr)
+{
+	if (verbose)
+		tst_res(TINFO, "%s...", desc);
+	set_nr_hugepages(base_nr);
+
+	/* untouched, shared mmap */
+	map(SL_TEST, 1, MAP_SHARED);
+	unmap(SL_TEST, 1, MAP_SHARED);
+
+	/* untouched, private mmap */
+	map(SL_TEST, 1, MAP_PRIVATE);
+	unmap(SL_TEST, 1, MAP_PRIVATE);
+
+	/* touched, shared mmap */
+	map(SL_TEST, 1, MAP_SHARED);
+	touch(SL_TEST, 1, MAP_SHARED);
+	unmap(SL_TEST, 1, MAP_SHARED);
+
+	/* touched, private mmap */
+	map(SL_TEST, 1, MAP_PRIVATE);
+	touch(SL_TEST, 1, MAP_PRIVATE);
+	unmap(SL_TEST, 1, MAP_PRIVATE);
+
+	/* Explicit resizing during outstanding surplus */
+	/* Consume surplus when growing pool */
+	map(SL_TEST, 2, MAP_SHARED);
+	set_nr_hugepages(max(base_nr, 1));
+
+	/* Add pages once surplus is consumed */
+	set_nr_hugepages(max(base_nr, 3));
+
+	/* Release free huge pages first */
+	set_nr_hugepages(max(base_nr, 2));
+
+	/* When shrinking beyond committed level, increase surplus */
+	set_nr_hugepages(base_nr);
+
+	/* Upon releasing the reservation, reduce surplus counts */
+	unmap(SL_TEST, 2, MAP_SHARED);
+	if (verbose)
+		tst_res(TINFO, "OK");
+}
+
+static void per_iteration_cleanup(void)
+{
+	for (int nr = 0; nr < NR_SLOTS; nr++) {
+		if (map_fd[nr] >= 0)
+			SAFE_CLOSE(map_fd[nr]);
+	}
+	if (hpage_size <= 0)
+		return;
+	if (saved_nr_hugepages >= 0)
+		SAFE_FILE_PRINTF(PROC_NR_HUGEPAGES, "%ld", saved_nr_hugepages);
+	if (saved_oc_hugepages >= 0)
+		SAFE_FILE_PRINTF(PROC_OVERCOMMIT, "%ld", saved_oc_hugepages);
+}
+
+static void run_test(void)
+{
+	int base_nr = 0;
+
+	saved_nr_hugepages = SAFE_READ_MEMINFO("HugePages_Total:");
+
+	/* Verify Dynamic Pool support */
+	SAFE_FILE_LINES_SCANF(PROC_OVERCOMMIT, "%ld", &saved_oc_hugepages);
+	if (saved_oc_hugepages < 0)
+		tst_brk(TCONF, "Kernel appears to lack dynamic hugetlb pool support");
+
+	SAFE_FILE_PRINTF(PROC_OVERCOMMIT, "%d", 3);
+
+	private_resv = kernel_has_private_reservations();
+	/*
+	 * This test case should require a maximum of 3 huge pages.
+	 * Run through the battery of tests multiple times, with an increasing
+	 * base pool size.  This alters the circumstances under which surplus
+	 * pages need to be allocated and increases the corner cases tested.
+	 */
+	for (base_nr = 0; base_nr <= 3; base_nr++) {
+		if (verbose)
+			tst_res(TINFO, "Base pool size: %i", base_nr);
+		/* Run the tests with a clean slate */
+		test_counters("Clean", base_nr);
+
+		/* Now with a pre-existing untouched, shared mmap */
+		map(SL_SETUP, 1, MAP_SHARED);
+		test_counters("Untouched, shared", base_nr);
+		unmap(SL_SETUP, 1, MAP_SHARED);
+
+		/* Now with a pre-existing untouched, private mmap */
+		map(SL_SETUP, 1, MAP_PRIVATE);
+		test_counters("Untouched, private", base_nr);
+		unmap(SL_SETUP, 1, MAP_PRIVATE);
+
+		/* Now with a pre-existing touched, shared mmap */
+		map(SL_SETUP, 1, MAP_SHARED);
+		touch(SL_SETUP, 1, MAP_SHARED);
+		test_counters("Touched, shared", base_nr);
+		unmap(SL_SETUP, 1, MAP_SHARED);
+
+		/* Now with a pre-existing touched, private mmap */
+		map(SL_SETUP, 1, MAP_PRIVATE);
+		touch(SL_SETUP, 1, MAP_PRIVATE);
+		test_counters("Touched, private", base_nr);
+		unmap(SL_SETUP, 1, MAP_PRIVATE);
+	}
+	tst_res(TPASS, "Hugepages Counters works as expected.");
+	per_iteration_cleanup();
+}
+
+static void setup(void)
+{
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+	for (int nr = 0; nr < NR_SLOTS; nr++) {
+		snprintf(hfile[nr], sizeof(hfile[nr]), "%s/ltp_hugetlbfile%d_%d",
+				Hopt, getpid(), nr);
+	}
+
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	per_iteration_cleanup();
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {0, TST_REQUEST},
+};
+
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 05/29] Hugetlb: Migrating libhugetlbfs directio
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (3 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 04/29] Hugetlb: Migrating libhugetlbfs counters Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-17 12:28   ` Cyril Hrubis
  2022-10-16 12:57 ` [LTP] [PATCH 06/29] Hugetlb: Migrating libhugetlbfs fadvise_reserve Tarun Sahu
                   ` (24 subsequent siblings)
  29 siblings, 1 reply; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/direct.c test

Test Description: This Test perform Direct Write/Read from/To hugetlbfs
file which is mapped to process address space. The test is checking if it
succeeds and data written or read is not corrupted.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap11.c  | 111 ++++++++++++++++++
 3 files changed, 113 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 8a56d52a3..b9ee7227d 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -7,6 +7,7 @@ hugemmap07 hugemmap07
 hugemmap08 hugemmap08
 hugemmap09 hugemmap09
 hugemmap10 hugemmap10
+hugemmap11 hugemmap11
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index e7def68cb..3e64b67be 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -8,6 +8,7 @@
 /hugetlb/hugemmap/hugemmap08
 /hugetlb/hugemmap/hugemmap09
 /hugetlb/hugemmap/hugemmap10
+/hugetlb/hugemmap/hugemmap11
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c
new file mode 100644
index 000000000..c4dbe76e6
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c
@@ -0,0 +1,111 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ *
+ * Test Name: Direct I/O
+ *
+ * Test Description: This Test perform Direct Write/Read from/To hugetlbfs file
+ * which is mapped to process address space. The test is checking if it
+ * succeeds and data written or read is not corrupted.
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *
+ */
+
+#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 P0 "ffffffff"
+#define IOSZ 4096
+#define NHFILE "ltp_nfile"
+
+static char buf[IOSZ] __attribute__((aligned(IOSZ)));
+static int  fd = -1, nfd = -1;
+static char hfile[MAXPATHLEN];
+static long hpage_size;
+
+static void run_test(void)
+{
+	void *p;
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	nfd = SAFE_OPEN(NHFILE, O_CREAT|O_EXCL|O_RDWR|O_DIRECT, 0600);
+	SAFE_UNLINK(NHFILE);
+
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+	memcpy(p, P0, 8);
+
+	/* Direct write from huge page */
+	SAFE_WRITE(1, nfd, p, IOSZ);
+	SAFE_LSEEK(nfd, 0, SEEK_SET);
+
+	/* Check for accuracy */
+	SAFE_READ(1, nfd, buf, IOSZ);
+	if (memcmp(P0, buf, 8)) {
+		tst_res(TFAIL, "Memory mismatch after Direct-IO write");
+		goto fail;
+	}
+	SAFE_LSEEK(nfd, 0, SEEK_SET);
+
+	/* Direct read to huge page */
+	memset(p, 0, IOSZ);
+	SAFE_READ(1, nfd, p, IOSZ);
+
+	/* Check for accuracy */
+	if (memcmp(p, P0, 8)) {
+		tst_res(TFAIL, "Memory mismatch after Direct-IO read");
+		goto fail;
+	}
+	tst_res(TPASS, "Successfully tested Hugepage Direct I/O");
+	SAFE_MUNMAP(p, hpage_size);
+	SAFE_CLOSE(fd);
+	SAFE_CLOSE(nfd);
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 1)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	if (nfd >= 0)
+		SAFE_CLOSE(nfd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {1, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 06/29] Hugetlb: Migrating libhugetlbfs fadvise_reserve
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (4 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 05/29] Hugetlb: Migrating libhugetlbfs directio Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-17 12:35   ` Cyril Hrubis
  2022-10-16 12:57 ` [LTP] [PATCH 07/29] Hugetlb: Migrating libhugetlbfs fallocate_align Tarun Sahu
                   ` (23 subsequent siblings)
  29 siblings, 1 reply; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/fadvise_reserve.c test

Test Description: fadvise() 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's fixed in kernel by 'commit
f2deae9d4e70 ("Remove implementation of readpage from the hugetlbfs_aops")'

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap12.c  | 114 ++++++++++++++++++
 3 files changed, 116 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index b9ee7227d..b019c4195 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -8,6 +8,7 @@ hugemmap08 hugemmap08
 hugemmap09 hugemmap09
 hugemmap10 hugemmap10
 hugemmap11 hugemmap11
+hugemmap12 hugemmap12
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 3e64b67be..ec250592d 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -9,6 +9,7 @@
 /hugetlb/hugemmap/hugemmap09
 /hugetlb/hugemmap/hugemmap10
 /hugetlb/hugemmap/hugemmap11
+/hugetlb/hugemmap/hugemmap12
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c
new file mode 100644
index 000000000..9773199ca
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 IBM Corporation.
+ *
+ * Test Name: fadvise_reserve
+ *
+ * Test Description: fadvise() 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's fixed in kernel by commit
+ * f2deae9d4e70793568ef9e85d227abb7bef5b622.
+ *
+ * HISTORY
+ *  Written by Mel Gorman
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+static long hpage_size;
+static int  fd = -1;
+static char hfile[MAXPATHLEN];
+static char *verbose;
+
+static void run_test(void)
+{
+	void *p;
+	unsigned long initial_rsvd, map_rsvd, fadvise_rsvd, end_rsvd;
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	initial_rsvd = SAFE_READ_MEMINFO("HugePages_Rsvd:");
+	if (verbose)
+		tst_res(TINFO, "Reserve count before map: %lu", initial_rsvd);
+
+	/* mmap a region and record reservations */
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
+		 fd, 0);
+	map_rsvd = SAFE_READ_MEMINFO("HugePages_Rsvd:");
+	if (verbose)
+		tst_res(TINFO, "Reserve count after map: %lu", map_rsvd);
+
+	/* fadvise the region and record reservations */
+	if (posix_fadvise(fd, 0, hpage_size, POSIX_FADV_WILLNEED) == -1) {
+		tst_res(TFAIL|TERRNO, "fadvise()");
+		goto fail;
+	}
+	fadvise_rsvd = SAFE_READ_MEMINFO("HugePages_Rsvd:");
+	if (verbose)
+		tst_res(TINFO, "Reserve count after fadvise: %lu", fadvise_rsvd);
+
+	/* Write the region */
+	memset(p, 1, hpage_size);
+
+	/* Free region */
+	SAFE_MUNMAP(p, hpage_size);
+	SAFE_CLOSE(fd);
+	end_rsvd = SAFE_READ_MEMINFO("HugePages_Rsvd:");
+	if (verbose)
+		tst_res(TINFO, "Reserve count after close: %lu", end_rsvd);
+
+	/* Reserve count should match initial reserve count */
+	if (end_rsvd != initial_rsvd) {
+		tst_res(TFAIL, "Reserve leaked: %lu != %lu", end_rsvd, initial_rsvd);
+		goto fail;
+	}
+	tst_res(TPASS, "Successful");
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 1)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {1, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 07/29] Hugetlb: Migrating libhugetlbfs fallocate_align
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (5 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 06/29] Hugetlb: Migrating libhugetlbfs fadvise_reserve Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-17 12:45   ` Cyril Hrubis
  2022-10-16 12:57 ` [LTP] [PATCH 08/29] Hugetlb: Migrating libhugetlbfs fallocate_basic Tarun Sahu
                   ` (22 subsequent siblings)
  29 siblings, 1 reply; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/fallocate_align.c test

Test Description: It tests alignment of fallocate arguments. fallocate will
take non-huge page aligned offsets and addresses.  However, operations are
only performed on huge pages.  This is different that than fallocate
behavior in "normal" filesystems.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   2 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugefallocate/Makefile |  10 +
 .../hugetlb/hugefallocate/hugefallocate01.c   | 187 ++++++++++++++++++
 4 files changed, 200 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/Makefile
 create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate01.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index b019c4195..ca92dfcff 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -1,3 +1,5 @@
+hugefallocate01 hugefallocate01
+
 hugemmap01 hugemmap01
 hugemmap02 hugemmap02
 hugemmap04 hugemmap04
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index ec250592d..cafdb5259 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -1,4 +1,5 @@
 /cpuset/cpuset01
+/hugetlb/hugefallocate/hugefallocate01
 /hugetlb/hugemmap/hugemmap01
 /hugetlb/hugemmap/hugemmap02
 /hugetlb/hugemmap/hugemmap04
diff --git a/testcases/kernel/mem/hugetlb/hugefallocate/Makefile b/testcases/kernel/mem/hugetlb/hugefallocate/Makefile
new file mode 100644
index 000000000..77ebb0aef
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugefallocate/Makefile
@@ -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
+
diff --git a/testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate01.c b/testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate01.c
new file mode 100644
index 000000000..a4dae9812
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate01.c
@@ -0,0 +1,187 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2015 Mike Kravetz, Oracle Corporation
+ *
+ * Test Name: fallocate_align
+ *
+ * Test Description: It tests alignment of fallocate arguments. fallocate will
+ * take non-huge page aligned offsets and addresses.  However, operations are
+ * only performed on huge pages.  This is different that than fallocate
+ * behavior in "normal" filesystems.
+ *
+ * HISTORY
+ *  Written by Mike Kravetz
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+static int  fd = -1;
+static char hfile[MAXPATHLEN];
+static long hpage_size;
+
+static void run_test(void)
+{
+	int err;
+	unsigned long free_before, free_after;
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	free_before = SAFE_READ_MEMINFO("HugePages_Free:");
+
+	/*
+	 * First preallocate file with just 1 byte.  Allocation sizes
+	 * are rounded up, so we should get an entire huge page.
+	 */
+	err = fallocate(fd, 0, 0, 1);
+	if (err) {
+		if (errno == EOPNOTSUPP)
+			tst_brk(TCONF, "Operation Not Supported");
+		tst_res(TFAIL|TERRNO, "fallocate()");
+		goto fail;
+	}
+
+	free_after = SAFE_READ_MEMINFO("HugePages_Free:");
+	if (free_before - free_after != 1) {
+		tst_res(TFAIL, "fallocate 1 byte did not preallocate entire huge page");
+		goto fail;
+	}
+
+	/*
+	 * Now punch a hole with just 1 byte.  On hole punch, sizes are
+	 * rounded down.  So, this operation should not create a hole.
+	 */
+	err = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
+			0, 1);
+	if (err) {
+		tst_res(TFAIL|TERRNO, "fallocate(FALLOC_FL_PUNCH_HOLE)");
+		goto fail;
+	}
+
+	free_after = SAFE_READ_MEMINFO("HugePages_Free:");
+	if (free_after == free_before) {
+		tst_res(TFAIL, "fallocate hole punch 1 byte free'ed a huge page");
+		goto fail;
+	}
+
+	/*
+	 * Now punch a hole with of 2 * hpage_size - 1 byte.  This size
+	 * should be rounded down to a single huge page and the hole created.
+	 */
+	err = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
+			0, (2 * hpage_size) - 1);
+	if (err) {
+		tst_res(TFAIL|TERRNO, "fallocate(FALLOC_FL_PUNCH_HOLE)");
+		goto fail;
+	}
+
+	free_after = SAFE_READ_MEMINFO("HugePages_Free:");
+	if (free_after != free_before) {
+		tst_res(TFAIL, "fallocate hole punch 2 * hpage_size - 1 byte did not"
+				" free huge page");
+		goto fail;
+	}
+
+	/*
+	 * Perform a preallocate operation with offset 1 and size of
+	 * hpage_size.  The offset should be rounded down and the
+	 * size rounded up to preallocate two huge pages.
+	 */
+	err = fallocate(fd, 0, 1, hpage_size);
+	if (err) {
+		tst_res(TFAIL, "fallocate()");
+		goto fail;
+	}
+
+	free_after = SAFE_READ_MEMINFO("HugePages_Free:");
+	if (free_before - free_after != 2) {
+		tst_res(TFAIL, "fallocate 1 byte offset, huge page size did not"
+				" preallocate two huge pages");
+		goto fail;
+	}
+
+	/*
+	 * The hole punch code will only delete 'whole' huge pags that are
+	 * in the specified range.  The offset is rounded up, and (offset
+	 * + size) is rounded down to determine the huge pages to be deleted.
+	 * In this case, after rounding the range is (hpage_size, hpage_size).
+	 * So, no pages should be deleted.
+	 */
+	err = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
+			1, hpage_size);
+	if (err) {
+		tst_res(TFAIL|TERRNO, "fallocate(FALLOC_FL_PUNCH_HOLE)");
+		goto fail;
+	}
+
+	free_after = SAFE_READ_MEMINFO("HugePages_Free:");
+	if (free_before - free_after != 2) {
+		tst_res(TFAIL, "fallocate hole punch 1 byte offset, huge page size"
+				" incorrectly deleted a huge page");
+		goto fail;
+	}
+
+	/*
+	 * To delete both huge pages, the range passed to hole punch must
+	 * overlap the allocated pages
+	 */
+	err = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
+			0, 2 * hpage_size);
+	if (err) {
+		tst_res(TFAIL|TERRNO, "fallocate(FALLOC_FL_PUNCH_HOLE)");
+		goto fail;
+	}
+
+	free_after = SAFE_READ_MEMINFO("HugePages_Free:");
+	if (free_after != free_before) {
+		tst_res(TFAIL, "fallocate hole punch did not delete two huge pages");
+		goto fail;
+	}
+	tst_res(TPASS, "Successful");
+	SAFE_CLOSE(fd);
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 2)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {2, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 08/29] Hugetlb: Migrating libhugetlbfs fallocate_basic
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (6 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 07/29] Hugetlb: Migrating libhugetlbfs fallocate_align Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-17 12:53   ` Cyril Hrubis
  2022-10-16 12:57 ` [LTP] [PATCH 09/29] Hugetlb: Migrating libhugetlbfs fork-cow Tarun Sahu
                   ` (21 subsequent siblings)
  29 siblings, 1 reply; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/fallocate_basic.c test

Test Description: It tests basic fallocate functionality in hugetlbfs.
Preallocate huge pages to a file in hugetlbfs, and then remove the pages
via hole punch.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../hugetlb/hugefallocate/hugefallocate02.c   | 116 ++++++++++++++++++
 3 files changed, 118 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index ca92dfcff..ec1fc2515 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -1,4 +1,5 @@
 hugefallocate01 hugefallocate01
+hugefallocate02 hugefallocate02
 
 hugemmap01 hugemmap01
 hugemmap02 hugemmap02
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index cafdb5259..c0906f3d3 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -1,5 +1,6 @@
 /cpuset/cpuset01
 /hugetlb/hugefallocate/hugefallocate01
+/hugetlb/hugefallocate/hugefallocate02
 /hugetlb/hugemmap/hugemmap01
 /hugetlb/hugemmap/hugemmap02
 /hugetlb/hugemmap/hugemmap04
diff --git a/testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c b/testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c
new file mode 100644
index 000000000..54e1e42f4
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c
@@ -0,0 +1,116 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2015 Mike Kravetz, Oracle Corporation
+ *
+ * Test Name: fallocate_basic
+ *
+ * Test Description: It tests basic fallocate functionality in hugetlbfs.
+ * Preallocate huge pages to a file in hugetlbfs, and then remove the pages
+ * via hole punch.
+ *
+ * HISTORY
+ *  Written by Mike Kravetz
+ *
+ */
+
+#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 MAX_PAGES_TO_USE 5
+
+static int  fd = -1;
+static char hfile[MAXPATHLEN];
+static long hpage_size;
+
+static void run_test(void)
+{
+	long nr_hpages_free;
+	int err;
+	unsigned long max_iterations;
+	unsigned long free_before, free_after;
+
+	nr_hpages_free = SAFE_READ_MEMINFO("HugePages_Free:");
+	max_iterations = MIN(nr_hpages_free, MAX_PAGES_TO_USE);
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	free_before = SAFE_READ_MEMINFO("HugePages_Free:");
+
+	/* First preallocate file with max_iterations pages */
+	err = fallocate(fd, 0, 0, hpage_size * max_iterations);
+	if (err) {
+		if (errno == EOPNOTSUPP)
+			tst_brk(TCONF, "fallocate() Operation is not supported");
+		tst_res(TFAIL|TERRNO, "fallocate()");
+		goto fail;
+	}
+
+	free_after = SAFE_READ_MEMINFO("HugePages_Free:");
+	if (free_before - free_after != max_iterations) {
+		tst_res(TFAIL, "fallocate did not preallocate %lu huge pages",
+							max_iterations);
+		goto fail;
+	}
+
+	/* Now punch a hole of the same size */
+	err = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
+			0, hpage_size * max_iterations);
+	if (err) {
+		tst_res(TFAIL|TERRNO, "fallocate(FALLOC_FL_PUNCH_HOLE)");
+		goto fail;
+	}
+
+	free_after = SAFE_READ_MEMINFO("HugePages_Free:");
+	if (free_after != free_before) {
+		tst_res(TFAIL, "fallocate hole punch did not release %lu huge pages",
+							max_iterations);
+		goto fail;
+	}
+
+	tst_res(TPASS, "Successful");
+	SAFE_CLOSE(fd);
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 2)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {2, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 09/29] Hugetlb: Migrating libhugetlbfs fork-cow
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (7 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 08/29] Hugetlb: Migrating libhugetlbfs fallocate_basic Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-17 13:45   ` Cyril Hrubis
  2022-10-18  6:56   ` Li Wang
  2022-10-16 12:57 ` [LTP] [PATCH 10/29] Hugetlb: Migrating libhugetlbfs huge_at_4GB_normal_below Tarun Sahu
                   ` (20 subsequent siblings)
  29 siblings, 2 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

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.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   2 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugefork/Makefile      |  10 +
 .../kernel/mem/hugetlb/hugefork/hugefork01.c  | 220 ++++++++++++++++++
 4 files changed, 233 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugefork/Makefile
 create mode 100644 testcases/kernel/mem/hugetlb/hugefork/hugefork01.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index ec1fc2515..4c16e1e7c 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -1,6 +1,8 @@
 hugefallocate01 hugefallocate01
 hugefallocate02 hugefallocate02
 
+hugefork01 hugefork01
+
 hugemmap01 hugemmap01
 hugemmap02 hugemmap02
 hugemmap04 hugemmap04
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index c0906f3d3..adea760c7 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -1,6 +1,7 @@
 /cpuset/cpuset01
 /hugetlb/hugefallocate/hugefallocate01
 /hugetlb/hugefallocate/hugefallocate02
+/hugetlb/hugefork/hugefork01
 /hugetlb/hugemmap/hugemmap01
 /hugetlb/hugemmap/hugemmap02
 /hugetlb/hugemmap/hugemmap04
diff --git a/testcases/kernel/mem/hugetlb/hugefork/Makefile b/testcases/kernel/mem/hugetlb/hugefork/Makefile
new file mode 100644
index 000000000..77ebb0aef
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugefork/Makefile
@@ -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
+
diff --git a/testcases/kernel/mem/hugetlb/hugefork/hugefork01.c b/testcases/kernel/mem/hugetlb/hugefork/hugefork01.c
new file mode 100644
index 000000000..096ff0c4d
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugefork/hugefork01.c
@@ -0,0 +1,220 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2008 David Gibson, IBM Corporation.
+ *
+ * Test Name: fork COW
+ *
+ * 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.
+ *
+ * HISTORY
+ *  Written by David Gibson
+ *
+ */
+
+#define _GNU_SOURCE
+
+
+#include <sys/shm.h>
+#include <sys/wait.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+#define RANDOM_CONSTANT		0x1234ABCD
+#define OTHER_CONSTANT		0xfeef5678
+
+static int  fd = -1;
+static char hfile[MAXPATHLEN];
+static long hpage_size;
+static char *verbose;
+
+/*
+ * The parent uses this to check if the child terminated badly.
+ */
+static void sigchld_handler(int signum, siginfo_t *si, void *uc)
+{
+	(void)signum;
+	(void)uc;
+	if (WEXITSTATUS(si->si_status) != 0) {
+		tst_res(TFAIL, "Child failed: %d", WEXITSTATUS(si->si_status));
+		goto fail;
+	}
+	if (WIFSIGNALED(si->si_status)) {
+		tst_res(TFAIL, "Child recived signal %s",
+				strsignal(WTERMSIG(si->si_status)));
+		goto fail;
+	}
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+}
+
+static void run_test(void)
+{
+	int status;
+	void *syncarea;
+	volatile unsigned int *p;
+	volatile unsigned int *trigger, *child_readback;
+	int parent_readback;
+	pid_t pid;
+	struct sigaction sa = {
+		.sa_sigaction = sigchld_handler,
+		.sa_flags = SA_SIGINFO,
+	};
+
+	/* Get a shared normal page for synchronization */
+	if (verbose)
+		tst_res(TINFO, "Mapping synchronization area..");
+	syncarea = SAFE_MMAP(NULL, getpagesize(), PROT_READ|PROT_WRITE,
+			MAP_SHARED|MAP_ANONYMOUS, -1, 0);
+	if (verbose)
+		tst_res(TINFO, "done");
+
+	trigger = syncarea;
+	*trigger = 0;
+
+	child_readback = trigger + 1;
+	*child_readback = 0;
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	if (verbose)
+		tst_res(TINFO, "Mapping hugepage area...");
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+	if (verbose)
+		tst_res(TINFO, "mapped at %p", p);
+	/* Touch the page for write in parent */
+	if (verbose)
+		tst_res(TINFO, "Parent writes pre-fork...");
+	*p = RANDOM_CONSTANT;
+	if (verbose)
+		tst_res(TINFO, "%x", RANDOM_CONSTANT);
+
+	SAFE_SIGACTION(SIGCHLD, &sa, NULL);
+
+	pid = SAFE_FORK();
+
+	if (pid != 0) {
+		/* Parent */
+		if (verbose)
+			tst_res(TINFO, "Parent writes post-fork...");
+		*p = ~RANDOM_CONSTANT;
+		if (verbose)
+			tst_res(TINFO, "~RANDOM_CONSTANT: %x", ~RANDOM_CONSTANT);
+		*trigger = 1;
+
+		while (*trigger != 2)
+			;
+
+		if (verbose)
+			tst_res(TINFO, "Parent reads..");
+		parent_readback = *p;
+		if (verbose)
+			tst_res(TINFO, "Parent readback: %x", parent_readback);
+		*trigger = 3;
+	} else {
+		/* Child */
+		if (verbose)
+			tst_res(TINFO, "Child starts..");
+		while (*trigger != 1)
+			;
+
+		if (verbose)
+			tst_res(TINFO, "Child reads...");
+		*child_readback = *p;
+		if (verbose) {
+			tst_res(TINFO, "child readback: %x", *child_readback);
+			tst_res(TINFO, "Child writes...");
+		}
+		*p = OTHER_CONSTANT;
+		if (verbose)
+			tst_res(TINFO, "OTHER_CONSTANT: %x", OTHER_CONSTANT);
+
+		*trigger = 2;
+
+		while (*trigger != 3)
+			;
+		if (verbose)
+			tst_res(TINFO, "Child exits...");
+		exit(0);
+	}
+
+	if (verbose)
+		tst_res(TINFO, "child_readback = 0x%x, parent_readback = 0x%x\n",
+		       *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);
+		goto fail;
+	}
+	if (parent_readback != ~RANDOM_CONSTANT) {
+		tst_res(TFAIL, "Parent read back 0x%x instead of 0x%x",
+		     parent_readback, RANDOM_CONSTANT);
+		goto fail;
+	}
+
+	SAFE_WAITPID(pid, &status, 0);
+
+	tst_res(TPASS, "Successful");
+	SAFE_MUNMAP((void *)p, hpage_size);
+	SAFE_MUNMAP(syncarea, getpagesize());
+	SAFE_CLOSE(fd);
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+}
+
+static void setup(void)
+{
+	int free_pages = SAFE_READ_MEMINFO("HugePages_Free:");
+
+	if (tst_hugepages < 2 || free_pages < 2)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.forks_child = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {2, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 10/29] Hugetlb: Migrating libhugetlbfs huge_at_4GB_normal_below
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (8 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 09/29] Hugetlb: Migrating libhugetlbfs fork-cow Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-17 14:46   ` Cyril Hrubis
  2022-10-16 12:57 ` [LTP] [PATCH 11/29] Hugetlb: Migrating libhugetlbfs huge_below_4GB_normal_above Tarun Sahu
                   ` (19 subsequent siblings)
  29 siblings, 1 reply; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

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

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap13.c  | 160 ++++++++++++++++++
 3 files changed, 162 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 4c16e1e7c..2029ee4b3 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -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
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index adea760c7..5955ed613 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -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
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c
new file mode 100644
index 000000000..0eae937ab
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c
@@ -0,0 +1,160 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ *
+ * Test Name: Huge at 4GB normal below
+ *
+ * Test Description: Designed to pick up a bug on ppc64 where
+ * touches_hugepage_high_range() falsely reported true for ranges reaching
+ * below 4GB
+ *
+ * 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.
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *
+ */
+
+#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 FOURGB (1UL << 32)
+
+static int  fd = -1;
+static char hfile[MAXPATHLEN];
+static unsigned long hpage_size;
+static char *verbose;
+
+static void run_test(void)
+{
+	int page_size;
+	int fd;
+	void *p, *q;
+	unsigned long lowaddr;
+	int err;
+
+	page_size = getpagesize();
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	p = mmap((void *)FOURGB, hpage_size, PROT_READ|PROT_WRITE,
+		 MAP_SHARED | MAP_FIXED, fd, 0);
+	if (p == MAP_FAILED) {
+		/* slice 0 (high) spans from 4G-1T */
+		unsigned long below_start = FOURGB;
+		unsigned long above_end = 1024L*1024*1024*1024;
+
+		if (range_is_mapped(below_start, above_end) == 1) {
+			if (verbose) {
+				tst_res(TINFO, "region 4G-IT is not free");
+				tst_res(TINFO|TERRNO, "mmap() failed");
+			}
+			tst_res(TPASS, "Successful but inconclusive");
+			SAFE_CLOSE(fd);
+			return;
+		}
+		tst_res(TFAIL|TERRNO, "mmap() huge");
+		goto fail;
+	}
+	if (p != (void *)FOURGB) {
+		tst_res(TFAIL, "Wrong address with MAP_FIXED huge");
+		goto fail;
+	}
+
+	if (verbose)
+		tst_res(TINFO, "Mapped hugetlb at %p", p);
+
+	memset(p, 0, hpage_size);
+
+	err = test_addr_huge(p);
+	if (err != 1) {
+		tst_res(TFAIL, "Mapped address is not hugepage");
+		goto fail;
+	}
+
+	/* Test just below 4GB to check for off-by-one errors */
+	lowaddr = FOURGB - page_size;
+	q = mmap((void *)lowaddr, page_size, PROT_READ|PROT_WRITE,
+		 MAP_SHARED|MAP_FIXED|MAP_ANONYMOUS, 0, 0);
+	if (p == MAP_FAILED) {
+		unsigned long below_start = FOURGB - page_size;
+		unsigned long above_end = FOURGB;
+
+		if (range_is_mapped(below_start, above_end) == 1) {
+			if (verbose) {
+				tst_res(TINFO, "region (4G-page)-4G is not free\n");
+				tst_res(TINFO|TERRNO, "mmap() failed");
+			}
+			tst_res(TPASS, "Successful but inconclusive");
+			SAFE_MUNMAP(p, hpage_size);
+			SAFE_CLOSE(fd);
+			return;
+		}
+		tst_res(TFAIL|TERRNO, "mmap() normal");
+		goto fail;
+	}
+	if (q != (void *)lowaddr) {
+		tst_res(TFAIL, "Wrong address with MAP_FIXED normal");
+		goto fail;
+	}
+
+	memset(q, 0, page_size);
+
+	tst_res(TPASS, "Successful");
+	SAFE_MUNMAP(p, hpage_size);
+	SAFE_MUNMAP(q, page_size);
+	SAFE_CLOSE(fd);
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 1)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+
+	if (sizeof(void *) <= 4)
+		tst_brk(TCONF, "Machine must be >32 bit");
+
+	if (hpage_size > FOURGB)
+		tst_brk(TCONF, "Huge page size is too large");
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {2, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 11/29] Hugetlb: Migrating libhugetlbfs huge_below_4GB_normal_above
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (9 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 10/29] Hugetlb: Migrating libhugetlbfs huge_at_4GB_normal_below Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-17 14:48   ` Cyril Hrubis
  2022-10-16 12:57 ` [LTP] [PATCH 12/29] Hugetlb: Migrating libhugetlbfs icache-hygiene Tarun Sahu
                   ` (18 subsequent siblings)
  29 siblings, 1 reply; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

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

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap14.c  | 204 ++++++++++++++++++
 3 files changed, 206 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 2029ee4b3..796ebe7fa 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -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
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 5955ed613..3106579ce 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -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
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c
new file mode 100644
index 000000000..c49f13935
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c
@@ -0,0 +1,204 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ *
+ * Test Name: Huge_below_4GB_normal_above
+ *
+ * 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
+ *
+ * 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.
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *
+ */
+
+#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 FOURGB (1UL << 32)
+
+static int  fd = -1;
+static char hfile[MAXPATHLEN];
+static unsigned long hpage_size;
+static char *verbose;
+
+static void run_test(void)
+{
+	int page_size;
+	void *p, *q, *r;
+	unsigned long lowaddr, highaddr;
+	int err;
+
+	page_size = getpagesize();
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	/* We use a low address right below 4GB so we can test for
+	 * off-by-one errors
+	 */
+	lowaddr = FOURGB - hpage_size;
+	if (verbose)
+		tst_res(TINFO, "Mapping hugepage at %lx...", lowaddr);
+	p = mmap((void *)lowaddr, hpage_size, PROT_READ|PROT_WRITE,
+		 MAP_SHARED|MAP_FIXED, fd, 0);
+	if (p == MAP_FAILED) {
+		/* This is last low slice - 256M just before 4G */
+		unsigned long below_start = FOURGB - 256L*1024*1024;
+		unsigned long above_end = FOURGB;
+
+		if (range_is_mapped(below_start, above_end) == 1) {
+			if (verbose) {
+				tst_res(TINFO, "region (4G-256M)-4G is not free");
+				tst_res(TINFO|TERRNO, "mmap() failed");
+			}
+			tst_res(TPASS, "Successful but inconclusive");
+			SAFE_CLOSE(fd);
+			return;
+		}
+		tst_res(TFAIL|TERRNO, "mmap() huge");
+		goto fail;
+	}
+	if (p != (void *)lowaddr) {
+		tst_res(TFAIL, "Wrong address with MAP_FIXED huge");
+		goto fail;
+	}
+	if (verbose)
+		tst_res(TINFO, "done");
+	memset(p, 0, hpage_size);
+
+	err = test_addr_huge(p);
+	if (err != 1) {
+		tst_res(TFAIL, "Mapped address is not hugepage");
+		goto fail;
+	}
+
+	/* Test for off by one errors */
+	highaddr = FOURGB;
+	if (verbose)
+		tst_res(TINFO, "Mapping normal page at %lx...", highaddr);
+	q = mmap((void *)highaddr, page_size, PROT_READ|PROT_WRITE,
+		 MAP_SHARED|MAP_FIXED|MAP_ANONYMOUS, 0, 0);
+	if (q == MAP_FAILED) {
+		unsigned long below_start = FOURGB;
+		unsigned long above_end = FOURGB + page_size;
+
+		if (range_is_mapped(below_start, above_end) == 1) {
+			if (verbose) {
+				tst_res(TINFO, "region 4G-(4G+page) is not free\n");
+				tst_res(TINFO|TERRNO, "mmap() failed");
+			}
+			tst_res(TPASS, "Successful but inconclusive");
+			SAFE_MUNMAP(p, hpage_size);
+			SAFE_CLOSE(fd);
+			return;
+		}
+		tst_res(TFAIL|TERRNO, "mmap() normal 1");
+		goto fail;
+	}
+	if (q != (void *)highaddr) {
+		tst_res(TFAIL, "Wrong address with MAP_FIXED normal 2");
+		goto fail;
+	}
+	if (verbose)
+		tst_res(TINFO, "done");
+
+	memset(q, 0, page_size);
+
+	/* Why this address?  Well on ppc64, we're working with 256MB
+	 * segment numbers, hence >>28.  In practice the shift
+	 * instructions only start wrapping around with shifts 128 or
+	 * greater.
+	 */
+	highaddr = ((lowaddr >> 28) + 128) << 28;
+	if (verbose)
+		tst_res(TINFO, "Mapping normal page at %lx...", highaddr);
+	r = mmap((void *)highaddr, page_size, PROT_READ|PROT_WRITE,
+		 MAP_SHARED|MAP_FIXED|MAP_ANONYMOUS, 0, 0);
+	if (r == MAP_FAILED) {
+		unsigned long below_start = highaddr;
+		unsigned long above_end = highaddr + page_size;
+
+		if (range_is_mapped(below_start, above_end) == 1) {
+			if (verbose) {
+				tst_res(TINFO, "region haddr-(haddr+page) not free");
+				tst_res(TINFO|TERRNO, "mmap() failed");
+			}
+			tst_res(TPASS, "Successful but inconclusive");
+			SAFE_MUNMAP(p, hpage_size);
+			SAFE_MUNMAP(q, page_size);
+			SAFE_CLOSE(fd);
+			return;
+		}
+		tst_res(TFAIL|TERRNO, "mmap() normal 2");
+		goto fail;
+	}
+	if (r != (void *)highaddr) {
+		tst_res(TFAIL, "Wrong address with MAP_FIXED normal 2");
+		goto fail;
+	}
+	if (verbose)
+		tst_res(TINFO, "done");
+
+	memset(r, 0, page_size);
+	tst_res(TPASS, "Successful");
+	SAFE_MUNMAP(p, hpage_size);
+	SAFE_MUNMAP(q, page_size);
+	SAFE_MUNMAP(r, page_size);
+	SAFE_CLOSE(fd);
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 1)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+
+	if (sizeof(void *) <= 4)
+		tst_brk(TCONF, "Machine must be >32 bit");
+
+	if (hpage_size > FOURGB)
+		tst_brk(TCONF, "Huge page size is too large");
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {1, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 12/29] Hugetlb: Migrating libhugetlbfs icache-hygiene
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (10 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 11/29] Hugetlb: Migrating libhugetlbfs huge_below_4GB_normal_above Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-17 19:37   ` Cyril Hrubis
  2022-10-16 12:57 ` [LTP] [PATCH 13/29] Hugetlb: Migrating libhugetlbfs madvise_reserve Tarun Sahu
                   ` (17 subsequent siblings)
  29 siblings, 1 reply; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

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.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap15.c  | 250 ++++++++++++++++++
 3 files changed, 252 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 796ebe7fa..0714ed34c 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -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
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 3106579ce..d59b60fd4 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -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
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c
new file mode 100644
index 000000000..cf1cd96ea
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c
@@ -0,0 +1,250 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ *
+ * Test Name: icache hygiene
+ *
+ * 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.
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <setjmp.h>
+#include <unistd.h>
+#include <signal.h>
+#include <sys/mman.h>
+#include <ucontext.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+static int  fd = -1;
+static char hfile[MAXPATHLEN];
+
+#define COPY_SIZE	128
+#define NUM_REPETITIONS	64	/* Seems to be enough to trigger reliably */
+
+static char *verbose;
+static long hpage_size;
+
+static void cacheflush(void *p)
+{
+	(void)p;
+#if defined(__powerpc__)
+	asm volatile("dcbst 0,%0; sync; icbi 0,%0; isync" : : "r"(p));
+#elif defined(__arm__) || defined(__aarch64__)
+	__clear_cache(p, p + COPY_SIZE);
+#endif
+}
+
+static void jumpfunc(int copy, void *p)
+{
+	/* gcc bug workaround: if there is exactly one &&label
+	 * construct in the function, gcc assumes the computed goto
+	 * goes there, leading to the complete elision of the goto in
+	 * this case
+	 */
+	void *l = &&dummy;
+
+	l = &&jumplabel;
+
+	if (copy) {
+		memcpy(p, l, COPY_SIZE);
+		cacheflush(p);
+	}
+
+	goto *p;
+ dummy:
+	tst_res(TWARN, "unreachable?");
+
+ jumplabel:
+	return;
+}
+
+static sigjmp_buf sig_escape;
+static void *sig_expected;
+
+static void sig_handler(int signum, siginfo_t *si, void *uc)
+{
+#if defined(__powerpc__) || defined(__powerpc64__) || defined(__ia64__) || \
+	defined(__s390__) || defined(__s390x__) || defined(__sparc__) || \
+	defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64)
+	/* On powerpc, ia64, s390 and Aarch64, 0 bytes are an illegal
+	 * instruction, so, if the icache is cleared properly, we SIGILL
+	 * as soon as we jump into the cleared page
+	 */
+	if (signum == SIGILL) {
+		if (verbose)
+			tst_res(TINFO, "SIGILL at %p (sig_expected=%p)", si->si_addr,
+				       sig_expected);
+		if (si->si_addr == sig_expected)
+			siglongjmp(sig_escape, 1);
+		tst_res(TFAIL, "SIGILL somewhere unexpected");
+		goto fail;
+	}
+#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__)
+	/* On x86, zero bytes form a valid instruction:
+	 *	add %al,(%eax)		(i386)
+	 * or	add %al,(%rax)		(x86_64)
+	 *
+	 * So, behaviour depends on the contents of [ER]AX, which in
+	 * turn depends on the details of code generation.  If [ER]AX
+	 * contains a valid pointer, we will execute the instruction
+	 * repeatedly until we run off that hugepage and get a SIGBUS
+	 * on the second, truncated page.  If [ER]AX does not contain
+	 * a valid pointer, we will SEGV on the first instruction in
+	 * the cleared page.  We check for both possibilities
+	 * below.
+	 *
+	 * On 32 bit ARM, zero bytes are interpreted as follows:
+	 *  andeq	r0, r0, r0	(ARM state, 4 bytes)
+	 *  movs	r0, r0		(Thumb state, 2 bytes)
+	 *
+	 * So, we only expect to run off the end of the huge page and
+	 * generate a SIGBUS.
+	 */
+	if (signum == SIGBUS) {
+		if (verbose)
+			tst_res(TINFO, "SIGBUS at %p (sig_expected=%p)", si->si_addr,
+				       sig_expected);
+		if (sig_expected
+		    && (ALIGN((unsigned long)sig_expected, hpage_size)
+			== (unsigned long)si->si_addr)) {
+			siglongjmp(sig_escape, 2);
+		}
+		tst_res(TFAIL, "SIGBUS somewhere unexpected");
+		goto fail;
+	}
+#if defined(__x86_64__) || defined(__i386__)
+	if (signum == SIGSEGV) {
+#ifdef __x86_64__
+		void *pc = (void *)((ucontext_t *)uc)->uc_mcontext.gregs[REG_RIP];
+#else
+		void *pc = (void *)((ucontext_t *)uc)->uc_mcontext.gregs[REG_EIP];
+#endif
+		if (verbose)
+			tst_res(TINFO, "SIGSEGV at %p, PC=%p (sig_expected=%p)\n",
+				       si->si_addr, pc, sig_expected);
+		if (sig_expected == pc)
+			siglongjmp(sig_escape, 1);
+		tst_res(TFAIL, "SIGSEGV somewhere unexpected");
+		goto fail;
+	}
+#endif
+#else
+#error "Need to setup signal conditions for this arch"
+#endif
+	return;
+fail:
+	tst_brk(TBROK, "Once Failed, No Need to continue the next iteration.");
+}
+
+static void test_once(int fd)
+{
+	void *p, *q;
+
+	SAFE_FTRUNCATE(fd, 0);
+
+	if (sigsetjmp(sig_escape, 1)) {
+		sig_expected = NULL;
+		SAFE_FTRUNCATE(fd, 0);
+		return;
+	}
+
+	p = SAFE_MMAP(NULL, 2*hpage_size, PROT_READ|PROT_WRITE|PROT_EXEC,
+		 MAP_SHARED, fd, 0);
+
+	SAFE_FTRUNCATE(fd, hpage_size);
+
+	q = p + hpage_size - COPY_SIZE;
+
+	jumpfunc(1, q);
+
+	SAFE_FTRUNCATE(fd, 0);
+	p = SAFE_MMAP(p, hpage_size, PROT_READ|PROT_WRITE|PROT_EXEC,
+		 MAP_SHARED|MAP_FIXED, fd, 0);
+
+	q = p + hpage_size - COPY_SIZE;
+	sig_expected = q;
+
+	jumpfunc(0, q); /* This should blow up */
+
+	tst_res(TFAIL, "icache unclean");
+	tst_brk(TBROK, "Once Failed, No Need to continue the next iteration.");
+}
+
+static void run_test(void)
+{
+	int i;
+
+	struct sigaction sa = {
+		.sa_sigaction = sig_handler,
+		.sa_flags = SA_SIGINFO,
+	};
+
+	SAFE_SIGACTION(SIGILL, &sa, NULL);
+	SAFE_SIGACTION(SIGBUS, &sa, NULL);
+	SAFE_SIGACTION(SIGSEGV, &sa, NULL);
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	for (i = 0; i < NUM_REPETITIONS; i++)
+		test_once(fd);
+
+	tst_res(TPASS, "Successful");
+	SAFE_CLOSE(fd);
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 3)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {3, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 13/29] Hugetlb: Migrating libhugetlbfs madvise_reserve
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (11 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 12/29] Hugetlb: Migrating libhugetlbfs icache-hygiene Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 14/29] Hugetlb: Migrating libhugetlbfs map_high_truncate_2 Tarun Sahu
                   ` (16 subsequent siblings)
  29 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

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")'.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap16.c  | 112 ++++++++++++++++++
 3 files changed, 114 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap16.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 0714ed34c..1691ce37d 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -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
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index d59b60fd4..eb8e87c40 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -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
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap16.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap16.c
new file mode 100644
index 000000000..2b6a5e374
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap16.c
@@ -0,0 +1,112 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 IBM Corporation.
+ *
+ * Test Name: madvise_reserve
+ *
+ * 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 f2deae9d4e70793568ef9e85d227abb7bef5b622
+ *
+ * HISTORY
+ *  Written by Eric B Munson and Mel Gorman
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+static char *verbose;
+static int  fd = -1;
+static char hfile[MAXPATHLEN];
+static long hpage_size;
+
+static void test_directio(void)
+{
+	void *p;
+	unsigned long initial_rsvd, map_rsvd, madvise_rsvd, end_rsvd;
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+	initial_rsvd = SAFE_READ_MEMINFO("HugePages_Rsvd:");
+
+	if (verbose)
+		tst_res(TINFO, "Reserve count before map: %lu", initial_rsvd);
+
+	/* mmap a region and record reservations */
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
+		 fd, 0);
+	map_rsvd = SAFE_READ_MEMINFO("HugePages_Rsvd:");
+	if (verbose)
+		tst_res(TINFO, "Reserve count after map: %lu", map_rsvd);
+
+	/* madvise the region and record reservations */
+	if (madvise(p, hpage_size, MADV_WILLNEED) == -1)
+		tst_brk(TBROK|TERRNO, "madvise()");
+	madvise_rsvd = SAFE_READ_MEMINFO("HugePages_Rsvd:");
+	if (verbose)
+		tst_res(TINFO, "Reserve count after madvise: %lu", madvise_rsvd);
+
+	/* Free region */
+	SAFE_MUNMAP(p, hpage_size);
+	SAFE_CLOSE(fd);
+	end_rsvd = SAFE_READ_MEMINFO("HugePages_Rsvd:");
+	if (verbose)
+		tst_res(TINFO, "Reserve count after close(): %lu", end_rsvd);
+
+	/* Reserve count should match initial reserve count */
+	if (end_rsvd != initial_rsvd) {
+		tst_res(TFAIL, "Reserve leaked: %lu != %lu", end_rsvd, initial_rsvd);
+		goto fail;
+	}
+	tst_res(TPASS, "Successful");
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing to next iteration");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 1)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = test_directio,
+	.hugepages = {1, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 14/29] Hugetlb: Migrating libhugetlbfs map_high_truncate_2
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (12 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 13/29] Hugetlb: Migrating libhugetlbfs madvise_reserve Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 15/29] Hugetlb: Migrating libhugetlbfs misalign Tarun Sahu
                   ` (15 subsequent siblings)
  29 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

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 <kenneth.w.chen@intel.com>

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")'.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap17.c  | 126 ++++++++++++++++++
 3 files changed, 128 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap17.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 1691ce37d..5fac3481c 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -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
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index eb8e87c40..6aa54f902 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -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
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap17.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap17.c
new file mode 100644
index 000000000..8679dcece
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap17.c
@@ -0,0 +1,126 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ *
+ * Test Name: Map High Truncate 2
+ *
+ * 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 <kenneth.w.chen@intel.com>
+ *
+ * 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
+ * 856fc29505556cf263f3dcda2533cf3766c14ab6.
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *
+ */
+
+#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 MAP_LENGTH	(4UL * hpage_size)
+#if defined(__s390__) && __WORDSIZE == 32
+#define TRUNCATE_POINT 0x20000000UL
+#else
+#define TRUNCATE_POINT 0x60000000UL
+#endif
+#define HIGH_ADDR	0xa0000000UL
+#define FOURGIG		((off64_t)0x100000000ULL)
+
+static char *verbose;
+static unsigned long hpage_size;
+static int  fd = -1;
+static char hfile[MAXPATHLEN];
+
+static void run_test(void)
+{
+	char *p, *q;
+	unsigned long i;
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+	/* First mapping */
+	p = SAFE_MMAP(0, MAP_LENGTH + TRUNCATE_POINT, PROT_READ | PROT_WRITE,
+		 MAP_PRIVATE | MAP_NORESERVE, fd, 0);
+
+	SAFE_MUNMAP(p, 4*hpage_size + TRUNCATE_POINT);
+
+	q = SAFE_MMAP((void *)HIGH_ADDR, MAP_LENGTH, PROT_READ | PROT_WRITE,
+		 MAP_PRIVATE, fd, 0);
+	if (verbose)
+		tst_res(TINFO, "High map at %p\n", q);
+
+	for (i = 0; i < MAP_LENGTH; i += hpage_size)
+		q[i] = 1;
+
+	SAFE_FTRUNCATE(fd, TRUNCATE_POINT);
+
+	if (q[0] != 1) {
+		tst_res(TFAIL, "data mismatch");
+		goto fail;
+	}
+
+	tst_res(TPASS, "Successful");
+	SAFE_MUNMAP(p, MAP_LENGTH + TRUNCATE_POINT);
+	SAFE_MUNMAP(q, MAP_LENGTH);
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing to next iteration");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 4)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+
+	if (hpage_size > TRUNCATE_POINT)
+		tst_brk(TCONF, "Huge page size is too large");
+
+	if (TRUNCATE_POINT % hpage_size)
+		tst_brk(TCONF, "Truncation point is not aligned to huge page size");
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {4, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 15/29] Hugetlb: Migrating libhugetlbfs misalign
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (13 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 14/29] Hugetlb: Migrating libhugetlbfs map_high_truncate_2 Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 16/29] Hugetlb: Migrating libhugetlbfs misaligned_offset Tarun Sahu
                   ` (14 subsequent siblings)
  29 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

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 af73e4d9506d3b797509f3c030e7dcd554f7d9c4
("hugetlbfs: fix mmap failure in unaligned size request")' added ALIGN()
to kernel side, in mmap_pgoff(), when mapping huge page files.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap18.c  | 173 ++++++++++++++++++
 3 files changed, 175 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap18.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 5fac3481c..de76cdaf2 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -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
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 6aa54f902..daee70586 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -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
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap18.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap18.c
new file mode 100644
index 000000000..bd3593570
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap18.c
@@ -0,0 +1,173 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2007 David Gibson & Adam Litke, IBM Corporation.
+ *
+ * Test Name: Misalign
+ *
+ * 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 af73e4d9506d3b797509f3c030e7dcd554f7d9c4
+ * added ALIGN() to kernel side, in mmap_pgoff(), when mapping huge page
+ * files.
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <signal.h>
+#include <sys/mman.h>
+#include <sys/utsname.h>
+
+#include "hugetlb.h"
+
+static char *verbose;
+static long hpage_size;
+static int  fd = -1;
+static char hfile[MAXPATHLEN];
+
+static void run_test(void)
+{
+	long page_size;
+	void *p, *q;
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	page_size = getpagesize();
+
+	/* First see what an ok mapping looks like, as a basis for our
+	 * bad addresses and so forth
+	 */
+	p = mmap(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+	if (p == MAP_FAILED) {
+		tst_res(TFAIL|TERRNO, "mmap() without hint failed");
+		goto fail;
+	}
+	if (((unsigned long)p % hpage_size) != 0) {
+		tst_res(TFAIL, "mmap() without hint at misaligned address");
+		goto fail;
+	}
+
+	if (verbose)
+		tst_res(TINFO, "Mapped at %p, length 0x%lx\n", p, hpage_size);
+
+	SAFE_MUNMAP(p, hpage_size);
+
+	/* 1) Try a misaligned hint address */
+	q = mmap(p + page_size, hpage_size, PROT_READ|PROT_WRITE,
+		 MAP_PRIVATE, fd, 0);
+	if (q == MAP_FAILED) {
+		/* Bad hint shouldn't fail, just ignore the hint */
+		tst_res(TFAIL|TERRNO, "mmap() with hint failed");
+		goto fail;
+	}
+	if (((unsigned long)q % hpage_size) != 0) {
+		tst_res(TFAIL, "mmap() with hint at misaligned address");
+		goto fail;
+	}
+
+	SAFE_MUNMAP(q, hpage_size);
+
+	/* 2) Try a misaligned address with MAP_FIXED */
+	q = mmap(p + page_size, hpage_size, PROT_READ|PROT_WRITE,
+		 MAP_PRIVATE|MAP_FIXED, fd, 0);
+	if (q != MAP_FAILED) {
+		tst_res(TFAIL, "mmap() MAP_FIXED at misaligned address succeeded");
+		goto fail;
+	}
+
+	/* 3) Try a misaligned length */
+	q = mmap(NULL, page_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+	if (q == MAP_FAILED) {
+		tst_res(TFAIL, "mmap() with misaligned length 0x%lx failed",
+			page_size);
+		goto fail;
+	}
+
+	/* 4) Try a misaligned length with MAP_FIXED */
+	q = mmap(p, page_size, PROT_READ|PROT_WRITE,
+			MAP_PRIVATE|MAP_FIXED, fd, 0);
+	if (q == MAP_FAILED) {
+		tst_res(TFAIL, "mmap() MAP_FIXED with misaligned length 0x%lx "
+			"failed", page_size);
+	}
+
+	/* 5) Try a misaligned offset */
+	q = mmap(NULL, hpage_size, PROT_READ|PROT_WRITE,
+		 MAP_PRIVATE, fd, page_size);
+	if (q != MAP_FAILED) {
+		tst_res(TFAIL, "mmap() with misaligned offset 0x%lx succeeded",
+		     page_size);
+		goto fail;
+	}
+
+	/* 6) Try a misaligned offset with MAP_FIXED*/
+	q = mmap(p, hpage_size, PROT_READ|PROT_WRITE,
+		 MAP_PRIVATE|MAP_FIXED, fd, page_size);
+	if (q != MAP_FAILED) {
+		tst_res(TFAIL, "mmap() MAP_FIXED with misaligned offset 0x%lx succeeded",
+		     page_size);
+		goto fail;
+	}
+
+	tst_res(TPASS, "Successful");
+	SAFE_CLOSE(fd);
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing to next iteration");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 4)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "run"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {4, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 16/29] Hugetlb: Migrating libhugetlbfs misaligned_offset
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (14 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 15/29] Hugetlb: Migrating libhugetlbfs misalign Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 17/29] Hugetlb: Migrating libhugetlbfs mlock Tarun Sahu
                   ` (13 subsequent siblings)
  29 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

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")'.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap19.c  | 166 ++++++++++++++++++
 3 files changed, 168 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap19.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index de76cdaf2..4da1525a7 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -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
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index daee70586..b6b3e5ddd 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -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
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap19.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap19.c
new file mode 100644
index 000000000..57965307e
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap19.c
@@ -0,0 +1,166 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ * Copyright (C) 2006 Hugh Dickins <hugh@veritas.com>
+ *
+ * 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
+ * 856fc29505556cf263f3dcda2533cf3766c14ab6.
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *
+ */
+
+#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 RANDOM_CONSTANT	0x1234ABCD
+static char *verbose;
+static int page_size;
+static long hpage_size;
+static int  fd = -1;
+static char hfile[MAXPATHLEN];
+
+static void run_test(void)
+{
+	off_t buggy_offset;
+	void *p, *q;
+	volatile int *pi;
+	int err;
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+	/* First, we make a 2 page sane hugepage mapping.  Then we
+	 * memset() it to ensure that the ptes are instantiated for
+	 * it.  Then we attempt to replace the second half of the map
+	 * with one at a bogus offset.  We leave the first page of
+	 * sane mapping in place to ensure that the corresponding
+	 * pud/pmd/whatever entries aren't cleaned away.  It's those
+	 * bad entries which can trigger bad_pud() checks if the
+	 * backout path for the bogus mapping is buggy, which it was
+	 * in some kernels.
+	 */
+	if (verbose)
+		tst_res(TINFO, "Initial free hugepages: %lu\n",
+			SAFE_READ_MEMINFO("HugePages_Free:"));
+
+	/* First get arena of three hpages size, at file offset 4GB */
+	p = SAFE_MMAP(NULL, 2*hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+	if (verbose) {
+		tst_res(TINFO, "After Mapping reference map, Free hugepages: %lu",
+			SAFE_READ_MEMINFO("HugePages_Free:"));
+		tst_res(TINFO, "Mapped Address Range: %p-%p", p, p+2*hpage_size-1);
+	}
+
+	/* Instantiate the pages */
+	memset(p, 0, 2*hpage_size);
+	pi = p;
+	*pi = RANDOM_CONSTANT;
+
+	if (verbose)
+		tst_res(TINFO, "After instantiate the pages, Free hugepages: %lu",
+			   SAFE_READ_MEMINFO("HugePages_Free:"));
+
+	/* Toggle the permissions on the first page.  This forces TLB
+	 * entries (including hash page table on powerpc) to be
+	 * flushed, so that the page tables must be accessed for the
+	 * test further down.  In the buggy case, those page tables
+	 * can get thrown away by a pud_clear()
+	 */
+	err = mprotect(p, hpage_size, PROT_READ);
+	if (err)
+		tst_brk(TBROK|TERRNO, "mprotect(%p, 0x%lx, PROT_READ)", p, hpage_size);
+
+	/* Replace top hpage by hpage mapping at confusing file offset */
+	buggy_offset = page_size;
+	if (verbose)
+		tst_res(TINFO, "Replacing map at %p with map from offset 0x%lx...",
+		       p + hpage_size, (unsigned long)buggy_offset);
+	q = mmap(p + hpage_size, hpage_size, PROT_READ|PROT_WRITE,
+		 MAP_FIXED|MAP_PRIVATE, fd, buggy_offset);
+	if (q != MAP_FAILED) {
+		tst_res(TFAIL|TERRNO, "bogus offset mmap() succeeded at %p", q);
+		goto fail;
+	}
+	if (errno != EINVAL) {
+		tst_res(TFAIL|TERRNO, "bogus mmap() failed should be \"%s\" but it is",
+		     strerror(EINVAL));
+		goto fail;
+	}
+
+	if (verbose)
+		tst_res(TINFO, "After Mapping with buggy offset, Free hugepages: %lu",
+			SAFE_READ_MEMINFO("HugePages_Free:"));
+
+	if (*pi != RANDOM_CONSTANT) {
+		tst_res(TFAIL, "Pre-existing mapping clobbered: %x instead of %x",
+		     *pi, RANDOM_CONSTANT);
+		goto fail;
+	}
+
+	/* The real test is whether we got a bad_pud() or similar
+	 * during the run.  The check above, combined with the earlier
+	 * mprotect()s to flush the TLB are supposed to catch it, but
+	 * it's hard to be certain.  Once bad_pud() is called
+	 * behaviour can be very strange.
+	 */
+
+	tst_res(TPASS, "Successful but inconclusive");
+	SAFE_MUNMAP(p, 2*hpage_size);
+	SAFE_CLOSE(fd);
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing to next interation");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 4)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+	page_size = getpagesize();
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {4, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 17/29] Hugetlb: Migrating libhugetlbfs mlock
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (15 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 16/29] Hugetlb: Migrating libhugetlbfs misaligned_offset Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 18/29] Hugetlb: Migrating libhugetlbfs mmap-cow Tarun Sahu
                   ` (12 subsequent siblings)
  29 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/mlock.c test

Test Description: The test checks that mlocking hugetlb areas works
with all combinations of MAP_PRIVATE and MAP_SHARED with and without
MAP_LOCKED specified.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap20.c  | 108 ++++++++++++++++++
 3 files changed, 110 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 4da1525a7..2dffa8421 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -21,6 +21,7 @@ hugemmap16 hugemmap16
 hugemmap17 hugemmap17
 hugemmap18 hugemmap18
 hugemmap19 hugemmap19
+hugemmap20 hugemmap20
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index b6b3e5ddd..dfd372892 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -20,6 +20,7 @@
 /hugetlb/hugemmap/hugemmap17
 /hugetlb/hugemmap/hugemmap18
 /hugetlb/hugemmap/hugemmap19
+/hugetlb/hugemmap/hugemmap20
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c
new file mode 100644
index 000000000..702de7de9
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap20.c
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ *
+ * Test Name: mlock
+ *
+ * Test Description: The test checks that mlocking hugetlb areas works
+ * with all combinations of MAP_PRIVATE and MAP_SHARED with and without
+ * MAP_LOCKED specified.
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/resource.h>
+
+#include "hugetlb.h"
+
+static int  fd = -1;
+static char hfile[MAXPATHLEN];
+static unsigned long hpage_size;
+
+static void test_simple_mlock(int flags)
+{
+	void *p;
+	int ret;
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	p = SAFE_MMAP(0, hpage_size, PROT_READ|PROT_WRITE, flags, fd, 0);
+
+	/* Can't use SAFE_MLOCK, as this test requires manual check */
+	ret = mlock(p, hpage_size);
+	if (ret) {
+		tst_res(TFAIL|TERRNO, "mlock() failed (flags=%x)", flags);
+		goto fail;
+	}
+
+	ret = munlock(p, hpage_size);
+	if (ret) {
+		tst_res(TFAIL|TERRNO, "munlock() failed (flags=%x)", flags);
+		goto fail;
+	}
+	SAFE_MUNMAP(p, hpage_size);
+	SAFE_CLOSE(fd);
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing to next iteration");
+}
+
+static void run_test(void)
+{
+	struct rlimit limit_info;
+
+	if (getrlimit(RLIMIT_MEMLOCK, &limit_info))
+		tst_res(TWARN|TERRNO, "Unable to read locked memory rlimit");
+	if (limit_info.rlim_cur < hpage_size)
+		tst_brk(TCONF, "Locked memory ulimit set below huge page size");
+
+	test_simple_mlock(MAP_PRIVATE);
+	test_simple_mlock(MAP_SHARED);
+	test_simple_mlock(MAP_PRIVATE|MAP_LOCKED);
+	test_simple_mlock(MAP_SHARED|MAP_LOCKED);
+
+	tst_res(TPASS, "Successful");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 1)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {1, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 18/29] Hugetlb: Migrating libhugetlbfs mmap-cow
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (16 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 17/29] Hugetlb: Migrating libhugetlbfs mlock Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 19/29] Hugetlb: Migrating libhugetlbfs mmap-gettest Tarun Sahu
                   ` (11 subsequent siblings)
  29 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

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

Test Description: Tests copy-on-write semantics of large pages where a
number of threads map the same file with the MAP_PRIVATE flag. The threads
then write into their copy of the mapping and recheck the contents to
ensure they were not corrupted by the other threads.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap21.c  | 222 ++++++++++++++++++
 3 files changed, 224 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 2dffa8421..449fad56a 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -22,6 +22,7 @@ hugemmap17 hugemmap17
 hugemmap18 hugemmap18
 hugemmap19 hugemmap19
 hugemmap20 hugemmap20
+hugemmap21 hugemmap21 -T 2 -s 5
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index dfd372892..74edfa392 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -21,6 +21,7 @@
 /hugetlb/hugemmap/hugemmap18
 /hugetlb/hugemmap/hugemmap19
 /hugetlb/hugemmap/hugemmap20
+/hugetlb/hugemmap/hugemmap21
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c
new file mode 100644
index 000000000..adc76df44
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap21.c
@@ -0,0 +1,222 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ *
+ * Test Name: mmap COW
+ *
+ * Test Description: Tests copy-on-write semantics of large pages where a
+ * number of threads map the same file with the MAP_PRIVATE flag. The threads
+ * then write into their copy of the mapping and recheck the contents to
+ * ensure they were not corrupted by the other threads.
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/shm.h>
+#include <sys/wait.h>
+
+#include "hugetlb.h"
+
+#define BUF_SZ 256
+
+#define CHILD_FAIL(thread, fmt, ...) \
+	do { \
+		if (verbose) \
+			tst_res(TINFO|TERRNO, "Thread %d (pid=%d) FAIL: " fmt, \
+			       thread, getpid(), ##__VA_ARGS__); \
+		exit(1); \
+	} while (0)
+
+/* Setup Configuration */
+static int nr_hugepages;	/* Number of huge pages to allocate */
+static int threads;	/* Number of threads to run */
+static char *threads_opt;
+static char *verbose;
+static char hfile[MAXPATHLEN];
+static int fd = -1;
+static long hpage_size;
+
+static int mmap_file(int fd, char **addr, size_t size, int type)
+{
+	int flags = 0;
+
+	/* No SAFE_MMAP use here, because test failure is based on the
+	 * output of mmap
+	 */
+	*addr = mmap(NULL, size, PROT_READ|PROT_WRITE, flags | type, fd, 0);
+	if (*addr == MAP_FAILED)
+		return -1;
+
+	return 0;
+}
+
+static void do_work(int thread, size_t size, int fd)
+{
+	char *addr;
+	size_t i;
+	char pattern = thread+65;
+
+	if (mmap_file(fd, &addr, size, MAP_PRIVATE))
+		CHILD_FAIL(thread, "mmap() failed");
+
+	if (verbose)
+		tst_res(TINFO, "Thread %d (pid=%d): Mapped at address %p",
+		       thread, getpid(), addr);
+
+	/* Write to the mapping with a distinct pattern */
+	if (verbose)
+		tst_res(TINFO, "Thread %d (pid=%d): Writing %c to the mapping",
+		       thread, getpid(), pattern);
+	for (i = 0; i < size; i++)
+		memcpy((char *)addr+i, &pattern, 1);
+
+	if (msync(addr, size, MS_SYNC))
+		CHILD_FAIL(thread, "msync() failed");
+
+	/* Verify the pattern */
+	for (i = 0; i < size; i++)
+		if (addr[i] != pattern)
+			CHILD_FAIL(thread, "Corruption at %p; "
+				   "Got %c, Expected %c",
+				   &addr[i], addr[i], pattern);
+	if (verbose)
+		tst_res(TINFO, "Thread %d (pid=%d): Pattern verified\n",
+		       thread, getpid());
+
+	/* Munmap the area */
+	SAFE_MUNMAP(addr, size);
+	SAFE_CLOSE(fd);
+	exit(0);
+}
+
+static void run_test(void)
+{
+	char *addr;
+	size_t size, itr;
+	int i, pid, status;
+	pid_t *wait_list;
+
+	wait_list = SAFE_MALLOC(threads * sizeof(pid_t));
+
+	/* Have to have enough available hugepages for each thread to
+	 * get its own copy, plus one for the parent/page-cache
+	 */
+	size = (nr_hugepages / (threads+1)) * hpage_size;
+	if (verbose)
+		tst_res(TINFO, "hpage_size is %lx, Size is %zu, threads: %u\n",
+		       hpage_size, size, threads);
+
+	/* First, open the file */
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	/* First, mmap the file with MAP_SHARED and fill with data
+	 * If this is not done, then the fault handler will not be
+	 * called in the kernel since private mappings will be
+	 * created for the children at prefault time.
+	 */
+	if (mmap_file(fd, &addr, size, MAP_SHARED)) {
+		tst_res(TFAIL|TERRNO, "Failed to create shared mapping");
+		goto fail;
+	}
+
+	for (itr = 0; itr < size; itr += 8)
+		memcpy(addr+itr, "deadbeef", 8);
+
+	for (i = 0; i < threads; i++) {
+		pid = SAFE_FORK();
+
+		if (pid == 0)
+			do_work(i, size, fd);
+
+		wait_list[i] = pid;
+	}
+	for (i = 0; i < threads; i++) {
+		SAFE_WAITPID(wait_list[i], &status, 0);
+		if (WEXITSTATUS(status) != 0) {
+			tst_res(TFAIL, "Thread %d (pid=%d) failed", i, wait_list[i]);
+			goto fail;
+		}
+
+		if (WIFSIGNALED(status)) {
+			tst_res(TFAIL, "Thread %d (pid=%d) received unhandled signal", i,
+			     wait_list[i]);
+			goto fail;
+		}
+	}
+
+	SAFE_MUNMAP(addr, size);
+	SAFE_CLOSE(fd);
+	free(wait_list);
+
+	tst_res(TPASS, "Successful");
+	return;
+
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+}
+
+static void setup(void)
+{
+	int ret;
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+
+	if (!(threads_opt) || !(nr_opt))
+		tst_brk(TCONF, "Usage: -T <# threads> -s <# pages>\n");
+
+	ret = tst_parse_int(threads_opt, &threads, 1, INT_MAX);
+	if (ret || threads <= 0)
+		tst_brk(TCONF, "Invalid thread argument");
+	ret = tst_parse_int(nr_opt, &nr_hugepages, 1, INT_MAX);
+	if (ret || nr_hugepages <= 0)
+		tst_brk(TCONF, "Invalid pages argument");
+
+	if ((threads+1) > nr_hugepages)
+		tst_brk(TCONF, "Need more hugepages than threads\n");
+
+}
+
+static void cleanup(void)
+{
+	if (fd >= 1)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"T:", &threads_opt, "Number of threads"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.forks_child = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {2, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 19/29] Hugetlb: Migrating libhugetlbfs mmap-gettest
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (17 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 18/29] Hugetlb: Migrating libhugetlbfs mmap-cow Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 20/29] Hugetlb: Migrating libhugetlbfs mprotect Tarun Sahu
                   ` (10 subsequent siblings)
  29 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/mmap-gettest.c test

Test Description: This baseline test validates that a mapping of a
certain size can be created, correctly.  Once created, all the pages are
filled with a pattern and rechecked to test for corruption. The mapping is
then released.  This process is repeated for a specified number of
iterations.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap22.c  | 170 ++++++++++++++++++
 3 files changed, 172 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 449fad56a..5d06c8679 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -23,6 +23,7 @@ hugemmap18 hugemmap18
 hugemmap19 hugemmap19
 hugemmap20 hugemmap20
 hugemmap21 hugemmap21 -T 2 -s 5
+hugemmap22 hugemmap22 -T 2 -s 5
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 74edfa392..0fd01dbce 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -22,6 +22,7 @@
 /hugetlb/hugemmap/hugemmap19
 /hugetlb/hugemmap/hugemmap20
 /hugetlb/hugemmap/hugemmap21
+/hugetlb/hugemmap/hugemmap22
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c
new file mode 100644
index 000000000..5bc7b9389
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap22.c
@@ -0,0 +1,170 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ *
+ * Test Name: mmap gettest
+ *
+ * Test Description: This baseline test validates that a mapping of a
+ * certain size can be created, correctly.  Once created, all the pages are
+ * filled with a pattern and rechecked to test for corruption. The mapping is
+ * then released.  This process is repeated for a specified number of
+ * iterations.
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *  Migrated from libhugetlbfs by Tarun Sahu
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/shm.h>
+#include <sys/wait.h>
+
+#include "hugetlb.h"
+
+#define BUF_SZ 256
+
+/* Setup Configuration */
+static unsigned long nr_hugepages;	/* Number of huge pages to allocate */
+static char *iterations_opt;
+static int iter;
+static char *verbose;
+static char hfile[MAXPATHLEN];
+static unsigned long hpage_size;
+static int fha = -1;
+
+static int do_one(size_t size)
+{
+	char *ma;
+	size_t i, j;
+	char pattern = 'A';
+
+	fha = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	/* Map the files with MAP_PRIVATE */
+	ma = SAFE_MMAP(NULL, size, (PROT_READ|PROT_WRITE), MAP_SHARED, fha, 0);
+
+	/* Make sure the page is zeroed */
+	for (i = 0; i < nr_hugepages; i++) {
+		if (verbose)
+			tst_res(TINFO, "Verifying %p\n", (ma+(i*hpage_size)));
+		for (j = 0; j < hpage_size; j++) {
+			if (*(ma+(i*hpage_size)+j) != 0) {
+				tst_res(TFAIL, "Verifying the mmap area failed. "
+				     "Got %c, expected 0",
+				     *(ma+(i*hpage_size)+j));
+				goto fail;
+			}
+		}
+	}
+	/* Fill each file with a pattern */
+	for (i = 0; i < nr_hugepages; i++) {
+		pattern = 65+(i%26);
+		if (verbose)
+			tst_res(TINFO, "Touching %p with %c\n", ma+(i*hpage_size), pattern);
+		memset(ma+(i*hpage_size), pattern, hpage_size);
+	}
+
+	/* Verify the pattern */
+	for (i = 0; i < nr_hugepages; i++) {
+		pattern = 65+(i%26);
+		if (verbose)
+			tst_res(TINFO, "Verifying %p\n", (ma+(i*hpage_size)));
+		for (j = 0; j < hpage_size; j++) {
+			if (*(ma+(i*hpage_size)+j) != pattern) {
+				tst_res(TFAIL, "Verifying the mmap area failed. "
+				     "Got %c, expected %c",
+				     *(ma+(i*hpage_size)+j), pattern);
+				goto fail;
+			}
+		}
+	}
+
+	/* Munmap the area */
+	SAFE_MUNMAP(ma, size);
+
+	/* Close and delete the file */
+	SAFE_CLOSE(fha);
+	return 0;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+	return 0;
+}
+
+static void run_test(void)
+{
+	size_t size;
+	int i;
+
+	size = nr_hugepages * hpage_size;
+
+	for (i = 0; i < iter; i++) {
+		if (verbose)
+			tst_res(TINFO, "Iteration %d\n", i);
+		do_one(size);
+	}
+
+	tst_res(TPASS, "Successful");
+}
+
+static void setup(void)
+{
+	int nr_hpages, ret;
+
+	if (tst_hugepages == 0)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_mmapfile%d", Hopt, getpid());
+
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+
+	if (!(iterations_opt) || !(nr_opt))
+		tst_brk(TCONF, "Usage: -T <# iterations> -s <# pages>\n");
+
+	ret = tst_parse_int(iterations_opt, &iter, 1, INT_MAX);
+	if (ret || iter <= 0)
+		tst_brk(TCONF, "Invalid iteration argument");
+	ret = tst_parse_int(nr_opt, &nr_hpages, 1, INT_MAX);
+	if (ret || nr_hpages <= 0)
+		tst_brk(TCONF, "Invalid pages argument");
+	nr_hugepages = nr_hpages;
+}
+
+static void cleanup(void)
+{
+	if (fha >= 0)
+		SAFE_CLOSE(fha);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"T:", &iterations_opt, "Number of Iterations"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {2, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 20/29] Hugetlb: Migrating libhugetlbfs mprotect
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (18 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 19/29] Hugetlb: Migrating libhugetlbfs mmap-gettest Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 21/29] Hugetlb: Migrating libhugetlbfs mremap-fixed-huge-near-normal Tarun Sahu
                   ` (9 subsequent siblings)
  29 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/mprotect.c test

Test Description: This test uses mprotect to change protection of
hugepage mapping and perform read/write operation. It checks if the
operation results in expected behaviour as per the protection.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap23.c  | 283 ++++++++++++++++++
 3 files changed, 285 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 5d06c8679..2e8d58857 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -24,6 +24,7 @@ hugemmap19 hugemmap19
 hugemmap20 hugemmap20
 hugemmap21 hugemmap21 -T 2 -s 5
 hugemmap22 hugemmap22 -T 2 -s 5
+hugemmap23 hugemmap23
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 0fd01dbce..ffd831f2e 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -23,6 +23,7 @@
 /hugetlb/hugemmap/hugemmap20
 /hugetlb/hugemmap/hugemmap21
 /hugetlb/hugemmap/hugemmap22
+/hugetlb/hugemmap/hugemmap23
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c
new file mode 100644
index 000000000..e93f85669
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap23.c
@@ -0,0 +1,283 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ *
+ * Test Name: mprotect
+ *
+ * Test Description: This test uses mprotect to change protection of hugepage
+ * mapping and perform read/write operation. It checks if the operation results
+ * in expected behaviour as per the protection.
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *
+ */
+
+/* TODO: resolve mmap ENOMEM failure on more iteration */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <setjmp.h>
+#include <signal.h>
+
+#include "hugetlb.h"
+
+#ifndef barrier
+# ifdef mb
+	/* Redefining the mb() */
+#   define barrier() mb()
+# else
+#   define barrier() __asm__ __volatile__ ("" : : : "memory")
+# endif
+#endif
+
+static char *verbose;
+static int  fd = -1;
+static char hfile[MAXPATHLEN];
+static sigjmp_buf sig_escape;
+static void *sig_expected = MAP_FAILED;
+static long hpage_size;
+
+static void sig_handler(int signum, siginfo_t *si, void *uc)
+{
+	(void)uc;
+	if (signum == SIGSEGV) {
+		if (verbose)
+			tst_res(TINFO, "SIGSEGV at %p (sig_expected=%p)\n", si->si_addr,
+			       sig_expected);
+		if (si->si_addr == sig_expected)
+			siglongjmp(sig_escape, 1);
+		tst_res(TFAIL, "SIGSEGV somewhere unexpected");
+		goto fail;
+	}
+	tst_res(TFAIL, "Unexpected signal %s", strsignal(signum));
+fail:
+	tst_brk(TBROK, "Once failed, No point in continue the test.");
+}
+
+static int test_read(void *p)
+{
+	volatile unsigned long *pl = p;
+	unsigned long x;
+
+	if (sigsetjmp(sig_escape, 1)) {
+		/* We got a SEGV */
+		sig_expected = MAP_FAILED;
+		return -1;
+	}
+
+	sig_expected = p;
+	barrier();
+	x = *pl;
+	if (verbose)
+		tst_res(TINFO, "Read back %lu", x);
+	barrier();
+	sig_expected = MAP_FAILED;
+	/*
+	 * gcc 5 complains about x not ever being used, the following
+	 * statement is solely here to shut it up
+	 */
+	pl = (unsigned long *)x;
+
+	return 0;
+}
+
+static int test_write(void *p, unsigned long val)
+{
+	volatile unsigned long *pl = p;
+	unsigned long x;
+
+	if (sigsetjmp(sig_escape, 1)) {
+		/* We got a SEGV */
+		sig_expected = MAP_FAILED;
+		return -1;
+	}
+
+	sig_expected = p;
+	barrier();
+	*pl = val;
+	x = *pl;
+	barrier();
+	sig_expected = MAP_FAILED;
+
+	return (x != val);
+}
+
+#define RANDOM_CONSTANT	0x1234ABCD
+
+static void test_prot(void *p, int prot)
+{
+	int r, w;
+
+	r = test_read(p);
+	if (verbose)
+		tst_res(TINFO, "On Read: %d\n", r);
+	w = test_write(p, RANDOM_CONSTANT);
+	if (verbose)
+		tst_res(TINFO, "On Write: %d\n", w);
+
+	if (prot & PROT_READ) {
+		if (r != 0) {
+			tst_res(TFAIL, "read failed on mmap(prot=%x)", prot);
+			goto fail;
+		}
+
+	} else {
+		if (r != -1) {
+			tst_res(TFAIL, "read succeeded on mmap(prot=%x)", prot);
+			goto fail;
+		}
+	}
+
+	if (prot & PROT_WRITE) {
+		switch (w) {
+		case -1:
+			tst_res(TFAIL, "write failed on mmap(prot=%x)", prot);
+			goto fail;
+		case 0:
+			break;
+		case 1:
+			tst_res(TFAIL, "write mismatch on mmap(prot=%x)", prot);
+			goto fail;
+		default:
+			tst_res(TWARN, "Bug in test");
+			goto fail;
+		}
+	} else {
+		switch (w) {
+		case -1:
+			break;
+		case 0:
+			tst_res(TFAIL, "write succeeded on mmap(prot=%x)", prot);
+			goto fail;
+		case 1:
+			tst_res(TFAIL, "write mismatch on mmap(prot=%x)", prot);
+			goto fail;
+		default:
+			tst_res(TWARN, "Bug in test");
+			break;
+		}
+	}
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continue to the test");
+}
+
+static void test_mprotect(int fd, char *testname,
+			  unsigned long len1, int prot1,
+			  unsigned long len2, int prot2)
+{
+	void *p;
+	int err;
+
+	if (verbose) {
+		tst_res(TINFO, "Testing %s\n", testname);
+		tst_res(TINFO, "Mapping with prot=%x\n", prot1);
+	}
+	p = SAFE_MMAP(NULL, len1, prot1, MAP_SHARED, fd, 0);
+
+	test_prot(p, prot1);
+
+	if (verbose)
+		tst_res(TINFO, "mprotect()ing to prot=%x\n", prot2);
+	err = mprotect(p, len2, prot2);
+	if (err != 0) {
+		tst_res(TFAIL|TERRNO, "%s: mprotect(prot=%x)", testname, prot2);
+		goto fail;
+	}
+
+	test_prot(p, prot2);
+
+	if (len2 < len1)
+		test_prot(p + len2, prot1);
+
+	SAFE_MUNMAP(p, len1);
+	return;
+fail:
+	tst_brk(TBROK, "Once failed, No point in continue the test");
+}
+
+static void run_test(void)
+{
+	void *p;
+
+	struct sigaction sa = {
+		.sa_sigaction = sig_handler,
+		.sa_flags = SA_SIGINFO,
+	};
+
+	SAFE_SIGACTION(SIGSEGV, &sa, NULL);
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	p = SAFE_MMAP(NULL, 2*hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+	memset(p, 0, hpage_size);
+	SAFE_MUNMAP(p, hpage_size);
+
+	/* Basic protection change tests */
+	test_mprotect(fd, "R->RW", hpage_size, PROT_READ,
+		      hpage_size, PROT_READ|PROT_WRITE);
+	test_mprotect(fd, "RW->R", hpage_size, PROT_READ|PROT_WRITE,
+		      hpage_size, PROT_READ);
+
+	/* Tests which require VMA splitting */
+	test_mprotect(fd, "R->RW 1/2", 2*hpage_size, PROT_READ,
+		      hpage_size, PROT_READ|PROT_WRITE);
+	test_mprotect(fd, "RW->R 1/2", 2*hpage_size, PROT_READ|PROT_WRITE,
+		      hpage_size, PROT_READ);
+
+	/* PROT_NONE tests */
+	test_mprotect(fd, "NONE->R", hpage_size, PROT_NONE,
+		      hpage_size, PROT_READ);
+	test_mprotect(fd, "NONE->RW", hpage_size, PROT_NONE,
+		      hpage_size, PROT_READ|PROT_WRITE);
+
+	tst_res(TPASS, "Successful");
+	SAFE_CLOSE(fd);
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 2)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Run test with verbose"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {2, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 21/29] Hugetlb: Migrating libhugetlbfs mremap-fixed-huge-near-normal
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (19 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 20/29] Hugetlb: Migrating libhugetlbfs mprotect Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 22/29] Hugetlb: Migrating libhugetlbfs mremap-fixed-normal-near-huge Tarun Sahu
                   ` (8 subsequent siblings)
  29 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/mremap-fixed-huge-near-normal.c test

Test Description: The kernel has bug for mremap() on some architecture.
mremap() can cause crashes on architectures with holes in the address
space (like ia64) and on powerpc with it's distinct page size "slices".

This test get the normal mapping address and mremap() hugepage mapping
near to this normal mapping.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap25.c  | 168 ++++++++++++++++++
 3 files changed, 170 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap25.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 2e8d58857..3ae1065c7 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -25,6 +25,7 @@ hugemmap20 hugemmap20
 hugemmap21 hugemmap21 -T 2 -s 5
 hugemmap22 hugemmap22 -T 2 -s 5
 hugemmap23 hugemmap23
+hugemmap25 hugemmap25
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index ffd831f2e..c865a1e55 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -24,6 +24,7 @@
 /hugetlb/hugemmap/hugemmap21
 /hugetlb/hugemmap/hugemmap22
 /hugetlb/hugemmap/hugemmap23
+/hugetlb/hugemmap/hugemmap25
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap25.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap25.c
new file mode 100644
index 000000000..59d07734a
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap25.c
@@ -0,0 +1,168 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2009 David Gibson, IBM Corporation.
+ *
+ * Test Name: mremap fixed huge near normal
+ *
+ * Test Description: The kernel has bug for mremap() on some architecture.
+ * mremap() can cause crashes on architectures with holes in the address
+ * space (like ia64) and on powerpc with it's distinct page size "slices".
+ *
+ * This test get the normal mapping address and mremap() hugepage mapping
+ * near to this normal mapping.
+ *
+ * HISTORY
+ *  Written by David Gibson
+ *
+ */
+
+#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 RANDOM_CONSTANT	0x1234ABCD
+#define ALIGN(x, a)	(((x) + (a) - 1) & ~((a) - 1))
+#define PALIGN(p, a) ((void *)ALIGN((unsigned long)(p), (a)))
+
+static char *verbose;
+static int  fd = -1;
+static char hfile[MAXPATHLEN];
+static long hpage_size;
+
+static void do_readback(void *p, size_t size, const char *stage)
+{
+	unsigned int *q = p;
+	size_t i;
+
+	if (verbose)
+		tst_res(TINFO, "%s(%p, 0x%lx, \"%s\")\n", __func__, p,
+		       (unsigned long)size, stage);
+
+	for (i = 0; i < (size / sizeof(*q)); i++)
+		q[i] = RANDOM_CONSTANT ^ i;
+
+	for (i = 0; i < (size / sizeof(*q)); i++) {
+		if (q[i] != (RANDOM_CONSTANT ^ i)) {
+			tst_res(TFAIL, "Stage \"%s\": Mismatch at offset 0x%lx: 0x%x "
+					"instead of 0x%lx", stage, i, q[i], RANDOM_CONSTANT ^ i);
+			tst_brk(TBROK, "Once failed, No point in continue further");
+		}
+	}
+}
+
+static void do_remap(int fd, void *target)
+{
+	void *a, *b;
+
+	a = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+
+	if (verbose)
+		tst_res(TINFO, "Huge base mapping at %p\n", a);
+
+	do_readback(a, hpage_size, "base huge");
+
+	if (verbose)
+		tst_res(TINFO, "Attempting mremap(MAYMOVE|FIXED) to %p...", target);
+
+	b = mremap(a, hpage_size, hpage_size, MREMAP_MAYMOVE | MREMAP_FIXED,
+		   target);
+
+	if (b != MAP_FAILED) {
+		do_readback(b, hpage_size, "remapped");
+
+	} else {
+		if (verbose)
+			tst_res(TINFO|TERRNO, "disallowed");
+		b = a;
+	}
+	SAFE_MUNMAP(b, hpage_size);
+}
+
+static void *map_align(size_t size, size_t align)
+{
+	unsigned long xsize = size + align - getpagesize();
+	size_t t;
+	void *p, *q;
+
+	p = SAFE_MMAP(NULL, xsize, PROT_READ|PROT_WRITE,
+		 MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+
+	q = PALIGN(p, align);
+
+	t = q - p;
+	if (t)
+		SAFE_MUNMAP(p, t);
+
+	t = p + xsize - (q + size);
+	if (t)
+		SAFE_MUNMAP(q + size, t);
+
+	return q;
+}
+
+static void run_test(void)
+{
+	void *p;
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	p = map_align(3*hpage_size, hpage_size);
+
+	SAFE_MUNMAP(p, hpage_size);
+	SAFE_MUNMAP(p + 2*hpage_size, hpage_size);
+
+	p = p + hpage_size;
+
+	if (verbose)
+		tst_res(TINFO, "Normal mapping at %p\n", p);
+
+	do_readback(p, hpage_size, "base normal page");
+
+	do_remap(fd, p - hpage_size);
+	do_remap(fd, p + hpage_size);
+
+	tst_res(TPASS, "Successful");
+	SAFE_CLOSE(fd);
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 3)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {3, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 22/29] Hugetlb: Migrating libhugetlbfs mremap-fixed-normal-near-huge
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (20 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 21/29] Hugetlb: Migrating libhugetlbfs mremap-fixed-huge-near-normal Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 23/29] Hugetlb: Migrating libhugetlbfs noresv-reserve-resv-page Tarun Sahu
                   ` (7 subsequent siblings)
  29 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/mremap-fixed-normal-near-huge.c test

Test Description: The kernel has bug for mremap() on some architecture.
mremap() can cause crashes on architectures with holes in the address
space (like ia64) and on powerpc with it's distinct page size "slices".

This test get the huge mapping address and mremap() normal mapping
near to this huge mapping.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap26.c  | 148 ++++++++++++++++++
 3 files changed, 150 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 3ae1065c7..2c65c1439 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -26,6 +26,7 @@ hugemmap21 hugemmap21 -T 2 -s 5
 hugemmap22 hugemmap22 -T 2 -s 5
 hugemmap23 hugemmap23
 hugemmap25 hugemmap25
+hugemmap26 hugemmap26
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index c865a1e55..4886c6a5f 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -25,6 +25,7 @@
 /hugetlb/hugemmap/hugemmap22
 /hugetlb/hugemmap/hugemmap23
 /hugetlb/hugemmap/hugemmap25
+/hugetlb/hugemmap/hugemmap26
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c
new file mode 100644
index 000000000..0a6981470
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap26.c
@@ -0,0 +1,148 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2009 David Gibson, IBM Corporation.
+ *
+ * Test Name: mremap fixed normal near huge
+ *
+ * Test Description: The kernel has bug for mremap() on some architecture.
+ * mremap() can cause crashes on architectures with holes in the address
+ * space (like ia64) and on powerpc with it's distinct page size "slices".
+ *
+ * This test get the huge mapping address and mremap() normal mapping
+ * near to this huge mapping.
+ *
+ * HISTORY
+ *  Written by David Gibson
+ *
+ */
+
+#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 RANDOM_CONSTANT	0x1234ABCD
+
+static char *verbose;
+static int  fd = -1;
+static char hfile[MAXPATHLEN];
+static long hpage_size, page_size;
+
+static void do_readback(void *p, size_t size, const char *stage)
+{
+	unsigned int *q = p;
+	size_t i;
+
+	if (verbose)
+		tst_res(TINFO, "%s(%p, 0x%lx, \"%s\")", __func__, p,
+		       (unsigned long)size, stage);
+
+	for (i = 0; i < (size / sizeof(*q)); i++)
+		q[i] = RANDOM_CONSTANT ^ i;
+
+	for (i = 0; i < (size / sizeof(*q)); i++) {
+		if (q[i] != (RANDOM_CONSTANT ^ i)) {
+			tst_res(TFAIL, "Stage \"%s\": Mismatch at offset 0x%lx: 0x%x "
+					"instead of 0x%lx", stage, i, q[i], RANDOM_CONSTANT ^ i);
+			tst_brk(TBROK, "Once failed, No point in continue further");
+		}
+	}
+}
+
+static void do_remap(void *target)
+{
+	void *a, *b;
+
+	a = SAFE_MMAP(NULL, page_size, PROT_READ|PROT_WRITE,
+		  MAP_SHARED|MAP_ANONYMOUS, -1, 0);
+
+	if (verbose)
+		tst_res(TINFO, "Normal base mapping at %p\n", a);
+
+	do_readback(a, page_size, "base normal");
+
+	if (verbose)
+		tst_res(TINFO, "Attempting mremap(MAYMOVE|FIXED) to %p...", target);
+
+	b = mremap(a, page_size, page_size, MREMAP_MAYMOVE | MREMAP_FIXED,
+		   target);
+
+	if (b != MAP_FAILED) {
+		do_readback(b, page_size, "remapped");
+	} else {
+		if (verbose)
+			tst_res(TINFO|TERRNO, "disallowed");
+		b = a;
+	}
+
+	SAFE_MUNMAP(b, page_size);
+}
+
+static void run_test(void)
+{
+	void *p;
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+	p = SAFE_MMAP(NULL, 3*hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
+		 fd, 0);
+
+	SAFE_MUNMAP(p, hpage_size);
+
+	SAFE_MUNMAP(p + 2*hpage_size, hpage_size);
+
+	p = p + hpage_size;
+
+	if (verbose)
+		tst_res(TINFO, "Hugepage mapping at %p\n", p);
+
+	do_readback(p, hpage_size, "base hugepage");
+
+	do_remap(p - page_size);
+	do_remap(p + hpage_size);
+
+	tst_res(TPASS, "Successful");
+	SAFE_MUNMAP(p, hpage_size);
+	SAFE_CLOSE(fd);
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 3)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+	page_size = getpagesize();
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {3, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 23/29] Hugetlb: Migrating libhugetlbfs noresv-reserve-resv-page
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (21 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 22/29] Hugetlb: Migrating libhugetlbfs mremap-fixed-normal-near-huge Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 24/29] Hugetlb: Migrating libhugetlbfs noresv-regarded-as-resv Tarun Sahu
                   ` (6 subsequent siblings)
  29 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/noresv-preserve-resv-page.c test

Test Description: Test to preserve a reserved page against no-reserved
mapping. If all hugepages are reserved, access to no-reserved shared
mapping cause a process die, instead of stealing a hugepage which is
reserved for other process.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap27.c  | 166 ++++++++++++++++++
 3 files changed, 168 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap27.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 2c65c1439..c1c2c38bf 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -27,6 +27,7 @@ hugemmap22 hugemmap22 -T 2 -s 5
 hugemmap23 hugemmap23
 hugemmap25 hugemmap25
 hugemmap26 hugemmap26
+hugemmap27 hugemmap27
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 4886c6a5f..9862414c6 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -26,6 +26,7 @@
 /hugetlb/hugemmap/hugemmap23
 /hugetlb/hugemmap/hugemmap25
 /hugetlb/hugemmap/hugemmap26
+/hugetlb/hugemmap/hugemmap27
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap27.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap27.c
new file mode 100644
index 000000000..eeab19f41
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap27.c
@@ -0,0 +1,166 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2013 Joonsoo Kim, LG Electronics.
+ *
+ * Test Name: noresv-preserve-resv-page
+ *
+ * Test Description: Test to preserve a reserved page against no-reserved
+ * mapping. If all hugepages are reserved, access to no-reserved shared
+ * mapping cause a process die, instead of stealing a hugepage which is
+ * reserved for other process.
+ *
+ * HISTORY
+ *  Written by Joonsoo Kim
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <setjmp.h>
+#include <sys/types.h>
+
+#include "tst_test.h"
+
+#ifndef barrier
+# ifdef mb
+	/* Redefining the memory barrier */
+#   define barrier() mb()
+# else
+#   define barrier() __asm__ __volatile__ ("" : : : "memory")
+# endif
+#endif
+
+static char *verbose;
+static char hfile1[MAXPATHLEN], hfile2[MAXPATHLEN];
+static long hpage_size;
+static int fd1 = -1, fd2 = -1;
+static sigjmp_buf sig_escape;
+static void *sig_expected = MAP_FAILED;
+
+static void sig_handler(int signum, siginfo_t *si, void *uc)
+{
+	(void)uc;
+	if (signum == SIGBUS) {
+		if (verbose)
+			tst_res(TINFO, "SIGBUS at %p (sig_expected=%p)\n", si->si_addr,
+			       sig_expected);
+		if (si->si_addr == sig_expected)
+			siglongjmp(sig_escape, 1);
+		tst_res(TFAIL, "SIGBUS somewhere unexpected");
+		goto fail;
+	}
+	tst_res(TFAIL, "Unexpected signal %s", strsignal(signum));
+fail:
+	tst_brk(TBROK, "Once failed, No Point in continuing further");
+}
+
+static int test_write(void *p)
+{
+	volatile char *pl = p;
+
+	if (sigsetjmp(sig_escape, 1)) {
+		/* We got a SIGBUS */
+		tst_res(TPASS, "Successful");
+		return 1;
+	}
+
+	sig_expected = p;
+	barrier();
+	*pl = 's';
+	return 0;
+}
+
+static void run_test(void)
+{
+	int nr_hugepages;
+	int surp_hugepages;
+	int ret;
+	char *p, *q;
+	struct sigaction sa = {
+		.sa_sigaction = sig_handler,
+		.sa_flags = SA_SIGINFO,
+	};
+
+	nr_hugepages = SAFE_READ_MEMINFO("HugePages_Free:");
+
+	fd1 = SAFE_OPEN(hfile1, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile1);
+
+	fd2 = SAFE_OPEN(hfile2, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile2);
+
+	SAFE_SIGACTION(SIGBUS, &sa, NULL);
+
+	p = SAFE_MMAP(NULL, hpage_size * nr_hugepages,
+		PROT_READ | PROT_WRITE, MAP_SHARED, fd1, 0);
+
+	if (verbose)
+		tst_res(TINFO, "Reserve all hugepages %d", nr_hugepages);
+
+	q = SAFE_MMAP(NULL, hpage_size,
+		PROT_READ | PROT_WRITE, MAP_SHARED | MAP_NORESERVE, fd2, 0);
+
+	if (verbose)
+		tst_res(TINFO, "Write to %p to steal reserved page", q);
+
+	surp_hugepages = SAFE_READ_MEMINFO("HugePages_Surp:");
+	ret = test_write(q);
+	if (ret == 1)
+		goto pass;
+	/* Provisioning succeeded because of overcommit */
+	if (SAFE_READ_MEMINFO("HugePages_Surp:") ==
+			surp_hugepages + 1) {
+		tst_res(TPASS, "Successful");
+		goto pass;
+	}
+
+	tst_res(TFAIL, "Steal reserved page");
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+pass:
+	SAFE_MUNMAP(p, hpage_size * nr_hugepages);
+	SAFE_MUNMAP(q, hpage_size);
+	SAFE_CLOSE(fd1);
+	SAFE_CLOSE(fd2);
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 2)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile1, sizeof(hfile1), "%s/ltp_mmap1file%d", Hopt, getpid());
+	snprintf(hfile2, sizeof(hfile2), "%s/ltp_mmap2file%d", Hopt, getpid());
+
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd1 >= 0)
+		SAFE_CLOSE(fd1);
+	if (fd2 >= 0)
+		SAFE_CLOSE(fd2);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {2, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 24/29] Hugetlb: Migrating libhugetlbfs noresv-regarded-as-resv
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (22 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 23/29] Hugetlb: Migrating libhugetlbfs noresv-reserve-resv-page Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 25/29] Hugetlb: Migrating libhugetlbfs private Tarun Sahu
                   ` (5 subsequent siblings)
  29 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/noresv-regarded-as-resv.c test

Test Description: Test to correct handling for reserve count. If no
reserved mapping is created to reserved file region, it should be
considered as reserve mapping. Otherwise, reserve count will be
overflowed.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap28.c  | 107 ++++++++++++++++++
 3 files changed, 109 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap28.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index c1c2c38bf..f9a9501b7 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -28,6 +28,7 @@ hugemmap23 hugemmap23
 hugemmap25 hugemmap25
 hugemmap26 hugemmap26
 hugemmap27 hugemmap27
+hugemmap28 hugemmap28
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 9862414c6..2f8ed0df0 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -27,6 +27,7 @@
 /hugetlb/hugemmap/hugemmap25
 /hugetlb/hugemmap/hugemmap26
 /hugetlb/hugemmap/hugemmap27
+/hugetlb/hugemmap/hugemmap28
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap28.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap28.c
new file mode 100644
index 000000000..55399c3b6
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap28.c
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2013 Joonsoo Kim, LG Electronics.
+ *
+ * Test Name: noresv-regarded-as-resv
+ *
+ * Test Description: Test to correct handling for reserve count. If no
+ * reserved mapping is created to reserved file region, it should be
+ * considered as reserve mapping. Otherwise, reserve count will be
+ * overflowed.
+ *
+ * HISTORY
+ *  Written by Joonsoo Kim
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <setjmp.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+static char *verbose;
+static char hfile[MAXPATHLEN];
+static long hpage_size;
+static int fd = -1;
+
+static void run_test(void)
+{
+	int nr_resvpages1, nr_resvpages2;
+	int fd;
+	char *p, *q;
+
+	nr_resvpages1 = SAFE_READ_MEMINFO("HugePages_Rsvd:");
+	if (verbose)
+		tst_res(TINFO, "Number of reserve page is %d\n", nr_resvpages1);
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+
+	if (verbose)
+		tst_res(TINFO, "Reserve a page to file offset 0");
+
+	q = SAFE_MMAP(NULL, hpage_size,
+		PROT_READ | PROT_WRITE, MAP_SHARED | MAP_NORESERVE, fd, 0);
+
+	if (verbose)
+		tst_res(TINFO, "Map a page of file offset 0 with no resv mapping");
+	*q = 's';
+
+	SAFE_MUNMAP(p, hpage_size);
+	SAFE_MUNMAP(q, hpage_size);
+	SAFE_CLOSE(fd);
+
+	nr_resvpages2 = SAFE_READ_MEMINFO("HugePages_Rsvd:");
+	if (verbose)
+		tst_res(TINFO, "Number of reserve page is now %d\n", nr_resvpages2);
+
+	if (nr_resvpages1 != nr_resvpages2) {
+		tst_res(TFAIL, "Reserve count overflowed");
+		tst_brk(TBROK, "Once failed, No point in continuing the test");
+	}
+
+	tst_res(TPASS, "Successful");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 2)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlb1file%d", Hopt, getpid());
+
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {2, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 25/29] Hugetlb: Migrating libhugetlbfs private
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (23 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 24/29] Hugetlb: Migrating libhugetlbfs noresv-regarded-as-resv Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 26/29] Hugetlb: Migrating libhugetlbfs readahead_reserve Tarun Sahu
                   ` (4 subsequent siblings)
  29 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/private.c test

Test Description: The test do mmap() with shared mapping and write.
It matches the data with private mmap() and then change it with other
data. It checks shared mapping data if data is not contaiminated by
private mapping.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap29.c  | 129 ++++++++++++++++++
 3 files changed, 131 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index f9a9501b7..906acb266 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -29,6 +29,7 @@ hugemmap25 hugemmap25
 hugemmap26 hugemmap26
 hugemmap27 hugemmap27
 hugemmap28 hugemmap28
+hugemmap29 hugemmap29
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 2f8ed0df0..fef0a76d6 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -28,6 +28,7 @@
 /hugetlb/hugemmap/hugemmap26
 /hugetlb/hugemmap/hugemmap27
 /hugetlb/hugemmap/hugemmap28
+/hugetlb/hugemmap/hugemmap29
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c
new file mode 100644
index 000000000..c3ec56026
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap29.c
@@ -0,0 +1,129 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ *
+ * Test Name: Private Mapping
+ *
+ * Test Description: The test do mmap() with shared mapping and write.
+ * It matches the data with private mmap() and then change it with other
+ * data. It checks shared mapping data if data is not contaiminated by
+ * private mapping.
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <setjmp.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+#define RANDOM_CONSTANT	0x1234ABCD
+#define OTHER_CONSTANT  0xFEDC9876
+
+static char hfile[MAXPATHLEN];
+static unsigned long hpage_size;
+static int fd = -1;
+
+static void run_test(void)
+{
+	void *p, *q;
+	unsigned int *pl, *ql;
+	unsigned long i;
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
+		 fd, 0);
+
+	pl = p;
+	for (i = 0; i < (hpage_size / sizeof(*pl)); i++)
+		pl[i] = RANDOM_CONSTANT ^ i;
+
+	q = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE,
+		 fd, 0);
+
+	ql = q;
+	for (i = 0; i < (hpage_size / sizeof(*ql)); i++) {
+		if (ql[i] != (RANDOM_CONSTANT ^ i)) {
+			tst_res(TFAIL, "Mismatch");
+			goto fail;
+		}
+	}
+
+	for (i = 0; i < (hpage_size / sizeof(*ql)); i++)
+		ql[i] = OTHER_CONSTANT ^ i;
+
+	for (i = 0; i < (hpage_size / sizeof(*ql)); i++) {
+		if (ql[i] != (OTHER_CONSTANT ^ i)) {
+			tst_res(TFAIL, "PRIVATE mismatch");
+			goto fail;
+		}
+	}
+
+	for (i = 0; i < (hpage_size / sizeof(*pl)); i++) {
+		if (pl[i] != (RANDOM_CONSTANT ^ i)) {
+			tst_res(TFAIL, "SHARED map contaminated");
+			goto fail;
+		}
+	}
+
+	memset(p, 0, hpage_size);
+
+	for (i = 0; i < (hpage_size / sizeof(*ql)); i++) {
+		if (ql[i] != (OTHER_CONSTANT ^ i)) {
+			tst_res(TFAIL, "PRIVATE map contaminated");
+			goto fail;
+		}
+	}
+	tst_res(TPASS, "Successful");
+	SAFE_MUNMAP(p, hpage_size);
+	SAFE_MUNMAP(q, hpage_size);
+	SAFE_CLOSE(fd);
+	return;
+
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 2)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {2, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 26/29] Hugetlb: Migrating libhugetlbfs readahead_reserve
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (24 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 25/29] Hugetlb: Migrating libhugetlbfs private Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 27/29] Hugetlb: Migrating libhugetlbfs readback Tarun Sahu
                   ` (3 subsequent siblings)
  29 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/readahead_reserve.c test

Test Description: readahead() 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's fixed in kernel by 'commit f2deae9d4e70
("Remove implementation of readpage from the hugetlbfs_aops")'.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap30.c  | 120 ++++++++++++++++++
 3 files changed, 122 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap30.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 906acb266..76ff1a3dd 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -30,6 +30,7 @@ hugemmap26 hugemmap26
 hugemmap27 hugemmap27
 hugemmap28 hugemmap28
 hugemmap29 hugemmap29
+hugemmap30 hugemmap30
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index fef0a76d6..bb9720452 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -29,6 +29,7 @@
 /hugetlb/hugemmap/hugemmap27
 /hugetlb/hugemmap/hugemmap28
 /hugetlb/hugemmap/hugemmap29
+/hugetlb/hugemmap/hugemmap30
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap30.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap30.c
new file mode 100644
index 000000000..030dbb851
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap30.c
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 IBM Corporation.
+ *
+ * Test Name: Readahead Reserve
+ *
+ * Test Description: readahead() 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's fixed in kernel by commit f2deae9d4e70793568ef9e85d227abb7bef5b622.
+ *
+ * HISTORY
+ *  Written by Mel Gorman & Eric B Munson
+ *
+ */
+
+#define _GNU_SOURCE
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+static char *verbose;
+static char hfile[MAXPATHLEN];
+static long hpage_size;
+static int fd = -1;
+
+static void run_test(void)
+{
+	void *p;
+	unsigned long initial_rsvd, map_rsvd, readahead_rsvd, end_rsvd;
+
+	/* Setup */
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	initial_rsvd = SAFE_READ_MEMINFO("HugePages_Rsvd:");
+	if (verbose)
+		tst_res(TINFO, "Reserve count before map: %lu", initial_rsvd);
+
+	/* mmap a region and record reservations */
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
+		 fd, 0);
+	map_rsvd = SAFE_READ_MEMINFO("HugePages_Rsvd:");
+	if (verbose)
+		tst_res(TINFO, "Reserve count after map: %lu", map_rsvd);
+
+	/* readahead the region and record reservations */
+	readahead(fd, 0, hpage_size);
+	readahead_rsvd = SAFE_READ_MEMINFO("HugePages_Rsvd:");
+	if (verbose)
+		tst_res(TINFO, "Reserve count after readahead: %lu", readahead_rsvd);
+
+	/* Write the region */
+	memset(p, 1, hpage_size);
+
+	/* Free region */
+	SAFE_MUNMAP(p, hpage_size);
+	SAFE_CLOSE(fd);
+	end_rsvd = SAFE_READ_MEMINFO("HugePages_Rsvd:");
+	if (verbose)
+		tst_res(TINFO, "Reserve count after close(): %lu\n", end_rsvd);
+
+	/* Reserve count should match initial reserve count */
+	if (end_rsvd != initial_rsvd) {
+		tst_res(TFAIL, "Reserve leaked: %lu != %lu\n", end_rsvd, initial_rsvd);
+		goto fail;
+	}
+
+	tst_res(TPASS, "Successful");
+	return;
+
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 1)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {1, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 27/29] Hugetlb: Migrating libhugetlbfs readback
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (25 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 26/29] Hugetlb: Migrating libhugetlbfs readahead_reserve Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 28/29] Hugetlb: Migrating libhugetlbfs shared Tarun Sahu
                   ` (2 subsequent siblings)
  29 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/readback.c test

Test Description: This test is basic test for data validation written on
hugepages. It writes random data in chunks, read back and confirm they
are same.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |  1 +
 testcases/kernel/mem/.gitignore               |  1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap31.c  | 98 +++++++++++++++++++
 3 files changed, 100 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap31.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 76ff1a3dd..32d22dd88 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -31,6 +31,7 @@ hugemmap27 hugemmap27
 hugemmap28 hugemmap28
 hugemmap29 hugemmap29
 hugemmap30 hugemmap30
+hugemmap31 hugemmap31
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index bb9720452..8375389cd 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -30,6 +30,7 @@
 /hugetlb/hugemmap/hugemmap28
 /hugetlb/hugemmap/hugemmap29
 /hugetlb/hugemmap/hugemmap30
+/hugetlb/hugemmap/hugemmap31
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap31.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap31.c
new file mode 100644
index 000000000..8d3a62e28
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap31.c
@@ -0,0 +1,98 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ *
+ * Test Name: Readback
+ *
+ * Test Description: This test is basic test for data validation written on
+ * hugepages. It writes random data in chunks, read back and confirm they
+ * are same.
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <setjmp.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+#define RANDOM_CONSTANT	0x1234ABCD
+static char *verbose;
+static char hfile[MAXPATHLEN];
+static long hpage_size;
+static int fd = -1;
+
+static void run_test(void)
+{
+	void *p;
+	unsigned long *q;
+	unsigned long i;
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
+		 fd, 0);
+
+	q = p;
+	for (i = 0; i < (hpage_size / sizeof(*q)); i++)
+		q[i] = RANDOM_CONSTANT ^ i;
+
+	for (i = 0; i < (hpage_size / sizeof(*q)); i++) {
+		if (q[i] != (RANDOM_CONSTANT ^ i)) {
+			tst_res(TFAIL, "Mismatch at offset 0x%lx: 0x%lx instead of 0x%lx",
+			     i, q[i], RANDOM_CONSTANT ^ i);
+			goto fail;
+		}
+	}
+	tst_res(TPASS, "Successful");
+	SAFE_MUNMAP(p, hpage_size);
+	SAFE_CLOSE(fd);
+	return;
+
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 1)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {1, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 28/29] Hugetlb: Migrating libhugetlbfs shared
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (26 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 27/29] Hugetlb: Migrating libhugetlbfs readback Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-16 12:57 ` [LTP] [PATCH 29/29] Hugetlb: Migrating libhugetlbfs shm-fork Tarun Sahu
  2022-10-18 13:51 ` [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Richard Palethorpe
  29 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

Migrating the libhugetlbfs/testcases/shared.c test

Test Description: This test is basic shared mapping test. Two shared
mappings are created with same offset on a file. It checks if writing
to one mapping can be seen to other mapping or not?

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap32.c  | 104 ++++++++++++++++++
 3 files changed, 106 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 32d22dd88..2088df636 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -32,6 +32,7 @@ hugemmap28 hugemmap28
 hugemmap29 hugemmap29
 hugemmap30 hugemmap30
 hugemmap31 hugemmap31
+hugemmap32 hugemmap32
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
 hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 8375389cd..81b9f547c 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -31,6 +31,7 @@
 /hugetlb/hugemmap/hugemmap29
 /hugetlb/hugemmap/hugemmap30
 /hugetlb/hugemmap/hugemmap31
+/hugetlb/hugemmap/hugemmap32
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
 /hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.c
new file mode 100644
index 000000000..e40e351da
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap32.c
@@ -0,0 +1,104 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ *
+ * Test Name: Shared Mapping
+ *
+ * Test Description: This test is basic shared mapping test. Two shared
+ * mappings are created with same offset on a file. It checks if writing
+ * to one mapping can be seen to other mapping or not?
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <setjmp.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+#define RANDOM_CONSTANT	0x1234ABCD
+
+static char *verbose;
+static char hfile[MAXPATHLEN];
+static long hpage_size;
+static int fd = -1;
+
+static void run_test(void)
+{
+	void *p, *q;
+	unsigned long *pl, *ql;
+	unsigned long i;
+
+	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
+	SAFE_UNLINK(hfile);
+
+	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
+		 fd, 0);
+
+	q = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
+		 fd, 0);
+
+	pl = p;
+	for (i = 0; i < (hpage_size / sizeof(*pl)); i++)
+		pl[i] = RANDOM_CONSTANT ^ i;
+
+	ql = q;
+	for (i = 0; i < (hpage_size / sizeof(*ql)); i++) {
+		if (ql[i] != (RANDOM_CONSTANT ^ i)) {
+			tst_res(TFAIL, "Mismatch");
+			goto fail;
+		}
+	}
+
+	tst_res(TPASS, "Successful");
+	SAFE_MUNMAP(p, hpage_size);
+	SAFE_MUNMAP(q, hpage_size);
+	SAFE_CLOSE(fd);
+	return;
+
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+}
+
+static void setup(void)
+{
+	if (tst_hugepages < 2)
+		tst_brk(TCONF, "Not enough hugepages for testing.");
+
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
+
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {2, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* [LTP] [PATCH 29/29] Hugetlb: Migrating libhugetlbfs shm-fork
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (27 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 28/29] Hugetlb: Migrating libhugetlbfs shared Tarun Sahu
@ 2022-10-16 12:57 ` Tarun Sahu
  2022-10-18 13:51 ` [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Richard Palethorpe
  29 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-16 12:57 UTC (permalink / raw)
  To: ltp; +Cc: aneesh.kumar, sbhat, vaibhav

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

Test Description: Test shared memory behavior when multiple threads are
Test shared memory behavior when multiple threads are attached
to a segment.  A segment is created and then children are
spawned which attach, write, read (verify), and detach from the
shared memory segment.

Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugefork/hugefork02.c  | 196 ++++++++++++++++++
 3 files changed, 198 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugefork/hugefork02.c

diff --git a/runtest/hugetlb b/runtest/hugetlb
index 2088df636..28dc487a4 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -2,6 +2,7 @@ hugefallocate01 hugefallocate01
 hugefallocate02 hugefallocate02
 
 hugefork01 hugefork01
+hugefork02 hugefork02 -P 3 -s 5
 
 hugemmap01 hugemmap01
 hugemmap02 hugemmap02
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 81b9f547c..20b60b1a1 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -2,6 +2,7 @@
 /hugetlb/hugefallocate/hugefallocate01
 /hugetlb/hugefallocate/hugefallocate02
 /hugetlb/hugefork/hugefork01
+/hugetlb/hugefork/hugefork02
 /hugetlb/hugemmap/hugemmap01
 /hugetlb/hugemmap/hugemmap02
 /hugetlb/hugemmap/hugemmap04
diff --git a/testcases/kernel/mem/hugetlb/hugefork/hugefork02.c b/testcases/kernel/mem/hugetlb/hugefork/hugefork02.c
new file mode 100644
index 000000000..16e41486b
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugefork/hugefork02.c
@@ -0,0 +1,196 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ *
+ * Test Name: Private Mapping
+ *
+ * Test Description: Test shared memory behavior when multiple threads are
+ * Test shared memory behavior when multiple threads are attached
+ * to a segment.  A segment is created and then children are
+ * spawned which attach, write, read (verify), and detach from the
+ * shared memory segment.
+ *
+ * HISTORY
+ *  Written by David Gibson & Adam Litke
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <setjmp.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/shm.h>
+
+#include "tst_safe_sysv_ipc.h"
+#include "hugetlb.h"
+
+static int nr_hugepages;
+static int numprocs;
+static int shmid = -1;
+
+#define MAX_PROCS 200
+#define BUF_SZ 256
+
+#define CHILD_FAIL(thread, fmt, ...) \
+	do { \
+		if (verbose) \
+			tst_res(TINFO, "Thread %d (pid=%d) FAIL: " fmt, \
+			       thread, getpid(), ##__VA_ARGS__); \
+		exit(1); \
+	} while (0)
+
+static char *verbose;
+static char hfile[MAXPATHLEN];
+static long hpage_size;
+static int numprocs;
+static char *numprocs_opt;
+
+static void do_child(int thread, unsigned long size)
+{
+	volatile char *shmaddr;
+	int j;
+	unsigned long k;
+
+	for (j = 0; j < 5; j++) {
+		shmaddr = shmat(shmid, 0, SHM_RND);
+		if (shmaddr == MAP_FAILED)
+			CHILD_FAIL(thread, "shmat() failed");
+
+		for (k = 0; k < size; k++)
+			shmaddr[k] = (char) (k);
+		for (k = 0; k < size; k++)
+			if (shmaddr[k] != (char)k)
+				CHILD_FAIL(thread, "Index %lu mismatch", k);
+
+		if (shmdt((const void *)shmaddr) != 0)
+			CHILD_FAIL(thread, "shmdt() failed: %s",
+				   strerror(errno));
+	}
+	exit(0);
+}
+
+static void check_hugetlb_shm_group(void)
+{
+	int fd;
+	char gid_buffer[64] = {0};
+	gid_t hugetlb_shm_group;
+	gid_t gid = getgid();
+	uid_t uid = getuid();
+
+	/* root is an exception */
+	if (uid == 0)
+		return;
+
+	fd = SAFE_OPEN("/proc/sys/vm/hugetlb_shm_group", O_RDONLY);
+	SAFE_READ(0, fd, &gid_buffer, sizeof(gid_buffer));
+	hugetlb_shm_group = atoi(gid_buffer);
+	SAFE_CLOSE(fd);
+	if (hugetlb_shm_group != gid)
+		tst_brk(TCONF, "Do not have permission to use SHM_HUGETLB");
+}
+
+static void run_test(void)
+{
+	unsigned long size;
+	int pid, status;
+	int i;
+	int wait_list[MAX_PROCS];
+
+	check_hugetlb_shm_group();
+
+	size = hpage_size * nr_hugepages;
+	if (verbose)
+		tst_res(TINFO, "Requesting %lu bytes\n", size);
+
+	shmid = shmget(2, size, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W);
+	if (shmid < 0) {
+		tst_res(TFAIL|TERRNO, "shmget()");
+		goto fail;
+	}
+
+	if (verbose) {
+		tst_res(TINFO, "shmid: %d\n", shmid);
+		tst_res(TINFO, "Spawning children:\n");
+	}
+	for (i = 0; i < numprocs; i++) {
+		pid = SAFE_FORK();
+
+		if (pid == 0)
+			do_child(i, size);
+
+		wait_list[i] = pid;
+	}
+
+	for (i = 0; i < numprocs; i++) {
+		SAFE_WAITPID(wait_list[i], &status, 0);
+		if (WEXITSTATUS(status) != 0) {
+			tst_res(TFAIL, "Thread %d (pid=%d) failed", i, wait_list[i]);
+			goto fail;
+		}
+		if (WIFSIGNALED(status)) {
+			tst_res(TFAIL, "Thread %d (pid=%d) received unhandled signal",
+			     i, wait_list[i]);
+			goto fail;
+		}
+	}
+
+	tst_res(TPASS, "Successful");
+	return;
+
+fail:
+	tst_brk(TBROK, "Once failed, No point in continuing the test");
+}
+
+static void setup(void)
+{
+	if (!Hopt)
+		Hopt = tst_get_tmpdir();
+	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
+
+	snprintf(hfile, sizeof(hfile), "%s/ltp_mmapfile%d", Hopt, getpid());
+
+	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+
+	if (!(numprocs_opt) || !(nr_opt))
+		tst_brk(TCONF, "Usage: -P  <# procs> -s <# pages>");
+
+	tst_parse_int(numprocs_opt, &numprocs, 1, INT_MAX);
+	tst_parse_int(nr_opt, &nr_hugepages, 1, INT_MAX);
+
+	if (numprocs > MAX_PROCS)
+		tst_brk(TCONF, "Cannot spawn more than %d processes", MAX_PROCS);
+
+	if ((unsigned long)nr_hugepages > tst_hugepages)
+		tst_brk(TCONF, "Not enough hugepages available only %lu max",
+				tst_hugepages);
+}
+
+static void cleanup(void)
+{
+	if (shmid >= 0)
+		SAFE_SHMCTL(shmid, IPC_RMID, NULL);
+	umount2(Hopt, MNT_DETACH);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.options = (struct tst_option[]) {
+		{"v", &verbose, "Turns on verbose mode"},
+		{"P:", &numprocs_opt, "Num of process to run in parallel"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
+		{}
+	},
+	.forks_child = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {5, TST_REQUEST},
+};
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge
  2022-10-16 12:57 ` [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge Tarun Sahu
@ 2022-10-17  9:30   ` Cyril Hrubis
  2022-10-18  7:33     ` Tarun Sahu
  2022-10-17 10:20   ` Li Wang
  1 sibling, 1 reply; 53+ messages in thread
From: Cyril Hrubis @ 2022-10-17  9:30 UTC (permalink / raw)
  To: Tarun Sahu; +Cc: aneesh.kumar, sbhat, ltp, vaibhav

Hi!
> Test Description:
> Certain kernels have a bug where brk() does not perform the same checks
> that a MAP_FIXED mmap() will, allowing brk() to create a normal page VMA in
> a hugepage only address region. This can lead to oopses or other badness.
> 
> Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
> ---
>  runtest/hugetlb                               |   1 +
>  testcases/kernel/mem/.gitignore               |   1 +
>  .../kernel/mem/hugetlb/hugemmap/hugemmap07.c  | 163 ++++++++++++++++++
>  testcases/kernel/mem/hugetlb/lib/hugetlb.c    |  75 ++++++++
>  testcases/kernel/mem/hugetlb/lib/hugetlb.h    |   5 +
>  5 files changed, 245 insertions(+)
>  create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c
> 
> diff --git a/runtest/hugetlb b/runtest/hugetlb
> index f719217ab..f7ff81cb3 100644
> --- a/runtest/hugetlb
> +++ b/runtest/hugetlb
> @@ -3,6 +3,7 @@ hugemmap02 hugemmap02
>  hugemmap04 hugemmap04
>  hugemmap05 hugemmap05
>  hugemmap06 hugemmap06
> +hugemmap07 hugemmap07
>  hugemmap05_1 hugemmap05 -m
>  hugemmap05_2 hugemmap05 -s
>  hugemmap05_3 hugemmap05 -s -m
> diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
> index ff2910533..df5256ec8 100644
> --- a/testcases/kernel/mem/.gitignore
> +++ b/testcases/kernel/mem/.gitignore
> @@ -4,6 +4,7 @@
>  /hugetlb/hugemmap/hugemmap04
>  /hugetlb/hugemmap/hugemmap05
>  /hugetlb/hugemmap/hugemmap06
> +/hugetlb/hugemmap/hugemmap07
>  /hugetlb/hugeshmat/hugeshmat01
>  /hugetlb/hugeshmat/hugeshmat02
>  /hugetlb/hugeshmat/hugeshmat03
> diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c
> new file mode 100644
> index 000000000..06fd0b86c
> --- /dev/null
> +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c
> @@ -0,0 +1,163 @@
> +// SPDX-License-Identifier: LGPL-2.1-or-later
> +/*
> + * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
> + *
> + * Test Name: brk near hugepage
> + *
> + * Test Description: Certain kernels have a bug where brk() does not perform
> + * the same checks that a MAP_FIXED mmap() will, allowing brk() to create a
> + * normal page VMA in a hugepage only address region. This can lead to oopses
> + * or other badness.

This description has to be in a separate ascii-doc formatted comment
that starts with /*\

> + * HISTORY
> + *  Written by David Gibson & Adam Litke
> + *
> + */
> +
> +#define _GNU_SOURCE
> +#include <stdio.h>
> +#include <sys/mount.h>
> +#include <limits.h>
> +#include <sys/param.h>
> +#include <sys/types.h>
> +
> +#include "hugetlb.h"
> +#include "tst_safe_stdio.h"
> +
> +static char *verbose;
> +static int  fd = -1;
> +static char hfile[MAXPATHLEN];
> +static long hpage_size;
> +
> +static int arch_has_slice_support(void)
> +{
> +#ifdef __powerpc64__
> +	char mmu_type[16];
> +	FILE *fp;
> +
> +	fp = SAFE_POPEN("cat /proc/cpuinfo | grep MMU | awk '{ print $3}'", "r");
> +	if (fscanf(fp, "%s", mmu_type) < 0)
> +		tst_brk(TBROK, "Failed to determine MMU type");
> +
> +	pclose(fp);
> +	return strcmp(mmu_type, "Hash") == 0;
> +#elif defined(__powerpc__) && !defined(PPC_NO_SEGMENTS)
> +	return 1;
> +#else
> +	return 0;
> +#endif
> +}
> +
> +#ifdef __powerpc64__
> +static void *next_chunk(void *addr)
> +{
> +	if (!arch_has_slice_support())
> +		return PALIGN(addr, SAFE_READ_MEMINFO("Hugepagesize:")*1024);
> +
> +	if ((unsigned long)addr < 0x100000000UL)
> +		/* 256M segments below 4G */
> +		return PALIGN(addr, 0x10000000UL);
> +	/* 1TB segments above */
> +	return PALIGN(addr, 0x10000000000UL);
> +}
> +#elif defined(__powerpc__) && !defined(PPC_NO_SEGMENTS)
> +static void *next_chunk(void *addr)
> +{
> +	return PALIGN(addr, 0x10000000UL);
> +}
> +#elif defined(__ia64__)
> +static void *next_chunk(void *addr)
> +{
> +	return PALIGN(addr, 0x8000000000000000UL);
> +}
> +#else
> +static void *next_chunk(void *addr)
> +{
> +	return PALIGN(addr, SAFE_READ_MEMINFO("Hugepagesize:")*1024);
> +}
> +#endif
> +
> +static void run_test(void)
> +{
> +	void *brk0, *hugemap_addr, *newbrk;
> +	char *p;
> +	int err;
> +
> +	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
> +	SAFE_UNLINK(hfile);

> +	brk0 = sbrk(0);
> +	if (verbose)
> +		tst_res(TINFO, "Initial break at %p", brk0);
> +
> +	hugemap_addr = next_chunk(brk0) + hpage_size;
> +
> +	p = SAFE_MMAP(hugemap_addr, hpage_size, PROT_READ|PROT_WRITE,
> +			MAP_PRIVATE|MAP_FIXED, fd, 0);
> +	if (p != hugemap_addr) {
> +		tst_res(TFAIL, "mmap() at unexpected address %p instead of %p\n", p,
> +		     hugemap_addr);
> +		goto fail;

Can we just do return here instead. The failure has been reported there
is no point in calling tst_brk(TBROK, ...) as well.

> +	}
> +
> +	err = test_addr_huge((void *)p);
> +	if (err != 1) {
> +		tst_res(TFAIL, "Mapped address is not hugepage");
> +		goto fail;
> +	}

I do not get why we even need this check. We map a file located on
hugetlbfs and then we stat it and check that it indeed is on hutetlbfs.
What did we expect to fail here? I would say that the mmap() with right
path is enough to make sure that the file is created on hugetlbfs.

> +	newbrk = next_chunk(brk0) + getpagesize();
> +	err = brk((void *)newbrk);
> +	if (err == -1) {
> +		/* Failing the brk() is an acceptable kernel response */
> +		tst_res(TPASS, "Failing the brk is an acceptable response");
> +	} else {
> +		/* Suceeding the brk() is acceptable iff the new memory is
> +		 * properly accesible and we don't have a kernel blow up when
> +		 * we touch it.
> +		 */
> +		memset(brk0, 0, newbrk-brk0);
> +		tst_res(TPASS, "Succeding brk is acceptable, as memset confirms that "
> +				"new memory is properly accessible without kernel blow up");
> +	}
> +	SAFE_MUNMAP(p, hpage_size);
> +	SAFE_CLOSE(fd);

Shouldn't we brk() back to the original brk0? Does the test work with -i 2?

> +	return;
> +fail:
> +	tst_brk(TBROK, "Once failed, No point in continuing the test");
> +}
> +
> +static void setup(void)
> +{
> +	if (tst_hugepages < 1)
> +		tst_brk(TCONF, "Not enough hugepages for testing.");
> +
> +	if (!Hopt)
> +		Hopt = tst_get_tmpdir();
> +	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
> +
> +	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
> +	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
> +}
> +
> +static void cleanup(void)
> +{
> +	if (fd >= 0)
> +		SAFE_CLOSE(fd);
> +	umount2(Hopt, MNT_DETACH);

We whould umount here only if we actually have mounted something.

> +}
> +
> +static struct tst_test test = {
> +	.needs_root = 1,
> +	.needs_tmpdir = 1,
> +	.options = (struct tst_option[]) {
> +		{"v", &verbose, "Turns on verbose mode"},
> +		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
> +		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
> +		{}
> +	},
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test_all = run_test,
> +	.hugepages = {1, TST_REQUEST},
> +};
> diff --git a/testcases/kernel/mem/hugetlb/lib/hugetlb.c b/testcases/kernel/mem/hugetlb/lib/hugetlb.c
> index 1204f21d2..d215c69dd 100644
> --- a/testcases/kernel/mem/hugetlb/lib/hugetlb.c
> +++ b/testcases/kernel/mem/hugetlb/lib/hugetlb.c
> @@ -29,15 +29,19 @@
>   *	getipckey()
>   *	getuserid()
>   *	rm_shm()
> + *	read_maps()
> + *	test_addr_huge()
>   */
>  
>  #define TST_NO_DEFAULT_MAIN
> +#define _GNU_SOURCE
>  #include <sys/types.h>
>  #include <sys/ipc.h>
>  #include <sys/shm.h>
>  #include <sys/time.h>
>  #include <pwd.h>
>  #include "hugetlb.h"
> +#include "tst_safe_stdio.h"
>  
>  key_t shmkey;
>  
> @@ -111,3 +115,74 @@ void rm_shm(int shm_id)
>  		tst_res(TINFO, "id = %d", shm_id);
>  	}
>  }
> +
> +#define MAPS_BUF_SZ 4096
> +#define HUGETLBFS_MAGIC 0x958458f6
> +
> +int read_maps(unsigned long addr, char *buf)
> +{
> +	FILE *f;
> +	char line[MAPS_BUF_SZ];
> +	char *tmp;
> +
> +	f = SAFE_FOPEN("/proc/self/maps", "r");
> +
> +	while (1) {
> +		unsigned long start, end, off, ino;
> +		int ret;
> +
> +		tmp = fgets(line, MAPS_BUF_SZ, f);
> +		if (!tmp)
> +			break;
> +
> +		buf[0] = '\0';
> +		ret = sscanf(line, "%lx-%lx %*s %lx %*s %ld %255s",
> +			     &start, &end, &off, &ino,
> +			     buf);
> +		if ((ret < 4) || (ret > 5)) {
> +			tst_res(TWARN, "Couldn't parse /proc/self/maps line: %s\n",
> +			      line);
> +			SAFE_FCLOSE(f);
> +			return -1;
> +		}
> +
> +		if ((start <= addr) && (addr < end)) {
> +			SAFE_FCLOSE(f);
> +			return 1;
> +		}
> +	}
> +
> +	SAFE_FCLOSE(f);
> +	return 0;
> +}
> +
> +int test_addr_huge(void *p)
> +{
> +	char name[256];
> +	char *dirend;
> +	int ret;
> +	struct statfs64 sb;
> +
> +	ret = read_maps((unsigned long)p, name);
> +	if (ret < 0)
> +		return ret;
> +	if (ret == 0) {
> +		tst_res(TWARN, "Couldn't find address %p in /proc/self/maps\n", p);
> +		return -1;
> +	}
> +
> +	/* looks like a filename? */
> +	if (name[0] != '/')
> +		return 0;
> +
> +	/* Truncate the filename portion */
> +	dirend = strrchr(name, '/');
> +	if (dirend && dirend > name)
> +		*dirend = '\0';
> +
> +	ret = statfs64(name, &sb);
> +	if (ret)
> +		return -1;
> +
> +	return (sb.f_type == HUGETLBFS_MAGIC);
> +}
> diff --git a/testcases/kernel/mem/hugetlb/lib/hugetlb.h b/testcases/kernel/mem/hugetlb/lib/hugetlb.h
> index f75109f3e..c522314eb 100644
> --- a/testcases/kernel/mem/hugetlb/lib/hugetlb.h
> +++ b/testcases/kernel/mem/hugetlb/lib/hugetlb.h
> @@ -20,6 +20,9 @@
>  #include "old_tmpdir.h"
>  #include "mem.h"
>  
> +#define ALIGN(x, a)	(((x) + (a) - 1) & ~((a) - 1))
> +#define PALIGN(p, a) ((void *)ALIGN((unsigned long)(p), (a)))
> +
>  #define SHM_RD	0400
>  #define SHM_WR	0200
>  #define SHM_RW	(SHM_RD|SHM_WR)
> @@ -39,5 +42,7 @@ extern key_t shmkey;			/* an IPC key generated by ftok() */
>  int getipckey(void);
>  int getuserid(char *user);
>  void rm_shm(int shm_id);
> +int test_addr_huge(void *p);
> +int read_maps(unsigned long addr, char *buf);
>  
>  #endif /* hugetlb.h */
> -- 
> 2.31.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge
  2022-10-16 12:57 ` [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge Tarun Sahu
  2022-10-17  9:30   ` Cyril Hrubis
@ 2022-10-17 10:20   ` Li Wang
  2022-10-18  7:36     ` Tarun Sahu
  1 sibling, 1 reply; 53+ messages in thread
From: Li Wang @ 2022-10-17 10:20 UTC (permalink / raw)
  To: Tarun Sahu; +Cc: aneesh.kumar, sbhat, ltp, vaibhav


[-- Attachment #1.1: Type: text/plain, Size: 1949 bytes --]

Tarun Sahu <tsahu@linux.ibm.com> wrote:



> +
> +static void setup(void)
> +{
> +       if (tst_hugepages < 1)
> +               tst_brk(TCONF, "Not enough hugepages for testing.");
>


If we needs at least 1 huge page for testing, the TST_NEEDS will
be more useful than TST_REQUEST, and do not need to double
check the hpage numbers anymore.


TST_REQUEST:
  It will try the best to reserve available huge pages and return the number
  of available hugepages in tst_hugepages, which may be 0 if hugepages are
  not supported at all.

TST_NEEDS:
  This is an enforced requirement, LTP should strictly do hpages applying
and
  guarantee the 'HugePages_Free' no less than pages which makes that test
can
  use these specified numbers correctly. Otherwise, test exits with TCONF if
  the attempt to reserve hugepages fails or reserves less than requested.

See:
https://github.com/linux-test-project/ltp/blob/master/doc/c-test-api.txt#L2009



> +
> +       if (!Hopt)
> +               Hopt = tst_get_tmpdir();
> +       SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
> +
> +       snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt,
> getpid());
> +       hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
> +}
> +
> +static void cleanup(void)
> +{
> +       if (fd >= 0)
> +               SAFE_CLOSE(fd);
> +       umount2(Hopt, MNT_DETACH);
> +}
> +
> +static struct tst_test test = {
> +       .needs_root = 1,
> +       .needs_tmpdir = 1,
> +       .options = (struct tst_option[]) {
> +               {"v", &verbose, "Turns on verbose mode"},
> +               {"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H
> /var/hugetlbfs"},
> +               {"s:", &nr_opt, "Set the number of the been allocated
> hugepages"},
> +               {}
> +       },
> +       .setup = setup,
> +       .cleanup = cleanup,
> +       .test_all = run_test,
> +       .hugepages = {1, TST_REQUEST},
>

^ TST_NEEDS



> +};
>



-- 
Regards,
Li Wang

[-- Attachment #1.2: Type: text/html, Size: 3743 bytes --]

[-- Attachment #2: Type: text/plain, Size: 60 bytes --]


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 02/29] Hugetlb: Migrating libhugetlbfs chunk-overcommit
  2022-10-16 12:57 ` [LTP] [PATCH 02/29] Hugetlb: Migrating libhugetlbfs chunk-overcommit Tarun Sahu
@ 2022-10-17 11:09   ` Cyril Hrubis
  0 siblings, 0 replies; 53+ messages in thread
From: Cyril Hrubis @ 2022-10-17 11:09 UTC (permalink / raw)
  To: Tarun Sahu; +Cc: aneesh.kumar, sbhat, ltp, vaibhav

Hi!
> Test Description: Some kernel versions after hugepage demand allocation was
> added used a dubious heuristic to check if there was enough hugepage space
> available for a given mapping.  The number of not-already-instantiated
> pages in the mapping was compared against the total hugepage free pool. It
> was very easy to confuse this heuristic into overcommitting by allocating
> hugepage memory in chunks, each less than the total available pool size but
> together more than available.  This would generally lead to OOM SIGKILLs of
> one process or another when it tried to instantiate pages beyond the
> available pool.
> 
> Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
> ---
>  runtest/hugetlb                               |   1 +
>  testcases/kernel/mem/.gitignore               |   1 +
>  .../kernel/mem/hugetlb/hugemmap/hugemmap08.c  | 173 ++++++++++++++++++
>  3 files changed, 175 insertions(+)
>  create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c
> 
> diff --git a/runtest/hugetlb b/runtest/hugetlb
> index f7ff81cb3..664f18827 100644
> --- a/runtest/hugetlb
> +++ b/runtest/hugetlb
> @@ -4,6 +4,7 @@ hugemmap04 hugemmap04
>  hugemmap05 hugemmap05
>  hugemmap06 hugemmap06
>  hugemmap07 hugemmap07
> +hugemmap08 hugemmap08
>  hugemmap05_1 hugemmap05 -m
>  hugemmap05_2 hugemmap05 -s
>  hugemmap05_3 hugemmap05 -s -m
> diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
> index df5256ec8..003ce422b 100644
> --- a/testcases/kernel/mem/.gitignore
> +++ b/testcases/kernel/mem/.gitignore
> @@ -5,6 +5,7 @@
>  /hugetlb/hugemmap/hugemmap05
>  /hugetlb/hugemmap/hugemmap06
>  /hugetlb/hugemmap/hugemmap07
> +/hugetlb/hugemmap/hugemmap08
>  /hugetlb/hugeshmat/hugeshmat01
>  /hugetlb/hugeshmat/hugeshmat02
>  /hugetlb/hugeshmat/hugeshmat03
> diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c
> new file mode 100644
> index 000000000..63a731e09
> --- /dev/null
> +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c
> @@ -0,0 +1,173 @@
> +// SPDX-License-Identifier: LGPL-2.1-or-later
> +/*
> + * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
> + *
> + * Test Name: Chunk Overcommit
> + *
> + * Test Description: Some kernel versions after hugepage demand allocation was
> + * added used a dubious heuristic to check if there was enough hugepage space
> + * available for a given mapping.  The number of not-already-instantiated pages
> + * in the mapping was compared against the total hugepage free pool. It was
> + * very easy to confuse this heuristic into overcommitting by allocating
> + * hugepage memory in chunks, each less than the total available pool size but
> + * together more than available.  This would generally lead to OOM SIGKILLs of
> + * one process or another when it tried to instantiate pages beyond the
> + * available pool.

Here as well.

> + * HISTORY
> + *  Written by David Gibson & Adam Litke
> + *
> + */
> +
> +#define _GNU_SOURCE
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <sys/mount.h>
> +#include <limits.h>
> +#include <sys/param.h>
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +#include <signal.h>
> +
> +#include "hugetlb.h"
> +
> +#define PROC_OVERCOMMIT "/proc/sys/vm/nr_overcommit_hugepages"
> +#define WITH_OVERCOMMIT 0
> +#define WITHOUT_OVERCOMMIT 1
> +
> +static char *verbose;
> +static char hfile[MAXPATHLEN];
> +static int fd = -1;
> +static long hpage_size;
> +
> +static void test_chunk_overcommit(void)
> +{
> +	unsigned long totpages, chunk1, chunk2;
> +	void *p, *q;
> +	pid_t child;
> +	int status;
> +
> +	totpages = SAFE_READ_MEMINFO("HugePages_Free:");
> +
> +	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
> +	SAFE_UNLINK(hfile);
> +
> +	chunk1 = (totpages / 2) + 1;
> +	chunk2 = totpages - chunk1 + 1;
> +
> +	if (verbose)
> +		tst_res(TINFO, "overcommit: %ld hugepages available: "
> +		       "chunk1=%ld chunk2=%ld", totpages, chunk1, chunk2);
> +
> +	p = SAFE_MMAP(NULL, chunk1*hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
> +		 fd, 0);
> +
> +	/* Can't use SAFE_MMAP here, as test needs to process the output of mmap */

No comments like this plase.

> +	q = mmap(NULL, chunk2*hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
> +		 fd, chunk1*hpage_size);
> +	if (q == MAP_FAILED) {
> +		if (errno != ENOMEM) {
> +			tst_res(TFAIL | TERRNO, "mmap() chunk2");
> +			goto fail;

Again just return here. In case of cleanup below it should be:

			goto cleanup1;

> +		} else {
> +			tst_res(TPASS, "Successful without overcommit pages");
> +			goto pass;

If you want to use kernel-like goto cleanup do it at least properly as:

	} else {
		tst_res(TPASS, "Successful without overcommit pages");
		goto cleanup1;
	}

	...

cleanup2:
	SAFE_MUNMAP(q);
cleanup1:
	SAFE_MUNMAP(p);
cleanup0:
	SAFE_CLOSE(fd);
}

> +		}
> +	}
> +
> +	if (verbose)
> +		tst_res(TINFO, "Looks like we've overcommitted, testing...");
> +	/* Looks like we're overcommited, but we need to confirm that
> +	 * this is bad.  We touch it all in a child process because an
> +	 * overcommit will generally lead to a SIGKILL which we can't
> +	 * handle, of course.
> +	 */
> +	child = SAFE_FORK();
> +
> +	if (child == 0) {
> +		memset(p, 0, chunk1*hpage_size);
> +		memset(q, 0, chunk2*hpage_size);
> +		exit(0);
> +	}
> +
> +	SAFE_WAITPID(child, &status, 0);
> +
> +	if (WIFSIGNALED(status)) {
> +		tst_res(TFAIL, "Killed by signal \"%s\" due to overcommit",
                                                   ^
						   Single quotes ('')
						   here plase
> +		     strsignal(WTERMSIG(status)));
                      ^
		      Please use tst_strsig()

> +		goto fail;

Here as well.

> +	}
> +
> +	tst_res(TPASS, "Successful with overcommit pages");
> +
> +pass:
> +	SAFE_MUNMAP(p, chunk1*hpage_size);
> +	if (q && q != MAP_FAILED)
> +		SAFE_MUNMAP(q, chunk2*hpage_size);
> +	SAFE_CLOSE(fd);
> +	return;
> +fail:
> +	tst_brk(TBROK, "Once failed, No point in continuing the test");
> +}
> +
> +static void run_test(unsigned int test_type)
> +{
> +	long saved_oc_hugepages;
> +
> +	SAFE_FILE_LINES_SCANF(PROC_OVERCOMMIT, "%ld", &saved_oc_hugepages);

This is wrong function, the LINES_SCANF function is supposed to be used
for files that have more than one line. For this case SAFE_FILE_SCANF()
should be used instead.

> +	switch (test_type) {
> +	case WITH_OVERCOMMIT:
> +		if (saved_oc_hugepages > 0)
> +			SAFE_FILE_PRINTF(PROC_OVERCOMMIT, "%d", 0);
> +		break;

This case says WITH_OVERCOMMIT but we disable the overcommit by writing 0?

> +	case WITHOUT_OVERCOMMIT:
> +		if (saved_oc_hugepages < 0)
> +			tst_brk(TCONF, "Kernel appears to lack dynamic hugetlb pool "
> +					"support");

I do not think that saved_oc_hugepages can even be < 0, kernel handles
the number as long unsigned.

> +		else if (saved_oc_hugepages == 0)
> +			SAFE_FILE_PRINTF(PROC_OVERCOMMIT, "%d", 2);
> +		break;
> +	default:
> +		tst_brk(TCONF, "Not a proper test type");
> +		break;

This never happens, there is no need to handle this case.

> +	}
> +	test_chunk_overcommit();

And the PROC_OVERCOMMIT should be properly restored after the test.
Ideally by setting up .save_restore field in tst_test structure.

> +}
> +
> +static void setup(void)
> +{
> +	if (tst_hugepages < 3)
> +		tst_brk(TCONF, "Not enough hugepages for testing.");
> +
> +	if (!Hopt)
> +		Hopt = tst_get_tmpdir();
> +	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
> +
> +	snprintf(hfile, sizeof(hfile), "%s/ltp_huetlbfile%d", Hopt, getpid());
> +	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
> +}
> +
> +static void cleanup(void)
> +{
> +	if (fd >= 0)
> +		SAFE_CLOSE(fd);
> +	umount2(Hopt, MNT_DETACH);

Here as well.

> +}
> +
> +static struct tst_test test = {
> +	.needs_root = 1,
> +	.needs_tmpdir = 1,
> +	.forks_child = 1,
> +	.options = (struct tst_option[]) {
> +		{"v", &verbose, "Turns on verbose mode"},
> +		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
> +		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
> +		{}
> +	},
> +	.tcnt = 2,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test = run_test,
> +	.hugepages = {5, TST_REQUEST},
> +};
> +
> -- 
> 2.31.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 03/29] Hugetlb: Migrating libhugetlbfs corrupt-by-cow-opt
  2022-10-16 12:57 ` [LTP] [PATCH 03/29] Hugetlb: Migrating libhugetlbfs corrupt-by-cow-opt Tarun Sahu
@ 2022-10-17 11:46   ` Cyril Hrubis
  0 siblings, 0 replies; 53+ messages in thread
From: Cyril Hrubis @ 2022-10-17 11:46 UTC (permalink / raw)
  To: Tarun Sahu; +Cc: aneesh.kumar, sbhat, ltp, vaibhav

Hi!
> Migrating the libhugetlbfs/testcases/corrupt-by-cow-opt.c test
> 
> Test Description: Test sanity of cow optimization on page cache. If a page
> in page cache has only 1 ref count, it is mapped for a private mapping
> directly and is overwritten freely, so next time we access the page, we
> can see corrupt data.
> 
> Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
> ---
>  runtest/hugetlb                               |   1 +
>  testcases/kernel/mem/.gitignore               |   1 +
>  .../kernel/mem/hugetlb/hugemmap/hugemmap09.c  | 102 ++++++++++++++++++
>  3 files changed, 104 insertions(+)
>  create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c
> 
> diff --git a/runtest/hugetlb b/runtest/hugetlb
> index 664f18827..e2ada7a97 100644
> --- a/runtest/hugetlb
> +++ b/runtest/hugetlb
> @@ -5,6 +5,7 @@ hugemmap05 hugemmap05
>  hugemmap06 hugemmap06
>  hugemmap07 hugemmap07
>  hugemmap08 hugemmap08
> +hugemmap09 hugemmap09
>  hugemmap05_1 hugemmap05 -m
>  hugemmap05_2 hugemmap05 -s
>  hugemmap05_3 hugemmap05 -s -m
> diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
> index 003ce422b..1a242ffe0 100644
> --- a/testcases/kernel/mem/.gitignore
> +++ b/testcases/kernel/mem/.gitignore
> @@ -6,6 +6,7 @@
>  /hugetlb/hugemmap/hugemmap06
>  /hugetlb/hugemmap/hugemmap07
>  /hugetlb/hugemmap/hugemmap08
> +/hugetlb/hugemmap/hugemmap09
>  /hugetlb/hugeshmat/hugeshmat01
>  /hugetlb/hugeshmat/hugeshmat02
>  /hugetlb/hugeshmat/hugeshmat03
> diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c
> new file mode 100644
> index 000000000..eeacf68a2
> --- /dev/null
> +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c
> @@ -0,0 +1,102 @@
> +// SPDX-License-Identifier: LGPL-2.1-or-later
> +/*
> + * Copyright (C) 2013 Joonsoo Kim, LG Electronics.
> + *
> + * Test Name: Corrupt by COW optimization
> + *
> + * Test Description: Test sanity of cow optimization on page cache. If a page
> + * in page cache has only 1 ref count, it is mapped for a private mapping
> + * directly and is overwritten freely, so next time we access the page, we
> + * can see corrupt data.

Here as well.

> + * HISTORY
> + *  Written by Joonsoo Kim
> + *
> + */
> +
> +#define _GNU_SOURCE
> +#include <stdio.h>
> +#include <sys/mount.h>
> +#include <limits.h>
> +#include <sys/param.h>
> +#include <sys/types.h>
> +
> +#include "hugetlb.h"
> +
> +static char *verbose;
> +static int  fd = -1;
> +static char hfile[MAXPATHLEN];
> +static long hpage_size;
> +
> +static void run_test(void)
> +{
> +	char *p;
> +	char c;
> +
> +	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
> +	SAFE_UNLINK(hfile);

This SAFE_OPEN() and SAFE_UNLINK() should be in setup()

> +	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
> +	*p = 's';
> +	if (verbose)
> +		tst_res(TINFO, "Write %c to %p via shared mapping", *p, p);
> +	SAFE_MUNMAP(p, hpage_size);
> +
> +	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
> +	*p = 'p';
> +	if (verbose)
> +		tst_res(TINFO, "Write %c to %p via private mapping", *p, p);
> +	SAFE_MUNMAP(p, hpage_size);
> +
> +	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
> +	c = *p;
> +	if (verbose)
> +		tst_res(TINFO, "Read %c from %p via shared mapping", *p, p);
> +	SAFE_MUNMAP(p, hpage_size);

Also I'm not keen on the verbose flag, I would just print these messages
by default. It does not make sense to have verbose flag because in
practice it's not enabled on production testing and these days we got
reports from various automated systems so we better include anything
useful by default.

> +	/* Direct write from huge page */
> +	if (c != 's') {
> +		tst_res(TFAIL, "Data got corrupted.");
> +		goto fail;
> +	}
> +	tst_res(TPASS, "Successful");

Here the cleanest code would just be:

	if (c != 's')
		tst_res(TFAIL, "Data are corrupted");
	else
		tst_res(TPASS, "Data are correct");

> +	SAFE_CLOSE(fd);

And this SAFE_CLOSE() is already in cleanup() so we just need to move
the SAFE_OPEN() into the setup() and remove this one.

> +	return;
> +fail:
> +	tst_brk(TBROK, "Once failed, No point in continuing the test");
> +}
> +
> +static void setup(void)
> +{
> +	if (tst_hugepages < 2)
> +		tst_brk(TCONF, "Not enough hugepages for testing.");
> +
> +	if (!Hopt)
> +		Hopt = tst_get_tmpdir();
> +	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
> +
> +	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
> +	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
> +}
> +
> +static void cleanup(void)
> +{
> +	if (fd >= 0)
> +		SAFE_CLOSE(fd);
> +	umount2(Hopt, MNT_DETACH);

Here as well, umount only what was mounted.

> +}
> +
> +static struct tst_test test = {
> +	.needs_root = 1,
> +	.needs_tmpdir = 1,
> +	.options = (struct tst_option[]) {
> +		{"v", &verbose, "Turns on verbose mode"},
> +		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
> +		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
> +		{}
> +	},
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test_all = run_test,
> +	.hugepages = {2, TST_REQUEST},
> +};
> -- 
> 2.31.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 04/29] Hugetlb: Migrating libhugetlbfs counters
  2022-10-16 12:57 ` [LTP] [PATCH 04/29] Hugetlb: Migrating libhugetlbfs counters Tarun Sahu
@ 2022-10-17 12:02   ` Cyril Hrubis
  2022-11-03  8:39     ` Tarun Sahu
  2022-10-18  3:38   ` Li Wang
  1 sibling, 1 reply; 53+ messages in thread
From: Cyril Hrubis @ 2022-10-17 12:02 UTC (permalink / raw)
  To: Tarun Sahu; +Cc: aneesh.kumar, sbhat, ltp, vaibhav

Hi!
> Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
> ---
>  runtest/hugetlb                               |   1 +
>  testcases/kernel/mem/.gitignore               |   1 +
>  .../kernel/mem/hugetlb/hugemmap/hugemmap10.c  | 475 ++++++++++++++++++
>  3 files changed, 477 insertions(+)
>  create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c
> 
> diff --git a/runtest/hugetlb b/runtest/hugetlb
> index e2ada7a97..8a56d52a3 100644
> --- a/runtest/hugetlb
> +++ b/runtest/hugetlb
> @@ -6,6 +6,7 @@ hugemmap06 hugemmap06
>  hugemmap07 hugemmap07
>  hugemmap08 hugemmap08
>  hugemmap09 hugemmap09
> +hugemmap10 hugemmap10
>  hugemmap05_1 hugemmap05 -m
>  hugemmap05_2 hugemmap05 -s
>  hugemmap05_3 hugemmap05 -s -m
> diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
> index 1a242ffe0..e7def68cb 100644
> --- a/testcases/kernel/mem/.gitignore
> +++ b/testcases/kernel/mem/.gitignore
> @@ -7,6 +7,7 @@
>  /hugetlb/hugemmap/hugemmap07
>  /hugetlb/hugemmap/hugemmap08
>  /hugetlb/hugemmap/hugemmap09
> +/hugetlb/hugemmap/hugemmap10
>  /hugetlb/hugeshmat/hugeshmat01
>  /hugetlb/hugeshmat/hugeshmat02
>  /hugetlb/hugeshmat/hugeshmat03
> diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c
> new file mode 100644
> index 000000000..107add669
> --- /dev/null
> +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap10.c
> @@ -0,0 +1,475 @@
> +// SPDX-License-Identifier: LGPL-2.1-or-later
> +/*
> + * Copyright (C) 2005-2007 David Gibson & Adam Litke, IBM Corporation.
> + *
> + * Test Name: Counters
> + *
> + * Test Description: This Test perform mmap and unmap and write operation on
> + * hugetlb file based mapping. Mapping can be shared or private. and it checks
> + * for Hugetlb counter (Total, Free, Reserve, Surplus) in /proc/meminfo and
> + * compare them with expected (calculated) value. if all checks are successful,
> + * the test passes.

Here as well.

> + * HISTORY
> + *  Written by David Gibson & Adam Litke
> + *
> + */
> +
> +#define _GNU_SOURCE
> +#include <unistd.h>
> +#include <stdio.h>
> +#include <sys/mount.h>
> +#include <limits.h>
> +#include <sys/param.h>
> +#include <sys/types.h>
> +
> +#include "hugetlb.h"
> +
> +
> +/* Global test configuration */

Please no useless comments like this one.

> +#define PROC_NR_HUGEPAGES "/proc/sys/vm/nr_hugepages"
> +#define PROC_OVERCOMMIT "/proc/sys/vm/nr_overcommit_hugepages"
> +static long saved_nr_hugepages = -1;
> +static long saved_oc_hugepages = -1;

The two proc files should be saved and restored by the .save_restore
array in the tst_test structure.

> +static long hpage_size;
> +static int private_resv;
> +static char *verbose;
> +
> +/* State arrays for our mmaps */
> +#define NR_SLOTS	2
> +#define SL_SETUP	0
> +#define SL_TEST		1
> +static char hfile[NR_SLOTS][MAXPATHLEN];
> +static int map_fd[NR_SLOTS];
> +static char *map_addr[NR_SLOTS];
> +static unsigned long map_size[NR_SLOTS];
> +static unsigned int touched[NR_SLOTS];
> +
> +/* Keep track of expected counter values */
> +static long prev_total;
> +static long prev_free;
> +static long prev_resv;
> +static long prev_surp;
> +
> +#define min(a, b) (((a) < (b)) ? (a) : (b))
> +#define max(a, b) (((a) > (b)) ? (a) : (b))

We already have MIN() and MAX() defined in LTP, use them, do not
reinvent the wheel.

> +static void read_meminfo_huge(long *total, long *free, long *resv, long *surp)
> +{
> +	*total = SAFE_READ_MEMINFO("HugePages_Total:");
> +	*free = SAFE_READ_MEMINFO("HugePages_Free:");
> +	*resv = SAFE_READ_MEMINFO("HugePages_Rsvd:");
> +	*surp = SAFE_READ_MEMINFO("HugePages_Surp:");
> +}
> +
> +static int kernel_has_private_reservations(void)
> +{
> +	int fd;
> +	long t, f, r, s;
> +	long nt, nf, nr, ns;
> +	void *map;
> +
> +	/* Read pool counters */

Here again, useless comment.

> +	read_meminfo_huge(&t, &f, &r, &s);
> +
> +	fd = SAFE_OPEN(hfile[0], O_RDWR | O_CREAT, 0600);
> +	SAFE_UNLINK(hfile[0]);
> +	map = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
> +
> +	/* Recheck the counters */

And here too.

> +	read_meminfo_huge(&nt, &nf, &nr, &ns);
> +
> +	SAFE_MUNMAP(map, hpage_size);
> +	SAFE_CLOSE(fd);
> +
> +	/*
> +	 * There are only three valid cases:
> +	 * 1) If a surplus page was allocated to create a reservation, all
> +	 *    four pool counters increment
> +	 * 2) All counters remain the same except for Hugepages_Rsvd, then
> +	 *    a reservation was created using an existing pool page.
> +	 * 3) All counters remain the same, indicates that no reservation has
> +	 *    been created
> +	 */
> +	if ((nt == t + 1) && (nf == f + 1) && (ns == s + 1) && (nr == r + 1)) {
> +		return 1;
> +	} else if ((nt == t) && (nf == f) && (ns == s)) {
> +		if (nr == r + 1)
> +			return 1;
> +		else if (nr == r)
> +			return 0;
> +	} else {
> +		tst_brk(TCONF, "%s: bad counter state - "
> +		      "T:%li F:%li R:%li S:%li -> T:%li F:%li R:%li S:%li\n",
> +			__func__, t, f, r, s, nt, nf, nr, ns);

There is absolutely no reason to print __func__ all the tst_* reporting
function print filename and linenumber already.

> +	}
> +	return -1;
> +}
> +
> +static void bad_value(int line, const char *name, long expect, long actual)
> +{
> +	tst_res(TFAIL, "Failure Line %i: Bad %s: expected %li, actual %li",
> +			line, name, expect, actual);
> +	tst_brk(TBROK, "Breaking.. as once one of counter is not expected, "
> +			"it will cause other failure anyway");
> +}

Never ever create wrappers around result reporting functions like this.
This break the best feature these function have, i.e. they print file
and line number where the problem has happenend.

> +static void verify_counters(int line, long et, long ef, long er, long es)
> +{
> +	long t, f, r, s;
> +
> +	/* Read pool counters */
> +	read_meminfo_huge(&t, &f, &r, &s);
> +
> +	if (f < r)
> +		tst_res(TWARN, "HugePages_Free < HugePages_Rsvd");

Why exactly do we warn here?

> +	/* Check actual values against expected values */
> +	if (t != et)
> +		bad_value(line, "HugePages_Total", et, t);
> +
> +	if (f != ef)
> +		bad_value(line, "HugePages_Free", ef, f);
> +
> +	if (r != er)
> +		bad_value(line, "HugePages_Rsvd", er, r);
> +
> +	if (s != es)
> +		bad_value(line, "HugePages_Surp", es, s);

We do have rather nice macros exactly for this TST_EXP_EQ_LI() that
would work nicely as long as you name the variables with something more
reasonable than a single character.


> +	/* Everything's good.  Update counters */
> +	prev_total = t;
> +	prev_free = f;
> +	prev_resv = r;
> +	prev_surp = s;
> +}
> +
> +/* Memory operations:
> + * Each of these has a predefined effect on the counters
> + */
> +#define persistent_huge_pages (et - es)

Just NO. Argument-less macros that use local variables like this are
nightmare.

> +static void _set_nr_hugepages(long count, int line)

Identifiers starting with underscore are reserved in C, don't use them.

> +{
> +	long min_size;
> +	long et, ef, er, es;
> +
> +	SAFE_FILE_PRINTF(PROC_NR_HUGEPAGES, "%lu", count);
> +
> +	/* The code below is based on set_max_huge_pages in mm/hugetlb.c */
> +	es = prev_surp;
> +	et = prev_total;
> +	ef = prev_free;
> +	er = prev_resv;
> +
> +	/*
> +	 * Increase the pool size
> +	 * First take pages out of surplus state.  Then make up the
> +	 * remaining difference by allocating fresh huge pages.
> +	 */
> +	while (es && count > persistent_huge_pages)
> +		es--;
> +	while (count > persistent_huge_pages) {
> +		et++;
> +		ef++;
> +	}
> +	if (count >= persistent_huge_pages)
> +		goto out;
> +
> +	/*
> +	 * Decrease the pool size
> +	 * First return free pages to the buddy allocator (being careful
> +	 * to keep enough around to satisfy reservations).  Then place
> +	 * pages into surplus state as needed so the pool will shrink
> +	 * to the desired size as pages become free.
> +	 */
> +	min_size = MAX(count, er + et - ef);
> +	while (min_size < persistent_huge_pages) {
> +		ef--;
> +		et--;
> +	}
> +	while (count < persistent_huge_pages)
> +		es++;
> +
> +out:
> +	verify_counters(line, et, ef, er, es);
> +}
> +#define set_nr_hugepages(c) _set_nr_hugepages(c, __LINE__)
> +
> +static void _map(int s, int hpages, int flags, int line)

Here ase well.

> +{
> +	long et, ef, er, es;
> +
> +	map_fd[s] = SAFE_OPEN(hfile[s], O_RDWR | O_CREAT, 0600);
> +	SAFE_UNLINK(hfile[s]);
> +	map_size[s] = hpages * hpage_size;
> +	map_addr[s] = SAFE_MMAP(NULL, map_size[s], PROT_READ|PROT_WRITE, flags,
> +				map_fd[s], 0);
> +	touched[s] = 0;
> +
> +	et = prev_total;
> +	ef = prev_free;
> +	er = prev_resv;
> +	es = prev_surp;
> +
> +	/*
> +	 * When using MAP_SHARED, a reservation will be created to guarantee
> +	 * pages to the process.  If not enough pages are available to
> +	 * satisfy the reservation, surplus pages are added to the pool.
> +	 * NOTE: This code assumes that the whole mapping needs to be
> +	 * reserved and hence, will not work with partial reservations.
> +	 *
> +	 * If the kernel supports private reservations, then MAP_PRIVATE
> +	 * mappings behave like MAP_SHARED at mmap time.  Otherwise,
> +	 * no counter updates will occur.
> +	 */
> +	if ((flags & MAP_SHARED) || private_resv) {
> +		unsigned long shortfall = 0;
> +
> +		if (hpages + prev_resv > prev_free)
> +			shortfall = hpages - prev_free + prev_resv;
> +		et += shortfall;
> +		ef = prev_free + shortfall;
> +		er = prev_resv + hpages;
> +		es = prev_surp + shortfall;
> +	}
> +
> +	verify_counters(line, et, ef, er, es);
> +}
> +#define map(s, h, f) _map(s, h, f, __LINE__)
> +
> +static void _unmap(int s, int hpages, int flags, int line)

And here.

> +{
> +	long et, ef, er, es;
> +	unsigned long i;
> +
> +	SAFE_MUNMAP(map_addr[s], map_size[s]);
> +	SAFE_CLOSE(map_fd[s]);
> +	map_addr[s] = NULL;
> +	map_size[s] = 0;
> +
> +	et = prev_total;
> +	ef = prev_free;
> +	er = prev_resv;
> +	es = prev_surp;
> +
> +	/*
> +	 * When a VMA is unmapped, the instantiated (touched) pages are
> +	 * freed.  If the pool is in a surplus state, pages are freed to the
> +	 * buddy allocator, otherwise they go back into the hugetlb pool.
> +	 * NOTE: This code assumes touched pages have only one user.
> +	 */
> +	for (i = 0; i < touched[s]; i++) {
> +		if (es) {
> +			et--;
> +			es--;
> +		} else
> +			ef++;
> +	}
> +
> +	/*
> +	 * mmap may have created some surplus pages to accommodate a
> +	 * reservation.  If those pages were not touched, then they will
> +	 * not have been freed by the code above.  Free them here.
> +	 */
> +	if ((flags & MAP_SHARED) || private_resv) {
> +		int unused_surplus = MIN(hpages - touched[s], es);
> +
> +		et -= unused_surplus;
> +		ef -= unused_surplus;
> +		er -= hpages - touched[s];
> +		es -= unused_surplus;
> +	}
> +
> +	verify_counters(line, et, ef, er, es);
> +}
> +#define unmap(s, h, f) _unmap(s, h, f, __LINE__)
> +
> +static void _touch(int s, int hpages, int flags, int line)

And here.

> +{
> +	long et, ef, er, es;
> +	int nr;
> +	char *c;
> +
> +	for (c = map_addr[s], nr = hpages;
> +			hpages && c < map_addr[s] + map_size[s];
> +			c += hpage_size, nr--)
> +		*c = (char) (nr % 2);
> +	/*
> +	 * Keep track of how many pages were touched since we can't easily
> +	 * detect that from user space.
> +	 * NOTE: Calling this function more than once for a mmap may yield
> +	 * results you don't expect.  Be careful :)
> +	 */
> +	touched[s] = MAX(touched[s], hpages);
> +
> +	/*
> +	 * Shared (and private when supported) mappings and consume resv pages
> +	 * that were previously allocated. Also deduct them from the free count.
> +	 *
> +	 * Unreserved private mappings may need to allocate surplus pages to
> +	 * satisfy the fault.  The surplus pages become part of the pool
> +	 * which could elevate total, free, and surplus counts.  resv is
> +	 * unchanged but free must be decreased.
> +	 */
> +	if (flags & MAP_SHARED || private_resv) {
> +		et = prev_total;
> +		ef = prev_free - hpages;
> +		er = prev_resv - hpages;
> +		es = prev_surp;
> +	} else {
> +		if (hpages + prev_resv > prev_free)
> +			et = prev_total + (hpages - prev_free + prev_resv);
> +		else
> +			et = prev_total;
> +		er = prev_resv;
> +		es = prev_surp + et - prev_total;
> +		ef = prev_free - hpages + et - prev_total;
> +	}
> +	verify_counters(line, et, ef, er, es);
> +}
> +#define touch(s, h, f) _touch(s, h, f, __LINE__)
> +
> +static void test_counters(char *desc, int base_nr)
> +{
> +	if (verbose)
> +		tst_res(TINFO, "%s...", desc);
> +	set_nr_hugepages(base_nr);
> +
> +	/* untouched, shared mmap */
> +	map(SL_TEST, 1, MAP_SHARED);
> +	unmap(SL_TEST, 1, MAP_SHARED);
> +
> +	/* untouched, private mmap */
> +	map(SL_TEST, 1, MAP_PRIVATE);
> +	unmap(SL_TEST, 1, MAP_PRIVATE);
> +
> +	/* touched, shared mmap */
> +	map(SL_TEST, 1, MAP_SHARED);
> +	touch(SL_TEST, 1, MAP_SHARED);
> +	unmap(SL_TEST, 1, MAP_SHARED);
> +
> +	/* touched, private mmap */
> +	map(SL_TEST, 1, MAP_PRIVATE);
> +	touch(SL_TEST, 1, MAP_PRIVATE);
> +	unmap(SL_TEST, 1, MAP_PRIVATE);
> +
> +	/* Explicit resizing during outstanding surplus */
> +	/* Consume surplus when growing pool */
> +	map(SL_TEST, 2, MAP_SHARED);
> +	set_nr_hugepages(max(base_nr, 1));
> +
> +	/* Add pages once surplus is consumed */
> +	set_nr_hugepages(max(base_nr, 3));
> +
> +	/* Release free huge pages first */
> +	set_nr_hugepages(max(base_nr, 2));
> +
> +	/* When shrinking beyond committed level, increase surplus */
> +	set_nr_hugepages(base_nr);
> +
> +	/* Upon releasing the reservation, reduce surplus counts */
> +	unmap(SL_TEST, 2, MAP_SHARED);
> +	if (verbose)
> +		tst_res(TINFO, "OK");
> +}
> +
> +static void per_iteration_cleanup(void)
> +{
> +	for (int nr = 0; nr < NR_SLOTS; nr++) {
> +		if (map_fd[nr] >= 0)
> +			SAFE_CLOSE(map_fd[nr]);
> +	}
> +	if (hpage_size <= 0)
> +		return;
> +	if (saved_nr_hugepages >= 0)
> +		SAFE_FILE_PRINTF(PROC_NR_HUGEPAGES, "%ld", saved_nr_hugepages);
> +	if (saved_oc_hugepages >= 0)
> +		SAFE_FILE_PRINTF(PROC_OVERCOMMIT, "%ld", saved_oc_hugepages);
> +}
> +
> +static void run_test(void)
> +{
> +	int base_nr = 0;
> +
> +	saved_nr_hugepages = SAFE_READ_MEMINFO("HugePages_Total:");
> +
> +	/* Verify Dynamic Pool support */
> +	SAFE_FILE_LINES_SCANF(PROC_OVERCOMMIT, "%ld", &saved_oc_hugepages);
> +	if (saved_oc_hugepages < 0)
> +		tst_brk(TCONF, "Kernel appears to lack dynamic hugetlb pool support");

Again, this cannot happen at all.

> +	SAFE_FILE_PRINTF(PROC_OVERCOMMIT, "%d", 3);
> +
> +	private_resv = kernel_has_private_reservations();
> +	/*
> +	 * This test case should require a maximum of 3 huge pages.
> +	 * Run through the battery of tests multiple times, with an increasing
> +	 * base pool size.  This alters the circumstances under which surplus
> +	 * pages need to be allocated and increases the corner cases tested.
> +	 */

Any verbose description like this should rather be part of the
documentaiton comment.

> +	for (base_nr = 0; base_nr <= 3; base_nr++) {
> +		if (verbose)
> +			tst_res(TINFO, "Base pool size: %i", base_nr);

Again not very keen on the verbose flag.

> +		/* Run the tests with a clean slate */
> +		test_counters("Clean", base_nr);
> +
> +		/* Now with a pre-existing untouched, shared mmap */
> +		map(SL_SETUP, 1, MAP_SHARED);
> +		test_counters("Untouched, shared", base_nr);
> +		unmap(SL_SETUP, 1, MAP_SHARED);
> +
> +		/* Now with a pre-existing untouched, private mmap */
> +		map(SL_SETUP, 1, MAP_PRIVATE);
> +		test_counters("Untouched, private", base_nr);
> +		unmap(SL_SETUP, 1, MAP_PRIVATE);
> +
> +		/* Now with a pre-existing touched, shared mmap */
> +		map(SL_SETUP, 1, MAP_SHARED);
> +		touch(SL_SETUP, 1, MAP_SHARED);
> +		test_counters("Touched, shared", base_nr);
> +		unmap(SL_SETUP, 1, MAP_SHARED);
> +
> +		/* Now with a pre-existing touched, private mmap */
> +		map(SL_SETUP, 1, MAP_PRIVATE);
> +		touch(SL_SETUP, 1, MAP_PRIVATE);
> +		test_counters("Touched, private", base_nr);
> +		unmap(SL_SETUP, 1, MAP_PRIVATE);
> +	}
> +	tst_res(TPASS, "Hugepages Counters works as expected.");
> +	per_iteration_cleanup();
> +}
> +
> +static void setup(void)
> +{
> +	if (!Hopt)
> +		Hopt = tst_get_tmpdir();
> +	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
> +	for (int nr = 0; nr < NR_SLOTS; nr++) {
> +		snprintf(hfile[nr], sizeof(hfile[nr]), "%s/ltp_hugetlbfile%d_%d",
> +				Hopt, getpid(), nr);
> +	}
> +
> +	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
> +}
> +
> +static void cleanup(void)
> +{
> +	per_iteration_cleanup();
> +	umount2(Hopt, MNT_DETACH);
> +}
> +
> +static struct tst_test test = {
> +	.needs_root = 1,
> +	.needs_tmpdir = 1,
> +	.options = (struct tst_option[]) {
> +		{"v", &verbose, "Turns on verbose mode"},
> +		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
> +		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
> +		{}
> +	},
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test_all = run_test,
> +	.hugepages = {0, TST_REQUEST},
> +};
> +
> -- 
> 2.31.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 05/29] Hugetlb: Migrating libhugetlbfs directio
  2022-10-16 12:57 ` [LTP] [PATCH 05/29] Hugetlb: Migrating libhugetlbfs directio Tarun Sahu
@ 2022-10-17 12:28   ` Cyril Hrubis
  0 siblings, 0 replies; 53+ messages in thread
From: Cyril Hrubis @ 2022-10-17 12:28 UTC (permalink / raw)
  To: Tarun Sahu; +Cc: aneesh.kumar, sbhat, ltp, vaibhav

Hi!
> Migrating the libhugetlbfs/testcases/direct.c test
> 
> Test Description: This Test perform Direct Write/Read from/To hugetlbfs
> file which is mapped to process address space. The test is checking if it
> succeeds and data written or read is not corrupted.
> 
> Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
> ---
>  runtest/hugetlb                               |   1 +
>  testcases/kernel/mem/.gitignore               |   1 +
>  .../kernel/mem/hugetlb/hugemmap/hugemmap11.c  | 111 ++++++++++++++++++
>  3 files changed, 113 insertions(+)
>  create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c
> 
> diff --git a/runtest/hugetlb b/runtest/hugetlb
> index 8a56d52a3..b9ee7227d 100644
> --- a/runtest/hugetlb
> +++ b/runtest/hugetlb
> @@ -7,6 +7,7 @@ hugemmap07 hugemmap07
>  hugemmap08 hugemmap08
>  hugemmap09 hugemmap09
>  hugemmap10 hugemmap10
> +hugemmap11 hugemmap11
>  hugemmap05_1 hugemmap05 -m
>  hugemmap05_2 hugemmap05 -s
>  hugemmap05_3 hugemmap05 -s -m
> diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
> index e7def68cb..3e64b67be 100644
> --- a/testcases/kernel/mem/.gitignore
> +++ b/testcases/kernel/mem/.gitignore
> @@ -8,6 +8,7 @@
>  /hugetlb/hugemmap/hugemmap08
>  /hugetlb/hugemmap/hugemmap09
>  /hugetlb/hugemmap/hugemmap10
> +/hugetlb/hugemmap/hugemmap11
>  /hugetlb/hugeshmat/hugeshmat01
>  /hugetlb/hugeshmat/hugeshmat02
>  /hugetlb/hugeshmat/hugeshmat03
> diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c
> new file mode 100644
> index 000000000..c4dbe76e6
> --- /dev/null
> +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap11.c
> @@ -0,0 +1,111 @@
> +// SPDX-License-Identifier: LGPL-2.1-or-later
> +/*
> + * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
> + *
> + * Test Name: Direct I/O
> + *
> + * Test Description: This Test perform Direct Write/Read from/To hugetlbfs file
> + * which is mapped to process address space. The test is checking if it
> + * succeeds and data written or read is not corrupted.

Here as well, documentation comment.

> + * HISTORY
> + *  Written by David Gibson & Adam Litke
> + *
> + */
> +
> +#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 P0 "ffffffff"
> +#define IOSZ 4096
> +#define NHFILE "ltp_nfile"
> +
> +static char buf[IOSZ] __attribute__((aligned(IOSZ)));

There is no need for this buffer to be global.

> +static int  fd = -1, nfd = -1;
> +static char hfile[MAXPATHLEN];
> +static long hpage_size;
> +
> +static void run_test(void)
> +{
> +	void *p;
> +
> +	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
> +	SAFE_UNLINK(hfile);
> +
> +	nfd = SAFE_OPEN(NHFILE, O_CREAT|O_EXCL|O_RDWR|O_DIRECT, 0600);
> +	SAFE_UNLINK(NHFILE);
> +
> +	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
> +	memcpy(p, P0, 8);
> +
> +	/* Direct write from huge page */
> +	SAFE_WRITE(1, nfd, p, IOSZ);
> +	SAFE_LSEEK(nfd, 0, SEEK_SET);
> +
> +	/* Check for accuracy */
> +	SAFE_READ(1, nfd, buf, IOSZ);
> +	if (memcmp(P0, buf, 8)) {
> +		tst_res(TFAIL, "Memory mismatch after Direct-IO write");
> +		goto fail;
> +	}
> +	SAFE_LSEEK(nfd, 0, SEEK_SET);
> +
> +	/* Direct read to huge page */
> +	memset(p, 0, IOSZ);
> +	SAFE_READ(1, nfd, p, IOSZ);
> +
> +	/* Check for accuracy */
> +	if (memcmp(p, P0, 8)) {
> +		tst_res(TFAIL, "Memory mismatch after Direct-IO read");
> +		goto fail;
> +	}
> +	tst_res(TPASS, "Successfully tested Hugepage Direct I/O");
> +	SAFE_MUNMAP(p, hpage_size);
> +	SAFE_CLOSE(fd);
> +	SAFE_CLOSE(nfd);
> +	return;
> +fail:
> +	tst_brk(TBROK, "Once failed, No point in continuing the test");

Here as well.

> +}
> +
> +static void setup(void)
> +{
> +	if (tst_hugepages < 1)
> +		tst_brk(TCONF, "Not enough hugepages for testing.");
> +
> +	if (!Hopt)
> +		Hopt = tst_get_tmpdir();
> +	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
> +
> +	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
> +	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
> +}
> +
> +static void cleanup(void)
> +{
> +	if (fd >= 0)
> +		SAFE_CLOSE(fd);
> +	if (nfd >= 0)
> +		SAFE_CLOSE(nfd);
> +	umount2(Hopt, MNT_DETACH);

Here as well.

> +}
> +
> +static struct tst_test test = {
> +	.needs_root = 1,
> +	.needs_tmpdir = 1,
> +	.options = (struct tst_option[]) {
> +		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
> +		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
> +		{}
> +	},
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test_all = run_test,
> +	.hugepages = {1, TST_REQUEST},
> +};
> -- 
> 2.31.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 06/29] Hugetlb: Migrating libhugetlbfs fadvise_reserve
  2022-10-16 12:57 ` [LTP] [PATCH 06/29] Hugetlb: Migrating libhugetlbfs fadvise_reserve Tarun Sahu
@ 2022-10-17 12:35   ` Cyril Hrubis
  0 siblings, 0 replies; 53+ messages in thread
From: Cyril Hrubis @ 2022-10-17 12:35 UTC (permalink / raw)
  To: Tarun Sahu; +Cc: aneesh.kumar, sbhat, ltp, vaibhav

Hi!
> Test Description: fadvise() 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's fixed in kernel by 'commit
> f2deae9d4e70 ("Remove implementation of readpage from the hugetlbfs_aops")'
> 
> Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
> ---
>  runtest/hugetlb                               |   1 +
>  testcases/kernel/mem/.gitignore               |   1 +
>  .../kernel/mem/hugetlb/hugemmap/hugemmap12.c  | 114 ++++++++++++++++++
>  3 files changed, 116 insertions(+)
>  create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c
> 
> diff --git a/runtest/hugetlb b/runtest/hugetlb
> index b9ee7227d..b019c4195 100644
> --- a/runtest/hugetlb
> +++ b/runtest/hugetlb
> @@ -8,6 +8,7 @@ hugemmap08 hugemmap08
>  hugemmap09 hugemmap09
>  hugemmap10 hugemmap10
>  hugemmap11 hugemmap11
> +hugemmap12 hugemmap12
>  hugemmap05_1 hugemmap05 -m
>  hugemmap05_2 hugemmap05 -s
>  hugemmap05_3 hugemmap05 -s -m
> diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
> index 3e64b67be..ec250592d 100644
> --- a/testcases/kernel/mem/.gitignore
> +++ b/testcases/kernel/mem/.gitignore
> @@ -9,6 +9,7 @@
>  /hugetlb/hugemmap/hugemmap09
>  /hugetlb/hugemmap/hugemmap10
>  /hugetlb/hugemmap/hugemmap11
> +/hugetlb/hugemmap/hugemmap12
>  /hugetlb/hugeshmat/hugeshmat01
>  /hugetlb/hugeshmat/hugeshmat02
>  /hugetlb/hugeshmat/hugeshmat03
> diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c
> new file mode 100644
> index 000000000..9773199ca
> --- /dev/null
> +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap12.c
> @@ -0,0 +1,114 @@
> +// SPDX-License-Identifier: LGPL-2.1-or-later
> +/*
> + * Copyright (C) 2005-2006 IBM Corporation.
> + *
> + * Test Name: fadvise_reserve
> + *
> + * Test Description: fadvise() 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's fixed in kernel by commit

Here as well.

> + * f2deae9d4e70793568ef9e85d227abb7bef5b622.

This hash should be added into .tags in the tst_test structure instead.

> + * HISTORY
> + *  Written by Mel Gorman
> + */
> +
> +#define _GNU_SOURCE
> +#include <stdio.h>
> +#include <sys/mount.h>
> +#include <limits.h>
> +#include <sys/param.h>
> +#include <sys/types.h>
> +
> +#include "hugetlb.h"
> +
> +static long hpage_size;
> +static int  fd = -1;
> +static char hfile[MAXPATHLEN];
> +static char *verbose;
> +
> +static void run_test(void)
> +{
> +	void *p;
> +	unsigned long initial_rsvd, map_rsvd, fadvise_rsvd, end_rsvd;
> +
> +	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
> +	SAFE_UNLINK(hfile);
> +
> +	initial_rsvd = SAFE_READ_MEMINFO("HugePages_Rsvd:");
> +	if (verbose)
> +		tst_res(TINFO, "Reserve count before map: %lu", initial_rsvd);

Here as well, not keen on the verbose flag.

> +	/* mmap a region and record reservations */

Here as well, no useless comments.

> +	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
> +		 fd, 0);
> +	map_rsvd = SAFE_READ_MEMINFO("HugePages_Rsvd:");
> +	if (verbose)
> +		tst_res(TINFO, "Reserve count after map: %lu", map_rsvd);
> +
> +	/* fadvise the region and record reservations */
> +	if (posix_fadvise(fd, 0, hpage_size, POSIX_FADV_WILLNEED) == -1) {
> +		tst_res(TFAIL|TERRNO, "fadvise()");
> +		goto fail;
> +	}
> +	fadvise_rsvd = SAFE_READ_MEMINFO("HugePages_Rsvd:");
> +	if (verbose)
> +		tst_res(TINFO, "Reserve count after fadvise: %lu", fadvise_rsvd);
> +
> +	/* Write the region */

Here as well.

> +	memset(p, 1, hpage_size);
> +
> +	/* Free region */

And here as well.

> +	SAFE_MUNMAP(p, hpage_size);
> +	SAFE_CLOSE(fd);
> +	end_rsvd = SAFE_READ_MEMINFO("HugePages_Rsvd:");
> +	if (verbose)
> +		tst_res(TINFO, "Reserve count after close: %lu", end_rsvd);
> +
> +	/* Reserve count should match initial reserve count */

And here.

> +	if (end_rsvd != initial_rsvd) {
> +		tst_res(TFAIL, "Reserve leaked: %lu != %lu", end_rsvd, initial_rsvd);
> +		goto fail;
> +	}
> +	tst_res(TPASS, "Successful");

Just TST_EXP_EQ_LU(end_rsvd, initial_rsvd);

> +	return;
> +fail:
> +	tst_brk(TBROK, "Once failed, No point in continuing the test");

Here as well, no tst_brk() like this.

> +}
> +
> +static void setup(void)
> +{
> +	if (tst_hugepages < 1)
> +		tst_brk(TCONF, "Not enough hugepages for testing.");
> +
> +	if (!Hopt)
> +		Hopt = tst_get_tmpdir();
> +	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
> +
> +	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
> +	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
> +}
> +
> +static void cleanup(void)
> +{
> +	if (fd >= 0)
> +		SAFE_CLOSE(fd);
> +	umount2(Hopt, MNT_DETACH);

Here as well.

> +}
> +
> +static struct tst_test test = {
> +	.needs_root = 1,
> +	.needs_tmpdir = 1,
> +	.options = (struct tst_option[]) {
> +		{"v", &verbose, "Turns on verbose mode"},
> +		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
> +		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
> +		{}
> +	},
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test_all = run_test,
> +	.hugepages = {1, TST_REQUEST},
> +};
> -- 
> 2.31.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 07/29] Hugetlb: Migrating libhugetlbfs fallocate_align
  2022-10-16 12:57 ` [LTP] [PATCH 07/29] Hugetlb: Migrating libhugetlbfs fallocate_align Tarun Sahu
@ 2022-10-17 12:45   ` Cyril Hrubis
  0 siblings, 0 replies; 53+ messages in thread
From: Cyril Hrubis @ 2022-10-17 12:45 UTC (permalink / raw)
  Cc: aneesh.kumar, sbhat, ltp, vaibhav

Hi!
The same comments apply for this test as well.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 08/29] Hugetlb: Migrating libhugetlbfs fallocate_basic
  2022-10-16 12:57 ` [LTP] [PATCH 08/29] Hugetlb: Migrating libhugetlbfs fallocate_basic Tarun Sahu
@ 2022-10-17 12:53   ` Cyril Hrubis
  0 siblings, 0 replies; 53+ messages in thread
From: Cyril Hrubis @ 2022-10-17 12:53 UTC (permalink / raw)
  To: Tarun Sahu; +Cc: aneesh.kumar, sbhat, ltp, vaibhav

Hi!
And the same comments apply to this test as well.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 09/29] Hugetlb: Migrating libhugetlbfs fork-cow
  2022-10-16 12:57 ` [LTP] [PATCH 09/29] Hugetlb: Migrating libhugetlbfs fork-cow Tarun Sahu
@ 2022-10-17 13:45   ` Cyril Hrubis
  2022-10-18  6:56   ` Li Wang
  1 sibling, 0 replies; 53+ messages in thread
From: Cyril Hrubis @ 2022-10-17 13:45 UTC (permalink / raw)
  To: Tarun Sahu; +Cc: aneesh.kumar, sbhat, ltp, vaibhav

Hi!
> 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.
> 
> Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
> ---
>  runtest/hugetlb                               |   2 +
>  testcases/kernel/mem/.gitignore               |   1 +
>  .../kernel/mem/hugetlb/hugefork/Makefile      |  10 +
>  .../kernel/mem/hugetlb/hugefork/hugefork01.c  | 220 ++++++++++++++++++
>  4 files changed, 233 insertions(+)
>  create mode 100644 testcases/kernel/mem/hugetlb/hugefork/Makefile
>  create mode 100644 testcases/kernel/mem/hugetlb/hugefork/hugefork01.c
> 
> diff --git a/runtest/hugetlb b/runtest/hugetlb
> index ec1fc2515..4c16e1e7c 100644
> --- a/runtest/hugetlb
> +++ b/runtest/hugetlb
> @@ -1,6 +1,8 @@
>  hugefallocate01 hugefallocate01
>  hugefallocate02 hugefallocate02
>  
> +hugefork01 hugefork01
> +
>  hugemmap01 hugemmap01
>  hugemmap02 hugemmap02
>  hugemmap04 hugemmap04
> diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
> index c0906f3d3..adea760c7 100644
> --- a/testcases/kernel/mem/.gitignore
> +++ b/testcases/kernel/mem/.gitignore
> @@ -1,6 +1,7 @@
>  /cpuset/cpuset01
>  /hugetlb/hugefallocate/hugefallocate01
>  /hugetlb/hugefallocate/hugefallocate02
> +/hugetlb/hugefork/hugefork01
>  /hugetlb/hugemmap/hugemmap01
>  /hugetlb/hugemmap/hugemmap02
>  /hugetlb/hugemmap/hugemmap04
> diff --git a/testcases/kernel/mem/hugetlb/hugefork/Makefile b/testcases/kernel/mem/hugetlb/hugefork/Makefile
> new file mode 100644
> index 000000000..77ebb0aef
> --- /dev/null
> +++ b/testcases/kernel/mem/hugetlb/hugefork/Makefile
> @@ -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
> +
> diff --git a/testcases/kernel/mem/hugetlb/hugefork/hugefork01.c b/testcases/kernel/mem/hugetlb/hugefork/hugefork01.c
> new file mode 100644
> index 000000000..096ff0c4d
> --- /dev/null
> +++ b/testcases/kernel/mem/hugetlb/hugefork/hugefork01.c
> @@ -0,0 +1,220 @@
> +// SPDX-License-Identifier: LGPL-2.1-or-later
> +/*
> + * Copyright (C) 2008 David Gibson, IBM Corporation.
> + *
> + * Test Name: fork COW
> + *
> + * 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.
> + *
> + * HISTORY
> + *  Written by David Gibson
> + *
> + */
> +
> +#define _GNU_SOURCE
> +
> +
> +#include <sys/shm.h>
> +#include <sys/wait.h>
> +#include <sys/mman.h>
> +#include <errno.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
> +#include <sys/mount.h>
> +#include <limits.h>
> +#include <sys/param.h>
> +#include <sys/types.h>
> +
> +#include "hugetlb.h"
> +
> +#define RANDOM_CONSTANT		0x1234ABCD
> +#define OTHER_CONSTANT		0xfeef5678
> +
> +static int  fd = -1;
> +static char hfile[MAXPATHLEN];
> +static long hpage_size;
> +static char *verbose;
> +
> +/*
> + * The parent uses this to check if the child terminated badly.
> + */
> +static void sigchld_handler(int signum, siginfo_t *si, void *uc)
> +{
> +	(void)signum;
> +	(void)uc;
> +	if (WEXITSTATUS(si->si_status) != 0) {
> +		tst_res(TFAIL, "Child failed: %d", WEXITSTATUS(si->si_status));
> +		goto fail;
> +	}
> +	if (WIFSIGNALED(si->si_status)) {
> +		tst_res(TFAIL, "Child recived signal %s",
> +				strsignal(WTERMSIG(si->si_status)));
> +		goto fail;
> +	}
> +	return;
> +fail:
> +	tst_brk(TBROK, "Once failed, No point in continuing the test");

You cannot call tst_* functions from a signal handler, these are not
async-signal-safe.

The only sensible thing to use the value filled in by the waitpid() call
instead.

> +}
> +
> +static void run_test(void)
> +{
> +	int status;
> +	void *syncarea;
> +	volatile unsigned int *p;
> +	volatile unsigned int *trigger, *child_readback;
> +	int parent_readback;
> +	pid_t pid;
> +	struct sigaction sa = {
> +		.sa_sigaction = sigchld_handler,
> +		.sa_flags = SA_SIGINFO,
> +	};
> +
> +	/* Get a shared normal page for synchronization */
> +	if (verbose)
> +		tst_res(TINFO, "Mapping synchronization area..");
> +	syncarea = SAFE_MMAP(NULL, getpagesize(), PROT_READ|PROT_WRITE,
> +			MAP_SHARED|MAP_ANONYMOUS, -1, 0);
> +	if (verbose)
> +		tst_res(TINFO, "done");
> +
> +	trigger = syncarea;
> +	*trigger = 0;
> +
> +	child_readback = trigger + 1;
> +	*child_readback = 0;
> +
> +	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
> +	SAFE_UNLINK(hfile);
> +
> +	if (verbose)
> +		tst_res(TINFO, "Mapping hugepage area...");
> +	p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
> +	if (verbose)
> +		tst_res(TINFO, "mapped at %p", p);
> +	/* Touch the page for write in parent */
> +	if (verbose)
> +		tst_res(TINFO, "Parent writes pre-fork...");
> +	*p = RANDOM_CONSTANT;
> +	if (verbose)
> +		tst_res(TINFO, "%x", RANDOM_CONSTANT);
> +
> +	SAFE_SIGACTION(SIGCHLD, &sa, NULL);
> +
> +	pid = SAFE_FORK();
> +
> +	if (pid != 0) {
> +		/* Parent */

Useless comment again.

> +		if (verbose)
> +			tst_res(TINFO, "Parent writes post-fork...");
> +		*p = ~RANDOM_CONSTANT;
> +		if (verbose)
> +			tst_res(TINFO, "~RANDOM_CONSTANT: %x", ~RANDOM_CONSTANT);
> +		*trigger = 1;

We do have checkpoint library exactly for synchronization between parent
and child make use of them, see TST_CHECKPOINT_*.

> +		while (*trigger != 2)
> +			;
> +
> +		if (verbose)
> +			tst_res(TINFO, "Parent reads..");

I would be inclined to remove these "Parent does xyz" and "Child does abc"
messages from test once we make use of the CHECKPOINTs the
synchronization is guaranteed to be right.

> +		parent_readback = *p;
> +		if (verbose)
> +			tst_res(TINFO, "Parent readback: %x", parent_readback);
> +		*trigger = 3;
> +	} else {
> +		/* Child */

Here as well.

> +		if (verbose)
> +			tst_res(TINFO, "Child starts..");
> +		while (*trigger != 1)
> +			;
> +
> +		if (verbose)
> +			tst_res(TINFO, "Child reads...");
> +		*child_readback = *p;
> +		if (verbose) {
> +			tst_res(TINFO, "child readback: %x", *child_readback);
> +			tst_res(TINFO, "Child writes...");
> +		}
> +		*p = OTHER_CONSTANT;
> +		if (verbose)
> +			tst_res(TINFO, "OTHER_CONSTANT: %x", OTHER_CONSTANT);
> +
> +		*trigger = 2;
> +
> +		while (*trigger != 3)
> +			;
> +		if (verbose)
> +			tst_res(TINFO, "Child exits...");
> +		exit(0);
> +	}
> +
> +	if (verbose)
> +		tst_res(TINFO, "child_readback = 0x%x, parent_readback = 0x%x\n",
> +		       *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);
> +		goto fail;
> +	}
> +	if (parent_readback != ~RANDOM_CONSTANT) {
> +		tst_res(TFAIL, "Parent read back 0x%x instead of 0x%x",
> +		     parent_readback, RANDOM_CONSTANT);
> +		goto fail;
> +	}
> +
> +	SAFE_WAITPID(pid, &status, 0);
> +
> +	tst_res(TPASS, "Successful");
> +	SAFE_MUNMAP((void *)p, hpage_size);
> +	SAFE_MUNMAP(syncarea, getpagesize());
> +	SAFE_CLOSE(fd);
> +	return;
> +fail:
> +	tst_brk(TBROK, "Once failed, No point in continuing the test");

Here as well.

> +}
> +
> +static void setup(void)
> +{
> +	int free_pages = SAFE_READ_MEMINFO("HugePages_Free:");
> +
> +	if (tst_hugepages < 2 || free_pages < 2)
> +		tst_brk(TCONF, "Not enough hugepages for testing.");
> +
> +	if (!Hopt)
> +		Hopt = tst_get_tmpdir();
> +	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
> +
> +	snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt, getpid());
> +	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
> +}
> +
> +static void cleanup(void)
> +{
> +	if (fd >= 0)
> +		SAFE_CLOSE(fd);
> +	umount2(Hopt, MNT_DETACH);

Here as well.

> +}
> +
> +static struct tst_test test = {
> +	.needs_root = 1,
> +	.needs_tmpdir = 1,
> +	.options = (struct tst_option[]) {
> +		{"v", &verbose, "Turns on verbose mode"},
> +		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
> +		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
> +		{}
> +	},
> +	.forks_child = 1,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test_all = run_test,
> +	.hugepages = {2, TST_REQUEST},
> +};
> -- 
> 2.31.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 10/29] Hugetlb: Migrating libhugetlbfs huge_at_4GB_normal_below
  2022-10-16 12:57 ` [LTP] [PATCH 10/29] Hugetlb: Migrating libhugetlbfs huge_at_4GB_normal_below Tarun Sahu
@ 2022-10-17 14:46   ` Cyril Hrubis
  0 siblings, 0 replies; 53+ messages in thread
From: Cyril Hrubis @ 2022-10-17 14:46 UTC (permalink / raw)
  To: Tarun Sahu; +Cc: aneesh.kumar, sbhat, ltp, vaibhav


> 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
> 
> Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
> ---
>  runtest/hugetlb                               |   1 +
>  testcases/kernel/mem/.gitignore               |   1 +
>  .../kernel/mem/hugetlb/hugemmap/hugemmap13.c  | 160 ++++++++++++++++++
>  3 files changed, 162 insertions(+)
>  create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c
> 
> diff --git a/runtest/hugetlb b/runtest/hugetlb
> index 4c16e1e7c..2029ee4b3 100644
> --- a/runtest/hugetlb
> +++ b/runtest/hugetlb
> @@ -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
> diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
> index adea760c7..5955ed613 100644
> --- a/testcases/kernel/mem/.gitignore
> +++ b/testcases/kernel/mem/.gitignore
> @@ -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
> diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c
> new file mode 100644
> index 000000000..0eae937ab
> --- /dev/null
> +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c
> @@ -0,0 +1,160 @@
> +// SPDX-License-Identifier: LGPL-2.1-or-later
> +/*
> + * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
> + *
> + * Test Name: Huge at 4GB normal below
> + *
> + * Test Description: Designed to pick up a bug on ppc64 where
> + * touches_hugepage_high_range() falsely reported true for ranges reaching
> + * below 4GB
> + *
> + * 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.
> + *
> + * HISTORY
> + *  Written by David Gibson & Adam Litke
> + *
> + */
> +
> +#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 FOURGB (1UL << 32)
> +
> +static int  fd = -1;
> +static char hfile[MAXPATHLEN];
> +static unsigned long hpage_size;
> +static char *verbose;
> +
> +static void run_test(void)
> +{
> +	int page_size;
> +	int fd;
> +	void *p, *q;
> +	unsigned long lowaddr;
> +	int err;
> +
> +	page_size = getpagesize();
> +
> +	fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
> +	SAFE_UNLINK(hfile);
> +
> +	p = mmap((void *)FOURGB, hpage_size, PROT_READ|PROT_WRITE,
> +		 MAP_SHARED | MAP_FIXED, fd, 0);
> +	if (p == MAP_FAILED) {
> +		/* slice 0 (high) spans from 4G-1T */
> +		unsigned long below_start = FOURGB;
> +		unsigned long above_end = 1024L*1024*1024*1024;
> +
> +		if (range_is_mapped(below_start, above_end) == 1) {
> +			if (verbose) {
> +				tst_res(TINFO, "region 4G-IT is not free");
> +				tst_res(TINFO|TERRNO, "mmap() failed");

This should be single TINFO message.

> +			}
> +			tst_res(TPASS, "Successful but inconclusive");
> +			SAFE_CLOSE(fd);
> +			return;
> +		}
> +		tst_res(TFAIL|TERRNO, "mmap() huge");
> +		goto fail;
> +	}
> +	if (p != (void *)FOURGB) {
> +		tst_res(TFAIL, "Wrong address with MAP_FIXED huge");
> +		goto fail;
> +	}
> +
> +	if (verbose)
> +		tst_res(TINFO, "Mapped hugetlb at %p", p);
> +
> +	memset(p, 0, hpage_size);
> +
> +	err = test_addr_huge(p);
> +	if (err != 1) {
> +		tst_res(TFAIL, "Mapped address is not hugepage");
> +		goto fail;
> +	}

Again I fail to see how this is useful. This check looks to me like a
circular definition at best. We create file on hugetlbfs, stat() it and
check that the magic matches.

> +	/* Test just below 4GB to check for off-by-one errors */
> +	lowaddr = FOURGB - page_size;
> +	q = mmap((void *)lowaddr, page_size, PROT_READ|PROT_WRITE,
> +		 MAP_SHARED|MAP_FIXED|MAP_ANONYMOUS, 0, 0);
> +	if (p == MAP_FAILED) {
> +		unsigned long below_start = FOURGB - page_size;
> +		unsigned long above_end = FOURGB;
> +
> +		if (range_is_mapped(below_start, above_end) == 1) {
> +			if (verbose) {
> +				tst_res(TINFO, "region (4G-page)-4G is not free\n");
> +				tst_res(TINFO|TERRNO, "mmap() failed");

Here as well, single message.

> +			}
> +			tst_res(TPASS, "Successful but inconclusive");
> +			SAFE_MUNMAP(p, hpage_size);
> +			SAFE_CLOSE(fd);
> +			return;
> +		}
> +		tst_res(TFAIL|TERRNO, "mmap() normal");
> +		goto fail;
> +	}
> +	if (q != (void *)lowaddr) {
> +		tst_res(TFAIL, "Wrong address with MAP_FIXED normal");
> +		goto fail;
> +	}
> +
> +	memset(q, 0, page_size);
> +
> +	tst_res(TPASS, "Successful");
> +	SAFE_MUNMAP(p, hpage_size);
> +	SAFE_MUNMAP(q, page_size);
> +	SAFE_CLOSE(fd);
> +	return;
> +fail:
> +	tst_brk(TBROK, "Once failed, No point in continuing the test");
> +}

And the usuall comments apply as well.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 11/29] Hugetlb: Migrating libhugetlbfs huge_below_4GB_normal_above
  2022-10-16 12:57 ` [LTP] [PATCH 11/29] Hugetlb: Migrating libhugetlbfs huge_below_4GB_normal_above Tarun Sahu
@ 2022-10-17 14:48   ` Cyril Hrubis
  0 siblings, 0 replies; 53+ messages in thread
From: Cyril Hrubis @ 2022-10-17 14:48 UTC (permalink / raw)
  To: Tarun Sahu; +Cc: aneesh.kumar, sbhat, ltp, vaibhav

Hi!
Same comments as for the previous one apply here as well.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 12/29] Hugetlb: Migrating libhugetlbfs icache-hygiene
  2022-10-16 12:57 ` [LTP] [PATCH 12/29] Hugetlb: Migrating libhugetlbfs icache-hygiene Tarun Sahu
@ 2022-10-17 19:37   ` Cyril Hrubis
  0 siblings, 0 replies; 53+ messages in thread
From: Cyril Hrubis @ 2022-10-17 19:37 UTC (permalink / raw)
  To: Tarun Sahu; +Cc: aneesh.kumar, sbhat, ltp, vaibhav

Hi!
> 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.
> 
> Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
> ---
>  runtest/hugetlb                               |   1 +
>  testcases/kernel/mem/.gitignore               |   1 +
>  .../kernel/mem/hugetlb/hugemmap/hugemmap15.c  | 250 ++++++++++++++++++
>  3 files changed, 252 insertions(+)
>  create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c
> 
> diff --git a/runtest/hugetlb b/runtest/hugetlb
> index 796ebe7fa..0714ed34c 100644
> --- a/runtest/hugetlb
> +++ b/runtest/hugetlb
> @@ -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
> diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
> index 3106579ce..d59b60fd4 100644
> --- a/testcases/kernel/mem/.gitignore
> +++ b/testcases/kernel/mem/.gitignore
> @@ -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
> diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c
> new file mode 100644
> index 000000000..cf1cd96ea
> --- /dev/null
> +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap15.c
> @@ -0,0 +1,250 @@
> +// SPDX-License-Identifier: LGPL-2.1-or-later
> +/*
> + * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
> + *
> + * Test Name: icache hygiene
> + *
> + * 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.
> + *
> + * HISTORY
> + *  Written by David Gibson & Adam Litke
> + *
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <setjmp.h>
> +#include <unistd.h>
> +#include <signal.h>
> +#include <sys/mman.h>
> +#include <ucontext.h>
> +#include <sys/mount.h>
> +#include <limits.h>
> +#include <sys/param.h>
> +#include <sys/types.h>
> +
> +#include "hugetlb.h"
> +
> +static int  fd = -1;
> +static char hfile[MAXPATHLEN];
> +
> +#define COPY_SIZE	128
> +#define NUM_REPETITIONS	64	/* Seems to be enough to trigger reliably */
> +
> +static char *verbose;
> +static long hpage_size;
> +
> +static void cacheflush(void *p)
> +{
> +	(void)p;
> +#if defined(__powerpc__)
> +	asm volatile("dcbst 0,%0; sync; icbi 0,%0; isync" : : "r"(p));
> +#elif defined(__arm__) || defined(__aarch64__)
> +	__clear_cache(p, p + COPY_SIZE);
> +#endif
> +}
> +
> +static void jumpfunc(int copy, void *p)
> +{
> +	/* gcc bug workaround: if there is exactly one &&label
> +	 * construct in the function, gcc assumes the computed goto
> +	 * goes there, leading to the complete elision of the goto in
> +	 * this case
> +	 */
> +	void *l = &&dummy;
> +
> +	l = &&jumplabel;
> +
> +	if (copy) {
> +		memcpy(p, l, COPY_SIZE);
> +		cacheflush(p);
> +	}
> +
> +	goto *p;
> + dummy:
> +	tst_res(TWARN, "unreachable?");
> +
> + jumplabel:
> +	return;
> +}
> +
> +static sigjmp_buf sig_escape;
> +static void *sig_expected;
> +
> +static void sig_handler(int signum, siginfo_t *si, void *uc)
> +{
> +#if defined(__powerpc__) || defined(__powerpc64__) || defined(__ia64__) || \
> +	defined(__s390__) || defined(__s390x__) || defined(__sparc__) || \
> +	defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64)
> +	/* On powerpc, ia64, s390 and Aarch64, 0 bytes are an illegal
> +	 * instruction, so, if the icache is cleared properly, we SIGILL
> +	 * as soon as we jump into the cleared page
> +	 */
> +	if (signum == SIGILL) {
> +		if (verbose)
> +			tst_res(TINFO, "SIGILL at %p (sig_expected=%p)", si->si_addr,
> +				       sig_expected);
> +		if (si->si_addr == sig_expected)
> +			siglongjmp(sig_escape, 1);
> +		tst_res(TFAIL, "SIGILL somewhere unexpected");
> +		goto fail;
> +	}
> +#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__)
> +	/* On x86, zero bytes form a valid instruction:
> +	 *	add %al,(%eax)		(i386)
> +	 * or	add %al,(%rax)		(x86_64)
> +	 *
> +	 * So, behaviour depends on the contents of [ER]AX, which in
> +	 * turn depends on the details of code generation.  If [ER]AX
> +	 * contains a valid pointer, we will execute the instruction
> +	 * repeatedly until we run off that hugepage and get a SIGBUS
> +	 * on the second, truncated page.  If [ER]AX does not contain
> +	 * a valid pointer, we will SEGV on the first instruction in
> +	 * the cleared page.  We check for both possibilities
> +	 * below.
> +	 *
> +	 * On 32 bit ARM, zero bytes are interpreted as follows:
> +	 *  andeq	r0, r0, r0	(ARM state, 4 bytes)
> +	 *  movs	r0, r0		(Thumb state, 2 bytes)
> +	 *
> +	 * So, we only expect to run off the end of the huge page and
> +	 * generate a SIGBUS.
> +	 */
> +	if (signum == SIGBUS) {
> +		if (verbose)
> +			tst_res(TINFO, "SIGBUS at %p (sig_expected=%p)", si->si_addr,
> +				       sig_expected);
> +		if (sig_expected
> +		    && (ALIGN((unsigned long)sig_expected, hpage_size)
> +			== (unsigned long)si->si_addr)) {
> +			siglongjmp(sig_escape, 2);
> +		}
> +		tst_res(TFAIL, "SIGBUS somewhere unexpected");
> +		goto fail;
> +	}
> +#if defined(__x86_64__) || defined(__i386__)
> +	if (signum == SIGSEGV) {
> +#ifdef __x86_64__
> +		void *pc = (void *)((ucontext_t *)uc)->uc_mcontext.gregs[REG_RIP];
> +#else
> +		void *pc = (void *)((ucontext_t *)uc)->uc_mcontext.gregs[REG_EIP];
> +#endif
> +		if (verbose)
> +			tst_res(TINFO, "SIGSEGV at %p, PC=%p (sig_expected=%p)\n",
> +				       si->si_addr, pc, sig_expected);
> +		if (sig_expected == pc)
> +			siglongjmp(sig_escape, 1);
> +		tst_res(TFAIL, "SIGSEGV somewhere unexpected");
> +		goto fail;
> +	}
> +#endif
> +#else
> +#error "Need to setup signal conditions for this arch"
> +#endif
> +	return;
> +fail:
> +	tst_brk(TBROK, "Once Failed, No Need to continue the next iteration.");
> +}

Again no tst_res() or tst_brk() is allowed inside a signal handler, the
best we can is to propagate different values for pass/fail in the return
value from siglongjmp().


And the usuall comments apply to this test as well.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 04/29] Hugetlb: Migrating libhugetlbfs counters
  2022-10-16 12:57 ` [LTP] [PATCH 04/29] Hugetlb: Migrating libhugetlbfs counters Tarun Sahu
  2022-10-17 12:02   ` Cyril Hrubis
@ 2022-10-18  3:38   ` Li Wang
  1 sibling, 0 replies; 53+ messages in thread
From: Li Wang @ 2022-10-18  3:38 UTC (permalink / raw)
  To: Tarun Sahu; +Cc: aneesh.kumar, sbhat, ltp, vaibhav


[-- Attachment #1.1: Type: text/plain, Size: 612 bytes --]

Tarun Sahu <tsahu@linux.ibm.com> wrote:



> +
> +static void per_iteration_cleanup(void)
> +{
> +       for (int nr = 0; nr < NR_SLOTS; nr++) {
>

Here the for-loop usage is introduced from C99, we have to avoid
definition in the loop to dismiss compiling broken on old compilers.

See:
https://github.com/wangli5665/ltp/actions/runs/3261830153/jobs/5357590260


+
> +static void setup(void)
> +{
> +       if (!Hopt)
> +               Hopt = tst_get_tmpdir();
> +       SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
> +       for (int nr = 0; nr < NR_SLOTS; nr++) {
>


Here as well ^


-- 
Regards,
Li Wang

[-- Attachment #1.2: Type: text/html, Size: 1757 bytes --]

[-- Attachment #2: Type: text/plain, Size: 60 bytes --]


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 09/29] Hugetlb: Migrating libhugetlbfs fork-cow
  2022-10-16 12:57 ` [LTP] [PATCH 09/29] Hugetlb: Migrating libhugetlbfs fork-cow Tarun Sahu
  2022-10-17 13:45   ` Cyril Hrubis
@ 2022-10-18  6:56   ` Li Wang
  1 sibling, 0 replies; 53+ messages in thread
From: Li Wang @ 2022-10-18  6:56 UTC (permalink / raw)
  To: Tarun Sahu; +Cc: aneesh.kumar, sbhat, ltp, vaibhav


[-- Attachment #1.1: Type: text/plain, Size: 2178 bytes --]

Tarun Sahu <tsahu@linux.ibm.com> wrote:



> +static void run_test(void)
> +{
> +       int status;
> +       void *syncarea;
> +       volatile unsigned int *p;
> +       volatile unsigned int *trigger, *child_readback;
> +       int parent_readback;
> +       pid_t pid;
> +       struct sigaction sa = {
> +               .sa_sigaction = sigchld_handler,
> +               .sa_flags = SA_SIGINFO,
> +       };
> +
> +       /* Get a shared normal page for synchronization */
> +       if (verbose)
> +               tst_res(TINFO, "Mapping synchronization area..");
> +       syncarea = SAFE_MMAP(NULL, getpagesize(), PROT_READ|PROT_WRITE,
> +                       MAP_SHARED|MAP_ANONYMOUS, -1, 0);
> +       if (verbose)
> +               tst_res(TINFO, "done");
> +
> +       trigger = syncarea;
> +       *trigger = 0;
> +
> +       child_readback = trigger + 1;
> +       *child_readback = 0;
> +
> +       fd = SAFE_OPEN(hfile, O_RDWR | O_CREAT, 0600);
> +       SAFE_UNLINK(hfile);
> +
> +       if (verbose)
> +               tst_res(TINFO, "Mapping hugepage area...");
> +       p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_PRIVATE,
> fd, 0);
>


After roughly looking at those hpage testcases, almost each one
requests the huge memory via mapping a file on hugetlbfs, which
can work but quite don't have to.

We can absolutely simplify them via `MAP_HUGETLB` to get expected
size of huge memory for use.

Reference how hugemamp06.c does:
https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/mem/hugetlb/hugemmap/hugemmap06.c#L71


+static void setup(void)
> +{
> +       int free_pages = SAFE_READ_MEMINFO("HugePages_Free:");
> +
> +       if (tst_hugepages < 2 || free_pages < 2)
> +               tst_brk(TCONF, "Not enough hugepages for testing.");
>



> +
> +       if (!Hopt)
> +               Hopt = tst_get_tmpdir();
> +       SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
> +
> +       snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d", Hopt,
> getpid());
>

If we go using MAP_HUGETLB above, those lines can be removed.



> +       hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
> +}
>



-- 
Regards,
Li Wang

[-- Attachment #1.2: Type: text/html, Size: 4277 bytes --]

[-- Attachment #2: Type: text/plain, Size: 60 bytes --]


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge
  2022-10-17  9:30   ` Cyril Hrubis
@ 2022-10-18  7:33     ` Tarun Sahu
  2022-10-21  8:58       ` Cyril Hrubis
  0 siblings, 1 reply; 53+ messages in thread
From: Tarun Sahu @ 2022-10-18  7:33 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: aneesh.kumar, sbhat, ltp, vaibhav

Hi, 

Thanks Cyril for reviewing it.
Please check my comments below.

On
Mon, 2022-10-17 at 11:30 +0200, Cyril Hrubis wrote:

-- skip
> + *
> > + * Test Name: brk near hugepage
> > + *
> > + * Test Description: Certain kernels have a bug where brk() does
> > not perform
> > + * the same checks that a MAP_FIXED mmap() will, allowing brk() to
> > create a
> > + * normal page VMA in a hugepage only address region. This can
> > lead to oopses
> > + * or other badness.
> 
> This description has to be in a separate ascii-doc formatted comment
> that starts with /*\

Ok. I will update this in all of the patches in this series.

-- skip
> > +	p = SAFE_MMAP(hugemap_addr, hpage_size, PROT_READ|PROT_WRITE,
> > +			MAP_PRIVATE|MAP_FIXED, fd, 0);
> > +	if (p != hugemap_addr) {
> > +		tst_res(TFAIL, "mmap() at unexpected address %p instead
> > of %p\n", p,
> > +		     hugemap_addr);
> > +		goto fail;
> 
> Can we just do return here instead. The failure has been reported
> there
> is no point in calling tst_brk(TBROK, ...) as well.
When we run one iteration only, tst_brk does not make sense, I agree.
But if we are running more than one iteration (i >= 2), test
should not continue to next iteration if the current iteration fails.
Only way I could find is to use tst_brk(TBROK,... , as tst_brk(TFAIl...
is deprecated.

> 
> > +	}
> > +
> > +	err = test_addr_huge((void *)p);
> > +	if (err != 1) {
> > +		tst_res(TFAIL, "Mapped address is not hugepage");
> > +		goto fail;
> > +	}
> 
> I do not get why we even need this check. We map a file located on
> hugetlbfs and then we stat it and check that it indeed is on
> hutetlbfs.
> What did we expect to fail here? I would say that the mmap() with
> right
> path is enough to make sure that the file is created on hugetlbfs.
> 
I agree, this check is redundant, I will remove it.

> > +	newbrk = next_chunk(brk0) + getpagesize();
> > +	err = brk((void *)newbrk);
> > +	if (err == -1) {
> > +		/* Failing the brk() is an acceptable kernel response
> > */
> > +		tst_res(TPASS, "Failing the brk is an acceptable
> > response");
> > +	} else {
> > +		/* Suceeding the brk() is acceptable iff the new memory
> > is
> > +		 * properly accesible and we don't have a kernel blow
> > up when
> > +		 * we touch it.
> > +		 */
> > +		memset(brk0, 0, newbrk-brk0);
> > +		tst_res(TPASS, "Succeding brk is acceptable, as memset
> > confirms that "
> > +				"new memory is properly accessible
> > without kernel blow up");
> > +	}
> > +	SAFE_MUNMAP(p, hpage_size);
> > +	SAFE_CLOSE(fd);
> 
> Shouldn't we brk() back to the original brk0? Does the test work with
> -i 2?
> 
Yes, will update it back to brk0.
Yes -i 2.. working, may be becuase, we
are just moving it by 1 page.

--skip
> > +
> > +static void cleanup(void)
> > +{
> > +	if (fd >= 0)
> > +		SAFE_CLOSE(fd);
> > +	umount2(Hopt, MNT_DETACH);
> 
> We whould umount here only if we actually have mounted something.
umount only, will require explicit unmap when test fails or break.
For
that, all the local variable for address mapping will have to be
static defined so that they can be accessed in cleanup() function.

I tried to avoid it by using umount2 which eventually umount when
process unmaps all the mappings after it finishes.



-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge
  2022-10-17 10:20   ` Li Wang
@ 2022-10-18  7:36     ` Tarun Sahu
  0 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-18  7:36 UTC (permalink / raw)
  To: Li Wang; +Cc: aneesh.kumar, sbhat, ltp, vaibhav

Hi Li, 
Thanks for reviewing the patch.

I will update it to TST_NEEDS
wherever required in other tests
too. Thanks for pointing it.

On Mon,
2022-10-17 at 18:20 +0800, Li Wang wrote:
> This Message Is From an External Sender
> This message came from outside your organization.       
> Tarun Sahu <tsahu@linux.ibm.com> wrote:
> 
>  
> > +
> > +static void setup(void)
> > +{
> > +       if (tst_hugepages < 1)
> > +               tst_brk(TCONF, "Not enough hugepages for
> > testing.");
> 
> 
> If we needs at least 1 huge page for testing, the TST_NEEDS will
> be more useful than TST_REQUEST, and do not need to double
> check the hpage numbers anymore.
> 
> 
> TST_REQUEST:
>   It will try the best to reserve available huge pages and return the
> number
>   of available hugepages in tst_hugepages, which may be 0 if
> hugepages are
>   not supported at all.
> 
> TST_NEEDS:
>   This is an enforced requirement, LTP should strictly do hpages
> applying and
>   guarantee the 'HugePages_Free' no less than pages which makes that
> test can
>   use these specified numbers correctly. Otherwise, test exits with
> TCONF if
>   the attempt to reserve hugepages fails or reserves less than
> requested.
> 
> See: 
> https://github.com/linux-test-project/ltp/blob/master/doc/c-test-api.txt#L2009
> 
>  
> > +
> > +       if (!Hopt)
> > +               Hopt = tst_get_tmpdir();
> > +       SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
> > +
> > +       snprintf(hfile, sizeof(hfile), "%s/ltp_hugetlbfile%d",
> > Hopt, getpid());
> > +       hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
> > +}
> > +
> > +static void cleanup(void)
> > +{
> > +       if (fd >= 0)
> > +               SAFE_CLOSE(fd);
> > +       umount2(Hopt, MNT_DETACH);
> > +}
> > +
> > +static struct tst_test test = {
> > +       .needs_root = 1,
> > +       .needs_tmpdir = 1,
> > +       .options = (struct tst_option[]) {
> > +               {"v", &verbose, "Turns on verbose mode"},
> > +               {"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H
> > /var/hugetlbfs"},
> > +               {"s:", &nr_opt, "Set the number of the been
> > allocated hugepages"},
> > +               {}
> > +       },
> > +       .setup = setup,
> > +       .cleanup = cleanup,
> > +       .test_all = run_test,
> > +       .hugepages = {1, TST_REQUEST},
> 
> ^ TST_NEEDS
> 
>  
> > +};
> 
>  
> 


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests
  2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
                   ` (28 preceding siblings ...)
  2022-10-16 12:57 ` [LTP] [PATCH 29/29] Hugetlb: Migrating libhugetlbfs shm-fork Tarun Sahu
@ 2022-10-18 13:51 ` Richard Palethorpe
  2022-10-19  5:11   ` Tarun Sahu
  29 siblings, 1 reply; 53+ messages in thread
From: Richard Palethorpe @ 2022-10-18 13:51 UTC (permalink / raw)
  To: Tarun Sahu; +Cc: aneesh.kumar, ltp, sbhat, vaibhav

Hello,

Tarun Sahu <tsahu@linux.ibm.com> writes:

> Hi,
> 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.
>
> As per previous dicussion in RFC[1], Here, this patch series consists
> of hugetlb tests taken from libhugetlbfs modified to work in ltp
> environment. This series do not include all the tests, I
> will post another series for the remaining tests soon.

Perhaps Cyril already said this, but I suggest just getting one or two
of the tests merged first then working through the rest.

This reduces the iteration time and batch size.

At least in terms of what you submit to the mailing list. Perhaps if it
gets to the point where most tests pass review first time, you can
submit everything remaining.

Also note that submitting this many new tests, once they are merged we
will probably get failure reports (including compilation failures). It
will make life easier to stagger that.

I'm going to mark this patch-set as changes requested in patchwork.

-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests
  2022-10-18 13:51 ` [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Richard Palethorpe
@ 2022-10-19  5:11   ` Tarun Sahu
  0 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-10-19  5:11 UTC (permalink / raw)
  To: rpalethorpe; +Cc: aneesh.kumar, ltp, sbhat, vaibhav


Hi Richard, 

Understood, I will repost the patch, with first 2/3 in the series.

Thanks,

On Tue, 2022-10-18 at 14:51 +0100, Richard Palethorpe wrote:
> Hello,
> 
> Tarun Sahu <tsahu@linux.ibm.com> writes:
> 
> > Hi,
> > 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.
> > 
> > As per previous dicussion in RFC[1], Here, this patch series
> > consists
> > of hugetlb tests taken from libhugetlbfs modified to work in ltp
> > environment. This series do not include all the tests, I
> > will post another series for the remaining tests soon.
> 
> Perhaps Cyril already said this, but I suggest just getting one or
> two
> of the tests merged first then working through the rest.
> 
> This reduces the iteration time and batch size.
> 
> At least in terms of what you submit to the mailing list. Perhaps if
> it
> gets to the point where most tests pass review first time, you can
> submit everything remaining.
> 
> Also note that submitting this many new tests, once they are merged
> we
> will probably get failure reports (including compilation failures).
> It
> will make life easier to stagger that.
> 
> I'm going to mark this patch-set as changes requested in patchwork.
> 


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge
  2022-10-18  7:33     ` Tarun Sahu
@ 2022-10-21  8:58       ` Cyril Hrubis
  2022-10-25  5:56         ` Tarun Sahu
  0 siblings, 1 reply; 53+ messages in thread
From: Cyril Hrubis @ 2022-10-21  8:58 UTC (permalink / raw)
  To: Tarun Sahu; +Cc: aneesh.kumar, sbhat, ltp, vaibhav


> -- skip
> > > +	p = SAFE_MMAP(hugemap_addr, hpage_size, PROT_READ|PROT_WRITE,
> > > +			MAP_PRIVATE|MAP_FIXED, fd, 0);
> > > +	if (p != hugemap_addr) {
> > > +		tst_res(TFAIL, "mmap() at unexpected address %p instead
> > > of %p\n", p,
> > > +		     hugemap_addr);
> > > +		goto fail;
> > 
> > Can we just do return here instead. The failure has been reported
> > there
> > is no point in calling tst_brk(TBROK, ...) as well.
> When we run one iteration only, tst_brk does not make sense, I agree.
> But if we are running more than one iteration (i >= 2), test
> should not continue to next iteration if the current iteration fails.
> Only way I could find is to use tst_brk(TBROK,... , as tst_brk(TFAIl...
> is deprecated.

I do not see why we should abort on first failure as long as it's not
unrecoverable error. The TBROK status is only for cases where something
went really wrong and we cannot continue.

> > > +static void cleanup(void)
> > > +{
> > > +	if (fd >= 0)
> > > +		SAFE_CLOSE(fd);
> > > +	umount2(Hopt, MNT_DETACH);
> > 
> > We whould umount here only if we actually have mounted something.
> umount only, will require explicit unmap when test fails or break.
> For
> that, all the local variable for address mapping will have to be
> static defined so that they can be accessed in cleanup() function.
> 
> I tried to avoid it by using umount2 which eventually umount when
> process unmaps all the mappings after it finishes.

That's not what I meant, as long as you pass Hopt on a commandline
the test shoud not attempt to umount it at all.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge
  2022-10-21  8:58       ` Cyril Hrubis
@ 2022-10-25  5:56         ` Tarun Sahu
  2022-10-26 12:44           ` Cyril Hrubis
  0 siblings, 1 reply; 53+ messages in thread
From: Tarun Sahu @ 2022-10-25  5:56 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: aneesh.kumar, sbhat, ltp, vaibhav

Hi Cyril, 

On Fri, 2022-10-21 at 10:58 +0200, Cyril Hrubis wrote:
> > -- skip
> > > > +	p = SAFE_MMAP(hugemap_addr, hpage_size,
> > > > PROT_READ|PROT_WRITE,
> > > > +			MAP_PRIVATE|MAP_FIXED, fd, 0);
> > > > +	if (p != hugemap_addr) {
> > > > +		tst_res(TFAIL, "mmap() at unexpected address %p
> > > > instead
> > > > of %p\n", p,
> > > > +		     hugemap_addr);
> > > > +		goto fail;
> > > 
> > > Can we just do return here instead. The failure has been reported
> > > there
> > > is no point in calling tst_brk(TBROK, ...) as well.
> > When we run one iteration only, tst_brk does not make sense, I
> > agree.
> > But if we are running more than one iteration (i >= 2), test
> > should not continue to next iteration if the current iteration
> > fails.
> > Only way I could find is to use tst_brk(TBROK,... , as
> > tst_brk(TFAIl...
> > is deprecated.
> 
> I do not see why we should abort on first failure as long as it's not
> unrecoverable error. The TBROK status is only for cases where
> something
> went really wrong and we cannot continue.

Understood. I have removed it & updated your suggestions here
https://lore.kernel.org/all/20221019184846.89318-1-tsahu@linux.ibm.com/
Here, I posted same patches in small batch (only 3 at first) based on
suggestion given by Richard.
> 
> > > > +static void cleanup(void)
> > > > +{
> > > > +	if (fd >= 0)
> > > > +		SAFE_CLOSE(fd);
> > > > +	umount2(Hopt, MNT_DETACH);
> > > 
> > > We whould umount here only if we actually have mounted something.
> > umount only, will require explicit unmap when test fails or break.
> > For
> > that, all the local variable for address mapping will have to be
> > static defined so that they can be accessed in cleanup() function.
> > 
> > I tried to avoid it by using umount2 which eventually umount when
> > process unmaps all the mappings after it finishes.
> 
> That's not what I meant, as long as you pass Hopt on a commandline
> the test shoud not attempt to umount it at all.

Hopt is supposed to be the location which test will use to mount/umount
the hugetlbfs fs. If Hopt is not provided, it will create a temp
location. It is only to avoid creating any temporary locations outside
user concerned test environment.

     if(!Hopt)
	Hopt = tst_get_tmpdir();
     SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);

It is not expecting any already mounted hugetlbfs.
Please, check 
https://lore.kernel.org/all/20221019184846.89318-1-
tsahu@linux.ibm.com/
 for updated patch.

Thanks, 
Tarun


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge
  2022-10-25  5:56         ` Tarun Sahu
@ 2022-10-26 12:44           ` Cyril Hrubis
  0 siblings, 0 replies; 53+ messages in thread
From: Cyril Hrubis @ 2022-10-26 12:44 UTC (permalink / raw)
  To: Tarun Sahu; +Cc: aneesh.kumar, sbhat, ltp, vaibhav

Hi!
> Hopt is supposed to be the location which test will use to mount/umount
> the hugetlbfs fs. If Hopt is not provided, it will create a temp
> location. It is only to avoid creating any temporary locations outside
> user concerned test environment.
> 
>      if(!Hopt)
> 	Hopt = tst_get_tmpdir();
>      SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);
> 
> It is not expecting any already mounted hugetlbfs.

Ah right, this has been changed long ago in:

    7420ed0 hugemmap04: auto mount the temporary dir for testing
    c4dd870 hugemmap03: auto mount the temporary dir for testing
    9b4865f hugemmap02: auto mount the temporary dir for testing
    d8728dc hugemmap01: auto mount the temporary dir for testing

Before that the path had to point to already mounted hugetlbfs. At this
point this option is useless. So I would not add it to new tests at all
and just use the tmpdir unconditionally.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

* Re: [LTP] [PATCH 04/29] Hugetlb: Migrating libhugetlbfs counters
  2022-10-17 12:02   ` Cyril Hrubis
@ 2022-11-03  8:39     ` Tarun Sahu
  0 siblings, 0 replies; 53+ messages in thread
From: Tarun Sahu @ 2022-11-03  8:39 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: aneesh.kumar, ltp, sbhat, vaibhav

Hi, 
I am now working on this test after recently posted series,
Looking at your comments on this, I got the following question.

On Oct 17 2022, Cyril Hrubis wrote:
> Hi!
> > +static void bad_value(int line, const char *name, long expect, long actual)
> > +{
> > +	tst_res(TFAIL, "Failure Line %i: Bad %s: expected %li, actual %li",
> > +			line, name, expect, actual);
> > +	tst_brk(TBROK, "Breaking.. as once one of counter is not expected, "
> > +			"it will cause other failure anyway");
> > +}
> 
> Never ever create wrappers around result reporting functions like this.
> This break the best feature these function have, i.e. they print file
> and line number where the problem has happenend.
Sure will update it,
> 
> > +static void verify_counters(int line, long et, long ef, long er, long es)
> > +{
> > +	long t, f, r, s;
> > +
> > +	/* Read pool counters */
> > +	read_meminfo_huge(&t, &f, &r, &s);
> > +
> > +	if (f < r)
> > +		tst_res(TWARN, "HugePages_Free < HugePages_Rsvd");
> 
> Why exactly do we warn here?
> 
Yeah, Will remove this check.
> > +	/* Check actual values against expected values */
> > +	if (t != et)
> > +		bad_value(line, "HugePages_Total", et, t);
> > +
> > +	if (f != ef)
> > +		bad_value(line, "HugePages_Free", ef, f);
> > +
> > +	if (r != er)
> > +		bad_value(line, "HugePages_Rsvd", er, r);
> > +
> > +	if (s != es)
> > +		bad_value(line, "HugePages_Surp", es, s);
> 
> We do have rather nice macros exactly for this TST_EXP_EQ_LI() that
> would work nicely as long as you name the variables with something more
> reasonable than a single character.
> 
Q: TST_EXP_EQ_LI retuns with TPASS if counters matches. Only issue is
these counters are getting checked around 4*4*95=(1520) times in the test.
so to avoid printing PASS for so many times, I propse to avoid use of
it and only print TFAIL in case of failure and exit with help of goto
statements (because once counter are not expected, further checks will
not matter as they will be checked again corrupted counter values).
With this, PASS will be reported only once when all counters will be
checked and test will will be finished without any failure.
> 
> > -- 
> > 2.31.1
> > 
> > 
> > -- 
> > Mailing list info: https://lists.linux.it/listinfo/ltp
> 
> -- 
> Cyril Hrubis
> chrubis@suse.cz
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 53+ messages in thread

end of thread, other threads:[~2022-11-03  8:39 UTC | newest]

Thread overview: 53+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-16 12:57 [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 01/29] Hugetlb: Migrating libhugetlbfs brk_near_huge Tarun Sahu
2022-10-17  9:30   ` Cyril Hrubis
2022-10-18  7:33     ` Tarun Sahu
2022-10-21  8:58       ` Cyril Hrubis
2022-10-25  5:56         ` Tarun Sahu
2022-10-26 12:44           ` Cyril Hrubis
2022-10-17 10:20   ` Li Wang
2022-10-18  7:36     ` Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 02/29] Hugetlb: Migrating libhugetlbfs chunk-overcommit Tarun Sahu
2022-10-17 11:09   ` Cyril Hrubis
2022-10-16 12:57 ` [LTP] [PATCH 03/29] Hugetlb: Migrating libhugetlbfs corrupt-by-cow-opt Tarun Sahu
2022-10-17 11:46   ` Cyril Hrubis
2022-10-16 12:57 ` [LTP] [PATCH 04/29] Hugetlb: Migrating libhugetlbfs counters Tarun Sahu
2022-10-17 12:02   ` Cyril Hrubis
2022-11-03  8:39     ` Tarun Sahu
2022-10-18  3:38   ` Li Wang
2022-10-16 12:57 ` [LTP] [PATCH 05/29] Hugetlb: Migrating libhugetlbfs directio Tarun Sahu
2022-10-17 12:28   ` Cyril Hrubis
2022-10-16 12:57 ` [LTP] [PATCH 06/29] Hugetlb: Migrating libhugetlbfs fadvise_reserve Tarun Sahu
2022-10-17 12:35   ` Cyril Hrubis
2022-10-16 12:57 ` [LTP] [PATCH 07/29] Hugetlb: Migrating libhugetlbfs fallocate_align Tarun Sahu
2022-10-17 12:45   ` Cyril Hrubis
2022-10-16 12:57 ` [LTP] [PATCH 08/29] Hugetlb: Migrating libhugetlbfs fallocate_basic Tarun Sahu
2022-10-17 12:53   ` Cyril Hrubis
2022-10-16 12:57 ` [LTP] [PATCH 09/29] Hugetlb: Migrating libhugetlbfs fork-cow Tarun Sahu
2022-10-17 13:45   ` Cyril Hrubis
2022-10-18  6:56   ` Li Wang
2022-10-16 12:57 ` [LTP] [PATCH 10/29] Hugetlb: Migrating libhugetlbfs huge_at_4GB_normal_below Tarun Sahu
2022-10-17 14:46   ` Cyril Hrubis
2022-10-16 12:57 ` [LTP] [PATCH 11/29] Hugetlb: Migrating libhugetlbfs huge_below_4GB_normal_above Tarun Sahu
2022-10-17 14:48   ` Cyril Hrubis
2022-10-16 12:57 ` [LTP] [PATCH 12/29] Hugetlb: Migrating libhugetlbfs icache-hygiene Tarun Sahu
2022-10-17 19:37   ` Cyril Hrubis
2022-10-16 12:57 ` [LTP] [PATCH 13/29] Hugetlb: Migrating libhugetlbfs madvise_reserve Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 14/29] Hugetlb: Migrating libhugetlbfs map_high_truncate_2 Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 15/29] Hugetlb: Migrating libhugetlbfs misalign Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 16/29] Hugetlb: Migrating libhugetlbfs misaligned_offset Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 17/29] Hugetlb: Migrating libhugetlbfs mlock Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 18/29] Hugetlb: Migrating libhugetlbfs mmap-cow Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 19/29] Hugetlb: Migrating libhugetlbfs mmap-gettest Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 20/29] Hugetlb: Migrating libhugetlbfs mprotect Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 21/29] Hugetlb: Migrating libhugetlbfs mremap-fixed-huge-near-normal Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 22/29] Hugetlb: Migrating libhugetlbfs mremap-fixed-normal-near-huge Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 23/29] Hugetlb: Migrating libhugetlbfs noresv-reserve-resv-page Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 24/29] Hugetlb: Migrating libhugetlbfs noresv-regarded-as-resv Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 25/29] Hugetlb: Migrating libhugetlbfs private Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 26/29] Hugetlb: Migrating libhugetlbfs readahead_reserve Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 27/29] Hugetlb: Migrating libhugetlbfs readback Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 28/29] Hugetlb: Migrating libhugetlbfs shared Tarun Sahu
2022-10-16 12:57 ` [LTP] [PATCH 29/29] Hugetlb: Migrating libhugetlbfs shm-fork Tarun Sahu
2022-10-18 13:51 ` [LTP] [PATCH 00/29] Hugetlb: Migrating libhugetlbfs tests Richard Palethorpe
2022-10-19  5:11   ` Tarun Sahu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.