Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: walimis <walimisdev@gmail.com>
To: Sasha Levin <levinsasha928@gmail.com>
Cc: Pekka Enberg <penberg@kernel.org>, Ingo Molnar <mingo@elte.hu>,
	Asias He <asias.hejun@gmail.com>,
	kvm@vger.kernel.org
Subject: Re: [PATCH 2/3] kvm tools: check negative value of num_pages
Date: Thu, 11 Aug 2011 13:40:37 +0800	[thread overview]
Message-ID: <20110811054037.GB13190@walimis-desktop> (raw)
In-Reply-To: <1313041021.10059.9.camel@lappy>

On Thu, Aug 11, 2011 at 08:37:01AM +0300, Sasha Levin wrote:
>On Thu, 2011-08-11 at 13:07 +0800, Liming Wang wrote:
>> If num_pages is negative, balloon will make kernel crash with
>> "out of memory". So we check this value to avoid it to be negative.
>> 
>> Signed-off-by: Liming Wang <walimisdev@gmail.com>
>> ---
>>  tools/kvm/virtio/balloon.c |    7 ++++++-
>>  1 files changed, 6 insertions(+), 1 deletions(-)
>> 
>> diff --git a/tools/kvm/virtio/balloon.c b/tools/kvm/virtio/balloon.c
>> index 854d04b..0223ee4 100644
>> --- a/tools/kvm/virtio/balloon.c
>> +++ b/tools/kvm/virtio/balloon.c
>> @@ -222,8 +222,13 @@ static void handle_sigmem(int sig)
>>  {
>>  	if (sig == SIGKVMADDMEM)
>>  		bdev.config.num_pages += 256;
>> -	else
>> +	else {
>>  		bdev.config.num_pages -= 256;
>> +		if ((s32)bdev.config.num_pages < 0){
>
>imo it's worth doing this check before the decrement instead of casting
>to signed here.
You mean that check whether num_pages less than 256 or equal to 0?

>
>you also need to wrap the 'if ()' with parenthesis if you add them to
>the 'else' case.
Sorry, I'm not clear what that does mean?

walimis
>
>> +			bdev.config.num_pages = 0;
>> +			return;
>> +		}
>> +	}
>>  
>>  	/* Notify that the configuration space has changed */
>>  	bdev.isr = VIRTIO_PCI_ISR_CONFIG;
>
>-- 
>
>Sasha.
>

  reply	other threads:[~2011-08-11  5:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-11  5:07 [PATCH 1/3] kvm tools: add signal placeholder to avoid balloon crash Liming Wang
2011-08-11  5:07 ` [PATCH 2/3] kvm tools: check negative value of num_pages Liming Wang
2011-08-11  5:37   ` Sasha Levin
2011-08-11  5:40     ` walimis [this message]
2011-08-11  7:22       ` Sasha Levin
2011-08-11  7:21         ` Liming Wang
2011-08-11 13:36           ` Pekka Enberg
2011-08-11 13:37             ` walimis
2011-08-11  5:07 ` [PATCH 3/3] kvm tools: enable keyboard press repeat for sdl Liming Wang
2011-08-11  7:29 ` [PATCH 1/3] kvm tools: add signal placeholder to avoid balloon crash Sasha Levin
2011-08-11  7:21   ` walimis
2011-08-11  7:28   ` [PATCH 1/3] kvm tools: ignore balloon signals by default " Liming Wang

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=20110811054037.GB13190@walimis-desktop \
    --to=walimisdev@gmail.com \
    --cc=asias.hejun@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=levinsasha928@gmail.com \
    --cc=mingo@elte.hu \
    --cc=penberg@kernel.org \
    /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