From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82C1D231C9F for ; Tue, 2 Dec 2025 16:03:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764691411; cv=none; b=CpEZ+eaDdH/1DjNCu8TAWwg6fc5rfqhlEHd+AKzYz/JTJP8g7S2n8vOHrO0yO940Jhsu8XLkDSrTEtTQ/0zJnMVboL+YJz5MsaNUMq/smzppHoLtpCmHNja/wvNP72EwGQ0wwyT3qJ+gCwEVTcWJN54jQPFpHQ0LovC5uLOW5GI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764691411; c=relaxed/simple; bh=qRYb2UuLMho7adIKiGqSJm3f0QgiMpUF9tCgxUcb1ls=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DNkY3ZUIrvHN5J/Neb8+G5nOVR82RxrEUMCCJ0xNgfdIkl3XNA7MxwpOCetZitwaM7Vh+rzeQiskYjGFyZOS24OC7zO5AyKBZtCErWbYmMUTA+fREtyomAGSX1YO7A0A9W8FaS7IHQFrkI13TpRLZXEYKs0sLqlKLz53hJtzm9Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=masZH/aq; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="masZH/aq" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-34374bfbcccso4997811a91.0 for ; Tue, 02 Dec 2025 08:03:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764691408; x=1765296208; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=7h65javEKiZCilvi53EqrbcCyqwHMbAxO5ZzdpYHZ2Q=; b=masZH/aqlMEUaLDkXB46XPz6/Tw58M9bfX7tPa37CMc35hdprpAhQH8fi2syvRE2CH Rmo30Tag66rhRj8cwfXYrKKJS0DXuI3b3pYpVAHJgWeOa/7ihsaqQqOIVmbJzZuHZ99f IEYLqNa+VZpHtdl58LrkXcHm0KHD2bYqNEjsZd5U2hc3G1Q0FVWWCOHl1UahzlkFrl1C 7dniGt15KRjnQBnpvyVp5Z3gRhszx/Lco2f6mU3cTmsIfGMlC9dBiTMhDq1SF54H0W6z 0HscIHluBmCaiBJyIk7kL3x11yepDNgxtR/i7QB1UWi9dsvff/w9R8o5/E8gP5l51wQ5 Fk9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764691408; x=1765296208; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7h65javEKiZCilvi53EqrbcCyqwHMbAxO5ZzdpYHZ2Q=; b=NgYNruLys2l+hGlOT6P5HgyqZCs8hsVqBOPx17b0r7iHvOTdIS8d6/ZKQrs+KT61SY BQL7DqxhPbSbjUPXjT6jzNFRApahTSjIXuQImxPIq1IMQUTXhTNvIj+5j75aDBCw+kSW 5MMmNUxnVVWo+Oa4tuDIOCGYKjVYFm8OHVgShu8jgHbOmZDogRGT4cUtn9Ed8imcFbxz lngyF0BALNGBJ4eKU8pwSlWGfuy6p2JhogefLoht1e2VKr9BqumgnYFHH8V9lFJkay7I kIMQ39ZgSv5l3ezDYSgJCOd3/ANk8RR3K6If2uSlsqknpzhS6z5XFk/XQPbP6b0Rh8P7 aOZw== X-Forwarded-Encrypted: i=1; AJvYcCUUkS9lWGq0NQY2ft6YoX3WRQtL8qh+OzAskuzW186X7aZu7gaIGfDvU+c/3UjUwNXYUxcz0/nbbmHbI0c=@vger.kernel.org X-Gm-Message-State: AOJu0YyW6DdUZo8qPuL0hoaXg5zvc+ieTbQBSJUmLcvFnU0zfU0o37jx zXw+oUREkVPg325T1HpaZh7J39RqiWUAq0W+ER8ysQinjgV1TeQP3qGfkNpyuhXpHfQ9HwdkC6F FmXFEHQ== X-Google-Smtp-Source: AGHT+IHgZDUiSW6QxjIjcAOYgkuyQjls1DupsHMaqWae+TriC3tvVF94Ipa05PoU8Re45MZOfysmDED4NVs= X-Received: from pjbca18.prod.google.com ([2002:a17:90a:f312:b0:32b:ae4c:196c]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5605:b0:340:bc27:97bd with SMTP id 98e67ed59e1d1-3475ebf93b2mr25169788a91.9.1764691407827; Tue, 02 Dec 2025 08:03:27 -0800 (PST) Date: Tue, 2 Dec 2025 08:03:26 -0800 In-Reply-To: <20251202124423.GC2458571@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251201142359.344741-1-sieberf@amazon.com> <20251202100311.GB2458571@noisy.programming.kicks-ass.net> <20251202124423.GC2458571@noisy.programming.kicks-ass.net> Message-ID: Subject: Re: [PATCH] KVM: x86/pmu: Do not accidentally create BTS events From: Sean Christopherson To: Peter Zijlstra Cc: Fernand Sieber , pbonzini@redhat.com, "Jan =?utf-8?Q?H=2E_Sch=C3=B6nherr?=" , tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, dwmw@amazon.co.uk, hborghor@amazon.de, nh-open-source@amazon.com, abusse@amazon.de, nsaenz@amazon.com, stable@vger.kernel.org Content-Type: text/plain; charset="us-ascii" On Tue, Dec 02, 2025, Peter Zijlstra wrote: > Does something like so work? It is still terrible, but perhaps slightly > less so. > > diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h > index 2b969386dcdd..493e6ba51e06 100644 > --- a/arch/x86/events/perf_event.h > +++ b/arch/x86/events/perf_event.h > @@ -1558,13 +1558,22 @@ static inline bool intel_pmu_has_bts_period(struct perf_event *event, u64 period > struct hw_perf_event *hwc = &event->hw; > unsigned int hw_event, bts_event; > > - if (event->attr.freq) > + /* > + * Only use BTS for fixed rate period==1 events. > + */ > + if (event->attr.freq || period != 1) > + return false; > + > + /* > + * BTS doesn't virtualize. > + */ > + if (event->attr.exclude_host) Ya, this seems like the right fix. Pulling in the original bug report: When BTS is enabled, it leads to general host performance degradation to both VMs and host. I assume the underlying problem is that intel_pmu_enable_bts() is called even when the event isn't enabled in the host, and BTS doesn't discrimate once it's enable and bogs down the host (but presumably not the guest, at least not directly, since KVM should prevent setting BTS in vmcs.GUEST_IA32_DEBUGCTL). Enabling BTS for exclude-host events simply can't work, even if the event came from host userspace.