From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4A20AA0547; Sat, 30 Oct 2021 19:45:19 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C859040DDD; Sat, 30 Oct 2021 19:45:18 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id D89DB40DDB for ; Sat, 30 Oct 2021 19:45:16 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 19UH0N2b002040; Sat, 30 Oct 2021 10:45:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=3xAl2E7L8BlthlVumApPIMGuHX+sHZifejd54u8x6kU=; b=B3GxYJstT/7zeGhalpJiq/DA26smwgczqnEyOm93v3PYzuWCgWk7LkFxO+984mqYHAMh Bokqo46ewyhaZr3QS04Y2BmoAoi6aM6nK5KiPKI0Bk1u67fyfJGY1SEexfLUL+iEdDr8 9i3H1YlmzEp+uFjueNyWU0q+cvwtoYh7MA5qOEQxAf8VrdS2odrR8z78MahWXFYpP7Gr kXY+zP44oCwLWFz6ZsDrTo9FNVVqbb0DwL3mqrYy3e/nBBEIy0ceCz2GGs+YT/alDPRw //inCYMnFlgo8saF9o56fjzWKIOLBlwAHH2qD+oaLin0Xw0TuD68FYT3CFdb4k0kp6fF ZQ== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3c15jk8q07-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sat, 30 Oct 2021 10:45:16 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sat, 30 Oct 2021 10:45:14 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Sat, 30 Oct 2021 10:45:14 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 6D3413F70AD; Sat, 30 Oct 2021 10:45:12 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: , , , , Gowrishankar Muthukrishnan Date: Sat, 30 Oct 2021 23:15:09 +0530 Message-ID: <835cb4c93debb80afd3decc7e4540ed0f07d33fa.1635614976.git.gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <2729853b1a569f04d39ca8e898c9005bc3b47118.1635255702.git.gmuthukrishn@marvell.com> References: <2729853b1a569f04d39ca8e898c9005bc3b47118.1635255702.git.gmuthukrishn@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: a_S6CxthGiGSdKrmPZTc3jH37X48j103 X-Proofpoint-ORIG-GUID: a_S6CxthGiGSdKrmPZTc3jH37X48j103 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-10-30_05,2021-10-29_01,2020-04-07_01 Subject: [dpdk-dev] [v1] security: add telemetry endpoint for cryptodev security capabilities X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add telemetry endpoint for cryptodev security capabilities. Signed-off-by: Gowrishankar Muthukrishnan --- v1: - forked from patch 20009 "crypto/cnxk: add telemetry endpoints to cryptodev" to integrate changes in lib/rte_security itself. --- lib/security/rte_security.c | 98 +++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/lib/security/rte_security.c b/lib/security/rte_security.c index fe81ed3e4c..068d855d9b 100644 --- a/lib/security/rte_security.c +++ b/lib/security/rte_security.c @@ -4,8 +4,10 @@ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved */ +#include #include #include +#include #include "rte_compat.h" #include "rte_security.h" #include "rte_security_driver.h" @@ -203,3 +205,99 @@ rte_security_capability_get(struct rte_security_ctx *instance, return NULL; } + +static int +cryptodev_handle_dev_list(const char *cmd __rte_unused, + const char *params __rte_unused, + struct rte_tel_data *d) +{ + int dev_id; + + if (rte_cryptodev_count() < 1) + return -1; + + rte_tel_data_start_array(d, RTE_TEL_INT_VAL); + for (dev_id = 0; dev_id < RTE_CRYPTO_MAX_DEVS; dev_id++) + if (rte_cryptodev_is_valid_dev(dev_id) && + rte_cryptodev_get_sec_ctx(dev_id)) + rte_tel_data_add_array_int(d, dev_id); + + return 0; +} + +#define SEC_CAPS_SZ \ + (RTE_ALIGN_CEIL(sizeof(struct rte_security_capability), \ + sizeof(uint64_t)) / sizeof(uint64_t)) + +static int +sec_caps_array(struct rte_tel_data *d, + const struct rte_security_capability *capabilities) +{ + const struct rte_security_capability *dev_caps; + uint64_t caps_val[SEC_CAPS_SZ]; + unsigned int i = 0, j; + + rte_tel_data_start_array(d, RTE_TEL_U64_VAL); + + while ((dev_caps = &capabilities[i++])->action != + RTE_SECURITY_ACTION_TYPE_NONE) { + memset(&caps_val, 0, SEC_CAPS_SZ * sizeof(caps_val[0])); + rte_memcpy(caps_val, dev_caps, sizeof(capabilities[0])); + for (j = 0; j < SEC_CAPS_SZ; j++) + rte_tel_data_add_array_u64(d, caps_val[j]); + } + + return i; +} + +static int +security_handle_dev_caps(const char *cmd __rte_unused, const char *params, + struct rte_tel_data *d) +{ + const struct rte_security_capability *capabilities; + struct rte_security_ctx *sec_ctx; + struct rte_tel_data *sec_caps; + int sec_caps_n; + char *end_param; + int dev_id; + + if (!params || strlen(params) == 0 || !isdigit(*params)) + return -EINVAL; + + dev_id = strtoul(params, &end_param, 0); + if (*end_param != '\0') + CDEV_LOG_ERR("Extra parameters passed to command, ignoring"); + + if (!rte_cryptodev_is_valid_dev(dev_id)) + return -EINVAL; + + rte_tel_data_start_dict(d); + sec_caps = rte_tel_data_alloc(); + if (!sec_caps) + return -ENOMEM; + + sec_ctx = (struct rte_security_ctx *)rte_cryptodev_get_sec_ctx(dev_id); + if (!sec_ctx) + return -EINVAL; + + capabilities = rte_security_capabilities_get(sec_ctx); + if (!capabilities) + return -EINVAL; + + sec_caps_n = sec_caps_array(sec_caps, capabilities); + rte_tel_data_add_dict_container(d, "sec_caps", sec_caps, 0); + rte_tel_data_add_dict_int(d, "sec_caps_n", sec_caps_n); + + return 0; +} + +RTE_INIT(security_init_telemetry) +{ + rte_telemetry_register_cmd("/security/list", + cryptodev_handle_dev_list, + "Returns list of available crypto devices by IDs. No parameters."); + + rte_telemetry_register_cmd("/security/caps", + security_handle_dev_caps, + "Returns security capabilities for a cryptodev. Parameters: int dev_id"); +} -- 2.25.1