Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2298837imj; Mon, 18 Feb 2019 03:39:55 -0800 (PST) X-Google-Smtp-Source: AHgI3IZn/DDTP2gA7x9a1JYbHeMmAEKSRKYvY3SkruhyDmfY4mnbpblJ6huuppSJ1yhcXz9VzkoT X-Received: by 2002:a63:2a82:: with SMTP id q124mr18355434pgq.402.1550489994795; Mon, 18 Feb 2019 03:39:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550489994; cv=none; d=google.com; s=arc-20160816; b=kBXJ/ZXQftjIzwi6+Vgxt6+Q0tngUjwP2wbrKJcIckzH7PjJws3Hnz25QqOMTC1ssP ae6Gzo9iefGwme+3PafYV1YzVBj4m1HvpD3G2L9s7EyoghdVrCKmy65UsY0d2scHStHS P3Aj51oFu6DO9RSTvwXTN0G5shRvW4Xwvehb904+KKY3++GiMN15O/V+b9emQk5E+bsw cKE8jADGajtBeyGMqP3YeI4oLBZQViIvrrRduT6utGtPqPPEcDnMM20nfrQGLjPphWWa haJBtClKg/MF270lzgQ7G/HH6/lH5XlRW3Dnfc2eHrohWXIA4HHGG03BHlBeJZsgwmQB rc3w== 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=lusWQ+J0d6AxRgiUDllLoAmZks2bg8/fbzSgLXDXx+Q=; b=PrtC8PlQuzAtuKNOicegccXlBp3jTG7UPv1YJdT9di+YYIU0TIei3mlXZ0sk8t/QXX ZPPmtufr24A6tMEJ42szihNyWwZv2Z6LiOFctVM1hDi1YHkr13Y6OZPJ90mkdUh6GnVt nSNFbkgpDy2J7f3q0Tb3Zv/RwnWGcJPBnhjFDP3Qx+IwY+4W6ADcciDr6TpFO+9eKHPt mefPabI348HJCwPLZRbZIosq9uORFubYVcW96KVLuDN0CvsAMMQ3xiFliJ3vCLr+gAlJ FWkbctl5iTjze0if4r/GoM9Yn+FqmqZTVdQKZeRK/jt24yey33CWHjwefUXUXfbPWkdZ 4l4w== 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 u7si13138973pfu.270.2019.02.18.03.39.39; Mon, 18 Feb 2019 03:39:54 -0800 (PST) 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 S1729693AbfBRL0y (ORCPT + 99 others); Mon, 18 Feb 2019 06:26:54 -0500 Received: from mga07.intel.com ([134.134.136.100]:13652 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728905AbfBRL0y (ORCPT ); Mon, 18 Feb 2019 06:26:54 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Feb 2019 03:26:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,384,1544515200"; d="scan'208";a="275885435" Received: from vmm.bj.intel.com ([10.240.192.123]) by orsmga004.jf.intel.com with ESMTP; 18 Feb 2019 03:26:49 -0800 From: Luwei Kang To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, pbonzini@redhat.com, rkrcmar@redhat.com, peterz@infradead.org, acme@kernel.org, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, kan.liang@linux.intel.com, ak@linux.intel.com, konrad.wilk@oracle.com, Janakarajan.Natarajan@amd.com, mattst88@gmail.com, tim.c.chen@linux.intel.com, Luwei Kang Subject: [PATCH v2 1/2] KVM: x86: Inject PMI for KVM guest Date: Mon, 18 Feb 2019 19:26:07 -0500 Message-Id: <1550535968-7652-2-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1550535968-7652-1-git-send-email-luwei.kang@intel.com> References: <1550535968-7652-1-git-send-email-luwei.kang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Inject a PMI for KVM guest when Intel PT working in Host-Guest mode and Guest ToPA entry memory buffer was completely filled. Signed-off-by: Luwei Kang --- arch/x86/events/intel/core.c | 6 +++++- arch/x86/include/asm/msr-index.h | 4 ++++ arch/x86/kvm/x86.c | 10 ++++++++++ include/linux/perf_event.h | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 730978d..37cecff 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -2273,7 +2273,11 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status) */ if (__test_and_clear_bit(55, (unsigned long *)&status)) { handled++; - intel_pt_interrupt(); + if (unlikely(perf_guest_cbs && perf_guest_cbs->is_in_guest() && + perf_guest_cbs->handle_intel_pt_intr)) + perf_guest_cbs->handle_intel_pt_intr(); + else + intel_pt_interrupt(); } /* diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 8e40c24..ae01fb0 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -775,6 +775,10 @@ #define MSR_CORE_PERF_GLOBAL_CTRL 0x0000038f #define MSR_CORE_PERF_GLOBAL_OVF_CTRL 0x00000390 +/* PERF_GLOBAL_OVF_CTL bits */ +#define MSR_CORE_PERF_GLOBAL_OVF_CTRL_TRACE_TOPA_PMI_BIT 55 +#define MSR_CORE_PERF_GLOBAL_OVF_CTRL_TRACE_TOPA_PMI (1ULL << MSR_CORE_PERF_GLOBAL_OVF_CTRL_TRACE_TOPA_PMI_BIT) + /* Geode defined MSRs */ #define MSR_GEODE_BUSCONT_CONF0 0x00001900 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 941f932..d1f4e0a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6795,10 +6795,20 @@ static unsigned long kvm_get_guest_ip(void) return ip; } +static void kvm_handle_intel_pt_intr(void) +{ + struct kvm_vcpu *vcpu = __this_cpu_read(current_vcpu); + + kvm_make_request(KVM_REQ_PMI, vcpu); + __set_bit(MSR_CORE_PERF_GLOBAL_OVF_CTRL_TRACE_TOPA_PMI_BIT, + (unsigned long *)&vcpu->arch.pmu.global_status); +} + static struct perf_guest_info_callbacks kvm_guest_cbs = { .is_in_guest = kvm_is_in_guest, .is_user_mode = kvm_is_user_mode, .get_guest_ip = kvm_get_guest_ip, + .handle_intel_pt_intr = kvm_handle_intel_pt_intr, }; static void kvm_set_mmio_spte_mask(void) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index e1a0517..2b26a34 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -30,6 +30,7 @@ struct perf_guest_info_callbacks { int (*is_in_guest)(void); int (*is_user_mode)(void); unsigned long (*get_guest_ip)(void); + void (*handle_intel_pt_intr)(void); }; #ifdef CONFIG_HAVE_HW_BREAKPOINT -- 1.8.3.1