From nobody Thu May 2 02:34:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501149006712307.5587158877231; Thu, 27 Jul 2017 02:50:06 -0700 (PDT) Received: from localhost ([::1]:42021 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dafQj-0006Lr-D4 for importer@patchew.org; Thu, 27 Jul 2017 05:50:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dafN8-00038w-Hr for qemu-devel@nongnu.org; Thu, 27 Jul 2017 05:46:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dafN5-0001DL-Vj for qemu-devel@nongnu.org; Thu, 27 Jul 2017 05:46:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42686) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dafN5-0001Cx-Mq for qemu-devel@nongnu.org; Thu, 27 Jul 2017 05:46:19 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A5A76C0BFD17 for ; Thu, 27 Jul 2017 09:46:18 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-94.ams2.redhat.com [10.36.116.94]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EB60A6E8D7; Thu, 27 Jul 2017 09:46:17 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 58EDC113864B; Thu, 27 Jul 2017 11:46:16 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A5A76C0BFD17 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=armbru@redhat.com From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 27 Jul 2017 11:46:14 +0200 Message-Id: <1501148776-16890-2-git-send-email-armbru@redhat.com> In-Reply-To: <1501148776-16890-1-git-send-email-armbru@redhat.com> References: <1501148776-16890-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 27 Jul 2017 09:46:18 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/3] xbzrle: Drop unused cache_resize() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Dr. David Alan Gilbert" , Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Unused since commit fd8cec XBZRLE: Fix qemu crash when resize the xbzrle cache. Cc: Juan Quintela Cc: "Dr. David Alan Gilbert" Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Eric Blake Reviewed-by: Amit Shah Signed-off-by: Markus Armbruster Reviewed-by: Juan Quintela --- migration/page_cache.c | 56 ----------------------------------------------= ---- migration/page_cache.h | 11 ---------- 2 files changed, 67 deletions(-) diff --git a/migration/page_cache.c b/migration/page_cache.c index 5f85787..ba984c4 100644 --- a/migration/page_cache.c +++ b/migration/page_cache.c @@ -178,59 +178,3 @@ int cache_insert(PageCache *cache, uint64_t addr, cons= t uint8_t *pdata, =20 return 0; } - -int64_t cache_resize(PageCache *cache, int64_t new_num_pages) -{ - PageCache *new_cache; - int64_t i; - - CacheItem *old_it, *new_it; - - g_assert(cache); - - /* cache was not inited */ - if (cache->page_cache =3D=3D NULL) { - return -1; - } - - /* same size */ - if (pow2floor(new_num_pages) =3D=3D cache->max_num_items) { - return cache->max_num_items; - } - - new_cache =3D cache_init(new_num_pages, cache->page_size); - if (!(new_cache)) { - DPRINTF("Error creating new cache\n"); - return -1; - } - - /* move all data from old cache */ - for (i =3D 0; i < cache->max_num_items; i++) { - old_it =3D &cache->page_cache[i]; - if (old_it->it_addr !=3D -1) { - /* check for collision, if there is, keep MRU page */ - new_it =3D cache_get_by_addr(new_cache, old_it->it_addr); - if (new_it->it_data && new_it->it_age >=3D old_it->it_age) { - /* keep the MRU page */ - g_free(old_it->it_data); - } else { - if (!new_it->it_data) { - new_cache->num_items++; - } - g_free(new_it->it_data); - new_it->it_data =3D old_it->it_data; - new_it->it_age =3D old_it->it_age; - new_it->it_addr =3D old_it->it_addr; - } - } - } - - g_free(cache->page_cache); - cache->page_cache =3D new_cache->page_cache; - cache->max_num_items =3D new_cache->max_num_items; - cache->num_items =3D new_cache->num_items; - - g_free(new_cache); - - return cache->max_num_items; -} diff --git a/migration/page_cache.h b/migration/page_cache.h index 10ed532..4fadd0c 100644 --- a/migration/page_cache.h +++ b/migration/page_cache.h @@ -72,15 +72,4 @@ uint8_t *get_cached_data(const PageCache *cache, uint64_= t addr); int cache_insert(PageCache *cache, uint64_t addr, const uint8_t *pdata, uint64_t current_age); =20 -/** - * cache_resize: resize the page cache. In case of size reduction the extra - * pages will be freed - * - * Returns -1 on error new cache size on success - * - * @cache pointer to the PageCache struct - * @num_pages: new page cache size (in pages) - */ -int64_t cache_resize(PageCache *cache, int64_t num_pages); - #endif --=20 2.7.5 From nobody Thu May 2 02:34:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501148985402726.1071846915011; Thu, 27 Jul 2017 02:49:45 -0700 (PDT) Received: from localhost ([::1]:42019 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dafQO-00068o-0d for importer@patchew.org; Thu, 27 Jul 2017 05:49:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54565) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dafN8-00038x-I1 for qemu-devel@nongnu.org; Thu, 27 Jul 2017 05:46:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dafN6-0001Da-FQ for qemu-devel@nongnu.org; Thu, 27 Jul 2017 05:46:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34984) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dafN6-0001D9-6r for qemu-devel@nongnu.org; Thu, 27 Jul 2017 05:46:20 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F1E5ADF155; Thu, 27 Jul 2017 09:46:18 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-94.ams2.redhat.com [10.36.116.94]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EACE162667; Thu, 27 Jul 2017 09:46:17 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5C30A113864E; Thu, 27 Jul 2017 11:46:16 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F1E5ADF155 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=armbru@redhat.com From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 27 Jul 2017 11:46:15 +0200 Message-Id: <1501148776-16890-3-git-send-email-armbru@redhat.com> In-Reply-To: <1501148776-16890-1-git-send-email-armbru@redhat.com> References: <1501148776-16890-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 27 Jul 2017 09:46:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/3] host-utils: Proactively fix pow2floor(), switch to unsigned X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kardashevskiy , Peter Maydell , "Dr . David Alan Gilbert" , Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The function's stated contract is simple enough: "round down to the nearest power of 2". Suggests the domain is the representable numbers >=3D 1, because that's the smallest power of two. The implementation doesn't check for domain errors, but returns garbage instead: * For negative arguments, pow2floor() returns -2^63, which is not even a power of two, let alone the nearest one. What sort of works is passing *unsigned* arguments >=3D 2^63. The implicit conversion to signed is implementation defined, but commonly yields the (negative) two's complement. pow2floor() then returns -2^63. Callers that convert that back to unsigned get the correct value 2^63. * For a zero argument, pow2floor() shifts right by 64. Undefined behavior. Common actual behavior is to shift by 0, yielding -2^63. Fix by switching from int64_t to uint64_t and amending the contract to map zero to zero. Callers are fine with that: * memory_access_size() This function makes no sense unless the argument is positive and the return value fits into int. * raw_refresh_limits() Passes an int between 1 and BDRV_REQUEST_MAX_BYTES. * iscsi_refresh_limits() Passes an integer between 0 and INT_MAX, converts the result to uint32_t. Passing zero would be undefined behavior, but commonly yield zero. The patch gives us the zero without the undefined behavior. * cache_init() Passes a positive int64_t argument. * xbzrle_cache_resize() Passes a positive int64_t argument (>=3D TARGET_PAGE_SIZE, actually). * spapr_node0_size() Passes a positive uint64_t argument, and converts the result to hwaddr, i.e. uint64_t. * spapr_populate_memory() Passes a positive hwaddr argument, and converts the result to hwaddr. Cc: Juan Quintela Cc: Dr. David Alan Gilbert Cc: Eric Blake Cc: Peter Maydell Cc: Alexey Kardashevskiy Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qemu/host-utils.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h index 95cf4f4..6c6005f 100644 --- a/include/qemu/host-utils.h +++ b/include/qemu/host-utils.h @@ -369,13 +369,16 @@ static inline bool is_power_of_2(uint64_t value) return !(value & (value - 1)); } =20 -/* round down to the nearest power of 2*/ -static inline int64_t pow2floor(int64_t value) +/** + * Return @value rounded down to the nearest power of two or zero. + */ +static inline uint64_t pow2floor(uint64_t value) { - if (!is_power_of_2(value)) { - value =3D 0x8000000000000000ULL >> clz64(value); + if (!value) { + /* Avoid undefined shift by 64 */ + return 0; } - return value; + return 0x8000000000000000ull >> clz64(value); } =20 /* round up to the nearest power of 2 (0 if overflow) */ --=20 2.7.5 From nobody Thu May 2 02:34:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501148884313878.367755492299; Thu, 27 Jul 2017 02:48:04 -0700 (PDT) Received: from localhost ([::1]:42010 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dafOj-00040V-F7 for importer@patchew.org; Thu, 27 Jul 2017 05:48:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dafN8-00038y-IB for qemu-devel@nongnu.org; Thu, 27 Jul 2017 05:46:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dafN5-0001DC-Jh for qemu-devel@nongnu.org; Thu, 27 Jul 2017 05:46:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42660) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dafN5-0001Cq-Dw for qemu-devel@nongnu.org; Thu, 27 Jul 2017 05:46:19 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51201C00F7D9 for ; Thu, 27 Jul 2017 09:46:18 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-94.ams2.redhat.com [10.36.116.94]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EDB2B60BE3; Thu, 27 Jul 2017 09:46:17 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5ECC3113864F; Thu, 27 Jul 2017 11:46:16 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 51201C00F7D9 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=armbru@redhat.com From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 27 Jul 2017 11:46:16 +0200 Message-Id: <1501148776-16890-4-git-send-email-armbru@redhat.com> In-Reply-To: <1501148776-16890-1-git-send-email-armbru@redhat.com> References: <1501148776-16890-1-git-send-email-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 27 Jul 2017 09:46:18 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 3/3] host-utils: Simplify pow2ceil() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cc: Radim Kr=C4=8Dm=C3=A1=C5=99 Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qemu/host-utils.h | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h index 6c6005f..5ac621c 100644 --- a/include/qemu/host-utils.h +++ b/include/qemu/host-utils.h @@ -381,18 +381,23 @@ static inline uint64_t pow2floor(uint64_t value) return 0x8000000000000000ull >> clz64(value); } =20 -/* round up to the nearest power of 2 (0 if overflow) */ +/* + * Return @value rounded up to the nearest power of two modulo 2^64. + * This is *zero* for @value > 2^63, so be careful. + */ static inline uint64_t pow2ceil(uint64_t value) { - uint8_t nlz =3D clz64(value); + int n =3D clz64(value - 1); =20 - if (is_power_of_2(value)) { - return value; + if (!n) { + /* + * @value - 1 has no leading zeroes, thus @value - 1 >=3D 2^63 + * Therefore, either @value =3D=3D 0 or @value > 2^63. + * If it's 0, return 1, else return 0. + */ + return !value; } - if (!nlz) { - return 0; - } - return 1ULL << (64 - nlz); + return 0x8000000000000000ull >> (n - 1); } =20 /** --=20 2.7.5