From patchwork Wed Oct 26 02:10:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 618774 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp114566pvb; Tue, 25 Oct 2022 19:22:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5kLhDx+4PYvEi0ETa86yuSu9aig8s4czfmykKNjZ4svxsLsCDbmaei3njrj5ZI/VA/b09n X-Received: by 2002:a05:620a:2493:b0:6ee:dae9:4009 with SMTP id i19-20020a05620a249300b006eedae94009mr29224688qkn.423.1666750967023; Tue, 25 Oct 2022 19:22:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666750967; cv=none; d=google.com; s=arc-20160816; b=yCf6VXCHQlmemE13flJ4v4C9lO17B47GnrkxfzSsHs6JBb0noEAxAqqnx1ey95h4ez xVWMSolpKKW3vAjikqBnQ2xqcAFdFXel6Ja/bC/zaKkl9Tfp0ie971AfU45TmHXsOSMR QphFNH5XISosxXkI7d08TSyC8waAOklebEC/e6K+XtkqWVihr80CEvzjPKL4x5DD760a /go82akVnE0rLlQMLtjTMttKdNTAcd5EDOFl1e755Rqp2Fcq+ZM1RNw9Xe8vMRk0RNNH 0BfFnr0uPfY2X0mjAvXJGUkdBaixBSwwNokRQ/S2VxGD1HutSChe4Yh0SvOPPvwer2lk xOVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender: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=su7SRG6mA4EK+3Nl1nKtKV8hb+mbjAByRO+UTdDwjN0=; b=SOoNQtp1vd7CrDZ/AZq2XxKvwmw931ooVUOFL4w2RDUztbsCMsAf+tCxlatzY58tFB ReFDZGCK2PS6q0TOjpgkUjNNHFyrywQOr/3ZbSPmmspgAVWVIoOcw0JI4UWVG7Amym15 eVM+4NtyIBXyEvUIYWrQQOf559g1OanxeCgOqEMJpT0pvPvagUe5rvEr/qsVhZEJc6mP JNXG4s+flPe2TLgoeM5WgpcSq4ikZ9gn0v2tKi/WDkLIU0K6fZbjthZt+ZtH6n7U/5CI elakI2/3a1NQY2kQv2x4uwlQ8ZghNNB3VozURVMdXa1kjFeGnvH/zvXHdpLvgoDVatfd AOrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AN5Sy4RY; 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 a1-20020ac85b81000000b0039cc8321725si3077117qta.286.2022.10.25.19.22.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Oct 2022 19:22:47 -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=AN5Sy4RY; 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 1onVu4-0004yQ-Vj; Tue, 25 Oct 2022 22:12:25 -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 1onVu3-0004yG-2S for qemu-devel@nongnu.org; Tue, 25 Oct 2022 22:12:23 -0400 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 1onVu1-0001EB-DR for qemu-devel@nongnu.org; Tue, 25 Oct 2022 22:12:22 -0400 Received: by mail-pj1-x102c.google.com with SMTP id m14-20020a17090a3f8e00b00212dab39bcdso1078581pjc.0 for ; Tue, 25 Oct 2022 19:12:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=su7SRG6mA4EK+3Nl1nKtKV8hb+mbjAByRO+UTdDwjN0=; b=AN5Sy4RY/pCtkYuTYQAYfVNLnO2S86ypK5qqiCs+TZUM3ZUCoqdIc7LOy2V01JSuYj K6ox1X7jnjZ3p6qV9rVsSiT4IeHYyCYlpba3aBXJt5589ew3wY1cZG8rQ2ZvRJjoZaTd ZtoHsTAowdwLttAGURgeFlXbWkv8QI2AR8w2633c42xyQxJTAB6hatEqGYAZ6ky2AMJ9 2r1XoPryPsCyAK60nW39+LYNiKDP7Y6JSZvUZia0D5US57iHe6qh0KcfcUgqEoPxQeyF 4ViaVD1ulyr4AjCsuRI/6+MfDmH1dVl+VD5qqplNSsXPX1+d0tbeJwfgg08GoptJoytK DTAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=su7SRG6mA4EK+3Nl1nKtKV8hb+mbjAByRO+UTdDwjN0=; b=53Bw7depUD5agb7e6DbLSaCmDzdwHsGAf94ygC5naouh2OLt3Rgo41RMIlaODosIux 97sTpFeHChh6f6HgGmEwFxJNj7rlD2K70XO9R9VhVcJ0LEzh3ZVDuHi4Cn0fk34dsAqM iq2gcYbxB6qzSqUkB/LcajYk2kvh1+fUhIQfmSpWv4YpRJ2dlqKBqWGfgWFiCA5dOVVq lHuoPf4tqc+jsOvr3p7L9f7J0DB5EPkAVMplQdXC2gk+F4zaaXgShTwT7xca4+BH6Jbo r/N7hKvQUiY6/jxIbhuw0GgMFuMqATkw9q3DmIjzUxef9/q2UxrgiO+bTwcxrnG9HciI M5gQ== X-Gm-Message-State: ACrzQf3vfn0w9ZO9G52ZiWO/XPgs9eTYBwxW1VBwnUDNYwEIsq+3NxyI AYH+t28Y4FDCMXF/z0s308AMx/gQzmHjk4N6 X-Received: by 2002:a17:90b:4f8a:b0:213:48f0:296f with SMTP id qe10-20020a17090b4f8a00b0021348f0296fmr1520582pjb.140.1666750340051; Tue, 25 Oct 2022 19:12:20 -0700 (PDT) Received: from stoup.hotspotlogin.services ([103.100.225.182]) by smtp.gmail.com with ESMTPSA id o29-20020a635d5d000000b0043c9da02729sm1897833pgm.6.2022.10.25.19.12.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 19:12:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 20/47] accel/tcg: Call tb_invalidate_phys_page for PAGE_RESET Date: Wed, 26 Oct 2022 12:10:49 +1000 Message-Id: <20221026021116.1988449-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221026021116.1988449-1-richard.henderson@linaro.org> References: <20221026021116.1988449-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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org When PAGE_RESET is set, we are replacing pages with new content, which means that we need to invalidate existing cached data, such as TranslationBlocks. Perform the reset invalidate while we're doing other invalidates, which allows us to remove the separate invalidates from the user-only mmap/munmap/mprotect routines. In addition, restrict invalidation to PAGE_EXEC pages. Since cdf713085131, we have validated PAGE_EXEC is present before translation, which means we can assume that if the bit is not present, there are no translations to invalidate. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- accel/tcg/translate-all.c | 19 +++++++++++-------- bsd-user/mmap.c | 2 -- linux-user/mmap.c | 4 ---- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 8d5233fa9e..478301f227 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1352,7 +1352,7 @@ int page_get_flags(target_ulong address) void page_set_flags(target_ulong start, target_ulong end, int flags) { target_ulong addr, len; - bool reset_target_data; + bool reset; /* This function should never be called with addresses outside the guest address space. If this assert fires, it probably indicates @@ -1369,7 +1369,7 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) if (flags & PAGE_WRITE) { flags |= PAGE_WRITE_ORG; } - reset_target_data = !(flags & PAGE_VALID) || (flags & PAGE_RESET); + reset = !(flags & PAGE_VALID) || (flags & PAGE_RESET); flags &= ~PAGE_RESET; for (addr = start, len = end - start; @@ -1377,14 +1377,17 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) len -= TARGET_PAGE_SIZE, addr += TARGET_PAGE_SIZE) { PageDesc *p = page_find_alloc(addr >> TARGET_PAGE_BITS, true); - /* If the write protection bit is set, then we invalidate - the code inside. */ - if (!(p->flags & PAGE_WRITE) && - (flags & PAGE_WRITE) && - p->first_tb) { + /* + * If the page was executable, but is reset, or is no longer + * executable, or has become writable, then invalidate any code. + */ + if ((p->flags & PAGE_EXEC) + && (reset || + !(flags & PAGE_EXEC) || + (flags & ~p->flags & PAGE_WRITE))) { tb_invalidate_phys_page(addr); } - if (reset_target_data) { + if (reset) { g_free(p->target_data); p->target_data = NULL; p->flags = flags; diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index e54e26de17..d6c5a344c9 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -663,7 +663,6 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, page_dump(stdout); printf("\n"); #endif - tb_invalidate_phys_range(start, start + len); mmap_unlock(); return start; fail: @@ -769,7 +768,6 @@ int target_munmap(abi_ulong start, abi_ulong len) if (ret == 0) { page_set_flags(start, start + len, 0); - tb_invalidate_phys_range(start, start + len); } mmap_unlock(); return ret; diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 28f3bc85ed..10f5079331 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -182,7 +182,6 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) } page_set_flags(start, start + len, page_flags); - tb_invalidate_phys_range(start, start + len); ret = 0; error: @@ -662,7 +661,6 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, qemu_log_unlock(f); } } - tb_invalidate_phys_range(start, start + len); mmap_unlock(); return start; fail: @@ -766,7 +764,6 @@ int target_munmap(abi_ulong start, abi_ulong len) if (ret == 0) { page_set_flags(start, start + len, 0); - tb_invalidate_phys_range(start, start + len); } mmap_unlock(); return ret; @@ -856,7 +853,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, page_set_flags(new_addr, new_addr + new_size, prot | PAGE_VALID | PAGE_RESET); } - tb_invalidate_phys_range(new_addr, new_addr + new_size); mmap_unlock(); return new_addr; }