Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3323399yba; Tue, 16 Apr 2019 09:03:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqwyODSh94adcp3jHqEumzjmn0xh4fN1pC5pL272RY03ATIz7aSg+Mj2/k/hubfQVW/zdfsQ X-Received: by 2002:a62:59cb:: with SMTP id k72mr84426588pfj.111.1555430632649; Tue, 16 Apr 2019 09:03:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555430632; cv=none; d=google.com; s=arc-20160816; b=E0TCAKwIlL3SE4UcHGw+oGdb1kJJZb4xhlj1H5Vnr2u4mYTgUkpJsXVQp5Mtw3U1cN r7GAk5tsghRSFKN7ZA5ckwUg3G2GmkWtbP0/QcLSNBGVywZxFzgUnaO1kkkX7nSaMPBX 3b+tyaG1U46KNEluTyliLzn/Dwo+r5kytFDB3rL1L9NN0dUMikcg4C1hPpiN9GvGMlK6 lKms9tfPXtZkFGC6d8gANRX9oDpIcnMMN1rZ8SMR/hFv9JKVW8Liq/2jFM96xuMBWiBR 3x+cPz/ra1VUyDioPotktUyO9wQtOa3FNqdICuzjtjFy2OVox16+onq0txOFCczdZ0s3 X9eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=BYK/5TNGNa/bUGtD5jJL86tG8xvOWrnoG14OC+DVi1w=; b=JxSguZiDxqsX6JZPkYuZBl4ztsv6tS+BURXnjclhvIFcO3aDEFqPQwRqSeF61ovhZ1 yD2AC2Ow+JvanMiRuLhElKCV6ydw1y+zrS/237I3oiZ2LoIXccBevAJZ1orUUuPqrYGi GwrY22E/xKY4z2VRxr29S/JExz6FrTblhDzMZgIZBLvNpNPT89cWmFs3R3dgI3SQhngj +nKjPHJmOPqqdlb4WmxB+FCcy+Iy+saZi3gPEuxycGu8plrVmMf9qR5zS8ZqRoS9xQZz 6GJBqJ23i+L4arl+uojLG/986iVZvEqiYEYCZSxnHpTh0gtyGmuGtSA/kyFLRmuXVMF9 aseQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k24si49787711pgf.294.2019.04.16.09.03.36; Tue, 16 Apr 2019 09:03:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730049AbfDPQCG (ORCPT + 99 others); Tue, 16 Apr 2019 12:02:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36308 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729984AbfDPQCD (ORCPT ); Tue, 16 Apr 2019 12:02:03 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 24AF95D60E; Tue, 16 Apr 2019 16:02:03 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1B9B5D71B; Tue, 16 Apr 2019 16:02:00 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Song Liu , lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Andi Kleen , Adrian Hunter , Alexei Starovoitov , Daniel Borkmann Subject: [PATCH 09/12] perf tools: Fix map reference counting Date: Tue, 16 Apr 2019 18:01:24 +0200 Message-Id: <20190416160127.30203-10-jolsa@kernel.org> In-Reply-To: <20190416160127.30203-1-jolsa@kernel.org> References: <20190416160127.30203-1-jolsa@kernel.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 16 Apr 2019 16:02:03 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org By calling maps__insert we assume to get 2 references on the map, which we relese within maps__remove call. However if there's already same map name, we currently don't bump the reference and can crash, like: Program received signal SIGABRT, Aborted. 0x00007ffff75e60f5 in raise () from /lib64/libc.so.6 (gdb) bt #0 0x00007ffff75e60f5 in raise () from /lib64/libc.so.6 #1 0x00007ffff75d0895 in abort () from /lib64/libc.so.6 #2 0x00007ffff75d0769 in __assert_fail_base.cold () from /lib64/libc.so.6 #3 0x00007ffff75de596 in __assert_fail () from /lib64/libc.so.6 #4 0x00000000004fc006 in refcount_sub_and_test (i=1, r=0x1224e88) at tools/include/linux/refcount.h:131 #5 refcount_dec_and_test (r=0x1224e88) at tools/include/linux/refcount.h:148 #6 map__put (map=0x1224df0) at util/map.c:299 #7 0x00000000004fdb95 in __maps__remove (map=0x1224df0, maps=0xb17d80) at util/map.c:953 #8 maps__remove (maps=0xb17d80, map=0x1224df0) at util/map.c:959 #9 0x00000000004f7d8a in map_groups__remove (map=, mg=) at util/map_groups.h:65 #10 machine__process_ksymbol_unregister (sample=, event=0x7ffff7279670, machine=) at util/machine.c:728 #11 machine__process_ksymbol (machine=, event=0x7ffff7279670, sample=) at util/machine.c:741 #12 0x00000000004fffbb in perf_session__deliver_event (session=0xb11390, event=0x7ffff7279670, tool=0x7fffffffc7b0, file_offset=13936) at util/session.c:1362 #13 0x00000000005039bb in do_flush (show_progress=false, oe=0xb17e80) at util/ordered-events.c:243 #14 __ordered_events__flush (oe=0xb17e80, how=OE_FLUSH__ROUND, timestamp=) at util/ordered-events.c:322 #15 0x00000000005005e4 in perf_session__process_user_event (session=session@entry=0xb11390, event=event@entry=0x7ffff72a4af8, ... Adding the map on the list and getting the reference event if we find the map with same name. Cc: Song Liu Link: http://lkml.kernel.org/n/tip-38t1ihcy32lvu4xfpm0p7yex@git.kernel.org Signed-off-by: Jiri Olsa --- tools/perf/util/map.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 28d484ef74ae..ee71efb9db62 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -926,10 +926,8 @@ static void __maps__insert_name(struct maps *maps, struct map *map) rc = strcmp(m->dso->short_name, map->dso->short_name); if (rc < 0) p = &(*p)->rb_left; - else if (rc > 0) - p = &(*p)->rb_right; else - return; + p = &(*p)->rb_right; } rb_link_node(&map->rb_node_name, parent, p); rb_insert_color(&map->rb_node_name, &maps->names); -- 2.17.2