Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp368267ybh; Thu, 12 Mar 2020 03:36:55 -0700 (PDT) X-Google-Smtp-Source: ADFU+vti4A77BchBkdanThfjb0yAYvIr3n94VjPZPfC2Rew4/FcfI+JrRlUgEY/pj7iJtFnf1wLj X-Received: by 2002:a05:6808:103:: with SMTP id b3mr2136950oie.46.1584009415029; Thu, 12 Mar 2020 03:36:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584009415; cv=none; d=google.com; s=arc-20160816; b=ljI8FK60IDHPDdSuqYzLBuvZPh/aqU6cL1LNGSTsOUsYmvIuGHUMmTkY4vORUFv2pC LLrHGXgCnESVgo4mtAPS/IZ1g7Gs3kj2h4L0sZ04QDIH1QfIzotNrVBXYwAgPMO8D0Cr GvXMPCPIOzV1mhBnPAew0e40Wmit169pVB3tsFd+1mTaw262lalB2TO2rtXq1nARqC/V 2tvZl8KXAOOxtMKbAm+vA5IhexUYu3XIJ5uBiMXt7bnHjD2PzP9Wm2MAW604CSqDeqcg uE+4/5RBozv3UOj/GTxMze6Cr1UZqygMTqgG9+HRSE+HIcefGLo6t8SS9Z8jF/EPSN0V 2ocA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=GH7fU1TWEWw40X0bZzMnWywwid5YSvqvgDDmRobv45Y=; b=QO2r88x4sysC2qbBPSkOEc4T4mQ+ZbV9ZxvdqEXjZBApNUrMpf1D1VJy+qlIRmOL/J g0d+ngELh783+gSpp00mom2RzOA/Y0QYKyGcY2GN36AK5G5WxZlCztToRReP/jfZZpZn ykG8+g4Wv2ZWmf0yt+LI2KoM9RC6Pc+zsuEr8yEtjSUg4UN9BON8G77BwBaIbh2A+O1Q OlVbqs92nY/omuJ05jMSb469K0mYJ4UipAHmenr5Oj0eY03+VmfCFP8yAdevFydb4XHe Q2XkSOshAkxhR+WoSC17aqPm7Mt7rtoBouhkRC9MDTytryozlUtzbOAiYMQX4G8pYY9I Bf+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iXtPj5wg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d3si2317581oia.236.2020.03.12.03.36.42; Thu, 12 Mar 2020 03:36:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iXtPj5wg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726867AbgCLKg0 (ORCPT + 99 others); Thu, 12 Mar 2020 06:36:26 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:60087 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726299AbgCLKgZ (ORCPT ); Thu, 12 Mar 2020 06:36:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584009384; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=GH7fU1TWEWw40X0bZzMnWywwid5YSvqvgDDmRobv45Y=; b=iXtPj5wgcCMHSPMzUsWRxwATQWYS/jAqATCs65UX95fNsBSU8NojmKBiZ0siIQNqoCgXSm bjdMrPSTDAzVtdUbL1L/5EPCPAaPVkeYNMJnR/m0riWF5afhlS0BRIlPbI/di/7mI0sHVq wkrvCNSM/fhh2LY7SCxCQzZUM0LJJE4= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-315-aaaiaHC8OHeu5ht11UZDLw-1; Thu, 12 Mar 2020 06:36:21 -0400 X-MC-Unique: aaaiaHC8OHeu5ht11UZDLw-1 Received: by mail-wr1-f69.google.com with SMTP id j17so2394132wru.19 for ; Thu, 12 Mar 2020 03:36:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=GH7fU1TWEWw40X0bZzMnWywwid5YSvqvgDDmRobv45Y=; b=EY4eiJ+yyQ8NhVjylE1Vjh9cSLFMMJH+tMGjYI+aUZhsatHc0EggpsiYI6MvyRnfBz 9nouFksM/Bn8FU7nPyPkUNIjrXfJ3cxcQVYwAZRZGellhF4lss6tBvw7zMSI9Q778VKE AnIu+nKcYJ+u4LB2ih9Hr6Hbi1EYrp20ex2puzkmnipfZa3LwKWFPSZDGv9ac9QqsvIw cUVKttE3pd4BlUL9vyDfEgcCrC8UktFZZMtg9CwBzDUtCbQvcN9RqHe7++gGT78cX5vR nhDY+D5AYruL9TOTmtmuUPzdCYVm6wJxQ8LsWZFOQZR0is424RUMFiBOysxtLW0xBB9K zIFQ== X-Gm-Message-State: ANhLgQ2JiQ6YsulPYHkr3gTqaJoAC3YCBw+fhmYW5JC8+/os9JB7w1yF /e6HOKNXGUnyWBN/dU2UtZYnwX3dbLrnXsH5UAuo5CJXl4HQuAg9Pj6jedHyfGhqivWYYjc5WSp SzONpXD9OpDSI7kYYL7rupuFF X-Received: by 2002:a1c:2e4d:: with SMTP id u74mr4107935wmu.96.1584009380311; Thu, 12 Mar 2020 03:36:20 -0700 (PDT) X-Received: by 2002:a1c:2e4d:: with SMTP id u74mr4107908wmu.96.1584009380046; Thu, 12 Mar 2020 03:36:20 -0700 (PDT) Received: from vitty.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id l7sm2679012wrw.33.2020.03.12.03.36.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 03:36:19 -0700 (PDT) From: Vitaly Kuznetsov To: Wanpeng Li , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Wanpeng Li , Jim Mattson , Joerg Roedel Subject: Re: [PATCH] KVM: VMX: Micro-optimize vmexit time when not exposing PMU In-Reply-To: <1584007547-4802-1-git-send-email-wanpengli@tencent.com> References: <1584007547-4802-1-git-send-email-wanpengli@tencent.com> Date: Thu, 12 Mar 2020 11:36:19 +0100 Message-ID: <87r1xxrhb0.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Wanpeng Li writes: > From: Wanpeng Li > > PMU is not exposed to guest by most of cloud providers since the bad performance > of PMU emulation and security concern. However, it calls perf_guest_switch_get_msrs() > and clear_atomic_switch_msr() unconditionally even if PMU is not exposed to the > guest before each vmentry. > > ~1.28% vmexit time reduced can be observed by kvm-unit-tests/vmexit.flat on my > SKX server. > > Before patch: > vmcall 1559 > > After patch: > vmcall 1539 > > Signed-off-by: Wanpeng Li > --- > arch/x86/kvm/vmx/vmx.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 40b1e61..fd526c8 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -6441,6 +6441,9 @@ static void atomic_switch_perf_msrs(struct vcpu_vmx *vmx) > int i, nr_msrs; > struct perf_guest_switch_msr *msrs; > > + if (!vcpu_to_pmu(&vmx->vcpu)->version) > + return; > + > msrs = perf_guest_get_msrs(&nr_msrs); > > if (!msrs) Personally, I'd prefer this to be expressed as diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 40b1e6138cd5..ace92076c90f 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6567,7 +6567,9 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu) pt_guest_enter(vmx); - atomic_switch_perf_msrs(vmx); + if (vcpu_to_pmu(&vmx->vcpu)->version) + atomic_switch_perf_msrs(vmx); + atomic_switch_umwait_control_msr(vmx); if (enable_preemption_timer) (which will likely produce the same code as atomic_switch_perf_msrs() is likely inlined). Also, (not knowing much about PMU), is "vcpu_to_pmu(&vmx->vcpu)->version" check correct? E.g. in intel_is_valid_msr() correct for Intel PMU or is it stated somewhere that it is generic rule? Also, speaking about cloud providers and the 'micro' nature of this optimization, would it rather make sense to introduce a static branch (the policy to disable vPMU is likely to be host wide, right)? -- Vitaly