From patchwork Mon Mar 27 21:18:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 667410 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp1314653wrt; Mon, 27 Mar 2023 14:19:55 -0700 (PDT) X-Google-Smtp-Source: AKy350ZLKeFouTyJ6tLYp4NcDJyKpZNZk04Vdfs6vybsQ1R19ukXGPTFEl6NbZdwxQ5HI0mJAAhg X-Received: by 2002:a05:6214:e8e:b0:5c7:d03c:f2b2 with SMTP id hf14-20020a0562140e8e00b005c7d03cf2b2mr20127442qvb.28.1679951995309; Mon, 27 Mar 2023 14:19:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679951995; cv=none; d=google.com; s=arc-20160816; b=c+nh4irz6zH5Zfn+bWIgnARlOcTDIOjDZ91iMQajpeWtMfHvzAAVHLBb3GbkNBApjf IEshVx4snGIllyfHQPakq+DmdVQDLv1R2DhhRUkU50EdSDdakz7RTE+4yrf/H++a2MSm VZlyiCtY1rx5MigkqdAvPPWGdl1MBBpVeKlsX9wG1sJTI7F3IvSLbyc4FkK5QfUImJlg hDCy//VVkGu+OqM0pwFTSk1B7Qnzz6t1IhNo2Cccon+zsdlXm9uM0LPuNIVAfDZ+Fe+h yCjztaxMpki2OL5RzCdhbmUYrS/NTqyVlp3iMGezViuT9uWjHX+uD6rkx4wObw4k4vz+ vlRQ== 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=OKXpyC7VGHMnjJkmA+No4Ch+oHJAGd3F6mhTFsBVzZt7lBBSxwrkldYr8//Rvow9kH LY7HSEg+d6yVZcZygT2sDNoJ396cXA53440sIZY3Yu6lgz2phhdsDSxJa2Y5S7yWWc9/ rRtRWNMIh51YSEqgaMs0DFIN04rvqR/Rv4ulx+RlvISuDzg5JzfeunlyNnDPVw2LN+7O /vIdyGOihVYhl431OkkdSUZzCtussm6dsUIfWZmJEh5DowLegbSUZYiEMf0So7QOYZcI ityf4kGqOD+2aZPtPRL5OQv84b7TuZUliGlfjRS8T5bh8pGhTVKOXb09gHi/DS8I2zYf aFZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=u6542RlU; 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 p187-20020a3742c4000000b00748750a33adsi1414618qka.261.2023.03.27.14.19.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Mar 2023 14:19:55 -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=u6542RlU; 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 1pguEh-00046E-G4; Mon, 27 Mar 2023 17:18:39 -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 1pguEe-00044i-UU for qemu-devel@nongnu.org; Mon, 27 Mar 2023 17:18:36 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pguEd-0005wq-2j for qemu-devel@nongnu.org; Mon, 27 Mar 2023 17:18:36 -0400 Received: by mail-pj1-x102a.google.com with SMTP id mp3-20020a17090b190300b0023fcc8ce113so13147681pjb.4 for ; Mon, 27 Mar 2023 14:18:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679951913; 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=u6542RlUtm0RAqWUesOoJpQ0ckVGNHlJ8P9bEPA30gOwkgkcK2kuUBRrC2RuGWCTyp Q9lxayrWgmZDIbvSwZ1+hAdUMTeNkVYBZ+HLRjaWq5/jGkSD3TljzP4KuidhcnKRMu9n hi0ytnMm8ifDZXzOIFJ5E7aANS4eArlyktJ4t9NI8FNYIYB1ePcCx8qP96qgyHeqJAcc eK3wVxoWWUiwXq6w+RvQz8GtR5FTTcB3TImkeOT4icjE0aTeyX4P5W7783QK9wEe0cyO 4qhCSZmvq9Ig2bIOrjC7QKB7q4zCh5J840RZWTZTk5DgP+3Kqsu2KCRyN3sx1arLX8/4 KQ4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679951913; 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=mreQskm3mzNX7tQPNtwjkPaOYE7CmALZaLf2uw2/3WIWY5HWeqHxs3CdyTzBWRhn3a eAw9DPwnD+hdv2mBIV7SJc0YgwPVIOlLbA3yHA4MDDI/K7tDtMkdIbfP3iri+86VedX6 ifm40xDjMZbjW/2rw3ckkzmVzdwUel3BKHYwDYcAIjiaF7ue1AYbGPcHBXQGBOK1TVRZ xeq1SK9gXm4aznM11jMd8KKwieIs2Qw6Ooh3MNOFVJmOs/SMNG8aJ3Eh1aM4JXHWftRP ekweaxsacfdxf3OT5A7zSTy7Zv+2ux7nE2gq4TQ2d3XsPUapiJQyw0F03+nxfoDs7sdB nnfg== X-Gm-Message-State: AAQBX9c8phvVmS1xrnxr23V/reySNDaDlTeA6yXEecSCk8Unh133HpoC hwRtz7Uc/PgwSQyqu9J3bVXiHKWvCmKj31Wo2Go= X-Received: by 2002:a17:90b:4d12:b0:23d:c49:3875 with SMTP id mw18-20020a17090b4d1200b0023d0c493875mr15044961pjb.33.1679951913009; Mon, 27 Mar 2023 14:18:33 -0700 (PDT) Received: from stoup.. ([2602:ae:1544:6601:6705:aa17:3641:e634]) by smtp.gmail.com with ESMTPSA id d2-20020a17090a6f0200b0023440af7aafsm7902708pjk.9.2023.03.27.14.18.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 14:18:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, philmd@linaro.org Subject: [PATCH for-8.0 v2 08/12] accel/tcg: Pass last not end to tb_invalidate_phys_page_range__locked Date: Mon, 27 Mar 2023 14:18:20 -0700 Message-Id: <20230327211824.1785547-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230327211824.1785547-1-richard.henderson@linaro.org> References: <20230327211824.1785547-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.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); } /*