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 0C37DC433EF for ; Fri, 28 Jan 2022 18:18:48 +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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gSllY7grKpIvoSjge0sE/QyapNh0UA+3GS+WPNKr35k=; b=vnwBRkbejMWn9S w1xI80GGL0ASbi2M54uoP8OZkYDmRvo6tUwxaljUWVDhJ9v0DPZ+DwS0Lcr6MKMIha7ptGGWoll6a 70MqIpdwh9Akzs8UIoK4705dTogcWKbh1FCz9UOBxe6+9JRLSFraE1hGM0pPPqE4Ve41hvfaIoZJt IaHRMv0w17feEGxD7apMG+4kT38FA5377KELTCVVaId5MGm6kjD1a6jdlMyUN4lLuFxla+pwsyPH1 aQPf3AmMr4vUDaaEIrUIM34b2JxtMVv3uph6XkPg96/62MYqkgkrdOZK8qqWUt7nO5NQ2TuIMMsxU DZZCzlQo0MqoliisbzAA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nDVoT-003KI0-Aa; Fri, 28 Jan 2022 18:17:33 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nDVoO-003KHK-3d for linux-arm-kernel@lists.infradead.org; Fri, 28 Jan 2022 18:17:30 +0000 Received: by mail-pj1-x1034.google.com with SMTP id o11so7174185pjf.0 for ; Fri, 28 Jan 2022 10:17:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=pT3n12B/l9+EUd+qQnBnFtzp+T4SMYem6IpLw61awTc=; b=MzcKy6JwxpNxjAUaLibqpio6IyKCkX5YSVgBXFHipj1J2yXq5p0InUmvG9ydhZyiTv a22SSaInRTjq2kni1nhjYv0ahlv23dJ2TFliXTpAVbc4f88Ahis1rKv+u0irLguCVVEP HWvzbLhfO0nJlnIG1hUSDfuBKQ8UNPrcQGrcHtZeSooTn2wiQ0pHPa577VMiMFydDstx C153JRDykml+De7trQuPVsuQQ2QThQhhZnvwl4jyz3kZFWJnOkt0vzGuqr55poeHKRWW og5Uf09aSOCES6RZETwYXcV+vT428i43fpqhptMBxrHwF9j4Ct8iLuLRukvvn7HEa7S6 n7eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=pT3n12B/l9+EUd+qQnBnFtzp+T4SMYem6IpLw61awTc=; b=kFtPQx8WpTv+kc6/2016MMMLC1YBfJvLGAE8GWkQNLpshDRa0fk2VSLH04HbMJjj60 lCgMBlCSUkFG5aJbGCNRdUIvGEQ994IwurMjpu0cY6nqflaPf3BR0ouMknGY04kUPHrC BUKJ6S6kdtLPNkeq2rCL5BcBCYz3fFGPdTN6BVywf/ETGhGifgDnutUxBN8L1on69xss H0FrgtZ77k2eiwCZvdn8H+JGF8IoZ/jOGZM8obN9U46MqIDj9UgBDIDjNPj/76CqDx11 OU73g2qLYAEVzSUgZmI490aNfNJTLXvPcCqAlbjQzSG5GHZ6bvZ0Dma4q9SVPO3hJsIm 2fRQ== X-Gm-Message-State: AOAM533waqGzeEiiS8KVXAUe1mTmL0c6hAMKLGgbvXW1mYvd7Yd3rc/R 04dAUpnOA6pat8c072iKehHJeQ== X-Google-Smtp-Source: ABdhPJyHM51yxN7doNcaM3nAw8EYjS/DPHkQskntQTYZ6QO7E82fMcAh41auIfzMhVS8FNW1G1TF6Q== X-Received: by 2002:a17:902:c40b:: with SMTP id k11mr9518433plk.94.1643393846188; Fri, 28 Jan 2022 10:17:26 -0800 (PST) Received: from p14s (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id b22sm10569803pfl.121.2022.01.28.10.17.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jan 2022 10:17:25 -0800 (PST) Date: Fri, 28 Jan 2022 11:17:23 -0700 From: Mathieu Poirier To: Mike Leach Cc: linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, suzuki.poulose@arm.com, leo.yan@linaro.org Subject: Re: [PATCH v2 2/6] coresight: configfs: Add in binary attributes to load files Message-ID: <20220128181723.GB2240873@p14s> References: <20211130220100.25888-1-mike.leach@linaro.org> <20211130220100.25888-3-mike.leach@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20211130220100.25888-3-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220128_101728_200793_72800621 X-CRM114-Status: GOOD ( 39.03 ) 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: , 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 On Tue, Nov 30, 2021 at 10:00:56PM +0000, Mike Leach wrote: > 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 433ede94dd63..50abdb5aa6b6 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); I am still very ambivalent about this status thing... Especially since it only reports on the last item that was loaded/unloaded. > +} > +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 098fc34c4829..b5804cc2af9c 100644 > --- a/drivers/hwtracing/coresight/coresight-syscfg.c > +++ b/drivers/hwtracing/coresight/coresight-syscfg.c > @@ -587,6 +587,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, > -- > 2.17.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel