From patchwork Fri Apr 8 16:47:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 558859 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp504081map; Fri, 8 Apr 2022 10:02:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzx5lGz12Uca4cl8GDYSEAHSXpcHBS/eu5hPUNvS3mNKLdp4KQ2Xr5aR+bk/k9dsE9KJxWv X-Received: by 2002:a5b:488:0:b0:61d:a178:68c9 with SMTP id n8-20020a5b0488000000b0061da17868c9mr14997011ybp.554.1649437349872; Fri, 08 Apr 2022 10:02:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649437349; cv=none; d=google.com; s=arc-20160816; b=iLJUn//MCRMmmXSLrV52WSLtvBY3nFXxDQBwFeTL9ooyNiNp/X3s4rM6GCleVKQlfl HbK04KA7xGDd/EhjTKvtBZQ4YbDKIIaAuuCaY1ZkV0OSf0OcSi6W/8crozV/xpt72lap +vjugXm1EYcc3L/M4wxfPp3VzwnQ4qEGPDJckndSarVMf+p6YGHb4Hd2I4C9hPpVql+U sTKcQ/+0dancC1wRR/MgHNRS3OPPjH7/o8EMQjTAvtwDlWvEjtqreC51ZiCtIrYPsLz/ niBB/9FW3sHT4b0WGD0EwI+4SvwzszTFmh80w1bbE9lPz01XEMmuDdAwkDBdyuzrbMbf no8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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=8RvB6WmUyabhe4EY+P1jACVM2phgaOzNjeVgtjqCztg=; b=Braanzl0RZ0dH762EwaIjVSuiRMUQAiPWe2OL1airV8cabJDafxaGgP+enjPIQWuP9 l+seGpmrJKUahW0RMTAAjH98wu5NMA6/mWbIHh7nNM7qIt5TZJHujllYf7uCb3UHEYm/ gjVZC6Mxe9LCCez6QYPqeYh8YZY1iV+tOWLFntBw9e24zaqZGWrU06h0lb9iWPmInogO bcj0EjKp49ZcnxyBpkMnRmDfO8K17aYPKHFG6q75TYMubzvCs3r4kv+HdouP+CC0vZmH 1t7WczYUzxx8SSt416EEg54cFY6gKgpKYLMz1wYXXsqcJjGvucWiiW/ep9UQdwxnik1Y HHdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=YpXssetP; 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=fail (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 by10-20020a05690c082a00b002e5bb9dcaabsi758356ywb.308.2022.04.08.10.02.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Apr 2022 10:02:29 -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=fail header.i=@linaro.org header.s=google header.b=YpXssetP; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:52432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncs0D-0008CT-Cm for patch@linaro.org; Fri, 08 Apr 2022 13:02:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51354) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncrso-0008CL-5Y for qemu-devel@nongnu.org; Fri, 08 Apr 2022 12:54:50 -0400 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]:43958) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ncrsm-0003u2-L5 for qemu-devel@nongnu.org; Fri, 08 Apr 2022 12:54:49 -0400 Received: by mail-ej1-x62b.google.com with SMTP id bq8so18457775ejb.10 for ; Fri, 08 Apr 2022 09:54:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8RvB6WmUyabhe4EY+P1jACVM2phgaOzNjeVgtjqCztg=; b=YpXssetPCMJVAp5fK20w2bhQd4q7LP8J3hqTsHNiYj7E/PGrAAZMWvf7MnoOI3x3+w jnuNQzMprrqlYP0VCtAdVQfwm6bg1Sa7SZc+MyZvJFJXE+BMVQJw0T6esEnL3txH6of3 huURKwVbMxDiqXK36jrsHHbpK+eqp06VDZ/eWWMldGgiLIdCFPSCFyNGv0ZgqrR0mKr+ iLEKY5wFPlIvKXIoQr1VQtk3k68DFb4A8ddt6yJXrpiCgyFrDEMnmSSWgJUJuTU/dDla i4ppY8oJsb8iLYFMAHYjNxzE/kv2pgjdnDpZApOQsaamNOXRvWdf8xxBKaxadgC9xUw2 LH+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8RvB6WmUyabhe4EY+P1jACVM2phgaOzNjeVgtjqCztg=; b=BEfw+vzQNM3Mly01RjWjU4jAuBNt9UITMFzMfjvzkVvZXaGu3+trUGceSqCWX/YNH1 mXe3sDJrjamOA1379EgGsnZUBcEU3Q6W22z+pVf0QG+w7qt8sJth0b6Wq6BbvmixK8hJ vCF5HbVghuHQ2P4aqQ7bcvuTib8kBJG/dNvDXxoI7isXl6x0N/i7C/sZsSokg5arhXKE jJ2Ity4t/OFsOgQuYk0vjf8MBNAwukhFHl/d18WodzPoY4QaL+hAKh3o60MT1ZuMKOLF yyNAlJeuZ7n5D7ZusDbqZCvPcYriwLa7ZZKlLABgXEbkfca+AWtAqV5jWjNLvDsu/pzh 1mkg== X-Gm-Message-State: AOAM532RiEp/eeHILjAen1b+d2ngYbIy0qj5h77rKoyUE+cF1BgFRUSq H+Iep8BWCLnMivFMww3TB7Jt3g== X-Received: by 2002:a17:907:8a13:b0:6e8:289d:c744 with SMTP id sc19-20020a1709078a1300b006e8289dc744mr12274489ejc.150.1649436887070; Fri, 08 Apr 2022 09:54:47 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id h7-20020a1709066d8700b006d4b4d137fbsm8914280ejt.50.2022.04.08.09.54.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Apr 2022 09:54:43 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B9F681FFC5; Fri, 8 Apr 2022 17:47:45 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 15/15] accel/tcg: add heuristic to invalidate al TBs in a page [hack!] Date: Fri, 8 Apr 2022 17:47:42 +0100 Message-Id: <20220408164742.2844631-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220408164742.2844631-1-alex.bennee@linaro.org> References: <20220408164742.2844631-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62b.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: fam@euphon.net, berrange@redhat.com, stefanha@redhat.com, crosa@redhat.com, Richard Henderson , aaron@os.amperecomputing.com, robhenry@microsoft.com, f4bug@amsat.org, mahmoudabdalghany@outlook.com, minyihh@uci.edu, cota@braap.org, Luke.Craig@ll.mit.edu, pbonzini@redhat.com, kuhn.chenqun@huawei.com, ma.mandourr@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= , aurelien@aurel32.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is a dumb attempt to reduce to the execution time of UEFI booted kernels and almost certainly not what the final solution should be. The problem is if we have generated JIT code from running firmware we can spend a lot of time carefully invalidating every TB in a page when the kernel that eventually boots and clears all the pages in RAM. This fix simply assumes any write to the start of the page should invalidate everything in the page. Once that is done following writes to the page should all follow the fast path. Signed-off-by: Alex Bennée --- accel/tcg/translate-all.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 625c46dd9b..67884260fa 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1830,6 +1830,16 @@ void tb_invalidate_phys_page_fast(struct page_collection *pages, uintptr_t retaddr) { PageDesc *p = page_find(start >> TARGET_PAGE_BITS); + unsigned int nr = start & ~TARGET_PAGE_MASK; + + /* + * Assume any write to the start of the page is start of clearing + * the whole page. To avoid coming back multiple times lets just + * invalidate everything first. + */ + if (nr == 0) { + len = TARGET_PAGE_SIZE; + } if (trace_event_get_state_backends(TRACE_TB_INVALIDATE_PHYS_PAGE_FAST)) { TranslationBlock *tb = tcg_tb_lookup(retaddr); @@ -1850,10 +1860,8 @@ void tb_invalidate_phys_page_fast(struct page_collection *pages, build_page_bitmap(p); } if (p->code_bitmap) { - unsigned int nr; unsigned long b; - nr = start & ~TARGET_PAGE_MASK; b = p->code_bitmap[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG - 1)); if (b & ((1 << len) - 1)) { goto do_invalidate;