From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.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 78CB536655C for ; Fri, 12 Jun 2026 10:23:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781259831; cv=none; b=eo1/Xg9Fx4Kc3zZx9g4931mBghKTd4BpADzFuI8Lfw6jGwtaNWQwqwtrxYwqQc52kAnruCIUMLqbRlcZGyZNTYsaJPFna4EbycwSGyqlQqhezmiRZSX7lhHAhBA4wyP/P/U0155jt45f/LQlHfbIZa8NKE6696heEX0BPlzpH8s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781259831; c=relaxed/simple; bh=2bp6i2caV1IPgQ36ib4fF6m+6xLxOZWEJFaOoMYDZnQ=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=L51hOqOHTYFTTnQqUTzpE4+G8flSUlWovHZZhR5BeXJf3ISKsumG61KaMmCv7lYNCQLHQIY4YPZO1r2XChQwAombPLy/WIhzJX3TpsnNlBQ76nVLh/yS+Fp32t5Izgq82WfSvTg8vutatT6tyfyn7MOVBBYVCbkI8OwEaB1YXHc= 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=aR24p8LB; arc=none smtp.client-ip=209.85.128.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="aR24p8LB" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-490b3ec3f7fso4875845e9.1 for ; Fri, 12 Jun 2026 03:23:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781259829; x=1781864629; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=0YFcRPBWc1sBVr+dWmTbZ0TsBZp12xAJxg+DiPsswnA=; b=aR24p8LBHrIT+3Rc7EvXz0KXcAMiqksiKtpo/FQUIztWirgzTKXo1s+9/i/0GEaYya ATYAeqOpK6fjPFYMnvdotmdj8JSNTHI24HoEsE6XQIBRYSvxyYLHT4z44SyXPLsPHMxj UQlJlTE4kb90Rcm8LNjXKHBgRnMKLE5qUiCIfLN40aj17FvcWEweFYS+cTol5cQ/k7L9 kUtw3IqoJ11V/kQdCitrP78kFAD833kXE5Pcim0twEWs4AVxN894FwDcV25FV6K7U19j NUx0xDPVm1DH0DruH4aHppHYZA9nSMuG5rFMXQmPw3eAMREymMiUaUMuoAfuKgyjsiv8 AjIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781259829; x=1781864629; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=0YFcRPBWc1sBVr+dWmTbZ0TsBZp12xAJxg+DiPsswnA=; b=MAEjFOyJ2/4yWbAmh08Gi10OZEn8nKqwlGiVumVepV8K2m6zxQ8ufJY4rAgJvZnCpg MOXPA2wVuGAALPUho/ylCWFUDtMAgaIVbBjjx0sjkFOsqR+7ALTugOY1breshbjGS3d8 Wu5Ws+9pEYS1VFjoL6iKpuKS4kfb92qEJpbGy9MTkAKvNv1/X3Q19WHlIdVKlrTdwXVd JLbOw3UmC0tI0hrYO6xtPut+q5Lgyc4YEf4Ucbn3OGPm4LbD7eO2vxck6cg8vh9J4MHZ zlgufdIKRXDbMrVDZrqoJIbUn4S+Te8XgYsYWH145Lf1g5KSj6Mi20/1W+0KOgZB7DPL 7Nyw== X-Forwarded-Encrypted: i=1; AFNElJ+QuhCZY0CV/ZPq0f6ZfKp9O5GwvErpe8lOKLBfVvejvYw3ySOi//H64CQ0xknJHPTT/yYYPgh9ylCVVco=@vger.kernel.org X-Gm-Message-State: AOJu0Yzk9CRwA2ZSMoxIh/wWVlpOBX8WzwlxqhVlYUER+hCEbYfOEoTj MwhgyEzhOug4XDwkgOCRm1gVknWUmMSjt1gb7R3593uI9aKKPDicD4gYPlK07tdCOv3j/IAPI3b EHg== X-Received: from wmlu18.prod.google.com ([2002:a05:600c:2112:b0:490:b58a:2c9b]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:21da:b0:490:b99c:9337 with SMTP id 5b1f17b1804b1-490ec4c1712mr18163655e9.10.1781259828771; Fri, 12 Jun 2026 03:23:48 -0700 (PDT) Date: Fri, 12 Jun 2026 11:23:47 +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: <20260612102347.914994-1-tabba@google.com> Subject: [PATCH] KVM: arm64: Sync SCTLR_EL1 when injecting an exception into a pVM From: tabba@google.com To: Marc Zyngier , Oliver Upton , kvmarm@lists.linux.dev Cc: Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Sascha Bischoff , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" When pKVM injects a synchronous exception into a protected guest, enter_exception64() reads SCTLR_EL1 to set the new PSTATE's PAN and SSBS bits. pKVM refreshes VBAR_EL1 from the live value before injecting but not SCTLR_EL1, which is untrapped for protected guests, so a guest that updates it and then traps takes the exception with stale PAN/SSBS. Sync SCTLR_EL1 alongside VBAR_EL1. Fixes: 798eb5978700 ("KVM: arm64: Sync protected guest VBAR_EL1 on injecting an undef exception") Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/nvhe/sys_regs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/sys_regs.c b/arch/arm64/kvm/hyp/nvhe/sys_regs.c index 8c3fbb413a06..7608cc4030b8 100644 --- a/arch/arm64/kvm/hyp/nvhe/sys_regs.c +++ b/arch/arm64/kvm/hyp/nvhe/sys_regs.c @@ -257,10 +257,11 @@ static void inject_sync64(struct kvm_vcpu *vcpu, u64 esr) *vcpu_cpsr(vcpu) = read_sysreg_el2(SYS_SPSR); /* - * Make sure we have the latest update to VBAR_EL1, as pKVM - * handles traps very early, before sysregs are resync'ed + * Sync VBAR_EL1 and SCTLR_EL1, both read by enter_exception64(), + * as pKVM handles traps before sysregs are resync'ed. */ __vcpu_assign_sys_reg(vcpu, VBAR_EL1, read_sysreg_el1(SYS_VBAR)); + __vcpu_assign_sys_reg(vcpu, SCTLR_EL1, read_sysreg_el1(SYS_SCTLR)); kvm_pend_exception(vcpu, EXCEPT_AA64_EL1_SYNC); -- 2.54.0.1136.gdb2ca164c4-goog