From patchwork Sat Oct 1 16:22:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 611400 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp282321pvb; Sat, 1 Oct 2022 09:52:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5TFuOG4HoQ8lhPMbtNYae3AyaVMGzVoRFk/D9+9gMWUV7u1RjQ8kFSVsrmiVrvRaBzx1qS X-Received: by 2002:ac8:7d11:0:b0:35c:f5c4:324a with SMTP id g17-20020ac87d11000000b0035cf5c4324amr11171789qtb.400.1664643150368; Sat, 01 Oct 2022 09:52:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664643150; cv=none; d=google.com; s=arc-20160816; b=LZw7zwqUIz5GwhVf3V1huzHyX/jUgWjpygoqe5UzzFuRxIhTHP+ofIVYqoxigHjIXz 0QU6vs8a1Ubz6YrCdoP9nPkm3P814bqL1YbvX3XdFZ2Wnf/maskhgQZ2WETGVIVaixoo PHDhUaYAktzG9//EFuR5G5rhLUOkcEz/ZF5+92FVbEDbl0Me2VoxiY6UDlKP9WPh+uV6 qKIMInj2/EaKkWd9FZGR+//TPkMvz+gYDN590mmx+ef9BMDK3BYsN3HIVW+bKehuzvxC iyOIuacphQQVIfgHW2j+SOZ6ijp/Die2JG4lk6VDGqbV24QXenl3jsp/qtXZRuQRJ32d z1DA== 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=H5wRwyD67tK/HHDlYGbPLh0Azkr3is2XWTQhRNefVK0=; b=dTthQbo6sYzBFyn3ukOZvQZhlZIXer0nqWAh+Pbev4irKSOqwTCzdvJcI9Om8eEuZ9 6c9hNKDrg060zmk3r3J2Kik7iwKD06EIPP3QQonC66Tipdv25WP/nGKXc2SPp8PuzTzL h927E0M8RfHEHXpwmojE7n8qs1sy2VNa9unUt9q3NqG3U2JUhzEvRXnvGixU3bcyVz1p iQYMAaOs/K0/nBtqd/nuFDn4852brmpHqOoy6FxAAW4SBhODcLrYMnXdBPEww6gc0PpO Y3a2Ba7XbUw65WzEG9frBNBb7VP3yFolsBhkFRie0Z7UIVSlDgEjyzqAPAvyH6ikOrJF +1xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FqPMFrjX; 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 gg5-20020a056214252500b004b1711604b7si2041834qvb.180.2022.10.01.09.52.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 01 Oct 2022 09:52: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=FqPMFrjX; 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]:38350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oefj3-0004wo-T2 for patch@linaro.org; Sat, 01 Oct 2022 12:52:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oefHp-0007HB-Kf for qemu-devel@nongnu.org; Sat, 01 Oct 2022 12:24:21 -0400 Received: from mail-qk1-x72a.google.com ([2607:f8b0:4864:20::72a]:42614) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oefHn-0006Gu-MF for qemu-devel@nongnu.org; Sat, 01 Oct 2022 12:24:21 -0400 Received: by mail-qk1-x72a.google.com with SMTP id d15so4533049qka.9 for ; Sat, 01 Oct 2022 09:24:19 -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:subject:date; bh=H5wRwyD67tK/HHDlYGbPLh0Azkr3is2XWTQhRNefVK0=; b=FqPMFrjXrK5LaLhkzo4xfkgIlt2Py9uJxb+7qq+6t7Bp3DXC6Myk8wVKbUWd053XiU iaLvwc0HEjspgy433K98Tv7lnISFlD5way/hj0Y13Mq/gCcEZUlafQIWVQrquGk0w5jf 27rdJGf/bVK4AWun+GMjPVc+rF1zswg0UHRYQ0DNXrlWXKH05gfULRx6ojE/gCENPw9x 34XSQs0mLIw4DetdE38ijPye6NvKgsD6K/aycj+fmwvhWThrXDoXjWfni5CvIEJuPIHj indQiJL9nEABANnCbUNyhPWTyX16jHAwW2QPxn6CHQdbvDPQEDgMDHDy7LMjxPYC4aha kSPQ== 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 :subject:date; bh=H5wRwyD67tK/HHDlYGbPLh0Azkr3is2XWTQhRNefVK0=; b=O9CwfEm8EYFuRY/HH3mTkHKGxCOx32b6djiouxywFr20/OwyerJwyWH6UJ55tHSQRO eDxuSkGEhPUpbWPDzGk4NJ7/pPBbJSh5xenoLG+rI4nYb54MEobojEfyLVNXjCR1usOV Z5km2y6DUZf60mVEQokti5Om3I91pRYiOoXxV1KfhFH7BQ/D88hqX1k4f7peaaGc7oAg I58jt4mvcmECpPLtjwrIfmLsw6ixaDbs/yjvYqE9XRCmNNIU4p7BgoiAgHUd6FtpHtZX G0KLeHav92Ig/HFFqyKTgwKZdssbD7UPec0gZ6Srm9n9JzcZdNEBJE9Roh0mb+SiDNg8 IvJQ== X-Gm-Message-State: ACrzQf2XU5tBOD0MOKoPQ6Za9NQnNTFCw/ALBGEZth8iTHDcmpy9skbn M+WgwolrVQxDtdnvBaBjNuzjI69w/7R9SQ== X-Received: by 2002:a05:620a:318a:b0:6ce:732a:f92 with SMTP id bi10-20020a05620a318a00b006ce732a0f92mr9662205qkb.347.1664641458978; Sat, 01 Oct 2022 09:24:18 -0700 (PDT) Received: from stoup.. ([2605:ef80:8084:91a4:f7cb:db31:c505:b931]) by smtp.gmail.com with ESMTPSA id t4-20020a37ea04000000b006d1d8fdea8asm4387445qkj.85.2022.10.01.09.24.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 09:24:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v3 23/42] target/arm: Use probe_access_full for BTI Date: Sat, 1 Oct 2022 09:22:59 -0700 Message-Id: <20221001162318.153420-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221001162318.153420-1-richard.henderson@linaro.org> References: <20221001162318.153420-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::72a; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72a.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=unavailable 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" Add a field to TARGET_PAGE_ENTRY_EXTRA to hold the guarded bit. In is_guarded_page, use probe_access_full instead of just guessing that the tlb entry is still present. Also handles the FIXME about executing from device memory. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/cpu-param.h | 8 ++++---- target/arm/cpu.h | 13 ------------- target/arm/internals.h | 1 + target/arm/ptw.c | 7 ++++--- target/arm/translate-a64.c | 22 ++++++++-------------- 5 files changed, 17 insertions(+), 34 deletions(-) diff --git a/target/arm/cpu-param.h b/target/arm/cpu-param.h index 118ca0e5c0..689a9645dc 100644 --- a/target/arm/cpu-param.h +++ b/target/arm/cpu-param.h @@ -32,12 +32,12 @@ # define TARGET_PAGE_BITS_MIN 10 /* - * Cache the attrs and sharability fields from the page table entry. + * Cache the attrs, sharability, and gp fields from the page table entry. */ # define TARGET_PAGE_ENTRY_EXTRA \ - uint8_t pte_attrs; \ - uint8_t shareability; - + uint8_t pte_attrs; \ + uint8_t shareability; \ + bool guarded; #endif #define NB_MMU_MODES 8 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 2694a93894..c8cad2ef7c 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3382,19 +3382,6 @@ static inline uint64_t *aa64_vfp_qreg(CPUARMState *env, unsigned regno) /* Shared between translate-sve.c and sve_helper.c. */ extern const uint64_t pred_esz_masks[5]; -/* Helper for the macros below, validating the argument type. */ -static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x) -{ - return x; -} - -/* - * Lvalue macros for ARM TLB bits that we must cache in the TCG TLB. - * Using these should be a bit more self-documenting than using the - * generic target bits directly. - */ -#define arm_tlb_bti_gp(x) (typecheck_memtxattrs(x)->target_tlb_bit0) - /* * AArch64 usage of the PAGE_TARGET_* bits for linux-user. * Note that with the Linux kernel, PROT_MTE may not be cleared by mprotect diff --git a/target/arm/internals.h b/target/arm/internals.h index fd17aee459..a50189e2e4 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -1067,6 +1067,7 @@ typedef struct ARMCacheAttrs { unsigned int attrs:8; unsigned int shareability:2; /* as in the SH field of the VMSAv8-64 PTEs */ bool is_s2_format:1; + bool guarded:1; /* guarded bit of the v8-64 PTE */ } ARMCacheAttrs; /* Fields that are valid upon success. */ diff --git a/target/arm/ptw.c b/target/arm/ptw.c index 1bc194ffa1..ccfef2caca 100644 --- a/target/arm/ptw.c +++ b/target/arm/ptw.c @@ -1319,9 +1319,10 @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, */ result->f.attrs.secure = false; } - /* When in aarch64 mode, and BTI is enabled, remember GP in the IOTLB. */ - if (aarch64 && guarded && cpu_isar_feature(aa64_bti, cpu)) { - arm_tlb_bti_gp(&result->f.attrs) = true; + + /* When in aarch64 mode, and BTI is enabled, remember GP in the TLB. */ + if (aarch64 && cpu_isar_feature(aa64_bti, cpu)) { + result->f.guarded = guarded; } if (mmu_idx == ARMMMUIdx_Stage2 || mmu_idx == ARMMMUIdx_Stage2_S) { diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 5b67375f4e..22802d1d2f 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -14601,22 +14601,16 @@ static bool is_guarded_page(CPUARMState *env, DisasContext *s) #ifdef CONFIG_USER_ONLY return page_get_flags(addr) & PAGE_BTI; #else + CPUTLBEntryFull *full; + void *host; int mmu_idx = arm_to_core_mmu_idx(s->mmu_idx); - unsigned int index = tlb_index(env, mmu_idx, addr); - CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr); + int flags; - /* - * We test this immediately after reading an insn, which means - * that any normal page must be in the TLB. The only exception - * would be for executing from flash or device memory, which - * does not retain the TLB entry. - * - * FIXME: Assume false for those, for now. We could use - * arm_cpu_get_phys_page_attrs_debug to re-read the page - * table entry even for that case. - */ - return (tlb_hit(entry->addr_code, addr) && - arm_tlb_bti_gp(&env_tlb(env)->d[mmu_idx].fulltlb[index].attrs)); + flags = probe_access_full(env, addr, MMU_INST_FETCH, mmu_idx, + false, &host, &full, 0); + assert(!(flags & TLB_INVALID_MASK)); + + return full->guarded; #endif }