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=-10.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,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 E9634C433EF for ; Thu, 23 Sep 2021 07:15:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE4BF60FE6 for ; Thu, 23 Sep 2021 07:15:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239598AbhIWHQ7 (ORCPT ); Thu, 23 Sep 2021 03:16:59 -0400 Received: from out30-43.freemail.mail.aliyun.com ([115.124.30.43]:42957 "EHLO out30-43.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239075AbhIWHQ6 (ORCPT ); Thu, 23 Sep 2021 03:16:58 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R971e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=hao.xiang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0UpIwbV9_1632381325; Received: from 30.43.105.150(mailfrom:hao.xiang@linux.alibaba.com fp:SMTPD_---0UpIwbV9_1632381325) by smtp.aliyun-inc.com(127.0.0.1); Thu, 23 Sep 2021 15:15:25 +0800 Message-ID: Date: Thu, 23 Sep 2021 15:15:25 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.1.1 Subject: Re: [PATCH] KVM: VMX: Check if bus lock vmexit was preempted Content-Language: en-US To: Sean Christopherson , Xiaoyao Li Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, chenyi.qiang@intel.com, shannon.zhao@linux.alibaba.com References: <1631964600-73707-1-git-send-email-hao.xiang@linux.alibaba.com> <87b411c3-da75-e074-91a4-a73891f9f5f8@redhat.com> <57597778-836c-7bac-7f1d-bcdae0cd6ac4@intel.com> From: Hao Xiang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/9/22 22:58, Sean Christopherson wrote: > On Wed, Sep 22, 2021, Xiaoyao Li wrote: >> 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? > In this case, I'd say yes. Hardware having non-deterministic behavior is the not > good thing, KVM would simply be correctly the not-technically-an-erratum erratum. > > Set it unconditionally and then handle everything in common path. This has the > added advantage of having only one site that deals with KVM_RUN_X86_BUS_LOCK. > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 33f92febe3ce..aa9372452e49 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -5561,9 +5561,9 @@ 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; > + /* The dedicated flag may or may not be set by hardware. /facepalm. */ > + vcpu->exit_reason.bus_lock_detected = true; > + return 1; > } > > /* > @@ -6050,9 +6050,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) I agree with your modifications. And I will  re-submit the patch. Thanks.