kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <lvivier@redhat.com>
To: Andrew Jones <drjones@redhat.com>, kvm@vger.kernel.org
Cc: pbonzini@redhat.com, thuth@redhat.com
Subject: Re: [kvm-unit-tests PATCH v2 5/6] x86: lib/alloc: introduce alloc_zeroed_page
Date: Thu, 3 Nov 2016 13:02:03 +0100	[thread overview]
Message-ID: <774fe268-f7a9-813a-dd1e-91b6d2ce5d22@redhat.com> (raw)
In-Reply-To: <1478119966-13252-6-git-send-email-drjones@redhat.com>



On 02/11/2016 21:52, Andrew Jones wrote:
> This allows us to remove a bunch of memsets.
> 
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> ---
>  lib/alloc.c     |  8 ++++++++
>  lib/alloc.h     |  1 +
>  lib/x86/vm.c    |  4 +---
>  x86/vmx.c       | 19 +++++++------------
>  x86/vmx_tests.c | 28 ++++++++++------------------
>  5 files changed, 27 insertions(+), 33 deletions(-)
> 
> diff --git a/lib/alloc.c b/lib/alloc.c
> index ce1198e2977f..d797690cc458 100644
> --- a/lib/alloc.c
> +++ b/lib/alloc.c
> @@ -191,6 +191,14 @@ void *alloc_page(void)
>  	return p;
>  }
>  
> +void *alloc_zeroed_page(void)
> +{
> +	void *p = alloc_page();

alloc_page() can return NULL.

As most of the callers don't check the return value of
alloc_zeroed_page(), I think you should assert() here.


> +	memset(p, 0, PAGE_SIZE);
> +	return p;
> +}
> +
>  void free_page(void *page)
>  {
>  	spin_lock(&heap_lock);
> diff --git a/lib/alloc.h b/lib/alloc.h
> index a37330b3088a..f61a5200c829 100644
> --- a/lib/alloc.h
> +++ b/lib/alloc.h
> @@ -126,6 +126,7 @@ extern void phys_alloc_show(void);
>   */
>  extern void heap_init(void *start, size_t size);
>  extern void *alloc_page(void);
> +extern void *alloc_zeroed_page(void);
>  extern void free_page(void *page);
>  
>  #endif /* _ALLOC_H_ */
> diff --git a/lib/x86/vm.c b/lib/x86/vm.c
> index 4e399f80dd31..8b95104ef80f 100644
> --- a/lib/x86/vm.c
> +++ b/lib/x86/vm.c
> @@ -91,9 +91,7 @@ static void setup_mmu_range(unsigned long *cr3, unsigned long start,
>  
>  static void setup_mmu(unsigned long len)
>  {
> -    unsigned long *cr3 = alloc_page();
> -
> -    memset(cr3, 0, PAGE_SIZE);
> +    unsigned long *cr3 = alloc_zeroed_page();
>  
>  #ifdef __x86_64__
>      if (len < (1ul << 32))
> diff --git a/x86/vmx.c b/x86/vmx.c
> index 411ed3211d4d..5d333e077a02 100644
> --- a/x86/vmx.c
> +++ b/x86/vmx.c
> @@ -29,6 +29,7 @@
>   */
>  
>  #include "libcflat.h"
> +#include "alloc.h"
>  #include "processor.h"
>  #include "vm.h"
>  #include "desc.h"
> @@ -276,9 +277,8 @@ static void split_large_ept_entry(unsigned long *ptep, int level)
>  	assert(pte & EPT_LARGE_PAGE);
>  	assert(level == 2 || level == 3);
>  
> -	new_pt = alloc_page();
> +	new_pt = alloc_zeroed_page();
>  	assert(new_pt);

If alloc_zeroed_page() uses assert(), this one is useless, otherwise add
the same to all the other calls of alloc_zeroed_page() below.

> -	memset(new_pt, 0, PAGE_SIZE);
>  
>  	prototype = pte & ~EPT_ADDR_MASK;
>  	if (level == 2)
> @@ -617,8 +617,7 @@ static void init_vmcs_guest(void)
...

Thanks,
Laurent

  reply	other threads:[~2016-11-03 12:02 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-02 20:52 [kvm-unit-tests PATCH v2 0/6] x86: enable malloc and friends Andrew Jones
2016-11-02 20:52 ` [kvm-unit-tests PATCH v2 1/6] lib/x86/vm: collection of improvements Andrew Jones
2016-11-03  9:40   ` Laurent Vivier
2016-11-03 10:42     ` Andrew Jones
2016-11-02 20:52 ` [kvm-unit-tests PATCH v2 2/6] lib/alloc: improve init Andrew Jones
2016-11-03 10:57   ` Laurent Vivier
2016-11-02 20:52 ` [kvm-unit-tests PATCH v2 3/6] lib/alloc: prepare to extend alloc.c's purpose Andrew Jones
2016-11-03 12:30   ` Laurent Vivier
2016-11-02 20:52 ` [kvm-unit-tests PATCH v2 4/6] x86: lib/alloc: move heap management to lib Andrew Jones
2016-11-03 13:28   ` Laurent Vivier
2016-11-03 13:38     ` Andrew Jones
2016-11-03 17:21   ` Paolo Bonzini
2016-11-03 17:53     ` Andrew Jones
2016-11-02 20:52 ` [kvm-unit-tests PATCH v2 5/6] x86: lib/alloc: introduce alloc_zeroed_page Andrew Jones
2016-11-03 12:02   ` Laurent Vivier [this message]
2016-11-03 12:47     ` Andrew Jones
2016-11-03 13:03       ` Laurent Vivier
2016-11-02 20:52 ` [kvm-unit-tests PATCH v2 6/6] lib/x86/vm: enable malloc and friends Andrew Jones
2016-11-03 14:12   ` Paolo Bonzini
2016-11-03 14:58     ` Andrew Jones
2016-11-03 16:00       ` Paolo Bonzini
2016-11-03 16:51         ` Andrew Jones
2016-11-03 17:34           ` Paolo Bonzini
2016-11-03 18:12             ` Andrew Jones
2016-11-03 18:20               ` Paolo Bonzini
2016-11-03 18:42                 ` Andrew Jones
2016-11-03 19:19                   ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=774fe268-f7a9-813a-dd1e-91b6d2ce5d22@redhat.com \
    --to=lvivier@redhat.com \
    --cc=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).