Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp9049419ybl; Fri, 17 Jan 2020 05:35:34 -0800 (PST) X-Google-Smtp-Source: APXvYqxIZZPtRtH7UB2VfxSmPjN+yMaHiBmRw3qawGoItlWOas+qGMWL/IfpguaVXP4sLvgGqC02 X-Received: by 2002:a05:6830:1402:: with SMTP id v2mr6012270otp.12.1579268134713; Fri, 17 Jan 2020 05:35:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579268134; cv=none; d=google.com; s=arc-20160816; b=V2NIvLmjMPinNaaYhe4EwavxdiS1GeuJeET9szDIitCzpgpY4qJz1+siYQ2+83nMwv hiFc09i1xeXsaxMdoAlu/Ezkop2bJt8cX3rMgEXk/vXoqTUKth7NnAptcnPUZtJIruMY +eMzjhmkC5QNEQbT0LWlD1D4Wd5y9Jf9tdtCrYqOF2M6Or3dlrSTGAT+f+WbCc2O3/a9 S9ZmQuQGsUJyiFMluWEQBt3lQ+LyskZ5toliXkvSh0QmW8CCR/iJF8CQw4CmLL+JrIQu /H2nF6FrzX/OKxqy/Hdbqdr87owjqohVWWlvFop6d044W+OLYRy2AESoEkdKxK4mK0bQ Q+hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=LzXXWC16J/bkAvB2AvgILmvmigCWBLJYsCNp/VkJW+4=; b=Un3o1lT69WQ69lMKUI03qEik0+iOB5jwXWJZX/zp1CxL9m3bwL9XFgpYN2FuRdEVoq t9/wS+fdO2nfX1wbXYgL8lVyrpRlrnUWP0MtVV4fQvPLK03YsZMucA9CEJdTd0FFDbj9 ToIZLSasIV7qA2oSS2pFHQsfJBohHvrxteVNvCKH/lFr5Qi68PGuFBnsuY5sipbpByIk 1UV03gWJmyAdCRJIB78j2dtXz1RuN2jJZlslNG885aPBgnkeC5uQPYdvWjI48FvUCEs2 DG56Q0zPzDB6B5uYXQOBtT0uHbfLt3ITYtsHAjlgP6QWSQv4liubRfJMsNWweoIuccV3 VRsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ClpaWwes; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u25si15347807otg.170.2020.01.17.05.35.21; Fri, 17 Jan 2020 05:35:34 -0800 (PST) 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ClpaWwes; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726970AbgAQNeU (ORCPT + 99 others); Fri, 17 Jan 2020 08:34:20 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:20117 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726587AbgAQNeU (ORCPT ); Fri, 17 Jan 2020 08:34:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579268059; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LzXXWC16J/bkAvB2AvgILmvmigCWBLJYsCNp/VkJW+4=; b=ClpaWwesuTSp69HWFKj0t6vi4bRY5WXhNMxYDRcF49Hh0jdPfAdYqdWzxmb9a7ngTSw21O Qo8MDZZzpi5/kB4PsUPNyK0/2dixc986dCsXkhYHy7fZzijVnfTdpljVuAKeQDzwtfUiLz ruJC6wT9bT+Kv33YlwHjtIYiZtsMzSM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-400-bOCTjrhlNKW8N1yvIRASHA-1; Fri, 17 Jan 2020 08:34:15 -0500 X-MC-Unique: bOCTjrhlNKW8N1yvIRASHA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C7935107ACCC; Fri, 17 Jan 2020 13:34:13 +0000 (UTC) Received: from sandy.ghostprotocols.net (ovpn-112-16.phx2.redhat.com [10.3.112.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0AF335C545; Fri, 17 Jan 2020 13:34:12 +0000 (UTC) Received: by sandy.ghostprotocols.net (Postfix, from userid 1000) id 3ABB611E4; Fri, 17 Jan 2020 10:34:09 -0300 (BRT) Date: Fri, 17 Jan 2020 10:34:09 -0300 From: Arnaldo Carvalho de Melo To: Leo Yan Cc: Mathieu Poirier , Suzuki K Poulose , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , Adrian Hunter , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach Subject: Re: [PATCH v6 2/2] perf parse: Copy string to perf_evsel_config_term Message-ID: <20200117133409.GB3323@redhat.com> References: <20200117055251.24058-1-leo.yan@linaro.org> <20200117055251.24058-2-leo.yan@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200117055251.24058-2-leo.yan@linaro.org> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.20 (2009-12-10) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, Jan 17, 2020 at 01:52:51PM +0800, Leo Yan escreveu: > perf with CoreSight fails to record trace data with command: > > perf record -e cs_etm/@tmc_etr0/u --per-thread ls > failed to set sink "" on event cs_etm/@tmc_etr0/u with 21 (Is a > directory)/perf/ > > This failure is root caused with the commit 1dc925568f01 ("perf > parse: Add a deep delete for parse event terms"). > > The log shows, cs_etm fails to parse the sink attribution; cs_etm event > relies on the event configuration to pass sink name, but the event > specific configuration data cannot be passed properly with flow: > > get_config_terms() > ADD_CONFIG_TERM(DRV_CFG, term->val.str); > __t->val.str = term->val.str; > `> __t->val.str is assigned to term->val.str; > > parse_events_terms__purge() > parse_events_term__delete() > zfree(&term->val.str); > `> term->val.str is freed and assigned to NULL pointer; > > cs_etm_set_sink_attr() > sink = __t->val.str; > `> sink string has been freed. > > To fix this issue, in the function get_config_terms(), this patch > changes to use strdup() for allocation a new duplicate string rather > than directly assignment string pointer. > > This patch addes a new field 'free_str' in the data structure > perf_evsel_config_term; 'free_str' is set to true when the union is used > as a string pointer; thus it can tell perf_evsel__free_config_terms() to > free the string. > > Fixes: 1dc925568f01 ("perf parse: Add a deep delete for parse event terms") > Suggested-by: Jiri Olsa > Signed-off-by: Leo Yan > Acked-by: Jiri Olsa > --- > tools/perf/util/evsel.c | 2 ++ > tools/perf/util/evsel_config.h | 1 + > tools/perf/util/parse-events.c | 7 ++++++- > 3 files changed, 9 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c > index 549abd43816f..6fe9e28180e5 100644 > --- a/tools/perf/util/evsel.c > +++ b/tools/perf/util/evsel.c > @@ -1265,6 +1265,8 @@ static void perf_evsel__free_config_terms(struct evsel *evsel) > > list_for_each_entry_safe(term, h, &evsel->config_terms, list) { > list_del_init(&term->list); > + if (term->free_str) > + free(term->val.str); I'm replacing this with zfree, so that we can catch possible bugs where term gets used after freed, just like you do below, in ADD_CONFIG_TERM_STR() Thanks, > free(term); > } > } > diff --git a/tools/perf/util/evsel_config.h b/tools/perf/util/evsel_config.h > index b4a65201e4f7..e026ab67b008 100644 > --- a/tools/perf/util/evsel_config.h > +++ b/tools/perf/util/evsel_config.h > @@ -32,6 +32,7 @@ enum evsel_term_type { > struct perf_evsel_config_term { > struct list_head list; > enum evsel_term_type type; > + bool free_str; > union { > u64 period; > u64 freq; > diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c > index f59f3c8da473..c01ba6f8fdad 100644 > --- a/tools/perf/util/parse-events.c > +++ b/tools/perf/util/parse-events.c > @@ -1240,7 +1240,12 @@ do { \ > #define ADD_CONFIG_TERM_STR(__type, __val) \ > do { \ > ADD_CONFIG_TERM(__type); \ > - __t->val.str = __val; \ > + __t->val.str = strdup(__val); \ > + if (!__t->val.str) { \ > + zfree(&__t); \ > + return -ENOMEM; \ > + } \ > + __t->free_str = true; \ > } while (0) > > struct parse_events_term *term; > -- > 2.17.1