qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, quintela@redhat.com
Subject: Re: [PATCH 4/6] migration: Check xbzrle-cache-size more carefully
Date: Fri, 13 Nov 2020 10:59:40 +0000	[thread overview]
Message-ID: <20201113105940.GC3251@work-vm> (raw)
In-Reply-To: <20201113065236.2644169-5-armbru@redhat.com>

* Markus Armbruster (armbru@redhat.com) wrote:
> migrate-set-parameters passes the size to xbzrle_cache_resize().
> xbzrle_cache_resize() checks it fits into size_t before it passes it
> on to cache_init().  cache_init() checks it is a power of two no
> smaller than @page_size.
> 
> cache_init() is also called from xbzrle_init(), bypassing
> xbzrle_cache_resize()'s check.
> 
> Drop xbzrle_cache_resize()'s check, and check more carefully in
> cache_init().
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  migration/page_cache.c | 15 ++++-----------
>  migration/ram.c        |  7 -------
>  2 files changed, 4 insertions(+), 18 deletions(-)
> 
> diff --git a/migration/page_cache.c b/migration/page_cache.c
> index b384f265fb..e07f4ad1dc 100644
> --- a/migration/page_cache.c
> +++ b/migration/page_cache.c
> @@ -41,17 +41,10 @@ struct PageCache {
>  PageCache *cache_init(uint64_t new_size, size_t page_size, Error **errp)
>  {
>      int64_t i;
> -    size_t num_pages = new_size / page_size;
> +    uint64_t num_pages = new_size / page_size;
>      PageCache *cache;
>  
> -    if (new_size < page_size) {
> -        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
> -                   "is smaller than one target page size");
> -        return NULL;
> -    }
> -
> -    /* round down to the nearest power of 2 */
> -    if (!is_power_of_2(num_pages)) {
> +    if (num_pages != (size_t)num_pages || !is_power_of_2(num_pages)) {
>          error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
>                     "is not a power of two number of pages");

That error message is now wrong since it includes a whole bunch of
reasons.
Also, the comparison is now on the divided num_pages, it's not that
obvious to me that checking the num_pages makes sense in acomparison to
checking the actual cache size.

(Arguably the check should also happen in migrate_params_test_apply)

Dave

>          return NULL;
> @@ -71,8 +64,8 @@ PageCache *cache_init(uint64_t new_size, size_t page_size, Error **errp)
>      trace_migration_pagecache_init(cache->max_num_items);
>  
>      /* We prefer not to abort if there is no memory */
> -    cache->page_cache = g_try_malloc((cache->max_num_items) *
> -                                     sizeof(*cache->page_cache));
> +    cache->page_cache = g_try_malloc_n(cache->max_num_items,
> +                                       sizeof(*cache->page_cache));
>      if (!cache->page_cache) {
>          error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
>                     "Failed to allocate page cache");
> diff --git a/migration/ram.c b/migration/ram.c
> index a84425d04f..d632ae694c 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -131,13 +131,6 @@ int xbzrle_cache_resize(uint64_t new_size, Error **errp)
>      PageCache *new_cache;
>      int64_t ret = 0;
>  
> -    /* Check for truncation */
> -    if (new_size != (size_t)new_size) {
> -        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
> -                   "exceeding address space");
> -        return -1;
> -    }
> -
>      if (new_size == migrate_xbzrle_cache_size()) {
>          /* nothing to do */
>          return 0;
> -- 
> 2.26.2
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



  reply	other threads:[~2020-11-13 11:00 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-13  6:52 [PATCH 0/6] migration: Fixes and cleanups aroung migrate-set-parameters Markus Armbruster
2020-11-13  6:52 ` [PATCH 1/6] migration: Fix and clean up around @tls-authz Markus Armbruster
2020-11-13 11:56   ` Dr. David Alan Gilbert
2020-12-10 17:35     ` Dr. David Alan Gilbert
2020-12-10 18:10   ` Daniel P. Berrangé
2020-12-14 10:14     ` Markus Armbruster
2020-12-16 10:55       ` Daniel P. Berrangé
2020-12-17 13:07         ` Markus Armbruster
2020-12-17 14:04           ` Daniel P. Berrangé
2021-01-27 16:01             ` Markus Armbruster
2020-11-13  6:52 ` [PATCH 2/6] migration: Fix migrate-set-parameters argument validation Markus Armbruster
2020-11-13 11:49   ` Dr. David Alan Gilbert
2020-11-13 13:24     ` Markus Armbruster
2020-11-13  6:52 ` [PATCH 3/6] migration: Clean up signed vs. unsigned XBZRLE cache-size Markus Armbruster
2020-11-13 10:40   ` Dr. David Alan Gilbert
2020-11-13  6:52 ` [PATCH 4/6] migration: Check xbzrle-cache-size more carefully Markus Armbruster
2020-11-13 10:59   ` Dr. David Alan Gilbert [this message]
2020-11-13 13:35     ` Markus Armbruster
2020-11-13 16:39       ` Dr. David Alan Gilbert
2020-11-16  7:00         ` Markus Armbruster
2020-11-13  6:52 ` [PATCH 5/6] migration: Fix cache_init()'s "Failed to allocate" error messages Markus Armbruster
2020-11-13 11:01   ` Dr. David Alan Gilbert
2020-11-13  6:52 ` [PATCH 6/6] migration: Fix a few absurdly defective " Markus Armbruster
2020-11-13 11:27   ` Dr. David Alan Gilbert
2020-11-13 11:56 ` [PATCH 0/6] migration: Fixes and cleanups aroung migrate-set-parameters Dr. David Alan Gilbert

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=20201113105940.GC3251@work-vm \
    --to=dgilbert@redhat.com \
    --cc=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).