From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753284AbbIRNp5 (ORCPT ); Fri, 18 Sep 2015 09:45:57 -0400 Received: from smtprelay0208.hostedemail.com ([216.40.44.208]:53712 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752741AbbIRNpz (ORCPT ); Fri, 18 Sep 2015 09:45:55 -0400 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::::::,RULES_HIT:41:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:1801:2393:2553:2559:2562:2693:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3870:3871:3872:3874:4321:4605:5007:6119:6120:6261:7809:7875:7901:7903:8603:8784:9036:9040:10004:10400:10450:10455:10848:10967:11232:11658:11914:12296:12517:12519:12555:12740:13019:13138:13160:13161:13184:13229:13231:13255:14096:14097:19904:19999:21080:21088,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0 X-HE-Tag: bit20_8ac4688605b60 X-Filterd-Recvd-Size: 3222 Date: Fri, 18 Sep 2015 09:45:52 -0400 From: Steven Rostedt To: Kapileshwar Singh Cc: Namhyung Kim , "linux-kernel@vger.kernel.org" , Arnaldo Carvalho de Melo , Javi Merino , David Ahern , Jiri Olsa Subject: Re: [PATCH] tools lib traceevent: Mask higher bits of str addresses for 32-bit traces Message-ID: <20150918094552.0c2d3a5b@gandalf.local.home> In-Reply-To: <55FBEDB3.3030705@arm.com> References: <1442488476-15366-1-git-send-email-kapileshwar.singh@arm.com> <20150917091154.575d031f@gandalf.local.home> <55FAD512.5030206@arm.com> <55FBEDB3.3030705@arm.com> X-Mailer: Claws Mail 3.12.0 (GTK+ 2.24.28; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 18 Sep 2015 11:55:47 +0100 Kapileshwar Singh wrote: > >>> Perhaps we need to make addr into a unsigned long long, and then add: > >>> > >>> addr = (pevent->long_size == 8) ? > >>> *(unsigned long long *)(data + field->offset) : > >>> (unsigned long long )*(unsigned int *)(data + field->offset); > > > > What about this? (untested) > > > > addr = *(uint64_t *)(data + field->offset) & > > ((1ULL << pevent->long_size * 8) - 1); > > I tested this and it works fine. Except that I think it may be buggy. > > > > > Do we also need to consider byte endians? Maybe it'd be better adding > > a helper to dereference pointers then.. Yes and no. > > In this particular case, since the address is just a key for a lookup into the > printk_map, which seems like a (addr -> const char *) mapping for string > literals in the trace file, the endian-ness should not matter (I could be wrong though). Correct, which is why I said "no", BUT! this is why I think Namhyung's version may be buggy (besides the overflow of the buffer). If this is a 64 bit big endian reading a 32 bit little endian file, I think the result will be incorrect. The *(uint64_t *) will return a 64bit number, but the address (with long_size == 4) only needs 32bits. Thus, we are getting 32 more bits than needed. Let's say the address is 0x12345678 that is loaded in the file. Being little endian, it would be loaded as "78 56 34 12". Let's say the 32bits after that is 0xDEADBEEF, loaded as "EF BE AD DE". Now the number returned to addr (being a 64 bit big endian) would be: 0x785643412EFBEADDE But then we do the shift: (1ULL << pevent->long_size * 8) - 1; which would leave us with: 0xEFBEADDE Not what we wanted. My version only reads the necessary bytes, and also wont suffer from reading past the data size of the buffer (which is another bug). -- Steve