From patchwork Tue Nov 30 22:00:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12694223 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 B7395C433F5 for ; Tue, 30 Nov 2021 22:02:54 +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=HbzYYd0XxqIbBVwq5RA9lP/sj4YmXWPRbC5hb3v9ndI=; b=jfiqs73AIjBjvn VPZpONAGhFO1ylcrhbM2ARdrp8+FEyizQ5qIaDBRvegOLJZMtKN4JOLU0DxbeqY+kIH8Veb2msx56 WzBHXw2v15rnv9rS+wxckxWXKYrXBpueE3kT38h2zFgyRJ0jkVJACycyRHjFkspE/0EeFX0AvRELZ ncgHaXILwp0UOTU5+v2tjAEbwqLC77IKtsXchNgV52PwW4HWHG8pQA+4rpi0cbJ78ieG3Dd+tecNz rNaalKWaIIhHl+oOckq4npRlfreJothJiXpEDeYRrpeB16W7nWEkDt182wAN/T8hCZBFPe3fibQJV U0ZfZ0NlkwTTIzdVZATA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1msBBm-006s2j-U2; Tue, 30 Nov 2021 22:01:27 +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 1msBBV-006rxE-82 for linux-arm-kernel@lists.infradead.org; Tue, 30 Nov 2021 22:01:11 +0000 Received: by mail-wr1-x430.google.com with SMTP id c4so47547233wrd.9 for ; Tue, 30 Nov 2021 14:01:09 -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=GY+FDPiasaC8qdBr5wxiNWpcZqX7PLh07XwtaUHV8jQ=; b=cb1V1l6xGNt4TozaDVBokqcM+ImwHZyicNRwjIbwboMzjFLUjkQ6cqoxvfNseaRbCd L3jJz7GkCSOqy6yU4AKFAVILZ/nrx2mDAmRI3v8Az4swWZ+NLAFyWaUop2x+EdDy+3QQ JjY65iSjylAwo9bw1FfO6b8Zx3Fnk4QtcfxHW0TmlsvG3gnVKTpilOhugQ9hiq5dWdOK U3y5nhCBb5XMCsWhZCpQbiRtsWxvyvnI1EM3z2WGlWUfjC/Y4kkEUupTv896Og6DGDIN Z2iZek0/ld8ICN9yLa+cUWzFKBi/GBgR5RBs8WoFgbfUc9FaLXUxua8xJp4Bsw3ZJdmw 8TrA== 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=GY+FDPiasaC8qdBr5wxiNWpcZqX7PLh07XwtaUHV8jQ=; b=qAQKivGebNPCBJCjTZXXqFDXxmgJGnY0AO6as14Dkllx61bSpOYO6naBc+lvMEQ11r k1MnmTlek89Q9OUqhmPBnL3yN3ZEZdvObsu2f2Db4BClXB23H1tjEoSQnMgACn0JEZMa ltsaUfNSc3Vyv6FUK0mAYhUZ0NhPco/IIVWfkLlQ4pent6qr0oN/bGfCXctjkQD47Nyd 6z7prelDkG08wc5d/4bV/xOG2IKIHvbPtp5UrXoRjIXMRFVB+/+/jik+ZXXQNY3bouQO 9S6iw/Ie1h2BzrFWAVM+/CyhwlmFUWWUrTdb1RNwJVlar3OVaUOFj3NV8hN600t5e58L yveA== X-Gm-Message-State: AOAM530/wZr42rOvArG8md9x68i4tIHtUe14Ydz+9o3NkyI2C4wsDkFm F695l4PQWjDvOyqqd0Sa0jpe0PiZRvIEmA== X-Google-Smtp-Source: ABdhPJwVziS6K5gv55KVh1/cRTnlJhXTgb6hvOqWFwQH6PGregvvIGAR21pq3PtqECrxz1fIIKyESA== X-Received: by 2002:a05:6000:1289:: with SMTP id f9mr1741682wrx.329.1638309668036; Tue, 30 Nov 2021 14:01:08 -0800 (PST) Received: from linaro.org ([2a00:23c5:6809:2201:546d:7d59:1703:bf96]) by smtp.gmail.com with ESMTPSA id y142sm3755280wmc.40.2021.11.30.14.01.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 14:01:07 -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 v2 2/6] coresight: configfs: Add in binary attributes to load files Date: Tue, 30 Nov 2021 22:00:56 +0000 Message-Id: <20211130220100.25888-3-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211130220100.25888-1-mike.leach@linaro.org> References: <20211130220100.25888-1-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211130_140109_321430_F867BAAA X-CRM114-Status: GOOD ( 28.78 ) 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 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); +} +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,