Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp3777533ybh; Tue, 6 Aug 2019 01:08:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqzl57qymyhwZy8vlrVXKjUW+WINVjA3LKQEH6dHi1aiBHW9NNLRoSeW9Ie6DfwGOGjYvTGd X-Received: by 2002:a17:90a:fa07:: with SMTP id cm7mr1847245pjb.138.1565078909214; Tue, 06 Aug 2019 01:08:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565078909; cv=none; d=google.com; s=arc-20160816; b=wfF1SkLfqEePExr+gz1aE/m0KlriGKlBCaz1I47aGQpSyl0POThXullkadK81wAKy6 wJ1UimhpSaqoHXUzSxnDI2E+r5mIB1xYnSrpHp4PiRN34JF7t/bNx80Woz65riFxNoSK 9UnyAZpqcwiGzKpYOCHwDsa0VpqkkrsJIBqBZfisV++LoQ/BMJF/e4sAakoMNbjlgcy3 u6cfAdmW9Sl9K34l7O2IrNunhINP36ivEm3kxwXLWc88Ed9hxyh+aWx+aI7swY++5MNE tNLVa9zlf8Sg8EMKfDsSh7SzeXoP1cYN8OYzgn1ByE4kvjQwycIgRMZ+QT88K9MLg1aC KZZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=Qvj/SwWMI61K9csREaNBUGEyEY8ogsZX6GHcvB4EPIc=; b=nlsi0cOOigFkZjKXrDE/L4fw0PCTGC31+h9cM2Owp0KdtPEqMb4oVKV/r2km8ZVhdk +DEddgb4YgkYwaWIpYNY1IWtMO1HsGpN44Bq9l/kfYJdwESFCy6tHVKZiTRjjRiQLbFj sN6k9Wj30/9mhQ+efEEqWcI7M48ExRPBUfsNfT0SVdVAAjjU7WkOhsJdC1GhSvT+0pTO xyHysROKkNqXtGW/mVnHveFN/snHl7NPB7Jvy+4vLNEmFEw6MVAFc4m+H0URuU3t9VZV IztU1aXnjlCZLBDL5vX+z0rAJ/95PEuD2LqOH1EziXsQq8kORQ26WoeOo5DLILApWl+A W7iA== 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 m143si46752364pfd.224.2019.08.06.01.08.13; Tue, 06 Aug 2019 01:08:29 -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 S1732410AbfHFIGH (ORCPT + 99 others); Tue, 6 Aug 2019 04:06:07 -0400 Received: from mga03.intel.com ([134.134.136.65]:5861 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732356AbfHFIGE (ORCPT ); Tue, 6 Aug 2019 04:06:04 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Aug 2019 01:00:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,352,1559545200"; d="scan'208";a="373337398" Received: from devel-ww.sh.intel.com ([10.239.48.128]) by fmsmga005.fm.intel.com with ESMTP; 06 Aug 2019 01:00:57 -0700 From: Wei Wang To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, ak@linux.intel.com, peterz@infradead.org, pbonzini@redhat.com Cc: kan.liang@intel.com, mingo@redhat.com, rkrcmar@redhat.com, like.xu@intel.com, wei.w.wang@intel.com, jannh@google.com, arei.gonglei@huawei.com, jmattson@google.com Subject: [PATCH v8 10/14] perf/x86/lbr: don't share lbr for the vcpu usage case Date: Tue, 6 Aug 2019 15:16:10 +0800 Message-Id: <1565075774-26671-11-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1565075774-26671-1-git-send-email-wei.w.wang@intel.com> References: <1565075774-26671-1-git-send-email-wei.w.wang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Perf event scheduling lets multiple lbr events share the lbr if they use the same config for LBR_SELECT. For the vcpu case, the vcpu's lbr event created on the host deliberately sets the config to the user callstack mode to have the host support to save/restore the lbr state on vcpu context switching, and the config won't be written to the LBR_SELECT, as the LBR_SELECT is configured by the guest, which might not be the same as the user callstack mode. So don't allow the vcpu's lbr event to share lbr with other host lbr events. Signed-off-by: Wei Wang --- arch/x86/events/intel/lbr.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c index 4f4bd18..a0f3686 100644 --- a/arch/x86/events/intel/lbr.c +++ b/arch/x86/events/intel/lbr.c @@ -45,6 +45,12 @@ static const enum { #define LBR_CALL_STACK_BIT 9 /* enable call stack */ /* + * Set this hardware reserved bit if the lbr perf event is for the vcpu lbr + * emulation. This makes the reg->config different from other regular lbr + * events' config, so that they will not share the lbr feature. + */ +#define LBR_VCPU_BIT 62 +/* * Following bit only exists in Linux; we mask it out before writing it to * the actual MSR. But it helps the constraint perf code to understand * that this is a separate configuration. @@ -62,6 +68,7 @@ static const enum { #define LBR_FAR (1 << LBR_FAR_BIT) #define LBR_CALL_STACK (1 << LBR_CALL_STACK_BIT) #define LBR_NO_INFO (1ULL << LBR_NO_INFO_BIT) +#define LBR_VCPU (1ULL << LBR_VCPU_BIT) #define LBR_PLM (LBR_KERNEL | LBR_USER) @@ -818,6 +825,26 @@ static int intel_pmu_setup_hw_lbr_filter(struct perf_event *event) (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_INFO)) reg->config |= LBR_NO_INFO; + /* + * An lbr perf event without a counter indicates this is for the vcpu + * lbr emulation. The vcpu lbr emulation does not allow the lbr + * feature to be shared with other lbr events on the host, because the + * LBR_SELECT msr is configured by the guest itself. The reg->config + * is deliberately configured to be user call stack mode via the + * related attr fileds to get the host perf's help to save/restore the + * lbr state on vcpu context switching. It doesn't represent what + * LBR_SELECT will be configured. + * + * Set the reserved LBR_VCPU bit for the vcpu usage case, so that the + * vcpu's lbr perf event will not share the lbr feature with other perf + * events. (see __intel_shared_reg_get_constraints, failing to share + * makes it return the emptyconstraint, which finally makes + * x86_schedule_events fail to schedule the lower priority lbr event on + * the lbr feature). + */ + if (is_no_counter_event(event)) + reg->config |= LBR_VCPU; + return 0; } -- 2.7.4