From nobody Sun Apr 26 08:21:06 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38AB0C43334 for ; Tue, 21 Jun 2022 15:27:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351811AbiFUP1l (ORCPT ); Tue, 21 Jun 2022 11:27:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235017AbiFUP1g (ORCPT ); Tue, 21 Jun 2022 11:27:36 -0400 Received: from mail-il1-x14a.google.com (mail-il1-x14a.google.com [IPv6:2607:f8b0:4864:20::14a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 223662A97B for ; Tue, 21 Jun 2022 08:27:35 -0700 (PDT) Received: by mail-il1-x14a.google.com with SMTP id w7-20020a056e021c8700b002d3bc8e95cbso9416012ill.3 for ; Tue, 21 Jun 2022 08:27:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=pJAAMlUR9Ydzb8Wli4Gr9USgcKMSCgzvdDTXVExWOBs=; b=qvMB8LoBpaFQ3GQUCSoTnXYGKUdpDLi2qS9fSWosgFZW6a9vh5vMNU1YdL3ai8VSFt BX8jS4oYUYceNUIdKCV4t5VtNX7ciKWxzBUVh7uoogjUG7nvpus5g7xx4STaT7Y1dVT+ xYYpueD6bCQPD3QgzWleZSHzHBVbVJpavqmsQiQdHu9PXOH9h0262IVju7GemWKC02N5 O+FHafG00jsVpcDQhEdjF4ehUJaXGe9DVYR44q1LKMY088VRjUAABKLdu8NIABYQLb0C Ae0SBv82idmUhns6AGaP+MIdZlQQ2nQQUAlFlh+O+klmpFaCCgAq2CYiZ1ffmeNAXpIA CI2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=pJAAMlUR9Ydzb8Wli4Gr9USgcKMSCgzvdDTXVExWOBs=; b=CyjjgCHPA/gQueQpdIAOPAfxdsEQlw44FveHxRc178DM9pzXaQ5DbCZlR2plQBwOyH Kb6DRbSHpneOFyhu2OAv4cFaDo9qr23F5RSctLdVScylyCUg8PVhysL6/ev4d9C/vrwL YDbaJmUvP4OqGHE/Gt6AdZNDUqbN/Q+MSAKqmB2QvPfEDmxy/wr8nwxqAOmiWHiypEHi Zhoebi8EP0VpPc2nD9p2U6Vqm+YL8S7o96HbnY4dj+J2x2qrewMX54PQwVa+T46Hc3Rg MJADVYxQiwRzj4Y/WhFOyZRgE1rO9VHZblL8spji26Sk0sO2QdyiHeIe8kZkphg0gMOB ooIA== X-Gm-Message-State: AJIora+NkcccB3Jf3fWebFgFz3Xprd3DMqInolnxCz6NKp5+2BJVJMcl 3fX5/CYAUq9asMOF9MrtJ1XIBJw+JgTvmA== X-Google-Smtp-Source: AGRyM1sxUjFEpBuJrnP39Ob4bVY8ckbZiuOog9KsddFGcK4Q2gPiLHpmQTwxlL016bzslu2xQYcvjIQqcGtHzQ== X-Received: from riochico.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:b3e]) (user=rsilvera job=sendgmr) by 2002:a02:ac02:0:b0:339:c83a:f6f3 with SMTP id a2-20020a02ac02000000b00339c83af6f3mr2553704jao.174.1655825254515; Tue, 21 Jun 2022 08:27:34 -0700 (PDT) Date: Tue, 21 Jun 2022 15:27:25 +0000 Message-Id: <20220621152725.2668041-1-rsilvera@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog Subject: [PATCH v2] perf: Adjust perf-inject output data offset for backward compatibility From: Raul Silvera To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Dave Marchevsky , Adrian Hunter , Colin Ian King , Athira Rajeev , Raul Silvera Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When perf inject creates a new file, it reuses the data offset from the input file. If there has been a change on the size of the header, as happened in v5.12 -> v5.13, the new offsets will be wrong, resulting in a corrupted output file. This change adds the function perf_session__data_offset to compute the data offset based on the current header size, and uses that instead of the offset from the original input file. Signed-off-by: Raul Silvera Acked-by: Adrian Hunter --- Changes since v1: - Use the adjusted header->data_offset in do_write_header instead of recomputing it. --- tools/perf/builtin-inject.c | 2 +- tools/perf/util/header.c | 14 ++++++++++++++ tools/perf/util/header.h | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index a75bf11585b5..1dfdcef36607 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -916,7 +916,7 @@ static int __cmd_inject(struct perf_inject *inject) inject->tool.tracing_data =3D perf_event__repipe_tracing_data; } =20 - output_data_offset =3D session->header.data_offset; + output_data_offset =3D perf_session__data_offset(session->evlist); =20 if (inject->build_id_all) { inject->tool.mmap =3D perf_event__repipe_buildid_mmap; diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 53332da100e8..6ad629db63b7 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3686,6 +3686,20 @@ int perf_session__write_header(struct perf_session *= session, return perf_session__do_write_header(session, evlist, fd, at_exit, NULL); } =20 +size_t perf_session__data_offset(const struct evlist *evlist) +{ + struct evsel *evsel; + size_t data_offset; + + data_offset =3D sizeof(struct perf_file_header); + evlist__for_each_entry(evlist, evsel) { + data_offset +=3D evsel->core.ids * sizeof(u64); + } + data_offset +=3D evlist->core.nr_entries * sizeof(struct perf_file_attr); + + return data_offset; +} + int perf_session__inject_header(struct perf_session *session, struct evlist *evlist, int fd, diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index 08563c1f1bff..56916dabce7b 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -136,6 +136,8 @@ int perf_session__inject_header(struct perf_session *se= ssion, int fd, struct feat_copier *fc); =20 +size_t perf_session__data_offset(const struct evlist *evlist); + void perf_header__set_feat(struct perf_header *header, int feat); void perf_header__clear_feat(struct perf_header *header, int feat); bool perf_header__has_feat(const struct perf_header *header, int feat); --=20 2.37.0.rc0.104.g0611611a94-goog