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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F224DC433F5 for ; Wed, 24 Nov 2021 20:02:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2LxVYctK8NNMSZSvxKAyMnzcfuewAsp0SFl4d0AWCps=; b=PgDj0tC4374YmW 1DDBLeCHY7UY+Wewh+N5l4VmA2eM+m4bPR85kvCc61kNYs0LJ/TAeeTkbeqpcHMSe2D3Kis7sNtEQ yUn5uBnMMIaQ03Yww/368Ly3PCuDQA4eiPLjTU7Fl5Z2HbVakiQ0OMG0LrFBVSvIGSFAvhXPiFDPs 9sjklaTcesT+c/oh+VM4Gm7m3cEIFC/pJ8uheZJgcWP3E/WmWI80w6fBOQJIx/BYoHyuxXQsLMRUI ynAkNKRbupj9ECNB2gfMHlNb+WQq8qYAgt/owZE+kxVajdPNBKD4VFM2v8uHCZjCZ35xBQhI3wUd/ m2Mo/VniLFtukRuceyNg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpyS3-005jYn-7l; Wed, 24 Nov 2021 20:01:07 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpyRj-005jRf-SO for linux-arm-kernel@lists.infradead.org; Wed, 24 Nov 2021 20:00:50 +0000 Received: by mail-wm1-x333.google.com with SMTP id j140-20020a1c2392000000b003399ae48f58so6444006wmj.5 for ; Wed, 24 Nov 2021 12:00:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eWnAOXeTWHv5g/Zw8GpYlbjwgfeIh+MuISMvOPyPsqM=; b=R+uOzWsIpLrj4XRjiCTN5/MxmCvIB8WRvV3dDsY/DUo7j17QoI7bCBJOn3drhBBKdh /jLma7SAad4lZrwg4aNlve6Z9Ce5iwdQPWj7m7lR3bAW5sT11WXAX2VYrRD2mZbXNOr2 BS5Ol7BivQtIKA4JW0kb1H2HGRi2/F0bgb/ZRkXjaG080p5KvqyGOqMJsB89s1Lr9ezo zoJfwcLVKDvVEq8XS9Vb+Cy3SZo6l2dRcyiUydFQIRf1QYJiDRlTtnYKV/Byio3LJHWH 5MQ7AD2wlIlVqnEpMnwPJbLfKdTkYquRGfQKBTThP1XWsqFKqpyE3KWKLq5BkeMol9Ku O3yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=eWnAOXeTWHv5g/Zw8GpYlbjwgfeIh+MuISMvOPyPsqM=; b=P/kEWcz286RMY+ktqI684mEsuNXYDNpEa2TYvQFhWzx/wLULcdyeK4HhegYJfIPi29 qW+fEsA9qhA8hU1VX8f1UP0EgZjDDKyGriN0GkBPOtow+5ZOVRwVgtOrtcRs4SOPWHc8 w0Q55dT9IsQHNmgnsEWk5bN3wrX1Lln3A6GzbLnsMsHIzqDV6JwwFXBHDw4TbOJ/wWzt Cn1M76XKD/rexa4aCtxXEDgWaZSpNtqJbWOs+/rSyB/DnC9r7+Q7l+zQUe5xCfFvXSx9 DucAncR1bFFpGoTJJvZTX1eiXVTlh1IEpFzIgg+BszkxUdQypfJJR4be7PXV71Vkd7fN 9N5g== X-Gm-Message-State: AOAM532a5BJZ56PGlUYBdGD87/3LF6TGKw13pP05AW+fAGMmQvKQ76tZ u18gweaGMTzuo4ojoX/QO8gw5JMCsZgjjQ== X-Google-Smtp-Source: ABdhPJwslDz/nliWp2/zM7MsCGeeWaGzlqy7nbiHEqeJNOrsBCyorsxKAhP+O4ne1zEjiezMxaZAGQ== X-Received: by 2002:a1c:7201:: with SMTP id n1mr18720850wmc.176.1637784046375; Wed, 24 Nov 2021 12:00:46 -0800 (PST) Received: from linaro.org ([2a00:23c5:6809:2201:dd2e:a6e1:6adf:269c]) by smtp.gmail.com with ESMTPSA id c1sm729582wrt.14.2021.11.24.12.00.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 12:00:46 -0800 (PST) From: Mike Leach To: linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Cc: mathieu.poirier@linaro.org, suzuki.poulose@arm.com, leo.yan@linaro.org, Mike Leach Subject: [PATCH v3 3/6] coresight: syscfg: Update load API for config loadable modules Date: Wed, 24 Nov 2021 20:00:35 +0000 Message-Id: <20211124200038.28662-4-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211124200038.28662-1-mike.leach@linaro.org> References: <20211124200038.28662-1-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211124_120047_939956_AC32A3DD X-CRM114-Status: GOOD ( 19.06 ) 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: , MIME-Version: 1.0 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 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 Reviewed-by: Mathieu Poirier --- .../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 8bff7da1aab2..678ee8250d85 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); @@ -739,6 +771,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 @@ -779,6 +815,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