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=-14.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 498D7C433B4 for ; Mon, 17 May 2021 17:40:56 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 BE55460FD7 for ; Mon, 17 May 2021 17:40:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BE55460FD7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.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=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc: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=Zmx6QOa/jnCA9fIQGcH6H24BOLgmNrxa0/WM4LvXpXQ=; b=TAPRB24+3+/m3Svpu51LnIE+f 7mTo7xBu1nJBh78uJa/Psgj2dWMIRriJy150lmyttnrjXHaaK+SJvg771ub6DKhFSJY0AymbZpi7A oyjCWRKgSrGibpwRHCayh9HTg5W42/W7Lzn1FT98DeKSqwWUntfah0Kvy0O9RLje5mYczfE2yJsQQ 4PFDFR240gxa8B0Xji8ch92cYmQyBz61D100zlJeOwzRfkCyjTbdHPmDwsYCmJLuMHNKFzqKiQ8pv zlqnzBFUFyyYs/u1GhFLfyEMkjFegzLunqbmCCgPXabRqKmLScd9Ok15ARMJMxF36bHkLOBrD4qxB 9N+xKdzwg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lihCv-00FhAy-Q4; Mon, 17 May 2021 17:39:10 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lihCW-00Fh31-RY for linux-arm-kernel@desiato.infradead.org; Mon, 17 May 2021 17:38:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=JpROjFzX8MbXyzCjx4INDVATu77h9MshI1AIXQoU4Nc=; b=pHWq5yaGYmX4Qy5vmlh/uYB9a3 VWvpMy7uUFJEBcJvG9Aegpl/N7njd/AfTbiaPVHvAOZXPH6nGtJFXq0djvov4C3SE46yETeOuoTsI n1lAp4eEFeC+Ceribv/LHPUktR8IjsQyjptH33ep0kO1JMgEy9y9L1frOdVwHB+iBwwH+bPeRGrbm sokfuXuUyoxNVgVTZlyEzxygbSTsYyk6QlBQEJYPSPh0tFxTPvIUijklwdo4zr+T3WPouikynXNYR cWMA2unTSqExnRJoDPk8wp2lbmdoJztmHH4S8ueEMYgFjJpQysrCO/ZklysLroWfVPgBJOejo5zyK kG6QWVyQ==; Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lihCS-00E1ZW-U0 for linux-arm-kernel@lists.infradead.org; Mon, 17 May 2021 17:38:42 +0000 Received: by mail-pj1-x1036.google.com with SMTP id g24so4071129pji.4 for ; Mon, 17 May 2021 10:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=JpROjFzX8MbXyzCjx4INDVATu77h9MshI1AIXQoU4Nc=; b=uErlHxpHLR5fwRy0yRzVWvdS9ctRxwneKkLwU3LKrEwgWwmS10AxCOkSh0XmlieIkd VMOZIhzC6Ei6d8ZMuI+0RgE39oQ0+MJsN0oPjR4OLdY2To1s1zaYOz0gJP3kJEfGN9y0 A5+UvOOf2ytqSvkcu3L9PfC1ErmGU1AsIIRw1XCvHvPyPq/ql0bBDFdr0WZ95lLiRxp6 thl+m1RYsu3BQPka65kJ5domuaqGAR7AY0P/sGkxZEBNzhOcTI0FoUONOJ7HiOizHuSn +mpuGuwBuXlPN1h1TLP7Jv2VeDudCgKjegQdMrimiGNhzAkEaOZ5j0YdHJ26iY31dhu/ V/2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=JpROjFzX8MbXyzCjx4INDVATu77h9MshI1AIXQoU4Nc=; b=OlETXFcUFpW9ofDh+NOL/PRPsLcu+zd7B87oo/yOnrta66UPNulIpXMyohVNCgMSSH kcel0m+aAd0EqUVIeLrxS4ExQw98XDNMxiURUmf9gSQzctJyizBl0YSqzTE2Hx/6qtJe oB029WsTgEJiqryo+SjL+ZThKJH9sBvWabGP2wR4bih/J6RFFjMuWTcwDuDWsY03zRAC Lo8Y7brFmZetvFAa9mKUdIYAQ9hGI+33Qs3OYsot4rEx5gRBF5A+mRTDK/3P6kaH3tL4 5XO0/v2K2R6wn6nADe23uNlUdk/RZX+/lwMR41m6sMzDmfAgJ8/MKa+bilyuH3zN73RE DIOQ== X-Gm-Message-State: AOAM532y+czdmur2Sge+WUiwp3VmfqGQxyN+XkR6nExQCJKHI7edXzL+ yZFVDh3T9NH3gYgcKiTDsVRlzg== X-Google-Smtp-Source: ABdhPJzrK0LLFfEmW1FaUplFEamVlgxXEqyS3uWHskQBGTwsasixVrw7XmT0lIUUtZmVT3Il1hVzBg== X-Received: by 2002:a17:90a:5881:: with SMTP id j1mr618579pji.122.1621273119538; Mon, 17 May 2021 10:38:39 -0700 (PDT) Received: from xps15 (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id x22sm74809pjp.42.2021.05.17.10.38.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 10:38:38 -0700 (PDT) Date: Mon, 17 May 2021 11:38:36 -0600 From: Mathieu Poirier To: Mike Leach Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, suzuki.poulose@arm.com, leo.yan@linaro.org Subject: Re: [RFC PATCH 2/8] coresight: syscfg: Update load API for config loadable modules Message-ID: <20210517173836.GC498571@xps15> References: <20210512211752.4103-1-mike.leach@linaro.org> <20210512211752.4103-3-mike.leach@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210512211752.4103-3-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210517_103840_996245_FCD49E0E X-CRM114-Status: GOOD ( 30.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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, May 12, 2021 at 10:17:46PM +0100, Mike Leach wrote: > CoreSight configurations and features can be added as kernel loadable > modules. This patch updates the load owner API to ensure that the module > cannot be unloaded either:- Please remove the '-'. It is not a big issue but you can be sure the various patch robots will complain. With that: Reviewed-by: Mathieu Poirier > 1) if the config it supplies is in use > 2) if the module is not the last in the load order list. > > Signed-off-by: Mike Leach > --- > .../hwtracing/coresight/coresight-syscfg.c | 39 ++++++++++++++++++- > .../hwtracing/coresight/coresight-syscfg.h | 1 + > 2 files changed, 39 insertions(+), 1 deletion(-) > > diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c > index ab5ec43a9dad..26c1a244c2b1 100644 > --- a/drivers/hwtracing/coresight/coresight-syscfg.c > +++ b/drivers/hwtracing/coresight/coresight-syscfg.c > @@ -368,6 +368,26 @@ int cscfg_update_feat_param_val(struct cscfg_feature_desc *feat_desc, > return err; > } > > +/* > + * Conditionally up reference count on owner to prevent unload. > + * > + * module loaded configs need to be locked in to prevent premature unload. > + */ > +static int cscfg_owner_get(struct cscfg_load_owner_info *owner_info) > +{ > + if ((owner_info->type == CSCFG_OWNER_MODULE) && > + (!try_module_get(owner_info->owner_handle))) > + return -EINVAL; > + return 0; > +} > + > +/* conditionally lower ref count on an owner */ > +static void cscfg_owner_put(struct cscfg_load_owner_info *owner_info) > +{ > + if (owner_info->type == CSCFG_OWNER_MODULE) > + module_put(owner_info->owner_handle); > +} > + > static void cscfg_remove_owned_csdev_configs(struct coresight_device *csdev, void *load_owner) > { > struct cscfg_config_csdev *config_csdev, *tmp; > @@ -497,6 +517,14 @@ int cscfg_load_config_sets(struct cscfg_config_desc **config_descs, > > /* add the load owner to the load order list */ > list_add_tail(&owner_info->item, &cscfg_mgr->load_order_list); > + if (!list_is_singular(&cscfg_mgr->load_order_list)) { > + /* lock previous item in load order list */ > + err = cscfg_owner_get(list_prev_entry(owner_info, item)); > + if (err) { > + cscfg_unload_owned_cfgs_feats(owner_info); > + list_del(&owner_info->item); > + } > + } > > exit_unlock: > mutex_unlock(&cscfg_mutex); > @@ -547,7 +575,11 @@ int cscfg_unload_config_sets(struct cscfg_load_owner_info *owner_info) > cscfg_unload_owned_cfgs_feats(owner_info); > > /* remove from load order list */ > - list_del(&load_list_item->item); > + if (!list_is_singular(&cscfg_mgr->load_order_list)) { > + /* unlock previous item in load order list */ > + cscfg_owner_put(list_prev_entry(owner_info, item)); > + } > + list_del(&owner_info->item); > > exit_unlock: > mutex_unlock(&cscfg_mutex); > @@ -737,6 +769,10 @@ int cscfg_activate_config(unsigned long cfg_hash) > > list_for_each_entry(config_desc, &cscfg_mgr->config_desc_list, item) { > if ((unsigned long)config_desc->event_ea->var == cfg_hash) { > + /* must ensure that config cannot be unloaded in use */ > + err = cscfg_owner_get(config_desc->load_owner); > + if (err) > + break; > /* > * increment the global active count - control changes to > * active configurations > @@ -777,6 +813,7 @@ void cscfg_deactivate_config(unsigned long cfg_hash) > if ((unsigned long)config_desc->event_ea->var == cfg_hash) { > atomic_dec(&config_desc->active_cnt); > atomic_dec(&cscfg_mgr->sys_active_cnt); > + cscfg_owner_put(config_desc->load_owner); > dev_dbg(cscfg_device(), "Deactivate config %s.\n", config_desc->name); > break; > } > diff --git a/drivers/hwtracing/coresight/coresight-syscfg.h b/drivers/hwtracing/coresight/coresight-syscfg.h > index e2b2bdab31aa..1da37874f70f 100644 > --- a/drivers/hwtracing/coresight/coresight-syscfg.h > +++ b/drivers/hwtracing/coresight/coresight-syscfg.h > @@ -61,6 +61,7 @@ struct cscfg_registered_csdev { > /* owner types for loading and unloading of config and feature sets */ > enum cscfg_load_owner_type { > CSCFG_OWNER_PRELOAD, > + CSCFG_OWNER_MODULE, > }; > > /** > -- > 2.17.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel