From patchwork Sat Jul 2 03:06:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 939982 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p62393qu028321 for ; Sat, 2 Jul 2011 03:09:03 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752252Ab1GBDIb (ORCPT ); Fri, 1 Jul 2011 23:08:31 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:62047 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751833Ab1GBDIa (ORCPT ); Fri, 1 Jul 2011 23:08:30 -0400 Received: by wwe5 with SMTP id 5so3718937wwe.1 for ; Fri, 01 Jul 2011 20:08:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; bh=O+oXuC56gXiyJmfn/mE6jcIQUrbvEwTk09+Khsk7bwQ=; b=WKblOa3xqEL8qo2kY+YKpXCibsPJwDj037HD9qGj6RdQ0niLa1PpKf+YQO1wko5n90 KXVpiiDEqlpt1phB0RkfiyjMrrx2VcM0PHdu11qauBB6LP15MfGk5/Xt/FmrayZbGcXq YbWK4j7jFhPHk0UEjSNHpf/mrYHllYvSfuaTI= Received: by 10.227.160.140 with SMTP id n12mr3389857wbx.69.1309576109339; Fri, 01 Jul 2011 20:08:29 -0700 (PDT) Received: from localhost.localdomain ([31.210.184.221]) by mx.google.com with ESMTPS id ge4sm2743018wbb.64.2011.07.01.20.08.27 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 01 Jul 2011 20:08:28 -0700 (PDT) From: Sasha Levin To: linux-kernel@vger.kernel.org Cc: Sasha Levin , Rusty Russell , "Michael S. Tsirkin" , virtualization@lists.linux-foundation.org, kvm@vger.kernel.org Subject: [PATCH] virtio_balloon: Notify guest only after deflating the balloon Date: Sat, 2 Jul 2011 06:06:56 +0300 Message-Id: <1309576016-22800-1-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.6 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Sat, 02 Jul 2011 03:09:03 +0000 (UTC) Unless the host requires that requested pages won't be used until he us notified (VIRTIO_BALLOON_F_MUST_TELL_HOST), only notify after deflating the balloon. This will avoid having to take an exit before actually using the pages. Cc: Rusty Russell Cc: "Michael S. Tsirkin" Cc: virtualization@lists.linux-foundation.org Cc: kvm@vger.kernel.org Signed-off-by: Sasha Levin --- drivers/virtio/virtio_balloon.c | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index e058ace..055f95d 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -148,14 +148,18 @@ static void leak_balloon(struct virtio_balloon *vb, size_t num) vb->num_pages--; } - /* - * Note that if - * virtio_has_feature(vdev, VIRTIO_BALLOON_F_MUST_TELL_HOST); - * is true, we *have* to do it in this order + * If the host doesn't require us to notify him before using + * pages which belong to the balloon, update him only after + * freeing those pages for guest use. */ - tell_host(vb, vb->deflate_vq); - release_pages_by_pfn(vb->pfns, vb->num_pfns); + if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_MUST_TELL_HOST)) { + tell_host(vb, vb->deflate_vq); + release_pages_by_pfn(vb->pfns, vb->num_pfns); + } else { + release_pages_by_pfn(vb->pfns, vb->num_pfns); + tell_host(vb, vb->deflate_vq); + } } static inline void update_stat(struct virtio_balloon *vb, int idx,