From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3B4A392C52 for ; Fri, 12 Jun 2026 11:34:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781264059; cv=none; b=q6T/iFFyYZ5DFGlonAsjDVYgf+8oYnwV9NPdM1TLQptAifSAUMB2gtNaJHROsXCqnrVp3mQc1YvFveFVRQpgF7R36ZjSJo/dE5+F/5Rvczg66HArtCI5yv6Z7aydzz8d4Ki0HlfiHrkkJ3Jn5MofduY1Mc0BGMrkqhixn6JmGDg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781264059; c=relaxed/simple; bh=39WpqfsqMXIC7gz122vRXwFEhrpbSRz2/WCB6ufDKeg=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=ZkUuoawkeGyhlgIPjxNNahtCsl2nnkdjDjIBG5uzMtyn7AuxLKBX22iCZJTThD8xV9RE9f8j5/wvNqtYoF6YtFC7FIbqG9QBNE5LVjuUNZfkihttcqZjDeN75bxgtSAbItggi+cJARJmZ8MH6jVMDIhqfVuFO9BRJ85AP2+Vbgg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tabba.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=bCK4Mka9; arc=none smtp.client-ip=209.85.208.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tabba.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bCK4Mka9" Received: by mail-ed1-f73.google.com with SMTP id 4fb4d7f45d1cf-68c6649a135so747679a12.0 for ; Fri, 12 Jun 2026 04:34:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781264055; x=1781868855; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Xa5/25SiNRkAqSjzYKvz46uYWaA8u0CL9trp73+tAk4=; b=bCK4Mka9XqTC5AsYzCLsX8CUu6qjZEr0hxfxTwwkOK16xIsAo+gywrUFBw6q1b7fNM /ZJ9R1nb7Xhy3f4AnrkbHGupNor7d+e4+poAJTP9TA6muH1RKw1Zuq/lr2G8ICzXnrMq WTsNkDVSOxp5PGJ8hglmtIACjkW4iD5HfS5f5uEsWG8EZvXTttQqz5CVF2uZQn5vnerU hndLc7Lq+6T7Lvn749ERb0+3yPanHmNc1/7eruH3bJ1GkVQsiucpZgO7MyOFMd4+3b4v Oo0zrmQe8kwVGBILd0e9kk9bV6vjGltOrSpXo7ipqrmYGVTcWb8MwI+kjpSFB2dj5TBw 1A4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781264055; x=1781868855; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Xa5/25SiNRkAqSjzYKvz46uYWaA8u0CL9trp73+tAk4=; b=cvf4b47hAWvPz0Y8qMQURwKoKR2GtmDhidprrhNUGB+PS65kFSIsw9lJI59e+3AdYY bc8ObdXnAC4XGdlIosR5CxtbSmCNKdmH/iOMkwEHW2yKwdkvi1j+J5xJ8zleN/pCnS+x wRJxAOBstvzvMWj8wCYB2a/prHcWeJd/5ZipvqKPmZgBggweuIBoV42bpWJigGlUKqR+ s0IqxtcoqCac/IiB9SLmlZHKYnbX7L2cchW+kH1j/g/WstLrjk6L0Dn/eK6Utb2n3XAz C+rMfws+IJkC+Tibs+gvffrfFDH4sPRvvHwf+iNZMOR/PwdzgbmqDbYp00kqt5g152mb imUA== X-Forwarded-Encrypted: i=1; AFNElJ/Ci4K3mJl/C4B62qyfziGKVVSVKQRWRdfrqFGKW3BFEZ/IfL9srlbJtxfvLh/w3Sfo43YftHrjBCyykGY=@vger.kernel.org X-Gm-Message-State: AOJu0Ywv81pZOwmRpVPigzNyMoVPA1pTjajtJmG5mYrePpZ8mhWfYZUF EIDlyKlp4rCByEUYqCqphZ2S+OGbAG52/s0fyzBn9fpgCQt/iMf3FjJ/UsytssWB+k9UHRWwBGa eaQ== X-Received: from edber23.prod.google.com ([2002:a05:6402:4497:b0:691:acc4:471e]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:3607:b0:691:956a:cf6a with SMTP id 4fb4d7f45d1cf-693785fed15mr1080488a12.12.1781264054903; Fri, 12 Jun 2026 04:34:14 -0700 (PDT) Date: Fri, 12 Jun 2026 12:34:14 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.54.0.1136.gdb2ca164c4-goog Message-ID: <20260612113414.1022901-1-tabba@google.com> Subject: [PATCH] KVM: arm64: Sync SPSR_EL1 when injecting an exception into a pVM From: Fuad Tabba To: Marc Zyngier , Oliver Upton , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Sascha Bischoff , Andrew Jones , tabba@google.com Content-Type: text/plain; charset="UTF-8" When pKVM injects a synchronous exception into a protected guest, it re-enters without restoring the guest's EL1 sysregs and writes the EL1 exception registers to hardware by hand: ESR_EL1 and ELR_EL1, but not SPSR_EL1. enter_exception64() sets SPSR_EL1 (the interrupted PSTATE) only in memory, so the guest's handler reads a stale SPSR_EL1 and restores the wrong PSTATE on eret. Write SPSR_EL1 alongside the other exception registers. Fixes: 6c30bfb18d0b ("KVM: arm64: Add handlers for protected VM System Registers") Reported-by: sashiko Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/kvm/hyp/nvhe/sys_regs.c b/arch/arm64/kvm/hyp/nvhe/sys_regs.c index 8c3fbb413a06..1a7d5cd16d72 100644 --- a/arch/arm64/kvm/hyp/nvhe/sys_regs.c +++ b/arch/arm64/kvm/hyp/nvhe/sys_regs.c @@ -268,6 +268,7 @@ static void inject_sync64(struct kvm_vcpu *vcpu, u64 esr) write_sysreg_el1(esr, SYS_ESR); write_sysreg_el1(read_sysreg_el2(SYS_ELR), SYS_ELR); + write_sysreg_el1(read_sysreg_el2(SYS_SPSR), SYS_SPSR); write_sysreg_el2(*vcpu_pc(vcpu), SYS_ELR); write_sysreg_el2(*vcpu_cpsr(vcpu), SYS_SPSR); } -- 2.54.0.1136.gdb2ca164c4-goog