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 48171C433EF for ; Wed, 25 May 2022 19:47:24 +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=pD7rpWZ3idra+YvtZftXEnmcx3Wv/5m5Z9axSVQCPbA=; b=TXwe462IyjVg9K j3hKBXPXzHtOzzyWIsJ4Mo0rorUTYAsC5GJyYPgv3N4+w1L0FtGTfrKin++OhkHmzRDWSPvt28eJs 64UjWGTyff4DkA1OZoW5MqqJXCcIs4jJLgGBp0vyk0gJ2tN+DaCrHeUzoBtIE1ALajygZHAVI2/QE lEy1nHV6cAeF5y2ZLlRac3/2iMw/stB/3eZYFf1JNwDVMay0jdxuNPmmoNW8r89L+1wA0+jZpsQ2m voEHL4vyq4lUmrZjMoysGUhrEyZmgCng5uejADQ3xS8ukpvWV8YrojdD01UTXjcyBV+98rLzKMS4l 8SqfYQph8AwrrsqynGzg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ntwx1-00CTuy-DU; Wed, 25 May 2022 19:45:47 +0000 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ntwiU-00CNgP-Dq for linux-arm-kernel@lists.infradead.org; Wed, 25 May 2022 19:30:49 +0000 Received: by mail-pg1-x533.google.com with SMTP id v15so5485896pgk.11 for ; Wed, 25 May 2022 12:30:45 -0700 (PDT) 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=ZCEAPVTT/zVshTSREC+qmtefu1S6J0j4Ew0fxsSPqNA=; b=ij8O0s4ExrdC3y67SXZoE9VykayQcwRK5/4rYHDs24pAapCsuzXWplX+h7l1iEfFM2 KHX/+igiuIhTW6p/tgo3GFD5zHS7wv++FqOz6Pdrb4qh0sFyjd6CVXCmQAFaeVzVZ9XT bsuKJ+vIkg/SMoN7AhWfW+GD4kGM69khCYfYFapROMq1xjDyzxMnNSsUpspQE4AgUbac AOuApbta+23r+MC/oVzp6sXw7riSN4oOtJgn4Fe1uiUq3uXl8/gmZcnplEHXZLL+OLmU xpKRRhNCnRjhxXATqNAXq2Xai9Gi1oIYvVazkpqeDWol+alBtpw6JRPDtUHDF5Diowvw 7uHw== 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=ZCEAPVTT/zVshTSREC+qmtefu1S6J0j4Ew0fxsSPqNA=; b=A0aaQ9NVUKsb8PkrwA00NxEot6UOzZTQ2HQ0Y7dOCyae8N7H+hcTAtN7nY56Pf7E/5 eTledo2gZXxBK9FFmkQFB5VUN7fOJJ0/7jt2M/qRywOP9GfyaMVWVB5PziQ2CYNDJiE1 r0ZH3lK6MZ9nV1ehypmmXIcppPNKhvxVRYW81OBkkytsb4WyvfTtxzTlVLhQezI7m3bA qNwVxE1ZCjYte4YFEOl8qA8DvQ4V9ND34OLIXZ2NEMnJ5rev98v11gEZ4NoWrbmXxFvi E29RIO0NcafpaNtVgTjZxSX1MhNsfiCzUXICH4uaplM+vZjh0LwgHtOoTIXTA10eVnl0 fDDg== X-Gm-Message-State: AOAM533+OSl82jaIQAg+rsnNFuZ1lNtIyAC9lC8fq89huYL3kKCpiISz VnSeQdsFgP9T6fe0hjs0nFqIKg== X-Google-Smtp-Source: ABdhPJwCYpv8xGgDZFQKFnMJ3VE2YwDykrw2dGJEikMH6fA8rBVgPJlsYsqcHAwj95NWT9+GSaCNEw== X-Received: by 2002:a05:6a00:1588:b0:518:8ce2:7753 with SMTP id u8-20020a056a00158800b005188ce27753mr21164764pfk.51.1653507044557; Wed, 25 May 2022 12:30:44 -0700 (PDT) Received: from p14s (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id c2-20020a17090ae10200b001d93118827asm2090335pjz.57.2022.05.25.12.30.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 12:30:42 -0700 (PDT) Date: Wed, 25 May 2022 13:30:39 -0600 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 v3 2/5] coresight: configfs: Add in binary attributes to load files Message-ID: <20220525193039.GA273925@p14s> References: <20220414064457.12052-1-mike.leach@linaro.org> <20220414064457.12052-3-mike.leach@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220414064457.12052-3-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220525_123046_563690_FD22EB5B X-CRM114-Status: GOOD ( 36.15 ) 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 Thu, Apr 14, 2022 at 07:44:54AM +0100, 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 | 9 ++ > .../coresight/coresight-syscfg-configfs.c | 91 +++++++++++++++++++ > .../hwtracing/coresight/coresight-syscfg.c | 37 ++++++++ > .../hwtracing/coresight/coresight-syscfg.h | 1 + > 4 files changed, 138 insertions(+) > > diff --git a/drivers/hwtracing/coresight/coresight-config-file.h b/drivers/hwtracing/coresight/coresight-config-file.h > index 591f4c2c4be9..f85cf1aabf56 100644 > --- a/drivers/hwtracing/coresight/coresight-config-file.h > +++ b/drivers/hwtracing/coresight/coresight-config-file.h > @@ -7,6 +7,8 @@ > #ifndef _CORESIGHT_CORESIGHT_CONFIG_FILE_H > #define _CORESIGHT_CORESIGHT_CONFIG_FILE_H > > +#include "coresight-config.h" > + > /* > * Structures to represent configuration descriptors in a memory buffer > * to serialise to and from files > @@ -114,4 +116,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..d1ddcba10ad8 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,10 +381,100 @@ 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_load_descs *load_descs = 0; > + struct cscfg_load_owner_info *owner_info = 0; > + int err = 0; > + > + if (size > CSCFG_FILE_MAXSIZE) { > + pr_err("cscfg: 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; > + } > + > + owner_info->owner_handle = load_descs; > + owner_info->type = CSCFG_OWNER_CONFIGFS; > + > + err = cscfg_file_read_buffer(buffer, size, load_descs); > + if (err) { > + pr_err("cscfg: 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) { > + pr_err("cscfg: Load error - Failed to load configuaration file.\n"); > + goto exit_memfree; > + } > + > + 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_load_owner_info *owner_info = 0; > + const char *name; > + int err; > + > + if (size > CSCFG_FILE_MAXSIZE) { > + pr_err("cscfg: Unload error - Input file too large\n"); > + return -EINVAL; > + } > + > + err = cscfg_file_read_buffer_first_name(buffer, size, &name); > + if (err) { > + pr_err("cscfg: Unload error - Failed to read input file\n"); > + return err; > + } > + > + owner_info = cscfg_find_fs_owned_cfg_by_name(name); > + if (!owner_info) { > + pr_err("cscfg: Unload error: Failed to find configuration %s from input file\n", > + name); > + return err; > + } > + err = cscfg_unload_config_sets(owner_info); > + if (err) { > + pr_err("cscfg: Unload error: Cannot unload configuration %s\n", > + name); > + return err; > + } > + > + kfree(owner_info); > + kfree((struct cscfg_fs_load_descs *)(owner_info->owner_handle)); > + return size; > +} > +CONFIGFS_BIN_ATTR_WO(cscfg_cfg_, unload, NULL, CSCFG_FILE_MAXSIZE); > + > +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, I was thinking... Because it is possible to have a configuration file that only has features, wouldn't it make more sense to add the load and unload entries under cs-syscfg rather than cs-syscfg/configuration? > }; > > +/* group for configurations dir, with load and unload attribs */ > static struct config_group cscfg_configs_grp = { > .cg_item = { > .ci_namebuf = "configurations", > diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c > index 11850fd8c3b5..2e478b3e8c8d 100644 > --- a/drivers/hwtracing/coresight/coresight-syscfg.c > +++ b/drivers/hwtracing/coresight/coresight-syscfg.c > @@ -587,6 +587,43 @@ 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_load_owner_info *cscfg_find_fs_owned_cfg_by_name(const char *name) > +{ > + struct cscfg_load_owner_info *owner_info = NULL; > + struct cscfg_fs_load_descs *fs_load_cfg; > + 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; > + } > + } > + } > + > + /* not found */ > + owner_info = NULL; > + > +exit_unlock: > + mutex_unlock(&cscfg_mutex); > + return owner_info; > +} > + > /* 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..487d872d931a 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_load_owner_info *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