From patchwork Mon Aug 7 23:52:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 798975 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=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=braap.org header.i=@braap.org header.b="HinQanVP"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="Oj11wnPB"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xRF1d66XGz9s72 for ; Tue, 8 Aug 2017 10:01:41 +1000 (AEST) Received: from localhost ([::1]:40078 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1derxr-0005Bi-O0 for incoming@patchwork.ozlabs.org; Mon, 07 Aug 2017 20:01:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47819) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1derpN-0005yg-LH for qemu-devel@nongnu.org; Mon, 07 Aug 2017 19:53:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1derpI-0005jq-5a for qemu-devel@nongnu.org; Mon, 07 Aug 2017 19:52:53 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:53669) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1derpI-0005jP-07 for qemu-devel@nongnu.org; Mon, 07 Aug 2017 19:52:48 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 7685521962; Mon, 7 Aug 2017 19:52:47 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Mon, 07 Aug 2017 19:52:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=n9b T+Unjpb37EFot595S5I1sWFnMLsbLDnFl7h/ieO8=; b=HinQanVPJSicDPQ8BUO 1+80719/T23LOK5deEGCq1BwoCCjw4J8vXeD3W9yfFiuTlSD13rje2oedb2IOm2F XioIPensfLO+N3Hf9vNXYt8VVukFBLz1hDECSJJLezOniFMKldSrk9eLRFfkb8lE edUAMeKzIwUYE9sVhHoUxSgM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=n9bT+Unjpb37EFot595S5I1sWFnMLsbLDnFl7h/ie O8=; b=Oj11wnPBMTODoSynpo8RqL807onb9qzI/da2O5W5V88lCW+a/ic2fKGT6 pTfpMwRrkcx9ENp+3azBZg8FMtNFIu5rxrmBod8mkKjcuZZmBpz16nQIzCXK+1xR t8/8u/OIyTWuoLxevZU3NYKSOM3F0Y8B3PDBE3lkIkcUTOQIwa88inr+n+s9dwFr LfMV03x3g4YSgFwOrqKPnpI5eXqsEzqgzkef0THvZ2e87oGhadSCNkjjutEFOtLq 6jxqrf1+zWEFCg3pi0DT33RwCe7EMsdc9/vXPuk33APpNiK2HJzGWUuNlbNlKVsN TBODlTVSzVUybHjSQckuFm3yNGCIg== X-ME-Sender: X-Sasl-enc: f8Essnat+Uwk1nqyaXXq35hJMvRY0jGtJl96Fru0zRNC 1502149967 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 3ADFD7E664; Mon, 7 Aug 2017 19:52:47 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Mon, 7 Aug 2017 19:52:30 -0400 Message-Id: <1502149958-23381-15-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502149958-23381-1-git-send-email-cota@braap.org> References: <1502149958-23381-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.25 Subject: [Qemu-devel] [PATCH 14/22] translate-all: work page-by-page in tb_invalidate_phys_range_1 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: Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" So that we pass a same-page range to tb_invalidate_phys_page_range, instead of always passing an end address that could be on a different page. As discussed with Peter Maydell on the list, tb_invalidate_phys_page_range doesn't actually do much with 'end', which explains why we have never hit a bug despite going against what the comment on top of tb_invalidate_phys_page_range requires: > * Invalidate all TBs which intersect with the target physical address range > * [start;end[. NOTE: start and end must refer to the *same* physical page. The appended honours the comment, which avoids confusion. While at it, rework the loop into a for loop, which is less error prone (e.g. "continue" won't result in an infinite loop). Signed-off-by: Emilio G. Cota --- accel/tcg/translate-all.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 64d099b..e8f663f 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1372,10 +1372,14 @@ TranslationBlock *tb_gen_code(CPUState *cpu, */ static void tb_invalidate_phys_range_1(tb_page_addr_t start, tb_page_addr_t end) { - while (start < end) { - tb_invalidate_phys_page_range(start, end, 0); - start &= TARGET_PAGE_MASK; - start += TARGET_PAGE_SIZE; + tb_page_addr_t next; + + for (next = (start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; + start < end; + start = next, next += TARGET_PAGE_SIZE) { + tb_page_addr_t bound = MIN(next, end); + + tb_invalidate_phys_page_range(start, bound, 0); } }