From patchwork Mon Jul 22 10:11:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13738639 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 A57DCC3DA59 for ; Mon, 22 Jul 2024 10:16:10 +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=sPkIquw077gYIEvctFCCllwMLWJh43EU4ppM2MPUVYk=; b=4pmQHyoRL8ZzxoG9xPXUYQZRv9 ui9I/QFBgZPrOY8vXaXLGtwqYxyxTUf3318J5lCudZrbMxhNeZo6c1yuSgAe8LiunZiHAdVbac68I LWXpS/2ombUPoLXBUMeUKwym3lR0XUvHUGhfEDQvwDK9mJeRJzmAUau3TeJO4Xl9dHwKzy2a1qvsG JCMSLwcWSpGg5rxqoVYU74ddz6h2+dat+blfjbEHAyTp8QL0F0HiSxKFqcSgufZqJQdKS+Cmk3Np7 Pt9U2BJD3Z0ypcojRCZHnECZh6IVbhO/aqu2muSRQfi65RyHr9sUhIqZuTYSKlOM6Oj9uYof0+S32 +A/jM3iQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sVq5I-00000009DPJ-21E6; Mon, 22 Jul 2024 10:16:00 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sVq2X-00000009CLL-18gF for linux-arm-kernel@lists.infradead.org; Mon, 22 Jul 2024 10:13:10 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4279c924ca7so29732305e9.2 for ; Mon, 22 Jul 2024 03:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721643188; x=1722247988; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sPkIquw077gYIEvctFCCllwMLWJh43EU4ppM2MPUVYk=; b=bvbfbK85PL1a3mxOFpyApONj9+obtNmQoBYaKf6cewTo2yowV4SjtGhZnO29NHCiqp kD4e8w+ReDppTNd/Fp/kaIo/rwpXshbEjnK+yaH4yZzAUcdYWvjtfeRTTpca4pm04UwS wq/8Lun04goV2bGaZXroYC3IC9rFbfHN114KU6lM3PMIHPxyRETbgrRjx8pUAIa/Uiw2 0QheHGaKM+t8jPys1imxMXdWH2EE7Cwc2Tp9lNiP42iqsaGxCADkynO5xkCSmBAJJohj 7Uey2YYZmIeUG6ZvXs0sqHc9la8IWOsm+D5N3eoZN8PWZI9W93ReQTDDOxR5BDMlBSMz s7GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643188; x=1722247988; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sPkIquw077gYIEvctFCCllwMLWJh43EU4ppM2MPUVYk=; b=mTz5wfsxRT3YgmXUro+rhr5lycI67/7GLOA8UA9F4QrkcVzhQN0SIx0xk2BEpRPa8l l1HdD5JvCHzltpS3146s5GnfZnagarG/Hqjtq0a3zfLAIgaqBSe86/psuoZUoSEKAae6 9l87qJ8ghfzUMcHNVACDHjBT51HQrk6ASbF5gk06drWlumi377Vc60Q/Z0/VLBj0TqSE ftVJQSvf3O7swW0sCIiE9NPESM0bXrjYQgbxPTuEFggaI5c4ZkdPElQvx4u/PAeipCFm 4nFr/s8u6WVAj6Xf5ydk12lLM0x3AdIrG/tmllL2U2ir0VDv24t6gz7IcEoGYltKhvwB mQvw== X-Forwarded-Encrypted: i=1; AJvYcCXFAcNlCQOIGF/uREQEeexnr3tPgKrUSMc9ZJMf7CLXD6AKccWlDc7fEJszeChogOybVNy8HLHeWjPOO9Gljc6bjzwurAOPcz85IGqTEfyBKgdjrkw= X-Gm-Message-State: AOJu0Yx0ZPyJCweh85To7fHq8koze133WfDdI/WyjYceY5RrfncZa7jN zkpE2tR5X/41otZ3wtkynC1MN0npx7cw1v0aTP5AF31ujE3qgc/aX2RzRcn5yas= X-Google-Smtp-Source: AGHT+IECJrbMk+SVuzf8P8M9gfHzpogypG1Je+ADnodsc8mmHRR3JgaHvZvv6i1KdtxQ2O7FGguNRw== X-Received: by 2002:a05:600c:524b:b0:426:6b85:bafb with SMTP id 5b1f17b1804b1-427dc529177mr44503555e9.20.1721643187954; Mon, 22 Jul 2024 03:13:07 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a8e436sm147993865e9.33.2024.07.22.03.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:13:07 -0700 (PDT) From: James Clark To: coresight@lists.linaro.org, suzuki.poulose@arm.com, gankulkarni@os.amperecomputing.com, mike.leach@linaro.org, leo.yan@linux.dev, anshuman.khandual@arm.com Cc: James Clark , James Clark , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-perf-users@vger.kernel.org Subject: [PATCH v6 08/17] perf: cs-etm: Add runtime version check for OpenCSD Date: Mon, 22 Jul 2024 11:11:50 +0100 Message-Id: <20240722101202.26915-9-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240722101202.26915-1-james.clark@linaro.org> References: <20240722101202.26915-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240722_031309_345072_A5103520 X-CRM114-Status: GOOD ( 22.35 ) 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 From: James Clark OpenCSD is dynamically linked so although there is a build time check, at runtime the user might still have the wrong version. To avoid hard to debug errors, add a runtime version check. Signed-off-by: James Clark Reviewed-by: Mike Leach Signed-off-by: James Clark --- tools/build/feature/test-libopencsd.c | 4 ++-- tools/perf/Makefile.config | 2 +- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 13 +++++++++++++ tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 1 + tools/perf/util/cs-etm-decoder/cs-etm-min-version.h | 13 +++++++++++++ tools/perf/util/cs-etm.c | 3 +++ 6 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 tools/perf/util/cs-etm-decoder/cs-etm-min-version.h diff --git a/tools/build/feature/test-libopencsd.c b/tools/build/feature/test-libopencsd.c index 4cfcef9da3e4..d092a0c662f4 100644 --- a/tools/build/feature/test-libopencsd.c +++ b/tools/build/feature/test-libopencsd.c @@ -1,12 +1,12 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include "cs-etm-decoder/cs-etm-min-version.h" /* * Check OpenCSD library version is sufficient to provide required features */ -#define OCSD_MIN_VER ((1 << 16) | (2 << 8) | (1)) #if !defined(OCSD_VER_NUM) || (OCSD_VER_NUM < OCSD_MIN_VER) -#error "OpenCSD >= 1.2.1 is required" +#error "OpenCSD minimum version (OCSD_MIN_VER) not met." #endif int main(void) diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index 7f1e016a9253..2d21be42820e 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -141,7 +141,7 @@ endif ifdef CSLIBS LIBOPENCSD_LDFLAGS := -L$(CSLIBS) endif -FEATURE_CHECK_CFLAGS-libopencsd := $(LIBOPENCSD_CFLAGS) +FEATURE_CHECK_CFLAGS-libopencsd := $(LIBOPENCSD_CFLAGS) -I$(src-perf)/util FEATURE_CHECK_LDFLAGS-libopencsd := $(LIBOPENCSD_LDFLAGS) $(OPENCSDLIBS) # for linking with debug library, run like: diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index b78ef0262135..5e1b4503aab1 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -16,6 +16,7 @@ #include "cs-etm.h" #include "cs-etm-decoder.h" +#include "cs-etm-min-version.h" #include "debug.h" #include "intlist.h" @@ -835,3 +836,15 @@ const char *cs_etm_decoder__get_name(struct cs_etm_decoder *decoder) { return decoder->decoder_name; } + +int cs_etm_decoder__check_ver(void) +{ + if (ocsd_get_version() < OCSD_MIN_VER) { + pr_err("OpenCSD >= %d.%d.%d is required\n", OCSD_MIN_MAJOR, + OCSD_MIN_MINOR, + OCSD_MIN_PATCH); + return -EINVAL; + } + + return 0; +} diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h index 12c782fa6db2..2ec426ee16dc 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -107,5 +107,6 @@ int cs_etm_decoder__get_packet(struct cs_etm_packet_queue *packet_queue, int cs_etm_decoder__reset(struct cs_etm_decoder *decoder); const char *cs_etm_decoder__get_name(struct cs_etm_decoder *decoder); +int cs_etm_decoder__check_ver(void); #endif /* INCLUDE__CS_ETM_DECODER_H__ */ diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-min-version.h b/tools/perf/util/cs-etm-decoder/cs-etm-min-version.h new file mode 100644 index 000000000000..c69597e9d0af --- /dev/null +++ b/tools/perf/util/cs-etm-decoder/cs-etm-min-version.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef INCLUDE__CS_ETM_MIN_VERSION_H__ +#define INCLUDE__CS_ETM_MIN_VERSION_H__ + +#define OCSD_MIN_MAJOR 1 +#define OCSD_MIN_MINOR 2 +#define OCSD_MIN_PATCH 1 + +#define OCSD_MIN_VER ((OCSD_MIN_MAJOR << 16) | \ + (OCSD_MIN_MINOR << 8) | \ + (OCSD_MIN_PATCH)) + +#endif /* INCLUDE__CS_ETM_MIN_VERSION_H__ */ diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 6298a5c7a651..3b4a5d5ca25b 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -3375,6 +3375,9 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event, u64 *ptr = NULL; u64 **metadata = NULL; + if (cs_etm_decoder__check_ver()) + return -EINVAL; + /* First the global part */ ptr = (u64 *) auxtrace_info->priv; num_cpu = ptr[CS_PMU_TYPE_CPUS] & 0xffffffff;