From patchwork Thu Apr 14 06:44:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12812978 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 73B02C433F5 for ; Thu, 14 Apr 2022 06:46:41 +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=hKmia0IWiVIjfuunl7wGnp1Zsi+add2x3E82PZ+01DY=; b=4cSmlbpaMpF+CF xRz3BK1D4jS3gOq27e323ENNGsbtHVY2hCWktVjdG8h7oEnzLpj4rJmrLCoeJlqp3ShUYq1cYRJGr I1N+Y3zxKKkXJn23/VLSpofidUOTNF4Us9aUfjh8nK4UX/eBGrqvo6Jx4hsfIZJv1y13sWe3Uvkt4 pVQyE4/L9/Jy9gn5fB0+2WtDfFky3qZYwsrVcy0oemB1XlaV1GkSYOPEYp7+3KxX+N3w7zuaUsOgd 2Xc0/EQmR3OnDYlw0Wusw6mKdbRUe5tM3Dvzcih0PZVGNUNsEhyFMRGVbGl1Vjqibg2NnoxS/lgGi inY5aNDeimlYFiWaEc4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1netEK-0049Xg-6l; Thu, 14 Apr 2022 06:45:24 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1netDz-0049S3-0l for linux-arm-kernel@lists.infradead.org; Thu, 14 Apr 2022 06:45:06 +0000 Received: by mail-wm1-x32a.google.com with SMTP id l62-20020a1c2541000000b0038e4570af2fso2520848wml.5 for ; Wed, 13 Apr 2022 23:45:01 -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=20kSwrvFes3d9AaLZ9Dsa6NcYkb3CXOirJC6L4XWTcM=; b=jEiS0wh/Ug0p+JdlQcW6M/+fscpuaZrp5VUSlmWuvarL35lY9kxSHTx5RcfBPErzlB IVbvN766FYdWwqUpKCD+JEvEcYPtvgmyaBUBJLGHZ554qb6nqBwQ+0ZNNQbU/sxZ40xN JpW0HFHsk+bIW/58H4XktbDwE212jKOA9qrz0tsPSO/DSIvzDA3tjdoSB6KTA/lMRvR4 fAOxTbtfquIjqwVN+C5PwsWAK+CXd4bGC/uAXSjXDLd9pbWqkKs9khKo11et49r8r0AM Kpzsspcjb7xQHg4MT7ZR9i1V7Xvgk2YTRSNMC+t8Civ53DCM9wFxW+1nCMHupru/RMF4 0QHw== 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=20kSwrvFes3d9AaLZ9Dsa6NcYkb3CXOirJC6L4XWTcM=; b=kqSNjL1LDunKosPbIntsT95JvnizHOXmgYB93xz+YjKfjeNeL6dSBBhCZkT/7HTIDw bqVc5Z7Lv14IUHVqHUP531zA/JFhQlrX/teDzMkbu6KDdL4hwJ8cJUOOqPaD2z/hLcNc 6j+6OMQh2Xrgq9T+Ko0UYklliF525HluPy/df2gxGAuGEnqoFnJBFMU3sHYWjavDzhPK Wbypjj8+xVSHKDQn37vf2o2R3SbO2xw6WXmbJcJ9sAhIsBtTVxqO5vsjAR7Sc88vM8CB 2dvgyJeyjuHPZLPE7w8TwdKCWkcrzTR24r6JVmyk0WGEPsBqNUOPC9fwxtcpEO8qSolt z3zA== X-Gm-Message-State: AOAM532JIaM/UWmLCRd5uf1iCFIFakrBfThTXZydMLIqpdGhzr1uMeYo bxIGvvRV7N5l6c6MZAc+32tNzeAHE2Hc/w== X-Google-Smtp-Source: ABdhPJyzBJHbclXN29uw7e8ofcEHBNIEuZieWcubgt30CuMi6nezIdsuJoGtjfeZVVDxb95ZMtTJlg== X-Received: by 2002:a05:600c:5025:b0:38f:f782:253c with SMTP id n37-20020a05600c502500b0038ff782253cmr1182447wmr.42.1649918700806; Wed, 13 Apr 2022 23:45:00 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6809:2201:e4bb:355f:cdcf:ea80]) by smtp.gmail.com with ESMTPSA id c18-20020a7bc852000000b0038ebf5f191esm5395954wml.45.2022.04.13.23.45.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Apr 2022 23:45:00 -0700 (PDT) From: Mike Leach To: linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, mathieu.poirier@linaro.org Cc: suzuki.poulose@arm.com, leo.yan@linaro.org, Mike Leach Subject: [PATCH v3 2/5] coresight: configfs: Add in binary attributes to load files Date: Thu, 14 Apr 2022 07:44:54 +0100 Message-Id: <20220414064457.12052-3-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220414064457.12052-1-mike.leach@linaro.org> References: <20220414064457.12052-1-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220413_234503_106837_1EEBEC0E X-CRM114-Status: GOOD ( 24.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: , 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 | 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, }; +/* 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,