From patchwork Mon Mar 4 06:51:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 1051004 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=none (p=none dis=none) header.from=linux.intel.com 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 44CW1G4gwhz9s47 for ; Mon, 4 Mar 2019 17:52:34 +1100 (AEDT) Received: from localhost ([127.0.0.1]:49106 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h0hSi-0007Z0-Hz for incoming@patchwork.ozlabs.org; Mon, 04 Mar 2019 01:52:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39972) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h0hRw-0007WR-0l for qemu-devel@nongnu.org; Mon, 04 Mar 2019 01:51:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h0hRu-0003cN-1s for qemu-devel@nongnu.org; Mon, 04 Mar 2019 01:51:43 -0500 Received: from mga04.intel.com ([192.55.52.120]:52781) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h0hRr-0003YB-Uy for qemu-devel@nongnu.org; Mon, 04 Mar 2019 01:51:41 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Mar 2019 22:51:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,439,1544515200"; d="scan'208";a="149011749" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by fmsmga004.fm.intel.com with ESMTP; 03 Mar 2019 22:51:33 -0800 From: Wei Yang To: qemu-devel@nongnu.org Date: Mon, 4 Mar 2019 14:51:02 +0800 Message-Id: <20190304065102.26447-1-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.120 Subject: [Qemu-devel] [PATCH] exec.c: remove an unnecessary condition in 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: , Cc: pbonzini@redhat.com, Wei Yang , rth@twiddle.net Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" flatview_add_to_dispatch() registers page based on the condition of *section*, which may looks like this: |s|PPPPPPP|s| where s stands for subpage and P for page. The procedure of this function could be described as: - register first subpage - register page - register last subpage This means only the first offset_within_address_space could be not TARGET_PAGE_SIZE aligned. During the wile loop, this will not happen. This patch just removes the unnecessary condition and adds some comment to clarify it. Signed-off-by: Wei Yang --- exec.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/exec.c b/exec.c index 518064530b..e6221d52ba 100644 --- a/exec.c +++ b/exec.c @@ -1599,12 +1599,26 @@ static void register_multipage(FlatView *fv, phys_page_set(d, start_addr >> TARGET_PAGE_BITS, num_pages, section_index); } +/* + * The range in *section* may look like this: + * + * |s|PPPPPPP|s| + * + * where s stands for subpage and P for page. + * + * The procedure in following function could be described as: + * + * - register first subpage + * - register page + * - register last subpage + */ void flatview_add_to_dispatch(FlatView *fv, MemoryRegionSection *section) { MemoryRegionSection now = *section, remain = *section; Int128 page_size = int128_make64(TARGET_PAGE_SIZE); if (now.offset_within_address_space & ~TARGET_PAGE_MASK) { + /* register first subpage */ uint64_t left = TARGET_PAGE_ALIGN(now.offset_within_address_space) - now.offset_within_address_space; @@ -1619,11 +1633,10 @@ void flatview_add_to_dispatch(FlatView *fv, MemoryRegionSection *section) 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 last subpage */ register_subpage(fv, &now); } else { + /* register page */ now.size = int128_and(now.size, int128_neg(page_size)); register_multipage(fv, &now); }