From: Dongli Si <kvmx86@gmail.com>
To: peterz@infradead.org, joro@8bytes.org, likexu@tencent.com
Cc: liam.merwick@oracle.com, kim.phillips@amd.com, mingo@kernel.org,
acme@kernel.org, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
namhyung@kernel.org, tglx@linutronix.de, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
jmattson@google.com, linux-perf-users@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] perf/x86/amd: cpu_hw_events::perf_ctr_virt_mask should only be used on host
Date: Mon, 11 Apr 2022 21:46:51 +0800 [thread overview]
Message-ID: <20220411134651.740234-1-sidongli1997@gmail.com> (raw)
From: Dongli Si <sidongli1997@gmail.com>
perf_ctr_virt_mask is used to mask Host-Only bit when SVM is disabled,
Using it on a guest doesn't make sense and make things obscure.
Revert commit df51fe7ea1c1c
("perf/x86/amd: Don't touch the AMD64_EVENTSEL_HOSTONLY bit inside the guest"),
Because it make things a little obscure and this #GP has been fixed in KVM.
Fixes: 1018faa6cf23 ("perf/x86/kvm: Fix Host-Only/Guest-Only counting with SVM disabled")
Signed-off-by: Dongli Si <sidongli1997@gmail.com>
---
arch/x86/events/amd/core.c | 19 ++++++++++++++++++-
arch/x86/events/perf_event.h | 3 +--
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
index 9687a8aef01c..5ac7d9410d36 100644
--- a/arch/x86/events/amd/core.c
+++ b/arch/x86/events/amd/core.c
@@ -533,7 +533,12 @@ static void amd_pmu_cpu_starting(int cpu)
struct amd_nb *nb;
int i, nb_id;
- cpuc->perf_ctr_virt_mask = AMD64_EVENTSEL_HOSTONLY;
+ /*
+ * When SVM is disabled, set the Host-Only bit will cause the
+ * performance counter to not work.
+ */
+ if (!boot_cpu_has(X86_FEATURE_HYPERVISOR))
+ cpuc->perf_ctr_virt_mask = AMD64_EVENTSEL_HOSTONLY;
if (!x86_pmu.amd_nb_constraints)
return;
@@ -1023,10 +1028,16 @@ __init int amd_pmu_init(void)
return 0;
}
+/*
+ * Unmask the Host-only bit when SVM is enabled on the Host Hypervisor
+ */
void amd_pmu_enable_virt(void)
{
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
+ if (boot_cpu_has(X86_FEATURE_HYPERVISOR))
+ return;
+
cpuc->perf_ctr_virt_mask = 0;
/* Reload all events */
@@ -1035,10 +1046,16 @@ void amd_pmu_enable_virt(void)
}
EXPORT_SYMBOL_GPL(amd_pmu_enable_virt);
+/*
+ * Mask the Host-only bit when SVM is disabled on the Host Hypervisor
+ */
void amd_pmu_disable_virt(void)
{
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
+ if (boot_cpu_has(X86_FEATURE_HYPERVISOR))
+ return;
+
/*
* We only mask out the Host-only bit so that host-only counting works
* when SVM is disabled. If someone sets up a guest-only counter when
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 150261d929b9..fa1428ca60b6 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -1138,10 +1138,9 @@ void x86_pmu_stop(struct perf_event *event, int flags);
static inline void x86_pmu_disable_event(struct perf_event *event)
{
- u64 disable_mask = __this_cpu_read(cpu_hw_events.perf_ctr_virt_mask);
struct hw_perf_event *hwc = &event->hw;
- wrmsrl(hwc->config_base, hwc->config & ~disable_mask);
+ wrmsrl(hwc->config_base, hwc->config);
if (is_counter_pair(hwc))
wrmsrl(x86_pmu_config_addr(hwc->idx + 1), 0);
--
2.32.0
next reply other threads:[~2022-04-11 13:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-11 13:46 Dongli Si [this message]
2022-04-11 14:29 ` [PATCH] perf/x86/amd: cpu_hw_events::perf_ctr_virt_mask should only be used on host Like Xu
2022-04-12 1:25 ` Dongli Si
2022-04-12 4:55 ` Like Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220411134651.740234-1-sidongli1997@gmail.com \
--to=kvmx86@gmail.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=jolsa@kernel.org \
--cc=joro@8bytes.org \
--cc=kim.phillips@amd.com \
--cc=liam.merwick@oracle.com \
--cc=likexu@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).