Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1981772pxx; Sat, 31 Oct 2020 04:45:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKKXnfHz4dqsnhYKD/zL+MY95/aHrVQVM1iV/9MMDYaqewnOyPTFX2kuF4uxkS0Jg7i0HZ X-Received: by 2002:a05:6402:b35:: with SMTP id bo21mr7470001edb.52.1604144743084; Sat, 31 Oct 2020 04:45:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604144743; cv=none; d=google.com; s=arc-20160816; b=eg+IRob1ERB2Gv1b5KvlAb+idRg4YaKJw5BTwWhbUy2empy8zZ7u9T4nSzDMbV09oJ trTp1SDyKUYxcE/aae4zwRosPmkOd82+WuTYeYCiTLQ9H5zso0pkFrrHVHUltDUp+wni 00S+IgK/1UqcNACRZzg9Dwtc8bakL+QGeeawdaSFNwtaxKzs469j2NRPWEMpoPXzF+B5 5zfgoi3IUK6MxFC845vFMqYt5JeQroxVhmGpHgGzJBtUlFzxcvsVvikpj7zooqqjoxbd p1WXt592ZsAUKGmB9If1/YVOV8ACxa7qWwjWtG4kfMSVs3X6ANQ2W1gHorunI2xzT/nc 3HBw== 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=Y6pkQRFRNlmtE+30IjyfpLUXoqq0IIGgJ03FN/D2BoI=; b=YVRo3y+qlpTlEDjXjD+t8Hq7rN5ZfoFfIvzgwad6DfAv81cEXTR81e9AuxB7p99PUU saklJWbps+NcprqyW4BPeuWe2Q5FHEiQHcwh5VkDu2TJiSL2sZb1mjZ7IX61FK0zLUAA b/tR+6wWubbQ7bWYPwuCvPKI5+aDUp5p3QKZy4XrqmzcdMZVgm5DrbgL6qWG27hb9VHF Q2SCnDhKnq9h3yxeq5lmJ/JG0swWLR8dcO2tc4SFcBWIEV0vKlXjt4/f61TtXAmH8K97 eK6IL7sEZKRAqF1AGRUOBcr+sFTgXKeD+u+DZMne64VlIWCROkOuHbYs681a3N5DptQC adCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oEDNzVnw; 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 h22si6612505edq.32.2020.10.31.04.45.20; Sat, 31 Oct 2020 04:45:43 -0700 (PDT) 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=oEDNzVnw; 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 S1727821AbgJaLmJ (ORCPT + 99 others); Sat, 31 Oct 2020 07:42:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:41482 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727810AbgJaLmF (ORCPT ); Sat, 31 Oct 2020 07:42:05 -0400 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 9BDDA20731; Sat, 31 Oct 2020 11:42:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604144525; bh=ELnbaPvLmgekO9zPLjNiFxIvLeYzSV+8Djt2I6YDpOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oEDNzVnwwilKyB8wkEWka0lnIY93lV7T3huUlePQ+WaR0LWbRDpB1LPpaD3RfSVxs qBFMIQ5xg/s75xLURf1/fLI09E07aK1wdwj3r1z2gZyDVj1Tt+MFCRbZ7sVsnCyL+A FF+rLmWam2vrXJVy5Y8js5Xh1/Iyc3uJLEjZ0hDQ= 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 5.8 50/70] arch/x86/amd/ibs: Fix re-arming IBS Fetch Date: Sat, 31 Oct 2020 12:36:22 +0100 Message-Id: <20201031113501.896701678@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201031113459.481803250@linuxfoundation.org> References: <20201031113459.481803250@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; @@ -363,7 +364,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); } /* @@ -733,6 +739,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) {