From patchwork Wed Mar 22 15:07:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 665906 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp204126wrt; Wed, 22 Mar 2023 08:09:51 -0700 (PDT) X-Google-Smtp-Source: AK7set/MpZz24/FDprjUZW6uz8/sxYOI0uMC+R4ePoQYqyx5/v9dK8nodHXDs4+Y6VRhr5Kn+NS9 X-Received: by 2002:ad4:5dcd:0:b0:5a9:c0a1:d31a with SMTP id m13-20020ad45dcd000000b005a9c0a1d31amr6174209qvh.49.1679497790582; Wed, 22 Mar 2023 08:09:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679497790; cv=none; d=google.com; s=arc-20160816; b=u8IdhLBndUlJocl5jecJv9yvo54KD5M9swy8pgoWSbyVZceBZhH2vMpNVgV019dJSz /PDlHqMENirZQsrpya1S0nUPCF+i85Qc7tjNPOT+giEt4AG9DzAs3xrPWq9TzWV07fg1 feNTvHhdxaMB1oQTrSiyxgRSsXP6Gk9+/Lsjvi3D8Ekoh46p/MwdGT/QisDj/VGCRVUV g1o48LtOBChY+U8LYqPQ0nOjLa8ZIzRmau9v7gTXr2/k2OE4jCa5GkhDwH0oB40vulhJ /9JSwk7Hv0s2HntR8E82mQOyUFbo/tPI9suN/UB1d6LvIA9UO6Qh4vPpWeXxVnNjXpQV C4PQ== 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=OMK6G6BOZWlbHX4rg+TLkGN/x34xkpFqL8aYBw8SQ0w=; b=BymDp76KIhWGZibqErTPyBN7o/FrRKqbqif+L+PcY72pkXUG/I1T1xU0r2BBk21Ucw FOSrVJ0XPhix/lrfJ80hlp4Dhi4IwISmzNByjJDBAHlkTkjYUf3sui0oCdBLwDp7N25b YuuD7kJHQ6gfhP5ww9Pd7v3/VUbfajr+gf82NQrOeD1WN7KN2AtEYQttZCp8x1fUh0lK kzeiMvmW+rz65fD+CfAorMzfXzLLiaaXzZLxBl+PYrAcJ9uj+w3SMJWvVERvhLDROhNF 6+hBrxoQInDIvbG073PJ1qhYuJmK7xbr+8WsnReZwdKRqGb9ByNmCMGDjuNddbmnidCK 8Onw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hg75OGgV; 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 kc8-20020a056214410800b005ca5decd352si6505483qvb.450.2023.03.22.08.09.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 22 Mar 2023 08:09:50 -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=Hg75OGgV; 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 1pf04k-0003Xg-Gz; Wed, 22 Mar 2023 11:08:30 -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 1pf04L-00032l-GW for qemu-devel@nongnu.org; Wed, 22 Mar 2023 11:08:10 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pf04H-0007Kg-E7 for qemu-devel@nongnu.org; Wed, 22 Mar 2023 11:08:04 -0400 Received: by mail-pl1-x634.google.com with SMTP id ja10so19554264plb.5 for ; Wed, 22 Mar 2023 08:07:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679497676; 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=OMK6G6BOZWlbHX4rg+TLkGN/x34xkpFqL8aYBw8SQ0w=; b=Hg75OGgVVVqJ8K9jjUZa98ox2YwUFnU+TI+Tco112arWLwXN1dj9DgdoEeKzTE2Ps5 0N3Ap4z4swtXI8xu6gZwyiHNyZQaEk+TLJz+9dS0j5lOBk5vGeODZlRjD+FSjzq2NKOw Oca5CCwhUsBXuSSP/7ydGA1ucZqqrlijQPLl2w1cC5VQ9G2Fw9+qpwftfieYCeh2rt9F mveIzBAbe0tvxZETzhXLlorgcDYsX9WuhwdgB1EPKoPn/ff6NjMqi3svOPBuk01lLs3T ZfH9Prj26vMqUD8BfpEkEibwusUAqys9PlW+kJ+HGOKj3tJkFSminJENLbayXZvJAAaX 1yWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679497676; 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=OMK6G6BOZWlbHX4rg+TLkGN/x34xkpFqL8aYBw8SQ0w=; b=DyvbrPnpfvVLSNNaN42HF4K0ImLBPEIbC1PMMeVkyQYlvbTCakx41TmBfDn7MNd01u cV2ZTWHvkPOnsa/5chK8okEVksHLfNeVl8V2fvQITxX+aCmzc4RcjfjtPbYHcAqDyJdl fbMlCB+sJL1EJmhH2Vn5pRCVbadZZSbpGZsqky7tpIxnwTy05m2gEKlOU2MQ5dgjbXmf 4WfqcssSm7TAisjUMz47NfUxARF9h+5KsYhupbrkbOJqvk3La2hCc+VoZ4AQ7PUwKWuC qGBUuWSAxYyDB3UYBeXHAOKlWPn2aYzlcvzJzVNmF+MF8aerscIcTh1Uakktxi785e0i AWYQ== X-Gm-Message-State: AO0yUKUv7IAIlS7Kt1xbaiAqf+lFUDoawPOvoUSZcOpwic5Ktu574w2K HlBV+z3lR40ZTa9KQHQVbUC+F7yEwcLGqkPWcw0= X-Received: by 2002:a17:902:c944:b0:1a1:e14f:3750 with SMTP id i4-20020a170902c94400b001a1e14f3750mr3584388pla.1.1679497676383; Wed, 22 Mar 2023 08:07:56 -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.55 (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 08/11] accel/tcg: Pass last not end to page_collection_lock Date: Wed, 22 Mar 2023 08:07:41 -0700 Message-Id: <20230322150744.175010-9-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::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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. Fixes a bug in the loop comparision where "<= end" would lock one more page than required. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- accel/tcg/tb-maint.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c index 04d2751bb6..57da2feb2f 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -511,20 +511,20 @@ static gint tb_page_addr_cmp(gconstpointer ap, gconstpointer bp, gpointer udata) } /* - * Lock a range of pages ([@start,@end[) as well as the pages of all + * Lock a range of pages ([@start,@last]) as well as the pages of all * intersecting TBs. * Locking order: acquire locks in ascending order of page index. */ static struct page_collection *page_collection_lock(tb_page_addr_t start, - tb_page_addr_t end) + tb_page_addr_t last) { struct page_collection *set = g_malloc(sizeof(*set)); tb_page_addr_t index; PageDesc *pd; start >>= TARGET_PAGE_BITS; - end >>= TARGET_PAGE_BITS; - g_assert(start <= end); + last >>= TARGET_PAGE_BITS; + g_assert(start <= last); set->tree = q_tree_new_full(tb_page_addr_cmp, NULL, NULL, page_entry_destroy); @@ -534,7 +534,7 @@ static struct page_collection *page_collection_lock(tb_page_addr_t start, retry: q_tree_foreach(set->tree, page_entry_lock, NULL); - for (index = start; index <= end; index++) { + for (index = start; index <= last; index++) { TranslationBlock *tb; PageForEachNext n; @@ -1154,7 +1154,7 @@ tb_invalidate_phys_page_range__locked(struct page_collection *pages, void tb_invalidate_phys_page(tb_page_addr_t addr) { struct page_collection *pages; - tb_page_addr_t start, end; + tb_page_addr_t start, last; PageDesc *p; p = page_find(addr >> TARGET_PAGE_BITS); @@ -1163,9 +1163,9 @@ void tb_invalidate_phys_page(tb_page_addr_t addr) } start = addr & TARGET_PAGE_MASK; - end = start + TARGET_PAGE_SIZE; - pages = page_collection_lock(start, end); - tb_invalidate_phys_page_range__locked(pages, p, start, end, 0); + last = addr | ~TARGET_PAGE_MASK; + pages = page_collection_lock(start, last); + tb_invalidate_phys_page_range__locked(pages, p, start, last + 1, 0); page_collection_unlock(pages); } @@ -1181,7 +1181,7 @@ void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t end) struct page_collection *pages; tb_page_addr_t next; - pages = page_collection_lock(start, end); + pages = page_collection_lock(start, end - 1); for (next = (start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; start < end; start = next, next += TARGET_PAGE_SIZE) { @@ -1226,7 +1226,7 @@ void tb_invalidate_phys_range_fast(ram_addr_t ram_addr, { struct page_collection *pages; - pages = page_collection_lock(ram_addr, ram_addr + size); + pages = page_collection_lock(ram_addr, ram_addr + size - 1); tb_invalidate_phys_page_fast__locked(pages, ram_addr, size, retaddr); page_collection_unlock(pages); }