From patchwork Tue Aug 23 22:05:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 599492 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp2741129mae; Tue, 23 Aug 2022 15:16:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR5+Q2cXZewNQkIRZfABfA9BeweXfQoI73lbVbLpiQ2OeA/5taYBg341oRbmSDBm1tgGR32z X-Received: by 2002:a05:622a:13c6:b0:342:f6c7:5305 with SMTP id p6-20020a05622a13c600b00342f6c75305mr21952266qtk.348.1661292963722; Tue, 23 Aug 2022 15:16:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661292963; cv=none; d=google.com; s=arc-20160816; b=p30MSYIWDPspOHXKTB/48XdQiFwrCC02GYDLxjtBaGJTmWtIJarancqs3KoxQ5GgID hb7zSdVD9z2zsbKUvldTbkF3X4w/f+7+49tXF9HTuL0hjM/58L31BrK65wpKfwyeIoBs 0sRKtqTMsdn5785IDGQ539Tcyu9GZ7IFXnZncGFbusJcuMilHq9/9BWWAQ9ZwNX7WKx8 mOpNX1eAxubzhDObmpHEuTwsdV1pJKsa10/id7M9Sn9Vz/q1Wcja93/xSE14MEQfKdkJ 2go0tuJ73g7f53QhcmtM/w/Ee7NneHoy6LDhiFK2wUMvm98RbWUT1suG+BaX4QTy9Md1 upxw== 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=ECNyBioIYFSxThQipqYF099TV03eKmjseYNKJpgjvci/XGzoH4cFrJtJwURd6lzrke k8KYr6UKZioLEIdgo+aiCNEjThJ8yWZwSyBa1Ub0KWA6c6H+WGCiCUv2uagyXfBnjDls o07D2nl622T2ADRBWBHgyqJ6z0E8jqDw7l+NXf9+Muo9h772LXwS7Iz4UFpGbgihKSCm 6GaRTwlI6YifucmdNZq+kOYzqT0LDOvcK3/zBMBzR/+wSeBBNnjIB/D+mxWDuPW9Man4 D9hwMI/xxKcguZEI21nU4WeSPJBfugK5unDki4AnspSBabvO1AFVnKvuFxmwTLjuEEkC BnXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Yvd06h/x"; 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 n15-20020ac8674f000000b00317ccd7c7b6si6724368qtp.2.2022.08.23.15.16.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Aug 2022 15:16:03 -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="Yvd06h/x"; 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]:40818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQcBn-0000VK-89 for patch@linaro.org; Tue, 23 Aug 2022 18:16:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50590) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQc26-0000Ai-W4 for qemu-devel@nongnu.org; Tue, 23 Aug 2022 18:06:03 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:46025) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQc24-0001QH-7t for qemu-devel@nongnu.org; Tue, 23 Aug 2022 18:06:02 -0400 Received: by mail-pf1-x42f.google.com with SMTP id z187so14704679pfb.12 for ; Tue, 23 Aug 2022 15:05:59 -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=Yvd06h/xswgFj6DgEE4F6BlJ4RtnT/OS2rf3y1TL9+ilAwFs/mSvo2O/vRKUjixJQ1 reyGWL5y/5U4aRycoSHkSW7KLsbKWL/A5F0/OvFlbJ0ocYG305LUUBQH0BTME3AoXkG1 PJ4lGGC4M7uelwptoGWv3fZM6c+zOfSqH91PLirQqKmAQ3ayqLVZlxL2BdIa1P5MJO9B r/qY1lRMa5ucfj6RQCxgWLI+ooTGo4Nsj7wmsNYoO8teCGhsfjBmoekSTjG//uTY8Iyp P+GLu7OzwzpExDOv3qHWyAVSh0ck6jySNeukgz7AM7DjNzGQx87GtURZg6B+9YxHEK4y xuQA== 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=z4Yheb9UE2Dby+1BVJMEbrWaZjGGYHm9Pn4+CNfP2A3VNSkzoHh6jk12K1Os5r9CtK 4fnO0hPUgOLlmnaP0sosw4PiWWok9vhDXMX8HE0gZx51K9CSaYnk/cD1VtkFuk/7hgyN kkh7GdYeHFmP+RzDB3Sl7KiosHw3LiKczrLAA03Cr3RRW5tLFN7//axK0KTon9k5jD4T ppyQ0Q1aSeHfb+INKnJNIKoo3up4VFG1911OOHMvqWo/QXw1tqJZJCBwHBRCRx4AhaZn Rnf7W4+X8+RoB51JsWbFIUMeBS/+fUx/qoBCzcnbvbF3/FJ6fGVH3KFvU2xQxk5MIn+j D8+A== X-Gm-Message-State: ACgBeo01ik4W4u3Odl+1tFEf5RobzGZqaeAIxx+ahTlxgGsLVYaeXYd5 xuQ+FglnBRfPUOdVNQPA5uB71odTEyg5Xg== X-Received: by 2002:a63:1063:0:b0:42b:1b01:b394 with SMTP id 35-20020a631063000000b0042b1b01b394mr150276pgq.602.1661292358956; Tue, 23 Aug 2022 15:05:58 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:46f9:77b4:ec0a:c2d9]) by smtp.gmail.com with ESMTPSA id n12-20020a170902f60c00b0017292073839sm11020974plg.178.2022.08.23.15.05.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 15:05:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: iii@linux.ibm.com, laurent@vivier.eu, alex.bennee@linaro.org Subject: [PATCH v7 12/20] accel/tcg: Use probe_access_internal for softmmu get_page_addr_code_hostp Date: Tue, 23 Aug 2022 15:05:34 -0700 Message-Id: <20220823220542.1993395-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220823220542.1993395-1-richard.henderson@linaro.org> References: <20220823220542.1993395-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.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.