Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp98814pxk; Wed, 2 Sep 2020 15:48:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyEcnHzPRC3HyyP8purDSEAB+WGUKAFWZDLzprOe3EflzY6jr8TQLS7kF/7i1cRuZyHf56 X-Received: by 2002:a50:de04:: with SMTP id z4mr165790edk.10.1599086919556; Wed, 02 Sep 2020 15:48:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599086919; cv=none; d=google.com; s=arc-20160816; b=nmEBAY1+i8S42Yde3jsqZsir5NaAeBKqdOrTqy5ZcZH20bf6H8vuqMDWLYABp6Vsro 5oCFictMPf4CjPxGw7lWrWP2EiSkFvnSQw5871YUAkgKQT3WM1p32iK8bSw32YvxGJ5W HbGZxn0nXSFy5CQxNiS8I2rtkn/pdAke9Fma7TWtVrpG6YqDTlUarSICGBo2IZjQFky6 ksjkYTq5YuwdvPZeeBYma+36KzeyBzK8kyxqLLaCihmgdJ9dKB3AdCRo6ANhnFOlQPdc elNQ+w5MQfZPNjLyysqJuNe0ExqwOz9WK0XBxkKxKey+Xy2qJWjrSfi9lHkkiGciH+VI 29Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=STCIyLIeAdTU8qMzLpboNhcFIK0Q1SNN0c2Ptwxj5pA=; b=KMl3Pn3bbnEqszUEVBvHWox9G2kY8GJraxVBWn2t5QaDpt425w6WkwZnYYGVqJpJHz V9nMFfjEjYQ69v9OWrI0GVGO04MMkCGTDkVmNMfRazM3uf5uIy/XN+NkJRpiQqCIo1bu 0UAyqFjjf2cO5Ovc5g1kochgvEvMkX12qTUPvmLumgqIb1mchBtgbVWnQJGar8bYssP4 OUiVmi+67o0AF2+3cROU6ObtXdMsM+0QDYd912gbM5dx40Y4BJQMB+itvCIp0XtAd0ze J0TycnUdjq0L3ubTib5iLSsZECglc5L2Q0+GzqRXG7VOioFALXaGhVIUOW9oYthl5kBf fulQ== 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 q10si655387eji.352.2020.09.02.15.47.53; Wed, 02 Sep 2020 15:48:39 -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 S1726933AbgIBWoJ (ORCPT + 99 others); Wed, 2 Sep 2020 18:44:09 -0400 Received: from mga11.intel.com ([192.55.52.93]:7459 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726247AbgIBWoJ (ORCPT ); Wed, 2 Sep 2020 18:44:09 -0400 IronPort-SDR: yYb2LRWEnovmxVusYZpk8nzGt8ICDB1QzQKWRISkyEsiZlmS3Fr338XqqtlPez6EXRFpuFlgYs w4hDCa/YCbHw== X-IronPort-AV: E=McAfee;i="6000,8403,9732"; a="154996681" X-IronPort-AV: E=Sophos;i="5.76,384,1592895600"; d="scan'208";a="154996681" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2020 15:44:07 -0700 IronPort-SDR: SgPuBa8KagMKUW23uXxcS5sth5yAXQj3CkBd39UgRDyePqw5JZKnGx4ZU3LbvuLYL1lgKr9a8x S1wtQdQosjJg== X-IronPort-AV: E=Sophos;i="5.76,384,1592895600"; d="scan'208";a="502837008" Received: from sjchrist-ice.jf.intel.com (HELO sjchrist-ice) ([10.54.31.34]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2020 15:44:07 -0700 Date: Wed, 2 Sep 2020 15:44:06 -0700 From: Sean Christopherson To: Vitaly Kuznetsov Cc: Chenyi Qiang , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Wanpeng Li , Jim Mattson , Joerg Roedel , Xiaoyao Li Subject: Re: [RFC v2 2/2] KVM: VMX: Enable bus lock VM exit Message-ID: <20200902224405.GK11695@sjchrist-ice> References: <20200817014459.28782-1-chenyi.qiang@intel.com> <20200817014459.28782-3-chenyi.qiang@intel.com> <87sgc1x4yn.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87sgc1x4yn.fsf@vitty.brq.redhat.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 01, 2020 at 10:43:12AM +0200, Vitaly Kuznetsov wrote: > > @@ -6809,6 +6824,19 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu) > > if (unlikely(vmx->exit_reason.failed_vmentry)) > > return EXIT_FASTPATH_NONE; > > > > + /* > > + * check the exit_reason to see if there is a bus lock > > + * happened in guest. > > + */ > > + if (kvm_bus_lock_exit_enabled(vmx->vcpu.kvm)) { > > + if (vmx->exit_reason.bus_lock_detected) { > > + vcpu->stat.bus_locks++; Why bother with stats? Every bus lock exits to userspace, having quick stats doesn't seem all that interesting. > > + vcpu->arch.bus_lock_detected = true; > > + } else { > > + vcpu->arch.bus_lock_detected = false; > > This is a fast path so I'm wondering if we can move bus_lock_detected > clearing somewhere else. Why even snapshot vmx->exit_reason.bus_lock_detected? I don't see any reason why vcpu_enter_guest() needs to handle the exit to userspace, e.g. it's just as easily handled in VMX code. > > > + } > > + } > > + > > vmx->loaded_vmcs->launched = 1; > > vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD); > > > > @@ -8060,6 +8088,9 @@ static __init int hardware_setup(void) > > kvm_tsc_scaling_ratio_frac_bits = 48; > > } > > > > + if (cpu_has_vmx_bus_lock_detection()) > > + kvm_has_bus_lock_exit = true; > > + > > set_bit(0, vmx_vpid_bitmap); /* 0 is reserved for host */ > > > > if (enable_ept) ... > > @@ -4990,6 +4996,12 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, > > kvm->arch.exception_payload_enabled = cap->args[0]; > > r = 0; > > break; > > + case KVM_CAP_X86_BUS_LOCK_EXIT: > > + if (!kvm_has_bus_lock_exit) > > + return -EINVAL; > > ... because userspace can check for -EINVAL when enabling the cap. Or we > can return e.g. -EOPNOTSUPP here. I don't have a strong opinion on the matter.. > > > + kvm->arch.bus_lock_exit = cap->args[0]; Assuming we even want to make this per-VM, I think it'd make sense to make args[0] a bit mask, e.g. to provide "off" and "exit" (this behavior) while allowing for future modes, e.g. log-only. > > + r = 0; > > + break; > > default: > > r = -EINVAL; > > break; > > @@ -7732,12 +7744,23 @@ static void post_kvm_run_save(struct kvm_vcpu *vcpu)