From patchwork Tue Mar 28 22:57:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 667884 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp49301wrt; Tue, 28 Mar 2023 16:00:20 -0700 (PDT) X-Google-Smtp-Source: AKy350aJ8n5zF/y7/oQmSka9PLepk+DtVWK7ZHdLlQV+MhKHYPLbC22u5qaiGOUS/cU+vGdO5N+U X-Received: by 2002:ac8:5a50:0:b0:3e3:897b:e9a2 with SMTP id o16-20020ac85a50000000b003e3897be9a2mr500238qta.12.1680044420453; Tue, 28 Mar 2023 16:00:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680044420; cv=none; d=google.com; s=arc-20160816; b=FvSi0SxLMSfYxV8WM9L73gp6uEf0NZqW7IEbORI2ZURvRnzlkjzjypyLhk5vXqmKDp zGsalPoJQb7D3ZmU5+JpQ9MBOIu9CbKlPgLjm3JoWfGxVzkB1SYuMAtCW6pnzB0scE0t IhRSAoXqkxGezf2wmJjt+pBZu8ueowYd0w+3ONQRcxhn7KT4daJ0P56lIron7v1yH1uy Ny1yepV2auUSldil2sryZy7z+yHNYmZBde7Zckdg6b3Xgup68YNo+7Z8rSJXqRC+7kUG wM+qVQUv+9Z+pmhvbq+fFuxWgOg8SCoeBb6iP6mR4W/ZS+nYmhoMZL1pU5WXnPFUSFf0 4Wlw== 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=DsodvbgfX5Oan99mKqLoLkAXg+TJ1+eCSG7k9qwlKqQjBDG39IFJ8TjNL5ebe+ucqC oyPEyP8QVtTgB6gWVmrFE6h0hNieNi9oeBKix1XVntfHkmnWk8vTJlnPIGnUihO7R7BY p03euz8c3hZCJSBDp6p55Nkk4KyG8ZZ7wCKkaPeRpLRBULVMFCM0d6tZWyfrHAcMHXTu vOkbl9Bh6Po7uDeBL175liualw905IyadnEpyRXT+r9nKsn3edHHy7StSvcuiDdctbS9 Xd/Uq+QdsDF446N4aodETpuzWPcqUAg/NGC+liOyDywtpHFLqqOZ1uWQI9ygjeDrd+eS BqlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EDVmEBix; 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 q20-20020a05622a04d400b003e4e2c19ffbsi6006081qtx.113.2023.03.28.16.00.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Mar 2023 16:00: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=EDVmEBix; 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 1phIGl-0006uN-4e; Tue, 28 Mar 2023 18:58: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 1phIGg-0006t5-DW for qemu-devel@nongnu.org; Tue, 28 Mar 2023 18:58:18 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1phIGe-00074I-LG for qemu-devel@nongnu.org; Tue, 28 Mar 2023 18:58:18 -0400 Received: by mail-pj1-x102e.google.com with SMTP id lr16-20020a17090b4b9000b0023f187954acso14260331pjb.2 for ; Tue, 28 Mar 2023 15:58:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680044295; 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=EDVmEBixoqKCsNzfT33au9L9b1ZaunRZbLgP7crJMv2AJXNSF5qhOAFpzLFlk8f1Cr VQLKDptRMChSq3GD0s/aMxe2RZU5VYvHchHb39y0VGnfUhXPAz2FzYycmk4lGpXjt3PV 52q7bk0VyaeHoHlqeitUrVJIgTanM5MpR4a9+WFTcpFgl4SUzGVRJ7uDBp6mF/KcWAQb hncaAmoYH8gAqquLNAfpgo8qJBGyjQ5ZK+E7cYb6coREe6/T7z2uZN8wOYDYAzFO0eud Jtm34Qz0BYdMWXWOH+E7DRAnlAqnVbr3tay5Q8GwsMf3CqyhaRhmaCH1HIVf0uJeX3rt pNWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680044295; 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=jOTCK9g76g93yZP5woLFVl//U6T0cZA/W/SYAW6nzqA3e8cnNJFyUe9467TucLykrq jKoU+aCEn8rgB4QrBeJoQ2twe6xxfQhP60XofaarGhKTgIWVArQ5t7MLXSten55cX+LN PnIycdIpu+X58fa+LDeCnNg02xRfiuAOzoScspq8Z3xO9LNsyyn0wKgTJWq5/qa4qZ9i btTvKYh2qiAt943a2YhPxClVJIeLUmSwwkw0qBHnRnWe19SEBBK1pPiMJAuLB/4EnQGn HOTePvx3YHUSy1XqIyLuoflNMrVTGMPg7bmDergRAOcQ6/CIsATzhSDxfxdFDnVfwS+Q FFdw== X-Gm-Message-State: AAQBX9ful5nFXQJ1jRgQj1OCtPYbGxzO8DF2GAi8Sk1djQPQBnVJ5AMI GpiBHWqyN9QzNqzVc9SlfN/B1Ndtqt6NbEdjVy0= X-Received: by 2002:a17:902:f547:b0:1a1:7899:f009 with SMTP id h7-20020a170902f54700b001a17899f009mr244699plf.17.1680044295371; Tue, 28 Mar 2023 15:58:15 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 15:58:15 -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 08/15] accel/tcg: Pass last not end to tb_invalidate_phys_page_range__locked Date: Tue, 28 Mar 2023 15:57:59 -0700 Message-Id: <20230328225806.2278728-9-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::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.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); } /*