From patchwork Fri Jul 12 10:20:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13731585 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 AC1FBC3DA4A for ; Fri, 12 Jul 2024 10:25:01 +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=T+cqckU3PK/4oZg7w+6ZlVXIz08ibsuhvPsyHiAGTJU=; b=FeE8vCq+kEi9HJ2jq5TSX6MMks nlg939yWdqntAIiS3KzDajIKtIVorVpPQJJZMJEB/a9/yBtOG454iETLs+SgeV8GVO7POH4qZQRkA RuaH68mjanxfJncKf9hOCeaZf25allkntobm+Fcyt1hDdmUJr2FCoLJ71s1j3wTRjMpMGwA1p+j4L Vp/wIRm/cUgnIukdBGPKw5eyyq75T/o60KqozOJuYD8WKomNA2UolXeW8pnvS78oR1ILRvWCUvpqq Ytu0VIOW1EV3h1+dG78F1N82VyN38lfMCnafyWZS8xBQDKob7XE+TjrXtpGARTFYDkw5hd4v2dHu5 EK9vax+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sSDSO-0000000HIBP-2buJ; Fri, 12 Jul 2024 10:24:52 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sSDQN-0000000HHAz-36qM for linux-arm-kernel@lists.infradead.org; Fri, 12 Jul 2024 10:22:50 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-42679f33fefso12234665e9.2 for ; Fri, 12 Jul 2024 03:22:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720779766; x=1721384566; 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=T+cqckU3PK/4oZg7w+6ZlVXIz08ibsuhvPsyHiAGTJU=; b=Iu2Mcrqt8AZOrcz7jLPIM+tNMHa+1byUoK+MQpZDj79KGVaEq/2R1t7lg2q5giE4Ve dL4K+vUIxDNFaTR15DUuCj60ZiLT5BELXlM0gPFbm97XtCjpo820mNYAKQ2GcsugQ+Iw LCQBKjPidfRDwUHctR0q85vZzAv/Ozj0s9ZP3hxYqypRylQneXcBlXQ9gv9cRjp/+IsF gWv7jTou4k2ffwJD1bO/oVBmUTnygwdR4RpTdyiGBmDo6U9vMHWR4U14W1tERZ4IvrBP 23bDVlBOzK/BW1MLNXSXd01hO8mLOqsJGqyP7cihUNuKClvZeTMJPPysdg+LsOn0APFC Beng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720779766; x=1721384566; 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=T+cqckU3PK/4oZg7w+6ZlVXIz08ibsuhvPsyHiAGTJU=; b=Rx5QKxebxTW6oKsJGuV3VT/ZpxmvelguAx/E3tlIVsXk7jS6100P9/vHHISY15qT4K 5VDW3f9CCcT0wgIqm8ZTGAx16IMMS/2gdcPvdbCz0P5DE+Rf0PzBeYoFVqNRRq+IduID QDnbZkPNvY/D/Wtayy+vbMoOnllrN7A99m9ETfilDodl+1zr785O65fOGi/m7LdNcV15 KdHDuTeMSyfvPaZf4vjWEhxxeq/rtdFnp7fX4XEpE4pMWRENY8TaXhyWYtABPiOOFalr y+ZlryXa/gYxnx3dpXld0YurhWj97BQtTeMD7uGa1PN+3goEUoUFPJoVFjX8pjTpGBnj SSYw== X-Forwarded-Encrypted: i=1; AJvYcCVzt5QohRn114NCiPDPDu4BTgcfeKvfgyFQ0iJjACrNHkmkF3YP0pNGjVmf/KFBPE230aHcFKdaa7P9MaA/F1saSdMvSJznus0p85BGAqUh0ZkLx40= X-Gm-Message-State: AOJu0Yxv2JKQdrfw9EOijsVD7ny86gOAgqtFZBS3KU4IEdjo7/B0C0SR NYk0DMUoYuXT/nF5oUdBxqi9bdgq320MurxfYBM3XdfOA2GfrEvmD6NpbPy0atA= X-Google-Smtp-Source: AGHT+IE+VB3WvOca9zdDx6Lys780musKRQG8QOG3x0Z34w+FsYxwd3eo3DXVQhPIsbF9WOcbW4gGhg== X-Received: by 2002:a5d:588d:0:b0:367:f2ea:13e4 with SMTP id ffacd0b85a97d-367f2ea15eamr3674929f8f.32.1720779766060; Fri, 12 Jul 2024 03:22:46 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367cde89164sm9911058f8f.63.2024.07.12.03.22.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jul 2024 03:22:45 -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 v5 08/17] perf: cs-etm: Add runtime version check for OpenCSD Date: Fri, 12 Jul 2024 11:20:17 +0100 Message-Id: <20240712102029.3697965-9-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240712102029.3697965-1-james.clark@linaro.org> References: <20240712102029.3697965-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-20240712_032247_812770_EBC8AEE5 X-CRM114-Status: GOOD ( 22.31 ) 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 Signed-off-by: James Clark Reviewed-by: Mike Leach --- 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 49fadf46f42b..2385d5ed5ea5 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -3369,6 +3369,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;