Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753970AbdFMSze (ORCPT ); Tue, 13 Jun 2017 14:55:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57326 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753549AbdFMSzb (ORCPT ); Tue, 13 Jun 2017 14:55:31 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0E9CF883A4 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=rkrcmar@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0E9CF883A4 Date: Tue, 13 Jun 2017 20:55:23 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Wanpeng Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Wanpeng Li Subject: Re: [PATCH 3/4] KVM: async_pf: Force a nested vmexit if the injected #PF is async_pf Message-ID: <20170613185522.GA29537@potion> References: <1497334094-6982-1-git-send-email-wanpeng.li@hotmail.com> <1497334094-6982-4-git-send-email-wanpeng.li@hotmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1497334094-6982-4-git-send-email-wanpeng.li@hotmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 13 Jun 2017 18:55:26 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2058 Lines: 53 2017-06-12 23:08-0700, Wanpeng Li: > From: Wanpeng Li > > Add an async_page_fault field to vcpu->arch.exception to identify an async > page fault, and constructs the expected vm-exit information fields. Force > a nested VM exit from nested_vmx_check_exception() if the injected #PF > is async page fault. > > Cc: Paolo Bonzini > Cc: Radim Krčmář > Signed-off-by: Wanpeng Li > --- > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > @@ -2422,13 +2422,28 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu) > static int nested_vmx_check_exception(struct kvm_vcpu *vcpu, unsigned nr) This function could use the same treatment as vmx_queue_exception(), so we are not mixing 'nr' with 'vcpu->arch.exception.*'. > { > struct vmcs12 *vmcs12 = get_vmcs12(vcpu); > + u32 intr_info = 0; > + unsigned long exit_qualification = 0; > > - if (!(vmcs12->exception_bitmap & (1u << nr))) > + if (!((vmcs12->exception_bitmap & (1u << nr)) || > + (nr == PF_VECTOR && vcpu->arch.exception.async_page_fault))) > return 0; > > + intr_info = nr | INTR_INFO_VALID_MASK; > + exit_qualification = vmcs_readl(EXIT_QUALIFICATION); This part still uses EXIT_QUALIFICATION(), which means it is not general and I think it would be nicer to just do simple special case on top: if (vcpu->arch.exception.async_page_fault) { vmcs_write32(VM_EXIT_INTR_ERROR_CODE, vcpu->arch.exception.error_code); nested_vmx_vmexit(vcpu, EXIT_REASON_EXCEPTION_NMI, PF_VECTOR | INTR_TYPE_HARD_EXCEPTION | INTR_INFO_DELIVER_CODE_MASK | INTR_INFO_VALID_MASK, vcpu->arch.cr2); return 1; } Using vcpu->arch.cr2 is suspicious as VMX doesn't update CR2 on VM exits; isn't this going to change the CR2 visible in L2 guest after a nested VM entry? Btw. nested_vmx_check_exception() didn't support emulated exceptions at all (it only passed through ones we got from hardware), or have I missed something? Thanks.