Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932991AbbKFOb7 (ORCPT ); Fri, 6 Nov 2015 09:31:59 -0500 Received: from m12-17.163.com ([220.181.12.17]:56605 "EHLO m12-17.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750800AbbKFOb5 convert rfc822-to-8bit (ORCPT ); Fri, 6 Nov 2015 09:31:57 -0500 Content-Type: text/plain; charset=gb2312 Mime-Version: 1.0 (1.0) Subject: Re: [PATCH] perf symbols/KCORE: Rebuild rbtree when adjusting symbols for kcore From: pi3orama X-Mailer: iPhone Mail (13B143) In-Reply-To: <563CB241.2090701@intel.com> Date: Fri, 6 Nov 2015 22:31:05 +0800 Cc: Arnaldo Carvalho de Melo , Wang Nan , namhyung@kernel.org, lizefan@huawei.com, linux-kernel@vger.kernel.org, jolsa@kernel.org, masami.hiramatsu.pt@hitachi.com Content-Transfer-Encoding: 8BIT Message-Id: <186B4EF0-539A-4F15-AAAD-BD73C6C035C8@163.com> References: <1446803172-83107-1-git-send-email-wangnan0@huawei.com> <20151106131950.GA13236@kernel.org> <563CB241.2090701@intel.com> To: Adrian Hunter X-CM-TRANSID: EcCowAC3PaaquTxWBu6CFQ--.30646S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxAF45Xw1DtF1DCFWDGrWxJFb_yoW5uw17p3 yUGay5CF4kJr1jg3WxJw40vFZI9rn2qF4fZr18JFWF9anFvr17ZFyxCFyFkF98XrykK3W5 Zws29ryq9F9aqrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jeOJ5UUUUU= X-Originating-IP: [223.104.38.48] X-CM-SenderInfo: lslt02xdpdqiywtou0bp/1tbiXwuqQFWBPZNjqgAAsN Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3982 Lines: 116 ?????ҵ? iPhone > ?? 2015??11??6?գ?????9:59??Adrian Hunter д???? > >> On 06/11/15 15:19, Arnaldo Carvalho de Melo wrote: >> Em Fri, Nov 06, 2015 at 09:46:12AM +0000, Wang Nan escreveu: >>> In dso__split_kallsyms_for_kcore(), current code adjusts symbol's >>> address but only reinsert it into rbtree if the symbol belongs to >>> another map. However, the expression for adjusting symbol (pos->start -= >>> curr_map->start - curr_map->pgoff) can change the relative order between >>> two symbols (even if the affected symbols are in different maps, in >>> kcore case they are possible to share one same dso), which damages the >>> rbtree. >> >> Right, some code does change the symbol values it gets from whatever >> symtab (kallsyms, ELF, JIT maps, etc) when it should instead use the per >> map data structure (struct map) and its ->{map,unmap}_ip, ->pgoff, >> ->reloc, members for that :-\ >> >> I.e. 'struct dso' should be just what comes from the symtab, while >> 'struct map' should be about where that DSO is in memory. >> >> With that in mind, do you still think your fix is the correct one? >> >> Adrian? > > The problem is when the order in memory (in kallsyms) is different > to the order on the dso (kcore). > > I think to make it more general it needs to insert to a new tree. > e.g. > Thanks to your quick reply, but I have left my office and won't have time and environment to test your patch until next Wednesday. Is it possible for you to test it for yourself? Thank you. > > diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c > index b4cc7662677e..09343a880c0b 100644 > --- a/tools/perf/util/symbol.c > +++ b/tools/perf/util/symbol.c > @@ -654,19 +654,24 @@ static int dso__split_kallsyms_for_kcore(struct dso *dso, struct map *map, > struct map_groups *kmaps = map__kmaps(map); > struct map *curr_map; > struct symbol *pos; > - int count = 0, moved = 0; > + int count = 0; > + struct rb_root old_root = dso->symbols[map->type]; > struct rb_root *root = &dso->symbols[map->type]; > struct rb_node *next = rb_first(root); > > if (!kmaps) > return -1; > > + *root = RB_ROOT; > + > while (next) { > char *module; > > pos = rb_entry(next, struct symbol, rb_node); > next = rb_next(&pos->rb_node); > > + rb_erase_init(&pos->rb_node, &old_root); > + > module = strchr(pos->name, '\t'); > if (module) > *module = '\0'; > @@ -674,28 +679,21 @@ static int dso__split_kallsyms_for_kcore(struct dso *dso, struct map *map, > curr_map = map_groups__find(kmaps, map->type, pos->start); > > if (!curr_map || (filter && filter(curr_map, pos))) { > - rb_erase_init(&pos->rb_node, root); > symbol__delete(pos); > - } else { > - pos->start -= curr_map->start - curr_map->pgoff; > - if (pos->end) > - pos->end -= curr_map->start - curr_map->pgoff; > - if (curr_map->dso != map->dso) { > - rb_erase_init(&pos->rb_node, root); > - symbols__insert( > - &curr_map->dso->symbols[curr_map->type], > - pos); > - ++moved; > - } else { > - ++count; > - } > + continue; > } > + > + pos->start -= curr_map->start - curr_map->pgoff; > + if (pos->end) > + pos->end -= curr_map->start - curr_map->pgoff; > + symbols__insert(&curr_map->dso->symbols[curr_map->type], pos); > + ++count; > } > > /* Symbols have been adjusted */ > dso->adjust_symbols = 1; > > - return count + moved; > + return count; > } > > /* > -- 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/