lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4CCE0EB2.9070302@oss.ntt.co.jp>
Date:	Mon, 01 Nov 2010 09:49:54 +0900
From:	Takuya Yoshikawa <yoshikawa.takuya@....ntt.co.jp>
To:	Jesper Juhl <jj@...osbits.net>
CC:	kvm@...r.kernel.org, Avi Kivity <avi@...hat.com>,
	Avi Kivity <avi@...ranet.com>,
	Marcelo Tosatti <mtosatti@...hat.com>,
	Yaniv Kamay <yaniv@...ranet.com>,
	Amit Shah <amit.shah@...ranet.com>,
	Ben-Ami Yassour <benami@...ibm.com>,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] KVM x86: remove memset, use vzalloc and don't assign
 the same value to a variable twice

(2010/10/31 3:28), Jesper Juhl wrote:
> Hi,
>
> We can improve kvm_vm_ioctl_get_dirty_log() slightly by using vzalloc()
> rather than first allocating and then manually zero the memory with
> memset(). Also, while I was looking at this I noticed that we assign

I personally prefer this new vzalloc() to vmalloc() + memset().

Just from my interest, is there real performance difference not just
the cleanup effect?  If so, we'd better do this for other places too.


> -ENOMEM to the 'r' variable twice even though none of the code inbetween
> the two assignments can change 'r', so I removed the second assignment.
>
> Patch has been compile tested only.
>
> Please consider merging and please CC me on all replies as I'm not
> subscribed to the kvm mailing list.
>
>
> Signed-off-by: Jesper Juhl<jj@...osbits.net>
> ---
>   x86.c |    4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 2288ad8..29f9c0a 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -3174,12 +3174,10 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
>   		spin_unlock(&kvm->mmu_lock);

This patch is not based on kvm.git, I guess.

>
>   		r = -ENOMEM;
> -		dirty_bitmap = vmalloc(n);
> +		dirty_bitmap = vzalloc(n);
>   		if (!dirty_bitmap)
>   			goto out;
> -		memset(dirty_bitmap, 0, n);
>
> -		r = -ENOMEM;

This one is here because this belongs to a different code block from the
previous one.  This keeps it easy to insert another codes in between these
two blocks.  The optimization will be done at compile time.
IIRC, I did like this based on Avi's advise.

   Takuya

>   		slots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL);
>   		if (!slots) {
>   			vfree(dirty_bitmap);
>
>

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