From patchwork Mon Jul 15 16:07:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 13733624 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 38659C3DA4B for ; Mon, 15 Jul 2024 16:08:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=cCev9GneZm/To8gYz2rn8LrUNxoNAbTR3nqhMcXfRRc=; b=XA8IKLdwAkXyeY9ni6RfhDBkuj 42w5oGYINLkFILTzpr0tgGykQUTJ4d3r7CwIK2Q+ya16+Fu8oFAjMWtmPkUvRbrqVQQVW9n5BvQ6M HKyHgkLzc0gtgVLTK2S40Gmi7BhlbXU0lgmmufX8MDxTEAWFnfyQaK5dQVHvdouk88DdO/MyMjkq/ LKRxWHpvkIkRZDpvyzH2ZeCrjFU0pcADeR/BcJEWziUJPZ30rW9cAi//XGRzn4E9NtyjsXNlb6K5L 1XA4W+eqVltyEvSKI5LULzf8oV+hIQ6hJT5pWsgDxXhd+HkONeSMf8gojh2svc8lA2rf5Sn0PBOxl /PnqZGVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sTOFF-00000007etj-203S; Mon, 15 Jul 2024 16:08:09 +0000 Received: from mgamail.intel.com ([192.198.163.13]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sTOEf-00000007eek-2iKu for linux-arm-kernel@lists.infradead.org; Mon, 15 Jul 2024 16:07:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1721059653; x=1752595653; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Sws7f9Vo49jdmhQbNZDTC7ZNdMCwPwHbF7VqYoaZz+g=; b=NB7PWPFS7c5KhHqMWhumEBCMqI4LRyrorBZIjsWwNmP2YaJ/F7youvoe rxNhWnU+5ZOynMY70aDsk576NZEQb57YYvAbYPul7WjRjdggjHmzNJIVM 7fDmD3ykHBuoAc+IDUHWnwfOewJVFtJmeKtQt8AgCRO6QJQ2bjC8cxc5U GcoNwPlmClYthJkpqf/fN6CI+LFHqbeXxcGn+B7aP72fUdNfLv9MpdIMk +DCQmPc6DTvuAzrO9gdO9mPfXPt1yuwvwDespmOLEwdQ+/CxYpGBT73FT 8j3cjN06nM7T+yQEqTOHU6PiJsJ64T/3EYqsDlUz9MZEfc+29SkvO3u2e g==; X-CSE-ConnectionGUID: S4C7IwVTQsSyLW1pZyMeIQ== X-CSE-MsgGUID: uQcC3C1eQ+qkvRQZ4WWSVg== X-IronPort-AV: E=McAfee;i="6700,10204,11134"; a="21361108" X-IronPort-AV: E=Sophos;i="6.09,210,1716274800"; d="scan'208";a="21361108" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jul 2024 09:07:33 -0700 X-CSE-ConnectionGUID: dZT8mAPQT5y9zf0gTjYJBg== X-CSE-MsgGUID: 065qeGZMRZenPeuhJD/43A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,210,1716274800"; d="scan'208";a="49413493" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO localhost.localdomain) ([10.246.49.253]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jul 2024 09:07:27 -0700 From: Adrian Hunter To: Peter Zijlstra Cc: Ingo Molnar , Mark Rutland , Alexander Shishkin , Heiko Carstens , Thomas Richter , Hendrik Brueckner , Suzuki K Poulose , Mike Leach , James Clark , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Yicong Yang , Jonathan Cameron , Will Deacon , Arnaldo Carvalho de Melo , Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH V9 01/13] perf/x86/intel/pt: Fix sampling synchronization Date: Mon, 15 Jul 2024 19:07:00 +0300 Message-Id: <20240715160712.127117-2-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240715160712.127117-1-adrian.hunter@intel.com> References: <20240715160712.127117-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240715_090733_724125_D06E9C05 X-CRM114-Status: GOOD ( 14.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org pt_event_snapshot_aux() uses pt->handle_nmi to determine if tracing needs to be stopped, however tracing can still be going because pt->handle_nmi is set to zero before tracing is stopped in pt_event_stop, whereas pt_event_snapshot_aux() requires that tracing must be stopped in order to copy a sample of trace from the buffer. Instead call pt_config_stop() always, which anyway checks config for RTIT_CTL_TRACEEN and does nothing if it is already clear. Note pt_event_snapshot_aux() can continue to use pt->handle_nmi to determine if the trace needs to be restarted afterwards. Fixes: 25e8920b301c ("perf/x86/intel/pt: Add sampling support") Cc: stable@vger.kernel.org Signed-off-by: Adrian Hunter --- Changes in V9: New patch arch/x86/events/intel/pt.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c index 14db6d9d318b..6aaa21729589 100644 --- a/arch/x86/events/intel/pt.c +++ b/arch/x86/events/intel/pt.c @@ -1606,6 +1606,7 @@ static void pt_event_stop(struct perf_event *event, int mode) * see comment in intel_pt_interrupt(). */ WRITE_ONCE(pt->handle_nmi, 0); + barrier(); pt_config_stop(event); @@ -1657,11 +1658,10 @@ static long pt_event_snapshot_aux(struct perf_event *event, return 0; /* - * Here, handle_nmi tells us if the tracing is on + * There is no PT interrupt in this mode, so stop the trace and it will + * remain stopped while the buffer is copied. */ - if (READ_ONCE(pt->handle_nmi)) - pt_config_stop(event); - + pt_config_stop(event); pt_read_offset(buf); pt_update_head(pt); @@ -1673,11 +1673,10 @@ static long pt_event_snapshot_aux(struct perf_event *event, ret = perf_output_copy_aux(&pt->handle, handle, from, to); /* - * If the tracing was on when we turned up, restart it. - * Compiler barrier not needed as we couldn't have been - * preempted by anything that touches pt->handle_nmi. + * Here, handle_nmi tells us if the tracing was on. + * If the tracing was on, restart it. */ - if (pt->handle_nmi) + if (READ_ONCE(pt->handle_nmi)) pt_config_start(event); return ret;