From patchwork Mon Nov 1 22:47:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12597509 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6F04C433F5 for ; Mon, 1 Nov 2021 22:49:11 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id B599160EDF for ; Mon, 1 Nov 2021 22:49:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B599160EDF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=21i1qwcjrilVJOB2sZtOsqOegs5Y7R65W1pQDV0ji7s=; b=rx/d8Rtq8tRJuN xUUZOesouVE5BD8GfQcUmOavvMHcSIyYMCyZnQbU62M7rP+MZ3oRoZfW6kH2arh7xMHRpLvrMCBi6 mZcKffA4Vxa+Ptm4Vgim59030hTed0hkhYFvm98/rZ5L+PglmLTDLcfRfcNG1CNj6rzHniRgwlNyR KracXi6gwfkG6Zj75AY2svvHwXFZwI9OXtXYpG3JzxRgU/SJqRKGy53wDPWs8P4rF47G9lUyxu8cc 5Gyr+lPqs/mc7fjz29sVZEo/jOWnqhHqBsUHwLF6QCKGNWaGtVFM7WWUa0/3fRZfsD9dkg4W3p8x1 SA4JBfcYvXh3EqsDFNTQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhg5m-00HRZ2-H9; Mon, 01 Nov 2021 22:47:50 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mhg5Y-00HRVn-Ei for linux-arm-kernel@lists.infradead.org; Mon, 01 Nov 2021 22:47:38 +0000 Received: by mail-wr1-x42b.google.com with SMTP id s13so23263431wrb.3 for ; Mon, 01 Nov 2021 15:47:36 -0700 (PDT) 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=6KRbH9mLbGvcaPLCyVN9O1UOrtK0Cg+7Cez0byQAE4I=; b=ubAyyYf+eVDvC24+SYffiyUH3C5VgTSu2W3g7ghzX33GGa3+R7LgW4fMuhyFC4ngAk qQHp0IEJkBY1Hxj3OwWsXdX0uzTAAeKGfr+JWxmOutK+KZZ4+uic9gZ7bc4s2lj0l0cu lJ9RrJKgLHvTm5s1W7YBmgB3b3zmfKaZbsoK9e/9RPHCZOsxMKZSA5fXKS2UxXAjbB4Z XODZEtXMNy8OCwfr5OECBgKl4FdErpdrlv5VX7Z0xzhzrB6E7AfI20TyUwOkLoN+nNsJ o2GgystNpBkWxQvEJHFaYyAmbUUt1j9UznPI0vmjFRHOkZfAur/ha0EXme3JuPL6lzXX dnSw== 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=6KRbH9mLbGvcaPLCyVN9O1UOrtK0Cg+7Cez0byQAE4I=; b=cjKPJmXCl5mTYSK8jon3sucrWITBdauqiLuk+4X6q8hekJUP84i925FUCKrrwWq6Pf 6zl4B/T1InYRShc7wuzoIaI34qdiKibHMiIDXtrvg0ZSb1tPnc8xNEg4OMQjNPqI0v7J xaHgJkgCrtc93qs4u683tmZYYWKxgAU8BQa8Tt4OxXQ+QLY7Tgcy8Uj+rc5rhaEGiPzg Ez7xdq6vZc0yiq+Yajb4eT8EV3rfj+f4Y7FZwFKop8hMnlCICvL2gymOgSHS40GeBgx0 szt5+J7ae7NbN9L9BkX5+/fcskfub5ODzkhvD/OHI1hxbcg8NXWkJzk3EHzG1d3uV5XY y1hA== X-Gm-Message-State: AOAM533dTFJNnS8l83YV2uixJbMfPGL5OQtiMwwAKsZa0bw7dFZQDDPu C0VBxJkxcDCEhhp4TTKaJToEpUDkSf00Og== X-Google-Smtp-Source: ABdhPJzQM3Y+hgpdXhItO57YzWQUUMP5De5XK513XJwJcEAI7pcRHJsv/D0qJWIvA3JVBIIOC093dA== X-Received: by 2002:adf:fb04:: with SMTP id c4mr40906792wrr.39.1635806855003; Mon, 01 Nov 2021 15:47:35 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:cd6d:75aa:3402:e4a]) by smtp.gmail.com with ESMTPSA id 10sm858647wme.27.2021.11.01.15.47.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 15:47:34 -0700 (PDT) From: Mike Leach 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 Subject: [PATCH 2/6] coresight: configfs: Add in binary attributes to load files Date: Mon, 1 Nov 2021 22:47:27 +0000 Message-Id: <20211101224731.27870-3-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211101224731.27870-1-mike.leach@linaro.org> References: <20211101224731.27870-1-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211101_154736_526434_1DF0B10B X-CRM114-Status: GOOD ( 28.60 ) 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 Add in functionality and binary attribute to load configurations as binary data. Reads the incoming attribute, which must be formatted correctly as defined in the file reader code - and will create a configuration and/or features and load them into the system. These will then appear in configfs ready for use. Unload functionality is also provided. Signed-off-by: Mike Leach --- .../coresight/coresight-config-file.h | 7 + .../coresight/coresight-syscfg-configfs.c | 148 +++++++++++++++++- .../coresight/coresight-syscfg-configfs.h | 8 + .../hwtracing/coresight/coresight-syscfg.c | 36 +++++ .../hwtracing/coresight/coresight-syscfg.h | 1 + 5 files changed, 193 insertions(+), 7 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-config-file.h b/drivers/hwtracing/coresight/coresight-config-file.h index 6c8c5af0a614..03899f7d94c9 100644 --- a/drivers/hwtracing/coresight/coresight-config-file.h +++ b/drivers/hwtracing/coresight/coresight-config-file.h @@ -115,4 +115,11 @@ struct cscfg_file_elem_str { char *str; }; +/* kernel configfs needs to read the incoming file buffers to load. */ +int cscfg_file_read_buffer(const u8 *buffer, const int buflen, + struct cscfg_fs_load_descs *desc_arrays); +/* to unload we just need the first name - config or first feature */ +int cscfg_file_read_buffer_first_name(const u8 *buffer, const int buflen, + const char **name); + #endif /* _CORESIGHT_CORESIGHT_CONFIG_FILE_H */ diff --git a/drivers/hwtracing/coresight/coresight-syscfg-configfs.c b/drivers/hwtracing/coresight/coresight-syscfg-configfs.c index c388a77a2683..21a67aae4ea9 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg-configfs.c +++ b/drivers/hwtracing/coresight/coresight-syscfg-configfs.c @@ -7,6 +7,7 @@ #include #include "coresight-config.h" +#include "coresight-config-file.h" #include "coresight-syscfg-configfs.h" /* create a default ci_type. */ @@ -380,14 +381,147 @@ static struct config_group *cscfg_create_feature_group(struct cscfg_feature_desc return &feat_view->group; } +/* Attributes in configfs that allow load and unload of configuration binary files */ + +/* load "buffer" as a configuration binary file */ +static ssize_t cscfg_cfg_load_write(struct config_item *item, const void *buffer, size_t size) +{ + struct cscfg_fs_configs_grp *configs_grp; + struct cscfg_fs_load_descs *load_descs = 0; + struct cscfg_load_owner_info *owner_info = 0; + int err = 0; + const char *name; + + configs_grp = container_of(to_config_group(item), struct cscfg_fs_configs_grp, group); + if (size > CSCFG_FILE_MAXSIZE) { + scnprintf(configs_grp->status, CSCFG_FS_STATUS_STRLEN, + "Load error: Input file too large.\n"); + return -EINVAL; + } + + load_descs = kzalloc(sizeof(struct cscfg_fs_load_descs), GFP_KERNEL); + owner_info = kzalloc(sizeof(struct cscfg_load_owner_info), GFP_KERNEL); + if (!load_descs || !owner_info) { + err = -ENOMEM; + goto exit_memfree; + } + + load_descs->owner_info = owner_info; + owner_info->owner_handle = load_descs; + owner_info->type = CSCFG_OWNER_CONFIGFS; + + err = cscfg_file_read_buffer(buffer, size, load_descs); + if (err) { + scnprintf(configs_grp->status, CSCFG_FS_STATUS_STRLEN, + "Load error: Failed to read input file.\n"); + goto exit_memfree; + } + + err = cscfg_load_config_sets(load_descs->config_descs, load_descs->feat_descs, owner_info); + if (err) { + scnprintf(configs_grp->status, CSCFG_FS_STATUS_STRLEN, + "Load error: Failed to load configuaration file.\n"); + goto exit_memfree; + } + + /* name of config if there is one, otherwise first feature */ + if (load_descs->config_descs[0]) + name = load_descs->config_descs[0]->name; + else + name = load_descs->feat_descs[0]->name; + scnprintf(configs_grp->status, CSCFG_FS_STATUS_STRLEN, + "OK: configuration file loaded (%s).\n", name); + + return size; + +exit_memfree: + kfree(load_descs); + kfree(owner_info); + return err; +} +CONFIGFS_BIN_ATTR_WO(cscfg_cfg_, load, NULL, CSCFG_FILE_MAXSIZE); + +/* read "buffer" and unload configuration */ +static ssize_t cscfg_cfg_unload_write(struct config_item *item, const void *buffer, size_t size) +{ + struct cscfg_fs_configs_grp *configs_grp; + struct cscfg_fs_load_descs *load_descs; + const char *name; + int err; + + configs_grp = container_of(to_config_group(item), struct cscfg_fs_configs_grp, group); + if (size > CSCFG_FILE_MAXSIZE) { + scnprintf(configs_grp->status, CSCFG_FS_STATUS_STRLEN, + "Unload error: Input file too large\n"); + return -EINVAL; + } + + err = cscfg_file_read_buffer_first_name(buffer, size, &name); + if (err) { + scnprintf(configs_grp->status, CSCFG_FS_STATUS_STRLEN, + "Unload error: Failed to read input file\n"); + return err; + } + + load_descs = cscfg_find_fs_owned_cfg_by_name(name); + if (!load_descs) { + scnprintf(configs_grp->status, CSCFG_FS_STATUS_STRLEN, + "Unload error: Failed to find configuration %s from input file\n", + name); + return err; + } + err = cscfg_unload_config_sets(load_descs->owner_info); + if (err) { + scnprintf(configs_grp->status, CSCFG_FS_STATUS_STRLEN, + "Unload error: Cannot unload configuration %s\n", + name); + return err; + } + + scnprintf(configs_grp->status, CSCFG_FS_STATUS_STRLEN, + "OK: configuration file unloaded (%s).\n", name); + + kfree((struct cscfg_load_owner_info *)load_descs->owner_info); + kfree(load_descs); + return size; +} +CONFIGFS_BIN_ATTR_WO(cscfg_cfg_, unload, NULL, CSCFG_FILE_MAXSIZE); + +/* show the status of the last load / unload operation */ +static ssize_t cscfg_cfg_last_load_status_show(struct config_item *item, char *page) +{ + struct cscfg_fs_configs_grp *configs_grp; + + configs_grp = container_of(to_config_group(item), struct cscfg_fs_configs_grp, group); + + return scnprintf(page, PAGE_SIZE, "%s\n", configs_grp->status); +} +CONFIGFS_ATTR_RO(cscfg_cfg_, last_load_status); + +static struct configfs_attribute *cscfg_config_configs_attrs[] = { + &cscfg_cfg_attr_last_load_status, + NULL, +}; + +static struct configfs_bin_attribute *cscfg_config_configfs_bin_attrs[] = { + &cscfg_cfg_attr_load, + &cscfg_cfg_attr_unload, + NULL, +}; + static struct config_item_type cscfg_configs_type = { .ct_owner = THIS_MODULE, + .ct_bin_attrs = cscfg_config_configfs_bin_attrs, + .ct_attrs = cscfg_config_configs_attrs, }; -static struct config_group cscfg_configs_grp = { - .cg_item = { - .ci_namebuf = "configurations", - .ci_type = &cscfg_configs_type, +/* group for configurations dir, with load, unload and status attribs */ +static struct cscfg_fs_configs_grp cscfg_configs_grp = { + .group = { + .cg_item = { + .ci_namebuf = "configurations", + .ci_type = &cscfg_configs_type, + }, }, }; @@ -400,7 +534,7 @@ int cscfg_configfs_add_config(struct cscfg_config_desc *config_desc) new_group = cscfg_create_config_group(config_desc); if (IS_ERR(new_group)) return PTR_ERR(new_group); - err = configfs_register_group(&cscfg_configs_grp, new_group); + err = configfs_register_group(&cscfg_configs_grp.group, new_group); if (!err) config_desc->fs_group = new_group; return err; @@ -468,8 +602,8 @@ int cscfg_configfs_init(struct cscfg_manager *cscfg_mgr) mutex_init(&subsys->su_mutex); /* Add default groups to subsystem */ - config_group_init(&cscfg_configs_grp); - configfs_add_default_group(&cscfg_configs_grp, &subsys->su_group); + config_group_init(&cscfg_configs_grp.group); + configfs_add_default_group(&cscfg_configs_grp.group, &subsys->su_group); config_group_init(&cscfg_features_grp); configfs_add_default_group(&cscfg_features_grp, &subsys->su_group); diff --git a/drivers/hwtracing/coresight/coresight-syscfg-configfs.h b/drivers/hwtracing/coresight/coresight-syscfg-configfs.h index 373d84d43268..8d6900e8c1ea 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg-configfs.h +++ b/drivers/hwtracing/coresight/coresight-syscfg-configfs.h @@ -11,6 +11,14 @@ #define CSCFG_FS_SUBSYS_NAME "cs-syscfg" +#define CSCFG_FS_STATUS_STRLEN 256 + +/* container for configs group */ +struct cscfg_fs_configs_grp { + struct config_group group; + char status[CSCFG_FS_STATUS_STRLEN]; +}; + /* container for configuration view */ struct cscfg_fs_config { struct cscfg_config_desc *config_desc; diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c index 759c32889efd..ceab30eac9b9 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.c +++ b/drivers/hwtracing/coresight/coresight-syscfg.c @@ -586,6 +586,42 @@ int cscfg_unload_config_sets(struct cscfg_load_owner_info *owner_info) } EXPORT_SYMBOL_GPL(cscfg_unload_config_sets); +/* find a configuration owned by configfs by name of config / first feature */ +struct cscfg_fs_load_descs *cscfg_find_fs_owned_cfg_by_name(const char *name) +{ + struct cscfg_load_owner_info *owner_info; + struct cscfg_fs_load_descs *fs_load_cfg = NULL; + struct cscfg_config_desc *config_desc; + struct cscfg_feature_desc *feat_desc; + + mutex_lock(&cscfg_mutex); + + /* search the load_owner list for CONFIGFS loaded types */ + list_for_each_entry(owner_info, &cscfg_mgr->load_order_list, item) { + /* if this is a config fs owned item, then try to match */ + if (owner_info->type == CSCFG_OWNER_CONFIGFS) { + fs_load_cfg = owner_info->owner_handle; + /* first try to match the name against the config if it exists */ + if (fs_load_cfg->config_descs[0]) { + config_desc = fs_load_cfg->config_descs[0]; + if (!strcmp(config_desc->name, name)) + goto exit_unlock; + /* no config - match against first feature name */ + } else { + feat_desc = fs_load_cfg->feat_descs[0]; + if (!strcmp(feat_desc->name, name)) + goto exit_unlock; + } + /* no match - move on */ + fs_load_cfg = NULL; + } + } + +exit_unlock: + mutex_unlock(&cscfg_mutex); + return fs_load_cfg; +} + /* 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 6a6e33585be9..6bc29abe0650 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.h +++ b/drivers/hwtracing/coresight/coresight-syscfg.h @@ -95,6 +95,7 @@ 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); +struct cscfg_fs_load_descs *cscfg_find_fs_owned_cfg_by_name(const char *name); /* syscfg manager external API */ int cscfg_load_config_sets(struct cscfg_config_desc **cfg_descs,