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=-11.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable 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 CC3E5C433E3 for ; Fri, 24 Jul 2020 00:43:35 +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 975202065F for ; Fri, 24 Jul 2020 00:43:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="q/YZBre8"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="xk03Xf8f" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 975202065F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=codeaurora.org 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-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Mv+thiJ9KJpr+6SWNQI3bpcz0Yp6SPP81BOWedjK7H4=; b=q/YZBre8ia6jBVyLGFv2VmC+t HpXoCgcljFvH90Hz1HaZ1X8VqqysyjNyU0KSgswRGWBOzH3GZyLeaMq/RWEtMzf9SPUToSveth6jR Wl+lDZQibKxaDQTCGcxKrH7sVz/AjX3yfGJmrLVmHPNKBNAsTTf75mgzZhoXMbyls/+uoivJz5wee DxaDtpGVESx4wyXTHYdGDex+ShcdTL/9SFqbzXnQMueTIxWAE7ziu9AStumjvnkbERDscg6lBBl1B hyLftOgiBexJOTNiWlBDTr7YQk/KwQJnlQf+wMOkAEa3yC5nw9ZWTL3gF0p7Qab9qBcyfpvevVY2l UQLhxRsZQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyln0-0005jr-AA; Fri, 24 Jul 2020 00:42:18 +0000 Received: from m43-7.mailgun.net ([69.72.43.7]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jylmt-0005jO-Mf for linux-arm-kernel@lists.infradead.org; Fri, 24 Jul 2020 00:42:16 +0000 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1595551335; h=In-Reply-To: Content-Type: MIME-Version: References: Message-ID: Subject: Cc: To: From: Date: Sender; bh=RCqkI2X9308fY90mBODFk2R+SJnVtmoR2pWhAxqIkYw=; b=xk03Xf8fKJ4zkFgjWG/DDX74+K62/SF6FDC9jEfEo8kVgLpXHrFEclFDVcd072iaPeiZVBdo GgA9sAKvTu1IjRffVPzSZZBVzIdiQMVuNuzTRFmSVfM5m8iB0fVS6pH67eb5UMezYYnFvn8z mLhNJZ2X0TxFMsN+Ecj8IkSAPYA= X-Mailgun-Sending-Ip: 69.72.43.7 X-Mailgun-Sid: WyJiYzAxZiIsICJsaW51eC1hcm0ta2VybmVsQGxpc3RzLmluZnJhZGVhZC5vcmciLCAiYmU5ZTRhIl0= Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n10.prod.us-east-1.postgun.com with SMTP id 5f1a2e5603c8596cdbeb22a3 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Fri, 24 Jul 2020 00:41:58 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 09EA6C433A1; Fri, 24 Jul 2020 00:41:56 +0000 (UTC) Received: from codeaurora.org (unknown [180.166.53.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: tingwei) by smtp.codeaurora.org (Postfix) with ESMTPSA id 9D44EC433C9; Fri, 24 Jul 2020 00:41:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 9D44EC433C9 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=tingweiz@codeaurora.org Date: Fri, 24 Jul 2020 08:41:48 +0800 From: Tingwei Zhang To: Mathieu Poirier Subject: Re: [PATCH v4 06/20] coresight: add try_get_module() in coresight_grab_device() Message-ID: <20200724004148.GB3530@codeaurora.org> References: <20200723042802.22511-1-tingwei@codeaurora.org> <20200723042802.22511-7-tingwei@codeaurora.org> <20200723110707.GA1960107@kroah.com> <20200723180447.GA1323936@xps15> <20200723181837.GA2944775@kroah.com> <20200723191540.GB1323936@xps15> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200723191540.GB1323936@xps15> User-Agent: Mutt/1.5.24 (2015-08-30) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200723_204215_990499_4FC7E04F X-CRM114-Status: GOOD ( 45.46 ) 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: tsoni@codeaurora.org, Sai Prakash Ranjan , Kim Phillips , Suzuki K Poulose , Alexander Shishkin , Greg Kroah-Hartman , coresight@lists.linaro.org, Mao Jinlong , Mian Yousaf Kaukab , Russell King , Randy Dunlap , Tingwei Zhang , Leo Yan , linux-arm-kernel@lists.infradead.org, Mike Leach Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Fri, Jul 24, 2020 at 03:15:40AM +0800, Mathieu Poirier wrote: > On Thu, Jul 23, 2020 at 08:18:37PM +0200, Greg Kroah-Hartman wrote: > > On Thu, Jul 23, 2020 at 12:04:47PM -0600, Mathieu Poirier wrote: > > > Hi Greg, > > > > > > On Thu, Jul 23, 2020 at 01:07:07PM +0200, Greg Kroah-Hartman wrote: > > > > On Thu, Jul 23, 2020 at 12:27:48PM +0800, Tingwei Zhang wrote: > > > > > When coresight device is in an active session, driver module of > > > > > that device should not be removed. Use try_get_module() in > > > > > coresight_grab_device() to prevent module to be unloaded. > > > > > > > > Are you sure this works? Why is it needed at all? Why not just > tear > > > > down the children properly when a module is removed so that you > don't > > > > need this at all? > > > > > > Using the terms parent and child is somewhat ambiguous... This is not > a > > > parent-child relationship but simply an association between devices, > something > > > like port 1 on device "parent" is connected to port 2 on device > "child". The > > > parent-child nomenclature was chosen to reflect that a device appears > before > > > another in a coresight path. Otherwise there is no other relation > between > > > devices, hence the choice of using try_get_module()/put_module() to > prevent > > > drivers from being taken away. I'd be happy to proceed differently > but haven't > > > found better options. > > > > > > Going back to parent/child, we could have chosen left/right, up/down > or A/B, all > > > of which are just as confusion. > > > > Ok, thanks. > > > > But this causes confusion for everyone as seen below: > > > > > > > Signed-off-by: Tingwei Zhang > > > > > --- > > > > > drivers/hwtracing/coresight/coresight.c | 27 > +++++++++++++++++++++---- > > > > > 1 file changed, 23 insertions(+), 4 deletions(-) > > > > > > > > > > diff --git a/drivers/hwtracing/coresight/coresight.c > b/drivers/hwtracing/coresight/coresight.c > > > > > index b7151c5f81b1..17bc76ea86ae 100644 > > > > > --- a/drivers/hwtracing/coresight/coresight.c > > > > > +++ b/drivers/hwtracing/coresight/coresight.c > > > > > @@ -640,7 +640,7 @@ struct coresight_device > *coresight_get_sink_by_id(u32 id) > > > > > * don't appear on the trace path, they should be handled along > with the > > > > > * the master device. > > > > > */ > > > > > -static void coresight_grab_device(struct coresight_device *csdev) > > > > > +static int coresight_grab_device(struct coresight_device *csdev) > > > > > { > > > > > int i; > > > > > > > > > > @@ -648,10 +648,25 @@ static void coresight_grab_device(struct > coresight_device *csdev) > > > > > struct coresight_device *child; > > > > > > > > > > child = csdev->pdata->conns[i].child_dev; > > > > > - if (child && child->type == > CORESIGHT_DEV_TYPE_HELPER) > > > > > + if (child && child->type == > CORESIGHT_DEV_TYPE_HELPER) { > > > > > + if > (!try_module_get(child->dev.parent->driver->owner)) > > > > > > > > Why the child's parent? Why not the child itself? > > > > > > The device structure of each coresight_device is not associated with a > driver. > > > It is there to take advantages of device goodies such as dev.type, > dev.group, > > > dev.release and dev.bus. Coresight IP blocks are discovered on the > AMBA bus and as > > > such amba_device::dev::driver holds the driver itself. In > coresight_register() > > > the association coresigth::dev::parent = amba_device::dev is made. > > > > > > > > > > > > > > > > + goto err; > > > > > > > > What about the error given to you here? Why throw that away? > > > > > > > > > pm_runtime_get_sync(child->dev.parent); > > > > > + } > > > > > } > > > > > + if (!try_module_get(csdev->dev.parent->driver->owner)) > > > > > + goto err; > > > > > > > > You don't reduce the child's parent's driver owner module reference > > > > here? > > > > > > Here @parent is referencing the current device. Now that helper > devices > > > connected to any of its outgoing ports have been enabled (and a > reference count > > > to the helper device driver incremented), a reference count to the > current device > > > driver can also be incremented. > > > > I mean the fact that your error handling does not seem to roll back the > > module reference count you got up above in the other loop. > > Ah! You were talking about the error condition, while I thought you were > referring to the normal execution path. I am in agreement with all your > comments on error > handling. > Thanks to point this error out, Greg and Mathieu. I'll check and fix them in next revision. > > > > Or if it does, it's really really not obvious, and should at the very > > least, be commented as to how it's all cleaning up properly. > > > > thanks, > > > > greg k-h > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel