From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49006) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W0Yue-0005rE-7V for qemu-devel@nongnu.org; Tue, 07 Jan 2014 10:49:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W0YuY-0003LD-89 for qemu-devel@nongnu.org; Tue, 07 Jan 2014 10:49:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:7700) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W0YuY-0003L9-0G for qemu-devel@nongnu.org; Tue, 07 Jan 2014 10:49:46 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s07FnjPj029189 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 7 Jan 2014 10:49:45 -0500 From: Orit Wasserman Date: Tue, 7 Jan 2014 17:50:08 +0200 Message-Id: <1389109808-19681-2-git-send-email-owasserm@redhat.com> In-Reply-To: <1389109808-19681-1-git-send-email-owasserm@redhat.com> References: <1389109808-19681-1-git-send-email-owasserm@redhat.com> Subject: [Qemu-devel] [PATCH 2/2] Add check for cache size smaller than page size List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, Orit Wasserman , quintela@redhat.com Signed-off-by: Orit Wasserman --- 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 5c55c68..e52c9ba 100644 --- a/arch_init.c +++ b/arch_init.c @@ -176,6 +176,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 2b1ab20..f28aa1d 100644 --- a/migration.c +++ b/migration.c @@ -455,6 +455,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) { @@ -463,8 +464,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) -- 1.8.3.1