From patchwork Wed Mar 22 15:07:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 665903 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp203790wrt; Wed, 22 Mar 2023 08:09:20 -0700 (PDT) X-Google-Smtp-Source: AK7set9FtLGjhJHVN2yWYh6BclyzxjP0lN2wA3Dj2mBB6v4VVnpEOZZ1xxwv2YrKygE4H39Pi1yW X-Received: by 2002:ac8:7f10:0:b0:3ba:18c2:99e7 with SMTP id f16-20020ac87f10000000b003ba18c299e7mr6716515qtk.45.1679497760100; Wed, 22 Mar 2023 08:09:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679497760; cv=none; d=google.com; s=arc-20160816; b=VRlozwlKwMw+S+fpsJgZvV/ZQpC0FlEYUFLDGlL+Hn5+GMBb+6hA9OSImaUhvm33+G JwrKlTJ4hFnoQ9QhOmoHAguP9wbdz3d3TfT6Igyy1PN2jeSBveYVwiMysfGp0t+18abD ROVOgnwGxFar86tmqlD/JRQX+PPQX14qk471F5wYhdywfkCNIUrKP4geAux/3yD0vtjb urkgeJLIn7yO9qAv0cmIeiQElyX8okP/80wJTZQR+rKW7AnxOwqvVMfexrPq9O6GA/Vf H+JyOtXy/kupuOOmIlY6jSQkR1/T7lyP9SAJ/l0w3qfSc2s25/pFzdtTC4RTbxpcHyPa cRnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=s8SVCaZUmE/Km0+IIG6EiSCxwnpR9ibdQSVxm7qmuBg=; b=XdEzGzcRZ6P3hZG0jqCjDTlbRxmsidDen0E0DJXdpzNWC3NrgCi3Skl8oo29p/lycd HmjA/5UItzHFPyRhv8zTfOW1icND8sZ39YgQGCcqlaAorpiLb+dcLGhmy5BEd9Am+vb2 8kIaIqxz461V/7pVNd4HcjFTceQVxjBu3h5W9ab1x7j/lI2ziRKigkQOPZE2Y2zi6oLY nwLOHUdtgsEs8KREjbW7X3x9VMV+dLJLddwY1vWIZzhBV2sZLyFqKsnX/meiJpsT0thF /xCedNOJy+M6WHMtOy161+9ZhS43UgMW9agOcFukc9eLYqfkA/LIec9vwmbNBnf2MHc5 OKsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="xw/9c7dW"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e12-20020ac85dcc000000b003ba201d92b0si10737993qtx.285.2023.03.22.08.09.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 22 Mar 2023 08:09:20 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="xw/9c7dW"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pf04g-0003Up-MG; Wed, 22 Mar 2023 11:08:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pf04J-0002zq-3K for qemu-devel@nongnu.org; Wed, 22 Mar 2023 11:08:03 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pf04C-0007Jn-QR for qemu-devel@nongnu.org; Wed, 22 Mar 2023 11:08:02 -0400 Received: by mail-pj1-x102c.google.com with SMTP id gp15-20020a17090adf0f00b0023d1bbd9f9eso23930404pjb.0 for ; Wed, 22 Mar 2023 08:07:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679497675; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s8SVCaZUmE/Km0+IIG6EiSCxwnpR9ibdQSVxm7qmuBg=; b=xw/9c7dWnXZ+TSfBjuEjcmhtRO0cMDYz6vsXm2WrJYTeXcf6qlYIu1OEMXJ/KpOhZP k7p1ufqW4ls1CsQEXE/IUG8DtJ0NqJPaMnnKrRPNjLX9GPsJyTIZ4AUbiqOxBNNYO4xy qPdptXr5gzDtm1Q/rLc78A+Xf+sQuACdiT6TiGubAL5CHEH+tPwE1IidVXn3A1abEZsO RMfDOu71FjF9t37Lfao/lwcM7kGVrhcTmUG9KrZt15fYTbka5nA/euoqOtA1Z5s3OT/h 2pLPgH4woK0xzh5Jm4FI9ocPBtahdzwcgW77lGqXYJE955ynRWPt5+Y7ohR5+Rl3YfTJ Vjjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679497675; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s8SVCaZUmE/Km0+IIG6EiSCxwnpR9ibdQSVxm7qmuBg=; b=R5Iz4w4Zyr/48SnaSJMkmJpibbj27OzCjvhpTI/Wv85F4g4oqRJ3Q2qP6Y1loif2iK k2JI+WyBlXAnWhXmVLAlkcXaSk3ZNtm75JShomHJ391r/R5np/xMw2S9FH6k/A6humEh XUEHiQVxf9mbi8KOdCb6uLsNEGZMuj0pMCNi6DWXYWfeLsfDbe6lo4XbIcDqvCYwE2Pd 4a1mwfJKRob+qu6H4MwvR9phYYXfyX4BRR0kOQwkcqI3BZcCmjS4IIMHkN1SCcGFt/j4 K+b0CZNpLS9Kb9NMuOlSaGlrQJi5kez/m9pkBcqAMIv51TSMgGhj0mSZXEEK/eZsLIVD 5LMQ== X-Gm-Message-State: AO0yUKUymtc2J94dSDpNdEcB19AXr6NG4y1UI5QbEigr7aQaJgwp42j/ zFIJsSBKzcUI6YQtrqikNc0Sa2nnPq/KvzgPDOM= X-Received: by 2002:a17:902:7c11:b0:19e:872b:e844 with SMTP id x17-20020a1709027c1100b0019e872be844mr2574829pll.40.1679497675428; Wed, 22 Mar 2023 08:07:55 -0700 (PDT) Received: from stoup.. (24-113-166-229.wavecable.com. [24.113.166.229]) by smtp.gmail.com with ESMTPSA id 17-20020a170902ee5100b0019339f3368asm10757555plo.3.2023.03.22.08.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 08:07:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: cota@braap.org, peter.maydell@linaro.org, =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= Subject: [PATCH for-8.0 07/11] accel/tcg: Pass last not end to PAGE_FOR_EACH_TB Date: Wed, 22 Mar 2023 08:07:40 -0700 Message-Id: <20230322150744.175010-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230322150744.175010-1-richard.henderson@linaro.org> References: <20230322150744.175010-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Pass the address of the last byte to be changed, rather than the first address past the last byte. This avoids overflow when the last page of the address space is involved. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- accel/tcg/tb-maint.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c index a173db17e6..04d2751bb6 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -127,29 +127,29 @@ static void tb_remove(TranslationBlock *tb) } /* TODO: For now, still shared with translate-all.c for system mode. */ -#define PAGE_FOR_EACH_TB(start, end, pagedesc, T, N) \ - for (T = foreach_tb_first(start, end), \ - N = foreach_tb_next(T, start, end); \ +#define PAGE_FOR_EACH_TB(start, last, pagedesc, T, N) \ + for (T = foreach_tb_first(start, last), \ + N = foreach_tb_next(T, start, last); \ T != NULL; \ - T = N, N = foreach_tb_next(N, start, end)) + T = N, N = foreach_tb_next(N, start, last)) typedef TranslationBlock *PageForEachNext; static PageForEachNext foreach_tb_first(tb_page_addr_t start, - tb_page_addr_t end) + tb_page_addr_t last) { - IntervalTreeNode *n = interval_tree_iter_first(&tb_root, start, end - 1); + IntervalTreeNode *n = interval_tree_iter_first(&tb_root, start, last); return n ? container_of(n, TranslationBlock, itree) : NULL; } static PageForEachNext foreach_tb_next(PageForEachNext tb, tb_page_addr_t start, - tb_page_addr_t end) + tb_page_addr_t last) { IntervalTreeNode *n; if (tb) { - n = interval_tree_iter_next(&tb->itree, start, end - 1); + n = interval_tree_iter_next(&tb->itree, start, last); if (n) { return container_of(n, TranslationBlock, itree); } @@ -320,7 +320,7 @@ struct page_collection { }; typedef int PageForEachNext; -#define PAGE_FOR_EACH_TB(start, end, pagedesc, tb, n) \ +#define PAGE_FOR_EACH_TB(start, last, pagedesc, tb, n) \ TB_FOR_EACH_TAGGED((pagedesc)->first_tb, tb, n, page_next) #ifdef CONFIG_DEBUG_TCG @@ -995,10 +995,11 @@ void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end) { TranslationBlock *tb; PageForEachNext n; + tb_page_addr_t last = end - 1; assert_memory_lock(); - PAGE_FOR_EACH_TB(start, end, unused, tb, n) { + PAGE_FOR_EACH_TB(start, last, unused, tb, n) { tb_phys_invalidate__locked(tb); } } @@ -1030,6 +1031,7 @@ bool tb_invalidate_phys_page_unwind(tb_page_addr_t addr, uintptr_t pc) bool current_tb_modified; TranslationBlock *tb; PageForEachNext n; + tb_page_addr_t last; /* * Without precise smc semantics, or when outside of a TB, @@ -1046,10 +1048,11 @@ bool tb_invalidate_phys_page_unwind(tb_page_addr_t addr, uintptr_t pc) assert_memory_lock(); current_tb = tcg_tb_lookup(pc); + last = addr | ~TARGET_PAGE_MASK; addr &= TARGET_PAGE_MASK; current_tb_modified = false; - PAGE_FOR_EACH_TB(addr, addr + TARGET_PAGE_SIZE, unused, tb, n) { + PAGE_FOR_EACH_TB(addr, last, unused, tb, n) { if (current_tb == tb && (tb_cflags(current_tb) & CF_COUNT_MASK) != 1) { /* @@ -1091,12 +1094,13 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages, bool current_tb_modified = false; TranslationBlock *current_tb = retaddr ? tcg_tb_lookup(retaddr) : NULL; #endif /* TARGET_HAS_PRECISE_SMC */ + tb_page_addr_t last G_GNUC_UNUSED = end - 1; /* * We remove all the TBs in the range [start, end[. * XXX: see if in some cases it could be faster to invalidate all the code */ - PAGE_FOR_EACH_TB(start, end, p, tb, n) { + PAGE_FOR_EACH_TB(start, last, p, tb, n) { /* NOTE: this is subtle as a TB may span two physical pages */ if (n == 0) { /* NOTE: tb_end may be after the end of the page, but