Skip to content

Commit 9321666

Browse files
committed
coresight: syscfg: Update load API for config loadable modules
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2055405 commit eb2ec49 Author: Mike Leach <mike.leach@linaro.org> Date: Wed Nov 24 20:00:35 2021 +0000 coresight: syscfg: Update load API for config loadable modules 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> Link: https://lore.kernel.org/r/20211124200038.28662-4-mike.leach@linaro.org Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org> Signed-off-by: Jeremy Linton <jlinton@redhat.com>
1 parent 27bb7fa commit 9321666

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

drivers/hwtracing/coresight/coresight-syscfg.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,26 @@ int cscfg_update_feat_param_val(struct cscfg_feature_desc *feat_desc,
368368
return err;
369369
}
370370

371+
/*
372+
* Conditionally up reference count on owner to prevent unload.
373+
*
374+
* module loaded configs need to be locked in to prevent premature unload.
375+
*/
376+
static int cscfg_owner_get(struct cscfg_load_owner_info *owner_info)
377+
{
378+
if ((owner_info->type == CSCFG_OWNER_MODULE) &&
379+
(!try_module_get(owner_info->owner_handle)))
380+
return -EINVAL;
381+
return 0;
382+
}
383+
384+
/* conditionally lower ref count on an owner */
385+
static void cscfg_owner_put(struct cscfg_load_owner_info *owner_info)
386+
{
387+
if (owner_info->type == CSCFG_OWNER_MODULE)
388+
module_put(owner_info->owner_handle);
389+
}
390+
371391
static void cscfg_remove_owned_csdev_configs(struct coresight_device *csdev, void *load_owner)
372392
{
373393
struct cscfg_config_csdev *config_csdev, *tmp;
@@ -497,6 +517,14 @@ int cscfg_load_config_sets(struct cscfg_config_desc **config_descs,
497517

498518
/* add the load owner to the load order list */
499519
list_add_tail(&owner_info->item, &cscfg_mgr->load_order_list);
520+
if (!list_is_singular(&cscfg_mgr->load_order_list)) {
521+
/* lock previous item in load order list */
522+
err = cscfg_owner_get(list_prev_entry(owner_info, item));
523+
if (err) {
524+
cscfg_unload_owned_cfgs_feats(owner_info);
525+
list_del(&owner_info->item);
526+
}
527+
}
500528

501529
exit_unlock:
502530
mutex_unlock(&cscfg_mutex);
@@ -547,7 +575,11 @@ int cscfg_unload_config_sets(struct cscfg_load_owner_info *owner_info)
547575
cscfg_unload_owned_cfgs_feats(owner_info);
548576

549577
/* remove from load order list */
550-
list_del(&load_list_item->item);
578+
if (!list_is_singular(&cscfg_mgr->load_order_list)) {
579+
/* unlock previous item in load order list */
580+
cscfg_owner_put(list_prev_entry(owner_info, item));
581+
}
582+
list_del(&owner_info->item);
551583

552584
exit_unlock:
553585
mutex_unlock(&cscfg_mutex);
@@ -739,6 +771,10 @@ int cscfg_activate_config(unsigned long cfg_hash)
739771

740772
list_for_each_entry(config_desc, &cscfg_mgr->config_desc_list, item) {
741773
if ((unsigned long)config_desc->event_ea->var == cfg_hash) {
774+
/* must ensure that config cannot be unloaded in use */
775+
err = cscfg_owner_get(config_desc->load_owner);
776+
if (err)
777+
break;
742778
/*
743779
* increment the global active count - control changes to
744780
* active configurations
@@ -779,6 +815,7 @@ void cscfg_deactivate_config(unsigned long cfg_hash)
779815
if ((unsigned long)config_desc->event_ea->var == cfg_hash) {
780816
atomic_dec(&config_desc->active_cnt);
781817
atomic_dec(&cscfg_mgr->sys_active_cnt);
818+
cscfg_owner_put(config_desc->load_owner);
782819
dev_dbg(cscfg_device(), "Deactivate config %s.\n", config_desc->name);
783820
break;
784821
}

drivers/hwtracing/coresight/coresight-syscfg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct cscfg_registered_csdev {
6161
/* owner types for loading and unloading of config and feature sets */
6262
enum cscfg_load_owner_type {
6363
CSCFG_OWNER_PRELOAD,
64+
CSCFG_OWNER_MODULE,
6465
};
6566

6667
/**

0 commit comments

Comments
 (0)