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 608B5A0C48; Tue, 20 Jul 2021 15:10:25 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 98F05410F8; Tue, 20 Jul 2021 15:10:13 +0200 (CEST) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2073.outbound.protection.outlook.com [40.107.244.73]) by mails.dpdk.org (Postfix) with ESMTP id 2BFFA40E6E for ; Tue, 20 Jul 2021 15:10:12 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m4ag0kSFz8k7Exj2cbayUyrsdYNFEmMcfdZvXseAF1d07yS0v3MstV2sU5TfQGFqf8YqbLHeUffChwnEF7zVfAyfJPDl3qAY74XlSTVBA3h/mSXfzzrfhqZaLtLe9O7ifxLi69TAMujAdq21kpMkmIsuYDexXjXzn3j1VajUEAOgsKNYEXJaautw+gEyv0M0aOr+YgkqsU65RrwUURQb8lwfNie8/r7x3cEJlCsJWquV2B7ICTRKi6qjwLQWjG8VWP4zq8ACL84gVzPdJL/18VxF+rkr44hwjpita3/OQPH59HSNIOGM/mceMSNT1CjwUQSN+6gObMJBUvl9RFWUrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1W6Yy007npaNxdn3dw47+7Kou8FbMxz+kMX1gKJ/TX8=; b=YCUUVLRxYzRoDvvwD7z9AfF9+x3rNoleJuZuHqBCbe8qwBbIP5uYjnP0mg3E8+usoibguAH5qEqVmDfIbbBFmzrApahgL34XTB+OWnthBePFtmLcT55cunf8dpqXHNb1c9B2RXDTF9mO3Ra4FxLB2yq+dt+Oo0bLCy/+gms0IczYmv9CWkRfhY9iMT6TGRacrvY2ff137qYdstYhkMEeNXBf/MwodVACf4mmv6x06qM/MMYHrs4M1Q9rKwvplSG+u0EX2nH5zs6oFZRBKJhEFqaBZUHHtQ1V5iz7+Wfw5AJisiWHONSs8eY+pMp9AoYEUGJ8/HwFPg7N/xNuN1Eb9w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1W6Yy007npaNxdn3dw47+7Kou8FbMxz+kMX1gKJ/TX8=; b=a7fqCWu+1QDxOvVjt9HPYlPrQSsYhEJnLCJvY4OKAOGy7GgyNkuXMgUoSDO/UqHDhEsQBGUoXDCyzSXt73ZB1IxTspRi7X+r4SzAC4El2NVoRich3Z5B4ZplIs3TzGOhqURrRgnXUSPeDXBYWK9Ak2wlzTASHkbcG+jKUgSd8nwUowB77+AKD8vEdfXBSFXbk7zn+/YsP0OHubYVfJd2etPDOdefQWuMZavIimQbU1Hl9h31xAyrFSRFn3gCym5JHOeU23gclyTKqCbmSp46NGe2FZoz4uF1gZXaFLX7esn9dgeq6dGdqIVoK928BrXa0EBaFrZPsT7gjkLrePUgjQ== Received: from DM6PR12CA0022.namprd12.prod.outlook.com (2603:10b6:5:1c0::35) by CY4PR12MB1704.namprd12.prod.outlook.com (2603:10b6:903:11d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.23; Tue, 20 Jul 2021 13:10:10 +0000 Received: from DM6NAM11FT006.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1c0:cafe::be) by DM6PR12CA0022.outlook.office365.com (2603:10b6:5:1c0::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.22 via Frontend Transport; Tue, 20 Jul 2021 13:10:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT006.mail.protection.outlook.com (10.13.173.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4331.21 via Frontend Transport; Tue, 20 Jul 2021 13:10:10 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 20 Jul 2021 13:10:06 +0000 From: Suanming Mou To: , CC: , , Date: Tue, 20 Jul 2021 16:09:31 +0300 Message-ID: <20210720130944.5407-3-suanmingm@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210720130944.5407-1-suanmingm@nvidia.com> References: <20210408204849.9543-1-shirik@nvidia.com> <20210720130944.5407-1-suanmingm@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0fa14900-8a71-4542-e54d-08d94b7fb410 X-MS-TrafficTypeDiagnostic: CY4PR12MB1704: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: f1tYA7NCWHAFO30opWZsnCjaCd9rP8z5MA5LT/mACZ/cc84ZytGc336T5JyIPYk13anzNNMisbKmx4SnK/KfR3OfFqOjCOQ5xSgMfwd0YKs7n1NZfeGH19l5q+K5DGtO7bxR9o1Khhki/gToQyZhGpG/4Mj1zdbUVcIaFUAut/eEagIusWjKYSbsy27NLGGRU1ll4Gx1TAbNsKHi2mxyDC+yObO5jYYKycEKO1kRerktwFCxt1QXnS2gzAOIODbwUQm8IA7AYdfEQti4KPQr5qVgB/JZYuLR25NI1MTaR5XrcN8fmVWSDwNlRP+TDt1DIvQB4JLMwFUTaniO5D/Bz1o6Ac+Fdo8N99C5gYG3cSa/9/BDvSzhlJ/iqbivS8Ry6t1Mmk91QdpKKhYGNZkwTDOZ46YeuZp9OqZsoKDsBeJu6dKr+GyL8xJCxdSxMFnmmX+DjZ0qlt1omLs+Mel7IpGYw7MnIh7Ptl4FWx4LVy675ViemQL0mJ+gTvHXnPcJxovdWF9n/l8h7dBRXZ/Buy+n/t+QKcZoJm3USiJi99V5ELyYUCuGM82tPg0stccv1ZaB2ypbK2wD2NWCCoFdRDxC+DmOQ3rnSORkfqc8orTFDnQ6iC6OlHnTBrUG2taKfiUvsv7+De5A7geaBT4ylbg9vzQitE7XFRFOZfQN0VDJJdPgrIti+5Tu9LdG6abTbDWgRClh8FhXpaXq+cJtYA== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(136003)(376002)(39860400002)(346002)(396003)(36840700001)(46966006)(36756003)(83380400001)(36906005)(47076005)(70206006)(86362001)(2616005)(426003)(82740400003)(316002)(70586007)(54906003)(6286002)(110136005)(356005)(6666004)(8936002)(16526019)(7636003)(1076003)(2906002)(8676002)(186003)(82310400003)(36860700001)(4326008)(26005)(7696005)(5660300002)(336012)(55016002)(478600001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2021 13:10:10.2262 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0fa14900-8a71-4542-e54d-08d94b7fb410 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT006.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1704 Subject: [dpdk-dev] [PATCH v9 02/15] crypto/mlx5: add DEK object management 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" From: Shiri Kuzin A DEK(Data encryption Key) is an mlx5 HW object which represents the cipher algorithm key. The DEKs are used during data encryption/decryption operations. In symmetric algorithms like AES-STS, we use the same DEK for both encryption and decryption. Use the mlx5 hash-list tool to manage the DEK objects in the PMD. Provide the compare, create and destroy functions to manage DEKs in hash-list and introduce an internal API to setup and unset the DEK management and to prepare and destroy specific DEK object. The DEK hash-list will be created in dev_configure routine and destroyed in dev_close routine. Signed-off-by: Shiri Kuzin Acked-by: Matan Azrad --- drivers/crypto/mlx5/meson.build | 1 + drivers/crypto/mlx5/mlx5_crypto.h | 25 ++++ drivers/crypto/mlx5/mlx5_crypto_dek.c | 160 ++++++++++++++++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 drivers/crypto/mlx5/mlx5_crypto_dek.c diff --git a/drivers/crypto/mlx5/meson.build b/drivers/crypto/mlx5/meson.build index 6fd70bc477..d55cdbfe6f 100644 --- a/drivers/crypto/mlx5/meson.build +++ b/drivers/crypto/mlx5/meson.build @@ -11,6 +11,7 @@ fmt_name = 'mlx5_crypto' deps += ['common_mlx5', 'eal', 'cryptodev'] sources = files( 'mlx5_crypto.c', + 'mlx5_crypto_dek.c', ) cflags_options = [ '-std=c11', diff --git a/drivers/crypto/mlx5/mlx5_crypto.h b/drivers/crypto/mlx5/mlx5_crypto.h index 6c187b7bc1..3f783fc956 100644 --- a/drivers/crypto/mlx5/mlx5_crypto.h +++ b/drivers/crypto/mlx5/mlx5_crypto.h @@ -12,6 +12,9 @@ #include +#define MLX5_CRYPTO_DEK_HTABLE_SZ (1 << 11) +#define MLX5_CRYPTO_KEY_LENGTH 80 + struct mlx5_crypto_priv { TAILQ_ENTRY(mlx5_crypto_priv) next; struct ibv_context *ctx; /* Device context. */ @@ -20,6 +23,28 @@ struct mlx5_crypto_priv { void *uar; /* User Access Region. */ uint32_t pdn; /* Protection Domain number. */ struct ibv_pd *pd; + struct mlx5_hlist *dek_hlist; /* Dek hash list. */ }; +struct mlx5_crypto_dek { + struct mlx5_list_entry entry; /* Pointer to DEK hash list entry. */ + struct mlx5_devx_obj *obj; /* Pointer to DEK DevX object. */ + uint8_t data[MLX5_CRYPTO_KEY_LENGTH]; /* DEK key data. */ + bool size_is_48; /* Whether the key\data size is 48 bytes or not. */ +} __rte_cache_aligned; + +int +mlx5_crypto_dek_destroy(struct mlx5_crypto_priv *priv, + struct mlx5_crypto_dek *dek); + +struct mlx5_crypto_dek * +mlx5_crypto_dek_prepare(struct mlx5_crypto_priv *priv, + struct rte_crypto_cipher_xform *cipher); + +int +mlx5_crypto_dek_setup(struct mlx5_crypto_priv *priv); + +void +mlx5_crypto_dek_unset(struct mlx5_crypto_priv *priv); + #endif /* MLX5_CRYPTO_H_ */ diff --git a/drivers/crypto/mlx5/mlx5_crypto_dek.c b/drivers/crypto/mlx5/mlx5_crypto_dek.c new file mode 100644 index 0000000000..67b1fa3819 --- /dev/null +++ b/drivers/crypto/mlx5/mlx5_crypto_dek.c @@ -0,0 +1,160 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2021 NVIDIA Corporation & Affiliates + */ + +#include +#include +#include +#include + +#include +#include + +#include "mlx5_crypto_utils.h" +#include "mlx5_crypto.h" + +struct mlx5_crypto_dek_ctx { + struct rte_crypto_cipher_xform *cipher; + struct mlx5_crypto_priv *priv; +}; + +int +mlx5_crypto_dek_destroy(struct mlx5_crypto_priv *priv, + struct mlx5_crypto_dek *dek) +{ + return mlx5_hlist_unregister(priv->dek_hlist, &dek->entry); +} + +struct mlx5_crypto_dek * +mlx5_crypto_dek_prepare(struct mlx5_crypto_priv *priv, + struct rte_crypto_cipher_xform *cipher) +{ + struct mlx5_hlist *dek_hlist = priv->dek_hlist; + struct mlx5_crypto_dek_ctx dek_ctx = { + .cipher = cipher, + .priv = priv, + }; + struct rte_crypto_cipher_xform *cipher_ctx = cipher; + uint64_t key64 = __rte_raw_cksum(cipher_ctx->key.data, + cipher_ctx->key.length, 0); + struct mlx5_list_entry *entry = mlx5_hlist_register(dek_hlist, + key64, &dek_ctx); + + return entry == NULL ? NULL : + container_of(entry, struct mlx5_crypto_dek, entry); +} + +static struct mlx5_list_entry * +mlx5_crypto_dek_clone_cb(void *tool_ctx __rte_unused, + struct mlx5_list_entry *oentry, + void *cb_ctx __rte_unused) +{ + struct mlx5_crypto_dek *entry = rte_zmalloc(__func__, sizeof(*entry), + RTE_CACHE_LINE_SIZE); + + if (!entry) { + DRV_LOG(ERR, "Cannot allocate dek resource memory."); + rte_errno = ENOMEM; + return NULL; + } + memcpy(entry, oentry, sizeof(*entry)); + return &entry->entry; +} + +static void +mlx5_crypto_dek_clone_free_cb(void *tool_ctx __rte_unused, + struct mlx5_list_entry *entry) +{ + struct mlx5_crypto_dek *dek = container_of(entry, + struct mlx5_crypto_dek, entry); + + rte_free(dek); +} + +static int +mlx5_crypto_dek_match_cb(void *tool_ctx __rte_unused, + struct mlx5_list_entry *entry, void *cb_ctx) +{ + struct mlx5_crypto_dek_ctx *ctx = cb_ctx; + struct rte_crypto_cipher_xform *cipher_ctx = ctx->cipher; + struct mlx5_crypto_dek *dek = + container_of(entry, typeof(*dek), entry); + uint32_t key_len = dek->size_is_48 ? 48 : 80; + + if (key_len != cipher_ctx->key.length) + return -1; + return memcmp(cipher_ctx->key.data, dek->data, key_len); +} + +static struct mlx5_list_entry * +mlx5_crypto_dek_create_cb(void *tool_ctx __rte_unused, void *cb_ctx) +{ + struct mlx5_crypto_dek_ctx *ctx = cb_ctx; + struct rte_crypto_cipher_xform *cipher_ctx = ctx->cipher; + struct mlx5_crypto_dek *dek = rte_zmalloc(__func__, sizeof(*dek), + RTE_CACHE_LINE_SIZE); + struct mlx5_devx_dek_attr dek_attr = { + .pd = ctx->priv->pdn, + .key_purpose = MLX5_CRYPTO_KEY_PURPOSE_AES_XTS, + .has_keytag = 1, + }; + + if (dek == NULL) { + DRV_LOG(ERR, "Failed to allocate dek memory."); + return NULL; + } + switch (cipher_ctx->key.length) { + case 48: + dek->size_is_48 = true; + dek_attr.key_size = MLX5_CRYPTO_KEY_SIZE_128b; + break; + case 80: + dek->size_is_48 = false; + dek_attr.key_size = MLX5_CRYPTO_KEY_SIZE_256b; + break; + default: + DRV_LOG(ERR, "Key size not supported."); + return NULL; + } + memcpy(&dek_attr.key, cipher_ctx->key.data, cipher_ctx->key.length); + dek->obj = mlx5_devx_cmd_create_dek_obj(ctx->priv->ctx, &dek_attr); + if (dek->obj == NULL) { + rte_free(dek); + return NULL; + } + memcpy(&dek->data, cipher_ctx->key.data, cipher_ctx->key.length); + return &dek->entry; +} + +static void +mlx5_crypto_dek_remove_cb(void *tool_ctx __rte_unused, + struct mlx5_list_entry *entry) +{ + struct mlx5_crypto_dek *dek = + container_of(entry, typeof(*dek), entry); + + claim_zero(mlx5_devx_cmd_destroy(dek->obj)); + rte_free(dek); +} + +int +mlx5_crypto_dek_setup(struct mlx5_crypto_priv *priv) +{ + priv->dek_hlist = mlx5_hlist_create("dek_hlist", + MLX5_CRYPTO_DEK_HTABLE_SZ, + 0, 1, NULL, mlx5_crypto_dek_create_cb, + mlx5_crypto_dek_match_cb, + mlx5_crypto_dek_remove_cb, + mlx5_crypto_dek_clone_cb, + mlx5_crypto_dek_clone_free_cb); + if (priv->dek_hlist == NULL) + return -1; + return 0; +} + +void +mlx5_crypto_dek_unset(struct mlx5_crypto_priv *priv) +{ + mlx5_hlist_destroy(priv->dek_hlist); + priv->dek_hlist = NULL; +} -- 2.25.1