Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3522757pxa; Wed, 26 Aug 2020 02:44:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxq13WuYCTa2ooFPYotLO+3Q2hnGWGLihqT+YWVwamSCalyeQb8wajwbshMgVHw9WF5Y+2x X-Received: by 2002:a17:906:194e:: with SMTP id b14mr11589274eje.86.1598435046672; Wed, 26 Aug 2020 02:44:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598435046; cv=none; d=google.com; s=arc-20160816; b=cg0qkBnvtyE9A3HjxLifzjS2KRG9zrnCRKyp1A0R2/h2LJsW0bJAg54Px/uwF94W9u 151UNlIHH23r1mreTcTDJEVHAjY1ZPv3a/rwiwE0Uya/dKuhYLDueeNK7t5JlTv0FBuM xxgaH3lUU324i9ABEYBh8SPHfW2C1VUdA3znjKivBYdhvMYIQLg6oZD//B49wlsNXLT5 1H6I6rd1i4M5q1DEtw5b52m4BqmBM/svrI3HvL9HkDdQgiNaY8x0/srL/mTfUdFuON4e UZhfqLaNYI8vl9xdGg8ZIMLr/0KIv4VwzgIAymm/ohP+SaL7IeSnOmp6F2qRwHUIA0qv PbHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:subject :from:to; bh=ECkORUCLPV4Qvfbw8tqRj/1kfmWsz1zGnqV85AfOAUk=; b=TenFVX8t08L+eT/Hs/tfTeVe2aTsqnSDaO2vjj9eCk1yneBoiQcGnAfsR3aEAYMcnW ZDIsar8kaXFf7FoypiEPQVX1aH1ZXpMUFuu12e+strG/4vibSMfJ9+tPLcDfjmmyhlV1 jibBGUIym/56sD9vYhQ/3dSQUP96PXGAoorX8RdPkKYh0SiZfbSOMJJZ5lJbxpyim/BB dsaGEjdJDvOQB0JTWhORwsZONg4LbfH/9bzGmz2QJJb7hElRI42I5gwDx8ons3mr0tJB cLsyryOdNn9r8xOK0M9GKPihUOxR2OlU2Lt51rn2+7+mg4wLzRg9xVzruE86hioS+TJn 99Ig== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k10si1189018ejr.684.2020.08.26.02.43.44; Wed, 26 Aug 2020 02:44:06 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728259AbgHZJmG (ORCPT + 99 others); Wed, 26 Aug 2020 05:42:06 -0400 Received: from foss.arm.com ([217.140.110.172]:43552 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728002AbgHZJmG (ORCPT ); Wed, 26 Aug 2020 05:42:06 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9CFDA101E; Wed, 26 Aug 2020 02:42:05 -0700 (PDT) Received: from [10.57.5.66] (unknown [10.57.5.66]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1EDDB3F66B; Wed, 26 Aug 2020 02:42:05 -0700 (PDT) To: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, acme@redhat.com From: Al Grant Subject: [PATCH] perf inject: correct event attribute sizes Message-ID: Date: Wed, 26 Aug 2020 10:42:04 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.0.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When perf inject reads a perf.data file from an older version of perf, it writes event attributes into the output with the original size field, but lays them out as if they had the size currently used. Readers see a corrupt file. Update the size field to match the layout. From: Denis Nikitin Signed-off-by: Al Grant tools/perf/util/header.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 9cf4efdcbbbd..762eb94bd532 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3326,6 +3326,14 @@ int perf_session__write_header(struct perf_session *session, attr_offset = lseek(ff.fd, 0, SEEK_CUR); evlist__for_each_entry(evlist, evsel) { + if (evsel->core.attr.size < sizeof(evsel->core.attr)) { + /* + * We are likely in "perf inject" and have read + * from an older file. Update attr size so that + * reader gets the right offset to the ids. + */ + evsel->core.attr.size = sizeof(evsel->core.attr); + } f_attr = (struct perf_file_attr){ .attr = evsel->core.attr, .ids = {