All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/4] lib: Add tst_kernel_bits()
@ 2017-01-12 13:23 Cyril Hrubis
  2017-01-12 13:23 ` [LTP] [PATCH 2/4] vma03: Disable the test on 64bit kernel as well Cyril Hrubis
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Cyril Hrubis @ 2017-01-12 13:23 UTC (permalink / raw)
  To: ltp

This function returns 32 or 64 depending on if we are running on 32bit
or 64bit kernel. This is detected from uname.machine string which seems
to be good enough heuristic and even if that fails we can always add a
special cases to the tst_kernel_bits() function.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 include/tst_kernel.h | 26 ++++++++++++++++++++++++++
 include/tst_test.h   |  1 +
 lib/tst_kernel.c     | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+)
 create mode 100644 include/tst_kernel.h
 create mode 100644 lib/tst_kernel.c

diff --git a/include/tst_kernel.h b/include/tst_kernel.h
new file mode 100644
index 0000000..5d5c04c
--- /dev/null
+++ b/include/tst_kernel.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TST_KERNEL_H__
+#define TST_KERNEL_H__
+
+/*
+ * Returns 32 if we are running on 32bit kernel and 64 if on 64bit kernel.
+ */
+int tst_kernel_bits(void);
+
+#endif	/* TST_KERNEL_H__ */
diff --git a/include/tst_test.h b/include/tst_test.h
index 1492ff5..7ff33b2 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -33,6 +33,7 @@
 #include "tst_atomic.h"
 #include "tst_kvercmp.h"
 #include "tst_clone.h"
+#include "tst_kernel.h"
 
 /*
  * Reports testcase result.
diff --git a/lib/tst_kernel.c b/lib/tst_kernel.c
new file mode 100644
index 0000000..7a53002
--- /dev/null
+++ b/lib/tst_kernel.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/utsname.h>
+#include "test.h"
+#include "tst_kernel.h"
+
+int tst_kernel_bits(void)
+{
+	struct utsname buf;
+	int kernel_bits;
+
+	if (uname(&buf))
+		tst_brkm(TBROK | TERRNO, NULL, "uname()");
+
+	kernel_bits = strstr(buf.machine, "64") ? 64 : 32;
+
+	tst_resm(TINFO, "uname.machine=%s kernel is %ibit",
+	         buf.machine, kernel_bits);
+
+	return kernel_bits;
+}
-- 
2.7.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [LTP] [PATCH 2/4] vma03: Disable the test on 64bit kernel as well
  2017-01-12 13:23 [LTP] [PATCH 1/4] lib: Add tst_kernel_bits() Cyril Hrubis
@ 2017-01-12 13:23 ` Cyril Hrubis
  2017-01-12 13:23 ` [LTP] [PATCH 3/4] mmapstress03: Small cleanup Cyril Hrubis
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2017-01-12 13:23 UTC (permalink / raw)
  To: ltp

The test works only on a 32bit kernel, otherwise we cannot cause the
overflow.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/mem/vma/vma03.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/mem/vma/vma03.c b/testcases/kernel/mem/vma/vma03.c
index 31c7716..edad9f4 100644
--- a/testcases/kernel/mem/vma/vma03.c
+++ b/testcases/kernel/mem/vma/vma03.c
@@ -49,6 +49,7 @@
 #include <unistd.h>
 
 #include "test.h"
+#include "tst_kernel.h"
 
 char *TCID = "vma03";
 int TST_TOTAL = 1;
@@ -70,9 +71,11 @@ int main(int argc, char *argv[])
 	void *map, *remap;
 	off_t pgoff;
 
-#if __WORDSIZE != 32
-	tst_brkm(TCONF, NULL, "test is designed for 32-bit system only.");
-#endif
+	if (__WORDSIZE != 32 || tst_kernel_bits() != 32) {
+		tst_brkm(TCONF, NULL,
+			 "test is designed for 32-bit system only.");
+	}
+
 	tst_parse_opts(argc, argv, NULL, NULL);
 
 	pgsz = sysconf(_SC_PAGE_SIZE);
-- 
2.7.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [LTP] [PATCH 3/4] mmapstress03: Small cleanup
  2017-01-12 13:23 [LTP] [PATCH 1/4] lib: Add tst_kernel_bits() Cyril Hrubis
  2017-01-12 13:23 ` [LTP] [PATCH 2/4] vma03: Disable the test on 64bit kernel as well Cyril Hrubis
