From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6010C433F5 for ; Fri, 15 Oct 2021 06:46:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9861D610E5 for ; Fri, 15 Oct 2021 06:46:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235642AbhJOGsW (ORCPT ); Fri, 15 Oct 2021 02:48:22 -0400 Received: from mga12.intel.com ([192.55.52.136]:9602 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235626AbhJOGsV (ORCPT ); Fri, 15 Oct 2021 02:48:21 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10137"; a="207975133" X-IronPort-AV: E=Sophos;i="5.85,375,1624345200"; d="scan'208";a="207975133" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2021 23:46:15 -0700 X-IronPort-AV: E=Sophos;i="5.85,375,1624345200"; d="scan'208";a="442430108" Received: from xiaoyaol-mobl.ccr.corp.intel.com (HELO [10.239.13.123]) ([10.239.13.123]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2021 23:46:13 -0700 Message-ID: <5eb45c93-38aa-cea8-a5c8-cf786c193342@intel.com> Date: Fri, 15 Oct 2021 14:46:11 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0 Thunderbird/91.2.0 Subject: Re: [PATCH v2] KVM: VMX: Remove redundant handling of bus lock vmexit Content-Language: en-US To: Hao Xiang , kvm@vger.kernel.org Cc: shannon.zhao@linux.alibaba.com, pbonzini@redhat.com, linux-kernel@vger.kernel.org References: <1634270265-99421-1-git-send-email-hao.xiang@linux.alibaba.com> From: Xiaoyao Li In-Reply-To: <1634270265-99421-1-git-send-email-hao.xiang@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/15/2021 11:57 AM, Hao Xiang wrote: > Hardware may or may not set exit_reason.bus_lock_detected on BUS_LOCK > VM-Exits. Dealing with KVM_RUN_X86_BUS_LOCK in handle_bus_lock_vmexit > could be redundant when exit_reason.basic is EXIT_REASON_BUS_LOCK. > > We can remove redundant handling of bus lock vmexit. Force Setting > exit_reason.bus_lock_detected in handle_bus_lock_vmexit(), and deal with > KVM_RUN_X86_BUS_LOCK only in vmx_handle_exit(). > > Suggested-by: Sean Christopherson > Signed-off-by: Hao Xiang > --- > v1 -> v2: a little modifications of comments > > arch/x86/kvm/vmx/vmx.c | 15 +++++++++------ > 1 file changed, 9 insertions(+), 6 deletions(-) > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 116b089..22be02e 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -5562,9 +5562,13 @@ static int handle_encls(struct kvm_vcpu *vcpu) > > static int handle_bus_lock_vmexit(struct kvm_vcpu *vcpu) > { > - vcpu->run->exit_reason = KVM_EXIT_X86_BUS_LOCK; > - vcpu->run->flags |= KVM_RUN_X86_BUS_LOCK; > - return 0; > + /* > + * Hardware may or may not set the BUS_LOCK_DETECTED flag on BUS_LOCK > + * VM-Exits, force setting the flag > so that the logic in vmx_handle_exit() > + * doesn't have to handle the flag and the basic exit reason. The code itself looks good. But the comment is partly incorrect. Now we rely only on the bus_lock_detected flag so vmx_handle_exit() must check the flag. > + */ > + to_vmx(vcpu)->exit_reason.bus_lock_detected = true; > + return 1; > } > > /* > @@ -6051,9 +6055,8 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath) > int ret = __vmx_handle_exit(vcpu, exit_fastpath); > > /* > - * Even when current exit reason is handled by KVM internally, we > - * still need to exit to user space when bus lock detected to inform > - * that there is a bus lock in guest. > + * Exit to user space when bus lock detected to inform that there is > + * a bus lock in guest. > */ > if (to_vmx(vcpu)->exit_reason.bus_lock_detected) { > if (ret > 0) >