From patchwork Sat Mar 25 10:54:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 666907 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp248399wrt; Sat, 25 Mar 2023 04:52:40 -0700 (PDT) X-Google-Smtp-Source: AK7set8id02yLW81akUoUq+Q8I8e5iOkEM5Mod3q7qDJm1o0mAAGIcAGr1Ry3rw/fU5kuzWs/Pjc X-Received: by 2002:ac8:5fcf:0:b0:3d8:519a:91c9 with SMTP id k15-20020ac85fcf000000b003d8519a91c9mr22110940qta.8.1679745160078; Sat, 25 Mar 2023 04:52:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679745160; cv=none; d=google.com; s=arc-20160816; b=XUO+z1LHY4P6RQPwbDXr3POuFdRPRwcFN9ybP/+kiElUVaNUvsRoWqVdCPWBz9cFEw dK4yPLdDuyFdPg8mbYdqry/inDm6DANBGOXVa0dgOHQPF0miUcjZDeLrvN9Ur3Z2unSu 6shOCQC7Hypo9tZULPqKHE7vcfO6KuXAFcNn0KZzKTRvBZC+s1S+KX339HdcNt6VXVpP CGlAjYn3RYj4CmnVboSG449KJb8x7I1XVd6Fb6rKTPKGjm04InvXh/5jCLV4fNILU0SV i20QolNHB36C3Mrzzsk/bX1PmRAG/JOZivYc1SvISgO6SYfUlSpFexmVh4ZdD9Mkbthi mLBg== 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=onbesb8ouykkYe8UFD25WNQYOxkMjhDNVi3Wh3XpRP0=; b=xg/Ju92WICCOKImAk3w87AHOh7a/VRrIe5xnmpuBP5AHIswyeloJpUqClMY5Rnkpzz RVXIO3JH9fuDbOdqvhR9agauPdQxAsq9DaTYJzzNB3uYkqQ8vfCNvaCCy54Q4Ht4vl8S ZtCKBn2NqEU+ncSG+roep48PyxdSfQCPCRuPmzp75SSqJyy4+snNBodzsgPClnic8ZdW rYpLuq55KzK+NYgHSUQz+QZmUg4zp4qtgPQEV2cEKsblDRA25APGiblF/V3jN3kqOOl6 syOkbrQpa3HwI/njCDDlVekaAXpZdKv+kSjk/Vu2B1iUvzWogXcq9uwWqCBcKfhrVy7d yTag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RQiolptp; 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 bn8-20020a05620a2ac800b007457afe9dccsi8800386qkb.465.2023.03.25.04.52.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 25 Mar 2023 04:52:40 -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=RQiolptp; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pg2Qz-0003PB-Hw; Sat, 25 Mar 2023 07:51:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pg2Qs-0003L1-NS for qemu-devel@nongnu.org; Sat, 25 Mar 2023 07:51:40 -0400 Received: from mail-yw1-x112a.google.com ([2607:f8b0:4864:20::112a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pg2Qq-0007dF-RY for qemu-devel@nongnu.org; Sat, 25 Mar 2023 07:51:38 -0400 Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-545ce8e77fcso5135367b3.1 for ; Sat, 25 Mar 2023 04:51:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679745091; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=onbesb8ouykkYe8UFD25WNQYOxkMjhDNVi3Wh3XpRP0=; b=RQiolptpmaK4Dg06ZVGoVBZY8tabDJ3D6QwBw4Go74PQpEa3vqi27pciLUGZwfbTsm 7PrUEbqm8Ncp1mUDQ6EM5utUAebqO8XZu/6ozAzod0ohjvqhvDgrMHP+U+hrXajuCOlN fwTyQdeeGDwqTWHxGSDL2xxt+y8eBvF/ZaH1dHjuoTZOVqfhyIKxISMYIMle6IhytT13 BcCCp3x6IVwShv94hDi++whkwWWQv+QGqi1H1gb4UCWJo94Ci6vcQg6iR4VAKYpohk98 zC+OjdqqON/qtRJtRYC9pRJwifgNE1CHQMLddQmB4CL1qodAPyZyZt0HtCPtW266WBDr HtBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679745091; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=onbesb8ouykkYe8UFD25WNQYOxkMjhDNVi3Wh3XpRP0=; b=wBtkqT0jGGjRf/ScszS/IQ/TNq8WhhrM6EPKaJQ7MlNhZa/RvLev/wAn/ZNIdblfEC qNh+d6yiEKn/G55m49hq8cLG5PWxJNkLNDfXPUQ+d8bAwt6l7tvHYqzXidcFqsEZao0v /muaiy7sYQiE9d3J168F/2GUaqvew/5whXwoke0voRjBG08RbpwGWAEdXfMWKTCBoxTr FZINu6f22TG4K5F01LwZ/GQHDayXKzRrbl3GA3O5AjDHO2y5W972p7wj5NfXxMHvKKJL 2Gm6N5CxB3b1fcpMW7dZd5mv/0B62Qwf5zhfSg5ctqf1WpMEGYS6xEwpM32u1sur08Gd dXRQ== X-Gm-Message-State: AAQBX9cfJB+bn+5FRbISUE66UkVAlojNqSUlHlW4OAWD+2rIswY+bs0a ZTl5hpGQgfsuk3T96diJX3qY1zKdHB8aEIbl8O8= X-Received: by 2002:a17:90a:4c:b0:23b:3b26:c612 with SMTP id 12-20020a17090a004c00b0023b3b26c612mr5457198pjb.20.1679741677863; Sat, 25 Mar 2023 03:54:37 -0700 (PDT) Received: from stoup.. ([2602:ae:1544:6601:790a:6e23:4a91:70a]) by smtp.gmail.com with ESMTPSA id p14-20020a17090a2d8e00b0023af4eb597csm1234684pjd.52.2023.03.25.03.54.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Mar 2023 03:54:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, palmer@dabbelt.com, zhiwei_liu@linux.alibaba.com, fei2.wu@intel.com Subject: [PATCH v6 08/25] accel/tcg: Add cpu_ld*_code_mmu Date: Sat, 25 Mar 2023 03:54:12 -0700 Message-Id: <20230325105429.1142530-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230325105429.1142530-1-richard.henderson@linaro.org> References: <20230325105429.1142530-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::112a; envelope-from=richard.henderson@linaro.org; helo=mail-yw1-x112a.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 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-bounces+patch=linaro.org@nongnu.org At least RISC-V has the need to be able to perform a read using execute permissions, outside of translation. Add helpers to facilitate this. Signed-off-by: Richard Henderson Acked-by: Alistair Francis --- include/exec/cpu_ldst.h | 9 +++++++ accel/tcg/cputlb.c | 48 ++++++++++++++++++++++++++++++++++ accel/tcg/user-exec.c | 58 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h index 09b55cc0ee..c141f0394f 100644 --- a/include/exec/cpu_ldst.h +++ b/include/exec/cpu_ldst.h @@ -445,6 +445,15 @@ static inline CPUTLBEntry *tlb_entry(CPUArchState *env, uintptr_t mmu_idx, # define cpu_stq_mmu cpu_stq_le_mmu #endif +uint8_t cpu_ldb_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t ra); +uint16_t cpu_ldw_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t ra); +uint32_t cpu_ldl_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t ra); +uint64_t cpu_ldq_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t ra); + uint32_t cpu_ldub_code(CPUArchState *env, abi_ptr addr); uint32_t cpu_lduw_code(CPUArchState *env, abi_ptr addr); uint32_t cpu_ldl_code(CPUArchState *env, abi_ptr addr); diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index e984a98dc4..e62c8f3c3f 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -2768,3 +2768,51 @@ uint64_t cpu_ldq_code(CPUArchState *env, abi_ptr addr) MemOpIdx oi = make_memop_idx(MO_TEUQ, cpu_mmu_index(env, true)); return full_ldq_code(env, addr, oi, 0); } + +uint8_t cpu_ldb_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t retaddr) +{ + return full_ldub_code(env, addr, oi, retaddr); +} + +uint16_t cpu_ldw_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t retaddr) +{ + MemOp mop = get_memop(oi); + int idx = get_mmuidx(oi); + uint16_t ret; + + ret = full_lduw_code(env, addr, make_memop_idx(MO_TEUW, idx), retaddr); + if ((mop & MO_BSWAP) != MO_TE) { + ret = bswap16(ret); + } + return ret; +} + +uint32_t cpu_ldl_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t retaddr) +{ + MemOp mop = get_memop(oi); + int idx = get_mmuidx(oi); + uint32_t ret; + + ret = full_ldl_code(env, addr, make_memop_idx(MO_TEUL, idx), retaddr); + if ((mop & MO_BSWAP) != MO_TE) { + ret = bswap32(ret); + } + return ret; +} + +uint64_t cpu_ldq_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t retaddr) +{ + MemOp mop = get_memop(oi); + int idx = get_mmuidx(oi); + uint64_t ret; + + ret = full_ldq_code(env, addr, make_memop_idx(MO_TEUQ, idx), retaddr); + if ((mop & MO_BSWAP) != MO_TE) { + ret = bswap64(ret); + } + return ret; +} diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 7b37fd229e..44e0ea55ba 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -1222,6 +1222,64 @@ uint64_t cpu_ldq_code(CPUArchState *env, abi_ptr ptr) return ret; } +uint8_t cpu_ldb_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t ra) +{ + void *haddr; + uint8_t ret; + + haddr = cpu_mmu_lookup(env, addr, oi, ra, MMU_INST_FETCH); + ret = ldub_p(haddr); + clear_helper_retaddr(); + return ret; +} + +uint16_t cpu_ldw_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t ra) +{ + void *haddr; + uint16_t ret; + + haddr = cpu_mmu_lookup(env, addr, oi, ra, MMU_INST_FETCH); + ret = lduw_p(haddr); + clear_helper_retaddr(); + if (get_memop(oi) & MO_BSWAP) { + ret = bswap16(ret); + } + return ret; +} + +uint32_t cpu_ldl_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t ra) +{ + void *haddr; + uint32_t ret; + + haddr = cpu_mmu_lookup(env, addr, oi, ra, MMU_INST_FETCH); + ret = ldl_p(haddr); + clear_helper_retaddr(); + if (get_memop(oi) & MO_BSWAP) { + ret = bswap32(ret); + } + return ret; +} + +uint64_t cpu_ldq_code_mmu(CPUArchState *env, abi_ptr addr, + MemOpIdx oi, uintptr_t ra) +{ + void *haddr; + uint64_t ret; + + validate_memop(oi, MO_BEUQ); + haddr = cpu_mmu_lookup(env, addr, oi, ra, MMU_DATA_LOAD); + ret = ldq_p(haddr); + clear_helper_retaddr(); + if (get_memop(oi) & MO_BSWAP) { + ret = bswap64(ret); + } + return ret; +} + #include "ldst_common.c.inc" /*