Blame SOURCES/libhugetlbfs-2.16-misalign_test.patch

226aa2
commit fd430caf7126228cd7e208547ae83b335400e040
226aa2
Author: Jan Stancek <jstancek@redhat.com>
226aa2
Date:   Mon Feb 10 21:18:05 2014 -0500
226aa2
226aa2
    [PATCH] misalign: misaligned length allowed on kernels >= 3.10-rc1
226aa2
    
226aa2
    Startin with 3.10-rc1, length passed in mmap() doesn't need
226aa2
    to be aligned because commit af73e4d9506d3b797509f3c030e7dcd554f7d9c4
226aa2
    added ALIGN() to kernel side, in mmap_pgoff(), when mapping huge
226aa2
    page files.
226aa2
    
226aa2
    This patch treats successful mmap() with misaligned length on
226aa2
    kernels >= 3.10 as PASS.
226aa2
    
226aa2
    See also:
226aa2
    Bug 56881 - MAP_HUGETLB mmap fails for certain sizes
226aa2
    https://bugzilla.kernel.org/show_bug.cgi?id=56881
226aa2
    
226aa2
    Signed-off-by: Jan Stancek <jstancek@redhat.com>
226aa2
    Signed-off-by: Eric Munson <emunson@mgebm.net>
226aa2
226aa2
diff --git a/tests/misalign.c b/tests/misalign.c
226aa2
index de85be6..de1bf98 100644
226aa2
--- a/tests/misalign.c
226aa2
+++ b/tests/misalign.c
226aa2
@@ -23,6 +23,7 @@
226aa2
 #include <errno.h>
226aa2
 #include <signal.h>
226aa2
 #include <sys/mman.h>
226aa2
+#include <sys/utsname.h>
226aa2
 
226aa2
 #include <hugetlbfs.h>
226aa2
 
226aa2
@@ -40,6 +41,11 @@
226aa2
  * necessary checks for the hugepage paths.  This testcase ensures
226aa2
  * that attempted hugepage mappings with parameters which are not
226aa2
  * correctly hugepage aligned are rejected.
226aa2
+ *
226aa2
+ * However starting with 3.10-rc1, length passed in mmap() doesn't need
226aa2
+ * to be aligned because commit af73e4d9506d3b797509f3c030e7dcd554f7d9c4
226aa2
+ * added ALIGN() to kernel side, in mmap_pgoff(), when mapping huge page
226aa2
+ * files.
226aa2
  */
226aa2
 int main(int argc, char *argv[])
226aa2
 {
226aa2
@@ -47,9 +53,13 @@ int main(int argc, char *argv[])
226aa2
 	int fd;
226aa2
 	void *p, *q;
226aa2
 	int err;
226aa2
+	struct utsname buf;
226aa2
 
226aa2
 	test_init(argc, argv);
226aa2
 
226aa2
+	if (uname(&buf) != 0)
226aa2
+		FAIL("uname failed %s", strerror(errno));
226aa2
+
226aa2
 	page_size = getpagesize();
226aa2
 	hpage_size = check_hugepagesize();
226aa2
 
226aa2
@@ -92,16 +102,30 @@ int main(int argc, char *argv[])
226aa2
 
226aa2
 	/* 3) Try a misaligned length */
226aa2
 	q = mmap(NULL, page_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
226aa2
-	if (q != MAP_FAILED)
226aa2
-		FAIL("mmap() with misaligned length 0x%lx succeeded",
226aa2
-		     page_size);
226aa2
+
226aa2
+	if (test_compare_kver(buf.release, "3.10.0") < 0) {
226aa2
+		if (q != MAP_FAILED)
226aa2
+			FAIL("mmap() with misaligned length 0x%lx succeeded",
226aa2
+				page_size);
226aa2
+	} else {
226aa2
+		if (q == MAP_FAILED)
226aa2
+			FAIL("mmap() with misaligned length 0x%lx failed",
226aa2
+				page_size);
226aa2
+	}
226aa2
 
226aa2
 	/* 4) Try a misaligned length with MAP_FIXED */
226aa2
 	q = mmap(p, page_size, PROT_READ|PROT_WRITE,
226aa2
 		 MAP_PRIVATE|MAP_FIXED, fd, 0);
226aa2
-	if (q != MAP_FAILED)
226aa2
-		FAIL("mmap() MAP_FIXED with misaligned length 0x%lx succeeded",
226aa2
-		     page_size);
226aa2
+
226aa2
+	if (test_compare_kver(buf.release, "3.10.0") < 0) {
226aa2
+		if (q != MAP_FAILED)
226aa2
+			FAIL("mmap() MAP_FIXED with misaligned length 0x%lx "
226aa2
+				"succeeded", page_size);
226aa2
+	} else {
226aa2
+		if (q == MAP_FAILED)
226aa2
+			FAIL("mmap() MAP_FIXED with misaligned length 0x%lx "
226aa2
+				"failed", page_size);
226aa2
+	}
226aa2
 
226aa2
 	/* 5) Try a misaligned offset */
226aa2
 	q = mmap(NULL, hpage_size, PROT_READ|PROT_WRITE,