From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796057002; b=RUWjbaObPwFprkIi8thHG3SAvwxTA9U52H0kFn4bzPCmNZozXPJ4XwNoQJB2aoPew/vs pfV2v66HiEGDTqwM7Bgps2IqIUWAWTTw/gR5Fxx26D50VskU7DEXDbh9wdlEAZ286rKWr LxJFXh/RPKOm51vaYkN/bJASGP5zdeRYdmKWHBjoDiO5TzsTRW6tNflE+W0PQRiSzXZFA kL6CVPehsnJbQnCAS3Y3RNZPp8NV8DY851RiIVDy6tewqQ67tEk159wBCzAogX0unPh+V xZKB6hn9N5Q0X42IkNtT78ZW2vR+BBynLUPvK9CLN/ezbNahqv1E90tAbc5XrZWStfw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796057002; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=y27qswmp6MSP3Fv4qlwhFTia0tfbvNvZKWNNm6ypSBk=; b=3p8iVHXzMrJXMPmuEp7C7de4WXmS/KFTd/zdgXWWpLxxg/ioA3A/h/4wNVMI2/SmaP7N JM8QQqcj2vIrczTRCOEmV6X5bWNGb6TSr5gG4P4Jpjz9i9KqUxGe77CvedktE0Pdeqqk/ nud9xHC2yXpwH7KLOiDz09AxE4lUGb7e2rkuTkqbehY24CMjGiQm5cBjqGTZCoGmWYRzv nD6+bCmCk2ZSudTl3vwZz9g4p+u18YWsAG9XMAg/6YlS5Pj7IFcO/B+q61x3RwMmR4mVU lzqyaxi1DUlqbxQQExrc7hngneTk3HQmGEE0xgP0ji8o6pKMX2xnQS1OaO7P7XJmbtw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=S0HivqLU; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF7E3606A327; Mon, 30 Nov 2026 16:43:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=S0HivqLU Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE8551F00934; Mon, 30 Nov 2026 16:43:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796057002; bh=y27qswmp6MSP3Fv4qlwhFTia0tfbvNvZKWNNm6ypSBk=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=S0HivqLUU08HXbkCL3dDD9am7bM+3yaBYcuLwQ/vTlZxD5wqAHrP9dV/alrDlGVRG sz3CbL9ItxtO130N4eF4cM6d9y5C8cCrEorQHZoe/+JMDEItm4Y3hr2wQsttjCIjvP s9XzaoHXWS6lpnY60Gw6OFScXupO5qCaXv6WqvSsb/uE2QwdnQFAlEa+ZrR/oBwA7v kz1ayXhp+Pk+VjX5Zb31qGhUY9V6WrUYFH/M+ZpHLyqNHRMBgp6k0302YeMPCz/CCW 8P0Tr+bWH4W2DmUSKhoR5SxYN1XNVm5BWUZEMOjGzxhkq3QyFXimGkdxB+1xVBSq0B xtLL6SAIFrp+A== From: Mark Brown Date: Mon, 30 Nov 2026 16:35:46 +0000 Subject: [PATCH v22 05/16] KVM: arm64: Set PSTATE.EXLOCK when entering an exception X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-arm64-gcs-v22-5-80454edf47ea@kernel.org> References: <20261130-arm64-gcs-v22-0-80454edf47ea@kernel.org> In-Reply-To: <20261130-arm64-gcs-v22-0-80454edf47ea@kernel.org> To: Catalin Marinas , Will Deacon , Marc Zyngier , Joey Gouly , Suzuki K Poulose , Shuah Khan , Oliver Upton , Fuad Tabba Cc: Peter Maydell , Leonardo Bras , Wei-Lin Chang , Yao Yuan , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown , "Lorenzo Stoakes (ARM)" X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3350; i=broonie@kernel.org; h=from:subject:message-id; bh=oecUOQ3KfhkvM8HpOGN2KW0f6/424MF23GpTGADw7p8=; b=owGbwMvMwCWm/754w+YLFp2Mp9WSGLJ5l7dP/aHgFeHKZ6JyzGLCjFO/xE+Fms8r2MZz82vzb l+9Nx3hHaUsDGJcDLJiiixxWdwv60ter+E7uLANZg4rE8gQBi5OAZjIpmUMf/j6+mP4T+n1fOVw 1VsSYFl0x2xqRvjJPOHtRVqR724fYWb4p7U/sM5hOSvb77tzd5X+lpu3eJKF84/70pcdyoV7C26 c5gcA X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB As per DDI 0487 R_WTXBY we need to manage PSTATE.EXLOCK when entering an exception, when the exception is entered from a lower EL the bit is cleared while if entering from the same EL it is set to GCSCR_ELx.EXLOCKEN. Implement this behaviour in enter_exception64(). Reviewed-by: Yuan Yao Reviewed-by: Leonardo Bras Reviewed-by: Lorenzo Stoakes (ARM) Signed-off-by: Mark Brown --- arch/arm64/include/uapi/asm/ptrace.h | 1 + arch/arm64/kvm/hyp/exception.c | 40 +++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi/asm/ptrace.h index 0c8c6a126c3b..ac38744951c7 100644 --- a/arch/arm64/include/uapi/asm/ptrace.h +++ b/arch/arm64/include/uapi/asm/ptrace.h @@ -56,6 +56,7 @@ #define PSR_C_BIT 0x20000000 #define PSR_Z_BIT 0x40000000 #define PSR_N_BIT 0x80000000 +#define PSR_EXLOCK_BIT 0x400000000 #define PSR_BTYPE_SHIFT 10 diff --git a/arch/arm64/kvm/hyp/exception.c b/arch/arm64/kvm/hyp/exception.c index 7521bddf73e4..ce482c5dedfc 100644 --- a/arch/arm64/kvm/hyp/exception.c +++ b/arch/arm64/kvm/hyp/exception.c @@ -49,6 +49,37 @@ static void __vcpu_write_spsr_und(struct kvm_vcpu *vcpu, u64 val) vcpu->arch.ctxt.spsr_und = val; } +static bool compute_exlock(struct kvm *kvm, struct kvm_vcpu *vcpu, + unsigned long mode, unsigned long target_mode) +{ + u64 gcscr; + + if (!(kvm && kvm_has_gcs(kvm))) + return false; + + /* GCS can't be enabled for 32 bit */ + if (mode & PSR_MODE32_BIT) + return false; + + /* When taking an exception to a higher EL EXLOCK is cleared. */ + if ((mode | PSR_MODE_THREAD_BIT) < target_mode) + return false; + + /* + * When taking an exception to the same EL EXLOCK is set to + * the effective value of GCSCR_ELx.EXLOCKEN. + */ + if (is_hyp_ctxt(vcpu)) + gcscr = vcpu_read_sys_reg(vcpu, GCSCR_EL2); + else + gcscr = vcpu_read_sys_reg(vcpu, GCSCR_EL1); + + if (gcscr & GCSCR_ELx_EXLOCKEN) + return true; + + return false; +} + /* * This performs the exception entry at a given EL (@target_mode), stashing PC * and PSTATE into ELR and SPSR respectively, and compute the new PC/PSTATE. @@ -113,7 +144,6 @@ static void enter_exception64(struct kvm_vcpu *vcpu, unsigned long target_mode, kvm = vcpu_get_kvm(vcpu); if (kvm && kvm_has_mte(kvm)) new |= PSR_TCO_BIT; - vcpu_put_kvm(vcpu, kvm); new |= (old & PSR_DIT_BIT); @@ -141,6 +171,12 @@ static void enter_exception64(struct kvm_vcpu *vcpu, unsigned long target_mode, // PSTATE.BTYPE is set to zero upon any exception to AArch64 // See ARM DDI 0487E.a, pages D1-2293 to D1-2294. + // PSTATE.EXLOCK is set to 0 upon any exception to a higher + // EL, or to GCSCR_ELx.EXLOCKEN for an exception to the same + // exception level. See ARM DDI 0487 R_WTXBY. + if (compute_exlock(kvm, vcpu, mode, target_mode)) + new |= PSR_EXLOCK_BIT; + new |= PSR_D_BIT; new |= PSR_A_BIT; new |= PSR_I_BIT; @@ -150,6 +186,8 @@ static void enter_exception64(struct kvm_vcpu *vcpu, unsigned long target_mode, *vcpu_cpsr(vcpu) = new; __vcpu_write_spsr(vcpu, target_mode, old); + + vcpu_put_kvm(vcpu, kvm); } /* -- 2.47.3