From patchwork Wed Mar 22 15:07:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 665904 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp203862wrt; Wed, 22 Mar 2023 08:09:26 -0700 (PDT) X-Google-Smtp-Source: AK7set83EjG9FnAkJWt2VahhXVAJKrW88iY8E222dMHN1wFlrkaVdMAo8wpZR9mTjcITYhMj69cY X-Received: by 2002:ac8:5d93:0:b0:3d6:d055:72af with SMTP id d19-20020ac85d93000000b003d6d05572afmr6476235qtx.53.1679497766038; Wed, 22 Mar 2023 08:09:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679497766; cv=none; d=google.com; s=arc-20160816; b=u8NwQnfAs+/lr3dwn8FRWJrP+Iu5WcWvghkX0UELqUQDbfmkYMAUzx9Q+A/3BTRxj3 ASCITzEIOQaHRPRv3IwA3KRGc8jLK9gQp8UUrTAB9xAyY2w+pmHonN0xwjCoV4xqeg+1 ewVwxYkF+3xwkg17Y0MhZ0fulqw8teOE8SsIg3HQNfBpRME0tmW9uoDWRGzQHh62D9wB PmcS4+T3inE5nlMecYg1GdLuYy7bZRpOz1kgqu508jDMOOi1ZCUx1/YXBZMCzDNg3c3z a4nfyO+VLj6R4F4gjvPYNpanW46FH/FEvsoDCNQHN0cAdmvey/0UNlPGFqYeEXZ3HXdU zlOw== 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=7lQNHN36cq4JX4MpVuNitP2N8g4BnbyjtKLtJ8yHuJE=; b=Qpk7sP8BnmU74qqV0YLM7Z+/pZf6rbcpWO3kI00T2FyTyCmXMdU9bavlLWD7BOkkD6 ajCiGXVb6jjDMdNhs/c8xp8wuqWi1rT/882fTHsPDgGXvIXVGWith1gt4tB1hvuWALcz EY1qzbAOlY95OwioJ1FOi33Oy2wvm+zgmhq/XjGX9Fe68F3mYS9vbHLpqoxbLbUKyiuc n9Fno5ZxdjLT4hVpnJ/IkUgavfc9JAwWbGVlda9jSZtHk795YPGvd8210rZbWvT0mWv5 xAKMdA1VbMLws1ZataB3cdLqrbHfz1eF1HUNexHvQbtbTa1u2dhgJw282ndZrC2Jf2Y7 HroQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MflxYJOx; 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 h19-20020a05622a171300b003e38a96d78bsi1497923qtk.340.2023.03.22.08.09.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 22 Mar 2023 08:09:26 -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=MflxYJOx; 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 1pf04d-0003Ke-Ci; Wed, 22 Mar 2023 11:08:23 -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-00031I-CR for qemu-devel@nongnu.org; Wed, 22 Mar 2023 11:08:03 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pf04H-0007LB-DU for qemu-devel@nongnu.org; Wed, 22 Mar 2023 11:08:03 -0400 Received: by mail-pj1-x1029.google.com with SMTP id l7so1731342pjg.5 for ; Wed, 22 Mar 2023 08:07:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679497677; 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=7lQNHN36cq4JX4MpVuNitP2N8g4BnbyjtKLtJ8yHuJE=; b=MflxYJOxIJIARWIPMDZRefRtzZfMoCmTzUISF2fxavT/eM0hXocv7oLPLRkk8FRsmh vmyLMPQZZu+InlCg9ZDKaYcBIYJTQ48/9WDYOoLkceIfX4Zc7itBZY3d+4gyMXt7xjfK coNR0h3LagNSgTd6tlr4xu0z9DDecj0aIW+Wm9Qc8KG/16WxxQUkNTZBogaWQfIluuwZ w6PlaNQ5D35K4WYInS/sOUNmRlLR88XkakXJK0bYMLwYqMiFXh3kceBP5S+MoO6M7dpT sqNzGa06PSS/nXLfisRRT/vaDa2uqQ122ZA90ISTDqZkkXo/lAW+wgAAEpyfPo5xw+wV LgHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679497677; 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=7lQNHN36cq4JX4MpVuNitP2N8g4BnbyjtKLtJ8yHuJE=; b=qJzIeYQewTR7P/G6grfO8iwkLB1mIodan+lQ2/6gpbfqif0qJfUI/YA9OP+SMs4gfa TimCSES72YY94az1Ywz2/6mn6Y7ivS1sCdVs0GJyhRx9MM2ZVstZyJ0V0cPDh+cH+1jl 2ty6uYf31dAnnDPnPTnA/7BwkYM1MHTJwzyXMenUcYNVJQ95WCoKjhePa/kDoroVAckX P8DSmR67RzO0N0nqCNnyfwXxiwYrgf8J8yEDMc/H2evYthdDulDMO8+rw95y7P0ndGuC X22KzRuWOngMpWi/pgOaOTSK5+Xt8z2FsOV2lNDT0AcNgBFF8VJSG8hiAFpYiEh8zCob EmVg== X-Gm-Message-State: AO0yUKUFp+vXYhvco2ocfNj4YWoo0PgbuQfvrHCZJAdiTcW8zLC5yTJY E9uppniUiYx6g2qP8ppHh1e6kxIWepwmjonEDj4= X-Received: by 2002:a17:902:c613:b0:1a1:e33e:2606 with SMTP id r19-20020a170902c61300b001a1e33e2606mr2456361plr.25.1679497677592; Wed, 22 Mar 2023 08:07:57 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 08:07:57 -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 09/11] accel/tcg: Pass last not end to tb_invalidate_phys_page_range__locked Date: Wed, 22 Mar 2023 08:07:42 -0700 Message-Id: <20230322150744.175010-10-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::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.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. Properly truncate tb_last to the end of the page; the comment about tb_end being past the end of the page being ok is not correct, considering overflow. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- accel/tcg/tb-maint.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c index 57da2feb2f..74823ba464 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -1084,35 +1084,33 @@ bool tb_invalidate_phys_page_unwind(tb_page_addr_t addr, uintptr_t pc) static void tb_invalidate_phys_page_range__locked(struct page_collection *pages, PageDesc *p, tb_page_addr_t start, - tb_page_addr_t end, + tb_page_addr_t last, uintptr_t retaddr) { TranslationBlock *tb; - tb_page_addr_t tb_start, tb_end; PageForEachNext n; #ifdef TARGET_HAS_PRECISE_SMC 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[. + * We remove all the TBs in the range [start, last]. * XXX: see if in some cases it could be faster to invalidate all the code */ PAGE_FOR_EACH_TB(start, last, p, tb, n) { + tb_page_addr_t tb_start, tb_last; + /* NOTE: this is subtle as a TB may span two physical pages */ + tb_start = tb_page_addr0(tb); + tb_last = tb_start + tb->size - 1; if (n == 0) { - /* NOTE: tb_end may be after the end of the page, but - it is not a problem */ - tb_start = tb_page_addr0(tb); - tb_end = tb_start + tb->size; + tb_last = MIN(tb_last, tb_start | ~TARGET_PAGE_MASK); } else { tb_start = tb_page_addr1(tb); - tb_end = tb_start + ((tb_page_addr0(tb) + tb->size) - & ~TARGET_PAGE_MASK); + tb_last = tb_start + (tb_last & ~TARGET_PAGE_MASK); } - if (!(tb_end <= start || tb_start >= end)) { + if (!(tb_last < start || tb_start > last)) { #ifdef TARGET_HAS_PRECISE_SMC if (current_tb == tb && (tb_cflags(current_tb) & CF_COUNT_MASK) != 1) { @@ -1165,7 +1163,7 @@ void tb_invalidate_phys_page(tb_page_addr_t addr) start = addr & TARGET_PAGE_MASK; last = addr | ~TARGET_PAGE_MASK; pages = page_collection_lock(start, last); - tb_invalidate_phys_page_range__locked(pages, p, start, last + 1, 0); + tb_invalidate_phys_page_range__locked(pages, p, start, last, 0); page_collection_unlock(pages); } @@ -1192,7 +1190,7 @@ void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end) continue; } assert_page_locked(pd); - tb_invalidate_phys_page_range__locked(pages, pd, start, bound, 0); + tb_invalidate_phys_page_range__locked(pages, pd, start, bound - 1, 0); } page_collection_unlock(pages); } @@ -1212,7 +1210,7 @@ static void tb_invalidate_phys_page_fast__locked(struct page_collection *pages, } assert_page_locked(p); - tb_invalidate_phys_page_range__locked(pages, p, start, start + len, ra); + tb_invalidate_phys_page_range__locked(pages, p, start, start + len - 1, ra); } /*