From patchwork Sat Jun 13 15:49:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolong Ye X-Patchwork-Id: 71502 X-Patchwork-Delegate: thomas@monjalon.net 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 41EC9A00BE; Sat, 13 Jun 2020 17:58:21 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D0E544C7A; Sat, 13 Jun 2020 17:58:15 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 96DE6493D; Sat, 13 Jun 2020 17:58:14 +0200 (CEST) IronPort-SDR: qvm//v4bbDF3obOUB9PDuYtA+PNjOy4dyPAeKJeDRc1GaJFmtInR2CqDLXiyzxwEoKaT88rf9Y rCoJ6wPyrd8g== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2020 08:58:13 -0700 IronPort-SDR: oiO6Va8jA/fJAXWnWiHXuGXm+wB4DJfd/yJWwUa8EI3tZZ9YgumTQr9MVrINvCjiRrcVhqdSdD vKZBVdYX2gZQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,507,1583222400"; d="scan'208";a="448663725" Received: from yexl-server.sh.intel.com ([10.67.116.183]) by orsmga005.jf.intel.com with ESMTP; 13 Jun 2020 08:58:11 -0700 From: Xiaolong Ye To: Olivier Matz , Thomas Monjalon , Konstantin Ananyev Cc: dev@dpdk.org, Xiaolong Ye , stable@dpdk.org Date: Sat, 13 Jun 2020 23:49:17 +0800 Message-Id: <20200613154922.42379-2-xiaolong.ye@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200613154922.42379-1-xiaolong.ye@intel.com> References: <20200613154922.42379-1-xiaolong.ye@intel.com> Subject: [dpdk-dev] [PATCH 1/5] mbuf: fix out-of-bounds access at dyn field register 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" We should make sure off + size < sizeof(struct rte_mbuf) to avoid possible out-of-bounds access of free_space array, there is no issue currently due to the low bits of free_flags (which is adjacent to free_space) are always set to 0. But we shouldn't rely on it since it's fragile and layout of struct mbuf_dyn_shm may be changed in the future. This patch adds boundary check explicitly to avoid potential risk of out-of-bounds access. Fixes: 4958ca3a443a ("mbuf: support dynamic fields and flags") Cc: stable@dpdk.org Signed-off-by: Xiaolong Ye Acked-by: Olivier Matz --- lib/librte_mbuf/rte_mbuf_dyn.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/librte_mbuf/rte_mbuf_dyn.c b/lib/librte_mbuf/rte_mbuf_dyn.c index 953e3ec31c..13d6da6d16 100644 --- a/lib/librte_mbuf/rte_mbuf_dyn.c +++ b/lib/librte_mbuf/rte_mbuf_dyn.c @@ -69,7 +69,8 @@ process_score(void) for (off = 0; off < sizeof(struct rte_mbuf); off++) { /* get the size of the free zone */ - for (size = 0; shm->free_space[off + size]; size++) + for (size = 0; (off + size) < sizeof(struct rte_mbuf) && + shm->free_space[off + size]; size++) ; if (size == 0) continue; From patchwork Sat Jun 13 15:49:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolong Ye X-Patchwork-Id: 71503 X-Patchwork-Delegate: thomas@monjalon.net 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 D8341A00BE; Sat, 13 Jun 2020 17:58:32 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 71A7F5F69; Sat, 13 Jun 2020 17:58:19 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 0202B4CBD; Sat, 13 Jun 2020 17:58:16 +0200 (CEST) IronPort-SDR: qLizPoESlTC3UCGQ+hweI2fjPIWsf3ucxgfddjSiZ4/wougdui3OrCgAfDgqzr4QS2U3qFxyTJ KRPHIL+J20Uw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2020 08:58:16 -0700 IronPort-SDR: OsTpodIPEL+V9p6Um937AiBJQrkfBFzjo9/if5jglusX+tvCghusrOjK8rEWeAB3JU8GW/Kx3h HnscAheuy3JA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,507,1583222400"; d="scan'208";a="448663731" Received: from yexl-server.sh.intel.com ([10.67.116.183]) by orsmga005.jf.intel.com with ESMTP; 13 Jun 2020 08:58:14 -0700 From: Xiaolong Ye To: Olivier Matz , Konstantin Ananyev , Thomas Monjalon Cc: dev@dpdk.org, Xiaolong Ye , stable@dpdk.org Date: Sat, 13 Jun 2020 23:49:18 +0800 Message-Id: <20200613154922.42379-3-xiaolong.ye@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200613154922.42379-1-xiaolong.ye@intel.com> References: <20200613154922.42379-1-xiaolong.ye@intel.com> Subject: [dpdk-dev] [PATCH 2/5] mbuf: fix missing errno for dyn field/flag registration 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" Set rte_errno as ENOMEM when allocation failure. Fixes: 4958ca3a443a ("mbuf: support dynamic fields and flags") Cc: stable@dpdk.org Signed-off-by: Xiaolong Ye Acked-by: Olivier Matz --- lib/librte_mbuf/rte_mbuf_dyn.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf_dyn.c b/lib/librte_mbuf/rte_mbuf_dyn.c index 13d6da6d16..de7d2eb9a5 100644 --- a/lib/librte_mbuf/rte_mbuf_dyn.c +++ b/lib/librte_mbuf/rte_mbuf_dyn.c @@ -278,12 +278,15 @@ __rte_mbuf_dynfield_register_offset(const struct rte_mbuf_dynfield *params, mbuf_dynfield_tailq.head, mbuf_dynfield_list); te = rte_zmalloc("MBUF_DYNFIELD_TAILQ_ENTRY", sizeof(*te), 0); - if (te == NULL) + if (te == NULL) { + rte_errno = ENOMEM; return -1; + } mbuf_dynfield = rte_zmalloc("mbuf_dynfield", sizeof(*mbuf_dynfield), 0); if (mbuf_dynfield == NULL) { rte_free(te); + rte_errno = ENOMEM; return -1; } @@ -456,12 +459,15 @@ __rte_mbuf_dynflag_register_bitnum(const struct rte_mbuf_dynflag *params, mbuf_dynflag_tailq.head, mbuf_dynflag_list); te = rte_zmalloc("MBUF_DYNFLAG_TAILQ_ENTRY", sizeof(*te), 0); - if (te == NULL) + if (te == NULL) { + rte_errno = ENOMEM; return -1; + } mbuf_dynflag = rte_zmalloc("mbuf_dynflag", sizeof(*mbuf_dynflag), 0); if (mbuf_dynflag == NULL) { rte_free(te); + rte_errno = ENOMEM; return -1; } From patchwork Sat Jun 13 15:49:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolong Ye X-Patchwork-Id: 71504 X-Patchwork-Delegate: thomas@monjalon.net 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 42EADA00BE; Sat, 13 Jun 2020 17:58:42 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id ACD7D49E0; Sat, 13 Jun 2020 17:58:23 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id A5F995323; Sat, 13 Jun 2020 17:58:22 +0200 (CEST) IronPort-SDR: dJhTQPtAmNDteTh91/hPiFrKk7SKdbanjMP5zWFIKS3y35C+To7JqfjasvOrSesEyuGt5b3u7e ctcuVV2JvO3A== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2020 08:58:21 -0700 IronPort-SDR: fi80MMwmvzjKO1T9yi9vB0n7sukaH4LUF1+RLeOeJ6vCH5vNi0AwpZv4HzzGd3jNs0Yn0clZx4 ITwbZSS+QeLw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,507,1583222400"; d="scan'208";a="448663744" Received: from yexl-server.sh.intel.com ([10.67.116.183]) by orsmga005.jf.intel.com with ESMTP; 13 Jun 2020 08:58:20 -0700 From: Xiaolong Ye To: Olivier Matz , Thomas Monjalon , Konstantin Ananyev Cc: dev@dpdk.org, Xiaolong Ye , stable@dpdk.org Date: Sat, 13 Jun 2020 23:49:19 +0800 Message-Id: <20200613154922.42379-4-xiaolong.ye@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200613154922.42379-1-xiaolong.ye@intel.com> References: <20200613154922.42379-1-xiaolong.ye@intel.com> Subject: [dpdk-dev] [PATCH 3/5] mbuf: fix free_space setting for dynamic field 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" The value free_space[i] is used to save the size of biggest aligned element that can fit in the zone, current implementation has one flaw, for example, if user registers dynfield1 (size = 4, align = 4, req = 124) first, the free_space would be as below after registration: 0070: 08 08 08 08 08 08 08 08 0078: 08 08 08 08 00 00 00 00 Then if user continues to register dynfield2 (size = 4, align = 4), free_space would become: 0070: 00 00 00 00 04 04 04 04 0078: 04 04 04 04 00 00 00 00 Further request dynfield3 (size = 8, align = 8) would fail to register due to alignment requirement can't be satisfied, though there is enough space remained in mbuf. This patch fixes above issue by saving alignment only in aligned zone, after the fix, above registrations order can be satisfied, free_space would be like: After dynfield1 registration: 0070: 08 08 08 08 08 08 08 08 0078: 04 04 04 04 00 00 00 00 After dynfield2 registration: 0070: 08 08 08 08 08 08 08 08 0078: 00 00 00 00 00 00 00 00 After dynfield3 registration: 0070: 00 00 00 00 00 00 00 00 0078: 00 00 00 00 00 00 00 00 This patch also reduces iterations in process_score() by jumping align steps in each loop. Fixes: 4958ca3a443a ("mbuf: support dynamic fields and flags") Cc: stable@dpdk.org Signed-off-by: Xiaolong Ye Acked-by: Olivier Matz --- lib/librte_mbuf/rte_mbuf_dyn.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf_dyn.c b/lib/librte_mbuf/rte_mbuf_dyn.c index de7d2eb9a5..fd51e1b68e 100644 --- a/lib/librte_mbuf/rte_mbuf_dyn.c +++ b/lib/librte_mbuf/rte_mbuf_dyn.c @@ -67,13 +67,16 @@ process_score(void) shm->free_space[i] = 1; } - for (off = 0; off < sizeof(struct rte_mbuf); off++) { + off = 0; + while (off < sizeof(struct rte_mbuf)) { /* get the size of the free zone */ for (size = 0; (off + size) < sizeof(struct rte_mbuf) && shm->free_space[off + size]; size++) ; - if (size == 0) + if (size == 0) { + off++; continue; + } /* get the alignment of biggest object that can fit in * the zone at this offset. @@ -84,8 +87,10 @@ process_score(void) ; /* save it in free_space[] */ - for (i = off; i < off + size; i++) + for (i = off; i < off + align; i++) shm->free_space[i] = RTE_MAX(align, shm->free_space[i]); + + off += align; } } From patchwork Sat Jun 13 15:49:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolong Ye X-Patchwork-Id: 71505 X-Patchwork-Delegate: thomas@monjalon.net 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 DE59FA00BE; Sat, 13 Jun 2020 17:58:52 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1DF121BC25; Sat, 13 Jun 2020 17:58:27 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 3D0831B952; Sat, 13 Jun 2020 17:58:25 +0200 (CEST) IronPort-SDR: CKQ+DLJx/gVpIv9ctamrFCvSZhde0FqsR9dW/ex5WASZk4vl5xpAPcXqRywo1K0471HbianTsr G1F5DrohPVYw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2020 08:58:24 -0700 IronPort-SDR: mYuB9LylJ8TykyRLMDllhrqc0rBf4yUxxoMhpHWX7vtxejpX0mWWJi7GxDM+zNk9mdQ4cehrzK 4Z8QLIzkQp8w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,507,1583222400"; d="scan'208";a="448663751" Received: from yexl-server.sh.intel.com ([10.67.116.183]) by orsmga005.jf.intel.com with ESMTP; 13 Jun 2020 08:58:23 -0700 From: Xiaolong Ye To: Olivier Matz , Konstantin Ananyev , Thomas Monjalon Cc: dev@dpdk.org, Xiaolong Ye , stable@dpdk.org Date: Sat, 13 Jun 2020 23:49:20 +0800 Message-Id: <20200613154922.42379-5-xiaolong.ye@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200613154922.42379-1-xiaolong.ye@intel.com> References: <20200613154922.42379-1-xiaolong.ye@intel.com> Subject: [dpdk-dev] [PATCH 4/5] mbuf: fix a dynamic field dump log 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" For each mbuf byte, free_space[i] == 0 means the space is occupied, free_space[i] != 0 means space is free. Fixes: 4958ca3a443a ("mbuf: support dynamic fields and flags") Cc: stable@dpdk.org Signed-off-by: Xiaolong Ye Acked-by: Olivier Matz --- lib/librte_mbuf/rte_mbuf_dyn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/librte_mbuf/rte_mbuf_dyn.c b/lib/librte_mbuf/rte_mbuf_dyn.c index fd51e1b68e..f071651acf 100644 --- a/lib/librte_mbuf/rte_mbuf_dyn.c +++ b/lib/librte_mbuf/rte_mbuf_dyn.c @@ -552,7 +552,7 @@ void rte_mbuf_dyn_dump(FILE *out) dynflag->params.name, dynflag->bitnum, dynflag->params.flags); } - fprintf(out, "Free space in mbuf (0 = free, value = zone alignment):\n"); + fprintf(out, "Free space in mbuf (0 = occupied, value = free zone alignment):\n"); for (i = 0; i < sizeof(struct rte_mbuf); i++) { if ((i % 8) == 0) fprintf(out, " %4.4zx: ", i); From patchwork Sat Jun 13 15:49:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolong Ye X-Patchwork-Id: 71506 X-Patchwork-Delegate: thomas@monjalon.net 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 F2A2FA00BE; Sat, 13 Jun 2020 17:59:01 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 68E011BE3D; Sat, 13 Jun 2020 17:58:30 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 074105B3C for ; Sat, 13 Jun 2020 17:58:27 +0200 (CEST) IronPort-SDR: /FE279+2h/rzGL8sabpW07FYF0aVzrPE+cnOU6Ik1agEUENfDJpcckhuMmulmcBeXlIBZW9hDs OSYti52dANtA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2020 08:58:27 -0700 IronPort-SDR: NcqLM3zrDszTFZqT5LVu3LyBdiylDwZB9atXVf8lFN24Rt0J0OKVAPNVGRM+AAFBtjCPeLUttE 0ARU6l7n6pJA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,507,1583222400"; d="scan'208";a="448663759" Received: from yexl-server.sh.intel.com ([10.67.116.183]) by orsmga005.jf.intel.com with ESMTP; 13 Jun 2020 08:58:26 -0700 From: Xiaolong Ye To: Olivier Matz Cc: dev@dpdk.org, Xiaolong Ye Date: Sat, 13 Jun 2020 23:49:21 +0800 Message-Id: <20200613154922.42379-6-xiaolong.ye@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200613154922.42379-1-xiaolong.ye@intel.com> References: <20200613154922.42379-1-xiaolong.ye@intel.com> Subject: [dpdk-dev] [PATCH 5/5] mbuf: support to dump free_flags for dynamic flag 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" Add support to dump free_flags as below format: Free bit in mbuf->ol_flags (0 = occupied, 1 = free): 0000: 0 0 0 0 0 0 0 0 0008: 0 0 0 0 0 0 0 0 0010: 0 0 0 0 0 0 0 1 0018: 1 1 1 1 1 1 1 1 0020: 1 1 1 1 1 1 1 1 0028: 1 0 0 0 0 0 0 0 0030: 0 0 0 0 0 0 0 0 0038: 0 0 0 0 0 0 0 0 Signed-off-by: Xiaolong Ye Acked-by: Olivier Matz --- lib/librte_mbuf/rte_mbuf_dyn.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/librte_mbuf/rte_mbuf_dyn.c b/lib/librte_mbuf/rte_mbuf_dyn.c index f071651acf..538a43f695 100644 --- a/lib/librte_mbuf/rte_mbuf_dyn.c +++ b/lib/librte_mbuf/rte_mbuf_dyn.c @@ -559,5 +559,13 @@ void rte_mbuf_dyn_dump(FILE *out) fprintf(out, "%2.2x%s", shm->free_space[i], (i % 8 != 7) ? " " : "\n"); } + fprintf(out, "Free bit in mbuf->ol_flags (0 = occupied, 1 = free):\n"); + for (i = 0; i < sizeof(uint64_t) * CHAR_BIT; i++) { + if ((i % 8) == 0) + fprintf(out, " %4.4zx: ", i); + fprintf(out, "%1.1x%s", (shm->free_flags & (1ULL << i)) ? 1 : 0, + (i % 8 != 7) ? " " : "\n"); + } + rte_mcfg_tailq_write_unlock(); }