From: Mike Leach <mike.leach@linaro.org>
To: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org, mathieu.poirier@linaro.org,
suzuki.poulose@arm.com, leo.yan@linaro.org,
Mike Leach <mike.leach@linaro.org>
Subject: [RFC PATCH 2/8] coresight: syscfg: Update load API for config loadable modules
Date: Wed, 12 May 2021 22:17:46 +0100 [thread overview]
Message-ID: <20210512211752.4103-3-mike.leach@linaro.org> (raw)
In-Reply-To: <20210512211752.4103-1-mike.leach@linaro.org>
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:-
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 <mike.leach@linaro.org>
---
.../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
next prev parent reply other threads:[~2021-05-12 21:21 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-12 21:17 [RFC PATCH 0/8] coresight: syscfg: dynamic load, resource management Mike Leach
2021-05-12 21:17 ` [RFC PATCH 1/8] coresight: syscfg: Update API to allow dynamic load and unload Mike Leach
2021-05-17 17:15 ` Mathieu Poirier
2021-05-17 17:27 ` Mathieu Poirier
2021-05-19 13:28 ` Mike Leach
2021-05-12 21:17 ` Mike Leach [this message]
2021-05-17 17:38 ` [RFC PATCH 2/8] coresight: syscfg: Update load API for config loadable modules Mathieu Poirier
2021-05-12 21:17 ` [RFC PATCH 3/8] coresight: syscfg: Example CoreSight configuration loadable module Mike Leach
2021-05-18 15:52 ` Mathieu Poirier
2021-05-18 16:38 ` Mike Leach
2021-05-18 21:15 ` Mathieu Poirier
2021-05-12 21:17 ` [RFC PATCH 4/8] coresight: configfs: Allow configfs to activate configuration Mike Leach
2021-05-18 19:36 ` Mathieu Poirier
2021-05-19 9:47 ` Mike Leach
2021-05-12 21:17 ` [RFC PATCH 5/8] coresight: syscfg: Add API to check and validate device resources Mike Leach
2021-05-21 17:56 ` Mathieu Poirier
2021-07-08 16:30 ` Mike Leach
2021-05-12 21:17 ` [RFC PATCH 6/8] coresight: etm4x: syscfg: Add resource management to etm4x Mike Leach
2021-05-26 17:51 ` Mathieu Poirier
2021-05-27 17:41 ` Mathieu Poirier
2021-05-28 16:17 ` Mathieu Poirier
2021-07-09 9:32 ` Mike Leach
2021-05-12 21:17 ` [RFC PATCH 7/8] coresight: etm4x: Update perf event resource handling Mike Leach
2021-05-12 21:17 ` [RFC PATCH 8/8] coresight: etm4x: Update configuration example Mike Leach
2021-05-13 15:56 ` [RFC PATCH 0/8] coresight: syscfg: dynamic load, resource management Mathieu Poirier
2021-05-13 16:53 ` Mike Leach
2021-05-14 1:35 ` Leo Yan
2021-05-18 18:31 ` Suzuki K Poulose
2021-05-19 9:43 ` Mike Leach
2021-05-19 15:37 ` Mathieu Poirier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210512211752.4103-3-mike.leach@linaro.org \
--to=mike.leach@linaro.org \
--cc=coresight@lists.linaro.org \
--cc=leo.yan@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mathieu.poirier@linaro.org \
--cc=suzuki.poulose@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).