From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752059AbdHGNQ2 (ORCPT ); Mon, 7 Aug 2017 09:16:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50156 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751987AbdHGNQ1 (ORCPT ); Mon, 7 Aug 2017 09:16:27 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 08AC47F405 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=pbonzini@redhat.com Subject: Re: [PATCH 2/3] KVM: X86: implement the logic for spinlock optimization To: "Longpeng(Mike)" Cc: "Longpeng(Mike)" , rkrcmar@redhat.com, agraf@suse.com, borntraeger@de.ibm.com, cohuck@redhat.com, christoffer.dall@linaro.org, marc.zyngier@arm.com, james.hogan@imgtec.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, weidong.huang@huawei.com, arei.gonglei@huawei.com, wangxinxin.wang@huawei.com, david@redhat.com References: <1502095466-21312-1-git-send-email-longpeng2@huawei.com> <1502095466-21312-3-git-send-email-longpeng2@huawei.com> From: Paolo Bonzini Message-ID: Date: Mon, 7 Aug 2017 15:16:15 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 07 Aug 2017 13:16:27 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/08/2017 14:28, Longpeng(Mike) wrote: > * kvm_arch_spin_in_kernel() returns whether the vcpu (which exits due to > spinlock) is CPL=0. It only be called by kvm_vcpu_on_spin(), and the > input vcpu is 'me' which get a PAUSE exit now. * > > I split kvm_arch_vcpu_in_kernel(in RFC) into two functions: > kvm_arch_spin_in_kernel and kvm_arch_preempt_in_kernel > > Because of KVM/VMX L1 never set CPU_BASED_PAUSE_EXITING and only set > SECONDARY_EXEC_PAUSE_LOOP_EXITING if supported, so for L1: I understand better now. I think vmx.c should just return true from vmx_spin_in_kernel. However, kvm_arch_vcpu_spin_in_kernel is not necessary. Instead you should make "in_kern" an argument to kvm_vcpu_on_spin (maybe renamed to "yield_to_kernel_mode_vcpu"). Then vmx.c can just call "kvm_vcpu_on_spin(vcpu, true)". > 1. get a PAUSE exit with CPL=0 if PLE is supported > 2. never get a PAUSE exit if don't support PLE > > So, I think it can direct return true(CPL=0) if supports PLE. > > But for nested KVM/VMX(I'm not familiar with nested), it could set > CPU_BASED_PAUSE_EXITING, so I think get_cpl() is also needed. If the nested hypervisor sets CPU_BASED_PAUSE_EXITING, a PAUSE vmexit while running a nested guest would be reflected to the nested hypervisor. So you wouldn't get to handle_pause and thus to kvm_vcpu_on_spin. Thanks, Paolo