From patchwork Tue Jun 6 09:48:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 689710 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d8a:0:0:0:0:0 with SMTP id b10csp2540466wru; Tue, 6 Jun 2023 02:51:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4MAIVIzQ2CQDPZMZaxrreQNHdRJnxGyqxwtUJft6HWvzeecQyXg9rJFgJIe8sE1zN9GX4o X-Received: by 2002:a05:620a:27d3:b0:75e:ac6b:3b89 with SMTP id i19-20020a05620a27d300b0075eac6b3b89mr1365219qkp.71.1686045068086; Tue, 06 Jun 2023 02:51:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686045068; cv=none; d=google.com; s=arc-20160816; b=B4H0dFF9hruRJdLdwYzAZDVoVPEH9zK5ChPaJEePlvHwfjr2eB/6HwjGQ4mCIAkYdZ kyu/7aT87WHXgQuPP2x75c3gKHVYDTSK0SVMoYWfMEexSTm9ws16CRAdNo4bhx+FRuG4 vRCf5ZJmSwHEt9zFSj/J8vn3g1S6J5wXR8fKkUyFwo0y0BYBaAsC/sbCoXBGdxcXb5Vd 3a/e0X8XAMzsjc+stpnJiPzVIM8tgGuZ4OG1NAxoMwYcYSSGqJguVoXycztn4ZYbUrD/ wxaFwoTbkz0S3yZ2PPGADc6vU5FZKzW3OCaL3n8FvP+uHvpZ97RAINlKqBtRkA23tANi SDBw== 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:to:from :dkim-signature; bh=xvF2QmUDjhFBRGwj3rIB4i3e5VdTHFDUcn/0aso6Dbs=; b=tV3tINDtNe4Fy0GbdmXjhRVL6EVYhzm5OjNUfqY4VKPXy9lNk7B8sfoc9wUKga0tiv 9ognLokTpdrNm5MdlBTD/IZy3Fi1fBlUW92IvJm16jjOZHFLSxw4+wjhqP/xrW6ZoktA 0TQ3KgYRIXZga/P9hwyFpT66u5b2okZFm2TGiGwqEVLCayX2DTs+wWEPC1uZUxMpBKcn ND/8sbzr4KalA+Sma63r+6BMKMj0lSJQeRKaU2o6kcQBn5pqeEdPFcA+MeTYJhn+L2TH ZLPBmeOTmrVuEQLNCuvqypixyZz5wow6UEUcQTbCPYa4CVxVqyV06Wc2I6lOmYQx7ubg B5hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="yuUSB/WS"; 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 x12-20020ae9f80c000000b0074e36f1b99dsi5625261qkh.233.2023.06.06.02.51.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jun 2023 02:51:08 -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="yuUSB/WS"; 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 1q6TJ2-0007t5-1n; Tue, 06 Jun 2023 05:48:48 -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 1q6TIu-0007nd-Ld for qemu-devel@nongnu.org; Tue, 06 Jun 2023 05:48:40 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q6TIr-0004ru-Gn for qemu-devel@nongnu.org; Tue, 06 Jun 2023 05:48:40 -0400 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-30b023b0068so4235509f8f.0 for ; Tue, 06 Jun 2023 02:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686044916; x=1688636916; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=xvF2QmUDjhFBRGwj3rIB4i3e5VdTHFDUcn/0aso6Dbs=; b=yuUSB/WSC71d2O6dOJJK+ke6smC8sPoY73I2HAUyiw6fJifPkjDWBc6rw+lJF4Liim RvkeKpe7HPIwT5OxTqfob4uZZNYVDHaaXJp1Uj0W18k0v0cc3Fi8Q91BoN0dS10a5Fws rsLrWYuri3E140a2SmhUzT3gBA+uREA+ap1dV6nVt3+JSaaiId3v9yJdTatgSmWxIfTK DkJTl3MFUUgcjNwxnHOY6Z8E0VGU9unTQortQraV84X3WpuB2XvU+JSRGvaaNWzIjTH3 Sdw7FnI2dya0hym+yg3aEMPSPdwwoPSGT+eGgZ8c13lhdnCA3u9micCHiMrqMmZ8nQhn pMzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686044916; x=1688636916; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xvF2QmUDjhFBRGwj3rIB4i3e5VdTHFDUcn/0aso6Dbs=; b=kVc4Gwkp6MfanuW2UNgqwvEb3SfdXwN8g6I0VvHCfVOyvRkY9z4IbGqVWFMsFGZW3k c6nLVw7qpgrozVOVvyNdwxXfy2Z67Da6W28p77aRrhwAZt8AhSMg0miTtE81j7vJZVKb hBWGUJQI0SZ1iMHllBKuEWyouupwR7+uxM18zLJRxYnhiBC6rZ2B8QUmA620REqbU5T7 KB/zlSqkHfR0o3dMCMi05CxcrZp9Dd0l5S/IYgYU3+U764o2JxCx5ivLsrppytmz1gtO 17GMKCYbQfJIf3w8Of2Lxd5wLX8bDNpJWXK+Qxvg82CY8XGDtfELPrTjegPPySlPMA1Z DEEw== X-Gm-Message-State: AC+VfDwivilxQ810vmbNVCfoMUEs1Gbm6UyesNiNc4LH1O9ZYrXjoWaS YZN9crP/TUIioBv0qr750Y3jy+9H9bYC7ockOmc= X-Received: by 2002:a5d:4943:0:b0:30a:e589:68a5 with SMTP id r3-20020a5d4943000000b0030ae58968a5mr1445293wrs.29.1686044916248; Tue, 06 Jun 2023 02:48:36 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id v10-20020a5d4b0a000000b0030789698eebsm12134017wrq.89.2023.06.06.02.48.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 02:48:36 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 42/42] target/arm: trap DCC access in user mode emulation Date: Tue, 6 Jun 2023 10:48:14 +0100 Message-Id: <20230606094814.3581397-43-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230606094814.3581397-1-peter.maydell@linaro.org> References: <20230606094814.3581397-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-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-bounces+patch=linaro.org@nongnu.org From: Zhuojia Shen Accessing EL0-accessible Debug Communication Channel (DCC) registers in user mode emulation is currently enabled. However, it does not match Linux behavior as Linux sets MDSCR_EL1.TDCC on startup to disable EL0 access to DCC (see __cpu_setup() in arch/arm64/mm/proc.S). This patch fixes access_tdcc() to check MDSCR_EL1.TDCC for EL0 and sets MDSCR_EL1.TDCC for user mode emulation to match Linux. Signed-off-by: Zhuojia Shen Reviewed-by: Richard Henderson Message-id: DS7PR12MB630905198DD8E69F6817544CAC4EA@DS7PR12MB6309.namprd12.prod.outlook.com Signed-off-by: Peter Maydell --- target/arm/cpu.c | 2 ++ target/arm/debug_helper.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 5182ed0c911..4d5bb57f079 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -289,6 +289,8 @@ static void arm_cpu_reset_hold(Object *obj) * This is not yet exposed from the Linux kernel in any way. */ env->cp15.sctlr_el[1] |= SCTLR_TSCXT; + /* Disable access to Debug Communication Channel (DCC). */ + env->cp15.mdscr_el1 |= 1 << 12; #else /* Reset into the highest available EL */ if (arm_feature(env, ARM_FEATURE_EL3)) { diff --git a/target/arm/debug_helper.c b/target/arm/debug_helper.c index d41cc643b1b..8362462a07e 100644 --- a/target/arm/debug_helper.c +++ b/target/arm/debug_helper.c @@ -842,12 +842,14 @@ static CPAccessResult access_tda(CPUARMState *env, const ARMCPRegInfo *ri, * is implemented then these are controlled by MDCR_EL2.TDCC for * EL2 and MDCR_EL3.TDCC for EL3. They are also controlled by * the general debug access trap bits MDCR_EL2.TDA and MDCR_EL3.TDA. + * For EL0, they are also controlled by MDSCR_EL1.TDCC. */ static CPAccessResult access_tdcc(CPUARMState *env, const ARMCPRegInfo *ri, bool isread) { int el = arm_current_el(env); uint64_t mdcr_el2 = arm_mdcr_el2_eff(env); + bool mdscr_el1_tdcc = extract32(env->cp15.mdscr_el1, 12, 1); bool mdcr_el2_tda = (mdcr_el2 & MDCR_TDA) || (mdcr_el2 & MDCR_TDE) || (arm_hcr_el2_eff(env) & HCR_TGE); bool mdcr_el2_tdcc = cpu_isar_feature(aa64_fgt, env_archcpu(env)) && @@ -855,6 +857,9 @@ static CPAccessResult access_tdcc(CPUARMState *env, const ARMCPRegInfo *ri, bool mdcr_el3_tdcc = cpu_isar_feature(aa64_fgt, env_archcpu(env)) && (env->cp15.mdcr_el3 & MDCR_TDCC); + if (el < 1 && mdscr_el1_tdcc) { + return CP_ACCESS_TRAP; + } if (el < 2 && (mdcr_el2_tda || mdcr_el2_tdcc)) { return CP_ACCESS_TRAP_EL2; }