Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3215481pxb; Mon, 9 Nov 2020 05:48:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJyaEHBRvY3NMSkD+yJZvRMjTqs+bchlUmNZFj0jACZSbI6ANTlSNHkEVtCinIQYy4fkol4S X-Received: by 2002:a17:906:3089:: with SMTP id 9mr15510762ejv.535.1604929717044; Mon, 09 Nov 2020 05:48:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604929717; cv=none; d=google.com; s=arc-20160816; b=fY9Mtp3YnpnmMrQnGPvpetoGOF3S21VLZhIOwA1gKLzygq2Vy+Nn3+L5iFbeV+stBZ fCUakggIVhALP9WhyKjy3KkLQD2Ywl+xayaa8Wv1V23fPvVm1IooQ65+CM0UIsY2mI17 f+wHOOJlsKcsBoKdxfneqfAq0SMzLMspiMfSlWs02orpCNcnMdAx6Lsrh3o04ryHTJMS Afhh+PIIBDdEokxLBTDkCBc8c1E6cJ5bLkB67s0vf1JE6w2NRSFD1G3SqJyhOqc4cReB ib9kjr8XDeasbpcRYy91sSbGnKgUKil7yVByUY64vJARKxIktucDNUDE4oz8WEBi9yGZ GeMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=egjNRn/aJDxuv4PQNi+k4pGSCYAznrvvBpSH0Eh6LRU=; b=ON27+tK1xCy7tq1tvSmNRuBjhx0Y4EoDZr8a6YYL6wZgeAvJY9L3DRMScJxGZ89E4e TbyQfpZJrJIsjHUjXjGbaQewo1NWbH13BIqx4ePmq9h6/c2QDfr/qe5RN+5DOyJrwUwP QGmDrCP1Gl7yiMWUjzlkReSRGnJj5oK/q4lVLZGGkm8Ct9a7OVvgm6AcP9rsI0NTMScI nVhFMGUOe3riMvb7q3nc8nDjRQXI7Hwz3KwQ0V8ASnx61aIAHSeaV+m51mPnQmuGCePh G83die0Z2cmDmCl7IF9sKExcRRWZo07fxxmb7OB4zsFIqx1EvONuTWBv87UDmoOmNM01 Ys+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pIK20osH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 93si2443297edm.34.2020.11.09.05.48.12; Mon, 09 Nov 2020 05:48:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pIK20osH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730324AbgKINpC (ORCPT + 99 others); Mon, 9 Nov 2020 08:45:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:54436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730471AbgKINAS (ORCPT ); Mon, 9 Nov 2020 08:00:18 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C8763207BC; Mon, 9 Nov 2020 13:00:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604926817; bh=chF+2QcwmhwhuONQqb9eOn0GYA5ZJm1n4K2hP20r7lw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pIK20osHboYNpP8MdQ8iGI1ySwb7kOqJ/+euRZYR8pIqogdqoXYRF4eSZDI8X0+e4 bD+8e+ipE2RpXSKfdLDqRchFh8mH3OSrX2jQfYl2e1j23trcu4I6SV5B3zdhsqwqL9 lt3LcAXnJ1fKCSTwF+TG6IFHp+Aul/FMAcnxaBQg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephane Eranian , Kim Phillips , "Peter Zijlstra (Intel)" Subject: [PATCH 4.9 007/117] arch/x86/amd/ibs: Fix re-arming IBS Fetch Date: Mon, 9 Nov 2020 13:53:53 +0100 Message-Id: <20201109125025.992020322@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125025.630721781@linuxfoundation.org> References: <20201109125025.630721781@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kim Phillips commit 221bfce5ebbdf72ff08b3bf2510ae81058ee568b upstream. Stephane Eranian found a bug in that IBS' current Fetch counter was not being reset when the driver would write the new value to clear it along with the enable bit set, and found that adding an MSR write that would first disable IBS Fetch would make IBS Fetch reset its current count. Indeed, the PPR for AMD Family 17h Model 31h B0 55803 Rev 0.54 - Sep 12, 2019 states "The periodic fetch counter is set to IbsFetchCnt [...] when IbsFetchEn is changed from 0 to 1." Explicitly set IbsFetchEn to 0 and then to 1 when re-enabling IBS Fetch, so the driver properly resets the internal counter to 0 and IBS Fetch starts counting again. A family 15h machine tested does not have this problem, and the extra wrmsr is also not needed on Family 19h, so only do the extra wrmsr on families 16h through 18h. Reported-by: Stephane Eranian Signed-off-by: Kim Phillips [peterz: optimized] Signed-off-by: Peter Zijlstra (Intel) Cc: stable@vger.kernel.org Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537 Signed-off-by: Greg Kroah-Hartman --- arch/x86/events/amd/ibs.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -88,6 +88,7 @@ struct perf_ibs { u64 max_period; unsigned long offset_mask[1]; int offset_max; + unsigned int fetch_count_reset_broken : 1; struct cpu_perf_ibs __percpu *pcpu; struct attribute **format_attrs; @@ -374,7 +375,12 @@ perf_ibs_event_update(struct perf_ibs *p static inline void perf_ibs_enable_event(struct perf_ibs *perf_ibs, struct hw_perf_event *hwc, u64 config) { - wrmsrl(hwc->config_base, hwc->config | config | perf_ibs->enable_mask); + u64 tmp = hwc->config | config; + + if (perf_ibs->fetch_count_reset_broken) + wrmsrl(hwc->config_base, tmp & ~perf_ibs->enable_mask); + + wrmsrl(hwc->config_base, tmp | perf_ibs->enable_mask); } /* @@ -743,6 +749,13 @@ static __init void perf_event_ibs_init(v { struct attribute **attr = ibs_op_format_attrs; + /* + * Some chips fail to reset the fetch count when it is written; instead + * they need a 0-1 transition of IbsFetchEn. + */ + if (boot_cpu_data.x86 >= 0x16 && boot_cpu_data.x86 <= 0x18) + perf_ibs_fetch.fetch_count_reset_broken = 1; + perf_ibs_pmu_init(&perf_ibs_fetch, "ibs_fetch"); if (ibs_caps & IBS_CAPS_OPCNT) {