From patchwork Thu Jun 14 19:31:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10465141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D5C94600D0 for ; Thu, 14 Jun 2018 19:43:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C513A28990 for ; Thu, 14 Jun 2018 19:43:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B7DB1289B0; Thu, 14 Jun 2018 19:43:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4FA0628990 for ; Thu, 14 Jun 2018 19:43:33 +0000 (UTC) Received: from localhost ([::1]:42382 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTY9c-0007BZ-FR for patchwork-qemu-devel@patchwork.kernel.org; Thu, 14 Jun 2018 15:43:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTXyd-00071B-1o for qemu-devel@nongnu.org; Thu, 14 Jun 2018 15:32:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fTXyb-0005pU-Tc for qemu-devel@nongnu.org; Thu, 14 Jun 2018 15:32:10 -0400 Received: from mail-pg0-x232.google.com ([2607:f8b0:400e:c05::232]:44099) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fTXyb-0005ol-NG for qemu-devel@nongnu.org; Thu, 14 Jun 2018 15:32:09 -0400 Received: by mail-pg0-x232.google.com with SMTP id p21-v6so3354716pgd.11 for ; Thu, 14 Jun 2018 12:32:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Wexsdf6RCRL9p3KT+WfakrG7waRhQx2Db6LZYDP544g=; b=a9np+/ixxS+/jL4/AphXpNTu7XSPCqNuE+JT0rbqg9vJvpIzPcmkMwg8ANaWTksXyt 3/6t5L1d4u4QaU+FRXwb9uKh88UqVgmGV9EABKXk+FCbp57HwrClsRhUdaAmjVcFkK4X /NVZw68ivbZsKeyJgZRbXCpc1S7zmwKEk3MGU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Wexsdf6RCRL9p3KT+WfakrG7waRhQx2Db6LZYDP544g=; b=U82Bke+fU6S5bKrc3QMk1vv2HsDa/NT48OzQS+t+RcNU2p8HKIJn7F6az0+9e4npKt 6xZDZDL9/Q0R6N6ixzob6eODIDUpCzyXoL9Hpb8bbHFVeYvLWEALgKaJNtqq7PhOwRgQ dEtO6FBKkHsclkEW97OwhYtEkXVci2fho5rnsTLKs26iDLLvDxXmlsXBfZqCv5y9B3fp R+PoNXq0l+icoewTDkQH25BIbOsEdRfe9hIW40cK6YWvhzw8Uebu4wb0gIhMJ1V9d4AP 7X72RAysONTzRwBDwmm1PaAkIHjRbLZ87pIHiNj5gsk9Bo61qfs828GN99MSh8y4lH6P cbAA== X-Gm-Message-State: APt69E0AEgMarMfnhBuhijFg+g5Ylx1e7xKKd6jjaHAViWgp/XFfKekI CuUOq0OoEZhshvH5Wq2lsSRAhvL1hpE= X-Google-Smtp-Source: ADUXVKJOogYVxfEXbhzrcAhx/gD9WKA6RMegJYjh20kP/Ps/gBuQKEhkrnZUSrxm6cfqkRv7hN3KxA== X-Received: by 2002:a62:c8a:: with SMTP id 10-v6mr10749076pfm.27.1529004728406; Thu, 14 Jun 2018 12:32:08 -0700 (PDT) Received: from cloudburst.twiddle.net (rrcs-173-198-77-219.west.biz.rr.com. [173.198.77.219]) by smtp.gmail.com with ESMTPSA id x24-v6sm11532184pfj.104.2018.06.14.12.32.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Jun 2018 12:32:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Jun 2018 09:31:38 -1000 Message-Id: <20180614193147.29680-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180614193147.29680-1-richard.henderson@linaro.org> References: <20180614193147.29680-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::232 Subject: [Qemu-devel] [PULL 09/18] 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: peter.maydell@linaro.org, "Emilio G. Cota" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" 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 Signed-off-by: Richard Henderson --- 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 b9c36a3e45..f32904d4a3 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); } }