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 9922242800 for ; Wed, 22 Mar 2023 01:42:02 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 53CE842BC9; Wed, 22 Mar 2023 01:42:02 +0100 (CET) Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by mails.dpdk.org (Postfix) with ESMTP id 4EBE6427F2 for ; Wed, 22 Mar 2023 01:42:01 +0100 (CET) Received: by mail-wr1-f42.google.com with SMTP id l27so7113270wrb.2 for ; Tue, 21 Mar 2023 17:42:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679445721; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tObgIzBA3LN9qpF6eNg0g2f+BsWBwdp/nJjxUM8+do8=; b=jbVido2atddzIFwE76t1hBH1Mv/HHabed8FXKeFwZulfdY3+zS8CWyCEPaeYdaBmHx qwO4CYUiu5kJB+0HdhTT9uk9TDwgzHH/HPcKlMRuQu/DI/VuT7xHYBRSxM1emW5G0HNB VrGkOmfRxIqKRK5wK0uLBGC/tSP02i97X6QUn4IjNP0/fD8JRHmcSQdCZeGbhT/Pjti9 XDMyfSrP2megz5XDlvP5qubYu58A+81a6TUVMCivO/sXK7zlCnKSFX8xNp83WYh0c61j VFdAT7H6aVWlY9ULbn/aH+rALYfE1WbeXWN9nqlgg4oCpqHcK71ho/T/Svw0lLvDtgts biXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679445721; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tObgIzBA3LN9qpF6eNg0g2f+BsWBwdp/nJjxUM8+do8=; b=I21e38Aah+LN8ZJEzgGiJnNsncyylyZ809pRxn5FWxZ0yrC05Ykc+5MWdtWaO/12jD pGDqCn/BuDp/mkSiy7Z41Aagu3a0voKAAc2eUizGyX9vJWtgmaVPAURVwWaoMagdZLOz E2ScnxvYDogvPc5Ni/jjEnr8+KlGyd9JM/2uv0aoEv1kJJ3Ricvz1ukrGnK8faAE/ZFB 3aE7ytdINbOJcq+cc9WIy0i6/A8uy6VZIT1qtAZC9+3H+bVvquk3c5z++5m/HvXPkF9Q wPWd4EOkkA28b7TI3vyCuhjk4hIOdgqkEK8v4J+BMknP7aQRMm6GBtROeutbFFun55C1 WvGA== X-Gm-Message-State: AO0yUKUse0zZsFb85+GAHfAuWZvn5+q+in5RcMCOzCLfufiNkQ82RMXE V6sG1u8ddrnZHrvODfVyR2CLdyJ9YGU= X-Google-Smtp-Source: AK7set89NV5JUDez8VqK1/HPdMMoFNqs7Ga1OQjLJxReHfkf+kWeIHs/ks3zZ6/ijStthEcta4TGCA== X-Received: by 2002:adf:cf12:0:b0:2cb:76d4:42ea with SMTP id o18-20020adfcf12000000b002cb76d442eamr3519295wrj.36.1679445720742; Tue, 21 Mar 2023 17:42:00 -0700 (PDT) Received: from localhost ([2a01:4b00:d307:1000:f1d3:eb5e:11f4:a7d9]) by smtp.gmail.com with ESMTPSA id w2-20020a5d6802000000b002cfe687fc7asm12438512wru.67.2023.03.21.17.42.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 17:42:00 -0700 (PDT) From: luca.boccassi@gmail.com To: Volodymyr Fialko Cc: dpdk stable Subject: patch 'reorder: fix sequence number mbuf field register' has been queued to stable release 20.11.8 Date: Wed, 22 Mar 2023 00:41:39 +0000 Message-Id: <20230322004155.2333903-3-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230322004155.2333903-1-luca.boccassi@gmail.com> References: <20230315224631.1025649-39-luca.boccassi@gmail.com> <20230322004155.2333903-1-luca.boccassi@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Hi, FYI, your patch has been queued to stable release 20.11.8 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 03/23/23. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/bluca/dpdk-stable This queued commit can be viewed at: https://github.com/bluca/dpdk-stable/commit/fca297ca06833f852cf1880a2147daa6cdd59a8f Thanks. Luca Boccassi --- >From fca297ca06833f852cf1880a2147daa6cdd59a8f Mon Sep 17 00:00:00 2001 From: Volodymyr Fialko Date: Mon, 13 Mar 2023 14:04:28 +0100 Subject: [PATCH] reorder: fix sequence number mbuf field register [ upstream commit ec87595f4de01cb81878874d209fa03e6963b3e4 ] It's possible to initialize reorder buffer with user allocated memory via rte_reorder_init() function. In such case, rte_reorder_create() is not required and reorder dynamic field in rte_mbuf will not be registered. Both reorder lib and mbuf dynamic field are using `rte_mcfg_tailq` read/write lock for synchronization. To avoid deadlocking, move reorder buffer initialization before queue insertion. Fixes: 01f3496695b5 ("reorder: switch sequence number to dynamic mbuf field") Signed-off-by: Volodymyr Fialko --- lib/librte_reorder/rte_reorder.c | 95 ++++++++++++++++++++------------ lib/librte_reorder/rte_reorder.h | 1 + 2 files changed, 62 insertions(+), 34 deletions(-) diff --git a/lib/librte_reorder/rte_reorder.c b/lib/librte_reorder/rte_reorder.c index a5b9663aa5..5d4fab17ff 100644 --- a/lib/librte_reorder/rte_reorder.c +++ b/lib/librte_reorder/rte_reorder.c @@ -61,6 +61,11 @@ rte_reorder_init(struct rte_reorder_buffer *b, unsigned int bufsize, { const unsigned int min_bufsize = sizeof(*b) + (2 * size * sizeof(struct rte_mbuf *)); + static const struct rte_mbuf_dynfield reorder_seqn_dynfield_desc = { + .name = RTE_REORDER_SEQN_DYNFIELD_NAME, + .size = sizeof(rte_reorder_seqn_t), + .align = __alignof__(rte_reorder_seqn_t), + }; if (b == NULL) { RTE_LOG(ERR, REORDER, "Invalid reorder buffer parameter:" @@ -87,6 +92,15 @@ rte_reorder_init(struct rte_reorder_buffer *b, unsigned int bufsize, return NULL; } + rte_reorder_seqn_dynfield_offset = rte_mbuf_dynfield_register(&reorder_seqn_dynfield_desc); + if (rte_reorder_seqn_dynfield_offset < 0) { + RTE_LOG(ERR, REORDER, + "Failed to register mbuf field for reorder sequence number, rte_errno: %i\n", + rte_errno); + rte_errno = ENOMEM; + return NULL; + } + memset(b, 0, bufsize); strlcpy(b->name, name, sizeof(b->name)); b->memsize = bufsize; @@ -99,21 +113,45 @@ rte_reorder_init(struct rte_reorder_buffer *b, unsigned int bufsize, return b; } +/* + * Insert new entry into global list. + * Returns pointer to already inserted entry if such exists, or to newly inserted one. + */ +static struct rte_tailq_entry * +rte_reorder_entry_insert(struct rte_tailq_entry *new_te) +{ + struct rte_reorder_list *reorder_list; + struct rte_reorder_buffer *b, *nb; + struct rte_tailq_entry *te; + + rte_mcfg_tailq_write_lock(); + + reorder_list = RTE_TAILQ_CAST(rte_reorder_tailq.head, rte_reorder_list); + /* guarantee there's no existing */ + TAILQ_FOREACH(te, reorder_list, next) { + b = (struct rte_reorder_buffer *) te->data; + nb = (struct rte_reorder_buffer *) new_te->data; + if (strncmp(nb->name, b->name, RTE_REORDER_NAMESIZE) == 0) + break; + } + + if (te == NULL) { + TAILQ_INSERT_TAIL(reorder_list, new_te, next); + te = new_te; + } + + rte_mcfg_tailq_write_unlock(); + + return te; +} + struct rte_reorder_buffer* rte_reorder_create(const char *name, unsigned socket_id, unsigned int size) { struct rte_reorder_buffer *b = NULL; - struct rte_tailq_entry *te; - struct rte_reorder_list *reorder_list; + struct rte_tailq_entry *te, *te_inserted; const unsigned int bufsize = sizeof(struct rte_reorder_buffer) + (2 * size * sizeof(struct rte_mbuf *)); - static const struct rte_mbuf_dynfield reorder_seqn_dynfield_desc = { - .name = RTE_REORDER_SEQN_DYNFIELD_NAME, - .size = sizeof(rte_reorder_seqn_t), - .align = __alignof__(rte_reorder_seqn_t), - }; - - reorder_list = RTE_TAILQ_CAST(rte_reorder_tailq.head, rte_reorder_list); /* Check user arguments. */ if (!rte_is_power_of_2(size)) { @@ -129,32 +167,12 @@ rte_reorder_create(const char *name, unsigned socket_id, unsigned int size) return NULL; } - rte_reorder_seqn_dynfield_offset = - rte_mbuf_dynfield_register(&reorder_seqn_dynfield_desc); - if (rte_reorder_seqn_dynfield_offset < 0) { - RTE_LOG(ERR, REORDER, "Failed to register mbuf field for reorder sequence number\n"); - rte_errno = ENOMEM; - return NULL; - } - - rte_mcfg_tailq_write_lock(); - - /* guarantee there's no existing */ - TAILQ_FOREACH(te, reorder_list, next) { - b = (struct rte_reorder_buffer *) te->data; - if (strncmp(name, b->name, RTE_REORDER_NAMESIZE) == 0) - break; - } - if (te != NULL) - goto exit; - /* allocate tailq entry */ te = rte_zmalloc("REORDER_TAILQ_ENTRY", sizeof(*te), 0); if (te == NULL) { RTE_LOG(ERR, REORDER, "Failed to allocate tailq entry\n"); rte_errno = ENOMEM; - b = NULL; - goto exit; + return NULL; } /* Allocate memory to store the reorder buffer structure. */ @@ -163,14 +181,23 @@ rte_reorder_create(const char *name, unsigned socket_id, unsigned int size) RTE_LOG(ERR, REORDER, "Memzone allocation failed\n"); rte_errno = ENOMEM; rte_free(te); + return NULL; } else { - rte_reorder_init(b, bufsize, name, size); + if (rte_reorder_init(b, bufsize, name, size) == NULL) { + rte_free(b); + rte_free(te); + return NULL; + } te->data = (void *)b; - TAILQ_INSERT_TAIL(reorder_list, te, next); } -exit: - rte_mcfg_tailq_write_unlock(); + te_inserted = rte_reorder_entry_insert(te); + if (te_inserted != te) { + rte_free(b); + rte_free(te); + return te_inserted->data; + } + return b; } diff --git a/lib/librte_reorder/rte_reorder.h b/lib/librte_reorder/rte_reorder.h index 9de0240374..4d4ea31e41 100644 --- a/lib/librte_reorder/rte_reorder.h +++ b/lib/librte_reorder/rte_reorder.h @@ -81,6 +81,7 @@ rte_reorder_create(const char *name, unsigned socket_id, unsigned int size); * The initialized reorder buffer instance, or NULL on error * On error case, rte_errno will be set appropriately: * - EINVAL - invalid parameters + * - ENOMEM - not enough memory to register dynamic field */ struct rte_reorder_buffer * rte_reorder_init(struct rte_reorder_buffer *b, unsigned int bufsize, -- 2.39.2 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2023-03-21 21:56:37.182035599 +0000 +++ 0003-reorder-fix-sequence-number-mbuf-field-register.patch 2023-03-21 21:56:37.008805712 +0000 @@ -1 +1 @@ -From ec87595f4de01cb81878874d209fa03e6963b3e4 Mon Sep 17 00:00:00 2001 +From fca297ca06833f852cf1880a2147daa6cdd59a8f Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit ec87595f4de01cb81878874d209fa03e6963b3e4 ] + @@ -15 +16,0 @@ -Cc: stable@dpdk.org @@ -19,2 +20,2 @@ - lib/reorder/rte_reorder.c | 95 +++++++++++++++++++++++++-------------- - lib/reorder/rte_reorder.h | 1 + + lib/librte_reorder/rte_reorder.c | 95 ++++++++++++++++++++------------ + lib/librte_reorder/rte_reorder.h | 1 + @@ -23,4 +24,4 @@ -diff --git a/lib/reorder/rte_reorder.c b/lib/reorder/rte_reorder.c -index 9026403ea6..4bf36f6df6 100644 ---- a/lib/reorder/rte_reorder.c -+++ b/lib/reorder/rte_reorder.c +diff --git a/lib/librte_reorder/rte_reorder.c b/lib/librte_reorder/rte_reorder.c +index a5b9663aa5..5d4fab17ff 100644 +--- a/lib/librte_reorder/rte_reorder.c ++++ b/lib/librte_reorder/rte_reorder.c @@ -172,5 +173,5 @@ -diff --git a/lib/reorder/rte_reorder.h b/lib/reorder/rte_reorder.h -index 7ed5f66a2e..f1207f72a9 100644 ---- a/lib/reorder/rte_reorder.h -+++ b/lib/reorder/rte_reorder.h -@@ -82,6 +82,7 @@ rte_reorder_create(const char *name, unsigned socket_id, unsigned int size); +diff --git a/lib/librte_reorder/rte_reorder.h b/lib/librte_reorder/rte_reorder.h +index 9de0240374..4d4ea31e41 100644 +--- a/lib/librte_reorder/rte_reorder.h ++++ b/lib/librte_reorder/rte_reorder.h +@@ -81,6 +81,7 @@ rte_reorder_create(const char *name, unsigned socket_id, unsigned int size);