From patchwork Thu Sep 1 06:52:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 601812 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp271869mae; Thu, 1 Sep 2022 00:39:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR59Y9n+4XbpMu0nQkP4v/Z304MtRvQ7dcAsAAAQ++llMUrNdU24vSajtJqvCo76IkyeI+rT X-Received: by 2002:ac8:4e4f:0:b0:344:a6db:1b58 with SMTP id e15-20020ac84e4f000000b00344a6db1b58mr21829092qtw.38.1662017984898; Thu, 01 Sep 2022 00:39:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662017984; cv=none; d=google.com; s=arc-20160816; b=umwpSy1ac9s13wIAn/IuMyc/IFTBWm+jKCnxGcjSgo+jPdcx2MPrfmWgLs/LaCWzU8 T2I4GUWMk9+nMT16PMhHsYFQ8vrXmthi9aMoaEkgnDW/c4tJVzyCSOMTO8NNnc7O3Hem gRK5JdohT2dtKA8FSLRTfOT9hcHyBb1Vf90bdTKsVZrCPFbL3mQkN+ShYmipiqHDRnY2 nV/ncmEvXcdqVftM3jM0w+YtXBo2Bla1VYoWF6PbnNvAg9wFMFYajP6HfgCwaGNnvTMp eHdRHXs18Ggfid0u9YVCgHRDCdZOsYAXFRW2XidWXNgGkneUSMCOslvjI17lGGpT1U6+ vgiQ== 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=aenCwLhyHz+42ttancSjHI4JZk2Ya2FL+nx6M3jTwMg=; b=W/JeVFl1WHoWqzYB781WTnkzaVet6p2fnO7QwZc3mvHamxzc/WK4DkJPyOpk43LN1f KNnhi0LKJsSPIXYqR5YX0a0/7sXO+uDmyJIlKFsVA5EA3CSnjg6sgqRXhNYNkOWEF2A4 VlIEsKmqHS6FTZKlU9Yt6LKjpq7Y2Q0oB8/gjatKvdy0FmSt/kQuaVB3uGYCa0/H2xoT 1Q5Wxlpco53a9WQOM9ptXntBgQIbDy2Y6Z33jAZBq2MFWgeRUjqnspGVqn52XneZpllx Ae5dWPdCyAm+vn80XmzwnbZ5YjQHNVDy37QJ6NvN+Khvi3Rhqo7n0he9sZWHK73F10NQ hJng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z2D14sNY; 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 r15-20020a056214212f00b00496f3e26879si9274239qvc.331.2022.09.01.00.39.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Sep 2022 00:39:44 -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=z2D14sNY; 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]:35372 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oTenc-0005ep-GL for patch@linaro.org; Thu, 01 Sep 2022 03:39:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55018) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oTe4W-0005yn-6Q for qemu-devel@nongnu.org; Thu, 01 Sep 2022 02:53:04 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:39717) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oTe4U-0003Gu-E0 for qemu-devel@nongnu.org; Thu, 01 Sep 2022 02:53:03 -0400 Received: by mail-wr1-x435.google.com with SMTP id az27so21015919wrb.6 for ; Wed, 31 Aug 2022 23:53:02 -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=aenCwLhyHz+42ttancSjHI4JZk2Ya2FL+nx6M3jTwMg=; b=z2D14sNY3YduiJeshwg3aEXmGQfRy716YpLt9ZO7I3RVYi8t+F3lK4ygqiYQzos1R2 o/iXxcyyacdJ9jm/kfJrDgc3alaruPfLsub/bf8kA1WA1FPdDA/s9KdHjnrWabR2KWqQ nnEijWsDqwsTY0QXCQ6uC8uCiZi7WhOqxnVVan74+BN8cqnqVuDjo847lzEvd3T5LPYf h4x128WYje/JjPQ9J4tJx+HKm/pGtn2x69sIeyz7wS4sVW4IjDgUdG2zGhWMEjX4SZC1 Auck4hQvwi+Mh3ozGHMq+PAGro68qZLbvMfBCvPeyWKoBLRtMXpjsZxEud3IvnYfkpUe CYUA== 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=aenCwLhyHz+42ttancSjHI4JZk2Ya2FL+nx6M3jTwMg=; b=E5WJxtE1YStRpVVTsZOAZvdkhn/lnDBmrf/Zi2XdoUhQE4tJCf1A3nKjebZWHuA7nL MCbUZy1KNinEwHhsFFVyLTzl8+u3J/eE5GwM1+FOe7E6ok4MFv/WSVS+/168tn5qvK1m ZQ0RcoJuvEdKqr8AtKsJzDZEGpwtNCMXrHpwLVdfbukkheM52EfslQHUPS1AAXFioOPv 9gjFiWWDjhubCnVLXVoYbPYdd6kz2pk+l3/eG0mmYjyHSoitztCovTUBNgttfaOSHfsC /Iq03+SOvtZS+jkSG77iSJhyhvwj3LRGaH9rqxiQ+67O4MJAAYc0T4DIhXzXZJnaH/dy RIIw== X-Gm-Message-State: ACgBeo1bQhzhD2kKVBwD+6xNU7h78Z+KS7AWxqUfREwTFXaxfPZPCYI2 77gv+xGksNQP8X7GuoEpjoUhioaqt+TfZcwc X-Received: by 2002:a05:6000:81b:b0:226:bada:a5 with SMTP id bt27-20020a056000081b00b00226bada00a5mr13699436wrb.539.1662015181647; Wed, 31 Aug 2022 23:53:01 -0700 (PDT) Received: from stoup.. ([87.192.221.83]) by smtp.gmail.com with ESMTPSA id a6-20020a5d4d46000000b00226dedf1ab7sm8308153wru.76.2022.08.31.23.52.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 23:53:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich Subject: [PULL 12/20] accel/tcg: Use probe_access_internal for softmmu get_page_addr_code_hostp Date: Thu, 1 Sep 2022 07:52:02 +0100 Message-Id: <20220901065210.117081-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220901065210.117081-1-richard.henderson@linaro.org> References: <20220901065210.117081-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x435.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: , 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. Acked-by: Ilya Leoshkevich Tested-by: Ilya Leoshkevich 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..8fad2d9b83 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), false, &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.