@ 2017-01-12 13:23 ` Cyril Hrubis
  2017-01-12 13:23 ` [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel Cyril Hrubis
  2017-01-12 14:40 ` [LTP] [PATCH 1/4] lib: Add tst_kernel_bits() Jan Stancek
  3 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2017-01-12 13:23 UTC (permalink / raw)
  To: ltp

No fucntional changes done.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/mem/mmapstress/mmapstress03.c | 47 ++++++++------------------
 1 file changed, 14 insertions(+), 33 deletions(-)

diff --git a/testcases/kernel/mem/mmapstress/mmapstress03.c b/testcases/kernel/mem/mmapstress/mmapstress03.c
index 066587a..76a77a9 100644
--- a/testcases/kernel/mem/mmapstress/mmapstress03.c
+++ b/testcases/kernel/mem/mmapstress/mmapstress03.c
@@ -42,11 +42,9 @@
 #include <errno.h>
 #include <unistd.h>
 #include <limits.h>
+#include <stdlib.h>
 
-/*****  LTP Port        *****/
 #include "test.h"
-#define FAILED 0
-#define PASSED 1
 
 char *TCID = "mmapstress03";
 FILE *temp;
@@ -54,36 +52,24 @@ int TST_TOTAL = 1;
 
 int anyfail();
 void ok_exit();
-/*****  **      **      *****/
 
 #define AS_SVSM_VSEG_MAX	48UL
 #define AS_SVSM_MMAP_MAX	16UL
 
 #define EXTRA_VSEGS	2L
 #define NUM_SEGS	(AS_SVSM_VSEG_MAX + EXTRA_VSEGS)
-#define ERROR(M) (void)fprintf(stderr, "%s: errno = %d: " M "\n", progname, \
+#define ERROR(M) (void)fprintf(stderr, "%s: errno = %d: " M "\n", TCID, \
 			errno)
 #define NEG1	(char *)-1
 #define POINTER_SIZE	(sizeof(void *) << 3)
 
-extern long sysconf(int name);
-extern void exit(int);
-extern time_t time(time_t *);
-extern char *ctime(const time_t *);
-static void do_test(caddr_t brk_max, long pagesize);
+static void do_test(void* brk_max, long pagesize);
 
-static char *progname;
-
- /*ARGSUSED*/ int main(int argc, char *argv[])
+int main(void)
 {
 	char *brk_max_addr, *hole_addr, *brk_start, *hole_start;
 	size_t pagesize = (size_t) sysconf(_SC_PAGE_SIZE);
-	time_t t;
-
-	progname = argv[0];
 
-	(void)time(&t);
-//      (void)printf("%s: Started %s", argv[0], ctime(&t));
 	if ((brk_start = sbrk(0)) == NEG1) {
 		ERROR("initial sbrk failed");
 		anyfail();
@@ -105,7 +91,7 @@ static char *progname;
 		ERROR("couldn't find top of brk");
 		anyfail();
 	}
-	do_test((caddr_t) brk_max_addr, pagesize);
+	do_test((void*) brk_max_addr, pagesize);
 
 	/* now make holes and repeat test */
 	while (hole_addr + pagesize < brk_max_addr) {
@@ -120,7 +106,7 @@ static char *progname;
 		ERROR("do_test should leave the top of brk where it began");
 		anyfail();
 	}
-	do_test((caddr_t) brk_max_addr, pagesize);
+	do_test((void*) brk_max_addr, pagesize);
 
 	/* Shrink brk */
 	if (sbrk(-NUM_SEGS * pagesize) == NEG1) {
@@ -152,11 +138,11 @@ static char *progname;
 		anyfail();
 	}
 	/* Ask for a ridiculously large mmap region@a high address */
-	if (mmap((caddr_t) (1UL << (POINTER_SIZE - 1)) - pagesize,
+	if (mmap((void*) (1UL << (POINTER_SIZE - 1)) - pagesize,
 		 (size_t) ((1UL << (POINTER_SIZE - 1)) - pagesize),
 		 PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_FIXED | MAP_SHARED,
 		 0, 0)
-	    != (caddr_t) - 1) {
+	    != (void*) - 1) {
 		ERROR("really large mmap didn't fail");
 		anyfail();
 	}
@@ -164,8 +150,7 @@ static char *progname;
 		ERROR("really large mmap didn't set errno = ENOMEM nor EINVAL");
 		anyfail();
 	}
-	(void)time(&t);
-//      (void)printf("%s: Finished %s", argv[0], ctime(&t));
+
 	ok_exit();
 	tst_exit();
 }
@@ -174,21 +159,20 @@ static char *progname;
  * do_test assumes that brk_max is a multiple of pagesize
  */
 
-static
-void do_test(caddr_t brk_max, long pagesize)
+static void do_test(void* brk_max, long pagesize)
 {
-	if (mmap((caddr_t) ((long)brk_max - 3 * pagesize), (2 * pagesize),
+	if (mmap((void*) ((long)brk_max - 3 * pagesize), (2 * pagesize),
 		 PROT_READ | PROT_WRITE,
 		 MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0, 0)
-	    == (caddr_t) - 1) {
+	    == (void*) - 1) {
 		ERROR("mmap failed");
 		anyfail();
 	}
 	/* extend mmap */
-	if (mmap((caddr_t) ((long)brk_max - 2 * pagesize), (2 * pagesize),
+	if (mmap((void*) ((long)brk_max - 2 * pagesize), (2 * pagesize),
 		 PROT_READ | PROT_WRITE,
 		 MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0, 0)
-	    == (caddr_t) - 1) {
+	    == (void*) - 1) {
 		ERROR("mmap failed");
 		anyfail();
 	}
@@ -214,7 +198,6 @@ void do_test(caddr_t brk_max, long pagesize)
 	}
 }
 
-/*****  LTP Port        *****/
 void ok_exit(void)
 {
 	tst_resm(TPASS, "Test passed");
@@ -225,5 +208,3 @@ int anyfail(void)
 {
 	tst_brkm(TFAIL, NULL, "Test failed");
 }
-
-/*****  **      **      *****/
-- 
2.7.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel
  2017-01-12 13:23 [LTP] [PATCH 1/4] lib: Add tst_kernel_bits() Cyril Hrubis
  2017-01-12 13:23 ` [LTP] [PATCH 2/4] vma03: Disable the test on 64bit kernel as well Cyril Hrubis
  2017-01-12 13:23 ` [LTP] [PATCH 3/4] mmapstress03: Small cleanup Cyril Hrubis
@ 2017-01-12 13:23 ` Cyril Hrubis
  2017-01-12 14:41   ` Jan Stancek
  2017-01-12 14:40 ` [LTP] [PATCH 1/4] lib: Add tst_kernel_bits() Jan Stancek
  3 siblings, 1 reply; 11+ messages in thread
From: Cyril Hrubis @ 2017-01-12 13:23 UTC (permalink / raw)
  To: ltp

The ridiculously large mapping size has to be adjusted based on the
kernel addressing size not on a pointer size otherwise the testcase
segfaults when 32bit binary is executed on 64bit kernel.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/mem/mmapstress/mmapstress03.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/mem/mmapstress/mmapstress03.c b/testcases/kernel/mem/mmapstress/mmapstress03.c
index 76a77a9..fe25b7a 100644
--- a/testcases/kernel/mem/mmapstress/mmapstress03.c
+++ b/testcases/kernel/mem/mmapstress/mmapstress03.c
@@ -45,6 +45,7 @@
 #include <stdlib.h>
 
 #include "test.h"
+#include "tst_kernel.h"
 
 char *TCID = "mmapstress03";
 FILE *temp;
@@ -61,7 +62,6 @@ void ok_exit();
 #define ERROR(M) (void)fprintf(stderr, "%s: errno = %d: " M "\n", TCID, \
 			errno)
 #define NEG1	(char *)-1
-#define POINTER_SIZE	(sizeof(void *) << 3)
 
 static void do_test(void* brk_max, long pagesize);
 
@@ -69,6 +69,7 @@ int main(void)
 {
 	char *brk_max_addr, *hole_addr, *brk_start, *hole_start;
 	size_t pagesize = (size_t) sysconf(_SC_PAGE_SIZE);
+	int kernel_bits = tst_kernel_bits();
 
 	if ((brk_start = sbrk(0)) == NEG1) {
 		ERROR("initial sbrk failed");
@@ -137,9 +138,10 @@ int main(void)
 		ERROR("failed to fiddle with brk at the end");
 		anyfail();
 	}
+
 	/* Ask for a ridiculously large mmap region@a high address */
-	if (mmap((void*) (1UL << (POINTER_SIZE - 1)) - pagesize,
-		 (size_t) ((1UL << (POINTER_SIZE - 1)) - pagesize),
+	if (mmap((void*) (1UL << (kernel_bits - 1)) - pagesize,
+		 (size_t) ((1ULL << (kernel_bits - 1)) - pagesize),
 		 PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_FIXED | MAP_SHARED,
 		 0, 0)
 	    != (void*) - 1) {
-- 
2.7.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [LTP] [PATCH 1/4] lib: Add tst_kernel_bits()
  2017-01-12 13:23 [LTP] [PATCH 1/4] lib: Add tst_kernel_bits() Cyril Hrubis
                   ` (2 preceding siblings ...)
  2017-01-12 13:23 ` [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel Cyril Hrubis
@ 2017-01-12 14:40 ` Jan Stancek
  2017-01-12 14:45   ` Cyril Hrubis
  3 siblings, 1 reply; 11+ messages in thread
From: Jan Stancek @ 2017-01-12 14:40 UTC (permalink / raw)
  To: ltp




----- Original Message -----
> This function returns 32 or 64 depending on if we are running on 32bit
> or 64bit kernel. This is detected from uname.machine string which seems
> to be good enough heuristic and even if that fails we can always add a
> special cases to the tst_kernel_bits() function.

ACK, though I keep thinking if there isn't something in /proc
or /sys we could query and guess kernel bits from that.

Regards,
Jan

> 
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>  include/tst_kernel.h | 26 ++++++++++++++++++++++++++
>  include/tst_test.h   |  1 +
>  lib/tst_kernel.c     | 36 ++++++++++++++++++++++++++++++++++++
>  3 files changed, 63 insertions(+)
>  create mode 100644 include/tst_kernel.h
>  create mode 100644 lib/tst_kernel.c
> 
> diff --git a/include/tst_kernel.h b/include/tst_kernel.h
> new file mode 100644
> index 0000000..5d5c04c
> --- /dev/null
> +++ b/include/tst_kernel.h
> @@ -0,0 +1,26 @@
> +/*
> + * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#ifndef TST_KERNEL_H__
> +#define TST_KERNEL_H__
> +
> +/*
> + * Returns 32 if we are running on 32bit kernel and 64 if on 64bit kernel.
> + */
> +int tst_kernel_bits(void);
> +
> +#endif	/* TST_KERNEL_H__ */
> diff --git a/include/tst_test.h b/include/tst_test.h
> index 1492ff5..7ff33b2 100644
> --- a/include/tst_test.h
> +++ b/include/tst_test.h
> @@ -33,6 +33,7 @@
>  #include "tst_atomic.h"
>  #include "tst_kvercmp.h"
>  #include "tst_clone.h"
> +#include "tst_kernel.h"
>  
>  /*
>   * Reports testcase result.
> diff --git a/lib/tst_kernel.c b/lib/tst_kernel.c
> new file mode 100644
> index 0000000..7a53002
> --- /dev/null
> +++ b/lib/tst_kernel.c
> @@ -0,0 +1,36 @@
> +/*
> + * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <sys/utsname.h>
> +#include "test.h"
> +#include "tst_kernel.h"
> +
> +int tst_kernel_bits(void)
> +{
> +	struct utsname buf;
> +	int kernel_bits;
> +
> +	if (uname(&buf))
> +		tst_brkm(TBROK | TERRNO, NULL, "uname()");
> +
> +	kernel_bits = strstr(buf.machine, "64") ? 64 : 32;
> +
> +	tst_resm(TINFO, "uname.machine=%s kernel is %ibit",
> +	         buf.machine, kernel_bits);
> +
> +	return kernel_bits;
> +}
> --
> 2.7.3
> 
> 
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel
  2017-01-12 13:23 ` [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel Cyril Hrubis
@ 2017-01-12 14:41   ` Jan Stancek
  2017-01-12 15:05     ` Cyril Hrubis
  0 siblings, 1 reply; 11+ messages in thread
From: Jan Stancek @ 2017-01-12 14:41 UTC (permalink / raw)
  To: ltp





----- Original Message -----
> From: "Cyril Hrubis" <chrubis@suse.cz>
> To: ltp@lists.linux.it
> Sent: Thursday, 12 January, 2017 2:23:39 PM
> Subject: [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel
> 
> The ridiculously large mapping size has to be adjusted based on the
> kernel addressing size not on a pointer size otherwise the testcase
> segfaults when 32bit binary is executed on 64bit kernel.
> 
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>  testcases/kernel/mem/mmapstress/mmapstress03.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/testcases/kernel/mem/mmapstress/mmapstress03.c
> b/testcases/kernel/mem/mmapstress/mmapstress03.c
> index 76a77a9..fe25b7a 100644
> --- a/testcases/kernel/mem/mmapstress/mmapstress03.c
> +++ b/testcases/kernel/mem/mmapstress/mmapstress03.c
> @@ -45,6 +45,7 @@
>  #include <stdlib.h>
>  
>  #include "test.h"
> +#include "tst_kernel.h"
>  
>  char *TCID = "mmapstress03";
>  FILE *temp;
> @@ -61,7 +62,6 @@ void ok_exit();
>  #define ERROR(M) (void)fprintf(stderr, "%s: errno = %d: " M "\n", TCID, \
>  			errno)
>  #define NEG1	(char *)-1
> -#define POINTER_SIZE	(sizeof(void *) << 3)
>  
>  static void do_test(void* brk_max, long pagesize);
>  
> @@ -69,6 +69,7 @@ int main(void)
>  {
>  	char *brk_max_addr, *hole_addr, *brk_start, *hole_start;
>  	size_t pagesize = (size_t) sysconf(_SC_PAGE_SIZE);
> +	int kernel_bits = tst_kernel_bits();
>  
>  	if ((brk_start = sbrk(0)) == NEG1) {
>  		ERROR("initial sbrk failed");
> @@ -137,9 +138,10 @@ int main(void)
>  		ERROR("failed to fiddle with brk at the end");
>  		anyfail();
>  	}
> +
>  	/* Ask for a ridiculously large mmap region at a high address */
> -	if (mmap((void*) (1UL << (POINTER_SIZE - 1)) - pagesize,
> -		 (size_t) ((1UL << (POINTER_SIZE - 1)) - pagesize),
> +	if (mmap((void*) (1UL << (kernel_bits - 1)) - pagesize,

Since this has same range as below, shouldn't it be also 1ULL?
Entire series looks OK to me.

Regards,
Jan

> +		 (size_t) ((1ULL << (kernel_bits - 1)) - pagesize),
>  		 PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_FIXED | MAP_SHARED,
>  		 0, 0)
>  	    != (void*) - 1) {
> --
> 2.7.3
> 
> 
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [LTP] [PATCH 1/4] lib: Add tst_kernel_bits()
  2017-01-12 14:40 ` [LTP] [PATCH 1/4] lib: Add tst_kernel_bits() Jan Stancek
@ 2017-01-12 14:45   ` Cyril Hrubis
  0 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2017-01-12 14:45 UTC (permalink / raw)
  To: ltp

Hi!
> > This function returns 32 or 64 depending on if we are running on 32bit
> > or 64bit kernel. This is detected from uname.machine string which seems
> > to be good enough heuristic and even if that fails we can always add a
> > special cases to the tst_kernel_bits() function.
> 
> ACK, though I keep thinking if there isn't something in /proc
> or /sys we could query and guess kernel bits from that.

Unfortunately parsing the machine from uname was the only way I could
came up with.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel
  2017-01-12 14:41   ` Jan Stancek
@ 2017-01-12 15:05     ` Cyril Hrubis
  2017-01-12 16:41       ` Jan Stancek
  0 siblings, 1 reply; 11+ messages in thread
From: Cyril Hrubis @ 2017-01-12 15:05 UTC (permalink / raw)
  To: ltp

Hi!
> >  	/* Ask for a ridiculously large mmap region at a high address */
> > -	if (mmap((void*) (1UL << (POINTER_SIZE - 1)) - pagesize,
> > -		 (size_t) ((1UL << (POINTER_SIZE - 1)) - pagesize),
> > +	if (mmap((void*) (1UL << (kernel_bits - 1)) - pagesize,
> 
> Since this has same range as below, shouldn't it be also 1ULL?
> Entire series looks OK to me.

Hmm, that produces warnings in case that sizeof(void) == 4 and with
64bit kernel since the value is truncated. I guess that the addres
should be generated accordingly to the binary and not kernel after all
because of address space limitations.

Something as (((uintptr_t)1) << ((sizeof(void*)<<3) - 1) - pagesize)

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel
  2017-01-12 15:05     ` Cyril Hrubis
@ 2017-01-12 16:41       ` Jan Stancek
  2017-01-12 17:00         ` Cyril Hrubis
  2017-01-12 17:00         ` Jan Stancek
  0 siblings, 2 replies; 11+ messages in thread
From: Jan Stancek @ 2017-01-12 16:41 UTC (permalink / raw)
  To: ltp





----- Original Message -----
> From: "Cyril Hrubis" <chrubis@suse.cz>
> To: "Jan Stancek" <jstancek@redhat.com>
> Cc: ltp@lists.linux.it
> Sent: Thursday, 12 January, 2017 4:05:51 PM
> Subject: Re: [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel
> 
> Hi!
> > >  	/* Ask for a ridiculously large mmap region at a high address */
> > > -	if (mmap((void*) (1UL << (POINTER_SIZE - 1)) - pagesize,
> > > -		 (size_t) ((1UL << (POINTER_SIZE - 1)) - pagesize),
> > > +	if (mmap((void*) (1UL << (kernel_bits - 1)) - pagesize,
> > 
> > Since this has same range as below, shouldn't it be also 1ULL?
> > Entire series looks OK to me.
> 
> Hmm, that produces warnings in case that sizeof(void) == 4 and with
> 64bit kernel since the value is truncated. I guess that the addres
> should be generated accordingly to the binary and not kernel after all
> because of address space limitations.
> 
> Something as (((uintptr_t)1) << ((sizeof(void*)<<3) - 1) - pagesize)

Wouldn't this crash same as original?

On 32 bit, it seems that as soon as mmap touches "stack"
we crash. On 64-bit I'm guessing map area is so high, that
we get rejected immediately with ENOMEM.

Example of lowering size to 1M and targeting stack (32bit on 64bit kernel):

# uname -r
4.8.0-1.el7.test.x86_64

Address           Kbytes     RSS   Dirty Mode  Mapping
0000000008048000      56      56      56 r-x-- mmapstress03
0000000008048000       0       0       0 r-x-- mmapstress03
0000000008056000       4       4       4 r---- mmapstress03
0000000008056000       0       0       0 r---- mmapstress03
0000000008057000       4       4       4 rw--- mmapstress03
0000000008057000       0       0       0 rw--- mmapstress03
0000000008058000      12       0       0 rw---   [ anon ]
0000000008058000       0       0       0 rw---   [ anon ]
00000000f7519000       4       4       4 rw---   [ anon ]
00000000f7519000       0       0       0 rw---   [ anon ]
00000000f751a000    1756     920       0 r-x-- libc-2.17.so
00000000f751a000       0       0       0 r-x-- libc-2.17.so
00000000f76d1000       4       0       0 ----- libc-2.17.so
00000000f76d1000       0       0       0 ----- libc-2.17.so
00000000f76d2000       8       8       8 r---- libc-2.17.so
00000000f76d2000       0       0       0 r---- libc-2.17.so
00000000f76d4000       4       4       4 rw--- libc-2.17.so
00000000f76d4000       0       0       0 rw--- libc-2.17.so
00000000f76d5000      12       8       8 rw---   [ anon ]
00000000f76d5000       0       0       0 rw---   [ anon ]
00000000f76e7000     124     120       0 r-x-- ld-2.17.so
00000000f76e7000       0       0       0 r-x-- ld-2.17.so
00000000f7706000       4       4       4 rw---   [ anon ]
00000000f7706000       0       0       0 rw---   [ anon ]
00000000f7707000       4       4       4 r---- ld-2.17.so
00000000f7707000       0       0       0 r---- ld-2.17.so
00000000f7708000       4       4       4 rw--- ld-2.17.so
00000000f7708000       0       0       0 rw--- ld-2.17.so
00000000ff873000     132       8       8 rw---   [ stack ]
00000000ff873000       0       0       0 rw---   [ stack ]
---------------- ------- ------- ------- 
total kB            2132    1148     108

...
mmap2(0xff800000, 1048576, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED|MAP_ANONYMOUS, 0, 0) = 0xffffffffff800000
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0} ---
+++ killed by SIGSEGV +++
Segmentation fault


> 
> --
> Cyril Hrubis
> chrubis@suse.cz
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel
  2017-01-12 16:41       ` Jan Stancek
@ 2017-01-12 17:00         ` Cyril Hrubis
  2017-01-12 17:00         ` Jan Stancek
  1 sibling, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2017-01-12 17:00 UTC (permalink / raw)
  To: ltp

Hi!
> > Something as (((uintptr_t)1) << ((sizeof(void*)<<3) - 1) - pagesize)
> 
> Wouldn't this crash same as original?

That does not seem to be the case here I guess that the reason is that
the size passed to the mmap2() in case of the 32bit binary on 64bit
kernel is so close to 4GB after the patch that it's rejected right away
as well. And possibly for 32bit binary on 32bit kernel 2GB size is
enough to be rejected for the very same reason.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel
  2017-01-12 16:41       ` Jan Stancek
  2017-01-12 17:00         ` Cyril Hrubis
@ 2017-01-12 17:00         ` Jan Stancek
  1 sibling, 0 replies; 11+ messages in thread
From: Jan Stancek @ 2017-01-12 17:00 UTC (permalink / raw)
  To: ltp





----- Original Message -----
> From: "Jan Stancek" <jstancek@redhat.com>
> To: "Cyril Hrubis" <chrubis@suse.cz>
> Cc: ltp@lists.linux.it
> Sent: Thursday, 12 January, 2017 5:41:25 PM
> Subject: Re: [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel
> 
> 
> 
> 
> 
> ----- Original Message -----
> > From: "Cyril Hrubis" <chrubis@suse.cz>
> > To: "Jan Stancek" <jstancek@redhat.com>
> > Cc: ltp@lists.linux.it
> > Sent: Thursday, 12 January, 2017 4:05:51 PM
> > Subject: Re: [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel
> > 
> > Hi!
> > > >  	/* Ask for a ridiculously large mmap region at a high address */
> > > > -	if (mmap((void*) (1UL << (POINTER_SIZE - 1)) - pagesize,
> > > > -		 (size_t) ((1UL << (POINTER_SIZE - 1)) - pagesize),
> > > > +	if (mmap((void*) (1UL << (kernel_bits - 1)) - pagesize,
> > > 
> > > Since this has same range as below, shouldn't it be also 1ULL?
> > > Entire series looks OK to me.
> > 
> > Hmm, that produces warnings in case that sizeof(void) == 4 and with
> > 64bit kernel since the value is truncated. I guess that the addres
> > should be generated accordingly to the binary and not kernel after all
> > because of address space limitations.
> > 
> > Something as (((uintptr_t)1) << ((sizeof(void*)<<3) - 1) - pagesize)
> 
> Wouldn't this crash same as original?
> 
> On 32 bit, it seems that as soon as mmap touches "stack"
> we crash. On 64-bit I'm guessing map area is so high, that
> we get rejected immediately with ENOMEM.

Most likely here (for 64-bit case):

get_unmapped_area()
...
        if (len > TASK_SIZE)
                return -ENOMEM;

#define TASK_SIZE_MAX   ((1UL << 47) - PAGE_SIZE)
and our len is almost half of address space.


> 
> Example of lowering size to 1M and targeting stack (32bit on 64bit kernel):
> 
> # uname -r
> 4.8.0-1.el7.test.x86_64
> 
> Address           Kbytes     RSS   Dirty Mode  Mapping
> 0000000008048000      56      56      56 r-x-- mmapstress03
> 0000000008048000       0       0       0 r-x-- mmapstress03
> 0000000008056000       4       4       4 r---- mmapstress03
> 0000000008056000       0       0       0 r---- mmapstress03
> 0000000008057000       4       4       4 rw--- mmapstress03
> 0000000008057000       0       0       0 rw--- mmapstress03
> 0000000008058000      12       0       0 rw---   [ anon ]
> 0000000008058000       0       0       0 rw---   [ anon ]
> 00000000f7519000       4       4       4 rw---   [ anon ]
> 00000000f7519000       0       0       0 rw---   [ anon ]
> 00000000f751a000    1756     920       0 r-x-- libc-2.17.so
> 00000000f751a000       0       0       0 r-x-- libc-2.17.so
> 00000000f76d1000       4       0       0 ----- libc-2.17.so
> 00000000f76d1000       0       0       0 ----- libc-2.17.so
> 00000000f76d2000       8       8       8 r---- libc-2.17.so
> 00000000f76d2000       0       0       0 r---- libc-2.17.so
> 00000000f76d4000       4       4       4 rw--- libc-2.17.so
> 00000000f76d4000       0       0       0 rw--- libc-2.17.so
> 00000000f76d5000      12       8       8 rw---   [ anon ]
> 00000000f76d5000       0       0       0 rw---   [ anon ]
> 00000000f76e7000     124     120       0 r-x-- ld-2.17.so
> 00000000f76e7000       0       0       0 r-x-- ld-2.17.so
> 00000000f7706000       4       4       4 rw---   [ anon ]
> 00000000f7706000       0       0       0 rw---   [ anon ]
> 00000000f7707000       4       4       4 r---- ld-2.17.so
> 00000000f7707000       0       0       0 r---- ld-2.17.so
> 00000000f7708000       4       4       4 rw--- ld-2.17.so
> 00000000f7708000       0       0       0 rw--- ld-2.17.so
> 00000000ff873000     132       8       8 rw---   [ stack ]
> 00000000ff873000       0       0       0 rw---   [ stack ]
> ---------------- ------- ------- -------
> total kB            2132    1148     108
> 
> ...
> mmap2(0xff800000, 1048576, PROT_READ|PROT_WRITE,
> MAP_SHARED|MAP_FIXED|MAP_ANONYMOUS, 0, 0) = 0xffffffffff800000
> --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0} ---
> +++ killed by SIGSEGV +++
> Segmentation fault
> 
> 
> > 
> > --
> > Cyril Hrubis
> > chrubis@suse.cz
> > 
> 
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-01-12 17:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-12 13:23 [LTP] [PATCH 1/4] lib: Add tst_kernel_bits() Cyril Hrubis
2017-01-12 13:23 ` [LTP] [PATCH 2/4] vma03: Disable the test on 64bit kernel as well Cyril Hrubis
2017-01-12 13:23 ` [LTP] [PATCH 3/4] mmapstress03: Small cleanup Cyril Hrubis
2017-01-12 13:23 ` [LTP] [PATCH 4/4] mmapstress03: Fix 32bit test on 64bit kernel Cyril Hrubis
2017-01-12 14:41   ` Jan Stancek
2017-01-12 15:05     ` Cyril Hrubis
2017-01-12 16:41       ` Jan Stancek
2017-01-12 17:00         ` Cyril Hrubis
2017-01-12 17:00         ` Jan Stancek
2017-01-12 14:40 ` [LTP] [PATCH 1/4] lib: Add tst_kernel_bits() Jan Stancek
2017-01-12 14:45   ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.