From patchwork Fri Nov 9 15:21:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 150658 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp75621ljp; Fri, 9 Nov 2018 07:24:07 -0800 (PST) X-Google-Smtp-Source: AJdET5dPXt8EUYfK+3Ja5g7gCh4i2xFMWAKcXtRsIeW4N8ccPVjOFB9Y3mL2LSIsw06nHojiWRyX X-Received: by 2002:a0c:b517:: with SMTP id d23mr5925540qve.221.1541777047757; Fri, 09 Nov 2018 07:24:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541777047; cv=none; d=google.com; s=arc-20160816; b=kZSGRf3frbzrm2KjXOlWQugIuDF2jv00WB5ygQ7GsDFCm5WuaW/eXYlazTXOSzVaEJ Rd0O668EeKR5XGIqhO+UbUHH9B75Juo+S6O/jacpd3P0+2yBHg+u34v/MMtb5kXGWYYl cSR7/1k2c3be6uZT71sjRf8AXzLm7SKDUcKtnA/lSQDfU1sXOOrIgxmRDwvLhocLbdlU LSenK8mkd5W6iLP3FIPyVDU9C9qcnDIetqeHJez9jQxspp0zGuv+1RAPirPt1uFdiioP S9BrY4shKbddw23QdlajMjGUhy4+B0HHWdA1FxXHDkV8B+unm7MXwZPEZ4hwpbiQXfN/ NIng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=BbD6VI0WAZqcOWIe9t90I9j76OAQGf7qYc88DzkrQ3c=; b=ja4Wfc0pypdQZRwGuv1vgdSHo2lIbWwvLtMeGoD+ZccQ1zN9SCLZbquDw7e/mccnIQ Rt5ywNoLeruQWdMuElswua46/KYqMbBC40DfO16hWivvXZbm0K52z2HvqQJNEd3cgqgO cLCi7kp0LX994vj6mNREQ4P/icJn67/zMKjELxb37VTSFV3NMLYLH2k+F2kAUtQmIRAj RFLI6VTZ6gFYriTwmIxr6KfTnZ4fcsdILXqy8ydJ8bDgPZk1kcNbtbL/pbQNG39+V15p t3p22Hy9dIzdMWcuCCgvEeNghRFwEhbkPiBfFX4Qb+j5zXKWxSQdkJY2gpVesD0E+AOb aBQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=FI+XjthO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 73si327585qkb.181.2018.11.09.07.24.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 09 Nov 2018 07:24:07 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=FI+XjthO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34722 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gL8di-0004yM-MR for patch@linaro.org; Fri, 09 Nov 2018 10:24:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gL8bC-0001CS-5r for qemu-devel@nongnu.org; Fri, 09 Nov 2018 10:21:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gL8bA-00030Q-Fm for qemu-devel@nongnu.org; Fri, 09 Nov 2018 10:21:29 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:38703) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gL8bA-0002xU-2N for qemu-devel@nongnu.org; Fri, 09 Nov 2018 10:21:28 -0500 Received: by mail-wr1-x442.google.com with SMTP id e3-v6so2298968wrs.5 for ; Fri, 09 Nov 2018 07:21:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BbD6VI0WAZqcOWIe9t90I9j76OAQGf7qYc88DzkrQ3c=; b=FI+XjthORKzHYeHe4nGA+Y9YWreBdHdzRsGQDs7FBNPBbNNrFCm3SkXa0gUznnBGSh Du6yr22CNBYo45afB78+UwI/ce/nX3XKsLIbxc+sC2qG6tSsQ6P1jOR1dWv79YZ2bFev h+xSuGYcmjvXqpcgc9WZwX0oUOj+o2ll01xSI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BbD6VI0WAZqcOWIe9t90I9j76OAQGf7qYc88DzkrQ3c=; b=miNwqZTYCpk2/MXcRyVC8k2R3YzN8GY1iFiHxP978cTWvAR91Czzs4dTDKY0ziDPqk y5u+00quBm9fESw7GTofLw4qsTrCzdi6Wdsl3zylkqCkuL8lPSK52SoRk9a2jsncWcYX UAznasla+q5xPO3FLhnqjdbWuMl7PSnTVimn339vJvMJqnJVmT3W114t7522hk0V3fhk ZukQzcPVSy0l1a9hqyLGGI2NdARwtD3dliXhtZWlPs99C81sG9LAa5swEF4VgzXeLe4z Pnjv3z+wGRZawr8A4I7EWpxwpn1vtFcYWCUepXNIWXCFY0g1TTdgcA/IC9jfckywBWfm Bt4w== X-Gm-Message-State: AGRZ1gK0BX7cyokkUA2RqjDdmDbLs7fZqEQOi18qd5n96CZyHK7xA2kX /ifAxpbv1I0SGmT9bYsuLEcK7A== X-Received: by 2002:adf:ef85:: with SMTP id d5-v6mr8126702wro.163.1541776885898; Fri, 09 Nov 2018 07:21:25 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id e10-v6sm2019691wmg.23.2018.11.09.07.21.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 09 Nov 2018 07:21:25 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 9C74B3E05B2; Fri, 9 Nov 2018 15:21:19 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Fri, 9 Nov 2018 15:21:19 +0000 Message-Id: <20181109152119.9242-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181109152119.9242-1-alex.bennee@linaro.org> References: <20181109152119.9242-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v3 7/7] arm: fix aa64_generate_debug_exceptions to work with EL2 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The test was incomplete and incorrectly caused debug exceptions to be generated when returning to EL2 after a failed attempt to single-step an EL1 instruction. Fix this while cleaning up the function a little. Signed-off-by: Alex Bennée --- v3 - further re-arrangement as suggested by rth --- target/arm/cpu.h | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) -- 2.17.1 Reviewed-by: Richard Henderson diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 1efff21a18..814ff69bc2 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -2764,23 +2764,35 @@ static inline bool arm_v7m_csselr_razwi(ARMCPU *cpu) return (cpu->clidr & R_V7M_CLIDR_CTYPE_ALL_MASK) != 0; } +/* See AArch64.GenerateDebugExceptionsFrom() in ARM ARM pseudocode */ static inline bool aa64_generate_debug_exceptions(CPUARMState *env) { - if (arm_is_secure(env)) { - /* MDCR_EL3.SDD disables debug events from Secure state */ - if (extract32(env->cp15.mdcr_el3, 16, 1) != 0 - || arm_current_el(env) == 3) { - return false; - } + int cur_el = arm_current_el(env); + int debug_el; + + if (cur_el == 3) { + return false; } - if (arm_current_el(env) == arm_debug_target_el(env)) { - if ((extract32(env->cp15.mdscr_el1, 13, 1) == 0) - || (env->daif & PSTATE_D)) { - return false; - } + /* MDCR_EL3.SDD disables debug events from Secure state */ + if (arm_is_secure_below_el3(env) + && extract32(env->cp15.mdcr_el3, 16, 1)) { + return false; } - return true; + + /* + * Same EL to same EL debug exceptions need MDSCR_KDE enabled + * while not masking the (D)ebug bit in DAIF. + */ + debug_el = arm_debug_target_el(env); + + if (cur_el == debug_el) { + return extract32(env->cp15.mdscr_el1, 13, 1) + && !(env->daif & PSTATE_D); + } + + /* Otherwise the debug target needs to be a higher EL */ + return debug_el > cur_el; } static inline bool aa32_generate_debug_exceptions(CPUARMState *env) @@ -2833,9 +2845,6 @@ static inline bool aa32_generate_debug_exceptions(CPUARMState *env) * since the pseudocode has it at all callsites except for the one in * CheckSoftwareStep(), where it is elided because both branches would * always return the same value. - * - * Parts of the pseudocode relating to EL2 and EL3 are omitted because we - * don't yet implement those exception levels or their associated trap bits. */ static inline bool arm_generate_debug_exceptions(CPUARMState *env) {