Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752753AbbFQIqj (ORCPT ); Wed, 17 Jun 2015 04:46:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60845 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750838AbbFQIqa (ORCPT ); Wed, 17 Jun 2015 04:46:30 -0400 Date: Wed, 17 Jun 2015 10:46:16 +0200 From: Jiri Olsa To: Wang Nan Cc: acme@kernel.org, namhyung@kernel.org, masami.hiramatsu.pt@hitachi.com, a.p.zijlstra@chello.nl, mingo@redhat.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, pi3orama@163.com, lizefan@huawei.com Subject: Re: [PATCH] perf tools: Fix a problem when opening old perf.data with different byte order Message-ID: <20150617084616.GA8535@krava.redhat.com> References: <1434512442-41542-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1434512442-41542-1-git-send-email-wangnan0@huawei.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1833 Lines: 62 On Wed, Jun 17, 2015 at 03:40:42AM +0000, Wang Nan wrote: > Following error occurs when trying to use 'perf report' on x86_64 to > cross analysis a perf.data generated by an old perf on a big-endian > machine: > SNIP > - attr->branch_sample_type = bswap_64(attr->branch_sample_type); > - attr->sample_regs_user = bswap_64(attr->sample_regs_user); > - attr->sample_stack_user = bswap_32(attr->sample_stack_user); > - attr->aux_watermark = bswap_32(attr->aux_watermark); > - > - swap_bitfield((u8 *) (&attr->read_format + 1), sizeof(u64)); > +#define bswap_safe(f) \ > + (attr->size > offsetof(struct perf_event_attr, f)) > +#define bswap_field(f, sz) \ > +do { \ > + if (bswap_safe(f)) \ > + attr->f = bswap_##sz(attr->f); \ > +} while(0) > +#define bswap_field_32(f) bswap_field(f, 32) > +#define bswap_field_64(f) bswap_field(f, 64) all macros are function specific, please undef them at the bottom > + > + bswap_field_64(config); > + bswap_field_64(sample_period); > + bswap_field_64(sample_type); > + bswap_field_64(read_format); > + bswap_field_32(wakeup_events); > + bswap_field_32(bp_type); > + bswap_field_64(bp_addr); > + bswap_field_64(bp_len); > + bswap_field_64(branch_sample_type); > + bswap_field_64(sample_regs_user); > + bswap_field_32(sample_stack_user); > + bswap_field_32(aux_watermark); > + > + if (bswap_safe(read_format)) should this check for 'read_format + 1' ? jirka > + swap_bitfield((u8 *) (&attr->read_format + 1), > + sizeof(u64)); > } > > static void perf_event__hdr_attr_swap(union perf_event *event, > -- > 1.8.3.4 > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/