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=-8.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_MUTT 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 0320CC04E84 for ; Fri, 17 May 2019 20:05:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CF2202087B for ; Fri, 17 May 2019 20:05:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727380AbfEQUFK (ORCPT ); Fri, 17 May 2019 16:05:10 -0400 Received: from mga11.intel.com ([192.55.52.93]:39234 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726738AbfEQUFK (ORCPT ); Fri, 17 May 2019 16:05:10 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 May 2019 13:05:10 -0700 X-ExtLoop1: 1 Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.36]) by orsmga005.jf.intel.com with ESMTP; 17 May 2019 13:05:09 -0700 Date: Fri, 17 May 2019 13:05:09 -0700 From: Sean Christopherson To: Wanpeng Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Liran Alon Subject: Re: [PATCH v3 3/5] KVM: LAPIC: Expose per-vCPU timer_advance_ns to userspace Message-ID: <20190517200509.GJ15006@linux.intel.com> References: <1557975980-9875-1-git-send-email-wanpengli@tencent.com> <1557975980-9875-4-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1557975980-9875-4-git-send-email-wanpengli@tencent.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Thu, May 16, 2019 at 11:06:18AM +0800, Wanpeng Li wrote: > From: Wanpeng Li > > Expose per-vCPU timer_advance_ns to userspace, so it is able to > query the auto-adjusted value. > > Cc: Paolo Bonzini > Cc: Radim Krčmář > Cc: Sean Christopherson > Cc: Liran Alon > Signed-off-by: Wanpeng Li > --- > arch/x86/kvm/debugfs.c | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c > index c19c7ed..a6f1f93 100644 > --- a/arch/x86/kvm/debugfs.c > +++ b/arch/x86/kvm/debugfs.c > @@ -9,12 +9,22 @@ > */ > #include > #include > +#include "lapic.h" > > bool kvm_arch_has_vcpu_debugfs(void) > { > return true; > } > > +static int vcpu_get_timer_advance_ns(void *data, u64 *val) > +{ > + struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data; > + *val = vcpu->arch.apic->lapic_timer.timer_advance_ns; This needs to ensure to check lapic_in_kernel() to ensure apic isn't NULL. Actually, I think we can skip creation of the parameter entirely if lapic_in_kernel() is false. VMX and SVM both instantiate the lapic during kvm_arch_vcpu_create(), which is (obviously) called before kvm_arch_create_vcpu_debugfs(). > + return 0; > +} > + > +DEFINE_SIMPLE_ATTRIBUTE(vcpu_timer_advance_ns_fops, vcpu_get_timer_advance_ns, NULL, "%llu\n"); > + > static int vcpu_get_tsc_offset(void *data, u64 *val) > { > struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data; > @@ -51,6 +61,12 @@ int kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu) > if (!ret) > return -ENOMEM; > > + ret = debugfs_create_file("lapic_timer_advance_ns", 0444, > + vcpu->debugfs_dentry, > + vcpu, &vcpu_timer_advance_ns_fops); > + if (!ret) > + return -ENOMEM; > + > if (kvm_has_tsc_control) { > ret = debugfs_create_file("tsc-scaling-ratio", 0444, > vcpu->debugfs_dentry, > -- > 2.7.4 >