Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp726506pxb; Tue, 2 Feb 2021 16:50:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJyy1P/GoHIw+jI+ZG9rfunZ3A7BSbqbEfzxdvQkXdphO0bc4xyvQ9GN4OnIqMC/i0SH7NLS X-Received: by 2002:a17:906:7f06:: with SMTP id d6mr588947ejr.169.1612313438698; Tue, 02 Feb 2021 16:50:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612313438; cv=none; d=google.com; s=arc-20160816; b=y/LetKebSPT5z1e0nqV5nXCrGIYrCBaTk2EwQ39Uk/olmLaPf75xNTT3RWHmvpLyFF 1uakH9NELj96fcvxLZzGgmu7q4a9SLmtZwBcsO4bJtQGs2EHPTs+nMiEGHaUFlFBs7fs C//+midwp6SaschJxzV0e7sFSOlwyEcZ3SiYEXPcz2ff4guqJpCYIegI5I3ZKWHWqZU3 vdurf14SQ5HVlsh65zRGgNzn09XNSMr07av28COsUALtLe1XEdR50Ftctz6HQsUqrRzb bWq+38PVKnhS5X1J/4gfkz/n4zhUi4Sg2+53zt1Bar6PQt09MhfKIu0UPcOJsnzM6AJb KUsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZUB9wK1fyyycx/PdfsatsiLuWsEglU/DtOx58KsJ+KU=; b=oSYGDwj4mz91D7jtc3m4Yq/W8vLuI8NTQhi3C7/j+BY4E/SsYjnjVX+vls/faeJhGh NxXcA9pRg0JuroP6AYAeiH6zfulIgVMqUZnQlKrG0vy7gFG327qYjbWU86IGLLi2t4LZ mjFsjPRq4Ub52Fw3FL7WJDsD4a03xdUElVBeL44YmVVfvunO7RhoHqc9FVDao2lWh1uc faFmf5d9aY21wZVONF/KrZWQCM1Cn3l/BkSqfZNMjnhP9G8qciPlzaFOlPYrWAb9bH65 2/e3jq9nVy+G4PPwr54SXxTbcHYne2/7XCqYEKpoWs+AEsTxetyGJu0d5tq4+XIr5m8B ofcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q9tVjt2y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hk6si310583ejb.204.2021.02.02.16.50.14; Tue, 02 Feb 2021 16:50:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q9tVjt2y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240176AbhBBT6N (ORCPT + 99 others); Tue, 2 Feb 2021 14:58:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:41108 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232940AbhBBNuB (ORCPT ); Tue, 2 Feb 2021 08:50:01 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2FFCB64FA1; Tue, 2 Feb 2021 13:42:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612273354; bh=eR1JmH0TvrXwgf4kwoQSnDl0DgSldxgKUcc90l88V0I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q9tVjt2y7k4iPnEZOcdAeXnnXcE8isGpm1zCM+/v/v7NUNsOjIaQhJP8IVWkud0Ee KPTXm+zSJal6ZmKl0PsBCQWkMSQ1WW09ffYcwh3TEMb/Zg0lM7tBVE8i3VKGcTDRI9 +7clEBCgw8Zhmcm2zrRGcFUz/k9q2D4IyeIr8mUU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Maxim Levitsky , Paolo Bonzini Subject: [PATCH 5.10 044/142] KVM: nVMX: Sync unsyncd vmcs02 state to vmcs12 on migration Date: Tue, 2 Feb 2021 14:36:47 +0100 Message-Id: <20210202132959.545200167@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210202132957.692094111@linuxfoundation.org> References: <20210202132957.692094111@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Maxim Levitsky commit d51e1d3f6b4236e0352407d8a63f5c5f71ce193d upstream. Even when we are outside the nested guest, some vmcs02 fields may not be in sync vs vmcs12. This is intentional, even across nested VM-exit, because the sync can be delayed until the nested hypervisor performs a VMCLEAR or a VMREAD/VMWRITE that affects those rarely accessed fields. However, during KVM_GET_NESTED_STATE, the vmcs12 has to be up to date to be able to restore it. To fix that, call copy_vmcs02_to_vmcs12_rare() before the vmcs12 contents are copied to userspace. Fixes: 7952d769c29ca ("KVM: nVMX: Sync rarely accessed guest fields only when needed") Reviewed-by: Sean Christopherson Signed-off-by: Maxim Levitsky Message-Id: <20210114205449.8715-2-mlevitsk@redhat.com> Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/vmx/nested.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -6070,11 +6070,14 @@ static int vmx_get_nested_state(struct k if (is_guest_mode(vcpu)) { sync_vmcs02_to_vmcs12(vcpu, vmcs12); sync_vmcs02_to_vmcs12_rare(vcpu, vmcs12); - } else if (!vmx->nested.need_vmcs12_to_shadow_sync) { - if (vmx->nested.hv_evmcs) - copy_enlightened_to_vmcs12(vmx); - else if (enable_shadow_vmcs) - copy_shadow_to_vmcs12(vmx); + } else { + copy_vmcs02_to_vmcs12_rare(vcpu, get_vmcs12(vcpu)); + if (!vmx->nested.need_vmcs12_to_shadow_sync) { + if (vmx->nested.hv_evmcs) + copy_enlightened_to_vmcs12(vmx); + else if (enable_shadow_vmcs) + copy_shadow_to_vmcs12(vmx); + } } BUILD_BUG_ON(sizeof(user_vmx_nested_state->vmcs12) < VMCS12_SIZE);