From patchwork Thu Apr 30 01:45:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Li RongQing X-Patchwork-Id: 11519061 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B2F82912 for ; Thu, 30 Apr 2020 02:01:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9EE982083B for ; Thu, 30 Apr 2020 02:01:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726511AbgD3CBa (ORCPT ); Wed, 29 Apr 2020 22:01:30 -0400 Received: from mx22.baidu.com ([220.181.50.185]:38918 "EHLO baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726282AbgD3CBa (ORCPT ); Wed, 29 Apr 2020 22:01:30 -0400 Received: from BC-Mail-Ex16.internal.baidu.com (unknown [172.31.51.56]) by Forcepoint Email with ESMTPS id 7AD7E984D2F571FACB69; Thu, 30 Apr 2020 09:45:30 +0800 (CST) Received: from BJHW-Mail-Ex13.internal.baidu.com (10.127.64.36) by BC-Mail-Ex16.internal.baidu.com (172.31.51.56) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1531.3; Thu, 30 Apr 2020 09:45:30 +0800 Received: from BJHW-Mail-Ex13.internal.baidu.com ([100.100.100.36]) by BJHW-Mail-Ex13.internal.baidu.com ([100.100.100.36]) with mapi id 15.01.1713.004; Thu, 30 Apr 2020 09:45:30 +0800 From: "Li,Rongqing" To: Paolo Bonzini , Peter Zijlstra CC: "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "x86@kernel.org" , "hpa@zytor.com" , "bp@alien8.de" , "mingo@redhat.com" , "tglx@linutronix.de" , "joro@8bytes.org" , "jmattson@google.com" , "wanpengli@tencent.com" , "vkuznets@redhat.com" , "sean.j.christopherson@intel.com" Subject: =?utf-8?b?562U5aSNOiBbUEFUQ0hdW3YyXSBrdm06IHg4NjogZW11bGF0ZSBBUEVS?= =?utf-8?b?Ri9NUEVSRiByZWdpc3RlcnM=?= Thread-Topic: [PATCH][v2] kvm: x86: emulate APERF/MPERF registers Thread-Index: AQHWHgPRaxq7VoyE2kqvmC7wjQtzhaiPXbuAgAGG2mA= Date: Thu, 30 Apr 2020 01:45:30 +0000 Message-ID: References: <1588139196-23802-1-git-send-email-lirongqing@baidu.com> <20200429085440.GG13592@hirez.programming.kicks-ass.net> <201824a4-6b0f-9061-ec21-26d71fa11bc4@redhat.com> In-Reply-To: <201824a4-6b0f-9061-ec21-26d71fa11bc4@redhat.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.22.198.11] x-baidu-bdmsfe-datecheck: 1_BC-Mail-Ex16_2020-04-30 09:45:30:295 x-baidu-bdmsfe-viruscheck: BC-Mail-Ex16_GRAY_Inside_WithoutAtta_2020-04-30 09:45:30:186 MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org > -----邮件原件----- > 发件人: Paolo Bonzini [mailto:pbonzini@redhat.com] > 发送时间: 2020年4月29日 18:21 > 收件人: Peter Zijlstra ; Li,Rongqing > > 抄送: linux-kernel@vger.kernel.org; kvm@vger.kernel.org; x86@kernel.org; > hpa@zytor.com; bp@alien8.de; mingo@redhat.com; tglx@linutronix.de; > joro@8bytes.org; jmattson@google.com; wanpengli@tencent.com; > vkuznets@redhat.com; sean.j.christopherson@intel.com > 主题: Re: [PATCH][v2] kvm: x86: emulate APERF/MPERF registers > > On 29/04/20 10:54, Peter Zijlstra wrote: > > On Wed, Apr 29, 2020 at 01:46:36PM +0800, Li RongQing wrote: > >> Guest kernel reports a fixed cpu frequency in /proc/cpuinfo, this is > >> confused to user when turbo is enable, and aperf/mperf can be used to > >> show current cpu frequency after 7d5905dc14a > >> "(x86 / CPU: Always show current CPU frequency in /proc/cpuinfo)" > >> so we should emulate aperf mperf to achieve it > >> > >> the period of aperf/mperf in guest mode are accumulated as emulated > >> value, and add per-VM knod to enable emulate mperfaperf > >> > >> diff v1: > >> 1. support AMD > >> 2. support per-vm capability to enable > > Would it make sense to provide a pass-through APERF/MPERF for > > KVM_HINTS_REALTIME ? Because that hint guarantees we have a 1:1 > > vCPU:CPU binding and guaranteed no over-commit. > > > > Yes but that's up to userspace. > > Paolo Seem kernel should give the capability to userspace to disable the intercept mperf/aperf for KVM_HINTS_REALTIME So I will change this patch to support three mode mperfaperf: none, software emulate, and pt -Li diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 1d157a8dba46..6b05f78bde78 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -1657,9 +1657,11 @@ static void init_vmcb(struct vcpu_svm *svm) set_intercept(svm, INTERCEPT_SKINIT); set_intercept(svm, INTERCEPT_WBINVD); set_intercept(svm, INTERCEPT_XSETBV); - set_intercept(svm, INTERCEPT_RDPRU); set_intercept(svm, INTERCEPT_RSM); + if (!guest_mperfaperf_pt(svm->vcpu.kvm)) + set_intercept(svm, INTERCEPT_RDPRU); + if (!kvm_mwait_in_guest(svm->vcpu.kvm)) { set_intercept(svm, INTERCEPT_MONITOR); set_intercept(svm, INTERCEPT_MWAIT); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index b05e276e262b..231732924c50 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6765,6 +6765,12 @@ static int vmx_create_vcpu(struct kvm_vcpu *vcpu) vmx_disable_intercept_for_msr(msr_bitmap, MSR_CORE_C6_RESIDENCY, MSR_TYPE_R); vmx_disable_intercept_for_msr(msr_bitmap, MSR_CORE_C7_RESIDENCY, MSR_TYPE_R); } + + if (guest_mperfaperf_pt(vcpu->kvm)) { + vmx_disable_intercept_for_msr(msr_bitmap, MSR_IA32_MPERF, MSR_TYPE_R); + vmx_disable_intercept_for_msr(msr_bitmap, MSR_IA32_APERF, MSR_TYPE_R); + } + vmx->msr_bitmap_mode = 0; vmx->loaded_vmcs = &vmx->vmcs01;