Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp395486pxu; Fri, 23 Oct 2020 03:52:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhbPmy+AsWermV8OFqdkMZuFMVfEebkyE4BF42MU08uWkK//RdLiwN/J2TkhT7KNU/Z0pp X-Received: by 2002:a17:906:6a8b:: with SMTP id p11mr1381180ejr.470.1603450374619; Fri, 23 Oct 2020 03:52:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603450374; cv=none; d=google.com; s=arc-20160816; b=bEJ0XavCZL85/eMVFZAscHfaosV1I+lSndwwknB2nIE7fTTHyQr7sJTx5DWuGxgRXG YeGP/XI7s2IRt4EY9sH1voJmKPrNmZ8p4n60rI8gB7TQW5MPEKc0vlrIqnEnC9AGoOtu 8/wB/kuLkCdwmcWg90xZDyXMTeMc5WGbA2tKYXXW2w9uo+VO42IeB9bXvdCdC3APTuJs 8egreFpsfJg7otU0T7KulGo5BfyzK41/ZD6wXgANIYDrEVx9dl0ufCXyAjf5XOnVI0xX 4WP/ZxhPW1uAF0tl9FbknB8ZaflwX6Db+xtLHsdMUGSSXRhQP6muaNy8gsdLrrybqctD zvVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=dRLzZkslO7pc17sHwxWo7qkBQqbssg/CNWanWeK8xJI=; b=l7uaxJjFI6CiPzFwa1k6e9YXD+aA3heMRCEn6hL8ws6zad/GSdJcayD982kB4vNNlo oMyAkbXy5fRNmEAy5j09c8rB+dpLAQ9bKAfBPjCtGUHE4ENCic6E/A/OqUW8kPX8lg0W IHbPAAg7G3+bB0ltedMWzL0lQ9IT8Uq2+wm4qtDUt0/VnBURVZeUnzkclKSgRekT+x0m Orsz2Ue61pk9HLTSJTKSUv4hzkIcMdKXAiHeELP6GaHftFsJdfe6Fjrtvs2vTEZL7klV p/hqHRCmXq6UJ4RQImEua+ojV2JykcT5icdMRsevT42B08Asgq6d5nNWwumSmeiNIrOk ZzSg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oi22si636977ejb.466.2020.10.23.03.52.31; Fri, 23 Oct 2020 03:52:54 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S462496AbgJWKtg (ORCPT + 99 others); Fri, 23 Oct 2020 06:49:36 -0400 Received: from foss.arm.com ([217.140.110.172]:49174 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S462356AbgJWKtg (ORCPT ); Fri, 23 Oct 2020 06:49:36 -0400 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 810BE113E; Fri, 23 Oct 2020 03:49:35 -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 141CA3F66B; Fri, 23 Oct 2020 03:49:30 -0700 (PDT) Subject: Re: [PATCHv2 2/4] coresight: tmc-etf: Fix NULL ptr dereference in tmc_enable_etf_sink_perf() To: Peter Zijlstra Cc: Mathieu Poirier , Sai Prakash Ranjan , Mike Leach , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , coresight@lists.linaro.org, Stephen Boyd , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <20201022113214.GD2611@hirez.programming.kicks-ass.net> <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> <20201023092337.GQ2611@hirez.programming.kicks-ass.net> From: Suzuki Poulose Message-ID: <060def4c-ced9-74c5-8e73-d8aedfdbc107@arm.com> Date: Fri, 23 Oct 2020 11:49:29 +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: <20201023092337.GQ2611@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/23/20 10:23 AM, Peter Zijlstra wrote: > On Fri, Oct 23, 2020 at 09:49:53AM +0100, Suzuki Poulose wrote: >> On 10/23/20 8:39 AM, Peter Zijlstra wrote: > >>> So then I don't understand the !->owner issue, that only happens when >>> the task dies, which cannot be concurrent with event creation. Are you >> >> Part of the patch from Sai, fixes this by avoiding the dereferencing >> after event creation (by caching it). But the kernel events needs >> fixing. >> >> One follow up question on the !->owner issue. Given the ->owner is >> dying, does it prevent events from being scheduled ? Or is there a delay >> between that and eventually stopping the events. In this case, we hit >> the issue when : >> >> A A or B ? >> >> event_start() >> ... event->owner = NULL >> >> READ_ONCE(event->owner); >> >> Is this expected ? > > Yeah, teardown is a bit of an effort. Also, you can pass an fd over a > unix socket to another process, so this isn't something you can rely on > in any case. > > The perf tool doesn't do it, but the kernel infra should be able to deal > with someone doing a perf-deamon of sorts, where you can request a perf > event and recieve a fd from it. > > Imagine the fun ;-) > >>> As for the kernel events.. why do you care about the actual task_struct >>> * in there? I see you're using it to grab the task-pid, but how is that >>> useful? >> >> Correct, kernel events are something that the driver didn't account for. >> May be we could handle this case with a "special pid" and simply >> disallow sharing (which is fine I believe, given there are not grouping >> for the kernel created events). > > Why do you need a pid in the first place? Can't you use the "task_struct > *" as a value? We could. But, without a refcount on the task pointer, that could be tricky, even though we don't dereference it. In the same situation, if the tsk owner dies and is freed and is reallocated to a new perf session task but with different PID, we could be mixing things up again ? Special pid here could be -1.