From nobody Wed Feb 11 05:17:46 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 1670087554351522.5637369771981; Sat, 3 Dec 2022 09:12:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p1W1L-0000NE-7y; Sat, 03 Dec 2022 12:09:47 -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 1p1W1J-0000Ml-Ru for qemu-devel@nongnu.org; Sat, 03 Dec 2022 12:09:45 -0500 Received: from prt-mail.chinatelecom.cn ([42.123.76.219] helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p1W1I-0006Jd-4i for qemu-devel@nongnu.org; Sat, 03 Dec 2022 12:09:45 -0500 Received: from clientip-125.69.43.82 (unknown [172.18.0.218]) by chinatelecom.cn (HERMES) with SMTP id DD29F2800B4; Sun, 4 Dec 2022 01:09:40 +0800 (CST) Received: from ([125.69.43.82]) by app0025 with ESMTP id 86d2afa9d5824a2bb9e59c57bc468bc3 for qemu-devel@nongnu.org; Sun, 04 Dec 2022 01:09:42 CST HMM_SOURCE_IP: 172.18.0.218:60462.1823367042 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 86d2afa9d5824a2bb9e59c57bc468bc3 X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 125.69.43.82 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: qemu-devel Cc: Peter Xu , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini , Laurent Vivier , Eric Blake , Juan Quintela , Thomas Huth , Peter Maydell , Richard Henderson , =?UTF-8?q?Hyman=20Huang=28=E9=BB=84=E5=8B=87=29?= Subject: [PATCH RESEND v3 01/10] dirtylimit: Fix overflow when computing MB Date: Sun, 4 Dec 2022 01:09:04 +0800 Message-Id: <97fedfc5bac8ca91a15e7c73340c8bbbbce9b1fc.1670087275.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.219; 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: 1670087555379100001 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 1266855..940d238 100644 --- a/softmmu/dirtylimit.c +++ b/softmmu/dirtylimit.c @@ -236,14 +236,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 1.8.3.1