Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1305961imm; Thu, 6 Sep 2018 20:28:28 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaL9bvu+xwYLAzlM4bAKefQgohLE9MAWlD78p3BdRuwkgEjp9KXgXe7efrnBYc8JXQNPN17 X-Received: by 2002:a63:6283:: with SMTP id w125-v6mr5844916pgb.83.1536290908697; Thu, 06 Sep 2018 20:28:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536290908; cv=none; d=google.com; s=arc-20160816; b=C4yh3Vo6jfQyFlXmgHu4xSeRqGyqlxh9dO/dsW6NscSu2zZkKyeC3UJ2sSyuoB+COa 4TVsx/TyeK7BiN9O4eQfrjna1iveWpx6VXmeNbbaOUSA96TV7Jt3RpoF091sW98xWfgy l6sSPZVQUjynj2onCL9IRYLKw4MvdDfIopmE3R0hoT09ybJNuAwqxk8Dh4sZMOwGS0Gv V5wYoxQ2qd1Rt2vjtLh+2fhaukQvbAORlUeUgrNc+olurXKx3lCqEIoGWRoRlqyUJIr0 sU1rPuh4XMhbwAqbCShpC4MbSDHlRURQAm36op+JMnvqD9LSasndWPMA9ozJ5pji8Hv6 OmYw== 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; bh=pGI9P//mW1LetJcqH2LuOSvsPiyBf7WRIkruRKVKU30=; b=RXkLgvaq3HGJtlOCahh4cGRR0yx0h43pQXCTopUxE55yWN+9rdQZjdB/0qhpiPrQWJ yGSqp8uyO124MCSDHRzV/GROP9I0tMzsUOhrz/ABVM1LcxuLHsGncyBI+HarlfuqEiCJ n50fxXwot6T7rgEUVDKpdwh677G3my1vNJdYiYu3Hu04bHtSc/08VX5KW+wLsD7Ax57S f+Njw50humRv3JJOy3tjruhTJCpHcFFN6RbsS69TrA1JRk8jYynLktq0cjwqYetKT3YE 1LdBnAsBAo6w060gqruVqG6Ev8Yjo9u9L1sxsDAUxECt9z6ZLLPaAsiJfBTXFLglyKKd UmgA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e22-v6si6733162pgi.111.2018.09.06.20.28.13; Thu, 06 Sep 2018 20:28:28 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726187AbeIGIFx (ORCPT + 99 others); Fri, 7 Sep 2018 04:05:53 -0400 Received: from mga12.intel.com ([192.55.52.136]:6360 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725931AbeIGIFw (ORCPT ); Fri, 7 Sep 2018 04:05:52 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Sep 2018 20:27:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,340,1531810800"; d="scan'208";a="88381685" Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.7.201.126]) by orsmga001.jf.intel.com with ESMTP; 06 Sep 2018 20:27:07 -0700 Received: by tassilo.localdomain (Postfix, from userid 1000) id 276F0300B65; Thu, 6 Sep 2018 20:27:07 -0700 (PDT) Date: Thu, 6 Sep 2018 20:27:07 -0700 From: Andi Kleen To: Wei Wang Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, pbonzini@redhat.com, kan.liang@intel.com, peterz@infradead.org, mingo@redhat.com, rkrcmar@redhat.com, like.xu@intel.com Subject: Re: [PATCH v2 6/8] perf/x86/intel/lbr: guest requesting KVM for lbr stack save/restore Message-ID: <20180907032707.GN27886@tassilo.jf.intel.com> References: <1536233456-12173-1-git-send-email-wei.w.wang@intel.com> <1536233456-12173-7-git-send-email-wei.w.wang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1536233456-12173-7-git-send-email-wei.w.wang@intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 06, 2018 at 07:30:54PM +0800, Wei Wang wrote: > This patch adds an interface to enable a guest to request KVM to save > and restore the lbr stack on vCPU context switching. > > KVM couldn't capture the info about whether the guest is actively using > the lbr feature via the lbr enable bit in the debugctl MSR, because that > control bit is frequently enabled and disabled by the guest, and in some > csaes, it is disabled even when the guest is actively using the lbr > feature. For example, perf_pmu_sched_task in the guest disables the bit > before reading out the lbr stack. In this case, the bit is disabled though > the guest is still using the lbr feature. > > So, a KVM-specific MSR, MSR_KVM_PV_LBR_CTRL, is used by the guest at a > proper place to tell KVM if the LBR is actively in use or not. Basically, > the lbr user callstack mode needs the lbr stack to be saved/restored on a > context switching, so we set the ACTIVE bit of MSR_KVM_PV_LBR_CTRL only > when the user callstack mode is used. The KVM hypervisor will add the lbr > stack save/restore support on vCPU switching after the ACTIVE bit is set. PV is difficult because it requires changing all the users. Maybe a better approach would be a lazy restore of the LBRs: Don't restore the LBRs on context switch, but set the LBR MSRs to intercept. Then on the first access restore the LBRs and allow direct access to the MSRs again. Also when the LBRs haven't been set to direct access the state doesn't need to be saved. -Andi