Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3409338ybk; Tue, 19 May 2020 04:04:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZUYQBSfu0jK/9hzdmIUYJXqpDm+PjlwCA2s0IP7PBrnSVWKGBNnY3Jz+GT7z6dYczC6op X-Received: by 2002:a17:906:4088:: with SMTP id u8mr129774ejj.422.1589886266936; Tue, 19 May 2020 04:04:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589886266; cv=none; d=google.com; s=arc-20160816; b=araXMLAo87xPcTcrx3c74HKQidrDVLOb/x/3rliO0udW0Ghyi6otwfWkFxZJC3sEVB 75kRJWgWwaCOIQEEU0Mdz/sXSWLIFsHoPOTNkaVHlQgybWAvG382ZA0/NAK0rvuENN+/ KD4AYth+VVlx7D2THau5jQ7lUuWQyHhBUyFmxERbuFIaF8OOCJPmBsuv8Rxuv8KjsSlw PnHD97DcGSjvvc7/8oZq6eWdQYTkyX4XhiPYzReNReyPV1krdaMWULyWGAlHw7VlB4la K7UWvIt3FGptnE+KVn3joA27VlVjHusSGieNe3CiBszisOEFnvphx/qdfkcNrIPaIAML IOeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=VT+X+5rq1DXaytjnI7YmoqX52Zbfd4pwFpxuEA+HGCI=; b=TICFHBLeLrwOP08aAqCgaqByRMBLsSeI6f+1A2mFxQZsVbToUBCxFM2b9W0XO0QTyp 9It7/GmilT8vUHvouoV8aUrZFaYHpgXXNKeQFc0fRHkJnprXKwuGTSEE3A8fk77Ebcw2 +9hYw8YnDZRxJn9nnuv6IFpLuKiPgalwLBnqpUPG/qbsGBXDDpkUFEnQkCciUsok0HnW qGhrCbdR2eHhxFKG7Sd9mCkZXpTPC6bD1c1xjADVg9GGU/RNfGBJrjecuPG6t/7a3Inx u6oPNMnB6let4anNxPX/9kIYstXyItqsZXSej+QhcDEA3Gec1ECo/NOw2V4BRxhSEC+b 3PLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=JJPCqgBx; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y16si7808568edm.150.2020.05.19.04.04.03; Tue, 19 May 2020 04:04:26 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=JJPCqgBx; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728705AbgESLA2 (ORCPT + 99 others); Tue, 19 May 2020 07:00:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728573AbgESLA1 (ORCPT ); Tue, 19 May 2020 07:00:27 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A598CC061A0C; Tue, 19 May 2020 04:00:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=VT+X+5rq1DXaytjnI7YmoqX52Zbfd4pwFpxuEA+HGCI=; b=JJPCqgBxpP9DGH5rpeekl2GoZM pHe0x8uC/1s8dhbyftZRdkMnSvTj5b578nfrCWKKmppBKl91gEvjTNe3yJEmrA5xYz5gEDx8S7xop jh6tVVIxpoeZ+Y9eX1KXMhMqq9QH0lcXI4GbjpGXIYc52vG/ZUVc6vb4Ovj3vViFIi26L9a8OFrxX ykC+mlurLMxvYJnoHP5MQWp17aufSX6sJTYX6jID51x5YxRIlo5QNoWZjAspU6Vw8QNdpz12wi4e+ 399tRlBoNmInNaBNULWtdHSDEULvdtaIrniRNWFuWDoLcjI+clEWX2uFEo8I/OeLXovqJA4lLDQb9 X9aaVLLQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jazyn-0007S9-6j; Tue, 19 May 2020 11:00:13 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 4ACAC3008A8; Tue, 19 May 2020 13:00:11 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 371C12B16F2CA; Tue, 19 May 2020 13:00:11 +0200 (CEST) Date: Tue, 19 May 2020 13:00:11 +0200 From: Peter Zijlstra To: Like Xu Cc: Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , ak@linux.intel.com, wei.w.wang@intel.com Subject: Re: [PATCH v11 08/11] KVM: x86/pmu: Emulate LBR feature via guest LBR event Message-ID: <20200519110011.GG279861@hirez.programming.kicks-ass.net> References: <20200514083054.62538-1-like.xu@linux.intel.com> <20200514083054.62538-9-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200514083054.62538-9-like.xu@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 14, 2020 at 04:30:51PM +0800, Like Xu wrote: > +static inline bool event_is_oncpu(struct perf_event *event) > +{ > + return event && event->oncpu != -1; > +} > +/* > + * It's safe to access LBR msrs from guest when they have not > + * been passthrough since the host would help restore or reset > + * the LBR msrs records when the guest LBR event is scheduled in. > + */ > +static bool intel_pmu_access_lbr_msr(struct kvm_vcpu *vcpu, > + struct msr_data *msr_info, bool read) > +{ > + struct kvm_pmu *pmu = vcpu_to_pmu(vcpu); > + u32 index = msr_info->index; > + > + if (!intel_is_valid_lbr_msr(vcpu, index)) > + return false; > + > + if (!msr_info->host_initiated && !pmu->lbr_event) > + intel_pmu_create_lbr_event(vcpu); > + > + /* > + * Disable irq to ensure the LBR feature doesn't get reclaimed by the > + * host at the time the value is read from the msr, and this avoids the > + * host LBR value to be leaked to the guest. If LBR has been reclaimed, > + * return 0 on guest reads. > + */ > + local_irq_disable(); > + if (event_is_oncpu(pmu->lbr_event)) { > + if (read) > + rdmsrl(index, msr_info->data); > + else > + wrmsrl(index, msr_info->data); > + } else if (read) > + msr_info->data = 0; > + local_irq_enable(); > + > + return true; > +} So this runs in the vCPU thread in host context to emulate the MSR access, right?