From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796028515; b=jyf0vIXBuxYoCCvAolPpxZ75x3ZE/x6cuyJXo0tNrFHGOHVPAc7S9ADnhbMEBkezB5OH 7x85300JbU9CBa2WpfyBJmIU7g27oUCpLZCORfItLNfHAfv1/gm/dGBCIJGKuA2JSMeNW GOPzB1hkM4B5HiWZFFbjtduoVQ/n7hZe1rHfPwwJSzR16YZSY0YSZ5xyHMh1ov02xXisS kIctq3o9cIO6DTA2V2Ww8KY+wOWF6vHu1/waN4L5yd0byrpEsC5Fy4EDx1f6QEQO88RwY 50IBB9ZQOE4eqe+7Bxe4+tHm7DlDLh4J4NtnhZxn8Tnq+OIc6O9vNKr076AFet+lFDA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796028515; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=6uTSobnL4k4ybO4ZXY4EpWCjeat9pQnMAIUKoVaT0bk=; b=TfPTPcfVlsqWKqEOrOQ97F5OPlNsi5ucVqOB2V0fpWAJ8E/mr/4wY/XxA62jKrLnJ67Z Um77VIMH19A4Ta6AvznJw/KG/cstJjnpWeBccMvnaf46nVFVKr1XO0wRBZflxaUVedHr1 wzGeNcj8HHWiyqaCsJvoOlD6Ym2NS+EWp6cuHKkwMvvVv+FJqFg39KFJkIv5j36pDxJsj a4xESuBq4m8guE1HJJ9RXyk/v0v0c3Vy+U0bqYFPKslqFfFqXalbFFsPXQy3vd/QR+4SD adFG2o+bvlnZLzFDHJflrOMvVYXRP6oao9YET2Y4sn6Mw82bjC4ngYfCvkqzBU3CKPw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=pereq.eu; spf=pass smtp.mailfrom=cryspen.com; dkim=pass header.d=pereq.eu header.i=@pereq.eu header.a=rsa-sha256 header.s=google header.b=SYsY+2SG; arc=none smtp.remote-ip=209.85.221.51 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26F49606A68C for ; Mon, 30 Nov 2026 08:48:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 26F49606A68C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pereq.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cryspen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pereq.eu header.i=@pereq.eu header.a=rsa-sha256 header.s=google header.b=SYsY+2SG Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-4a358881793so5341766f8f.0 for ; Mon, 30 Nov 2026 00:48:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pereq.eu; s=google; t=1796028512; x=1796633312; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=6uTSobnL4k4ybO4ZXY4EpWCjeat9pQnMAIUKoVaT0bk=; b=SYsY+2SGO+PCX4Sbca/o6bCkc3pMD7DaGyc34za3W1iIC6orRpeuaZQwV3fZODWtYl l3L+pcAiKg/ehBlPcHEnMQuGCgEr77TxBh4HJrO2o2znoH1poVrz6qI8+S+JnPmoF+nK cOG6IFFOAtgeA7sFr7A+sHmt5igq+1ct8iizuFZptsZPYuh9xmTNByLlV5r80gHuery4 1taZRoCkt/LiOy9iRMRgJAht7tjAk+Lqri/eav/EVF76NNostBCM5KouhRIZCsg2R1Rb AiqjHSzKt5WygegPxHqrkRXn9nMxXEotC+MkmRWSEXX2EBv8MpmmhXCgqJ6FGnFTLye1 K5Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796028512; x=1796633312; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=6uTSobnL4k4ybO4ZXY4EpWCjeat9pQnMAIUKoVaT0bk=; b=ysz6eKd5LOfCzqFgHGRdq2owdncclZax+VqSTFW+qbcAucsGSNg/g8r14khWbsL77C TxsF6Dq+qU0TWHn9bNx1CPgnqdr98YeJkX01zJXUwuQ5lknOKjYq0E7/LvMtY7W6Ubji ksVLRpByVhFdYTVhmaDQr0nVs7ss2P9xfya41SfFXy4B8k/VskO7ZOYdiQxWJsklGOnF vk/3qR4U/QIygVJHpCXQKK+6rO6Xy4xjPRQU7yphfgyPNDjfk6k/nJWrefTjmLoV9UYw IdvxZTcbTf2uWe5OFdlZVbrThFfCisJStJ0ITmjnX8009jIZWJpx/5fXsv7+j8YC+u0J ntpA== X-Forwarded-Encrypted: i=1; AL+hErEWNW1QLi4WBBC5q+boTzKwKVTVjmKsc5EW1Q1Ua0lgS8yFU7vXUo9Ua4n1eL6D1J5S7HsY4TvvHX668wk=@vger.kernel.org X-Gm-Message-State: APuU4Z9Cl6zhAY7ThMMQtwZyE0cn3cMq1/c7ylXOSYSprmaeTpLh01HI kSbfUN4VPvKQj83UVKAtdCj+CPD3cm0Vo7HL1UadjN+kKzlyzNFmUe9syWm9SYkH5ZA= X-Gm-Gg: AZFdTZefOt/sguerOY1h3Fw24pNFE+Z59bGVIjXzBMTr48Lh5LO8vF0mNAunRgr3REE io6TAaLr7YJgN+kcc3KdPdG36MpfaJ6BQNyKvSUr8hzVBDwMlU+TAjf49ewsShLJgyecVVACg4q BJpNP+GIdObk55Pc4/VBG0N4lbt+f+3Uqrqi4HinRia6wBPJtMnDtHuehrpPH2vtXmGu0tUE55y qGxFDIhVlUYMHazO0xEzF+nl1QPcJsj3BDWzfIPs2VzUfrDcYIYsfdUZnN0hbBivvbrXaKDyWMl kmhPEb7bPh79CbzxBYNwR3O2l7ftcuehV6bIWDdWGpIUayZZpNIgVfluFXFYfmcXfE86gwFkdhj YFD5CGIgZa3md3fdGVggeRgOHnVh7/U51flEQ1wocF4dE8IYwgZwTnMPRLZO9YSPRqUxI/+Ip1i IFxNdxd6Lhmyz7HlhkcwccFn86fWHZwG7Cir++dz+lWL3zAw1Lf+Id2DrPA44gkl2kQXkP+G15k 98+A1IvmauxSpCiflUW6zL4zO+ELabp05PRWyW0zgGSda6q3dh9+g/DV2KG6Az6SmvwZD0xopXC 1N7OUx84vBmHEV5GY8U= X-Received: by 2002:a05:6000:2f87:b0:4a6:bc53:246b with SMTP id ffacd0b85a97d-4abb5144ebdmr62647432f8f.30.1796028512349; Mon, 30 Nov 2026 00:48:32 -0800 (PST) Received: from localhost ([2c0f:3d00:6be:8900:ce5e:9212:ea4b:f30]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ad6403fdbbsm52857691f8f.15.2026.11.30.00.48.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 00:48:31 -0800 (PST) From: Dan Carpenter Date: Mon, 30 Nov 2026 11:48:15 +0300 Subject: [PATCH v3 3/9] KVM: arm64: Reset SP_EL1, ELR_EL1 and SPSR_EL1 when resetting a vcpu 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-double_exception_v3-v3-3-864856664b26@pereq.eu> References: <20261130-double_exception_v3-v3-0-864856664b26@pereq.eu> In-Reply-To: <20261130-double_exception_v3-v3-0-864856664b26@pereq.eu> To: Marc Zyngier , Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Rusty Russell , Marcelo Tosatti , James Morse , Sebastian Ott , Eric Auger , Paolo Bonzini , Sean Christopherson , Shuah Khan Cc: Dan Carpenter , Karthik Bhargavan , =?utf-8?q?Cl=C3=A9ment_Blaudeau?= , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, stable@vger.kernel.org X-Mailer: b4 0.16.0 Resetting a vcpu keeps the old values of SP_EL1, ELR_EL1 and SPSR_EL1. Commit e47c2055c68e ("KVM: arm64: Make struct kvm_regs userspace-only") changed the reset to only clear the general purpose registers, SP, PC and PSTATE, and later commits moved these three registers to the system register array without a reset value. Commit 85d703746154 ("KVM: arm64: Fully zero the vcpu state on reset") fixed the FP registers and the 32-bit SPSRs the same commit missed, but not these three. The impact is that the guest that boots next can read the previous kernel's stack pointer and exception return address. KVM_GET_ONE_REG also returns the old values to userspace, and a rebooted VM doesn't start in the same state as a new one. Zero them in kvm_reset_vcpu_core(), which pkvm_reset_vcpu() also uses when a protected vcpu is turned on with PSCI CPU_ON. Fixes: e47c2055c68e ("KVM: arm64: Make struct kvm_regs userspace-only") Fixes: 9d4ec80be2eb ("KVM: arm64: Handle PSCI calls for protected VMs at EL2") Cc: stable@vger.kernel.org Signed-off-by: Dan Carpenter --- v3: Suzuki K Poulose pointed out this should be done in kvm_reset_vcpu_core() instead of kvm_reset_vcpu(). v2: new patch --- arch/arm64/include/asm/kvm_emulate.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h index 2d7c82cfb8a4..a40f434b64f0 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -777,6 +777,9 @@ static inline void kvm_reset_fpsimd(struct kvm_vcpu *vcpu) /* Reset a vcpu's core registers. */ static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu) { + /* NULL on s390 */ + u64 *elr_el1 = __ctxt_sys_reg(&vcpu->arch.ctxt, ELR_EL1); + u64 *spsr_el1 = __ctxt_sys_reg(&vcpu->arch.ctxt, SPSR_EL1); u32 pstate; if (vcpu_el1_is_32bit(vcpu)) @@ -790,6 +793,11 @@ static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu) memset(vcpu_gp_regs(vcpu), 0, sizeof(vcpu_gp_regs(vcpu))); *vcpu_pc(vcpu) = 0; *vcpu_sp_el0(vcpu) = 0; + *vcpu_sp_el1(vcpu) = 0; + if (elr_el1) + *elr_el1 = 0; + if (spsr_el1) + *spsr_el1 = 0; kvm_reset_fpsimd(vcpu); vcpu->arch.ctxt.spsr_abt = 0; vcpu->arch.ctxt.spsr_und = 0; -- 2.53.0