From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 510ED35940; Tue, 30 Sep 2025 14:51:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759243914; cv=none; b=EHT4Eiz9k7eGyB8Txlwh9psdGzRXzNUT7uAFWc5EmeKBHuw60rI9HJiy+Gec5WYe8l1/bsTRKpYoAbc9+cEJCeybj1N3vu+EJTvnVBb+umoTcGC5p+D1O0h4f/aWsxI1w7KhUBVyCe3/lN5onF6a0ar7ZXTS7qfBpkVxiSkzsdE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759243914; c=relaxed/simple; bh=BDFeYWOQXAPhCHxV/y/fYC2OB578qybnMEofrpFh/KY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gcGjvUeg8AmEe0gadrMN6lbg/Y/4HEZd3tXNyEwUpbLtaR4DEw/EQ2/DjEb7ve5/BRh13exRV2SrkS6Tc4IWEuf+hMO9tzlBRsueeXqf6QaJAlC0AkTdLb9dOWC8LPbw7JzvhO2/ByFRmycOxQzKX2ct9Lxp2wohVYcvNqfrp3Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=vrNqbuCn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="vrNqbuCn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 820CFC4CEF0; Tue, 30 Sep 2025 14:51:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1759243914; bh=BDFeYWOQXAPhCHxV/y/fYC2OB578qybnMEofrpFh/KY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vrNqbuCnuk28e/ce1K3rQzPV1YoloPaMJ+P5RI1EZmkYAR9CLfdWDUqdoqdtwR52M BJRltxvJgCXX53KEOtwc67IEQry5cGRAzNF3EVL3B1ON96OxFay38wadKCc2GeRB2M efnoz/O5l86d0qiQPTc2xBAs1zem0Yt5XmfURRJ8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Maciej S. Szmigiero" , "Naveen N Rao (AMD)" , Sean Christopherson , Sasha Levin Subject: [PATCH 5.4 54/81] KVM: SVM: Sync TPR from LAPIC into VMCB::V_TPR even if AVIC is active Date: Tue, 30 Sep 2025 16:46:56 +0200 Message-ID: <20250930143821.941564520@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250930143819.654157320@linuxfoundation.org> References: <20250930143819.654157320@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: "Maciej S. Szmigiero" [ Upstream commit d02e48830e3fce9701265f6c5a58d9bdaf906a76 ] Commit 3bbf3565f48c ("svm: Do not intercept CR8 when enable AVIC") inhibited pre-VMRUN sync of TPR from LAPIC into VMCB::V_TPR in sync_lapic_to_cr8() when AVIC is active. AVIC does automatically sync between these two fields, however it does so only on explicit guest writes to one of these fields, not on a bare VMRUN. This meant that when AVIC is enabled host changes to TPR in the LAPIC state might not get automatically copied into the V_TPR field of VMCB. This is especially true when it is the userspace setting LAPIC state via KVM_SET_LAPIC ioctl() since userspace does not have access to the guest VMCB. Practice shows that it is the V_TPR that is actually used by the AVIC to decide whether to issue pending interrupts to the CPU (not TPR in TASKPRI), so any leftover value in V_TPR will cause serious interrupt delivery issues in the guest when AVIC is enabled. Fix this issue by doing pre-VMRUN TPR sync from LAPIC into VMCB::V_TPR even when AVIC is enabled. Fixes: 3bbf3565f48c ("svm: Do not intercept CR8 when enable AVIC") Cc: stable@vger.kernel.org Signed-off-by: Maciej S. Szmigiero Reviewed-by: Naveen N Rao (AMD) Link: https://lore.kernel.org/r/c231be64280b1461e854e1ce3595d70cde3a2e9d.1756139678.git.maciej.szmigiero@oracle.com [sean: tag for stable@] Signed-off-by: Sean Christopherson [ Adjust context ] Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/svm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -5580,8 +5580,7 @@ static inline void sync_lapic_to_cr8(str struct vcpu_svm *svm = to_svm(vcpu); u64 cr8; - if (svm_nested_virtualize_tpr(vcpu) || - kvm_vcpu_apicv_active(vcpu)) + if (svm_nested_virtualize_tpr(vcpu)) return; cr8 = kvm_get_cr8(vcpu);