From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 30E65577E45; Wed, 9 Sep 2026 14:26:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788964003; cv=none; b=GzgMKlT4GbHFbv75zhKD9++cIOMn0S7QPSnWtDsmITGT5vuUMNFH/FCbJrFstyGRw/aWpY48osNAtLPb4gJwAXZ5eMS1qSoTTnSJc4OBduZfSg7d1bgEX/JXIR0wb/u/7P8pJfR8PkDd3bTSnHfQOhI1tLdENN+PkNMQhxDOgkE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788964003; c=relaxed/simple; bh=GxSyuwOKE3Rw0r/SyAYDdxxecyQhoLbdeXhgNM5/TLg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gIE89/cwG5n66rRYC2mX9J8OCqbtab6l352yvGHSEfPnT/6rR/ySzXivbrY/DKLQDy4XrU9pnexoQsjJnRr8wfInVKFW1zIyRMaGkL7lqT8Uz9fkUBssDrKWnauR/WM5bF1eVFmBxaLNEiYaJok4G4FHxh6OCCOcMFF1g/27w2o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JBSOEaOZ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="JBSOEaOZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 880AA1F00A3A; Wed, 9 Sep 2026 14:26:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788964002; bh=hl7K+CdaePej3DXjkTMAkVptWZ4dEu7rP4OBh70oHzk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JBSOEaOZX+wuMINU2qnQa0ns3+Dj5LzcO39EaEvoI4jk1V4FnrgxOvFKHQOWLLhnn 3yCMnZHsfkSUvgNvUTmV7ySgtzKVB9EmSosyZErpPtmznzky4S7AUUcuNLxzjJT02c E9EwFwkNrSX2GbXeqK4R65FJor2soOky0JAeZlDM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yosry Ahmed , Kai Huang , Jim Mattson , Sean Christopherson Subject: [PATCH 6.18 230/583] KVM: nVMX: Always flush vpid02 on first use Date: Wed, 9 Sep 2026 15:38:35 +0200 Message-ID: <20260909134246.126861726@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260909134237.773280130@linuxfoundation.org> References: <20260909134237.773280130@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 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yosry Ahmed commit f0772389413dce9657c7d6950abf3edbbd511356 upstream. Make sure vpid02 is always flushed on first use by setting last_vpid=0 when allocating vpid02. nested_vmx_transition_tlb_flush() will always detect a VPID change on first VM-Enter after VMXON, because VPID=0 in vmcs12 is not allowed if L1 enables VPID. This avoids using stale TLB entries from a previous lifetime of the VPID, that might have been associated with a different vCPU (or a completely different VM). Note that last_vpid is already being initialized as 0 when the vCPU is created, but it is not reset when vpid02 is freed on VMXOFF. Hence, the problem can only occur if L1 does VMXOFF -> VMXON, runs an L2, and KVM happens to reuse a VPID that has TLB entries on the physical CPU. Cc: stable@vger.kernel.org Signed-off-by: Yosry Ahmed Reviewed-by: Kai Huang Reviewed-by: Jim Mattson Link: https://patch.msgid.link/20260616214652.2157032-2-yosry@kernel.org Signed-off-by: Sean Christopherson Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/vmx/nested.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -1269,6 +1269,9 @@ static void nested_vmx_transition_tlb_fl * is the VPID incorporated into the MMU context. I.e. KVM must assume * that the new vpid12 has never been used and thus represents a new * guest ASID that cannot have entries in the TLB. + * + * Note, last_vpid is initialized as 0, so the first nested VM-Enter + * after VMXON will always flush the TLB to avoid using stale entries. */ if (is_vmenter && vmcs12->virtual_processor_id != vmx->nested.last_vpid) { vmx->nested.last_vpid = vmcs12->virtual_processor_id; @@ -5514,6 +5517,13 @@ static int enter_vmx_operation(struct kv vmx->nested.vpid02 = allocate_vpid(); + /* + * Clear last_vpid to ensure that the VPID is flushed on the first + * nested VM-Enter. Otherwise, stale TLB entries from a previous life of + * the VPID (e.g. different vCPU or even different VM) could be used. + */ + vmx->nested.last_vpid = 0; + vmx->nested.vmcs02_initialized = false; vmx->nested.vmxon = true;