From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755904AbbIUCVE (ORCPT ); Sun, 20 Sep 2015 22:21:04 -0400 Received: from mga14.intel.com ([192.55.52.115]:20316 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755827AbbIUCVC (ORCPT ); Sun, 20 Sep 2015 22:21:02 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,564,1437462000"; d="scan'208";a="648779813" Subject: Re: [PATCH] kvm: svm: reset mmu on VCPU reset To: Igor Mammedov , linux-kernel@vger.kernel.org References: <1442583545-266967-1-git-send-email-imammedo@redhat.com> Cc: joro@8bytes.org, pbonzini@redhat.com, kvm@vger.kernel.org From: Xiao Guangrong Message-ID: <55FF6820.5040406@linux.intel.com> Date: Mon, 21 Sep 2015 10:14:56 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <1442583545-266967-1-git-send-email-imammedo@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/18/2015 09:39 PM, Igor Mammedov wrote: > When INIT/SIPI sequence is sent to VCPU which before that > was in use by OS, VMRUN might fail with: > > KVM: entry failed, hardware error 0xffffffff > EAX=00000000 EBX=00000000 ECX=00000000 EDX=000006d3 > ESI=00000000 EDI=00000000 EBP=00000000 ESP=00000000 > EIP=00000000 EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0 > ES =0000 00000000 0000ffff 00009300 > CS =9a00 0009a000 0000ffff 00009a00 > [...] > CR0=60000010 CR2=b6f3e000 CR3=01942000 CR4=000007e0 > [...] > EFER=0000000000000000 > > with corresponding SVM error: > KVM: FAILED VMRUN WITH VMCB: > [...] > cpl: 0 efer: 0000000000001000 > cr0: 0000000080010010 cr2: 00007fd7fe85bf90 > cr3: 0000000187d0c000 cr4: 0000000000000020 > [...] > > What happens is that VCPU state right after offlinig: > CR0: 0x80050033 EFER: 0xd01 CR4: 0x7e0 > -> long mode with CR3 pointing to longmode page tables > > and when VCPU gets INIT/SIPI following transition happens > CR0: 0 -> 0x60000010 EFER: 0x0 CR4: 0x7e0 > -> paging disabled with stale CR3 > > However SVM under the hood puts VCPU in Paged Real Mode* > which effectively translates CR0 0x60000010 -> 80010010 after > > svm_vcpu_reset() > -> init_vmcb() > -> kvm_set_cr0() > -> svm_set_cr0() > > but from kvm_set_cr0() perspective CR0: 0 -> 0x60000010 > only caching bits are changed and > commit d81135a57aa6 > ("KVM: x86: do not reset mmu if CR0.CD and CR0.NW are changed")' > regressed svm_vcpu_reset() which relied on MMU being reset. > > As result VMRUN after svm_vcpu_reset() tries to run > VCPU in Paged Real Mode with stale MMU context (longmode page tables), > which causes some AMD CPUs** to bail out with VMEXIT_INVALID. > > Fix issue by unconditionally resetting MMU context > at init_vmcb() time. > > -- > * AMD64 Architecture Programmer’s Manual, > Volume 2: System Programming, rev: 3.25 > 15.19 Paged Real Mode > ** Opteron 1216 > Good catch and nice analysis. Thanks for your fix, Igor! Reviewed-by: Xiao Guangrong