@@ -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
@@ -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
new file mode 100644
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2013 LG Electronics.
+ * Author: Joonsoo Kim
+ */
+
+/*\
+ * [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.
+ */
+
+#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 MNTPOINT "hugetlbfs/"
+static long hpage_size;
+static int fd = -1;
+
+static void run_test(void)
+{
+ unsigned long initial_resv, end_resv;
+ int fd;
+ char *p, *q;
+
+ initial_resv = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD);
+
+ fd = tst_creat_unlinked(MNTPOINT, 0);
+ 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 | MAP_NORESERVE, fd, 0);
+
+ *q = 's';
+
+ SAFE_MUNMAP(p, hpage_size);
+ SAFE_MUNMAP(q, hpage_size);
+ SAFE_CLOSE(fd);
+
+ end_resv = SAFE_READ_MEMINFO(MEMINFO_HPAGE_RSVD);
+
+ TST_EXP_EQ_LU(initial_resv, end_resv);
+}
+
+static void setup(void)
+{
+ hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
+}
+
+static void cleanup(void)
+{
+ if (fd >= 0)
+ SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .mntpoint = MNTPOINT,
+ .needs_hugetlbfs = 1,
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = run_test,
+ .hugepages = {2, TST_NEEDS},
+};
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 | 74 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap28.c