From patchwork Sat Mar 9 07:48:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1053815 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Gv1MEUeA"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44GcKB0frMz9s47 for ; Sat, 9 Mar 2019 19:02:06 +1100 (AEDT) Received: from localhost ([127.0.0.1]:55441 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2Wvj-0005rl-U4 for incoming@patchwork.ozlabs.org; Sat, 09 Mar 2019 03:02:04 -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) 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) 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) 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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, void flatview_add_to_dispatch(FlatView *fv, MemoryRegionSection *section) { - MemoryRegionSection now = *section, remain = *section; + MemoryRegionSection remain = *section; Int128 page_size = int128_make64(TARGET_PAGE_SIZE); - if (now.offset_within_address_space & ~TARGET_PAGE_MASK) { + if (remain.offset_within_address_space & ~TARGET_PAGE_MASK) { + MemoryRegionSection now = remain; uint64_t left = TARGET_PAGE_ALIGN(now.offset_within_address_space) - now.offset_within_address_space; now.size = int128_min(int128_make64(left), now.size); register_subpage(fv, &now); - } else { - now.size = int128_zero(); - } - while (int128_ne(remain.size, now.size)) { + if (int128_eq(remain.size, now.size)) { + return; + } remain.size = int128_sub(remain.size, now.size); remain.offset_within_address_space += int128_get64(now.size); remain.offset_within_region += int128_get64(now.size); - now = remain; - if (int128_lt(remain.size, page_size)) { - register_subpage(fv, &now); - } else if (remain.offset_within_address_space & ~TARGET_PAGE_MASK) { - now.size = page_size; - register_subpage(fv, &now); - } else { - now.size = int128_and(now.size, int128_neg(page_size)); - register_multipage(fv, &now); + } + + if (int128_ge(remain.size, page_size)) { + MemoryRegionSection now = remain; + now.size = int128_and(now.size, int128_neg(page_size)); + register_multipage(fv, &now); + if (int128_eq(remain.size, now.size)) { + return; } + remain.size = int128_sub(remain.size, now.size); + remain.offset_within_address_space += int128_get64(now.size); + remain.offset_within_region += int128_get64(now.size); } + + register_subpage(fv, &remain); } void qemu_flush_coalesced_mmio_buffer(void)