From: Tarun Sahu <tsahu@linux.ibm.com>
To: ltp@lists.linux.it
Cc: geetika@linux.ibm.com, sbhat@linux.ibm.com,
aneesh.kumar@linux.ibm.com, vaibhav@linux.ibm.com,
rpalethorpe@suse.com
Subject: [LTP] [PATCH v6 4/4] Hugetlb: Migrating libhugetlbfs corrupt-by-cow-opt
Date: Thu, 3 Nov 2022 11:13:17 +0530 [thread overview]
Message-ID: <20221103054317.499221-5-tsahu@linux.ibm.com> (raw)
In-Reply-To: <20221103054317.499221-1-tsahu@linux.ibm.com>
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 | 80 +++++++++++++++++++
3 files changed, 82 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..df7c9edcb
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2013 Joonsoo Kim, LG Electronics.
+ * Author: Joonsoo Kim
+ */
+
+/*\
+ * [Description]
+ *
+ * Corrupt by COW optimization:
+ * 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.
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+#define MNTPOINT "hugetlbfs/"
+static long hpage_size;
+static int huge_fd = -1;
+
+static void run_test(void)
+{
+ char *p;
+ char c;
+
+ p = SAFE_MMAP(NULL, hpage_size, PROT_READ|PROT_WRITE, MAP_SHARED,
+ huge_fd, 0);
+ *p = 's';
+ 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,
+ huge_fd, 0);
+ *p = 'p';
+ 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,
+ huge_fd, 0);
+ c = *p;
+ 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.");
+ else
+ tst_res(TPASS, "Successful");
+}
+
+static void setup(void)
+{
+ hpage_size = SAFE_READ_MEMINFO("Hugepagesize:")*1024;
+ huge_fd = tst_creat_unlinked(MNTPOINT);
+}
+
+static void cleanup(void)
+{
+ SAFE_CLOSE(huge_fd);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .mntpoint = MNTPOINT,
+ .needs_hugetlbfs = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = run_test,
+ .hugepages = {2, TST_NEEDS},
+};
--
2.31.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
prev parent reply other threads:[~2022-11-03 5:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-03 5:43 [LTP] [PATCH v6 0/4] Hugetlb:Migrating the libhugetlbfs tests Tarun Sahu
2022-11-03 5:43 ` [LTP] [PATCH v6 1/4] Hugetlb: Add new tst_test options for hugeltb test support Tarun Sahu
2022-11-03 6:08 ` Li Wang
2022-11-03 9:31 ` Tarun Sahu
2022-11-03 9:55 ` Li Wang
2022-11-03 9:45 ` Cyril Hrubis
2022-11-03 5:43 ` [LTP] [PATCH v6 2/4] Hugetlb: Migrating libhugetlbfs brk_near_huge Tarun Sahu
2022-11-03 9:55 ` Cyril Hrubis
2022-11-03 10:01 ` Cyril Hrubis
2022-11-03 5:43 ` [LTP] [PATCH v6 3/4] Hugetlb: Migrating libhugetlbfs chunk-overcommit Tarun Sahu
2022-11-03 5:43 ` Tarun Sahu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221103054317.499221-5-tsahu@linux.ibm.com \
--to=tsahu@linux.ibm.com \
--cc=aneesh.kumar@linux.ibm.com \
--cc=geetika@linux.ibm.com \
--cc=ltp@lists.linux.it \
--cc=rpalethorpe@suse.com \
--cc=sbhat@linux.ibm.com \
--cc=vaibhav@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox