diff mbox series

[BUGFIX,v2,1/5] selftests: proc: Make va_max 1GB on 32bit arch

Message ID 157164648909.17692.6080553792829040898.stgit@devnote2 (mailing list archive)
State New
Headers show
Series selftests: Fixes for 32bit arch | expand

Commit Message

Masami Hiramatsu (Google) Oct. 21, 2019, 8:28 a.m. UTC
Currently proc-self-map-files-002.c sets va_max (max test address
of user virtual address) to 4GB, but it is too big for 32bit
arch and 1UL << 32 is overflow on 32bit long.

Make va_max 1GB on 32bit arch like i386 and arm.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
---
 Changes in v2:
  - Make the va_max 1GB according to Alexey's comment.
---
 .../selftests/proc/proc-self-map-files-002.c       |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Alexey Dobriyan Oct. 21, 2019, 5:30 p.m. UTC | #1
On Mon, Oct 21, 2019 at 05:28:09PM +0900, Masami Hiramatsu wrote:
> Currently proc-self-map-files-002.c sets va_max (max test address
> of user virtual address) to 4GB, but it is too big for 32bit
> arch and 1UL << 32 is overflow on 32bit long.
> 
> Make va_max 1GB on 32bit arch like i386 and arm.

> +#if __BITS_PER_LONG == 32
> +# define VA_MAX (1UL << 30)
> +#elif __BITS_PER_LONG == 64
> +# define VA_MAX (1UL << 32)
> +#else
> +# define VA_MAX 0
> +#endif
> +
>  int main(void)
>  {
>  	const int PAGE_SIZE = sysconf(_SC_PAGESIZE);
> -	const unsigned long va_max = 1UL << 32;
> +	const unsigned long va_max = VA_MAX;

No, just make it like 1MB unconditionally.
This is not intended to cover all address space, just large enough part
(larger than reasonable vm.mmap_min_addr)
Masami Hiramatsu (Google) Oct. 23, 2019, 1:56 a.m. UTC | #2
On Mon, 21 Oct 2019 20:30:53 +0300
Alexey Dobriyan <adobriyan@gmail.com> wrote:

> On Mon, Oct 21, 2019 at 05:28:09PM +0900, Masami Hiramatsu wrote:
> > Currently proc-self-map-files-002.c sets va_max (max test address
> > of user virtual address) to 4GB, but it is too big for 32bit
> > arch and 1UL << 32 is overflow on 32bit long.
> > 
> > Make va_max 1GB on 32bit arch like i386 and arm.
> 
> > +#if __BITS_PER_LONG == 32
> > +# define VA_MAX (1UL << 30)
> > +#elif __BITS_PER_LONG == 64
> > +# define VA_MAX (1UL << 32)
> > +#else
> > +# define VA_MAX 0
> > +#endif
> > +
> >  int main(void)
> >  {
> >  	const int PAGE_SIZE = sysconf(_SC_PAGESIZE);
> > -	const unsigned long va_max = 1UL << 32;
> > +	const unsigned long va_max = VA_MAX;
> 
> No, just make it like 1MB unconditionally.

Ah, I sse. BTW, would you mean 1GB?

> This is not intended to cover all address space, just large enough part
> (larger than reasonable vm.mmap_min_addr)

Then, should we better to check the /proc/sys/vm/mmap_min_addr?

Thank you,
Masami Hiramatsu (Google) Oct. 23, 2019, 4:51 a.m. UTC | #3
On Wed, 23 Oct 2019 10:56:18 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> On Mon, 21 Oct 2019 20:30:53 +0300
> Alexey Dobriyan <adobriyan@gmail.com> wrote:
> 
> > On Mon, Oct 21, 2019 at 05:28:09PM +0900, Masami Hiramatsu wrote:
> > > Currently proc-self-map-files-002.c sets va_max (max test address
> > > of user virtual address) to 4GB, but it is too big for 32bit
> > > arch and 1UL << 32 is overflow on 32bit long.
> > > 
> > > Make va_max 1GB on 32bit arch like i386 and arm.
> > 
> > > +#if __BITS_PER_LONG == 32
> > > +# define VA_MAX (1UL << 30)
> > > +#elif __BITS_PER_LONG == 64
> > > +# define VA_MAX (1UL << 32)
> > > +#else
> > > +# define VA_MAX 0
> > > +#endif
> > > +
> > >  int main(void)
> > >  {
> > >  	const int PAGE_SIZE = sysconf(_SC_PAGESIZE);
> > > -	const unsigned long va_max = 1UL << 32;
> > > +	const unsigned long va_max = VA_MAX;
> > 
> > No, just make it like 1MB unconditionally.
> 
> Ah, I sse. BTW, would you mean 1GB?

I understand that 1MB will be good enough, since vm.mmap_min_addr is
64KB by default (except for arm/arm64 which is 32KB).
OK, I'll update and resend.

Thank you,

> 
> > This is not intended to cover all address space, just large enough part
> > (larger than reasonable vm.mmap_min_addr)
> 
> Then, should we better to check the /proc/sys/vm/mmap_min_addr?
> 
> Thank you,
> 
> -- 
> Masami Hiramatsu <mhiramat@kernel.org>
diff mbox series

Patch

diff --git a/tools/testing/selftests/proc/proc-self-map-files-002.c b/tools/testing/selftests/proc/proc-self-map-files-002.c
index 47b7473dedef..5d372d66d6ad 100644
--- a/tools/testing/selftests/proc/proc-self-map-files-002.c
+++ b/tools/testing/selftests/proc/proc-self-map-files-002.c
@@ -22,6 +22,7 @@ 
 #include <unistd.h>
 #include <sys/mman.h>
 #include <stdlib.h>
+#include <asm/bitsperlong.h>
 
 static void pass(const char *fmt, unsigned long a, unsigned long b)
 {
@@ -44,10 +45,18 @@  static void fail(const char *fmt, unsigned long a, unsigned long b)
 	exit(1);
 }
 
+#if __BITS_PER_LONG == 32
+# define VA_MAX (1UL << 30)
+#elif __BITS_PER_LONG == 64
+# define VA_MAX (1UL << 32)
+#else
+# define VA_MAX 0
+#endif
+
 int main(void)
 {
 	const int PAGE_SIZE = sysconf(_SC_PAGESIZE);
-	const unsigned long va_max = 1UL << 32;
+	const unsigned long va_max = VA_MAX;
 	unsigned long va;
 	void *p;
 	int fd;