Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp116684pxx; Tue, 27 Oct 2020 23:25:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0dgcr/aEy2HY1/+9ZmdLmYvQL9Rc0csAmcI83Ru/OLS3NZxfSUH0TRG1CUvrISY0qcYwH X-Received: by 2002:a17:906:7157:: with SMTP id z23mr6307007ejj.474.1603866324655; Tue, 27 Oct 2020 23:25:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603866324; cv=none; d=google.com; s=arc-20160816; b=vowNIes0k2IJ7QzCFhWu/ZV0kir8KoVk/Xs53iAemhdozoRZ6tkibsGudjLwVD61On 6ZidSaGhxLYg/BYO/7ivgRs6boED/D6zK3IIuFXvCm/dmE4JuNfkm90ZyoKB/VSsmcWg NSkJ23Bv8KeSl0Kmt3iTL0JA9GYWXrm8rkWvknaJqJYgEwdL8tYzjIjrgGhY8Xa40Af5 QiBo5VrjuJwXeCmn5wTYFsTOYL2PFDc1lgWaBwoT4GSBskDHzdMsGm/00yV1AY/BBroy FHXX+zNUEnVrVYwjR5yHfODJjUc/0Zng8nIQg9ycKDifO1ggJIUvg4inujPulVUGoJHY lJyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=K3VfyojhY8OJ0Wn3cWDdoFkxsgNE4fP8GmslFxhfUtU=; b=mxqJsFCr3kE2O4aFVWKDwXFiqGsZi6vaZZZH1iU3Y23COwxvi4sBP4qprYX26WphMA z/Or0nm/D6os3UJKONqvKmnE5s/CoNHaLsbxytJpJwQSm2CwowF7HbTFO7i9TeKANE38 Jav6o8dKw1GkY+tSupHQP1RranvWYZ3qHaPFHRR+mBypIdw9Zqdz1xRkzisJJmW2LYBh P4MhtgLSbIUeY93Pk1jBZgVxH/vlZWwKSHy6N3Q0x8Bi+jQeuee7X+iC4r1RKl64z+aD d71EMgeBtlYLHUFNTf7vjXYVtQvxFqLBD84g7FGzvQgvIVVJTcrYqLViSxO2NYEGWnHR tSqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b="zrvx8/9O"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y18si1057612edl.592.2020.10.27.23.25.02; Tue, 27 Oct 2020 23:25:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b="zrvx8/9O"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2895915AbgJ0JvQ (ORCPT + 99 others); Tue, 27 Oct 2020 05:51:16 -0400 Received: from forwardcorp1p.mail.yandex.net ([77.88.29.217]:45032 "EHLO forwardcorp1p.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2895781AbgJ0JvP (ORCPT ); Tue, 27 Oct 2020 05:51:15 -0400 X-Greylist: delayed 427 seconds by postgrey-1.27 at vger.kernel.org; Tue, 27 Oct 2020 05:51:13 EDT Received: from sas1-5717c3cea310.qloud-c.yandex.net (sas1-5717c3cea310.qloud-c.yandex.net [IPv6:2a02:6b8:c14:3616:0:640:5717:c3ce]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id 0DFA52E150C; Tue, 27 Oct 2020 12:44:05 +0300 (MSK) Received: from sas1-b105e6591dac.qloud-c.yandex.net (sas1-b105e6591dac.qloud-c.yandex.net [2a02:6b8:c08:4790:0:640:b105:e659]) by sas1-5717c3cea310.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id CJ9YNxQAdI-i4w0taHC; Tue, 27 Oct 2020 12:44:04 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1603791844; bh=K3VfyojhY8OJ0Wn3cWDdoFkxsgNE4fP8GmslFxhfUtU=; h=Message-Id:Date:Subject:To:From:Cc; b=zrvx8/9ODZjbQRcEcYJ4/L6Tle9k1fbx28Ep4Qn7e6twQlfO+8LHhaVsAqN+1hC9Z ghYJnPAQoEoIEfbxZJzNuYJKEj1jBzd7w80WdnTQCRxAACKIG4XnFmq4kGEYsiklaX mJcp+DHJWwJTBxJJ8xB0VeYvsawY+9ZMWNsICQF4= Authentication-Results: sas1-5717c3cea310.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from 37.140.163.55-vpn.dhcp.yndx.net (37.140.163.55-vpn.dhcp.yndx.net [37.140.163.55]) by sas1-b105e6591dac.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id zReNbf03PH-i4nSe09A; Tue, 27 Oct 2020 12:44:04 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) From: Stanislav Ivanichkin To: linux-kernel@vger.kernel.org Cc: linux-perf-users@vger.kernel.org, dmtrmonakhov@yandex-team.ru, namhyung@gmail.com Subject: [PATCH v3] perf trace: Segfault when trying to trace events by cgroup Date: Tue, 27 Oct 2020 12:43:57 +0300 Message-Id: <20201027094357.94881-1-sivanichkin@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org # ./perf trace -e sched:sched_switch -G test -a sleep 1 perf: Segmentation fault Obtained 11 stack frames. ./perf(sighandler_dump_stack+0x43) [0x55cfdc636db3] /lib/x86_64-linux-gnu/libc.so.6(+0x3efcf) [0x7fd23eecafcf] ./perf(parse_cgroups+0x36) [0x55cfdc673f36] ./perf(+0x3186ed) [0x55cfdc70d6ed] ./perf(parse_options_subcommand+0x629) [0x55cfdc70e999] ./perf(cmd_trace+0x9c2) [0x55cfdc5ad6d2] ./perf(+0x1e8ae0) [0x55cfdc5ddae0] ./perf(+0x1e8ded) [0x55cfdc5ddded] ./perf(main+0x370) [0x55cfdc556f00] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe6) [0x7fd23eeadb96] ./perf(_start+0x29) [0x55cfdc557389] Segmentation fault It happens because "struct trace" in option->value is passed to parse_cgroups function instead of "struct evlist". v3: - missed commit message (Namhyung Kim) v2: - struct declaration fixed (Namhyung Kim) Fixes: 9ea42ba4411ac ("perf trace: Support setting cgroups as targets") Signed-off-by: Stanislav Ivanichkin Acked-by: Namhyung Kim --- tools/perf/builtin-trace.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 44a75f234db1..de80534473af 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -4639,9 +4639,9 @@ static int trace__parse_events_option(const struct option *opt, const char *str, err = 0; if (lists[0]) { - struct option o = OPT_CALLBACK('e', "event", &trace->evlist, "event", - "event selector. use 'perf list' to list available events", - parse_events_option); + struct option o = { + .value = &trace->evlist, + }; err = parse_events_option(&o, lists[0], 0); } out: @@ -4655,9 +4655,12 @@ static int trace__parse_cgroups(const struct option *opt, const char *str, int u { struct trace *trace = opt->value; - if (!list_empty(&trace->evlist->core.entries)) - return parse_cgroups(opt, str, unset); - + if (!list_empty(&trace->evlist->core.entries)) { + struct option o = { + .value = &trace->evlist, + }; + return parse_cgroups(&o, str, unset); + } trace->cgroup = evlist__findnew_cgroup(trace->evlist, str); return 0; -- 2.17.1