From nobody Mon Feb 9 16:04:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676564383067255.8847163144486; Thu, 16 Feb 2023 08:19:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSgyf-00080F-Hj; Thu, 16 Feb 2023 11:19:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSgyd-0007xY-21 for qemu-devel@nongnu.org; Thu, 16 Feb 2023 11:19:19 -0500 Received: from prt-mail.chinatelecom.cn ([42.123.76.223] helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSgya-000526-RQ for qemu-devel@nongnu.org; Thu, 16 Feb 2023 11:19:18 -0500 Received: from clientip-118.116.19.27 (unknown [172.18.0.188]) by chinatelecom.cn (HERMES) with SMTP id 1C63A2800E2; Fri, 17 Feb 2023 00:19:02 +0800 (CST) Received: from ([118.116.19.27]) by app0023 with ESMTP id 606cdf52dece466c84aacc876dd3eb98 for qemu-devel@nongnu.org; Fri, 17 Feb 2023 00:19:09 CST HMM_SOURCE_IP: 172.18.0.188:50698.1319324123 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 606cdf52dece466c84aacc876dd3eb98 X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 118.116.19.27 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel Cc: Markus Armbruster , Peter Xu , "Dr. David Alan Gilbert" , Juan Quintela , Thomas Huth , Paolo Bonzini , Eric Blake , Peter Maydell , Richard Henderson , =?UTF-8?q?Hyman=20Huang=28=E9=BB=84=E5=8B=87=29?= Subject: [PATCH v4 01/10] dirtylimit: Fix overflow when computing MB Date: Fri, 17 Feb 2023 00:18:30 +0800 Message-Id: <255bcba59296e91e6be756c1e6e540afeabd94f3.1676563222.git.huangy81@chinatelecom.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=42.123.76.223; envelope-from=huangy81@chinatelecom.cn; helo=chinatelecom.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1676564385901100001 From: Hyman Huang(=E9=BB=84=E5=8B=87) Coverity points out a overflow problem when computing MB, dirty_ring_size and TARGET_PAGE_SIZE are both 32 bits, multiplication will be done as a 32-bit operation, which could overflow. Simplify the formula. Meanwhile, fix spelling mistake of variable name. Reported-by: Peter Maydell Signed-off-by: Peter Maydell Signed-off-by: Richard Henderson Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) Reviewed-by: Peter Xu --- softmmu/dirtylimit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/softmmu/dirtylimit.c b/softmmu/dirtylimit.c index c56f0f58c8..065ed18afc 100644 --- a/softmmu/dirtylimit.c +++ b/softmmu/dirtylimit.c @@ -235,14 +235,14 @@ static inline int64_t dirtylimit_dirty_ring_full_time= (uint64_t dirtyrate) { static uint64_t max_dirtyrate; uint32_t dirty_ring_size =3D kvm_dirty_ring_size(); - uint64_t dirty_ring_size_meory_MB =3D - dirty_ring_size * TARGET_PAGE_SIZE >> 20; + uint32_t dirty_ring_size_memory_MB =3D + dirty_ring_size >> (20 - TARGET_PAGE_BITS); =20 if (max_dirtyrate < dirtyrate) { max_dirtyrate =3D dirtyrate; } =20 - return dirty_ring_size_meory_MB * 1000000 / max_dirtyrate; + return dirty_ring_size_memory_MB * 1000000ULL / max_dirtyrate; } =20 static inline bool dirtylimit_done(uint64_t quota, --=20 2.17.1