Blame SOURCES/libhugetlbfs-2.16-misalign_test.patch

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