From patchwork Fri Jul 21 14:32:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 704937 Delivered-To: patch@linaro.org Received: by 2002:a5d:60ca:0:b0:317:2194:b2bc with SMTP id x10csp466161wrt; Fri, 21 Jul 2023 07:34:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlHy8yzAhozXB8seqa3SLikttVgJjiThmKK8cTS5+8EKXBkwdlHD2VEi1MKfTMGOqTMNGwbO X-Received: by 2002:a81:6a45:0:b0:583:a418:c3fc with SMTP id f66-20020a816a45000000b00583a418c3fcmr297602ywc.23.1689950041623; Fri, 21 Jul 2023 07:34:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689950041; cv=none; d=google.com; s=arc-20160816; b=ESxLq7bGmdTJ/LrLckvpT8CE32XnQYcHfnv01ZuN2I8vTSuflj77y2J5jL/UWIHktt Aq3cp1JmatsNbkJvU0R0KOj4IkU4cSNhQmaEVz5wfCUQ5x30chN7otl4p4WbUFFXyDKd 17KJ59fmKE3l3FkwQHSB8NZQLiFX9vphkCXBO9L7G/b+nTFE8T5r2vkxoXkRmRZjKZGc TjUvXc8WchTxmksB7IjpnRPRMp6NvNac354K94Ew5W78B3xufOTXQU9Xwtr/oU1CDaC2 qc++n5XK6EQgDtQGJ8iU8wlk2sdRrhOC2jxlUX5bPQsKTXtYvHhduG2Ub3u8X2Y0N2cs UapQ== 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:message-id:date:subject:to:from:dkim-signature; bh=9Eu0+efAdWmcM1kvXZ0gk+7iJlGZwvte0bs6QH7LutQ=; fh=jvpdohKmRoZMO537s6xMKXXtj7EZws1LOMQI/oP4vXs=; b=cuNJZVS5wtMUYCpjGHLz7MAt/fAzLAi7+MXxADD8xEwUGz+vLZ0kdDzTWYLk6lQ4yt 7D9BZXU8wrXBaVoD0dKEXTEJqSBVh5RFxBxO00OqFMoIG/hgWDLKugEJ1pgIeesY+G37 CwluTjV5oOWU6RonMNqJk69Hga0GQVwexZjPLuiXmyPIkP72ZQ0sTblIv3+YtMnmUNXX WKGPYzZpU1Df54CyYPoAUTKv+exrQAITBpBTPB6EIQisk8Sf4fk8rLHk+ul+QvQHgqvh 9bjoQVgTUXbiEdorU+AdT8ODZJVPjUPe8vAQgn3wxBpCRyx2Cn2/giIQwyGygcTTMyo6 7SrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="p+P/js7F"; 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 e3-20020a05622a110300b00403b23456e4si1550481qty.522.2023.07.21.07.34.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Jul 2023 07:34:01 -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="p+P/js7F"; 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 1qMrBX-0005EJ-7H; Fri, 21 Jul 2023 10:32:47 -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 1qMrBV-0005Do-H4 for qemu-devel@nongnu.org; Fri, 21 Jul 2023 10:32:45 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qMrBT-00085s-Qk for qemu-devel@nongnu.org; Fri, 21 Jul 2023 10:32:45 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3142a9ff6d8so1692626f8f.3 for ; Fri, 21 Jul 2023 07:32:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689949961; x=1690554761; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=9Eu0+efAdWmcM1kvXZ0gk+7iJlGZwvte0bs6QH7LutQ=; b=p+P/js7FdoZ0UlkJmWtnUKM5bZRYeVU7S5ga4C8XqVq0zxS+AMNuM63g//wk+ve+k8 l0bwSJ/KpOGfGXQWC6Lbal6yUg5Z4EXiHaYnSra6IiX0rCG3VrN6w3K0RMuYj3ialsLH ycrelooUaA0C+ieDVW62KHAA7fA9NzFyP/hky/RLhYsfHq+r1AbYkOaH/9hJ5ru4z+fC z3ev1ZCRyYWaUAwAGivpXdt8vBjwaQPQXXa37nps8AipfX2DHbnTd+1LwZ4lKr2xHwth 6AuKb+zhEsQZQogZ/HbOIQ1PX1LJBgbra8StggTUHbjHHh6YDHSf8w/akYwrFMgvcAzF WyoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689949961; x=1690554761; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9Eu0+efAdWmcM1kvXZ0gk+7iJlGZwvte0bs6QH7LutQ=; b=e7F8GBDazlrY+XjXvFl0XlaPjZ937A/N8OiRZs4hTthXhdbFCA1eYVsJV/IxxsAZiv WcNJYbkrp0lWLYvq07tSFLZfCmFrya1xefM/cViK7lDW+5BIjKMMu5ixZY5r9q3mNpQm uVMBMmET9llwtLnjdT1X3TvhwAOBuhlXYLk7LBj5vcSCCOcnCxHaOYLj7w3MqNXvR0+X U9SQuvn0y6K7ozLSEmxwHVZ3m5AIvoeYLPmNyqaj7rcR9Dl5rf1K7ouT5LTYHrNQuGmM 1AhKM9zbzgpvUJDYHgaB/bPOiFycURdzfgLzDohBRWnVQn7eODEllo5d9Ls3PSBPCl+d N1Ow== X-Gm-Message-State: ABy/qLZwvuxYz/BBZEca1qc5MIQbywWuR6VsAA9Lnqee2tXLSWtnhUng /TWkHr8ujmLcFYi+AxKuQhSS3g== X-Received: by 2002:adf:f488:0:b0:315:9fb7:bd9 with SMTP id l8-20020adff488000000b003159fb70bd9mr1445146wro.69.1689949961429; Fri, 21 Jul 2023 07:32:41 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id j6-20020a5d6046000000b003143b14848dsm4304533wrt.102.2023.07.21.07.32.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 07:32:40 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH for-8.1] target/arm: Special case M-profile in debug_helper.c code Date: Fri, 21 Jul 2023 15:32:39 +0100 Message-Id: <20230721143239.1753066-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x430.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 A lot of the code called from helper_exception_bkpt_insn() is written assuming A-profile, but we will also call this helper on M-profile CPUs when they execute a BKPT insn. This used to work by accident, but recent changes mean that we will hit an assert when some of this code calls down into lower level functions that end up calling arm_security_space_below_el3(), arm_el_is_aa64(), and other functions that now explicitly assert that the guest CPU is not M-profile. Handle M-profile directly to avoid the assertions: * in arm_debug_target_el(), M-profile debug exceptions always go to EL1 * in arm_debug_exception_fsr(), M-profile always uses the short format FSR (compare commit d7fe699be54b2, though in this case the code in arm_v7m_cpu_do_interrupt() does not need to look at the FSR value at all) Cc: qemu-stable@nongnu.org Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1775 Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- Not sure exactly when this assert() got in (probably in the semi-recent refactorings for realm support), but it won't hurt to backport the fix even if the older QEMU doesn't assert(). --- target/arm/debug_helper.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/target/arm/debug_helper.c b/target/arm/debug_helper.c index 8362462a07e..abe72e35ae6 100644 --- a/target/arm/debug_helper.c +++ b/target/arm/debug_helper.c @@ -21,6 +21,10 @@ static int arm_debug_target_el(CPUARMState *env) bool secure = arm_is_secure(env); bool route_to_el2 = false; + if (arm_feature(env, ARM_FEATURE_M)) { + return 1; + } + if (arm_is_el2_enabled(env)) { route_to_el2 = env->cp15.hcr_el2 & HCR_TGE || env->cp15.mdcr_el2 & MDCR_TDE; @@ -434,18 +438,20 @@ static uint32_t arm_debug_exception_fsr(CPUARMState *env) { ARMMMUFaultInfo fi = { .type = ARMFault_Debug }; int target_el = arm_debug_target_el(env); - bool using_lpae = false; + bool using_lpae; - if (target_el == 2 || arm_el_is_aa64(env, target_el)) { + if (arm_feature(env, ARM_FEATURE_M)) { + using_lpae = false; + } else if (target_el == 2 || arm_el_is_aa64(env, target_el)) { using_lpae = true; } else if (arm_feature(env, ARM_FEATURE_PMSA) && arm_feature(env, ARM_FEATURE_V8)) { using_lpae = true; + } else if (arm_feature(env, ARM_FEATURE_LPAE) && + (env->cp15.tcr_el[target_el] & TTBCR_EAE)) { + using_lpae = true; } else { - if (arm_feature(env, ARM_FEATURE_LPAE) && - (env->cp15.tcr_el[target_el] & TTBCR_EAE)) { - using_lpae = true; - } + using_lpae = false; } if (using_lpae) {