From nobody Sun Nov 9 23:03:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552118600712950.9261863625746; Sat, 9 Mar 2019 00:03:20 -0800 (PST) Received: from localhost ([127.0.0.1]:55467 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2Wwv-00075O-Go for importer@patchew.org; Sat, 09 Mar 2019 03:03:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47510) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2Wir-0003yz-1v for qemu-devel@nongnu.org; Sat, 09 Mar 2019 02:48:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h2Wiq-0000hq-6E for qemu-devel@nongnu.org; Sat, 09 Mar 2019 02:48:45 -0500 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:42402) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h2Wip-0000h7-VW for qemu-devel@nongnu.org; Sat, 09 Mar 2019 02:48:44 -0500 Received: by mail-wr1-x432.google.com with SMTP id o9so448759wrv.9 for ; Fri, 08 Mar 2019 23:48:43 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id 11sm5252294wmg.27.2019.03.08.23.48.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Mar 2019 23:48:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=uIBSjJbSBlzJmgYY+P1hbCL5o/SExbcPwhWFh0qmdgw=; b=Gv1MEUeATxo8rC8ISqv/CWUtUPS8r86W+rnITkzg6d7YVCTMpM3K493Q87GIDxv9ma Aq5zwurq79LPKzh2I47z1vqwnL2XDlFfBWKEfbinbvplVn613JVsLfGOuYc3T4Q1g+Qv qHFO5AeCb0rrI/hqxCksRxzR4pVVyxzH+DU+lsQAh1LU4Zs6S8yJFdp0JjOJuqCG36fb /h6KBXkassrwRFAKzbdV8OhxXNHrlCIAWWkRe/NsGrKFrujpAd/TPwnc3KrKDO3zr28G jac9IGuJe7K/MIQUWxzluT8gYZUtNi+KbTkwEdpa0x9sWsRqTJeYJnilcVkvHgL2cuJg AifQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=uIBSjJbSBlzJmgYY+P1hbCL5o/SExbcPwhWFh0qmdgw=; b=htVqJ1qcNAWW317ODXWGWPMijN5cZdTuFXJ754r+1Obpu5ADtIgyKPyXjQ4+qKlvsY QQqadUHV4gonST08rVxh5798Xr59H+Ln7k8XVZy2qeR81CaUFcWCCENxDJK/+92o8LuN hA2pGknHxsO0hRrEQiGi/jvXj7aCQuMMEwVNaallHhvyeqrDP/V0n6YTLJ9wJOmuYerP N2R6Mjj5u0N1RIjNP7BtzKN2tv11NznZct4PQr6t9FEbndySaQh4vnTziGrCub+u6P5u SuVaRmG5cUIgx0Zk4OtsXvNAb7/MiVbpo7jF/Oy76pvbEO1HjuMnN9b+GDgRhSS4eT0o g7MA== X-Gm-Message-State: APjAAAXKV09XAFFK9pzmjvqA5lMS18fLRlA9YwMvW4tGLitOLU23eukK KWxr9npxr14ocz84RlNKXOPAgtL1 X-Google-Smtp-Source: APXvYqyBUmDCBeBoE/SO446Ev6EuuX/ZlckSxvWPoyhQqaqwrw3cnLGQAkF+af8a3ybCijfdq6DHqA== X-Received: by 2002:a5d:6542:: with SMTP id z2mr13535745wrv.237.1552117722753; Fri, 08 Mar 2019 23:48:42 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sat, 9 Mar 2019 08:48:18 +0100 Message-Id: <1552117698-12355-26-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1552117698-12355-1-git-send-email-pbonzini@redhat.com> References: <1552117698-12355-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::432 Subject: [Qemu-devel] [PULL 25/25] exec: streamline flatview_add_to_dispatch 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The while loop in flatview_add_to_dispatch can only be executed twice and it will go through different paths on each execution (in fact one of the "if" branches is dead). Remove the loop completely, the code becomes clearer at the cost of a handful of duplicated lines. Reported-by: Wei Yang Signed-off-by: Paolo Bonzini --- exec.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/exec.c b/exec.c index 1d4f378..9647593 100644 --- a/exec.c +++ b/exec.c @@ -1601,33 +1601,37 @@ static void register_multipage(FlatView *fv, =20 void flatview_add_to_dispatch(FlatView *fv, MemoryRegionSection *section) { - MemoryRegionSection now =3D *section, remain =3D *section; + MemoryRegionSection remain =3D *section; Int128 page_size =3D int128_make64(TARGET_PAGE_SIZE); =20 - if (now.offset_within_address_space & ~TARGET_PAGE_MASK) { + if (remain.offset_within_address_space & ~TARGET_PAGE_MASK) { + MemoryRegionSection now =3D remain; uint64_t left =3D TARGET_PAGE_ALIGN(now.offset_within_address_spac= e) - now.offset_within_address_space; =20 now.size =3D int128_min(int128_make64(left), now.size); register_subpage(fv, &now); - } else { - now.size =3D int128_zero(); - } - while (int128_ne(remain.size, now.size)) { + if (int128_eq(remain.size, now.size)) { + return; + } remain.size =3D int128_sub(remain.size, now.size); remain.offset_within_address_space +=3D int128_get64(now.size); remain.offset_within_region +=3D int128_get64(now.size); - now =3D remain; - if (int128_lt(remain.size, page_size)) { - register_subpage(fv, &now); - } else if (remain.offset_within_address_space & ~TARGET_PAGE_MASK)= { - now.size =3D page_size; - register_subpage(fv, &now); - } else { - now.size =3D int128_and(now.size, int128_neg(page_size)); - register_multipage(fv, &now); + } + + if (int128_ge(remain.size, page_size)) { + MemoryRegionSection now =3D remain; + now.size =3D int128_and(now.size, int128_neg(page_size)); + register_multipage(fv, &now); + if (int128_eq(remain.size, now.size)) { + return; } + remain.size =3D int128_sub(remain.size, now.size); + remain.offset_within_address_space +=3D int128_get64(now.size); + remain.offset_within_region +=3D int128_get64(now.size); } + + register_subpage(fv, &remain); } =20 void qemu_flush_coalesced_mmio_buffer(void) --=20 1.8.3.1