public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] mm/vma01: consider topdown and bottomup allocation
@ 2012-06-25  3:22 Caspar Zhang
  2012-06-25  3:46 ` Caspar Zhang
  0 siblings, 1 reply; 2+ messages in thread
From: Caspar Zhang @ 2012-06-25  3:22 UTC (permalink / raw)
  To: hejianet, Wang Sheng-Hui; +Cc: LTP list

[-- Attachment #1: Type: text/plain, Size: 1057 bytes --]


When calculating VMAs, results differ in topdown and bottomup memory
allocation mechanisms. This patch fix the potential failures and should
work like below:

In topdown allocation, the start addr in second VMA should be smaller
than first one, i.e.:

    u======t------(t+3*ps)
      2nd    1st

Thus, in buggy kernel, if we find a VMA mapping entry in child like:

    start_addr == u && end_addr == t+3*ps;

the test would go fail. Otherwise, in good kernel, we should see

    start_addr1 == u && end_addr1 == t;
    start_addr2 == t && end_addr2 == t+3*ps;

While in bottomup allocation, it's different:

    t------u======(t+6*ps)
      1st    2nd

Here in buggy kernel, we can see VMA mapping entry like this:

    start_addr == t && end_addr == t+6*ps;

And in good kernel:

    start_addr1 == t && end_addr1 == u;
    start_addr2 == u && end_addr2 == t+6*ps;

Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
 testcases/kernel/mem/vma/vma01.c |   35 ++++++++++++++++++++++-------------
 1 files changed, 22 insertions(+), 13 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-mm-vma01-consider-topdown-and-bottomup-allocation.patch --]
[-- Type: text/x-patch; name="0001-mm-vma01-consider-topdown-and-bottomup-allocation.patch", Size: 2178 bytes --]

diff --git a/testcases/kernel/mem/vma/vma01.c b/testcases/kernel/mem/vma/vma01.c
index 398d7a1..16ee078 100644
--- a/testcases/kernel/mem/vma/vma01.c
+++ b/testcases/kernel/mem/vma/vma01.c
@@ -59,7 +59,7 @@ char *TCID = "vma01";
 int TST_TOTAL = 1;
 
 static void check_vma(void);
-static void *get_end_addr(void *addr_s, char *mapfile);
+static void *get_end_addr(void *addr_s);
 static void check_status(int status);
 static void setup(void);
 static void cleanup(void);
@@ -90,9 +90,10 @@ int main(int argc, char **argv)
 static void check_vma(void)
 {
 	int status;
-	void *t, *u, *x, *y;
+	int topdown;
+	void *t, *u, *x;
 
-	t = mmap(NULL, 3*ps, PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
+	t = mmap(NULL, 3*ps, PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
 	if (t == MAP_FAILED)
 		tst_brkm(TBROK|TERRNO, cleanup, "mmap");
 	memset(t, 1, ps);
@@ -103,21 +104,29 @@ static void check_vma(void)
 	case 0:
 		memset(t, 2, ps);
 		u = mmap(t + 3*ps, 3*ps, PROT_WRITE,
-			    MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
+			    MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
 		if (u == MAP_FAILED) {
-			perror("mmap failed.\n");
+			perror("mmap");
 			exit(255);
 		}
+		topdown = (u > t) ? 0 : 1;
 		printf("parent: t = %p\n", t);
 		printf("child : u = %p\n", u);
 		memset(u, 2, ps);
 
-		x = get_end_addr(u, MAPS_FILE);
-		if (x == u + 6*ps)
-			exit(1);
-		if (x == u + 3*ps) {
-			y = get_end_addr(x, MAPS_FILE);
-			if (y == x + 3*ps)
+		if (topdown) {
+			x = get_end_addr(u);
+			printf("child : x = %p\n", x);
+			if (x == t + 3*ps)
+				exit(1);
+			else if (x == t && get_end_addr(x) == t + 3*ps)
+				exit(0);
+		} else {
+			x = get_end_addr(t);
+			printf("child : x = %p\n", x);
+			if (x == t + 6*ps)
+				exit(1);
+			else if (x == u && get_end_addr(x) == t + 6*ps)
 				exit(0);
 		}
 		exit(255);
@@ -131,13 +140,13 @@ static void check_vma(void)
 	}
 }
 
-static void *get_end_addr(void *addr_s, char *mapfile)
+static void *get_end_addr(void *addr_s)
 {
 	FILE *fp;
 	void *s, *t;
 	char buf[BUFSIZ];
 
-	fp = fopen(mapfile, "r");
+	fp = fopen(MAPS_FILE, "r");
 	if (fp == NULL)
 		tst_brkm(TBROK|TERRNO, cleanup, "fopen");
 	while (fgets(buf, BUFSIZ, fp) != NULL) {

[-- Attachment #3: Type: text/plain, Size: 395 bytes --]

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH] mm/vma01: consider topdown and bottomup allocation
  2012-06-25  3:22 [LTP] [PATCH] mm/vma01: consider topdown and bottomup allocation Caspar Zhang
@ 2012-06-25  3:46 ` Caspar Zhang
  0 siblings, 0 replies; 2+ messages in thread
From: Caspar Zhang @ 2012-06-25  3:46 UTC (permalink / raw)
  To: hejianet, Wang Sheng-Hui; +Cc: LTP list

On 06/25/2012 11:22 AM, Caspar Zhang wrote:
> 
> When calculating VMAs, results differ in topdown and bottomup memory
> allocation mechanisms. This patch fix the potential failures and should
> work like below:
> 
> In topdown allocation, the start addr in second VMA should be smaller
> than first one, i.e.:
> 
>     u======t------(t+3*ps)
>       2nd    1st
> 
> Thus, in buggy kernel, if we find a VMA mapping entry in child like:
> 
>     start_addr == u && end_addr == t+3*ps;
> 
> the test would go fail. Otherwise, in good kernel, we should see
> 
>     start_addr1 == u && end_addr1 == t;
>     start_addr2 == t && end_addr2 == t+3*ps;
> 
> While in bottomup allocation, it's different:
> 
>     t------u======(t+6*ps)
>       1st    2nd
> 
> Here in buggy kernel, we can see VMA mapping entry like this:
> 
>     start_addr == t && end_addr == t+6*ps;
> 
> And in good kernel:
> 
>     start_addr1 == t && end_addr1 == u;
>     start_addr2 == u && end_addr2 == t+6*ps;
> 
> Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
> ---
>  testcases/kernel/mem/vma/vma01.c |   35 ++++++++++++++++++++++-------------
>  1 files changed, 22 insertions(+), 13 deletions(-)
> 

The patch itself passes my test, yet I give it a self-NAK for now. Needs
one more patch to resolve the issue hejianet brought up.

Caspar

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2012-06-25  3:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-25  3:22 [LTP] [PATCH] mm/vma01: consider topdown and bottomup allocation Caspar Zhang
2012-06-25  3:46 ` Caspar Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox