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 E7696A0548; Thu, 4 Nov 2021 06:12:03 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6A87240E5A; Thu, 4 Nov 2021 06:12:03 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 7BB7740DFD for ; Thu, 4 Nov 2021 06:12:01 +0100 (CET) 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 1A3NWMVk028941; Wed, 3 Nov 2021 22:12:00 -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=JHNv9Wtpu/tjQ7tjPShoGuEzA79EUsO32XkQoAdQrno=; b=dtlnDHpEeCWGPoXzm5SRKsP2tXNAIHxdrb0Z0R/FAWVnrZ4jjORliK8u8wr7mjpAqea3 cuJ4ZtGFJcWl+YB8t+kRXZOkPKTF4woI63AqLdxL+gJLAHaGNqNPWRgp+qZ4+CONiz8s 7PMJ1ZXxbaIGrc8t4D0Npk8+vtdANFlQNqigLvX9NIAxvAXvpv+aDEJz0LbFgpDzbbMW 8VEagKozNvYHvTSltFqJu8RIi8L4Oi4BhHQM4xt9J50qfQ54Re7XSwYJA23L2raRwSZS wBlVgJhEZe65OBpi/f2+movwvuldZ0do/UU0NaeKbUvlCQRVh5h+rjuSgr2lS/0fQ+me 1A== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3c43sf12ww-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 03 Nov 2021 22:12:00 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 3 Nov 2021 22:11:57 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Wed, 3 Nov 2021 22:11:57 -0700 Received: from localhost.localdomain (unknown [10.28.34.38]) by maili.marvell.com (Postfix) with ESMTP id 818B73F7083; Wed, 3 Nov 2021 22:11:55 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: , , , , Gowrishankar Muthukrishnan Date: Thu, 4 Nov 2021 10:41:51 +0530 Message-ID: <83e53b59c4fba348511bd94ef7c30e8aee4736ae.1636002586.git.gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <4d0648e0347e8c6a4b2b095acf568faf6df135ca.1635864621.git.gmuthukrishn@marvell.com> References: <4d0648e0347e8c6a4b2b095acf568faf6df135ca.1635864621.git.gmuthukrishn@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: X6tI3bADH-YjgpZOyqWz7Du7FdSleeYg X-Proofpoint-GUID: X6tI3bADH-YjgpZOyqWz7Du7FdSleeYg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-04_01,2021-11-03_01,2020-04-07_01 Subject: [dpdk-dev] [v5] 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 --- v5: - fixed parsing security capabilities for a requested index. --- doc/guides/prog_guide/rte_security.rst | 28 ++++ doc/guides/rel_notes/release_21_11.rst | 5 + lib/security/rte_security.c | 199 +++++++++++++++++++++++++ 3 files changed, 232 insertions(+) diff --git a/doc/guides/prog_guide/rte_security.rst b/doc/guides/prog_guide/rte_security.rst index 46c9b51d1b..72ca0bd330 100644 --- a/doc/guides/prog_guide/rte_security.rst +++ b/doc/guides/prog_guide/rte_security.rst @@ -728,3 +728,31 @@ it is only valid to have a single flow to map to that security session. +-------+ +--------+ +-----+ | Eth | -> ... -> | ESP | -> | END | +-------+ +--------+ +-----+ + + +Telemetry support +----------------- + +The Security library has support for displaying Crypto device information +with respect to its Security capabilities. Telemetry commands that can be used +are shown below. + +#. Get the list of available Crypto devices by ID, that supports Security features:: + + --> /security/cryptodev/list + {"/security/cryptodev/list": [0, 1, 2, 3]} + +#. Get the security capabilities of a Crypto device:: + + --> /security/cryptodev/sec_caps,0 + {"/security/cryptodev/sec_caps": {"sec_caps": [], "sec_caps_n": }} + + #. Get the security crypto capabilities of a Crypto device:: + + --> /security/cryptodev/crypto_caps,0,0 + {"/security/cryptodev/crypto_caps": {"crypto_caps": [], "crypto_caps_n": }} + +For more information on how to use the Telemetry interface, see +the :doc:`../howto/telemetry`. diff --git a/doc/guides/rel_notes/release_21_11.rst b/doc/guides/rel_notes/release_21_11.rst index 763c1caca1..1cff823a43 100644 --- a/doc/guides/rel_notes/release_21_11.rst +++ b/doc/guides/rel_notes/release_21_11.rst @@ -197,6 +197,11 @@ New Features * Added port representors support on SN1000 SmartNICs * Added flow API transfer proxy support +* **Added Telemetry callback to Security library.** + + Added Telemetry callback functions to query security capabilities of + Crypto device. + * **Updated Marvell cnxk crypto PMD.** * Added AES-CBC SHA1-HMAC support in lookaside protocol (IPsec) for CN10K. diff --git a/lib/security/rte_security.c b/lib/security/rte_security.c index fe81ed3e4c..6e45a03fa0 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,200 @@ rte_security_capability_get(struct rte_security_ctx *instance, return NULL; } + +static int +security_handle_cryptodev_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 CRYPTO_CAPS_SZ \ + (RTE_ALIGN_CEIL(sizeof(struct rte_cryptodev_capabilities), \ + sizeof(uint64_t)) / sizeof(uint64_t)) + +static int +crypto_caps_array(struct rte_tel_data *d, + const struct rte_cryptodev_capabilities *capabilities) +{ + const struct rte_cryptodev_capabilities *dev_caps; + uint64_t caps_val[CRYPTO_CAPS_SZ]; + unsigned int i = 0, j; + + rte_tel_data_start_array(d, RTE_TEL_U64_VAL); + + while ((dev_caps = &capabilities[i++])->op != + RTE_CRYPTO_OP_TYPE_UNDEFINED) { + memset(&caps_val, 0, CRYPTO_CAPS_SZ * sizeof(caps_val[0])); + rte_memcpy(caps_val, dev_caps, sizeof(capabilities[0])); + for (j = 0; j < CRYPTO_CAPS_SZ; j++) + rte_tel_data_add_array_u64(d, caps_val[j]); + } + + return (i - 1); +} + +#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 - 1; +} + +static const struct rte_security_capability * +security_capability_by_index(const struct rte_security_capability *capabilities, + int index) +{ + const struct rte_security_capability *dev_caps = NULL; + int i = 0; + + while ((dev_caps = &capabilities[i])->action != + RTE_SECURITY_ACTION_TYPE_NONE) { + if (i == index) + return dev_caps; + + ++i; + } + + return NULL; +} + +static int +security_capabilities_from_dev_id(int dev_id, const void **caps) +{ + const struct rte_security_capability *capabilities; + struct rte_security_ctx *sec_ctx; + + if (rte_cryptodev_is_valid_dev(dev_id) == 0) + return -EINVAL; + + sec_ctx = (struct rte_security_ctx *)rte_cryptodev_get_sec_ctx(dev_id); + RTE_PTR_OR_ERR_RET(sec_ctx, -EINVAL); + + capabilities = rte_security_capabilities_get(sec_ctx); + RTE_PTR_OR_ERR_RET(capabilities, -EINVAL); + + *caps = capabilities; + return 0; +} + +static int +security_handle_cryptodev_sec_caps(const char *cmd __rte_unused, const char *params, + struct rte_tel_data *d) +{ + const struct rte_security_capability *capabilities; + struct rte_tel_data *sec_caps; + char *end_param; + int sec_caps_n; + int dev_id; + int rc; + + 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"); + + rc = security_capabilities_from_dev_id(dev_id, (void *)&capabilities); + if (rc < 0) + return rc; + + sec_caps = rte_tel_data_alloc(); + RTE_PTR_OR_ERR_RET(sec_caps, -ENOMEM); + + rte_tel_data_start_dict(d); + 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; +} + +static int +security_handle_cryptodev_crypto_caps(const char *cmd __rte_unused, const char *params, + struct rte_tel_data *d) +{ + const struct rte_security_capability *capabilities; + struct rte_tel_data *crypto_caps; + const char *capa_param; + int dev_id, capa_id; + int crypto_caps_n; + char *end_param; + int rc; + + if (!params || strlen(params) == 0 || !isdigit(*params)) + return -EINVAL; + + dev_id = strtoul(params, &end_param, 0); + capa_param = strtok(end_param, ","); + if (!capa_param || strlen(capa_param) == 0 || !isdigit(*capa_param)) + return -EINVAL; + + capa_id = strtoul(capa_param, &end_param, 0); + if (*end_param != '\0') + CDEV_LOG_ERR("Extra parameters passed to command, ignoring"); + + rc = security_capabilities_from_dev_id(dev_id, (void *)&capabilities); + if (rc < 0) + return rc; + + capabilities = security_capability_by_index(capabilities, capa_id); + RTE_PTR_OR_ERR_RET(capabilities, -EINVAL); + + crypto_caps = rte_tel_data_alloc(); + RTE_PTR_OR_ERR_RET(crypto_caps, -ENOMEM); + + rte_tel_data_start_dict(d); + crypto_caps_n = crypto_caps_array(crypto_caps, capabilities->crypto_capabilities); + + rte_tel_data_add_dict_container(d, "crypto_caps", crypto_caps, 0); + rte_tel_data_add_dict_int(d, "crypto_caps_n", crypto_caps_n); + + return 0; +} + +RTE_INIT(security_init_telemetry) +{ + rte_telemetry_register_cmd("/security/cryptodev/list", + security_handle_cryptodev_list, + "Returns list of available crypto devices by IDs. No parameters."); + + rte_telemetry_register_cmd("/security/cryptodev/sec_caps", + security_handle_cryptodev_sec_caps, + "Returns security capabilities for a cryptodev. Parameters: int dev_id"); + + rte_telemetry_register_cmd("/security/cryptodev/crypto_caps", + security_handle_cryptodev_crypto_caps, + "Returns crypto capabilities for a security capability. Parameters: int dev_id, sec_cap_id"); +} -- 2.25.1