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 X-Spam-Level: X-Spam-Status: No, score=-14.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26E46C433F5 for ; Wed, 22 Sep 2021 10:32:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0FE6D60F41 for ; Wed, 22 Sep 2021 10:32:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235166AbhIVKeD (ORCPT ); Wed, 22 Sep 2021 06:34:03 -0400 Received: from mga05.intel.com ([192.55.52.43]:41410 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234760AbhIVKd4 (ORCPT ); Wed, 22 Sep 2021 06:33:56 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10114"; a="309117992" X-IronPort-AV: E=Sophos;i="5.85,313,1624345200"; d="scan'208";a="309117992" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2021 03:32:26 -0700 X-IronPort-AV: E=Sophos;i="5.85,313,1624345200"; d="scan'208";a="550197430" Received: from xiaoyaol-mobl.ccr.corp.intel.com (HELO [10.255.29.182]) ([10.255.29.182]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2021 03:32:24 -0700 Subject: Re: [PATCH] KVM: VMX: Check if bus lock vmexit was preempted To: Paolo Bonzini , Hao Xiang , kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, chenyi.qiang@intel.com, shannon.zhao@linux.alibaba.com, Sean Christopherson References: <1631964600-73707-1-git-send-email-hao.xiang@linux.alibaba.com> <87b411c3-da75-e074-91a4-a73891f9f5f8@redhat.com> From: Xiaoyao Li Message-ID: <57597778-836c-7bac-7f1d-bcdae0cd6ac4@intel.com> Date: Wed, 22 Sep 2021 18:32:22 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <87b411c3-da75-e074-91a4-a73891f9f5f8@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/22/2021 6:02 PM, Paolo Bonzini wrote: > On 18/09/21 13:30, Hao Xiang wrote: >> exit_reason.bus_lock_detected is not only set when bus lock VM exit >> was preempted, in fact, this bit is always set if bus locks are >> detected no matter what the exit_reason.basic is. >> >> So the bus_lock_vmexit handling in vmx_handle_exit should be duplicated >> when exit_reason.basic is EXIT_REASON_BUS_LOCK(74). We can avoid it by >> checking if bus lock vmexit was preempted in vmx_handle_exit. > > I don't understand, does this mean that bus_lock_detected=1 if > basic=EXIT_REASON_BUS_LOCK?  If so, can we instead replace the contents > of handle_bus_lock_vmexit with > >     /* Do nothing and let vmx_handle_exit exit to userspace.  */ >     WARN_ON(!to_vmx(vcpu)->exit_reason.bus_lock_detected); >     return 0; > > ? > > That would be doable only if this is architectural behavior and not a > processor erratum, of course. EXIT_REASON.bus_lock_detected may or may not be set when exit reason == EXIT_REASON_BUS_LOCK. Intel will update ISE or SDM to state it. Maybe we can do below in handle_bus_lock_vmexit handler: if (!to_vmx(vcpu)->exit_reason.bus_lock_detected) to_vmx(vcpu)->exit_reason.bus_lock_detected = 1; But is manually changing the hardware reported value for software purpose a good thing? > Thanks, > > Paolo > >> Signed-off-by: Hao Xiang >> --- >>   arch/x86/kvm/vmx/vmx.c | 3 ++- >>   1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c >> index 0c2c0d5..5ddf1df 100644 >> --- a/arch/x86/kvm/vmx/vmx.c >> +++ b/arch/x86/kvm/vmx/vmx.c >> @@ -6054,7 +6054,8 @@ static int vmx_handle_exit(struct kvm_vcpu >> *vcpu, fastpath_t exit_fastpath) >>        * still need to 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 (to_vmx(vcpu)->exit_reason.bus_lock_detected && >> +            to_vmx(vcpu)->exit_reason.basic != EXIT_REASON_BUS_LOCK) { >>           if (ret > 0) >>               vcpu->run->exit_reason = KVM_EXIT_X86_BUS_LOCK; >> >