[PATCH 2/3] perf: require exclude_guest to use PEBS - kernel side enforcement

From: David Ahern
Date: Thu Sep 13 2012 - 16:59:46 EST

From: Peter Zijlstra <peterz@xxxxxxxxxxxxx>

Per Peter:
"Intel PEBS in VT-x context uses the DS address as a guest linear address,
even though its programmed by the host as a host linear address. This
either results in guest memory corruption and or the hardware faulting and
'crashing' the virtual machine. Therefore we have to disable PEBS on VT-x
enter and re-enable on VT-x exit, enforcing a strict exclude_guest.

This patch enforces exclude_guest kernel side.

Signed-off-by: David Ahern <dsahern@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Robert Richter <robert.richter@xxxxxxx>
Cc: Gleb Natapov <gleb@xxxxxxxxxx>
Cc: Avi Kivity <avi@xxxxxxxxxx>
Link: https://lkml.org/lkml/2012/7/9/298
arch/x86/kernel/cpu/perf_event.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 915b876..4bc96c5 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -338,6 +338,9 @@ int x86_setup_perfctr(struct perf_event *event)
/* BTS is currently only allowed for user-mode. */
if (!attr->exclude_kernel)
+ if (!attr->exclude_guest)
+ return -EOPNOTSUPP;

hwc->config |= config;
@@ -380,6 +383,9 @@ int x86_pmu_hw_config(struct perf_event *event)
if (event->attr.precise_ip) {
int precise = 0;

+ if (!event->attr.exclude_guest)
+ return -EOPNOTSUPP;
/* Support for constant skid */
if (x86_pmu.pebs_active && !x86_pmu.pebs_broken) {

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/