Received: by 2002:a05:6622:f08:0:0:0:0 with SMTP id l8csp4488936ivc; Tue, 3 Nov 2020 13:23:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJzY0BbBKZVPfGWGQ7SmM7d64Z5Yf74n6MUUDBFKdW9N/o1MslBVYNS/R4nfYpd3RGVdXXBP X-Received: by 2002:aa7:d408:: with SMTP id z8mr16158129edq.166.1604438586272; Tue, 03 Nov 2020 13:23:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604438586; cv=none; d=google.com; s=arc-20160816; b=xfgBZxSeG+0UaQQWTZd4oCBO8fKwTc9gGUTwiScTODxeJq38g1ZXFrjS4I7lM/7pLe vxHfQCnpMbG4T7BdqZ7bpOSDt0DHqjlPEBFMxQFgA41dCHIJG7MXddxR2/ErA2MuHVpx scAnjahVnC+YwUT0nAdb9wzIGJiHHldFbGFtCW5fVZRSBhIaclXTvQYdwtcY7DRKvGk8 4e6/hatvFO2WOqFcA79s22+Ov7CKca+Uy5KQkJh7Ba+mHMSyK4lhiB3UAhyjg8L7Vv62 FrD2te4sCh4f3yR3SUFwzZD6479agpyAKjWNP4NZ/whQF9SVI5DabtKewbOhVYjyVLCT w5+A== 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=MvOf1D026b43Q6CSsP6KMde8LZ828Y7lkC/VxNOhTpE=; b=KItYg8d1rQn3cagg13UP3T2ViMATk6q7V1RNwtzU2U21isPxqBH9oRQ6vegNgofhqi 171NfBac/cnHr5OUeHuBQgclFcwQEP8LWsvuTJiRbJ4Us9L/WjWO4XGFUEepEf4tZAwX b1i0QPLMs6zzFYt2cGUEjwrc5OK+Hoc20FvHwXsvb6LDbpu5nyH31aU7xGRhYMOehHkD 0G76ZQky0DwODgTvYEQ9+aJN8heOQw75F0Afj3VG70cHh6Q7MkIshq20ZzscFGkQvRag vrru9ORfimlILBO4X1OLWr/ycHE3wzBbBXo04fFBiniUVsueftFgI5STdTdQZAlK4stj FFwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wmYNt2a1; 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 p10si14528ejy.70.2020.11.03.13.22.42; Tue, 03 Nov 2020 13:23:06 -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=wmYNt2a1; 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 S2388517AbgKCVJ1 (ORCPT + 99 others); Tue, 3 Nov 2020 16:09:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:49478 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388503AbgKCVJ0 (ORCPT ); Tue, 3 Nov 2020 16:09:26 -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 5BDF9205ED; Tue, 3 Nov 2020 21:09:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437765; bh=CecjKyAvlWAKQTtQf0iP9h9WYD6bopjVvK0S3YdEjJU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wmYNt2a1IaHFxJqla5fDLsBHDch2CgM/7JKGLAMGhD7NMrSe+2ldSk+/xsSpOmAyj Hs0lapV2I5YaPcTU01r7zV5aAb/G7Oops7Zjlss1xufE1rYo6xegeZySmp0E3B5e92 r6p9v4123iAS/KL/mw1YGDmui4e+LXD8y7KRD6/s= 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.14 007/125] arch/x86/amd/ibs: Fix re-arming IBS Fetch Date: Tue, 3 Nov 2020 21:36:24 +0100 Message-Id: <20201103203157.802882607@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203156.372184213@linuxfoundation.org> References: <20201103203156.372184213@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 @@ -89,6 +89,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; @@ -375,7 +376,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); } /* @@ -744,6 +750,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) {