Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp985392pxu; Mon, 26 Oct 2020 00:36:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdkBiuGeA9uc833KmxwnuC9uKhGI//lnYNMLiVl8WA1J1R8fkBrOUFIK980v9F2lXQKvEz X-Received: by 2002:a17:907:70cb:: with SMTP id yk11mr14392933ejb.122.1603697767886; Mon, 26 Oct 2020 00:36:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603697767; cv=none; d=google.com; s=arc-20160816; b=kax1GPU3A8Xcxv26zuKOdR+NPKqg5KP61NFPNxezHb+xXH+A209qQiVtIQztD1S4ml NDTDcAziyClSrIx+O7NC0j5RBG/x9Sei4qTkZWFQSEqSK4xTz6Ysd4AJahXgocLKOrNE TECZzOT8SoWnpOHKuTdZVaNzmdvJAO2IMKVZJF7E/HgC8LISEh77v0AFwANQLyEH/d3D ojCf54MECiREbsxfbpPzlGCDtc5RO28pJQk8C7oacmK/TKrQK1/Ac46d5PE+FbHO+5wA LjKzQe9Ove87YLV75j8z9pRC9CNBDceRecBEiKa69b8x3ukB4rW70XPqNPeqnVMjL7as SynA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:ironport-sdr:ironport-sdr; bh=7Owb2m2O8SD+MPdBbxg8OZ3uiCypKdKdp7DgowK+mdg=; b=SLfxHwxpJU+okCl/Idgr0s5rO/RLlC58Mv3Ixg9UPnrA5xHCl4hMHw+W2OIX39hM66 SPfWOtgQU53LK6EECZdTWTDfk7XCx83FmPes6szBGAr7s3jhvB9O5fzSX/IG4PEYGABP fHtfEvdAU3XSTCHVbXWv3rIqbzYDQH+hQQiZGjRiLBvE8GwV5BCiTSqfQxKlz+lZdvpT +ac3Ig9HTpZHlaC5wz7RT/eJw5F+OPTopBqtcKAcVIBO/MpUmHvptNVYKJrL9ip4Ya7N 7cUlgdroi/JGcIiv+scowBw5OjQer5G+tHkse8o4iZP0sYqrpz2kELzPReZFvtGYvJkA 1fmw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h34si6902896edd.72.2020.10.26.00.35.45; Mon, 26 Oct 2020 00:36:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1768814AbgJZFbn (ORCPT + 99 others); Mon, 26 Oct 2020 01:31:43 -0400 Received: from mga09.intel.com ([134.134.136.24]:59405 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1768799AbgJZFbm (ORCPT ); Mon, 26 Oct 2020 01:31:42 -0400 IronPort-SDR: SZr3QPqWCNb2VQJvzOLP1lCWllkYXeUm60HgscWf/2LsScDJYIiSPheLGCoGU4C/CWswfouaPm M/347w+OvVBQ== X-IronPort-AV: E=McAfee;i="6000,8403,9785"; a="168004179" X-IronPort-AV: E=Sophos;i="5.77,417,1596524400"; d="scan'208";a="168004179" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2020 22:31:40 -0700 IronPort-SDR: fsc1bsyo4Ds+/OwR+SjIoEJtCTgoIqIIzIMma15t+HxFdyP5Gq9ihWWrFV6o/gDA4yLTYcB2Jz g+wI7imqg51A== X-IronPort-AV: E=Sophos;i="5.77,417,1596524400"; d="scan'208";a="535233013" Received: from cqiang-mobl.ccr.corp.intel.com (HELO [10.238.0.131]) ([10.238.0.131]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2020 22:31:37 -0700 Subject: Re: [RESEND v4 2/2] KVM: VMX: Enable bus lock VM exit To: Sean Christopherson Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , "Li, Xiaoyao" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" References: <20201012033542.4696-1-chenyi.qiang@intel.com> <20201012033542.4696-3-chenyi.qiang@intel.com> <20201020221943.GB9031@linux.intel.com> From: Chenyi Qiang Message-ID: Date: Mon, 26 Oct 2020 13:31:36 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 In-Reply-To: <20201020221943.GB9031@linux.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/21/2020 6:19 AM, Sean Christopherson wrote: > On Mon, Oct 12, 2020 at 11:35:42AM +0800, Chenyi Qiang wrote: >> @@ -6138,6 +6149,26 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath) >> return 0; >> } >> >> +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. >> + */ >> + if (to_vmx(vcpu)->exit_reason.bus_lock_detected) { >> + if (ret > 0) >> + vcpu->run->exit_reason = KVM_EXIT_BUS_LOCK; >> + else >> + vcpu->run->flags |= KVM_RUN_BUS_LOCK; > > This should always set flags.KVM_RUN_BUS_LOCK, e.g. so that userspace can > always check flags.KVM_RUN_BUS_LOCK instead of having to check both the flag > and the exit reason. As is, it's really bad because the flag is undefined, > which could teach userspace to do the wrong thing. > Got it. >> + return 0; >> + } >> + vcpu->run->flags &= ~KVM_RUN_BUS_LOCK; > > Hmm, I feel like explicitly clearing flags is should be unnecessary. By > that, I mean that's it's necessary in the current patch, bit I think we should > figure out how to make that not be the case. With the current approach, every > chunk of code that needs to set a flag also needs to clear it, which increases > the odds of missing a case and ending up with a flag in an undefined state. > > The easiest way I can think of is to add another prep patch that zeros > run->flags at the beginning of kvm_arch_vcpu_ioctl_run(), and changes > post_kvm_run_save() to do: > > if (is_smm(vcpu)) > kvm_run->flags |= KVM_RUN_X86_SMM; > > Then this patch can omit clearing KVM_RUN_BUS_LOCK, and doesn't have to touch > the SMM flag. > Make sense, I will add the prep patch. >> + return ret; >> +} >> + >> /* >> * Software based L1D cache flush which is used when microcode providing >> * the cache control MSR is not loaded.