diff mbox series

[kvm-unit-tests,v2,1/4] lib/alloc_page: Zero allocated pages

Message ID 20190503103207.9021-2-nadav.amit@gmail.com (mailing list archive)
State New, archived
Headers show
Series Zero allocated pages | expand

Commit Message

Nadav Amit May 3, 2019, 10:32 a.m. UTC
From: Nadav Amit <nadav.amit@gmail.com>

One of the most important properties of tests is reproducibility. For
tests to be reproducible, the same environment should be set on each
test invocation.

When it comes to memory content, this is not exactly the case in
kvm-unit-tests. The tests might, mistakenly or intentionally, assume
that memory is zeroed (by the BIOS or KVM).  However, failures might not
be reproducible if this assumption is broken.

As an example, consider x86 do_iret(), which mistakenly does not push
SS:RSP onto the stack on 64-bit mode, although they are popped
unconditionally on iret.

Do not assume that memory is zeroed. Clear it once it is allocated to
allow tests to easily be reproduced.

Signed-off-by: Nadav Amit <nadav.amit@gmail.com>
---
 lib/alloc_page.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Krish Sadhukhan May 3, 2019, 7:10 p.m. UTC | #1
On 05/03/2019 03:32 AM, nadav.amit@gmail.com wrote:
> From: Nadav Amit <nadav.amit@gmail.com>
>
> One of the most important properties of tests is reproducibility. For
> tests to be reproducible, the same environment should be set on each
> test invocation.
>
> When it comes to memory content, this is not exactly the case in
> kvm-unit-tests. The tests might, mistakenly or intentionally, assume
> that memory is zeroed (by the BIOS or KVM).  However, failures might not
> be reproducible if this assumption is broken.
>
> As an example, consider x86 do_iret(), which mistakenly does not push
> SS:RSP onto the stack on 64-bit mode, although they are popped
> unconditionally on iret.
>
> Do not assume that memory is zeroed. Clear it once it is allocated to
> allow tests to easily be reproduced.
>
> Signed-off-by: Nadav Amit <nadav.amit@gmail.com>
> ---
>   lib/alloc_page.c | 4 ++++
>   1 file changed, 4 insertions(+)
>
> diff --git a/lib/alloc_page.c b/lib/alloc_page.c
> index 730f2b5..97d1339 100644
> --- a/lib/alloc_page.c
> +++ b/lib/alloc_page.c
> @@ -65,6 +65,8 @@ void *alloc_page()
>   	freelist = *(void **)freelist;
>   	spin_unlock(&lock);
>   
> +	if (p)
> +		memset(p, 0, PAGE_SIZE);
>   	return p;
>   }
>   
> @@ -126,6 +128,8 @@ void *alloc_pages(unsigned long order)
>   		}
>   	}
>   	spin_unlock(&lock);
> +	if (run_start)
> +		memset(run_start, 0, n * PAGE_SIZE);
>   	return run_start;
>   }
>   

Reviewed-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
diff mbox series

Patch

diff --git a/lib/alloc_page.c b/lib/alloc_page.c
index 730f2b5..97d1339 100644
--- a/lib/alloc_page.c
+++ b/lib/alloc_page.c
@@ -65,6 +65,8 @@  void *alloc_page()
 	freelist = *(void **)freelist;
 	spin_unlock(&lock);
 
+	if (p)
+		memset(p, 0, PAGE_SIZE);
 	return p;
 }
 
@@ -126,6 +128,8 @@  void *alloc_pages(unsigned long order)
 		}
 	}
 	spin_unlock(&lock);
+	if (run_start)
+		memset(run_start, 0, n * PAGE_SIZE);
 	return run_start;
 }