From nobody Wed Feb 11 02:06:16 2026 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F015C26F288 for ; Tue, 10 Feb 2026 00:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770684922; cv=none; b=MEu5CPN4kq0pJSd+5Mz6hODIHYehuYBhjKv1UQ5TCektDZ7ql+qxV42Pu95gLTd5oJUei+T7EaAmBQbpEi4QEbUuUBp8LWtLJbNU24SmwWgwle4SgK0OvweDpK6HHCyjy9y3y7xlsfzCNPwAp0ofVBy3iBzVkH6PqlzZ541jBfY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770684922; c=relaxed/simple; bh=8qdbIjRxa9nJLV9evrdN17b0sf2bnxg2AJ97er+o+Rw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bydKFfLxG5sf2gEzNJlvpO71o+9O5Y9en87/b7ZoWl1l87T1LMznx1lVZgacVBcWnROb51CIIIpvd9Ii9stQJwzzfYnd7trzOthVecHb53xprDgL+tKNeh6l96QfNGCg8E2BpR7IguKE5n/f1Yhl9QuwqDe0omNks+B42j5ZwwU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=u9QMHXYj; arc=none smtp.client-ip=95.215.58.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="u9QMHXYj" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1770684919; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2J5PouiLGGC2lSaBelHHWIjarzEiNNlCjAXNBFFbCqM=; b=u9QMHXYjgL7ULBxfZcR5DWb5xZeuBRaKuH5LatfmAO9CB4tsnF+oUZokxdj3QTnv9pw6yi G3zph5tjf3bSQ577QAzG+eUFUnLT+1Ue+zga+eCaywn4KIFStYJFCAb2Qz6HYV78J6hmh4 yRhU/uS1PoXsodxACXLV9FlHwZDavoI= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed , stable@vger.kernel.org Subject: [PATCH 2/4] KVM: nSVM: Sync int_state to cached vmcb12 after VMRUN of L2 Date: Tue, 10 Feb 2026 00:54:47 +0000 Message-ID: <20260210005449.3125133-3-yosry.ahmed@linux.dev> In-Reply-To: <20260210005449.3125133-1-yosry.ahmed@linux.dev> References: <20260210005449.3125133-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" After VMRUN in guest mode, nested_sync_control_from_vmcb02() syncs fields written by the CPU from vmcb02 to the cached vmcb12. This is because the cached vmcb12 is used as the authoritative copy of some of the controls, and is the payload when saving/restoring nested state. int_state is also written by the CPU, specifically bit 0 (i.e. SVM_INTERRUPT_SHADOW_MASK) for nested VMs, but it is not sync'd to cached vmcb12. This does not cause a problem if KVM_SET_NESTED_STATE preceeds KVM_SET_VCPU_EVENTS in the restore path, as an interrupt shadow would be correctly restored to vmcb02 (KVM_SET_VCPU_EVENTS overwrites what KVM_SET_NESTED_STATE restored in int_state). However, if KVM_SET_VCPU_EVENTS preceeds KVM_SET_NESTED_STATE, an interrupt shadow would be restored into vmcb01 instead of vmcb02. This would mostly be benign for L1 (delays an interrupt), but not for L2. For L2, the vCPU could hang (e.g. if a wakeup interrupt is delivered before a HLT that should have been in an interrupt shadow). Sync int_state to the cached vmcb12 in nested_sync_control_from_vmcb02() to avoid this problem. With that, KVM_SET_NESTED_STATE restores the correct interrupt shadow state, and if KVM_SET_VCPU_EVENTS follows it would overwrite it with the same value. Fixes: cc440cdad5b7 ("KVM: nSVM: implement KVM_GET_NESTED_STATE and KVM_SET= _NESTED_STATE") CC: stable@vger.kernel.org Signed-off-by: Yosry Ahmed --- arch/x86/kvm/svm/nested.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 70086ba6497f..ff24a5748c7d 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -523,6 +523,7 @@ void nested_sync_control_from_vmcb02(struct vcpu_svm *s= vm) svm->nested.ctl.event_inj =3D svm->vmcb->control.event_inj; svm->nested.ctl.event_inj_err =3D svm->vmcb->control.event_inj_err; svm->nested.ctl.next_rip =3D svm->vmcb->control.next_rip; + svm->nested.ctl.int_state =3D svm->vmcb->control.int_state; =20 /* Only a few fields of int_ctl are written by the processor. */ mask =3D V_IRQ_MASK | V_TPR_MASK; --=20 2.53.0.rc2.204.g2597b5adb4-goog