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 7A522A0548; Sun, 9 May 2021 18:06:32 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C5DCE41145; Sun, 9 May 2021 18:05:47 +0200 (CEST) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-eopbgr750051.outbound.protection.outlook.com [40.107.75.51]) by mails.dpdk.org (Postfix) with ESMTP id 97E0A41141 for ; Sun, 9 May 2021 18:05:44 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A3Tc9HkKffqnhB1xBwSIV8zasgcoKo6oFntj5lWm9aJHA1HLucX560ib4HaHesL5xLxu/kKkIrCedvWxVgb+x1zb1PewhxAs1jzf725YpslD0IVCyaVKtvv+JKPKnprhLebb2H5RVEY6SHB610OGr0MMc7GPd8Pvcf/TOktUJQ5tvyVBWLdn12lNdGLwH+VKSfYAW5hjYdXzLGXWcf9hG/LQhBrvHnzVTogQ/oUWURN0n2q+hiyd1hn8YNg/u5i27tvJw6O2h9heub/FD6sWzgfcHlm3xUTzrGJUZMikMBkVyeLm+j2gOe7m/NUrKuYqfzK0Fw98mTp5qkmXqyuFoQ== 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=D9wOi57V074dnyAToXYKYZUkkqK7OIL3mqfLdXmdVPk=; b=E0B1wSkRYcQd57zwE+3XpynKAJ6H6ya0ssgU9VlbZH+T9iX50zxt1LXIvnZ35GbPUFo4z5N2DoSIc3UdfLQHiMNrh+HLparhJD1262H5PHVZibj9XgVTDhAZPSuIv9Z+wZ0jSmJOl7sn/srMXxF4bce8fbZyEbygUj6NEyDvb+aclLlVSwku21uoh9wvNvFgm5zm+NKjdjwJOI+/nBaLGW2UxsboLMk5eQuU/w9KgVBtfnshZYhtxbpypYQIZrCNSaIeKi6C3OHWrRHwklrW2DDFzLdILBQ2O7nfrfWmdiNUMzkkQYybjxAD+vs/CBwD2HGsMg7mUNdf0GO/gyfnsg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=monjalon.net smtp.mailfrom=nvidia.com; dmarc=pass (p=none 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=D9wOi57V074dnyAToXYKYZUkkqK7OIL3mqfLdXmdVPk=; b=q2pMtVizfsfYPLU4KWEUP3fj2EBk/NyscWooUi2EUUFWvSrlRbmvCMRU8LIdr0Y5VM6Xq1n9TSLnLQleNOsDr5wKtOmvQTvZHdeXif5pyigo7QnJV+dFojgWFjjZjMN5KcJv2yOo7UMgzM/6CMqXfiP0yFPfaWtxxknYsWOhL6CLHdWCROtgxqIUlYScKIQ+VQw4IrDdP3GAPTS0IUabPYdMfpBlV8P229Er00+oE+AzKXBFW6nuDqzOmThdZBO/j6Zv9LJrAQcR5yTLkMjGtRMxDKziWpHAYYh+Ij6pyjUNRL65UiAJEi1ShfUhnJdIL4Pu04XLRiDwPLNOKWskaA== Received: from MWHPR07CA0010.namprd07.prod.outlook.com (2603:10b6:300:116::20) by BL0PR12MB2435.namprd12.prod.outlook.com (2603:10b6:207:48::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.29; Sun, 9 May 2021 16:05:43 +0000 Received: from CO1NAM11FT042.eop-nam11.prod.protection.outlook.com (2603:10b6:300:116:cafe::9) by MWHPR07CA0010.outlook.office365.com (2603:10b6:300:116::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Sun, 9 May 2021 16:05:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; monjalon.net; dkim=none (message not signed) header.d=none;monjalon.net; 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 CO1NAM11FT042.mail.protection.outlook.com (10.13.174.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4108.25 via Frontend Transport; Sun, 9 May 2021 16:05:42 +0000 Received: from nvidia.com (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 9 May 2021 16:05:38 +0000 From: Matan Azrad To: CC: , , , "Thomas Monjalon" Date: Sun, 9 May 2021 19:05:02 +0300 Message-ID: <20210509160507.224644-10-matan@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210509160507.224644-1-matan@nvidia.com> References: <20210504210857.3398397-1-matan@nvidia.com> <20210509160507.224644-1-matan@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 12a56ecf-f550-41a4-3e11-08d913044c2f X-MS-TrafficTypeDiagnostic: BL0PR12MB2435: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MbWGjmiuKp3htxOSWLQIWVQVbMZ1nu2M4/uvxlM6U8eEby7ettA12hF9xQeGEtsgtzSF61aHycD609k9g8OfNqVOfC2hAiaMDfjLbHnwWypDU3lp7XaiBazaJ/jNJK0iyrBAK5GGH4prhPZdYx7TvbYp2GebYi8dVkQbuX+BzFP1/x/f+FdCd+TwJ+j8w0Vu46mcf17WBdseOvPAyCtXQ0yeiwVfuV+cuZdDsvLdoOFghxI238KY5fOaPZsISpLa27VlXK/XSsivafSMZkm1+BsSVbgDM8k212h1bG3gcRdfwObuheWodh+dT381FagFo1sEmGktS5izu/rBQmwkU7eMT2xS66OkpGs1cVzPckB7FVJrf6QhsOmGKw8ZqYE8mTp7AZO+2d+i8WpMMpZDwYovQ08gI4mTg+OL/HOg3aAo5M3X6MqUS4aCOJP6REj4pAp99Kk9Bu0iwFZvs4MNH80xCeO3++sFiu96yMfyteO4uO29qJY9V/FblQ0ER80pcLipQBdj5f4r9aYE0kTUOYEj4S8hdWvoSPjuavbbsiWGof2wujU1ktciwTr/6NIKUi2UZ98hX1bmiggabHBjwwncTem3FhtrBBOeZTh9lQUFeCQxRM+Ba7tfyU1kJ/WHSclLLA7BbwMkbItdiBaG3xm4chp41QRuUIIKsb7YHEU= 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)(39860400002)(346002)(136003)(396003)(376002)(36840700001)(46966006)(186003)(7696005)(86362001)(426003)(6286002)(5660300002)(26005)(6916009)(82310400003)(16526019)(4326008)(36756003)(478600001)(36860700001)(6666004)(336012)(8676002)(2616005)(8936002)(47076005)(70586007)(54906003)(2906002)(55016002)(82740400003)(356005)(316002)(70206006)(7636003)(83380400001)(36906005)(1076003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2021 16:05:42.7527 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 12a56ecf-f550-41a4-3e11-08d913044c2f 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: CO1NAM11FT042.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB2435 Subject: [dpdk-dev] [PATCH v4 09/14] crypto/mlx5: add keytag devarg 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: Suanming Mou A keytag is a piece of data encrypted together with a DEK. When a DEK is referenced by an MKEY.bsf through its index, the keytag is also supplied in the BSF as plaintext. The HW will decrypt the DEK (and the attached keytag) and will fail the operation if the keytags don't match. This commit adds the configuration of the keytag with devargs. Signed-off-by: Suanming Mou Signed-off-by: Matan Azrad --- drivers/crypto/mlx5/mlx5_crypto.c | 50 +++++++++++++++++-------------- drivers/crypto/mlx5/mlx5_crypto.h | 3 +- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/drivers/crypto/mlx5/mlx5_crypto.c b/drivers/crypto/mlx5/mlx5_crypto.c index acf6c514d3..d4379d2b05 100644 --- a/drivers/crypto/mlx5/mlx5_crypto.c +++ b/drivers/crypto/mlx5/mlx5_crypto.c @@ -469,56 +469,52 @@ mlx5_crypto_args_check_handler(const char *key, const char *val, void *opaque) attr->session_import_kek_ptr = (uint32_t)tmp; else if (strcmp(key, "credential_id") == 0) attr->credential_pointer = (uint32_t)tmp; + else if (strcmp(key, "keytag") == 0) + devarg_prms->keytag = tmp; else DRV_LOG(WARNING, "Invalid key %s.", key); return 0; } -static struct mlx5_devx_obj * -mlx5_crypto_config_login(struct rte_devargs *devargs, - struct ibv_context *ctx) +static int +mlx5_crypto_parse_devargs(struct rte_devargs *devargs, + struct mlx5_crypto_devarg_params *devarg_prms) { - /* - * Set credential pointer and session import KEK pointer to a default - * value of 0. - */ - struct mlx5_crypto_devarg_params login = { - .login_devarg = false, - .login_attr = { - .credential_pointer = 0, - .session_import_kek_ptr = 0, - } - }; + struct mlx5_devx_crypto_login_attr *attr = &devarg_prms->login_attr; struct rte_kvargs *kvlist; + /* Default values. */ + attr->credential_pointer = 0; + attr->session_import_kek_ptr = 0; + devarg_prms->keytag = 0; if (devargs == NULL) { DRV_LOG(ERR, "No login devargs in order to enable crypto operations in the device."); rte_errno = EINVAL; - return NULL; + return -1; } kvlist = rte_kvargs_parse(devargs->args, NULL); if (kvlist == NULL) { DRV_LOG(ERR, "Failed to parse devargs."); rte_errno = EINVAL; - return NULL; + return -1; } if (rte_kvargs_process(kvlist, NULL, mlx5_crypto_args_check_handler, - &login) != 0) { + devarg_prms) != 0) { DRV_LOG(ERR, "Devargs handler function Failed."); rte_kvargs_free(kvlist); rte_errno = EINVAL; - return NULL; + return -1; } rte_kvargs_free(kvlist); - if (login.login_devarg == false) { + if (devarg_prms->login_devarg == false) { DRV_LOG(ERR, "No login credential devarg in order to enable crypto operations " "in the device."); rte_errno = EINVAL; - return NULL; + return -1; } - return mlx5_devx_cmd_create_crypto_login_obj(ctx, &login.login_attr); + return 0; } /** @@ -544,6 +540,7 @@ mlx5_crypto_pci_probe(struct rte_pci_driver *pci_drv, struct ibv_context *ctx; struct mlx5_devx_obj *login; struct mlx5_crypto_priv *priv; + struct mlx5_crypto_devarg_params devarg_prms = { 0 }; struct mlx5_hca_attr attr = { 0 }; struct rte_cryptodev_pmd_init_params init_params = { .name = "", @@ -552,6 +549,8 @@ mlx5_crypto_pci_probe(struct rte_pci_driver *pci_drv, .max_nb_queue_pairs = RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS, }; + int ret; + RTE_SET_USED(pci_drv); if (rte_eal_process_type() != RTE_PROC_PRIMARY) { DRV_LOG(ERR, "Non-primary process type is not supported."); @@ -581,7 +580,13 @@ mlx5_crypto_pci_probe(struct rte_pci_driver *pci_drv, rte_errno = ENOTSUP; return -ENOTSUP; } - login = mlx5_crypto_config_login(pci_dev->device.devargs, ctx); + ret = mlx5_crypto_parse_devargs(pci_dev->device.devargs, &devarg_prms); + if (ret) { + DRV_LOG(ERR, "Failed to parse devargs."); + return -rte_errno; + } + login = mlx5_devx_cmd_create_crypto_login_obj(ctx, + &devarg_prms.login_attr); if (login == NULL) { DRV_LOG(ERR, "Failed to configure login."); return -rte_errno; @@ -621,6 +626,7 @@ mlx5_crypto_pci_probe(struct rte_pci_driver *pci_drv, } priv->mr_scache.reg_mr_cb = mlx5_common_verbs_reg_mr; priv->mr_scache.dereg_mr_cb = mlx5_common_verbs_dereg_mr; + priv->keytag = rte_cpu_to_be_64(devarg_prms.keytag); pthread_mutex_lock(&priv_list_lock); TAILQ_INSERT_TAIL(&mlx5_crypto_priv_list, priv, next); pthread_mutex_unlock(&priv_list_lock); diff --git a/drivers/crypto/mlx5/mlx5_crypto.h b/drivers/crypto/mlx5/mlx5_crypto.h index 0aef804b92..34c65f9a24 100644 --- a/drivers/crypto/mlx5/mlx5_crypto.h +++ b/drivers/crypto/mlx5/mlx5_crypto.h @@ -30,6 +30,7 @@ struct mlx5_crypto_priv { struct rte_cryptodev_config dev_config; struct mlx5_mr_share_cache mr_scache; /* Global shared MR cache. */ struct mlx5_devx_obj *login_obj; + uint64_t keytag; }; struct mlx5_crypto_qp { @@ -49,10 +50,10 @@ struct mlx5_crypto_dek { bool size_is_48; /* Whether the key\data size is 48 bytes or not. */ }; - struct mlx5_crypto_devarg_params { bool login_devarg; struct mlx5_devx_crypto_login_attr login_attr; + uint64_t keytag; }; int -- 2.25.1