From nobody Sun Feb 8 12:59:51 2026 Received: from fra-out-014.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-014.esa.eu-central-1.outbound.mail-perimeter.amazon.com [18.199.210.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D4A13161A6; Thu, 11 Dec 2025 18:36:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=18.199.210.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765478224; cv=none; b=XvLG1Oa5FL5Sj7ur4Z+kJ2/m77j/8PZUbZXW77VPo1mlRjeLr1giIfdHJ7deoxCQ5+p6BkHOLDG8LLrQzjwdkk/nQ+XQp6vqbqu+1WumvJUmKhW3u3TRgSVV7+IfQp6PRfLUgxqbdFs42A5ZObl8FTCkptuW3Doe+1wnC5aueRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765478224; c=relaxed/simple; bh=BLZDrpTLctOjJeBQ7kE6MzOtoDaCfVtSLHJPEeFgVwM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OTpVvp+Q+JerW9gvXxQLYq6BlE6rYQhek5R2gUDxGffMUkaHjl4iCVB7iHIlsbdWx+1z+gFBMc1BBEqA0a4oH8qGnTOGVw8oH4Ikvs3gng2JQRWM7aF2NB5n+wAaoVJQATPT7+Dre0StBc0CCBlGTO5iqj53HStKYElCgKfWY/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=FfCYuedE; arc=none smtp.client-ip=18.199.210.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="FfCYuedE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1765478220; x=1797014220; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BLZDrpTLctOjJeBQ7kE6MzOtoDaCfVtSLHJPEeFgVwM=; b=FfCYuedERb3ocuEALDgRbCIYCN+VX+2oy+PvrjdgQQVzz93pTqkV5UBA cqJuS9Js/I72aqL0VdyzfLo+y1o5xAyqcbAqrI+Bwr9qSRecsP0rCAcPY CVY/Pni4vbvU8jO3JM0fCiwTgwiDyP6XzsuyeYRMCQ7FsDS/ohcoqjJJt no5Ai9Dpu6l654hbw/+FOAGULviheXNG33iOdrl5UVqSOpchTONUV3ESA VtC21yuY+N/G/nKR3NSsVFEnG37pEnh/9spPQMmV3XEdChVvRkmHp0ud8 aoeEIpzBbtS1eeR5A5GVnumpHwdmvg1qZX4xKqYZxSwBTGY6IAaQOdTFi g==; X-CSE-ConnectionGUID: SHdbm8raRsiy5x2EVMJI/g== X-CSE-MsgGUID: 2+mG77+STLatB1e2eVkzXg== X-IronPort-AV: E=Sophos;i="6.21,141,1763424000"; d="scan'208";a="6480546" Received: from ip-10-6-11-83.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.11.83]) by internal-fra-out-014.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2025 18:36:40 +0000 Received: from EX19MTAEUC001.ant.amazon.com [54.240.197.225:31663] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.7.166:2525] with esmtp (Farcaster) id 74c1f423-9f86-49eb-b782-e2459c470737; Thu, 11 Dec 2025 18:36:40 +0000 (UTC) X-Farcaster-Flow-ID: 74c1f423-9f86-49eb-b782-e2459c470737 Received: from EX19D003EUB001.ant.amazon.com (10.252.51.97) by EX19MTAEUC001.ant.amazon.com (10.252.51.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.29; Thu, 11 Dec 2025 18:36:32 +0000 Received: from u5934974a1cdd59.ant.amazon.com (10.146.13.111) by EX19D003EUB001.ant.amazon.com (10.252.51.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.29; Thu, 11 Dec 2025 18:36:23 +0000 From: Fernand Sieber To: CC: , , , , , , , , , , , , , , , , , Subject: [PATCH v2] perf/x86/intel: Do not enable BTS for guests Date: Thu, 11 Dec 2025 20:36:04 +0200 Message-ID: <20251211183604.868641-1-sieberf@amazon.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251210111655.GB3911114@noisy.programming.kicks-ass.net> References: <20251210111655.GB3911114@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 X-ClientProxiedBy: EX19D037UWC004.ant.amazon.com (10.13.139.254) To EX19D003EUB001.ant.amazon.com (10.252.51.97) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable By default when users program perf to sample branch instructions (PERF_COUNT_HW_BRANCH_INSTRUCTIONS) with a sample period of 1, perf interprets this as a special case and enables BTS (Branch Trace Store) as an optimization to avoid taking an interrupt on every branch. Since BTS doesn't virtualize, this optimization doesn't make sense when the request originates from a guest. Add an additional check that prevents this optimization for virtualized events (exclude_host). Reported-by: Jan H. Sch=C3=B6nherr Suggested-by: Peter Zijlstra Signed-off-by: Fernand Sieber --- arch/x86/events/perf_event.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h index 3161ec0a3416..f2e2d9b03367 100644 --- a/arch/x86/events/perf_event.h +++ b/arch/x86/events/perf_event.h @@ -1574,13 +1574,22 @@ static inline bool intel_pmu_has_bts_period(struct = perf_event *event, u64 period struct hw_perf_event *hwc =3D &event->hw; unsigned int hw_event, bts_event; =20 - if (event->attr.freq) + /* + * Only use BTS for fixed rate period=3D=3D1 events. + */ + if (event->attr.freq || period !=3D 1) + return false; + + /* + * BTS doesn't virtualize. + */ + if (event->attr.exclude_host) return false; =20 hw_event =3D hwc->config & INTEL_ARCH_EVENT_MASK; bts_event =3D x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS); =20 - return hw_event =3D=3D bts_event && period =3D=3D 1; + return hw_event =3D=3D bts_event; } =20 static inline bool intel_pmu_has_bts(struct perf_event *event) --=20 2.43.0 Amazon Development Centre (South Africa) (Proprietary) Limited 29 Gogosoa Street, Observatory, Cape Town, Western Cape, 7925, South Africa Registration Number: 2004 / 034463 / 07