From patchwork Thu Sep 3 11:18:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ankur Dwivedi X-Patchwork-Id: 76403 X-Patchwork-Delegate: jerinj@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id CA398A04C5; Thu, 3 Sep 2020 13:20:06 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3CF511C0B7; Thu, 3 Sep 2020 13:20:06 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id EE8221C0B6 for ; Thu, 3 Sep 2020 13:20:04 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 083BFa5S006631; Thu, 3 Sep 2020 04:20:04 -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=bYQdmYxGsH7Z3LeXrasHxi5rApbXLPvqTAjrR/3qKzU=; b=VIpt166hvfLF2zLb+zz3fqzACy7guO6YdidnDlt8uLyonZ/N+JF2yymxoqFyafSnwwuC vrv3gkexjLKZ/PIai6VJt3jy6NXPBh3ZDg+oOGAoAc6u+rfmy61T7a/QrdQS751jI9yN qQX81GzeYbwNZ6ekLllQpoyD7r/dBsBthybHmSaluotv7reMTlwQSMGITRbIqhHx2KRP VcZdPrMELZD/E3wf00XXEuw7d+w8sP6+C5p5++ziyXsGcFWbPn9sCSrMlSSz7/KJJjio watwmfaxKpKNhhdufe3CeZ9Fr1JjflEwxvWC76h2o++mm3vjsOxe/tuL2LrV8ZBBwaHR sQ== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0b-0016f401.pphosted.com with ESMTP id 337phqb5fk-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 03 Sep 2020 04:20:04 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 3 Sep 2020 04:20:02 -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.2 via Frontend Transport; Thu, 3 Sep 2020 04:20:03 -0700 Received: from hyd1349.t110.caveonetworks.com (unknown [10.29.45.13]) by maili.marvell.com (Postfix) with ESMTP id 37BFF3F7043; Thu, 3 Sep 2020 04:20:00 -0700 (PDT) From: Ankur Dwivedi To: CC: , , , Ankur Dwivedi Date: Thu, 3 Sep 2020 16:48:35 +0530 Message-ID: <20200903111836.6864-2-adwivedi@marvell.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200903111836.6864-1-adwivedi@marvell.com> References: <20200903111836.6864-1-adwivedi@marvell.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-09-03_05:2020-09-03, 2020-09-03 signatures=0 Subject: [dpdk-dev] [PATCH 1/2] net/octeontx2: add anti replay support in security session X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" Initialize the inbound session for anti replay. The replay window is allocated during session create and freed in session destroy. Signed-off-by: Ankur Dwivedi --- drivers/crypto/octeontx2/otx2_ipsec_fp.h | 29 ++++++++++++++-- drivers/crypto/octeontx2/otx2_security.h | 3 ++ drivers/net/octeontx2/otx2_ethdev_sec.c | 42 ++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/octeontx2/otx2_ipsec_fp.h b/drivers/crypto/octeontx2/otx2_ipsec_fp.h index 52b3b41e2..a33041d77 100644 --- a/drivers/crypto/octeontx2/otx2_ipsec_fp.h +++ b/drivers/crypto/octeontx2/otx2_ipsec_fp.h @@ -8,6 +8,17 @@ #include #include +/* Macros for anti replay and ESN */ +#define OTX2_IPSEC_MAX_REPLAY_WIN_SZ 1024 +#define OTX2_IPSEC_SAINDEX_SZ 4 +#define OTX2_IPSEC_SEQNO_LO 4 + +#define OTX2_IPSEC_SEQNO_LO_INDEX (RTE_ETHER_HDR_LEN + \ + OTX2_IPSEC_SAINDEX_SZ) + +#define OTX2_IPSEC_SEQNO_HI_INDEX (OTX2_IPSEC_SEQNO_LO_INDEX + \ + OTX2_IPSEC_SEQNO_LO) + enum { OTX2_IPSEC_FP_SA_DIRECTION_INBOUND = 0, OTX2_IPSEC_FP_SA_DIRECTION_OUTBOUND = 1, @@ -105,6 +116,14 @@ struct otx2_ipsec_fp_out_sa { uint8_t hmac_key[48]; }; +struct otx2_ipsec_replay { + rte_spinlock_t lock; + uint32_t winb; + uint32_t wint; + uint64_t base; /**< base of the anti-replay window */ + uint64_t window[17]; /**< anti-replay window */ +}; + struct otx2_ipsec_fp_in_sa { /* w0 */ struct otx2_ipsec_fp_sa_ctl ctl; @@ -114,8 +133,8 @@ struct otx2_ipsec_fp_in_sa { uint32_t unused; /* w2 */ - uint32_t esn_low; uint32_t esn_hi; + uint32_t esn_low; /* w3-w6 */ uint8_t cipher_key[32]; @@ -128,9 +147,13 @@ struct otx2_ipsec_fp_in_sa { void *userdata; uint64_t udata64; }; + union { + struct otx2_ipsec_replay *replay; + uint64_t replay64; + }; + uint32_t replay_win_sz; - uint64_t reserved1; - uint64_t reserved2; + uint32_t reserved1; }; static inline int diff --git a/drivers/crypto/octeontx2/otx2_security.h b/drivers/crypto/octeontx2/otx2_security.h index 086b50604..33d3b1515 100644 --- a/drivers/crypto/octeontx2/otx2_security.h +++ b/drivers/crypto/octeontx2/otx2_security.h @@ -5,6 +5,8 @@ #ifndef __OTX2_SECURITY_H__ #define __OTX2_SECURITY_H__ +#include + #include "otx2_cryptodev_sec.h" #include "otx2_ethdev_sec.h" @@ -20,6 +22,7 @@ union otx2_sec_session_ipsec { struct otx2_sec_session_ipsec_ip ip; struct otx2_sec_session_ipsec_lp lp; + enum rte_security_ipsec_sa_direction dir; }; struct otx2_sec_session { diff --git a/drivers/net/octeontx2/otx2_ethdev_sec.c b/drivers/net/octeontx2/otx2_ethdev_sec.c index a155594e2..af91e30f4 100644 --- a/drivers/net/octeontx2/otx2_ethdev_sec.c +++ b/drivers/net/octeontx2/otx2_ethdev_sec.c @@ -360,6 +360,7 @@ eth_sec_ipsec_out_sess_create(struct rte_eth_dev *eth_dev, struct otx2_cpt_qp *qp; priv = get_sec_session_private_data(sec_sess); + priv->ipsec.dir = RTE_SECURITY_IPSEC_SA_DIR_EGRESS; sess = &priv->ipsec.ip; sa = &sess->out_sa; @@ -482,6 +483,7 @@ eth_sec_ipsec_in_sess_create(struct rte_eth_dev *eth_dev, ctl = &sa->ctl; priv = get_sec_session_private_data(sec_sess); + priv->ipsec.dir = RTE_SECURITY_IPSEC_SA_DIR_INGRESS; sess = &priv->ipsec.ip; if (ctl->valid) { @@ -519,6 +521,8 @@ eth_sec_ipsec_in_sess_create(struct rte_eth_dev *eth_dev, sa->userdata = priv->userdata; + sa->replay_win_sz = ipsec->replay_win_sz; + if (lookup_mem_sa_index_update(eth_dev, ipsec->spi, sa)) return -EINVAL; @@ -533,7 +537,32 @@ eth_sec_ipsec_in_sess_create(struct rte_eth_dev *eth_dev, return ret; ret = hmac_init(ctl, qp, auth_key, auth_key_len, sa->hmac_key); otx2_sec_idev_tx_cpt_qp_put(qp); + if (ret) + return ret; } + + if (sa->replay_win_sz) { + if (sa->replay_win_sz > OTX2_IPSEC_MAX_REPLAY_WIN_SZ) { + otx2_err("Replay window size is not supported"); + return -ENOTSUP; + } + sa->replay = rte_zmalloc(NULL, sizeof(struct otx2_ipsec_replay), + 0); + if (sa->replay == NULL) + return -ENOMEM; + + rte_spinlock_init(&sa->replay->lock); + /* + * Set window bottom to 1, base and top to size of + * window + */ + sa->replay->winb = 1; + sa->replay->wint = sa->replay_win_sz; + sa->replay->base = sa->replay_win_sz; + sa->esn_low = 0; + sa->esn_hi = 0; + } + return ret; } @@ -600,6 +629,15 @@ otx2_eth_sec_session_create(void *device, return ret; } +static void +otx2_eth_sec_free_anti_replay(struct otx2_ipsec_fp_in_sa *sa) +{ + if (sa != NULL) { + if (sa->replay_win_sz && sa->replay) + rte_free(sa->replay); + } +} + static int otx2_eth_sec_session_destroy(void *device __rte_unused, struct rte_security_session *sess) @@ -615,6 +653,10 @@ otx2_eth_sec_session_destroy(void *device __rte_unused, sess_ip = &priv->ipsec.ip; + /* Release the anti replay window */ + if (priv->ipsec.dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) + otx2_eth_sec_free_anti_replay(sess_ip->in_sa); + /* Release CPT LF used for this session */ if (sess_ip->qp != NULL) { ret = otx2_sec_idev_tx_cpt_qp_put(sess_ip->qp);