From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796374105; b=Gdcl/1U8ysoaWwWBoIb4ggnY3SV87z+WzscNyMILJjDP0iaAMJFI5UTkGosQJhSleLtD JTlCBiukvXyQyjFRpCbymk6UaST8OCs6QTGjiyiUd51bdy1iNbDWZgxhLqXjjfg8NOFh/ JG75O6Yw6g7dIOY9KcoS8MSRXAy/ONyUnx2sw3FQ/n1stNGeOkEMWv6F4c/EvGmse3RDd hZgrQQeWwrcJaBQDZLkI2mv5uma3XputczIN5wOWoT2GMXIUgSONL4z9GtjIeNpPn3QZW 6d5q44gdKRNjI0JXKfzsSS78qGDJ2ay7k7ucRsAP5anMm8xfoFPStch/IranYfVyb1w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796374105; 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=NM03CoAmd2dQWjQu6VHT/nNl5Qn/P3/wF6ymXHA0faA=; b=sI/4X/ALY6A2dQ0289iC5ABV/IXhClTOeDL5c4nMyep/VZZLp+093eV+/GLkuOS0t+tL n6VBts6BpItzob++A2r69y7aaD6ti2v3NWt00Hl+a7QzDrWqygAZ282FKDMmZ7CnJ9Slu zdAmbtWl6yJwrVOl764yzePvCj/6zikNr1qsNF0xYrdHIVu1FQV3/Ip/BsNm19kOqFkSb RVNUnFEcjKPTaTFuEdvGI9ndeJI33QJuOcO/t17/t5Jk16yvagCuw975oSI1nSnMayZlC 2BriFPYckqFTyfVClIQE+XoTnIprNl+IPItKd0F4HJIVN2kkaZIHvVrKViiPSryIimg== 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=WWvn1VzC; arc=none smtp.remote-ip=209.85.128.41 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 5F339606A69C for ; Fri, 4 Dec 2026 08:48:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5F339606A69C 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=WWvn1VzC Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4bb6057b333so2923065e9.3 for ; Fri, 04 Dec 2026 00:48:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pereq.eu; s=google; t=1796374104; x=1796978904; 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=NM03CoAmd2dQWjQu6VHT/nNl5Qn/P3/wF6ymXHA0faA=; b=WWvn1VzCdQvQ7u3sggX3funaUwVc8/nBceG6G37qvJv250BUu1L/6+DI2BPsc4kGHC 3DMKdxwuam+jYSaeNJTXAbz4FF58e4o2WcRQbf365GthiF8wHWUEqXbCVJa3CKbGCgco F7WffMcOMw6qUdTV5gryZ6NXbHr9zc2aR5WGhovA4DxJftzbQcT4GPtv26savgC35I2R 8Uodjh5kv6Eh12nwUmIqDPpR5LXHsnx2BYaJSDVCF7C0tCGL465H99o5yr/HxZx1wPgb iJKWeJbbk+sbkqcg67GWw70kwsbn4X8CgQSGicSlktVv73MtOitGFtPymUDBh08E1oNJ G8jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796374104; x=1796978904; 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=NM03CoAmd2dQWjQu6VHT/nNl5Qn/P3/wF6ymXHA0faA=; b=M9Lj12L+tHrVINE/uIxAxC/A71/ULThj4Kr+Bp9P5Xy9j+E03FUDUFWW05qsBu2Daw d/0JFVK9xiOB1BtEIzkr58KhXtBsfU2joqKYG96dg6PmIWec7X/rHdKxnT2XH6n23+PH +FYVP3Q+lPnsZaVWD7vGeK/j69d5KDBIenI+BqGoZfUjH9Wj/GHTgU/9Iv1WX6RaN+ow llrpVWIdkYm6J/LCOvUYOkLytyGlgdCXDGYtEawdulLomG3WCRgSfPJmYx/woKyn2Zrf pPx1jc23XmOEuKbnfpm8Bb8YtaFic5BWFRs0BSI5+jc/aE8Ztxk3S8QKpUFj4703mAmx fZwQ== X-Forwarded-Encrypted: i=1; AL+hErFLYIr7sITEj+NBPXFKzCF/E7te4LKgOUQYd0WQfsxUXJMheVjQAkhXbEj5QdgLIKQ0x0jPiOmek+HJz3E=@vger.kernel.org X-Gm-Message-State: APuU4Z/38n+Me5DwZC4umqjpQMzmtLG2UYEkaVFzeUN6uVxNHxhIE2ZL 2NCt6rKMEFUkXeel4xPbPjoikyAtx7EZnuHUclLoP8Le5rEdh8ra/dTHZ7QSMTG8PJc= X-Gm-Gg: AZFdTZdxMfG95Q/TLhMA4fx8TZSJ5a1PtmIH3ckWWwaLOthCsKUWHavF3h06Xlx/4Ui df05C5nHiHNjYYiLH4nE9oRByvrw+YrbtZqX3Tl7vRyUUArOka47GbhFzhHJgQ7FJ5wkhSZxFl9 nUDFsNo+Vurd/+Q8v0Jg5HVbu4gWvRwj+u9SWwPub2qGB5KqeCbEOIuCYYIc3q6SY/YdhVdTlGi eqI1tXh59/8AfhHb92ybdZqjevmbRyusorxAOipuz2rPVqLTlmoW2OKtSWPJzrLuxyNL04jV6Cn fm4Oa4QdxEVXwwZRYkyhKFki0VEhWW9JxWMIXcA9RRtRFfevk2cuRVmTTapYU7ej7CHlmaURKvN qnjVs/J4CIyl+Oi839jfc8VwTqO1b9gtC9DNl7J4+DtSLIU47VjG0TjEkYmKAQXfbpt7Z48M1Bc rHG6HHnXkWRBZrX2ujp+0YGaVJZZH4qB3E4xzFL7SiWYiWrE8/098+V3UNelswFauiI7i/9nVUy wvIJotPw2tYO+NzFDb/JBNjUl8Gxm6cK8mvok34W+fvYB7rbz81GLG8gtwxvFPg1nD6Sn7DEokO zguNveICqmqqLX5o5jg= X-Received: by 2002:a05:600c:a4b:b0:4a7:8fe8:130c with SMTP id 5b1f17b1804b1-4bbeb8d0de5mr20720805e9.28.1796374103631; Fri, 04 Dec 2026 00:48:23 -0800 (PST) Received: from localhost ([2c0f:3d00:6be:8900:ce5e:9212:ea4b:f30]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbea2ac245sm34676285e9.13.2026.12.04.00.48.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 00:48:23 -0800 (PST) From: Dan Carpenter Date: Fri, 04 Dec 2026 11:48:07 +0300 Subject: [PATCH v4 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: <20261204-double_exception_v4-v4-3-523921511673@pereq.eu> References: <20261204-double_exception_v4-v4-0-523921511673@pereq.eu> In-Reply-To: <20261204-double_exception_v4-v4-0-523921511673@pereq.eu> To: Marc Zyngier , Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Marcelo Tosatti , Rusty Russell , James Morse , Eric Auger , Sebastian Ott , Paolo Bonzini , Sean Christopherson , Shuah Khan Cc: 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, Dan Carpenter , 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 Reviewed-by: Steffen Eiden Signed-off-by: Dan Carpenter --- v4: Drop the "NULL on s390" comment (Steffen Eiden) 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 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h index 2d7c82cfb8a4..b66689818515 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -777,6 +777,8 @@ 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) { + 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 +792,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