Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp796894pxb; Tue, 3 Nov 2020 12:48:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJzQ4NXxWAFqj01feJxWHrCjOm8wfs69IBf7RkVzQ6aDjlE7WZqIlOyf7hfAUOot3oj6nTkk X-Received: by 2002:a50:99c3:: with SMTP id n3mr23783363edb.213.1604436481522; Tue, 03 Nov 2020 12:48:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604436481; cv=none; d=google.com; s=arc-20160816; b=XEg4paumclYRQEBpwWB/hf+EngABg+8qwR9rL0slBBSIYEVzHWxNaXqcVbYd+AFEQv Rpn+SsDSA3SC6ciBCrR7cKfUjpEhNyfUPU7VvsDMepFRO8GmDSgPNc9Px2vjf3iY7C4T fDWxd+PBlkcIjNQg6x3v5q1dLZ0ZiwJtxK8iIpX3X4VhYt7U3i0bugWwUL+wUTmqMRrh qZgz7ZG6S1hUiS6mAzur5RaZgPK90lhuHsvHlu2abZnogJGdEQBJekY5IMYpD/hQ3lYS xEgbsAiRaM9Q8U45zmyPtwB65zz/ebWkVAhOcODlrCRNnE4Y0Y902awEdvxQFFNPmEcS o06Q== 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=6Ywp3SxVPfHoVybOPjCDWIjQVZEfjfXUDUhjZAuEvds=; b=daP55GBomOs4be3C98jJdLDBpDlN2uMgby9G+YGfg0KkvLDn/Rm7HtJgTZ0sA7Z5j9 0H8rpgR3U89A7KgXvPTRNGHqk0iCaBcJMrEIPxxFJ55sGI2bToc3WNQyPwbRJFTlv6Jt 1ktgQ0Gf/Rp12K4TIRbNcMQ4qdN3D+6hpFnhoapY0KEpA/WiW2AUPbYUhY/jypuyUhed aTsrpcC2uCSwI6QBsenZBzWZGIPDawZQ2IHE6oc3jbsPgZQvLP9UJE9G8+d4M6MKL8m6 R9fspsXYv75z453fSqevwxrLUklZ+am6GFQIs43cevqskNQzbvooZguZ/y32o4KMqyfs qWBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KeWcIIdy; 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 a2si7694303edn.504.2020.11.03.12.47.38; Tue, 03 Nov 2020 12:48:01 -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=KeWcIIdy; 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 S1730626AbgKCUpG (ORCPT + 99 others); Tue, 3 Nov 2020 15:45:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:32800 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730457AbgKCUpD (ORCPT ); Tue, 3 Nov 2020 15:45:03 -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 72134223C6; Tue, 3 Nov 2020 20:45:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436302; bh=shjCMavqrPKyGuQkpKOaFnclbdK2XatE+I1jQD1R5m8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KeWcIIdypIRuwqxvBXEskrbgjL34VNzNJu3A5+v4GBsbn8lC7cWxtugXA0Dqb8Dsu tFRuaVo5IcT1yACWUllqQFxPL6o5ITPi5V/gYHWkZeJ1mzpnPuVLsLiho1V0qvzt6p N8n1K3Qd9qGt8C6R4nhFkNiIKzxovdlTVGDw18fY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kim Phillips , "Peter Zijlstra (Intel)" Subject: [PATCH 5.9 192/391] perf/x86/amd: Fix sampling Large Increment per Cycle events Date: Tue, 3 Nov 2020 21:34:03 +0100 Message-Id: <20201103203359.845949104@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203348.153465465@linuxfoundation.org> References: <20201103203348.153465465@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 26e52558ead4b39c0e0fe7bf08f82f5a9777a412 upstream. Commit 5738891229a2 ("perf/x86/amd: Add support for Large Increment per Cycle Events") mistakenly zeroes the upper 16 bits of the count in set_period(). That's fine for counting with perf stat, but not sampling with perf record when only Large Increment events are being sampled. To enable sampling, we sign extend the upper 16 bits of the merged counter pair as described in the Family 17h PPRs: "Software wanting to preload a value to a merged counter pair writes the high-order 16-bit value to the low-order 16 bits of the odd counter and then writes the low-order 48-bit value to the even counter. Reading the even counter of the merged counter pair returns the full 64-bit value." Fixes: 5738891229a2 ("perf/x86/amd: Add support for Large Increment per Cycle Events") Signed-off-by: Kim Phillips 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/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -1286,11 +1286,11 @@ int x86_perf_event_set_period(struct per wrmsrl(hwc->event_base, (u64)(-left) & x86_pmu.cntval_mask); /* - * Clear the Merge event counter's upper 16 bits since + * Sign extend the Merge event counter's upper 16 bits since * we currently declare a 48-bit counter width */ if (is_counter_pair(hwc)) - wrmsrl(x86_pmu_event_addr(idx + 1), 0); + wrmsrl(x86_pmu_event_addr(idx + 1), 0xffff); /* * Due to erratum on certan cpu we need