From patchwork Mon May 21 23:39:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 917930 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; dmarc=none (p=none dis=none) header.from=braap.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=braap.org header.i=@braap.org header.b="gG0nE42P"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="AM7psYUe"; 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 40qb5V24lSz9s4n for ; Tue, 22 May 2018 09:46:22 +1000 (AEST) Received: from localhost ([::1]:52875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKuVP-0007VJ-RS for incoming@patchwork.ozlabs.org; Mon, 21 May 2018 19:46:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57832) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKuOt-0002eK-6s for qemu-devel@nongnu.org; Mon, 21 May 2018 19:39:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fKuOq-0005Y3-Fl for qemu-devel@nongnu.org; Mon, 21 May 2018 19:39:35 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:57707) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fKuOq-0005We-6T for qemu-devel@nongnu.org; Mon, 21 May 2018 19:39:32 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 185CE2275A; Mon, 21 May 2018 19:39:30 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 21 May 2018 19:39:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=mesmtp; bh=Etwbtw+LlWQSFKjTg6m2HuY7A8 be0eVQhFpRAWTR0Vs=; b=gG0nE42PrZiOStfFknQzlZyK2+xgDZFIwoe4WDVLUd VgzdD2JOMGXVJ11nkpBKusLH5fmSd930ZYlqKVG1n5gPIglRTOvG+RSoiSryny2X Kz50i3Wm8gFqowgw/XsnmNrwEHbD/7D2PvuEgBzRDI/FcFSoZFY9wR5gQ0lMzzAt Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=Etwbtw +LlWQSFKjTg6m2HuY7A8be0eVQhFpRAWTR0Vs=; b=AM7psYUeJTVRvmiB0amLai xNX0omNIBLFRpX5L6ID28yHB7YXo3HUhkNbn/YGP8+kRA7mjHkYxi7ixv7jNAKkH dmZf3WObE2y44ivPLqUTpyVf+YRjFsNEMx+DhYmA6byN+CWit4TBkto5PrKWdGL3 guy4dkPkgQkWB1f65dasDxXUwRY8fBPewwjjgKejlLX3FZYUTcgUkR0LeK6Ki8i0 vZGac3tJmlJJMVk7B23etHFo+uRlHjSOsGajoDlnshHSNUYLMAsI5ot/2+KydqzJ AJJ3fHXF2frYap7TrdDpH84rEuMFxhoOyXeVrahdFwsrkyKNOkVPX4qsey8/MZvA == X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id C435FE4119; Mon, 21 May 2018 19:39:29 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Mon, 21 May 2018 19:39:18 -0400 Message-Id: <1526945967-9687-9-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526945967-9687-1-git-send-email-cota@braap.org> References: <1526945967-9687-1-git-send-email-cota@braap.org> MIME-Version: 1.0 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 v3 08/17] 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: =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson , Paolo Bonzini 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 [1], 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). [1] https://lists.gnu.org/archive/html/qemu-devel/2017-07/msg09165.html Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée 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 07674e4..8622f25 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1375,10 +1375,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); } }