From patchwork Tue Aug 16 20:33:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 597515 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp2701996maz; Tue, 16 Aug 2022 13:51:59 -0700 (PDT) X-Google-Smtp-Source: AA6agR7NONQzHYbyoC48tIr/p09K8vsPkYFlSnjn7YFW8RQTMXJyhGanJ1i5FdDMLtrAK82wszGR X-Received: by 2002:ac8:5f08:0:b0:344:5cbe:c0f5 with SMTP id x8-20020ac85f08000000b003445cbec0f5mr10268631qta.356.1660683119602; Tue, 16 Aug 2022 13:51:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660683119; cv=none; d=google.com; s=arc-20160816; b=IKyJBhie00/msQOyXAX7LDtQ7SIs6InCUBA7gCwUU+YthsgKGxftM2RfXqo2q3+hkz OXbDC6N8XpNyTrcReRkVFxiAufjAPItWV9Q/MtddGGqcJNiO3ph5WXPgG/X4VdGkV5O9 mPzf9vRz82EKGuDrw82hngv6v0XRbRkrNGyMcCImJUMCF6VLrTz17DZ579S9V13EVREr ODz+nflSqV39K4I8Jo8r15C5t9S7PipnpzyPebB+GaKoG79yfXV2Tz0EKDWvgMBFEv1N mprJNeTkwJjyjKD62kSevefdsrDJHtko9HEAX13pCIz4iFnQJxnbSUgG0YvbrTQCxDtF GXig== 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=xG7LkxSPgE8989MOfr7x1M7HWGz1uhuKkBsNsQ7qQC0=; b=p0jdhIr8a2jHHsV4MNk7vNiwiRAKaG3lomRpv7NgIlizjmaPugL6H1EpWhmCxYvmV5 eG6cGhKiQaWQxBw81evnOSOIr9XlPoqHdn8N1Kie+rjoDuWGnHhCdq2Vsek8HAzPTPt1 LD3t+GJpfvj9+9pdgw/KV8BzsTAP25FWxOTYp1KxfnyX+BJwVcnd0F/l2s8NNF3T6JQ4 voNB8jOqU0LN6CY2Babvr7KSGOrJ9tZPqKuaR2ilOfYzE2Zc0KkcXF5i9/rZidPpwQY7 jYeBWG+IuLo3VYfUmVigLgdUtConGQHCQMqujK2KW23pyVcOlujVRywekZbfq11iUMXi q9fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=l3o9QSKT; 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 b4-20020ac85404000000b0031ee8fa5b22si6275695qtq.542.2022.08.16.13.51.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Aug 2022 13:51:59 -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=l3o9QSKT; 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]:45868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oO3Xb-0007Au-6U for patch@linaro.org; Tue, 16 Aug 2022 16:51:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39680) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oO3Go-0004pE-Nx for qemu-devel@nongnu.org; Tue, 16 Aug 2022 16:34:38 -0400 Received: from mail-oa1-x2e.google.com ([2001:4860:4864:20::2e]:36738) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oO3Gl-0004Wm-0k for qemu-devel@nongnu.org; Tue, 16 Aug 2022 16:34:37 -0400 Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-10ea9ef5838so12958641fac.3 for ; Tue, 16 Aug 2022 13:34:33 -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; bh=xG7LkxSPgE8989MOfr7x1M7HWGz1uhuKkBsNsQ7qQC0=; b=l3o9QSKTTKry/OppmEvbfuMu3KtZ/i0MjHa5S66pt3qt3PX8gfq8v4/Qhl+Q9ijLAK 5Y53i0b6MJNyB5Ob9NrWq0wV34dvfmbq4+yCL5syvAHISEYL3ysOtPTOks+S8Yh5qGji J/Eyh7AbafKGEp9PYMyZl99w0GhRD92anwTtsTFNlRqPThJ4hhpjQEu2hDdAr7JCEKVn 76VjRzYeXf46ToEiAi1PYNPDSIUpoCi9dVj/Kq4PUwAeTdqKArPIcwpwF6obD7QnVWy1 /ctYkXcIQWMMb8KX/mD2+7aOUlYaqS1NWvhNHBb/pYK7mWHYBuztTaWuQypay9VfupwL gfyw== 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; bh=xG7LkxSPgE8989MOfr7x1M7HWGz1uhuKkBsNsQ7qQC0=; b=mPwHCb/jCRQ2D30c9CcKLAHfXVAWaOa0i/SGUPR8HX6QUrSmDOh25hNHXUWw528cJg gNPAR/08nM3oV3PzqvL33mloiTldCotm0W/AYuIaj5RR8EdzzRe72hcChwCjUPXvSYAN ysWJkdkGhhTuhkU6bG7Rvg/c6kY/fB1VTebHK1IdzFJCGx7xq7wnxWtzdpMZNbVZWi0A rupzAVsluPbepBrx1DJwYjsR/DJPnUQ60FsDsszeXpMxsUIDyLO21HXastugCic5zrEv wHlzJW0Fi0bxUIPr8EyprIEmWcYkS9T8ylyDNczdUA4IxgCpZPBLMWK+ElwsN7icq1aH UTtw== X-Gm-Message-State: ACgBeo10YKexoy/8YOW8WdUZgwZQyDZS1oi+H8stq/EUcsSp+uV791rW I3uQif9kjNioX0kjit9Lvala7w5hMGGHLg== X-Received: by 2002:a05:6870:b52c:b0:10e:e9e2:81b2 with SMTP id v44-20020a056870b52c00b0010ee9e281b2mr142766oap.75.1660682072397; Tue, 16 Aug 2022 13:34:32 -0700 (PDT) Received: from stoup.. ([2605:ef80:80f6:61fa:9bc2:5095:d612:5e22]) by smtp.gmail.com with ESMTPSA id y23-20020a056870b01700b0010ef8ccde67sm2285220oae.13.2022.08.16.13.34.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 13:34:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, alex.bennee@linaro.org, iii@linux.ibm.com Subject: [PATCH v2 11/33] accel/tcg: Use probe_access_internal for softmmu get_page_addr_code_hostp Date: Tue, 16 Aug 2022 15:33:38 -0500 Message-Id: <20220816203400.161187-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220816203400.161187-1-richard.henderson@linaro.org> References: <20220816203400.161187-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::2e; envelope-from=richard.henderson@linaro.org; helo=mail-oa1-x2e.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=unavailable 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" Simplify the implementation of get_page_addr_code_hostp by reusing the existing probe_access infrastructure. Signed-off-by: Richard Henderson --- accel/tcg/cputlb.c | 76 ++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 50 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 80a3eb4f1c..2dc2affa12 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1482,56 +1482,6 @@ static bool victim_tlb_hit(CPUArchState *env, size_t mmu_idx, size_t index, victim_tlb_hit(env, mmu_idx, index, offsetof(CPUTLBEntry, TY), \ (ADDR) & TARGET_PAGE_MASK) -/* - * Return a ram_addr_t for the virtual address for execution. - * - * Return -1 if we can't translate and execute from an entire page - * of RAM. This will force us to execute by loading and translating - * one insn at a time, without caching. - * - * NOTE: This function will trigger an exception if the page is - * not executable. - */ -tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, - void **hostp) -{ - uintptr_t mmu_idx = cpu_mmu_index(env, true); - uintptr_t index = tlb_index(env, mmu_idx, addr); - CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr); - void *p; - - if (unlikely(!tlb_hit(entry->addr_code, addr))) { - if (!VICTIM_TLB_HIT(addr_code, addr)) { - tlb_fill(env_cpu(env), addr, 0, MMU_INST_FETCH, mmu_idx, 0); - index = tlb_index(env, mmu_idx, addr); - entry = tlb_entry(env, mmu_idx, addr); - - if (unlikely(entry->addr_code & TLB_INVALID_MASK)) { - /* - * The MMU protection covers a smaller range than a target - * page, so we must redo the MMU check for every insn. - */ - return -1; - } - } - assert(tlb_hit(entry->addr_code, addr)); - } - - if (unlikely(entry->addr_code & TLB_MMIO)) { - /* The region is not backed by RAM. */ - if (hostp) { - *hostp = NULL; - } - return -1; - } - - p = (void *)((uintptr_t)addr + entry->addend); - if (hostp) { - *hostp = p; - } - return qemu_ram_addr_from_host_nofail(p); -} - static void notdirty_write(CPUState *cpu, vaddr mem_vaddr, unsigned size, CPUIOTLBEntry *iotlbentry, uintptr_t retaddr) { @@ -1687,6 +1637,32 @@ void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr, return flags ? NULL : host; } +/* + * Return a ram_addr_t for the virtual address for execution. + * + * Return -1 if we can't translate and execute from an entire page + * of RAM. This will force us to execute by loading and translating + * one insn at a time, without caching. + * + * NOTE: This function will trigger an exception if the page is + * not executable. + */ +tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, + void **hostp) +{ + void *p; + + (void)probe_access_internal(env, addr, 1, MMU_INST_FETCH, + cpu_mmu_index(env, true), true, &p, 0); + if (p == NULL) { + return -1; + } + if (hostp) { + *hostp = p; + } + return qemu_ram_addr_from_host_nofail(p); +} + #ifdef CONFIG_PLUGIN /* * Perform a TLB lookup and populate the qemu_plugin_hwaddr structure.