mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: KY Srinivasan <kys@microsoft.com>
To: Dexuan Cui <decui@microsoft.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"driverdev-devel@linuxdriverproject.org" 
	<driverdev-devel@linuxdriverproject.org>,
	"olaf@aepfle.de" <olaf@aepfle.de>,
	"apw@canonical.com" <apw@canonical.com>,
	"jasowang@redhat.com" <jasowang@redhat.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Subject: RE: [PATCH v2] hv: hv_balloon: avoid memory leak on alloc_error of 2MB memory block
Date: Tue, 25 Nov 2014 05:10:33 +0000	[thread overview]
Message-ID: <BY2PR0301MB07118588B302F59904455F15A0730@BY2PR0301MB0711.namprd03.prod.outlook.com> (raw)
In-Reply-To: <1416889963-31602-1-git-send-email-decui@microsoft.com>



> -----Original Message-----
> From: Dexuan Cui [mailto:decui@microsoft.com]
> Sent: Monday, November 24, 2014 8:33 PM
> To: gregkh@linuxfoundation.org; linux-kernel@vger.kernel.org; driverdev-
> devel@linuxdriverproject.org; olaf@aepfle.de; apw@canonical.com;
> jasowang@redhat.com; KY Srinivasan
> Cc: Haiyang Zhang
> Subject: [PATCH v2] hv: hv_balloon: avoid memory leak on alloc_error of
> 2MB memory block
> 
> If num_ballooned is not 0, we shouldn't neglect the already-partially-
> allocated 2MB memory block(s).
> 
> Cc: Jason Wang <jasowang@redhat.com>
> Cc: K. Y. Srinivasan <kys@microsoft.com>
> Signed-off-by: Dexuan Cui <decui@microsoft.com>

Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
> ---
> 
> v2: I fixed the logic error in v1, pointed by Jason Wang:
> 	In v1: in the case of partially-allocated 2MB, alloc_error is true,
> 	so we'll run "done = true" and hence we won't proceed with
> 	the next iteration of trying 4K allocation.
> 
>     I also changed the WARN_ON to WARN_ON_ONCE in case the host
> behavior
>     changes in the future.
> 
>  drivers/hv/hv_balloon.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index
> 5e90c5d..b958ded 100644
> --- a/drivers/hv/hv_balloon.c
> +++ b/drivers/hv/hv_balloon.c
> @@ -1087,10 +1087,12 @@ static void balloon_up(struct work_struct
> *dummy)
>  	struct dm_balloon_response *bl_resp;
>  	int alloc_unit;
>  	int ret;
> -	bool alloc_error = false;
> +	bool alloc_error;
>  	bool done = false;
>  	int i;
> 
> +	/* The host balloons pages in 2M granularity. */
> +	WARN_ON_ONCE(num_pages % PAGES_IN_2M != 0);
> 
>  	/*
>  	 * We will attempt 2M allocations. However, if we fail to @@ -1107,16
> +1109,18 @@ static void balloon_up(struct work_struct *dummy)
> 
> 
>  		num_pages -= num_ballooned;
> +		alloc_error = false;
>  		num_ballooned = alloc_balloon_pages(&dm_device,
> num_pages,
>  						bl_resp, alloc_unit,
>  						 &alloc_error);
> 
> -		if ((alloc_error) && (alloc_unit != 1)) {
> +		if (alloc_unit != 1 && num_ballooned == 0) {
>  			alloc_unit = 1;
>  			continue;
>  		}
> 
> -		if ((alloc_error) || (num_ballooned == num_pages)) {
> +		if ((alloc_unit == 1 && alloc_error) ||
> +			(num_ballooned == num_pages)) {
>  			bl_resp->more_pages = 0;
>  			done = true;
>  			dm_device.state = DM_INITIALIZED;
> --
> 1.9.1


      parent reply	other threads:[~2014-11-25  5:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-25  4:32 Dexuan Cui
2014-11-25  3:31 ` Jason Wang
2014-11-25  5:10 ` KY Srinivasan [this message]

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=BY2PR0301MB07118588B302F59904455F15A0730@BY2PR0301MB0711.namprd03.prod.outlook.com \
    --to=kys@microsoft.com \
    --cc=apw@canonical.com \
    --cc=decui@microsoft.com \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=haiyangz@microsoft.com \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olaf@aepfle.de \
    /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

all inboxes | Powered by JetHome®