From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id AA6B5A04B3; Sat, 16 Nov 2019 15:26:05 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 24D5E5B3E; Sat, 16 Nov 2019 15:25:35 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 17F7454AE for ; Sat, 16 Nov 2019 15:25:33 +0100 (CET) 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 xAGEJfwB018620 for ; Sat, 16 Nov 2019 06:25:32 -0800 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=pfpt0818; bh=ppPz5PLgMmADpZruZYvHU/rmgsTkqF9Iy0SN8JsMHbw=; b=wna8ByRTHXsWXPiK08nowqlSavhXFsDn8YUGFGJd1uv44aJBkw0ohJwhLinlJTmcSL66 lqv947noP6nKbOAJ3YYHROrNpnB1nqNKy6que43V2qXGPXx5oOxZVDKWXbWrTe6/TDcU WfRyQyBvkbKrUYTqEPbcYx8ZgBXwdQ3+x8Hcv967a38AJcfx+Tke+a1564svinnhLOKd eDFiHwc2nBxp8Vy0e796KcW/R1uKxhET/rpBSOKgGu5unCJkuOhDI2jtrSuAUmKAP6s+ +PbwuNFBCHj0towU7P1ocafbSKcHA4h2s9HRlqNecIWX5xp8XAdKI1A9bj2Rkr4wrdSa og== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0b-0016f401.pphosted.com with ESMTP id 2wahgs07km-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 16 Nov 2019 06:25:32 -0800 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sat, 16 Nov 2019 06:25:30 -0800 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Sat, 16 Nov 2019 06:25:30 -0800 Received: from BG-LT7430.marvell.com (unknown [10.28.17.42]) by maili.marvell.com (Postfix) with ESMTP id 4935E3F703F; Sat, 16 Nov 2019 06:25:29 -0800 (PST) From: To: CC: , Pavan Nikhilesh Date: Sat, 16 Nov 2019 19:55:15 +0530 Message-ID: <20191116142518.1500-5-pbhagavatula@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191116142518.1500-1-pbhagavatula@marvell.com> References: <20191116142518.1500-1-pbhagavatula@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,18.0.572 definitions=2019-11-16_04:2019-11-15,2019-11-16 signatures=0 Subject: [dpdk-dev] [PATCH 4/7] mempool/octeontx: add application domain validation 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" From: Pavan Nikhilesh Add application domain validation for OcteonTx FPA vfs. Signed-off-by: Pavan Nikhilesh --- drivers/mempool/octeontx/octeontx_fpavf.c | 86 +++++++++++++++-------- 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/drivers/mempool/octeontx/octeontx_fpavf.c b/drivers/mempool/octeontx/octeontx_fpavf.c index ec84a5cff..c97267db3 100644 --- a/drivers/mempool/octeontx/octeontx_fpavf.c +++ b/drivers/mempool/octeontx/octeontx_fpavf.c @@ -119,20 +119,22 @@ RTE_INIT(otx_pool_init_log) static int octeontx_fpa_gpool_alloc(unsigned int object_size) { + uint16_t global_domain = octeontx_get_global_domain(); struct fpavf_res *res = NULL; - uint16_t gpool; unsigned int sz128; + int i; sz128 = FPA_OBJSZ_2_CACHE_LINE(object_size); - for (gpool = 0; gpool < FPA_VF_MAX; gpool++) { + for (i = 0; i < FPA_VF_MAX; i++) { /* Skip VF that is not mapped Or _inuse */ - if ((fpadev.pool[gpool].bar0 == NULL) || - (fpadev.pool[gpool].is_inuse == true)) + if ((fpadev.pool[i].bar0 == NULL) || + (fpadev.pool[i].is_inuse == true) || + (fpadev.pool[i].domain_id != global_domain)) continue; - res = &fpadev.pool[gpool]; + res = &fpadev.pool[i]; RTE_ASSERT(res->domain_id != (uint16_t)~0); RTE_ASSERT(res->vf_id != (uint16_t)~0); @@ -140,15 +142,34 @@ octeontx_fpa_gpool_alloc(unsigned int object_size) if (res->sz128 == 0) { res->sz128 = sz128; + fpavf_log_dbg("gpool %d blk_sz %d\n", res->vf_id, + sz128); - fpavf_log_dbg("gpool %d blk_sz %d\n", gpool, sz128); - return gpool; + return res->vf_id; } } return -ENOSPC; } +static __rte_always_inline struct fpavf_res * +octeontx_get_fpavf(uint16_t gpool) +{ + uint16_t global_domain = octeontx_get_global_domain(); + int i; + + for (i = 0; i < FPA_VF_MAX; i++) { + if (fpadev.pool[i].domain_id != global_domain) + continue; + if (fpadev.pool[i].vf_id != gpool) + continue; + + return &fpadev.pool[i]; + } + + return NULL; +} + /* lock is taken by caller */ static __rte_always_inline uintptr_t octeontx_fpa_gpool2handle(uint16_t gpool) @@ -156,8 +177,10 @@ octeontx_fpa_gpool2handle(uint16_t gpool) struct fpavf_res *res = NULL; RTE_ASSERT(gpool < FPA_VF_MAX); + res = octeontx_get_fpavf(gpool); + if (res == NULL) + return 0; - res = &fpadev.pool[gpool]; return (uintptr_t)res->bar0 | gpool; } @@ -182,7 +205,7 @@ octeontx_fpa_handle_valid(uintptr_t handle) continue; /* validate gpool */ - if (gpool != i) + if (gpool != fpadev.pool[i].vf_id) return false; res = &fpadev.pool[i]; @@ -212,7 +235,10 @@ octeontx_fpapf_pool_setup(unsigned int gpool, unsigned int buf_size, struct octeontx_mbox_fpa_cfg cfg; int ret = -1; - fpa = &fpadev.pool[gpool]; + fpa = octeontx_get_fpavf(gpool); + if (fpa == NULL) + return -EINVAL; + memsz = FPA_ROUND_UP(max_buf_count / fpa->stack_ln_ptr, FPA_LN_SIZE) * FPA_LN_SIZE; @@ -278,7 +304,11 @@ octeontx_fpapf_pool_destroy(unsigned int gpool_index) struct fpavf_res *fpa = NULL; int ret = -1; - fpa = &fpadev.pool[gpool_index]; + fpa = octeontx_get_fpavf(gpool_index); + if (fpa == NULL) { + ret = -EINVAL; + goto err; + } hdr.coproc = FPA_COPROC; hdr.msg = FPA_CONFIGSET; @@ -422,6 +452,7 @@ octeontx_fpapf_start_count(uint16_t gpool_index) static __rte_always_inline int octeontx_fpavf_free(unsigned int gpool) { + struct fpavf_res *res = octeontx_get_fpavf(gpool); int ret = 0; if (gpool >= FPA_MAX_POOL) { @@ -430,7 +461,8 @@ octeontx_fpavf_free(unsigned int gpool) } /* Pool is free */ - fpadev.pool[gpool].is_inuse = false; + if (res != NULL) + res->is_inuse = false; err: return ret; @@ -439,8 +471,10 @@ octeontx_fpavf_free(unsigned int gpool) static __rte_always_inline int octeontx_gpool_free(uint16_t gpool) { - if (fpadev.pool[gpool].sz128 != 0) { - fpadev.pool[gpool].sz128 = 0; + struct fpavf_res *res = octeontx_get_fpavf(gpool); + + if (res && res->sz128 != 0) { + res->sz128 = 0; return 0; } return -EINVAL; @@ -460,8 +494,8 @@ octeontx_fpa_bufpool_block_size(uintptr_t handle) /* get the gpool */ gpool = octeontx_fpa_bufpool_gpool(handle); - res = &fpadev.pool[gpool]; - return FPA_CACHE_LINE_2_OBJSZ(res->sz128); + res = octeontx_get_fpavf(gpool); + return res ? FPA_CACHE_LINE_2_OBJSZ(res->sz128) : 0; } int @@ -722,6 +756,7 @@ octeontx_fpavf_identify(void *bar0) uint16_t domain_id; uint16_t vf_id; uint64_t stack_ln_ptr; + static uint16_t vf_idx; val = fpavf_read64((void *)((uintptr_t)bar0 + FPA_VF_VHAURA_CNT_THRESHOLD(0))); @@ -731,23 +766,18 @@ octeontx_fpavf_identify(void *bar0) stack_ln_ptr = fpavf_read64((void *)((uintptr_t)bar0 + FPA_VF_VHPOOL_THRESHOLD(0))); - if (vf_id >= FPA_VF_MAX) { + if (vf_idx >= FPA_VF_MAX) { fpavf_log_err("vf_id(%d) greater than max vf (32)\n", vf_id); - return -1; - } - - if (fpadev.pool[vf_id].is_inuse) { - fpavf_log_err("vf_id %d is_inuse\n", vf_id); - return -1; + return -E2BIG; } - fpadev.pool[vf_id].domain_id = domain_id; - fpadev.pool[vf_id].vf_id = vf_id; - fpadev.pool[vf_id].bar0 = bar0; - fpadev.pool[vf_id].stack_ln_ptr = stack_ln_ptr; + fpadev.pool[vf_idx].domain_id = domain_id; + fpadev.pool[vf_idx].vf_id = vf_id; + fpadev.pool[vf_idx].bar0 = bar0; + fpadev.pool[vf_idx].stack_ln_ptr = stack_ln_ptr; /* SUCCESS */ - return vf_id; + return vf_idx++; } /* FPAVF pcie device aka mempool probe */ -- 2.24.0