From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WAl05-0004fi-Cb for qemu-devel@nongnu.org; Tue, 04 Feb 2014 13:45:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WAkzy-0006xu-1n for qemu-devel@nongnu.org; Tue, 04 Feb 2014 13:45:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:22631) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WAiLl-0002tb-DO for qemu-devel@nongnu.org; Tue, 04 Feb 2014 10:55:49 -0500 From: Juan Quintela Date: Tue, 4 Feb 2014 16:55:30 +0100 Message-Id: <1391529334-30526-5-git-send-email-quintela@redhat.com> In-Reply-To: <1391529334-30526-1-git-send-email-quintela@redhat.com> References: <1391529334-30526-1-git-send-email-quintela@redhat.com> Subject: [Qemu-devel] [PATCH 4/8] 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: peter.maydell@linaro.org, anthony@codemonkey.ws, Orit Wasserman From: Orit Wasserman Signed-off-by: Orit Wasserman Reviewed-by: Juan Quintela Signed-off-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) -- 1.8.5.3