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 C3C12A0C41; Thu, 15 Jul 2021 18:43:10 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 744254131B; Thu, 15 Jul 2021 18:42:25 +0200 (CEST) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2069.outbound.protection.outlook.com [40.107.244.69]) by mails.dpdk.org (Postfix) with ESMTP id 7685541327 for ; Thu, 15 Jul 2021 18:42:20 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LSUlP4GRYDeySIkVlhAz/wE3ByA7C6XvNQR+a77n9wJ7XdS3BYPQ09aadceHqwdSVkhmUKVGBDdq6VwLNIx9soeU9P0xES4VPK8Zr0Qbbuw4XJx4XHzAH+mFTY68ETS99sj2jGxVxNaEiZ1JghXMFc9f42LMZ8pq8I2QXS4CYn0oclsSecl1gnEo2V7JvT50gOzPqfKLNGct6n4oSxx/I+Ej9B4Hcb1DfFdMJatquIfVWB/0wnYc3J+WjNZQsFg+Dnw9m4pPx671DTzjTeuhd5e/rDB8d9ZawXYc3kWtPKxIyXKQ8RBHsmLOiBpjAQ4xzwQRX+zsmKaLkvByqi0R5Q== 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=hZvn5bJ7Rk2g3jDa4qj0jnYqDhatdzrXjwl3ex3sXeI=; b=XwuPPLGvzJ/uZClI49Bp/BxLyvDL6K3H3EvcZIR7ReRbM4uG+Bywf0YLncbCmOy5VXRkWWygh03iCtyzdN9lg8KcYa8ApVGBQzpFe4SVoTfSwwzSUxT6lB6Drj1q72WbkveW/vHFttij6lo3uEjDR5/954i8zCowIBPcxJzOUO9J7WJ8AZhFM9lv1SXSxjk6DJbMwb46Omyr1RYHjyFOSNr/7kqfE4vXyD5tF0HY6kVz7Ew7/Rt4ZZs49HznbljHUmENkoMG4zhjHQKmBNC532LSHZS4ij7GhVvybaHvBQ4ExQyby40hVh8vgNxT4qf3LBOqVsyFJ9ahRXZvPISvMg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=redhat.com 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=hZvn5bJ7Rk2g3jDa4qj0jnYqDhatdzrXjwl3ex3sXeI=; b=Z+hrBobhwVip8Xfr/MyNrTisweWNx/DCFalK/yLshjQACKE9ScU1xamQAH+GMBhMaDsDfkoKGQk5hgGcpNybehZFIo9QxqQlzm4Ja6GGjyVDJ4zAQ8HmM9xAPeRt5ShgxMlkeUCRr1GYZpDXQCeZAZKox17j1q8rVtFs7NRlIg4VuhP6LdO21QMGyYWeA//VsQWjvd15wo8sGJO+pwGEkB2DLjbu9up/nnKNxOO22UAHWkOPFDGcGGJQy5DotBzBFNK8X2qXEU+60SuJJc0Be1hOAcOE7L9hphMG5j9V1oFAV89uR8tuXTTtBfgc1vmGOIVKCygahGxRjz8Nhp/NSg== Received: from MW4P221CA0003.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::8) by MN2PR12MB3181.namprd12.prod.outlook.com (2603:10b6:208:ae::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.23; Thu, 15 Jul 2021 16:42:18 +0000 Received: from CO1NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8b:cafe::fd) by MW4P221CA0003.outlook.office365.com (2603:10b6:303:8b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.22 via Frontend Transport; Thu, 15 Jul 2021 16:42:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; redhat.com; dkim=none (message not signed) header.d=none;redhat.com; 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 CO1NAM11FT015.mail.protection.outlook.com (10.13.175.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4331.21 via Frontend Transport; Thu, 15 Jul 2021 16:42:18 +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; Thu, 15 Jul 2021 16:42:14 +0000 From: Shiri Kuzin To: CC: , , , Date: Thu, 15 Jul 2021 19:41:19 +0300 Message-ID: <20210715164126.54073-10-shirik@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210715164126.54073-1-shirik@nvidia.com> References: <20210715150817.51485-1-shirik@nvidia.com> <20210715164126.54073-1-shirik@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.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: 83bd2239-0260-46f8-c537-08d947af8285 X-MS-TrafficTypeDiagnostic: MN2PR12MB3181: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:139; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vq+aJdRBax5D9ogLFkeJLqWHu9jwVmFtGTi3cxbX67a8Lo6xYr3DL/Fm/eEisPqpuOtxUzIxI8aEEbmJ9vnOnbWT72vYKCvQ39NNgaepYXU1YRj9m5v42OPn8p0KQK32PxCuu/szm6T4BDcBeAL7MMhkqX/PE8Yry6UC4Mz0lvPZ54QIJj76/obrQbV2qExKEe0puIk4+36dYyD+FOQ5RAmZAPjMHbR44zHf9np7wfJ8hUg2jyQrYHVEkg+e+2K0AdqWL/Rwdn+t9yYJO9w8sbMkJfjXg2r+VvvOiFLQokJTNR9SAnFBfgWXojCw2+22PlGuEMiqmytFEnDyyQXQ128noFfBvQYKyLpQ9YI4MBc5pMjeQa0E+EgaO7HGG9hCW2W5hRCgSS7VvXgwQyt95bEms4BDxYlh3e4t1+QwF88h0Y6wzV1SYmxoRQMlvCxYZtbcrDLHBjqmpaIO7FUb8/R8oNyFjRoaUjK8IEwidY5kYTOkJnjqJKfwrAimwVtMIJOC4a5c8hR3RXZlVxGFekpP+jdFgLycQ6drHOq8F8Hxzsh9leaMXNRlmpotcxWntBs2wd3jPFeISvbpwhCUio1hYIDqNvQOS1T4TWewHhqlJZG5LFdR1dtjNedsR1uUFBA+CGBy+o51oiJtwVKz5kpLUIJBKLHTC7dpPKC4hQ3iTnVo6307EqN1BNAV+EJmyBgC6Rj+kjBJ8tn2gLoDAe67Xxwe4Ik68qXHuUwqgM8= 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)(396003)(346002)(39860400002)(136003)(376002)(46966006)(36840700001)(82310400003)(86362001)(2616005)(26005)(36860700001)(426003)(6916009)(356005)(54906003)(478600001)(7636003)(34020700004)(82740400003)(316002)(55016002)(8676002)(47076005)(70586007)(186003)(1076003)(4326008)(70206006)(2906002)(36756003)(36906005)(16526019)(83380400001)(7696005)(336012)(5660300002)(6286002)(8936002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jul 2021 16:42:18.2700 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 83bd2239-0260-46f8-c537-08d947af8285 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: CO1NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3181 Subject: [dpdk-dev] [PATCH v8 09/16] 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 --- doc/guides/cryptodevs/mlx5.rst | 7 +++++ drivers/crypto/mlx5/mlx5_crypto.c | 50 +++++++++++++++++-------------- drivers/crypto/mlx5/mlx5_crypto.h | 3 +- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/doc/guides/cryptodevs/mlx5.rst b/doc/guides/cryptodevs/mlx5.rst index 6cae5affbd..c3632484a5 100644 --- a/doc/guides/cryptodevs/mlx5.rst +++ b/doc/guides/cryptodevs/mlx5.rst @@ -52,6 +52,9 @@ wrapping. The credential and the AES-XTS keys should be provided to the hardware, as ciphertext encrypted by the KEK. +A keytag (64 bits) should be appended to the AES-XTS keys (before wrapping), +and will be validated when the hardware attempts to access it. + When crypto engines are defined to work in wrapped import method, they come out of the factory in Commissioning mode, and thus, cannot be used for crypto operations yet. A dedicated tool is used for changing the mode from Commissioning to @@ -113,6 +116,10 @@ Driver options The identifier of the credential, default value is 0 represents the operational register credential. +- ``keytag`` parameter [int] + + The plaintext of the keytag appanded to the AES-XTS keys, default value is 0. + Supported NICs -------------- diff --git a/drivers/crypto/mlx5/mlx5_crypto.c b/drivers/crypto/mlx5/mlx5_crypto.c index cbaa2e52ff..0f786ac4ca 100644 --- a/drivers/crypto/mlx5/mlx5_crypto.c +++ b/drivers/crypto/mlx5/mlx5_crypto.c @@ -500,56 +500,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; } /** @@ -609,6 +605,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 = "", @@ -617,6 +614,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."); @@ -646,7 +645,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; @@ -686,6 +691,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); /* Register callback function for global shared MR cache management. */ if (TAILQ_EMPTY(&mlx5_crypto_priv_list)) rte_mem_event_callback_register("MLX5_MEM_EVENT_CB", diff --git a/drivers/crypto/mlx5/mlx5_crypto.h b/drivers/crypto/mlx5/mlx5_crypto.h index b98c621c23..d374d3c4e9 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. */ } __rte_cache_aligned; - struct mlx5_crypto_devarg_params { bool login_devarg; struct mlx5_devx_crypto_login_attr login_attr; + uint64_t keytag; }; int -- 2.27.0