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=-18.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FSL_HELO_FAKE, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_IN_DEF_DKIM_WL 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 1C584C433FE for ; Wed, 22 Sep 2021 14:59:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 048CE611C9 for ; Wed, 22 Sep 2021 14:59:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236364AbhIVPAe (ORCPT ); Wed, 22 Sep 2021 11:00:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236304AbhIVPA3 (ORCPT ); Wed, 22 Sep 2021 11:00:29 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37116C061574 for ; Wed, 22 Sep 2021 07:58:59 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id w19so2900779pfn.12 for ; Wed, 22 Sep 2021 07:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=4BWFRlURH0zCIzDJvPF7W8LOo55K5uYFem7UNOAo2W4=; b=P3j9Vr5KoI1hGqte/zzUiZq9ueEus3vwpVyhweN4PzPXBSF6gJEpN2JysyuxyUbH+c hTJRqQQQz5xcbLGhfs+ofgEvrmkd+XZJNiSkM/9N5q7QpzX/OJceRjXeT7U0s5FlAvuN NuYhM+bBKIDbrGfD31uEdiue5ZFcIR+SK9Jxr/HUJU2u0W1gILQ9TaYreehyonGdh3bs 3xX6zro4/xGqGj/WqpOHRxJ/jUgjWdtKB8FTFDKZ/OC5UmJHVBiBJx/n3Ges4rEpkyGx Hb6J/vje2oXUtI8tWq0Z1zDTTm5T3sdxP3kl0qSKzbP4uuzuneyIDU2PQ1JfdvkNmVPl pkkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=4BWFRlURH0zCIzDJvPF7W8LOo55K5uYFem7UNOAo2W4=; b=xS0MJpSTfrRSmqtRuQ67y+HlBT/w4dxzCWvzIIqliLi/aNtt5aJ4Riwk2eafDbLyJF tIIJ9a/kzancV5dJAxwMWu8wsIHXSKg87bnKzfRLRaz1xJz/5LHUIc1Merpvra2Haleu Qc78h0irSSeSKYan+3df1UU2MnpvSI7YBnOCRXlo9TrOpq6wUkZGBCTp/fV8jH2JYkKr BTgUBZxqiXdMByzr11gC6vSR181gqg0VURuhzhEV5w/NBAkrzteJ8ol9EuluXIxBBZNl YMmBg5Gml8Ju0r3C1EdmS2SkqpDgwtUsnVzT/2aIdiLOyYfxArbEcxhfp56YVrq7fs0b L8yA== X-Gm-Message-State: AOAM533DX0tpZQWTChnNQQ9FKQfZZepKynwaAxTpYUJ7RNuG701uXAnR AGJ13OFJroTIo3+2vc7VqdZ7fA== X-Google-Smtp-Source: ABdhPJwdYeOPs+9n16+HPBDRZMNwU3ntjxP7QSgPHZIuMryueYJCypE73VnvJPFH3zw0ebvOvgxc0Q== X-Received: by 2002:a63:f959:: with SMTP id q25mr64757pgk.79.1632322738517; Wed, 22 Sep 2021 07:58:58 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id i27sm2830809pfq.184.2021.09.22.07.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 07:58:57 -0700 (PDT) Date: Wed, 22 Sep 2021 14:58:53 +0000 From: Sean Christopherson To: Xiaoyao Li Cc: Paolo Bonzini , Hao Xiang , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, chenyi.qiang@intel.com, shannon.zhao@linux.alibaba.com Subject: Re: [PATCH] KVM: VMX: Check if bus lock vmexit was preempted Message-ID: 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> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <57597778-836c-7bac-7f1d-bcdae0cd6ac4@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)