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=ham 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 7BFB2C433DF for ; Thu, 6 Aug 2020 02:46:18 +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 4A1DB2086A for ; Thu, 6 Aug 2020 02:46:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GwpeUAGq"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="PCvcY1A3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A1DB2086A 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=KOv/8abmXrxhnkzjShXG1PUBrC7B/OPn+U41qDF3Roc=; b=GwpeUAGqmWFZPhyJdZSd65fu5 yfOU2Sm+Ucxu+LU8bZTHlS2WyrbKXEwyb3+Do9lSo8pn1l3RjKlvr+rW+BDLoSW/fZWMV655WqS/b 4bCrONv4nzi5W8aCE+iK365uiMQM/GHkCWheZ0aLyPG0vceT45nnIHfkrb7wV6eEppEHuC10XQK/9 286eu83BUsseKvZC8XGBDzVnpQZXtJK08i0UlDCKxp/qY/XKSxXA4j/77qtQOi7KW1ZqTOG/9edq0 kHqmfPjxsBMNeBcIZv/3dasbZvWN8MmbEh6GmIloW///l5mt8c7LOPw7aNxpyi2W1A60vYceb1qjs dGNV3fwDA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k3Vst-0007Uq-Bl; Thu, 06 Aug 2020 02:43:59 +0000 Received: from mail29.static.mailgun.info ([104.130.122.29]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k3Vso-0007UD-QB for linux-arm-kernel@lists.infradead.org; Thu, 06 Aug 2020 02:43:55 +0000 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1596681834; h=In-Reply-To: Content-Type: MIME-Version: References: Message-ID: Subject: Cc: To: From: Date: Sender; bh=xMpM+9Yqjz7COLp6/5nKxGrC54cFIt+CzJcfvRltWZ8=; b=PCvcY1A3XV+Ph8vi/yR42Wwo2YAZXZkMRKW/cmrD3pJWeFdS4QBm8QpTBcCkxG9QmpsuZIEZ krAqHVpGoJFPDQDsJOG+esnRr0ZRqFo5ybgf2yR7/ig1gErBx601qGhpQpy8UFbmL5DPVSCG TMkW9sV2FFwSH0HriGbIXrnkwBo= X-Mailgun-Sending-Ip: 104.130.122.29 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-n13.prod.us-east-1.postgun.com with SMTP id 5f2b6e6996bb98157aa451a1 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Thu, 06 Aug 2020 02:43:53 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 5740CC4339C; Thu, 6 Aug 2020 02:43:52 +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 1A22CC433C9; Thu, 6 Aug 2020 02:43:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 1A22CC433C9 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: Thu, 6 Aug 2020 10:43:39 +0800 From: Tingwei Zhang To: Suzuki K Poulose Subject: Re: [PATCH v7 06/25] coresight: add try_get_module() in coresight_grab_device() Message-ID: <20200806024338.GB10121@codeaurora.org> References: <20200805025458.2978-1-tingwei@codeaurora.org> <20200805025458.2978-7-tingwei@codeaurora.org> <7a0c543e-6e71-db1c-e207-79d0d78c89b8@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <7a0c543e-6e71-db1c-e207-79d0d78c89b8@arm.com> 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-20200805_224354_889171_912B1540 X-CRM114-Status: GOOD ( 30.73 ) 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, saiprakash.ranjan@codeaurora.org, kim.phillips@arm.com, mathieu.poirier@linaro.org, alexander.shishkin@linux.intel.com, gregkh@linuxfoundation.org, coresight@lists.linaro.org, jinlmao@codeaurora.org, ykaukab@suse.de, linux@armlinux.org.uk, rdunlap@infradead.org, tingwei@codeaurora.org, leo.yan@linaro.org, linux-arm-kernel@lists.infradead.org, mike.leach@linaro.org 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 On Wed, Aug 05, 2020 at 06:55:40PM +0800, Suzuki K Poulose wrote: > On 08/05/2020 03:54 AM, 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. > >Use get_device()/put_device() to protect device data > >in the middle of active session. > > > >Signed-off-by: Tingwei Zhang > >Tested-by: Mike Leach > >--- > > drivers/hwtracing/coresight/coresight.c | 39 +++++++++++++++++++++---- > > 1 file changed, 34 insertions(+), 5 deletions(-) > > > >diff --git a/drivers/hwtracing/coresight/coresight.c > b/drivers/hwtracing/coresight/coresight.c > >index b7151c5f81b1..1626bc885dfe 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; > > Please could you add a pair of helper functions to hold/drop reference > to a device/driver ? i.e, > > static inline bool coresight_get_ref(struct coresight_device *csdev) > { > struct device *dev = csdev->dev.parent; > > /* Make sure the driver cant be removed */ > if (!try_module_get(dev->driver->owner)) > return false; > /* Make sure the device can't go away */ > get_device(dev); > pm_runtime_get_sync(dev); > return true; > } > Sure. I'll add it to next revision. Thanks, Tingwei > static inline void coresight_put_ref(struct coresight_device *csdev) > { > struct device *dev = csdev->dev.parent; > > pm_runtime_put(dev); > put_device(dev); > module_put(dev->driver->owner); > } > > > >@@ -648,10 +648,30 @@ 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)) > >+ goto err; > >+ get_device(child->dev.parent); > > pm_runtime_get_sync(child->dev.parent); > >+ } > > } > > This could then be : > if (child && child->type == CORESIGHT_DEV_TYPE_HELPER) > if (!coresight_get_ref(child)) > goto err; > > >+ if (!try_module_get(csdev->dev.parent->driver->owner)) > >+ goto err; > >+ get_device(csdev->dev.parent); > > pm_runtime_get_sync(csdev->dev.parent); > > if (coresight_get_ref(csdev)) > return 0; > > >+ return 0; > >+err: > >+ for (i--; i >= 0; i--) { > >+ struct coresight_device *child; > >+ > >+ child = csdev->pdata->conns[i].child_dev; > >+ if (child && child->type == CORESIGHT_DEV_TYPE_HELPER) > >+ pm_runtime_put(child->dev.parent); > >+ put_device(child->dev.parent); > >+ module_put(child->dev.parent->driver->owner); > >+ } > > And this could be : > > if (child && child->type == CORESIGHT_DEV_TYPE_HELPER) > coresight_put_ref(child); > > >+ } > >+ return -ENODEV; > > } > > /* > >@@ -663,12 +683,17 @@ static void coresight_drop_device(struct > coresight_device *csdev) > > int i; > > pm_runtime_put(csdev->dev.parent); > >+ put_device(csdev->dev.parent); > >+ module_put(csdev->dev.parent->driver->owner); > > coresight_put_ref(csdev); > > > for (i = 0; i < csdev->pdata->nr_outport; i++) { > > 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) { > > pm_runtime_put(child->dev.parent); > >+ put_device(child->dev.parent); > >+ module_put(child->dev.parent->driver->owner); > >+ } > > coresight_put_ref(child); > > > } > > } > >@@ -687,7 +712,7 @@ static int _coresight_build_path(struct > coresight_device *csdev, > > struct coresight_device *sink, > > struct list_head *path) > > { > >- int i; > >+ int i, ret; > > bool found = false; > > struct coresight_node *node; > >@@ -721,7 +746,11 @@ static int _coresight_build_path(struct > coresight_device *csdev, > > if (!node) > > return -ENOMEM; > >- coresight_grab_device(csdev); > >+ ret = coresight_grab_device(csdev); > >+ if (ret) { > >+ kfree(node); > >+ return ret; > >+ } > > node->csdev = csdev; > > list_add(&node->link, path); > > > > > Cheers > Suzuki > > _______________________________________________ > 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