From patchwork Fri Aug 12 18:07:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 596824 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp1788255maz; Fri, 12 Aug 2022 11:28:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR4YLRo//MpGdBT/k5V2610/OkCTnLKKS5vmTkbhmaEP3x0P4pVZzeAWwdHh5Rmw86XpsvtI X-Received: by 2002:a05:6214:f24:b0:476:72bb:2473 with SMTP id iw4-20020a0562140f2400b0047672bb2473mr4777060qvb.82.1660328881612; Fri, 12 Aug 2022 11:28:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660328881; cv=none; d=google.com; s=arc-20160816; b=uYhl7X09qfVWyBHXbqGOh4bJBTtAgVvewocrDx1dwti0FfO3VTOuR8CaFs8+DB+Aw0 tPRy9snbY7tvxjV2gam32rIAJKm3AGhhyebPSIUaMTBDijpkkxKkcrb4gsULnI3xGruq +wIJtOQjqmfPgYwmr/NVIu0XHibH20QB2tHJmf54ZuprFls/nRrIJABHVNK6khq5p4v+ tQbqoOshX1ODZJCUXBNQNFos+BdvR/6LoOPWtHPhfTMKKJhhHq+IhsOianPCzz8yafdJ cgEvgpTWtFFjxCsyL1lxVFYuvYU8E+zZhdx/iqP+YibJVRjrwyPpTXooT7ta6l/HJp4Q S2HQ== 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=KvJKsEm3DipLqatiPhEHBuzHTGj14MXGYtIryj606BQXkEnXvuEUzKKVg+k4E6qmkV nHcy+MtkrGRGHAvlNX5pXnhaanApYN6ydexEyQqERSxRk+oQcfahbzo2QDmh6KGdq4ty +WlbMwsjYFppUeMItfgufitgoU72Air55NzI/48JXXp2VJz0hfRBFVilrky7LxXtgh9P Ew59MTmAZizoYVEpA70L7Do5yiQJPqS15q1BcyzVWIqE+BtQ3kHNxnUgJzCER/cXnDFr ixJfv2Yn/N9wG99/0VVtdn+eGhrf0qrlybamLcmz+WkvNP1gQXfpV5FAMeKtSKP939Wn jUqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P2KJKUyy; 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 20-20020ac85954000000b0031ef4ac10cesi2009060qtz.687.2022.08.12.11.28.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Aug 2022 11:28:01 -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=P2KJKUyy; 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]:40686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oMZO5-0003Y6-6q for patch@linaro.org; Fri, 12 Aug 2022 14:28:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oMZ56-0003Wh-Cq for qemu-devel@nongnu.org; Fri, 12 Aug 2022 14:08:24 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:54179) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oMZ54-0006Wj-P6 for qemu-devel@nongnu.org; Fri, 12 Aug 2022 14:08:24 -0400 Received: by mail-pj1-x102e.google.com with SMTP id pm17so1669115pjb.3 for ; Fri, 12 Aug 2022 11:08:22 -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=P2KJKUyyI1v8LWlO0sJ20TNjeZrkSaT9cGW+YXMMjeU/hB7XAQVzR7XH8zurWi/xaY 3nbQu4fGMtCPWrurDM/odsLTD3SwSHP7ya4F/LDjOvjnHyZTufcRz2XmXYQjhD2J0wkB eAAK0N2GBiYPvx93pJ3UyDnMvucQscjXlHiCNz3WEh0/VVOnQUzIevurMe4d8LCRpAnB v+dybmpp5jAc1boIG3LW0GNTbGD72Cf08lQm0fes1m9Ae9XVYa4puCQV4VkKfeOh1FI5 gQdUtf/Khe/dBcWA4uS8ih56tmAG7xrMLTVOD+uWcarLVnVxkYa+Cf2hbON806+QryIs kUgw== 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=cBuqLnDQFHcdlw2bAUu4KnMPqgpujVZoSzUA64rTzd6IjBEg+FW3BiREikN5xCKfEk FsLbGqxJNjpik+L8i2nGs+yxyggucSebFpqfUhhh9x8i8Qxp5u1j22LoJOZ6NWKJYzjV A4q11mzWVhUQI5I8BEUcIGexROYS4RcnjHHGqCwQfXnT5N5OL+sBsslZmBxOUcz8OKpS D+07glP3iqCgiQ5gSvlwdJtFoI33MDary/EnGzrFT3ODJTD+lPQfjh6i0mJA6KgxO8BB /9IILets/gl2o6Zo1JHbiwp09ERugNlXpmvNJrSQlmxf7kA8sYtzq/GCGqpFDXcmeryi bqNg== X-Gm-Message-State: ACgBeo3muiNwlmmeA0jVvtfUZdW378WKOYRGHyytKznn/4T3aGqYBdPN UXvNMzLfR927G9/N0Nv5AD31+oiVFwEnPg== X-Received: by 2002:a17:902:c401:b0:16f:b59:85a7 with SMTP id k1-20020a170902c40100b0016f0b5985a7mr5136106plk.115.1660327702039; Fri, 12 Aug 2022 11:08:22 -0700 (PDT) Received: from stoup.. ([2602:ae:154e:e201:a7aa:1d1d:c857:5500]) by smtp.gmail.com with ESMTPSA id h9-20020a056a00000900b0052dee21fecdsm1914761pfk.77.2022.08.12.11.08.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Aug 2022 11:08:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, iii@linux.ibm.com, alex.bennee@linaro.org Subject: [PATCH for-7.2 11/21] accel/tcg: Use probe_access_internal for softmmu get_page_addr_code_hostp Date: Fri, 12 Aug 2022 11:07:56 -0700 Message-Id: <20220812180806.2128593-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220812180806.2128593-1-richard.henderson@linaro.org> References: <20220812180806.2128593-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.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. 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.