From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 366A2C55179 for ; Fri, 23 Oct 2020 13:31:39 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C64BD21D43 for ; Fri, 23 Oct 2020 13:31:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="04/SHH3p" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C64BD21D43 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=70ngQYjZEmAy34oHfsR9SSu4ORuF9i/4ldRgdg9mHAc=; b=04/SHH3paFAOBnoB9FdY+ppFE hLrHxss0+czGl3xavTGWSqFmbAwG12xVJqdTh0IJG6Gu0h1aWdcJtIwBiGEQNcb7Cqm5A+NTN2DyJ DJJ+76EEdlq8M/6gaMbPVaKgSACqyYINZqZEKmj1Z3O9Gll03AzC+y6WrVOi3yeON+a7qQQzKicSL rjzxXEFVgAecqUtAOv/hEoWH42Qt3gG6rBeZF7aQF5jCw8A+uHLfndDAYQoEGrXJLg2neISSxH7jK J4RCYCrarIXltVsLoMZ372WUCcVs7giP3rYII8T/VllxJOyCRHvXlquRRcBsLS3GHyL3EA2zW7vRe 1DBdTl6eg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVx8q-0003Bh-Mg; Fri, 23 Oct 2020 13:30:00 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVx8n-0003AN-C0 for linux-arm-kernel@lists.infradead.org; Fri, 23 Oct 2020 13:29:58 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8939D142F; Fri, 23 Oct 2020 06:29:56 -0700 (PDT) Received: from [10.57.13.45] (unknown [10.57.13.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 542D13F66B; Fri, 23 Oct 2020 06:29:54 -0700 (PDT) Subject: Re: [PATCHv2 2/4] coresight: tmc-etf: Fix NULL ptr dereference in tmc_enable_etf_sink_perf() To: Peter Zijlstra References: <20201022150609.GI2611@hirez.programming.kicks-ass.net> <788706f2-0670-b7b6-a153-3ec6f16e0f2e@arm.com> <20201022212033.GA646497@xps15> <20201023073905.GM2611@hirez.programming.kicks-ass.net> <174e6461-4d46-cb65-c094-c06ee3b21568@arm.com> <20201023094115.GR2611@hirez.programming.kicks-ass.net> <20201023105431.GM2594@hirez.programming.kicks-ass.net> <2457de8f-8bc3-b350-fdc7-61276da31ce6@arm.com> <20201023131628.GY2628@hirez.programming.kicks-ass.net> From: Suzuki Poulose Message-ID: <728fd89c-78f2-0c5c-0443-c91c62b02f0e@arm.com> Date: Fri, 23 Oct 2020 14:29:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.2 MIME-Version: 1.0 In-Reply-To: <20201023131628.GY2628@hirez.programming.kicks-ass.net> Content-Language: en-GB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201023_092957_575586_29A9470A X-CRM114-Status: GOOD ( 30.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Sai Prakash Ranjan , Mathieu Poirier , Alexander Shishkin , linux-arm-msm@vger.kernel.org, coresight@lists.linaro.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Stephen Boyd , Ingo Molnar , Namhyung Kim , Jiri Olsa , linux-arm-kernel@lists.infradead.org, Mike Leach Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 10/23/20 2:16 PM, Peter Zijlstra wrote: > On Fri, Oct 23, 2020 at 01:56:47PM +0100, Suzuki Poulose wrote: >> On 10/23/20 11:54 AM, Peter Zijlstra wrote: > >>> I think I'm more confused now :-/ >>> >>> Where do we use ->owner after event creation? The moment you create your >>> eventN you create the link to sink0. That link either succeeds (same >>> 'cookie') or fails. >> >> The event->sink link is established at creation. At event::add(), we >> check the sink is free (i.e, it is inactive) or is used by an event >> of the same session (this is where the owner field *was* required. But >> this is not needed anymore, as we cache the "owner" read pid in the >> handle->rb->aux_priv for each event and this is compared against the >> pid from the handle currently driving the hardware) > > *groan*.. that's going to be a mess with sinks that are shared between > CPUs :/ > >>> I'm also not seeing why exactly we need ->owner in the first place. >>> >>> Suppose we make the sink0 device return -EBUSY on open() when it is >>> active. Then a perf session can open the sink0 device, create perf >>> events and attach them to the sink0 device using >>> perf_event_attr::config2. The events will attach to sink0 and increment >>> its usage count, such that any further open() will fail. >> >> Thats where we are diverging. The sink device doesn't have any fops. It >> is all managed by the coresight driver transparent to the perf tool. All >> the perf tool does is, specifying which sink to use (btw, we now have >> automatic sink selection support which gets rid of this, and uses >> the best possible sink e.g, in case of per-CPU sinks). > > per-CPU sinks sounds a lot better. > > I'm really not convinced it makes sense to do what you do with shared > sinks though. You'll loose random parts of the execution trace because > of what the other CPUs do. The ETM trace protocol has in built TraceID to distinguish the packets and thus we could decode the trace streams from the shared buffer. [ But, we don't have buffer overflow interrupts (I am keeping the lid closed on that can, for the sake of keeping sanity ;-) ), and thus any shared session could easily loose data unless we tune the AUX buffer size to a really large buffer ]. > > Full exclusive sink access is far more deterministic. > >>> Once the events are created, the perf tool close()s the sink0 device, >>> which is now will in-use by the events. No other events can be attached >>> to it. >>> >>> Or are you doing the event->sink mapping every time you do: pmu::add()? >>> That sounds insane. >> >> Sink is already mapped at event create. But yes, the refcount on the >> sink is managed at start/stop. Thats when we need to make sure that the >> event being scheduled belongs to the same owner as the one already >> driving the sink. > > pmu::add() I might hope, because pmu::start() is not allowed to fail. > Right. If we can't get the sink, we simply truncate the buffer. >> That way another session could use the same sink if it is free. i.e >> >> perf record -e cs_etm/@sink0/u --per-thread app1 >> >> and >> >> perf record -e cs_etm/@sink0/u --per-thread app2 >> >> both can work as long as the sink is not used by the other session. > > Like said above, if sink is shared between CPUs, that's going to be a > trainwreck :/ Why do you want that? That ship has sailed. That is how the current generation of systems are, unfortunately. But as I said, this is changing and there are guidelines in place to avoid these kind of topologies. With the future technologies, this will be completely gone. > > And once you have per-CPU sinks like mentioned above, the whole problem > goes away. True, until then, this is the best we could do. Suzuki _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel