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 CB576C433F5 for ; Wed, 25 May 2022 18:02:31 +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=VYm4koONlDfzkS0Nh42TAMpUVf3m4PEROQvKCyw+TcU=; b=KwUMEGIjun33YY bRlro0v//rcVEvjuwQvP7CZbDach+2dVyP2VhxAaxggTHYIya8u5/zfkDK0U2mk4eIT/TNU5N4r6Y /BqFp8uv4Iaj9wCribLlQqhnXmz3hmut5Oxg0vrtUH3ifr9eq2n1EMCFow870faLu4HbK0UKrd8PT 0nudKnKALIrv6J1h9ptWu+/tKv18wzzLLZ0msKY3vDqKHBoIZH0lJEIZFgmHm8lf9Y120yRvG8iIW NZM7bzcr2d3ngIkOql2rENZH7duUAH4Z25NO8ZBLFAJO4bll8vAhDue1Wv54kcQ4mIMz1sD781LMc 2dWxSkbAk1VIkEXCRcuQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ntvJm-00C4bs-IU; Wed, 25 May 2022 18:01:10 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ntvJf-00C4aD-C8 for linux-arm-kernel@lists.infradead.org; Wed, 25 May 2022 18:01:07 +0000 Received: by mail-pf1-x435.google.com with SMTP id y199so19859598pfb.9 for ; Wed, 25 May 2022 11:01:00 -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=1D23NMqLuV/Mjwzbdv99/v+HcjEioft1sxk/Bk24+Rw=; b=jFnbjJG2AFFd9majiEnH8Q9nUUnqSR+TiMMiObtWD6HljfnqGWrlB055hWr9aRedzg WjPANdrOKxku3GcFWRBd74RXIjznLgsQCCNCr/ukhjhT6TL0Ig5aVi31acHwYQAuo0Nl GQdeR0FNRrhW99suDriuhJc3tTbsZ/CwPPx0kGATbFV1j+064Kh9MIb2QToS94X6qFmL eLknfLhMcuxRIrUezSGL/5EREljuGPZD4rhHYxxlCqhfJhZ3JnwpTNEc4HkSkVF4tqBr 2DF3AL7BgmdXxaOc+sbdYDFX4/oeF9y6f1qPpVoQW1lNopusJs6V7ZrH78cOesA6KZ/M FiOg== 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=1D23NMqLuV/Mjwzbdv99/v+HcjEioft1sxk/Bk24+Rw=; b=u/PGfdsBqQt5S74/roAi8Y4ubVaeelYbFnStC69QqmgenO7g/2Xjp7eaplkQErVzkt 7AMMABWTax66VUzeaFI1/0EJ345x+7d0/JXer3+77vMQ2P2Vj0RrFoP1FeAGANk6q+Cz p4CQsxK6FnHGox1eugImthwRnRdqF0FCJcVA9dIPK7GCDYbIUa5XYbVnZiWNZe6Z4uPc FNYIhVbMHaVUF2tk8O/jZXfJujfgDUIP6v+Vt2JhqtsuEbKeIxUVojms+7rpr0+X94X/ NRgiTvP4qOiCMn/aC7QEmI3cSYXXYFD3OJt82xXmAY2VULmwtkOseYeuKTeQ4dqzGnYJ rhsw== X-Gm-Message-State: AOAM530EXbcB3kN4thusP+QOCU6xmTNR40GGaBpeZTBWhteXWioOqhtA fNHFILNrt+JyPMDW7f2a0q6obMYcFMtBDA== X-Google-Smtp-Source: ABdhPJySGoEltv6045J56XuIDmAHlzmY2vxskS8nRu61XjVl49oxv4Rzay6uXmWU47rtMZjKOciwDQ== X-Received: by 2002:a05:6a00:198b:b0:518:375b:531d with SMTP id d11-20020a056a00198b00b00518375b531dmr34466868pfl.82.1653501660262; Wed, 25 May 2022 11:01:00 -0700 (PDT) Received: from p14s (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id m23-20020a17090ade1700b001cd4989fee4sm1944602pjv.48.2022.05.25.11.00.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 11:00:59 -0700 (PDT) Date: Wed, 25 May 2022 12:00:56 -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: <20220525180056.GB268257@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_110104_210322_F6E2028F X-CRM114-Status: GOOD ( 35.93 ) 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; Since cscfg_find_fs_owned_cfg_by_name() reads a configuration of feature name, I think the error message should be: pr_err("cscfg: Unload error: Failed to find %s from input file\n", name); > + } > + 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)); I think the internal memory for the arrays contained in the cscfg_fs_load_descs structure should be freed explicitly here, especially if they can be up to 16K. More comments to come later or tomorrow. Thanks, Mathieu > + 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, > }; > > +/* 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