From patchwork Wed Nov 24 20:00:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12693580 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 05C83C433F5 for ; Wed, 24 Nov 2021 20:02:49 +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=5naMioADX4Vulpw+2+IFkXjCZmCtHZe3BI2lK+1iEco=; b=SvN7WwCIjqUsnS eHrbZiqnWV9n6AnSbCjrjz8k2K65ifL1m7DoGSj+C37lE6VIWLqUlEiAzoR8NVI638e+v5o0Y291+ /1YfUCcBB+jBr0gtFn2Ye6CUliXGaQ1YHMDqVmB4WZWsYws3NnTHarNilAImTy7GvNb3QwCbcdAV9 WHMuUHz/OT4hydHoajY/gtyTQMuZkWghZi+Bt7sh3f9AFno8Ua0IdaTWR7TnwbbOoHbTA155lLMnF 5v6FERRshGZlnx2a83pZVIoZ/VAzCCvKagrVXcF4HhYFzKJLCP849RUqg9JxAWbNJoUQir87dTK6b T9WZV4Iwv3GHi26yabsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpySH-005jcv-VF; Wed, 24 Nov 2021 20:01:22 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpyRi-005jR2-NZ for linux-arm-kernel@lists.infradead.org; Wed, 24 Nov 2021 20:00:50 +0000 Received: by mail-wm1-x32f.google.com with SMTP id p18so3540122wmq.5 for ; Wed, 24 Nov 2021 12:00:46 -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=7rZS4dOBAE84jxXnsOA/aw9s5xT/+bW788bYxm22cWA=; b=Z5ooGUYX0gzFRcCGHFuOFBSiM5I+hGsU3R0QlNVlunqZqL0WL8HtfgGsZs7cs9QCPe 4g95j1WOa5YzzZlLL+/y9YjzfpvOlOKdX9mXy0mGoJB5rIuUFUd+PAxBYpAeUHSuSlKR 7uyXx7OewK00pMc+scDAj8Zd35lSh9Y8AdaNDCb5lz0TV9p3pwEaCc3b3iAC2qJZefw+ SzAJkeim8QFSoZHsEIKkcqTa5CGIah1D/+Xdb0G7ib6hXfFdCTOU2nkWpxz+DySxsTE9 oF5H6PA768s23v8nNBGGhi7ocbbX71r7kVrY+4hgtBdTrQD8SZRmmse0c1kZP98EuOeT tRmA== 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=7rZS4dOBAE84jxXnsOA/aw9s5xT/+bW788bYxm22cWA=; b=QQEh+H42c+7kvOM205mYZW4x+K+ig4dwEOmjGbcc84IzfJdSQkchgLa9/UlwD3j3Vz gt3cwYVUDC6vLjyvjIFqSW+8psiSkbDG42AR5hpCTlS4/C7HEF2R0ku88G2kExZaS0Qu 3+RnBHoScI+nnx4QXfUfIOqG1O0GMU5HpxXymaRMUrf5H8zEQs6kOqG9YTCDoZDBskWu Z6P8YRJpUpBVwhIOc1Wjyzz3snbx5IcQoFi4S98iNVlr7hlwQz2ZHtmpaFVImM1D8Pdk 5+EVhndvsU1kvGkcyW/+i2+P2hy5NbIpxBW/fwe/9k0I/ncoTpoU5EqeUCuythjVgMW/ YrUA== X-Gm-Message-State: AOAM532aPamFndm6QHYq8hlE9VPpJZ0gf/cPQ210ejQ6NnbYlWBHgM6S mpI6cPTWQZNcZZMr5qJugDSHo+4/h9v3AQ== X-Google-Smtp-Source: ABdhPJwgtgvUG7IxJTbJLddfeqRWi8/eV6Kj7T53qJo55RzMZasFIsDrx53cJ7FYfPr3LJ7I94wx1w== X-Received: by 2002:a1c:96:: with SMTP id 144mr19029359wma.126.1637784045065; Wed, 24 Nov 2021 12:00:45 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 12:00:44 -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 1/6] coresight: configuration: Update API to introduce load owner concept Date: Wed, 24 Nov 2021 20:00:33 +0000 Message-Id: <20211124200038.28662-2-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_120046_813619_870A35C9 X-CRM114-Status: GOOD ( 22.72 ) 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 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Update the existing load API to introduce a "load owner" concept. This allows the tracking of the loaded configurations and features against the loading owner type, to allow later unload according to owner. A list of loaded configurations by owner is created. The load owner infrastructure will be used in following patches to implement dynanic load and unload, alongside dependency tracking. Signed-off-by: Mike Leach Reviewed-by: Mathieu Poirier --- .../coresight/coresight-cfg-preload.c | 9 ++++-- .../hwtracing/coresight/coresight-config.h | 5 +++- .../hwtracing/coresight/coresight-syscfg.c | 21 ++++++++++++-- .../hwtracing/coresight/coresight-syscfg.h | 29 +++++++++++++++++-- 4 files changed, 56 insertions(+), 8 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-cfg-preload.c b/drivers/hwtracing/coresight/coresight-cfg-preload.c index 751af3710d56..e237a4edfa09 100644 --- a/drivers/hwtracing/coresight/coresight-cfg-preload.c +++ b/drivers/hwtracing/coresight/coresight-cfg-preload.c @@ -24,8 +24,13 @@ static struct cscfg_config_desc *preload_cfgs[] = { NULL }; +static struct cscfg_load_owner_info preload_owner = { + .type = CSCFG_OWNER_PRELOAD, +}; + /* preload called on initialisation */ -int cscfg_preload(void) +int cscfg_preload(void *owner_handle) { - return cscfg_load_config_sets(preload_cfgs, preload_feats); + preload_owner.owner_handle = owner_handle; + return cscfg_load_config_sets(preload_cfgs, preload_feats, &preload_owner); } diff --git a/drivers/hwtracing/coresight/coresight-config.h b/drivers/hwtracing/coresight/coresight-config.h index 25eb6c632692..6e0d43901d66 100644 --- a/drivers/hwtracing/coresight/coresight-config.h +++ b/drivers/hwtracing/coresight/coresight-config.h @@ -97,6 +97,7 @@ struct cscfg_regval_desc { * @params_desc: array of parameters used. * @nr_regs: number of registers used. * @regs_desc: array of registers used. + * @load_owner: handle to load owner for dynamic load and unload of features. */ struct cscfg_feature_desc { const char *name; @@ -107,6 +108,7 @@ struct cscfg_feature_desc { struct cscfg_parameter_desc *params_desc; int nr_regs; struct cscfg_regval_desc *regs_desc; + void *load_owner; }; /** @@ -128,7 +130,7 @@ struct cscfg_feature_desc { * @presets: Array of preset values. * @event_ea: Extended attribute for perf event value * @active_cnt: ref count for activate on this configuration. - * + * @load_owner: handle to load owner for dynamic load and unload of configs. */ struct cscfg_config_desc { const char *name; @@ -141,6 +143,7 @@ struct cscfg_config_desc { const u64 *presets; /* nr_presets * nr_total_params */ struct dev_ext_attribute *event_ea; atomic_t active_cnt; + void *load_owner; }; /** diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c index 43054568430f..021f50949d7b 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.c +++ b/drivers/hwtracing/coresight/coresight-syscfg.c @@ -361,13 +361,22 @@ int cscfg_update_feat_param_val(struct cscfg_feature_desc *feat_desc, * descriptors and load into the system. * Features are loaded first to ensure configuration dependencies can be met. * + * To facilitate dynamic loading and unloading, features and configurations + * have a "load_owner", to allow later unload by the same owner. An owner may + * be a loadable module or configuration dynamically created via configfs. + * As later loaded configurations can use earlier loaded features, creating load + * dependencies, a load order list is maintained. Unload is strictly in the + * reverse order to load. + * * @config_descs: 0 terminated array of configuration descriptors. * @feat_descs: 0 terminated array of feature descriptors. + * @owner_info: Information on the owner of this set. */ int cscfg_load_config_sets(struct cscfg_config_desc **config_descs, - struct cscfg_feature_desc **feat_descs) + struct cscfg_feature_desc **feat_descs, + struct cscfg_load_owner_info *owner_info) { - int err, i = 0; + int err = 0, i = 0; mutex_lock(&cscfg_mutex); @@ -382,6 +391,7 @@ int cscfg_load_config_sets(struct cscfg_config_desc **config_descs, feat_descs[i]->name); goto exit_unlock; } + feat_descs[i]->load_owner = owner_info; i++; } } @@ -398,10 +408,14 @@ int cscfg_load_config_sets(struct cscfg_config_desc **config_descs, config_descs[i]->name); goto exit_unlock; } + config_descs[i]->load_owner = owner_info; i++; } } + /* add the load owner to the load order list */ + list_add_tail(&owner_info->item, &cscfg_mgr->load_order_list); + exit_unlock: mutex_unlock(&cscfg_mutex); return err; @@ -827,10 +841,11 @@ int __init cscfg_init(void) INIT_LIST_HEAD(&cscfg_mgr->csdev_desc_list); INIT_LIST_HEAD(&cscfg_mgr->feat_desc_list); INIT_LIST_HEAD(&cscfg_mgr->config_desc_list); + INIT_LIST_HEAD(&cscfg_mgr->load_order_list); atomic_set(&cscfg_mgr->sys_active_cnt, 0); /* preload built-in configurations */ - err = cscfg_preload(); + err = cscfg_preload(THIS_MODULE); if (err) goto exit_err; diff --git a/drivers/hwtracing/coresight/coresight-syscfg.h b/drivers/hwtracing/coresight/coresight-syscfg.h index 8d018efd6ead..08067e89edcf 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.h +++ b/drivers/hwtracing/coresight/coresight-syscfg.h @@ -25,6 +25,7 @@ * @csdev_desc_list: List of coresight devices registered with the configuration manager. * @feat_desc_list: List of feature descriptors to load into registered devices. * @config_desc_list: List of system configuration descriptors to load into registered devices. + * @load_order_list: Ordered list of owners for dynamically loaded configurations. * @sys_active_cnt: Total number of active config descriptor references. * @cfgfs_subsys: configfs subsystem used to manage configurations. */ @@ -33,6 +34,7 @@ struct cscfg_manager { struct list_head csdev_desc_list; struct list_head feat_desc_list; struct list_head config_desc_list; + struct list_head load_order_list; atomic_t sys_active_cnt; struct configfs_subsystem cfgfs_subsys; }; @@ -56,10 +58,32 @@ struct cscfg_registered_csdev { struct list_head item; }; +/* owner types for loading and unloading of config and feature sets */ +enum cscfg_load_owner_type { + CSCFG_OWNER_PRELOAD, +}; + +/** + * Load item - item to add to the load order list allowing dynamic load and + * unload of configurations and features. Caller loading a config + * set provides a context handle for unload. API ensures that + * items unloaded strictly in reverse order from load to ensure + * dependencies are respected. + * + * @item: list entry for load order list. + * @type: type of owner - allows interpretation of owner_handle. + * @owner_handle: load context - handle for owner of loaded configs. + */ +struct cscfg_load_owner_info { + struct list_head item; + int type; + void *owner_handle; +}; + /* internal core operations for cscfg */ int __init cscfg_init(void); void cscfg_exit(void); -int cscfg_preload(void); +int cscfg_preload(void *owner_handle); const struct cscfg_feature_desc *cscfg_get_named_feat_desc(const char *name); int cscfg_update_feat_param_val(struct cscfg_feature_desc *feat_desc, int param_idx, u64 value); @@ -67,7 +91,8 @@ int cscfg_update_feat_param_val(struct cscfg_feature_desc *feat_desc, /* syscfg manager external API */ int cscfg_load_config_sets(struct cscfg_config_desc **cfg_descs, - struct cscfg_feature_desc **feat_descs); + struct cscfg_feature_desc **feat_descs, + struct cscfg_load_owner_info *owner_info); int cscfg_register_csdev(struct coresight_device *csdev, u32 match_flags, struct cscfg_csdev_feat_ops *ops); void cscfg_unregister_csdev(struct coresight_device *csdev); From patchwork Wed Nov 24 20:00:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12693582 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 3529CC433F5 for ; Wed, 24 Nov 2021 20:03:26 +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=GpDLARbNcxRnkdyhl1lP/74yFS/RbbWvOmbp+habE4I=; b=tClL4SijAYicw5 QxodyYvL6GG+pXNcwn5/5PU7tzsOgcCDoFYSKXyXURxl6xA1XEyZLM06+2A1Ws1v3+hcHiOXixjAY DkMd+aybcFn3tEht+lPgSLc56JY1cTT3p5YrfTzhky4q+eOzN50YR5Da0LvtHTAVYs3dThoe4DdkU xBvq+uKLggX3Z66v2pqTMZdR4FT8VjOiMCUtBIHAayG6e6e12T3oX1leehH8AFNH5Qqb9T7JciBuN xSkmq+bEXi+nfKsZwxI8Mi8smpOa2FQeog9Wy/2QU/ifWEa84sspRqAwLdNhFvW/avLUYlMBfCWfr RjhN3Kawtais/qTsvRvQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpySo-005jnS-4h; Wed, 24 Nov 2021 20:01:54 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpyRj-005jR8-9J for linux-arm-kernel@lists.infradead.org; Wed, 24 Nov 2021 20:00:50 +0000 Received: by mail-wm1-x331.google.com with SMTP id g191-20020a1c9dc8000000b0032fbf912885so3041788wme.4 for ; Wed, 24 Nov 2021 12:00:46 -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=/0sMKWlKHEGZZmerIoHeR8BNRmG+vaThpY3WRjo3Zws=; b=Omi55R0pLvpbOWRiQO+nAkuCp28dkIRdD62u6JXh+dxF7diALeguN5XBlYx4fpRVzy BBZUc+555KUoVH2jyl+LvaFLJKPSF9bTKZk8VlgPIXPZeTf0rz74RNnTahBRX8D2SJ07 h5XqQVBJMlnX+U5txG8RjYn204PZ1iKIRa0BWyYlw9GioKGTefAOwD0DsrIfYMmYpVvk cgMYk7wCukeDz9WBsh7WKMxohEIC/aouazKGZDAAwzf6TXmBrWNMThL0ykCcH0uUgHKA B7gldXzYwVxNWIEH65KY9iHG6vEgg6nI6tff5s8xVrJ6D02j8hVgxm4DWY4jHuiXfjIN sD6w== 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=/0sMKWlKHEGZZmerIoHeR8BNRmG+vaThpY3WRjo3Zws=; b=NQdwJwrQwmJFEq3F2kwWx1Q3jo/S5VrRD0vr/RyDrW9FyvKv04Jzn5zKDF/lX6f2K1 n+zBTiE0wLE+7FlCoGqAA9wVRCuJ++j7OnelmOzgpO4ph7/xKvT2IFUTYjzc05ktK6pn J9nH1lxq0QmdJiawCngruvG+EF0iuT+HluGqXv+AVZ9/fWVsGEYqpUdzYrb1GOioc96H 37M6KJiQQvrpdz538WzK8xcXijh3hNO6JOTLS3ucIdsg+n51s9xPLvPsSiMZnhXFZkoF tQtXel82hy7LnkDtyAyX/ghtY+Dw26lYBh0S03eZs2x4ifUO0Q7PhXTmsU/4/ACsbfkD 0/6w== X-Gm-Message-State: AOAM531MQt9eyfJEGb4zjRrdWwrqsWYL8GLT4agbMGz+mFnTSHOzSCOU cnIDUY2iNft8s56SibwvLrA9AW61heeDKQ== X-Google-Smtp-Source: ABdhPJyg1oqq9yUFZVWxmulIuQZyc52d2DpdnZyacyAYKCU4YqgL37Lyt37wK0DGAS4wVUaTfBmVUg== X-Received: by 2002:a7b:c119:: with SMTP id w25mr18838670wmi.70.1637784045768; Wed, 24 Nov 2021 12:00:45 -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:45 -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 2/6] coresight: configuration: Update API to permit dynamic load/unload Date: Wed, 24 Nov 2021 20:00:34 +0000 Message-Id: <20211124200038.28662-3-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_359390_449C0F3C X-CRM114-Status: GOOD ( 25.19 ) 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 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Expand the configuration API to allow dynamic runtime load and unload of configurations and features. On load, configurations and features are tagged with a "load owner" that is used to determine sets that were loaded together in a given API call. To unload the API uses the load owner to unload all elements previously loaded by that owner. The API also records the order in which different owners loaded their elements into the system. Later loading configurations can use previously loaded features, creating load dependencies. Therefore unload is enforced strictly in the reverse order to load. A load owner will be an additional loadable module, or a configuration loaded via configfs. Signed-off-by: Mike Leach Reviewed-by: Mathieu Poirier --- .../hwtracing/coresight/coresight-config.h | 4 + .../coresight/coresight-syscfg-configfs.c | 20 +++ .../coresight/coresight-syscfg-configfs.h | 2 + .../hwtracing/coresight/coresight-syscfg.c | 133 ++++++++++++++++++ .../hwtracing/coresight/coresight-syscfg.h | 1 + 5 files changed, 160 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-config.h b/drivers/hwtracing/coresight/coresight-config.h index 6e0d43901d66..9bd44b940add 100644 --- a/drivers/hwtracing/coresight/coresight-config.h +++ b/drivers/hwtracing/coresight/coresight-config.h @@ -98,6 +98,7 @@ struct cscfg_regval_desc { * @nr_regs: number of registers used. * @regs_desc: array of registers used. * @load_owner: handle to load owner for dynamic load and unload of features. + * @fs_group: reference to configfs group for dynamic unload. */ struct cscfg_feature_desc { const char *name; @@ -109,6 +110,7 @@ struct cscfg_feature_desc { int nr_regs; struct cscfg_regval_desc *regs_desc; void *load_owner; + struct config_group *fs_group; }; /** @@ -131,6 +133,7 @@ struct cscfg_feature_desc { * @event_ea: Extended attribute for perf event value * @active_cnt: ref count for activate on this configuration. * @load_owner: handle to load owner for dynamic load and unload of configs. + * @fs_group: reference to configfs group for dynamic unload. */ struct cscfg_config_desc { const char *name; @@ -144,6 +147,7 @@ struct cscfg_config_desc { struct dev_ext_attribute *event_ea; atomic_t active_cnt; void *load_owner; + struct config_group *fs_group; }; /** diff --git a/drivers/hwtracing/coresight/coresight-syscfg-configfs.c b/drivers/hwtracing/coresight/coresight-syscfg-configfs.c index c547816b9000..345a62f1b728 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg-configfs.c +++ b/drivers/hwtracing/coresight/coresight-syscfg-configfs.c @@ -334,9 +334,19 @@ int cscfg_configfs_add_config(struct cscfg_config_desc *config_desc) if (IS_ERR(new_group)) return PTR_ERR(new_group); err = configfs_register_group(&cscfg_configs_grp, new_group); + if (!err) + config_desc->fs_group = new_group; return err; } +void cscfg_configfs_del_config(struct cscfg_config_desc *config_desc) +{ + if (config_desc->fs_group) { + configfs_unregister_group(config_desc->fs_group); + config_desc->fs_group = NULL; + } +} + static struct config_item_type cscfg_features_type = { .ct_owner = THIS_MODULE, }; @@ -358,9 +368,19 @@ int cscfg_configfs_add_feature(struct cscfg_feature_desc *feat_desc) if (IS_ERR(new_group)) return PTR_ERR(new_group); err = configfs_register_group(&cscfg_features_grp, new_group); + if (!err) + feat_desc->fs_group = new_group; return err; } +void cscfg_configfs_del_feature(struct cscfg_feature_desc *feat_desc) +{ + if (feat_desc->fs_group) { + configfs_unregister_group(feat_desc->fs_group); + feat_desc->fs_group = NULL; + } +} + int cscfg_configfs_init(struct cscfg_manager *cscfg_mgr) { struct configfs_subsystem *subsys; diff --git a/drivers/hwtracing/coresight/coresight-syscfg-configfs.h b/drivers/hwtracing/coresight/coresight-syscfg-configfs.h index 7d6ffe35ca4c..ea1e54d29f7f 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg-configfs.h +++ b/drivers/hwtracing/coresight/coresight-syscfg-configfs.h @@ -41,5 +41,7 @@ int cscfg_configfs_init(struct cscfg_manager *cscfg_mgr); void cscfg_configfs_release(struct cscfg_manager *cscfg_mgr); int cscfg_configfs_add_config(struct cscfg_config_desc *config_desc); int cscfg_configfs_add_feature(struct cscfg_feature_desc *feat_desc); +void cscfg_configfs_del_config(struct cscfg_config_desc *config_desc); +void cscfg_configfs_del_feature(struct cscfg_feature_desc *feat_desc); #endif /* CORESIGHT_SYSCFG_CONFIGFS_H */ diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c index 021f50949d7b..8bff7da1aab2 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.c +++ b/drivers/hwtracing/coresight/coresight-syscfg.c @@ -250,6 +250,13 @@ static int cscfg_check_feat_for_cfg(struct cscfg_config_desc *config_desc) static int cscfg_load_feat(struct cscfg_feature_desc *feat_desc) { int err; + struct cscfg_feature_desc *feat_desc_exist; + + /* new feature must have unique name */ + list_for_each_entry(feat_desc_exist, &cscfg_mgr->feat_desc_list, item) { + if (!strcmp(feat_desc_exist->name, feat_desc->name)) + return -EEXIST; + } /* add feature to any matching registered devices */ err = cscfg_add_feat_to_csdevs(feat_desc); @@ -267,6 +274,13 @@ static int cscfg_load_feat(struct cscfg_feature_desc *feat_desc) static int cscfg_load_config(struct cscfg_config_desc *config_desc) { int err; + struct cscfg_config_desc *config_desc_exist; + + /* new configuration must have a unique name */ + list_for_each_entry(config_desc_exist, &cscfg_mgr->config_desc_list, item) { + if (!strcmp(config_desc_exist->name, config_desc->name)) + return -EEXIST; + } /* validate features are present */ err = cscfg_check_feat_for_cfg(config_desc); @@ -354,6 +368,72 @@ int cscfg_update_feat_param_val(struct cscfg_feature_desc *feat_desc, return err; } +static void cscfg_remove_owned_csdev_configs(struct coresight_device *csdev, void *load_owner) +{ + struct cscfg_config_csdev *config_csdev, *tmp; + + if (list_empty(&csdev->config_csdev_list)) + return; + + list_for_each_entry_safe(config_csdev, tmp, &csdev->config_csdev_list, node) { + if (config_csdev->config_desc->load_owner == load_owner) + list_del(&config_csdev->node); + } +} + +static void cscfg_remove_owned_csdev_features(struct coresight_device *csdev, void *load_owner) +{ + struct cscfg_feature_csdev *feat_csdev, *tmp; + + if (list_empty(&csdev->feature_csdev_list)) + return; + + list_for_each_entry_safe(feat_csdev, tmp, &csdev->feature_csdev_list, node) { + if (feat_csdev->feat_desc->load_owner == load_owner) + list_del(&feat_csdev->node); + } +} + +/* + * removal is relatively easy - just remove from all lists, anything that + * matches the owner. Memory for the descriptors will be managed by the owner, + * memory for the csdev items is devm_ allocated with the individual csdev + * devices. + */ +static void cscfg_unload_owned_cfgs_feats(void *load_owner) +{ + struct cscfg_config_desc *config_desc, *cfg_tmp; + struct cscfg_feature_desc *feat_desc, *feat_tmp; + struct cscfg_registered_csdev *csdev_item; + + /* remove from each csdev instance feature and config lists */ + list_for_each_entry(csdev_item, &cscfg_mgr->csdev_desc_list, item) { + /* + * for each csdev, check the loaded lists and remove if + * referenced descriptor is owned + */ + cscfg_remove_owned_csdev_configs(csdev_item->csdev, load_owner); + cscfg_remove_owned_csdev_features(csdev_item->csdev, load_owner); + } + + /* remove from the config descriptor lists */ + list_for_each_entry_safe(config_desc, cfg_tmp, &cscfg_mgr->config_desc_list, item) { + if (config_desc->load_owner == load_owner) { + cscfg_configfs_del_config(config_desc); + etm_perf_del_symlink_cscfg(config_desc); + list_del(&config_desc->item); + } + } + + /* remove from the feature descriptor lists */ + list_for_each_entry_safe(feat_desc, feat_tmp, &cscfg_mgr->feat_desc_list, item) { + if (feat_desc->load_owner == load_owner) { + cscfg_configfs_del_feature(feat_desc); + list_del(&feat_desc->item); + } + } +} + /** * cscfg_load_config_sets - API function to load feature and config sets. * @@ -389,6 +469,7 @@ int cscfg_load_config_sets(struct cscfg_config_desc **config_descs, if (err) { pr_err("coresight-syscfg: Failed to load feature %s\n", feat_descs[i]->name); + cscfg_unload_owned_cfgs_feats(owner_info); goto exit_unlock; } feat_descs[i]->load_owner = owner_info; @@ -406,6 +487,7 @@ int cscfg_load_config_sets(struct cscfg_config_desc **config_descs, if (err) { pr_err("coresight-syscfg: Failed to load configuration %s\n", config_descs[i]->name); + cscfg_unload_owned_cfgs_feats(owner_info); goto exit_unlock; } config_descs[i]->load_owner = owner_info; @@ -422,6 +504,57 @@ int cscfg_load_config_sets(struct cscfg_config_desc **config_descs, } EXPORT_SYMBOL_GPL(cscfg_load_config_sets); +/** + * cscfg_unload_config_sets - unload a set of configurations by owner. + * + * Dynamic unload of configuration and feature sets is done on the basis of + * the load owner of that set. Later loaded configurations can depend on + * features loaded earlier. + * + * Therefore, unload is only possible if:- + * 1) no configurations are active. + * 2) the set being unloaded was the last to be loaded to maintain dependencies. + * + * @owner_info: Information on owner for set being unloaded. + */ +int cscfg_unload_config_sets(struct cscfg_load_owner_info *owner_info) +{ + int err = 0; + struct cscfg_load_owner_info *load_list_item = NULL; + + mutex_lock(&cscfg_mutex); + + /* cannot unload if anything is active */ + if (atomic_read(&cscfg_mgr->sys_active_cnt)) { + err = -EBUSY; + goto exit_unlock; + } + + /* cannot unload if not last loaded in load order */ + if (!list_empty(&cscfg_mgr->load_order_list)) { + load_list_item = list_last_entry(&cscfg_mgr->load_order_list, + struct cscfg_load_owner_info, item); + if (load_list_item != owner_info) + load_list_item = NULL; + } + + if (!load_list_item) { + err = -EINVAL; + goto exit_unlock; + } + + /* unload all belonging to load_owner */ + cscfg_unload_owned_cfgs_feats(owner_info); + + /* remove from load order list */ + list_del(&load_list_item->item); + +exit_unlock: + mutex_unlock(&cscfg_mutex); + return err; +} +EXPORT_SYMBOL_GPL(cscfg_unload_config_sets); + /* Handle coresight device registration and add configs and features to devices */ /* iterate through config lists and load matching configs to device */ diff --git a/drivers/hwtracing/coresight/coresight-syscfg.h b/drivers/hwtracing/coresight/coresight-syscfg.h index 08067e89edcf..e2b2bdab31aa 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.h +++ b/drivers/hwtracing/coresight/coresight-syscfg.h @@ -93,6 +93,7 @@ int cscfg_update_feat_param_val(struct cscfg_feature_desc *feat_desc, int cscfg_load_config_sets(struct cscfg_config_desc **cfg_descs, struct cscfg_feature_desc **feat_descs, struct cscfg_load_owner_info *owner_info); +int cscfg_unload_config_sets(struct cscfg_load_owner_info *owner_info); int cscfg_register_csdev(struct coresight_device *csdev, u32 match_flags, struct cscfg_csdev_feat_ops *ops); void cscfg_unregister_csdev(struct coresight_device *csdev); From patchwork Wed Nov 24 20:00:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12693579 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 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, }; /** From patchwork Wed Nov 24 20:00:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12693581 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 CF991C433F5 for ; Wed, 24 Nov 2021 20:03:03 +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=kH1sOPZEdPOV+Yt9myrTiZIazUgWdKEx0toh8sxDCeM=; b=pqRGS2elCXnE3N ruevl9fnzj+TWM+AtqbRJ/X+QbF8hWNcMZIra+lxYxfAsClTrJ3VaD/tV8wmqj4eT1DwipqAPOZ0J qNAk+HZprOGcn0xY6ZXLEJW3Fzt2DDu/a2cduCU1u/IaeKIT32+MSiAmn0KbyQPkXY4wI6ZgRRXty eJ6w/1fmkl3SgadcTyb2JsVNPyxkZ5c4tru9SaMifJracNBmh3rLJMINchUKBXUGWqI7jA6TrfA+A gFKcsl+mdE49OteJ6H1AeOLIxPwuWZft7f2y9wX+wKR3W6wgj9mmyWgyIKgupSoPofwF2IS+UXQ1+ sinJeTHimSqAIJWKOrzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpySU-005jgi-Ew; Wed, 24 Nov 2021 20:01:34 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpyRk-005jRy-8V for linux-arm-kernel@lists.infradead.org; Wed, 24 Nov 2021 20:00:50 +0000 Received: by mail-wm1-x32b.google.com with SMTP id i12so3526992wmq.4 for ; Wed, 24 Nov 2021 12:00:48 -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=L2N9DBJFT/LaykMxZ955Vn/H9ClRdLTcBhWxF4YCVME=; b=bf86iwyaSIO5Oy3WqpZhDA/X7AH8iObYkZgmjD8jxfC8xBlrIDPBiVj+Hb6KU6SRYU idR3/AaH2on2qZBTnz5N//SO2bdoQBesXhkLiALIV8mop1UdMfI2LRCqlYXDcLEcwouU FfqQ+3ZO6Jyc4NXs03Sx0ReyeuZVo3banE1jpC84tZxKhLwwY8WrnthEsWiXgfRwNwvu paNADQz7Epr2Gx68E/c9FL8Lo6WKdF5dIue3qtgFnD2OuNfco+JUclwmkHtqWFyX8OAq axlEf32Ds1EnsDQiq8nSVv+rTIePnYdOmuBb6krpjIRSfunBLwp6jE757yq9KNhjbGGJ UMPA== 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=L2N9DBJFT/LaykMxZ955Vn/H9ClRdLTcBhWxF4YCVME=; b=7V4oD06rHUVevv/L2ItWGCAsjR13WxZqsQft4w0cZm75nWeU1bFHK4vaGZlw2gjXRR 1jA2HBbHK6rNCfGaGc6Q1YHPBoaEy2Ukz6BMQ7GQjb7R76INgj2s5gAKSFZ4TvHwL0yw UziLihL/vhVXlI2dJQnyu10dpXBNkFhgpOnNEoA41Xdpgj9zDT+c5Yf3jQ8n6Qbem0EN qNgC6ctX2Y7oKSiLTXkfLLl2i1T2Dd2n4WDEpccYAZQPLSt0PIUOEE5fV7TorApZRcPj W+xdVkiPZ0kmfR/I9yhewZP9nAKcocogenhhcSQVPFPwr2seSh/PvHSwBESEgqYuAuVv qRoQ== X-Gm-Message-State: AOAM530HJN2Unx+xFl/qsFyO19ufl5KLIS+I5Mwr+ED1IlUfsfh7F7jJ nXo0iVMYCtpzFZWjtIYmvWZpRs6hNcYi/w== X-Google-Smtp-Source: ABdhPJxkBcNS+Mv7eef9juciXHrRh+5JRKO7H2WG7SKYgm92dlrysw3ziER6wZhwdNhfo2E6Lpl14Q== X-Received: by 2002:a7b:c452:: with SMTP id l18mr19222493wmi.46.1637784047000; Wed, 24 Nov 2021 12:00:47 -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.46 (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 4/6] coresight: syscfg: Example CoreSight configuration loadable module Date: Wed, 24 Nov 2021 20:00:36 +0000 Message-Id: <20211124200038.28662-5-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_120048_373070_51633CFB X-CRM114-Status: GOOD ( 21.18 ) 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 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org An example of creating a loadable module to add CoreSight configurations into a system. In the Kernel samples/coresight directory. Signed-off-by: Mike Leach Reviewed-by: Mathieu Poirier --- MAINTAINERS | 1 + samples/Kconfig | 9 +++ samples/Makefile | 1 + samples/coresight/Makefile | 4 ++ samples/coresight/coresight-cfg-sample.c | 73 ++++++++++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 samples/coresight/Makefile create mode 100644 samples/coresight/coresight-cfg-sample.c diff --git a/MAINTAINERS b/MAINTAINERS index 7a2345ce8521..85242fdd3b8c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1890,6 +1890,7 @@ F: Documentation/trace/coresight/* F: drivers/hwtracing/coresight/* F: include/dt-bindings/arm/coresight-cti-dt.h F: include/linux/coresight* +F: samples/coresight/* F: tools/perf/arch/arm/util/auxtrace.c F: tools/perf/arch/arm/util/cs-etm.c F: tools/perf/arch/arm/util/cs-etm.h diff --git a/samples/Kconfig b/samples/Kconfig index bec3528aa2de..fe8b56d576ce 100644 --- a/samples/Kconfig +++ b/samples/Kconfig @@ -232,6 +232,15 @@ config SAMPLE_WATCH_QUEUE Build example userspace program to use the new mount_notify(), sb_notify() syscalls and the KEYCTL_WATCH_KEY keyctl() function. +config SAMPLE_CORESIGHT_SYSCFG + tristate "Build example loadable module for CoreSight config" + depends on CORESIGHT && m + help + Build an example loadable module that adds new CoreSight features + and configuration using the CoreSight system configuration API. + This demonstrates how a user may create their own CoreSight + configurations and easily load them into the system at runtime. + endif # SAMPLES config HAVE_SAMPLE_FTRACE_DIRECT diff --git a/samples/Makefile b/samples/Makefile index b7b98307c2b4..c148ada64beb 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -32,3 +32,4 @@ obj-$(CONFIG_SAMPLE_INTEL_MEI) += mei/ subdir-$(CONFIG_SAMPLE_WATCHDOG) += watchdog subdir-$(CONFIG_SAMPLE_WATCH_QUEUE) += watch_queue obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak/ +obj-$(CONFIG_SAMPLE_CORESIGHT_SYSCFG) += coresight/ diff --git a/samples/coresight/Makefile b/samples/coresight/Makefile new file mode 100644 index 000000000000..b3fce4af2347 --- /dev/null +++ b/samples/coresight/Makefile @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_SAMPLE_CORESIGHT_SYSCFG) += coresight-cfg-sample.o +ccflags-y += -I$(srctree)/drivers/hwtracing/coresight diff --git a/samples/coresight/coresight-cfg-sample.c b/samples/coresight/coresight-cfg-sample.c new file mode 100644 index 000000000000..25485c80b5e3 --- /dev/null +++ b/samples/coresight/coresight-cfg-sample.c @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright(C) 2020 Linaro Limited. All rights reserved. + * Author: Mike Leach + */ + +#include "coresight-config.h" +#include "coresight-syscfg.h" + +/* create an alternate autofdo configuration */ + +/* we will provide 4 sets of preset parameter values */ +#define AFDO2_NR_PRESETS 4 +/* the total number of parameters in used features - strobing has 2 */ +#define AFDO2_NR_PARAM_SUM 2 + +static const char *afdo2_ref_names[] = { + "strobing", +}; + +/* + * set of presets leaves strobing window constant while varying period to allow + * experimentation with mark / space ratios for various workloads + */ +static u64 afdo2_presets[AFDO2_NR_PRESETS][AFDO2_NR_PARAM_SUM] = { + { 1000, 100 }, + { 1000, 1000 }, + { 1000, 5000 }, + { 1000, 10000 }, +}; + +struct cscfg_config_desc afdo2 = { + .name = "autofdo2", + .description = "Setup ETMs with strobing for autofdo\n" + "Supplied presets allow experimentation with mark-space ratio for various loads\n", + .nr_feat_refs = ARRAY_SIZE(afdo2_ref_names), + .feat_ref_names = afdo2_ref_names, + .nr_presets = AFDO2_NR_PRESETS, + .nr_total_params = AFDO2_NR_PARAM_SUM, + .presets = &afdo2_presets[0][0], +}; + +static struct cscfg_feature_desc *sample_feats[] = { + NULL +}; + +static struct cscfg_config_desc *sample_cfgs[] = { + &afdo2, + NULL +}; + +static struct cscfg_load_owner_info mod_owner = { + .type = CSCFG_OWNER_MODULE, + .owner_handle = THIS_MODULE, +}; + +/* module init and exit - just load and unload configs */ +static int __init cscfg_sample_init(void) +{ + return cscfg_load_config_sets(sample_cfgs, sample_feats, &mod_owner); +} + +static void __exit cscfg_sample_exit(void) +{ + cscfg_unload_config_sets(&mod_owner); +} + +module_init(cscfg_sample_init); +module_exit(cscfg_sample_exit); + +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Mike Leach "); +MODULE_DESCRIPTION("CoreSight Syscfg Example"); From patchwork Wed Nov 24 20:00:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12693584 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 D79E5C433EF for ; Wed, 24 Nov 2021 20:04:06 +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=ZLEh5jbirf047iwht7HsjotYQ2smNhktXKnZpbZCwnI=; b=z62rqdZGvYHJ6r S46A+3jyQ5k5Mp/Hs3YeGtr+cKJS1p0E2FcnX7c9EI3SnTyWdcRxSRvMljbObSGPLZ35uDSwT2ay3 xsxG3xRAT+sHJc8Fy++PUGjAajsfYzl/nt2rXy90mXzFov4rci1i6hKuvHDdcOjPNtoLZ30Zi8dXd 7zfDREfGBubn1SMe+PYNxCGmF2HuFheN3X+K790NPjmnvs4rMtsKH7DB2WvywsUwj8Sx0XKS6yX/c kZtmxSDZ45diwojQPjfZxtXy9WPoBLtVzd3nQELyyshr3wq0dUMnsitBgwXKtEURrp3x9pZuRJnmG dzNw16pd0ZLcrRS3qHXA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpyTW-005k6k-Oe; Wed, 24 Nov 2021 20:02:38 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpyRl-005jSb-74 for linux-arm-kernel@lists.infradead.org; Wed, 24 Nov 2021 20:00:53 +0000 Received: by mail-wr1-x430.google.com with SMTP id u1so6350945wru.13 for ; Wed, 24 Nov 2021 12:00:48 -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=Xx89p7HWheq7nOthISxHyqLh9mOso4esw/7b6ifVftk=; b=ZDYDXyhzf/kKv3yEbt8gH0G0vs8H0cM/jawnld6IuAAWjkWbM10H/uQHbi9gmZG6sA PoFaoX9QP7eXILENf2y4RhJyWK6CQQvDxzWh66TuKWIa4uKN/FI+n4nHzDt/f2c5l0ii zTjn9rXoMoWrRzQnSeepXJbn18npXavF+tInYessTwEES+SUKyyT5jz5obxv7zqMOANL JcJS0t8h1PsILZOwsy6j6L3WCsLy7tOxM6ZvKvk/QWYDKwCVbK5LOnPGUmzAwdn5bcIz iZ/L56Sxj0425gVqeCxJ5X0nbLbRoh00DXzh/yq+TwIEB3kmugAULkbulUAC2nGM5qcO BLzw== 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=Xx89p7HWheq7nOthISxHyqLh9mOso4esw/7b6ifVftk=; b=5I3U1Yg4bWU6arysYSW3qEsjfCZXK6uXdYnfn0YeWLmJ85MmlO1AUCAEIszHqt/q3n QFGlk/ZDTbmEsOhg6lRR/b9boJBLNfCfqIeJLIFqCG/TfYQkpDLwH0nOaqWteRWng4Ii JxDxXqPOb05uLNYaOjk9H3zLcehB1TqnUeQjAsaAXkuFKzVsvNXsNvABrI11p0o4NU+g hTfbFl4l1S+YQjLiJdC/0UmezB4XjNs1RDVVwtUi9odJNe0p3aBArGng+jGeo3qU2cNp tySQxkApZ2HhFhqkEwrqnfTh+K6zLyb7tILqBtkwe8kOtet0Bo5wdp5GQD4fEaz1fzEk jtsw== X-Gm-Message-State: AOAM531CZo2ps9dyM78Lm86X8I5N3l1wWxxhtlGh/E04OAkx2ikoSiCH +agZEMZej5E3yKHDyz/JL8ckT1YwtoO+ig== X-Google-Smtp-Source: ABdhPJx6XVuLUweFiYu+YkvkwSymtHW6bsOyPtSt4C7cRn8g5qX+0t5BggnBpAUFj1g74XIf+KGvuA== X-Received: by 2002:a5d:6e01:: with SMTP id h1mr21782464wrz.403.1637784047626; Wed, 24 Nov 2021 12:00:47 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 12:00:47 -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 5/6] coresight: configfs: Allow configfs to activate configuration Date: Wed, 24 Nov 2021 20:00:37 +0000 Message-Id: <20211124200038.28662-6-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_120049_305221_17D93A81 X-CRM114-Status: GOOD ( 30.28 ) 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 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Adds configfs attributes to allow a configuration to be enabled for use when sysfs is used to control CoreSight. perf retains independent enabling of configurations. Signed-off-by: Mike Leach Reviewed-by: Mathieu Poirier --- .../coresight/coresight-etm4x-core.c | 11 +- .../coresight/coresight-syscfg-configfs.c | 67 ++++++++++ .../coresight/coresight-syscfg-configfs.h | 2 + .../hwtracing/coresight/coresight-syscfg.c | 126 ++++++++++++++---- .../hwtracing/coresight/coresight-syscfg.h | 8 +- 5 files changed, 186 insertions(+), 28 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c index 86a313857b58..bf18128cf5de 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -722,7 +722,16 @@ static int etm4_enable_sysfs(struct coresight_device *csdev) { struct etmv4_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); struct etm4_enable_arg arg = { }; - int ret; + unsigned long cfg_hash; + int ret, preset; + + /* enable any config activated by configfs */ + cscfg_config_sysfs_get_active_cfg(&cfg_hash, &preset); + if (cfg_hash) { + ret = cscfg_csdev_enable_active_config(csdev, cfg_hash, preset); + if (ret) + return ret; + } spin_lock(&drvdata->spinlock); diff --git a/drivers/hwtracing/coresight/coresight-syscfg-configfs.c b/drivers/hwtracing/coresight/coresight-syscfg-configfs.c index 345a62f1b728..433ede94dd63 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg-configfs.c +++ b/drivers/hwtracing/coresight/coresight-syscfg-configfs.c @@ -6,6 +6,7 @@ #include +#include "coresight-config.h" #include "coresight-syscfg-configfs.h" /* create a default ci_type. */ @@ -87,9 +88,75 @@ static ssize_t cscfg_cfg_values_show(struct config_item *item, char *page) } CONFIGFS_ATTR_RO(cscfg_cfg_, values); +static ssize_t cscfg_cfg_enable_show(struct config_item *item, char *page) +{ + struct cscfg_fs_config *fs_config = container_of(to_config_group(item), + struct cscfg_fs_config, group); + + return scnprintf(page, PAGE_SIZE, "%d\n", fs_config->active); +} + +static ssize_t cscfg_cfg_enable_store(struct config_item *item, + const char *page, size_t count) +{ + struct cscfg_fs_config *fs_config = container_of(to_config_group(item), + struct cscfg_fs_config, group); + int err; + bool val; + + err = kstrtobool(page, &val); + if (!err) + err = cscfg_config_sysfs_activate(fs_config->config_desc, val); + if (!err) { + fs_config->active = val; + if (val) + cscfg_config_sysfs_set_preset(fs_config->preset); + } + return err ? err : count; +} +CONFIGFS_ATTR(cscfg_cfg_, enable); + +static ssize_t cscfg_cfg_preset_show(struct config_item *item, char *page) +{ + struct cscfg_fs_config *fs_config = container_of(to_config_group(item), + struct cscfg_fs_config, group); + + return scnprintf(page, PAGE_SIZE, "%d\n", fs_config->preset); +} + +static ssize_t cscfg_cfg_preset_store(struct config_item *item, + const char *page, size_t count) +{ + struct cscfg_fs_config *fs_config = container_of(to_config_group(item), + struct cscfg_fs_config, group); + int preset, err; + + err = kstrtoint(page, 0, &preset); + if (!err) { + /* + * presets start at 1, and go up to max (15), + * but the config may provide fewer. + */ + if ((preset < 1) || (preset > fs_config->config_desc->nr_presets)) + err = -EINVAL; + } + + if (!err) { + /* set new value */ + fs_config->preset = preset; + /* set on system if active */ + if (fs_config->active) + cscfg_config_sysfs_set_preset(fs_config->preset); + } + return err ? err : count; +} +CONFIGFS_ATTR(cscfg_cfg_, preset); + static struct configfs_attribute *cscfg_config_view_attrs[] = { &cscfg_cfg_attr_description, &cscfg_cfg_attr_feature_refs, + &cscfg_cfg_attr_enable, + &cscfg_cfg_attr_preset, NULL, }; diff --git a/drivers/hwtracing/coresight/coresight-syscfg-configfs.h b/drivers/hwtracing/coresight/coresight-syscfg-configfs.h index ea1e54d29f7f..373d84d43268 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg-configfs.h +++ b/drivers/hwtracing/coresight/coresight-syscfg-configfs.h @@ -15,6 +15,8 @@ struct cscfg_fs_config { struct cscfg_config_desc *config_desc; struct config_group group; + bool active; + int preset; }; /* container for feature view */ diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c index 678ee8250d85..098fc34c4829 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.c +++ b/drivers/hwtracing/coresight/coresight-syscfg.c @@ -745,30 +745,20 @@ void cscfg_csdev_reset_feats(struct coresight_device *csdev) } EXPORT_SYMBOL_GPL(cscfg_csdev_reset_feats); -/** - * cscfg_activate_config - Mark a configuration descriptor as active. - * - * This will be seen when csdev devices are enabled in the system. - * Only activated configurations can be enabled on individual devices. - * Activation protects the configuration from alteration or removal while - * active. - * - * Selection by hash value - generated from the configuration name when it - * was loaded and added to the cs_etm/configurations file system for selection - * by perf. +/* + * This activate configuration for either perf or sysfs. Perf can have multiple + * active configs, selected per event, sysfs is limited to one. * * Increments the configuration descriptor active count and the global active * count. * * @cfg_hash: Hash value of the selected configuration name. */ -int cscfg_activate_config(unsigned long cfg_hash) +static int _cscfg_activate_config(unsigned long cfg_hash) { struct cscfg_config_desc *config_desc; int err = -EINVAL; - mutex_lock(&cscfg_mutex); - 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 */ @@ -792,6 +782,101 @@ int cscfg_activate_config(unsigned long cfg_hash) break; } } + return err; +} + +static void _cscfg_deactivate_config(unsigned long cfg_hash) +{ + struct cscfg_config_desc *config_desc; + + list_for_each_entry(config_desc, &cscfg_mgr->config_desc_list, item) { + 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; + } + } +} + +/* + * called from configfs to set/clear the active configuration for use when + * using sysfs to control trace. + */ +int cscfg_config_sysfs_activate(struct cscfg_config_desc *config_desc, bool activate) +{ + unsigned long cfg_hash; + int err = 0; + + mutex_lock(&cscfg_mutex); + + cfg_hash = (unsigned long)config_desc->event_ea->var; + + if (activate) { + /* cannot be a current active value to activate this */ + if (cscfg_mgr->sysfs_active_config) { + err = -EBUSY; + goto exit_unlock; + } + err = _cscfg_activate_config(cfg_hash); + if (!err) + cscfg_mgr->sysfs_active_config = cfg_hash; + } else { + /* disable if matching current value */ + if (cscfg_mgr->sysfs_active_config == cfg_hash) { + _cscfg_deactivate_config(cfg_hash); + cscfg_mgr->sysfs_active_config = 0; + } else + err = -EINVAL; + } + +exit_unlock: + mutex_unlock(&cscfg_mutex); + return err; +} + +/* set the sysfs preset value */ +void cscfg_config_sysfs_set_preset(int preset) +{ + mutex_lock(&cscfg_mutex); + cscfg_mgr->sysfs_active_preset = preset; + mutex_unlock(&cscfg_mutex); +} + +/* + * Used by a device to get the config and preset selected as active in configfs, + * when using sysfs to control trace. + */ +void cscfg_config_sysfs_get_active_cfg(unsigned long *cfg_hash, int *preset) +{ + mutex_lock(&cscfg_mutex); + *preset = cscfg_mgr->sysfs_active_preset; + *cfg_hash = cscfg_mgr->sysfs_active_config; + mutex_unlock(&cscfg_mutex); +} +EXPORT_SYMBOL_GPL(cscfg_config_sysfs_get_active_cfg); + +/** + * cscfg_activate_config - Mark a configuration descriptor as active. + * + * This will be seen when csdev devices are enabled in the system. + * Only activated configurations can be enabled on individual devices. + * Activation protects the configuration from alteration or removal while + * active. + * + * Selection by hash value - generated from the configuration name when it + * was loaded and added to the cs_etm/configurations file system for selection + * by perf. + * + * @cfg_hash: Hash value of the selected configuration name. + */ +int cscfg_activate_config(unsigned long cfg_hash) +{ + int err = 0; + + mutex_lock(&cscfg_mutex); + err = _cscfg_activate_config(cfg_hash); mutex_unlock(&cscfg_mutex); return err; @@ -807,19 +892,8 @@ EXPORT_SYMBOL_GPL(cscfg_activate_config); */ void cscfg_deactivate_config(unsigned long cfg_hash) { - struct cscfg_config_desc *config_desc; - mutex_lock(&cscfg_mutex); - - list_for_each_entry(config_desc, &cscfg_mgr->config_desc_list, item) { - 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; - } - } + _cscfg_deactivate_config(cfg_hash); mutex_unlock(&cscfg_mutex); } EXPORT_SYMBOL_GPL(cscfg_deactivate_config); diff --git a/drivers/hwtracing/coresight/coresight-syscfg.h b/drivers/hwtracing/coresight/coresight-syscfg.h index 1da37874f70f..9106ffab4833 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.h +++ b/drivers/hwtracing/coresight/coresight-syscfg.h @@ -28,6 +28,8 @@ * @load_order_list: Ordered list of owners for dynamically loaded configurations. * @sys_active_cnt: Total number of active config descriptor references. * @cfgfs_subsys: configfs subsystem used to manage configurations. + * @sysfs_active_config:Active config hash used if CoreSight controlled from sysfs. + * @sysfs_active_preset:Active preset index used if CoreSight controlled from sysfs. */ struct cscfg_manager { struct device dev; @@ -37,6 +39,8 @@ struct cscfg_manager { struct list_head load_order_list; atomic_t sys_active_cnt; struct configfs_subsystem cfgfs_subsys; + u32 sysfs_active_config; + int sysfs_active_preset; }; /* get reference to dev in cscfg_manager */ @@ -88,7 +92,8 @@ int cscfg_preload(void *owner_handle); const struct cscfg_feature_desc *cscfg_get_named_feat_desc(const char *name); int cscfg_update_feat_param_val(struct cscfg_feature_desc *feat_desc, int param_idx, u64 value); - +int cscfg_config_sysfs_activate(struct cscfg_config_desc *cfg_desc, bool activate); +void cscfg_config_sysfs_set_preset(int preset); /* syscfg manager external API */ int cscfg_load_config_sets(struct cscfg_config_desc **cfg_descs, @@ -104,5 +109,6 @@ void cscfg_csdev_reset_feats(struct coresight_device *csdev); int cscfg_csdev_enable_active_config(struct coresight_device *csdev, unsigned long cfg_hash, int preset); void cscfg_csdev_disable_active_config(struct coresight_device *csdev); +void cscfg_config_sysfs_get_active_cfg(unsigned long *cfg_hash, int *preset); #endif /* CORESIGHT_SYSCFG_H */ From patchwork Wed Nov 24 20:00:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12693583 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 9106EC433EF for ; Wed, 24 Nov 2021 20:03:46 +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=iL5de7XmvRXUD7hORZtPChIExEAfgiOj6laNNLAK4kQ=; b=l/jeyXgBWsrt+9 qigNDGZx6CiHLF3NoYGsooYxWabQOzXKWf+JhE5WoeBZr5TnJ9rqKSh+JgFBNvkjUSRqsHF8K6Bw4 93gefhaSsvLoVNe28Oj+LwQaXW7sJQHb2QPAJ4Zp1WD9aVa8+PJ/L8CxAbX7DGQ+S+jJ3FAeB7SwZ QhNpJmwQbuJwuHCvTmKQa3v52CRblr9r7z3c52rxmvr80WNt+09VE7i7T08o5DIm4m+Ju6RX3a1NQ dXTbfeybv+GQyIyN5WzzJ6CQFWN3UPnm8ZkdD6gMnNvrLXXi9Kr1VZOXMu2sf4clTXV7y4fSaaEA4 vg6PRt1BKmyinO8/BmHA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpyT5-005jvR-RH; Wed, 24 Nov 2021 20:02:12 +0000 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpyRl-005jT0-NJ for linux-arm-kernel@lists.infradead.org; Wed, 24 Nov 2021 20:00:52 +0000 Received: by mail-wm1-x336.google.com with SMTP id j140-20020a1c2392000000b003399ae48f58so6444072wmj.5 for ; Wed, 24 Nov 2021 12:00:49 -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=wJfVGZzQLso7lttF1OkAKPmF7sFEmS3QY5IfzFqTl80=; b=Q8C6b2in2y0TplqUokPPUPniD/OFRDTqy0ue4ewaFjH7VNc7HoQ/Qpl8dMrQ7JP+d/ e8fh3bNt/G19MwTihfxYEfzIF5OW6H2Iavu4AdyJ9hgInXfFI4WmPX5oo1nboHYnvwXI kvDxvNiZfj1+GThfzaqlXi4pkWu2gQGEkOlUAehI4GuVeTIIBeBJhkg+0Fw7YbP1Eg+l mdqN0SanOlxIjEOJMA//nTlednxSR/sJv4wF8PkeKepwvXNYkBMnvZv+jixg9hoildGW YbSBQhBgQouWNbX9Bz6w9vmcs1S9E2hDiYctd7VyEyhvS1ZLK4B+xotemYUJ7+893oGn syqw== 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=wJfVGZzQLso7lttF1OkAKPmF7sFEmS3QY5IfzFqTl80=; b=dMkB94CVIWRnfo5BNdMOOZC4elJNTRflihaxLq/dE0kg4DzwauBV8NrMDIRnydRD/Y 7uKCzXlh8bpup/oYcDg18qASUgCXmHJT0dNnDV93GoRlFT9hts2a1QZnJxk6Xtg7S7qh aH7Xm+GE8QQYuhrBQlyZBALixLwVmT/o+Cjo1PYHsnS1W5e9Qq/C7MiU737mNzzcGfLp ONK0vLWWgSsK/W4LGgh9dw/caSsI65PIAEPaAEfJiZyJxSGTxK8dY1A7k2i0bEj1ZFOa YwFJM6irJXBKT6ZEc9TsKO0AdMLgE4sQMsW15gVieAMk8VkWrAJ63bFFCdTqgSAbzj24 NS6Q== X-Gm-Message-State: AOAM532f0rki42oQ8wB6WVL/4ziXvpo52bvkKMwiaOmu2/hsHloPPoj7 a0nPUx3bEVl0Y2R2H966RoCLae/f7HQJzw== X-Google-Smtp-Source: ABdhPJyiVpx/aRYRNkaVHsD9RVwfZKOQRNZSmOBHVCElQUGffjpJfN/6uHIk5TXDQV0TvABLhw7fsQ== X-Received: by 2002:a05:600c:22d0:: with SMTP id 16mr19012172wmg.37.1637784048185; Wed, 24 Nov 2021 12:00:48 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 12:00:47 -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 6/6] Documentation: coresight: Update coresight configuration docs Date: Wed, 24 Nov 2021 20:00:38 +0000 Message-Id: <20211124200038.28662-7-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_120049_784428_87247DD2 X-CRM114-Status: GOOD ( 22.44 ) 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 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Update the CoreSight System Configuration document to cover the use of loadable modules to add configurations and features to the system. Signed-off-by: Mike Leach --- .../trace/coresight/coresight-config.rst | 62 ++++++++++++++++++- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/Documentation/trace/coresight/coresight-config.rst b/Documentation/trace/coresight/coresight-config.rst index 6ed13398ca2c..6d5ffa6f7347 100644 --- a/Documentation/trace/coresight/coresight-config.rst +++ b/Documentation/trace/coresight/coresight-config.rst @@ -155,14 +155,14 @@ follows:: autofdo $ cd autofdo/ $ ls - description preset1 preset3 preset5 preset7 preset9 - feature_refs preset2 preset4 preset6 preset8 + description feature_refs preset1 preset3 preset5 preset7 preset9 + enable preset preset2 preset4 preset6 preset8 $ cat description Setup ETMs with strobing for autofdo $ cat feature_refs strobing -Each preset declared has a preset subdirectory declared. The values for +Each preset declared has a 'preset' subdirectory declared. The values for the preset can be examined:: $ cat preset1/values @@ -170,6 +170,9 @@ the preset can be examined:: $ cat preset2/values strobing.window = 0x1388 strobing.period = 0x4 +The 'enable' and 'preset' files allow the control of a configuration when +using CoreSight with sysfs. + The features referenced by the configuration can be examined in the features directory:: @@ -236,3 +239,56 @@ A preset to override the current parameter values can also be selected:: When configurations are selected in this way, then the trace sink used is automatically selected. + +Using Configurations in sysfs +============================= + +Coresight can be controlled using sysfs. When this is in use then a configuration +can be made active for the devices that are used in the sysfs session. + +In a configuration there are 'enable' and 'preset' files. + +To enable a configuration for use with sysfs:: + + $ cd configurations/autofdo + $ echo 1 > enable + +This will then use any default parameter values in the features - which can be +adjusted as described above. + +To use a preset set of parameter values:: + + $ echo 3 > preset + +This will select preset3 for the configuration. +The valid values for preset are 0 - to deselect presets, and any value of + where a preset sub-directory is present. + +Note that the active sysfs configuration is a global parameter, therefore +only a single configuration can be active for sysfs at any one time. +Attempting to enable a second configuration will result in an error. +Additionally, attempting to disable the configuration while in use will +also result in an error. + +The use of the active configuration by sysfs is independent of the configuration +used in perf. + + +Creating and Loading Custom Configurations +========================================== + +Custom configurations and / or features can be dynamically loaded into the +system by using a loadable module. + +An example of a custom configuration is found in ./samples/coresight. + +This creates a new configuration that uses the existing built in +strobing feature, but provides a different set of presets. + +When the module is loaded, then the configuration appears in the configfs +file system and is selectable in the same way as the built in configuration +described above. + +Configurations can use previously loaded features. The system will ensure +that it is not possible to unload a feature that is currently in use, by +enforcing the unload order as the strict reverse of the load order.