From patchwork Tue Mar 28 22:57:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 667883 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp49265wrt; Tue, 28 Mar 2023 16:00:15 -0700 (PDT) X-Google-Smtp-Source: AK7set9JeOhaUcf/fWghwKCl1gZmWvpPo9qr7xwYyqQTwQICYwzpJPMtABKm6MWERVK5aAgGvRFZ X-Received: by 2002:ac8:5fcd:0:b0:3de:94da:4fd7 with SMTP id k13-20020ac85fcd000000b003de94da4fd7mr31918837qta.39.1680044415819; Tue, 28 Mar 2023 16:00:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680044415; cv=none; d=google.com; s=arc-20160816; b=ovAKEBaamVWYItlT2h1ucXgKvtRgIoB+dcywGmCpdUItexhFaci46KLeUPLvRJdeX8 teUpohTaYPdyk2R5tEft3VbQb24vyOlJY19I7lc/nVRO+muchKYuxw34S3vhnLKj+bNC YwaQukjNybk/qbhz1E5lJLA0Ve3NAJmBIa3NwArGE/BLwpdpykQP2lXokgUo/yE0w+Mp qLL9tyCUZIgjBWcwDdSqrv4y66l3Pz5/YHgiM8KFZBG834iSxVteZ0dUqhSPlpWWFcHf /qOuJAtgitT+ARkQ8R1t4h9IswOQlWaW+Q+5kguJOYLwsbxfP1BCX9bvTXdj6H0qXgnS wovQ== 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=me43xxdqFFOAR6GEUxbBBRcc6+yvj4eur9tZSaDMwm36/yo4HO9ITooQGyMYry9HUv Phm/+bxmXiKy1KEOTNWSjArIlijfDKRbmZ/7poGSAv5VDCBRs349+cBsLgcddFEsBHJc 27JlJ4poFoMjCTYV3WJp4SsEE1hcz0e2/H/+G2glX9MfJT0mLj4z2uGm/ku5Nq3Cvrrl 7dLW41NMFppNNbedJyccCP5ZU2WRKbdXsdhdawhyZjgWHXbVZRrvEv3AfRU/PjUrn1y7 I4fYMI2WeN87ycXS/8XGNMJVlY3pILbw2wR52nXFIsw2pLOAcXPJuxGapDwM3rr72+x9 BvYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EDyXLAKt; 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 b21-20020a05622a021500b003e3891dcba2si13255669qtx.747.2023.03.28.16.00.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Mar 2023 16:00:15 -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=EDyXLAKt; 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 1phIGf-0006sU-RA; Tue, 28 Mar 2023 18:58:17 -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 1phIGe-0006rv-EX for qemu-devel@nongnu.org; Tue, 28 Mar 2023 18:58:16 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1phIGc-00073k-NL for qemu-devel@nongnu.org; Tue, 28 Mar 2023 18:58:16 -0400 Received: by mail-pj1-x1031.google.com with SMTP id om3-20020a17090b3a8300b0023efab0e3bfso16695170pjb.3 for ; Tue, 28 Mar 2023 15:58:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680044293; 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=EDyXLAKt8sR4o7bh2k1Tpgf0oK5fbBojrpiNHQ4HT6EkbcQVJOmWANSrDu5zm1eb+z dOePtEItL3aTXdmcLVuc47AkpJaum09IpbQItK4N+9LR45sxDSf7nF5RVF4hIPYFg9F7 Hb2srV0WIyHc9L36qrh2XNOaAcoBgHPCzeo1ODVS5KkihvuGgvxC4szY4+HgR7NeT58w ORuhD5BiAmnuXBM+D57BEW/5/gKbIQSaPnwUouWno72+EvjKmA7Omn2k14Uq9XVboixq KIO060CiT0iofk2dBdtcGBH9hOjfxA7+gxBR+jykWcukfGOJrODCwbif+uSqTpfsnSvB 2/Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680044293; 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=0lgTlxqmfu2NGiec9Hae5c+xllR896uPyUYq9B4N436l4/cyD5y9lv3XQg25X8lykM uwzEi+51cUBImT7S/jAREE4sOlwqCJFDLT+HFDzThYBh2KO62oHisanONrMvN1UU7z7t CP0nXB927pGcw9syDYvtamXNmioTBqQrnBvhLdL19XmUocmS+Cjq5sk+WJaJy/zDUr/v z6Op01KSOugSQa5W2EjVK3PN4byO5qBfyPy6AC5uk9IM329n0BlXb4L/kbztNNeSA+Qi GoHqEUifFk6/R4UiaxyUD2yScQqdyLcwHTldP+wuElvpLBCsptn7If+RuO+jJEVSh+ZT xC9w== X-Gm-Message-State: AAQBX9f2jssQ1VqO2DDI5j46j211InN8YKv7aXhCwehgbU6PQegl9V+4 /gaHo2rM/bU/uP0mvWRnfsMmAPuPvDj7E27zIzU= X-Received: by 2002:a17:90a:1953:b0:240:973d:b431 with SMTP id 19-20020a17090a195300b00240973db431mr5945113pjh.42.1680044293438; Tue, 28 Mar 2023 15:58:13 -0700 (PDT) Received: from stoup.. ([2602:ae:1541:f901:c23d:b6:6be1:f147]) by smtp.gmail.com with ESMTPSA id jw1-20020a170903278100b0019cd1ee1523sm21670633plb.30.2023.03.28.15.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 15:58:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 06/15] accel/tcg: Pass last not end to PAGE_FOR_EACH_TB Date: Tue, 28 Mar 2023 15:57:57 -0700 Message-Id: <20230328225806.2278728-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230328225806.2278728-1-richard.henderson@linaro.org> References: <20230328225806.2278728-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.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