From patchwork Thu Jan 30 07:14:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orit Wasserman X-Patchwork-Id: 315274 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 809E42C00AC for ; Thu, 30 Jan 2014 18:16:46 +1100 (EST) Received: from localhost ([::1]:46754 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W8lrg-00048l-10 for incoming@patchwork.ozlabs.org; Thu, 30 Jan 2014 02:16:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W8lp4-0008W5-G1 for qemu-devel@nongnu.org; Thu, 30 Jan 2014 02:14:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W8lox-0003eC-PZ for qemu-devel@nongnu.org; Thu, 30 Jan 2014 02:14:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:5017) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W8lox-0003e7-I0 for qemu-devel@nongnu.org; Thu, 30 Jan 2014 02:13:55 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0U7DqQV011711 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 30 Jan 2014 02:13:52 -0500 Received: from dhcp-1-120.tlv.redhat.com (ovpn-116-40.ams2.redhat.com [10.36.116.40]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s0U7DhZo011122; Thu, 30 Jan 2014 02:13:50 -0500 From: Orit Wasserman To: qemu-devel@nongnu.org Date: Thu, 30 Jan 2014 09:14:11 +0200 Message-Id: <1391066055-17024-3-git-send-email-owasserm@redhat.com> In-Reply-To: <1391066055-17024-1-git-send-email-owasserm@redhat.com> References: <1391066055-17024-1-git-send-email-owasserm@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: peter.maydell@linaro.org, Orit Wasserman , anthony@codemonkey.ws, quintela@redhat.com Subject: [Qemu-devel] [PATCH 2/6] Add check for cache size smaller than page size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Orit Wasserman Reviewed-by: Juan Quintela --- arch_init.c | 4 ++++ migration.c | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/arch_init.c b/arch_init.c index 66f5e82..8edeabe 100644 --- a/arch_init.c +++ b/arch_init.c @@ -178,6 +178,10 @@ static struct { int64_t xbzrle_cache_resize(int64_t new_size) { + if (new_size < TARGET_PAGE_SIZE) { + return -1; + } + if (XBZRLE.cache != NULL) { return cache_resize(XBZRLE.cache, new_size / TARGET_PAGE_SIZE) * TARGET_PAGE_SIZE; diff --git a/migration.c b/migration.c index 7235c23..84587e9 100644 --- a/migration.c +++ b/migration.c @@ -469,6 +469,7 @@ void qmp_migrate_cancel(Error **errp) void qmp_migrate_set_cache_size(int64_t value, Error **errp) { MigrationState *s = migrate_get_current(); + int64_t new_size; /* Check for truncation */ if (value != (size_t)value) { @@ -477,7 +478,14 @@ void qmp_migrate_set_cache_size(int64_t value, Error **errp) return; } - s->xbzrle_cache_size = xbzrle_cache_resize(value); + new_size = xbzrle_cache_resize(value); + if (new_size < 0) { + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cache size", + "is smaller than page size"); + return; + } + + s->xbzrle_cache_size = new_size; } int64_t qmp_query_migrate_cache_size(Error **errp)