From patchwork Mon Mar 6 02:13:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 659228 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp1598532wrb; Sun, 5 Mar 2023 18:13:57 -0800 (PST) X-Google-Smtp-Source: AK7set+5eseeRkkaxxyh9tqulksxCn2B8LF1DIjlYPW7kZrw64IXG338CnHvusl/N0Vx16djqofx X-Received: by 2002:a05:6214:f05:b0:56e:b25f:3602 with SMTP id gw5-20020a0562140f0500b0056eb25f3602mr18117997qvb.43.1678068836937; Sun, 05 Mar 2023 18:13:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678068836; cv=none; d=google.com; s=arc-20160816; b=iFXp5UyIvjIMbI4JDZW0f5VmkikjkbeCMjmN05JYAgKN292MdJW7yGgxheeFuDx1ST bAPKnEfvs7Vz/kvdIgkikDXAvYKi+7fSELjPdwyJcUhhS22IzhnSWEF3g3bQ/BbWC86m MY57n00jHkKBIsrlayoUg+YR8GK7cQJZNbsFKal4l0ns5caemSQz196RFoh0H3iYTRxg 4CYR3bR6XQVk+25eC+POoVtUNGG15DWeciqmiP4SMj1F8MQXCov9r7uOguo+Z4GoKXgo qSqR2+22Tgm4tmgmWmbxhKd/SGObOzama0c/IhYblUggC85rOLzh22asUrKbTy9Vhx8G iAWQ== 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:to:from :dkim-signature; bh=RvcMLtMZSPv7P6lANhDUocXLVd0nBQQsNtPV18yr4k4=; b=SJxp1YybYyX7i9A1YU5WEpxJ6+fgfhobvoBoIj5JTTQ8p5ur0i62Qi2iGM791zvPRT lq2U70X69FyVrFd3qUGi7uL6DfP3CjFYXHU0T27zyMzlSKtPhesb9+DrbP/2f+vJ5egY eAxFUvZCDvm0rSx50N/aXjMqeyHVInp0t4nDwdva4FNk0cttY1u/q8p/PCj2sL8pelyZ zoUflKM70xjeNo57TIHs5snR5HjpuHsI2sqYNHcf35myAIvz/RX+GekX9ioefN16h+OW 0Kdv6cgTXVK0XLvmT1nvPeLFV9Vn0QyuNu6Lk/q1ZdU6gGhdTvZ+PeKrlwoqe2X/YyOJ XZlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wh52Ylg3; 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 k17-20020a0cf291000000b0056c0a6a5ee7si6447086qvl.192.2023.03.05.18.13.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 05 Mar 2023 18:13:56 -0800 (PST) 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=wh52Ylg3; 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 1pZ0Ln-0003NQ-9V; Sun, 05 Mar 2023 21:13:19 -0500 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 1pZ0Ll-0003JB-Nw for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:17 -0500 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 1pZ0Lk-00062J-5k for qemu-devel@nongnu.org; Sun, 05 Mar 2023 21:13:17 -0500 Received: by mail-pj1-x102c.google.com with SMTP id bo22so8302567pjb.4 for ; Sun, 05 Mar 2023 18:13:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678068795; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=RvcMLtMZSPv7P6lANhDUocXLVd0nBQQsNtPV18yr4k4=; b=wh52Ylg3bwxtArx3aZ6tB+nDnP/KRGtwZkYcDqVIlM7iuD+Ck2gECuAbFMlrKaUfV6 GA42Lbt825aKn2rcDyIxrM7Xdr1X1nhm+wtV4uCaJK1LbkJZVjGJfIyN9UdP1sdkqVVT 7Pn6Z0foUnY0/Kcn+gyYsUyplemWr2Z/ZiSoZgZ7dl1yMuES6DLi03n1C47Q73D3EPmM 5xkfcPymF25VQL1KVV/anPOZ+Okflod3vGdEP+KDqAcJOCvXX3/pE7NgfSppp/zaIDQ9 UFJ/ZvmL7VA8B2YjIoAy/D0EKlhWnl0ts10OK+oFmkEOLme4a9XGf9RdeEqjamWAtHoV CN3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678068795; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RvcMLtMZSPv7P6lANhDUocXLVd0nBQQsNtPV18yr4k4=; b=gfrpmabsASTpW4IQrx+eVRiXod6lrh253nphwP2LlnkI2zDxfjtG/5VVHqx0YI3Er0 iROUGml1PzO6oizFL/imKvcRw43QQo0E5MRMjmmAkfVQYJ1VrliuZ2jUJVB3VVtzQlMn fF4o4i56mm/JIP7LEftkNuaXYj/c7HEleHhtVYiYVd/VY2WIq0N3zukxaxRSNswQTPl3 dMteToRbhBRY0fbor6RznrIxN4ovS1hVcSW/1KguK3TlAESI9x4pXmKI1Fcfd+Ksu56d kvw2H6hKFOvXUsggt6obEezK9PsZnYvn8fi4x4Xrl7MpjA2p0aQk69LeVqjaq34M90BE C5qw== X-Gm-Message-State: AO0yUKXLEcOeeovPcFRZK4UhEC/grWMWmMMxWeGm0yplDQiRzj2cPoaS d0gAuAEL352Hr6rGuzIWWd7d9qaSej6yQTMljHnteA== X-Received: by 2002:a05:6a20:5483:b0:cd:47dc:82b5 with SMTP id i3-20020a056a20548300b000cd47dc82b5mr13278691pzk.21.1678068794870; Sun, 05 Mar 2023 18:13:14 -0800 (PST) Received: from stoup.. ([2602:ae:154a:9f01:87cc:49bb:2900:c08b]) by smtp.gmail.com with ESMTPSA id d18-20020a630e12000000b005030136314dsm5048434pgl.71.2023.03.05.18.13.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Mar 2023 18:13:14 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 7/9] accel/tcg: Pass last not end to page_collection_lock Date: Sun, 5 Mar 2023 18:13:05 -0800 Message-Id: <20230306021307.1879483-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230306021307.1879483-1-richard.henderson@linaro.org> References: <20230306021307.1879483-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. Fixes a bug in the loop comparision where "<= end" would lock one more page than required. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- 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 745912e60a..c4e15c5591 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -509,20 +509,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 = g_tree_new_full(tb_page_addr_cmp, NULL, NULL, page_entry_destroy); @@ -532,7 +532,7 @@ static struct page_collection *page_collection_lock(tb_page_addr_t start, retry: g_tree_foreach(set->tree, page_entry_lock, NULL); - for (index = start; index <= end; index++) { + for (index = start; index <= last; index++) { TranslationBlock *tb; PageForEachNext n; @@ -1152,7 +1152,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); @@ -1161,9 +1161,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); } @@ -1179,7 +1179,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) { @@ -1224,7 +1224,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); }