Blame SOURCES/libhugetlbfs-2.16-misalign_test.patch

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