From patchwork Fri Aug 19 03:26:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 598479 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp1065994mae; Thu, 18 Aug 2022 20:34:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR70X3x2dGi6mtWRgxuaBztDfyjJkMziR0F0gTfKLNpZFZtiqTQmDtPpAX9zQkpXat+x8OxE X-Received: by 2002:a37:e313:0:b0:6b8:f66e:2275 with SMTP id y19-20020a37e313000000b006b8f66e2275mr4252960qki.0.1660880070149; Thu, 18 Aug 2022 20:34:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660880070; cv=none; d=google.com; s=arc-20160816; b=mpwPT84OCGaW1V62srsFmKF2inPaf5GkZdhNjGBBzhh3VYgunykpslt2MTzqacjBz9 PRy/jDTJ8cMecgU27JhnKxGUcGTK61A0cSFkXdNwZduhkSXzA1DBE3vqFp/OxBdvnhQL r1pg0QucCKdooVoq2idBbQ9W5/QO3fZUXeYzwcck8a78VHHm84xB9wG5UZVnFwy6M7FS ofPaIShGZ0nWy0FwFhpg00Mt/Vl8VKvhmLNo6FL8QIA6x3zmTw/CywAm2Y/PvSvqdI89 mSO5rWgKIjrQjamw8UW81N3YsUchLdOl40KIUgKUuL64Hmr/3F9C6RYZ98qVKEgbdh45 0WkQ== 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=A0u9JUCEei88oryz4thFTB37DQi2HhQU/t3S0pDWuTE2FhJLIiEDABdx9jrgfXecRJ Ir7VCDEtojzftOLEdSuKMlKegrtsbtMvQbfUAiglF52pB94DhaYOzaORICNfsuqnzx7w 5PrUZWBo1i8/G2P9RNoO0YHJo5XmmFkc9T5KS5z059091R6v9+5u2LF5CI+Ir9LeJPUr SO8AUjQyMPgJGFyHY3K2hZqTmO2DrN+H1rAanCA/OiD34PXPxtGEyPcUVkMMHF3hrr3M ewioiMIP9ZPC5Zw0XqoyBYZbjj1e3wFyaqaxeqmvvc2xRyZ1vQIpunQiFAyuajjR46M+ HiZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JcQCQhhh; 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 kc5-20020a056214410500b004736334f9e1si1434466qvb.545.2022.08.18.20.34.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Aug 2022 20:34:30 -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=JcQCQhhh; 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]:55644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oOsmD-0004eU-Jc for patch@linaro.org; Thu, 18 Aug 2022 23:34:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOseX-0001sb-6l for qemu-devel@nongnu.org; Thu, 18 Aug 2022 23:26:33 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]:41558) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oOseV-0002iF-FM for qemu-devel@nongnu.org; Thu, 18 Aug 2022 23:26:32 -0400 Received: by mail-pf1-x42b.google.com with SMTP id q19so3234355pfg.8 for ; Thu, 18 Aug 2022 20:26:31 -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=JcQCQhhh7IQ1ZxG2So/tlri576lcYHY1kkIK4JJyFLsQ0lqWi/W7Nilu4SoQ8sBk5b mGlbSteWt3zm2lVEB0cOrkX66gMQxhQoxE9PhWGU/fHG8VvAXgvr24VWMkkz7UNNE5+m K+pS6YZLfn3b6bV3LhK9jUebOKeCUMqCdyE+TiB77pRfaZDXLolm5vHmHdQjw04ZOmgq wp2RUzAwN3dniY/KSB7sUYQPen8c7G2+CywchHFFF0idANfU5QRJsG7TsDrCMUJzyWdK vhP5HL0EjjaksQPAcUjvaBkNpbCe6I/OILe95suWIj7djT4kkPVvrUEtkSwpTYhlSjFM PJ/w== 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=CJdzxY5+bstvYzZnDc2kkn/6LhrqYuAnvCvT+vsOHmqEJCRoIuOOirF4svImeS670L lvq1gG/pkTdqlkpzoWQ2/2DkXYvibyjTFE3EuGM8j03E+wm3GVo19V3GWFK5/ITuM3gb bQDDxvbiygsqDrxmqj3M50idFYentR7tYh0UeC5ZtWYgqJovr6venT+ecVPz8RIW826T P+eOmmrDmUk+2R3oTZ1hMojxSd1iDBPzaBonwnh//Nv0vxUoBqLeS/wB1pBaudeZoUAr Gi6ZeSk7QXCLX6+n3pqtdEu3Zw+Nz4sD8YTUvaN+I9WvlL8CHTHdzX/f26Ns5Z91Qz4B 4EBw== X-Gm-Message-State: ACgBeo2oJJThmNh1r5sLzcERPeJ7TCVWh0YWvvKre1FxoGYRFUQJvmIf Kh+CYDjnBW0O/S0G5h3E8yIBZrCGxprqYA== X-Received: by 2002:a63:b58:0:b0:429:c7fb:d60c with SMTP id a24-20020a630b58000000b00429c7fbd60cmr4800594pgl.210.1660879590668; Thu, 18 Aug 2022 20:26:30 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:bbf3:9914:aa9c:3b4e]) by smtp.gmail.com with ESMTPSA id g184-20020a6252c1000000b00535d19c46d7sm2199904pfb.203.2022.08.18.20.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 20:26:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, iii@linux.ibm.com, dramforever@live.com, alistair.francis@wdc.com, alex.bennee@linaro.org Subject: [PATCH v6 12/21] accel/tcg: Use probe_access_internal for softmmu get_page_addr_code_hostp Date: Thu, 18 Aug 2022 20:26:06 -0700 Message-Id: <20220819032615.884847-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220819032615.884847-1-richard.henderson@linaro.org> References: <20220819032615.884847-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.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.