From patchwork Thu Sep 8 15:29:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weiliang Luo X-Patchwork-Id: 15705 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id BE97D5398; Thu, 8 Sep 2016 17:31:01 +0200 (CEST) Received: from mail-pa0-f66.google.com (mail-pa0-f66.google.com [209.85.220.66]) by dpdk.org (Postfix) with ESMTP id 221A09E7 for ; Thu, 8 Sep 2016 17:31:00 +0200 (CEST) Received: by mail-pa0-f66.google.com with SMTP id ez1so2535884pab.3 for ; Thu, 08 Sep 2016 08:31:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=5opUi2qW3pvno8XYNzNlm7YahL2DqdRaDQOozP7RuzU=; b=PCumJZMyThwXezBnzPyDIF8Sa6cu/98LQtqz4EG3UG8TwwswVtN9mlg8EtcGfn0EON d+PVHlqggMjQkOGRj2ZLcoG+oGbtC40QPG4moA8XJh+riSV8DdN4HsVJNe0IiVc3364s HAhnHeV+P3wkpDWFz7XJuU5MOCoq0IWfjX42+R/ogRDQnJWBJcMDYaA6kjBGB5/W5Gk7 ibWJsbSARYtVtce1FfXdXuT62Y8DvPm7qXsPKFr6zAR2TXNRDNHtLW0aLG2DVuiGXKY1 s1n60F5dtNHMAlLG1P6iWA7zZZVLXsKp79Eb/24Lpi6jy5WpQu2hzXJZ1tl52KQHf1FE 4+lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=5opUi2qW3pvno8XYNzNlm7YahL2DqdRaDQOozP7RuzU=; b=ddXFk7gjuWTn3NVXfbVbYFTyrXfEBx6eoCHnGi7mz5oluOXwAp42oVYjVyIRlBdScN lrVULpvjVVJW5rVzsyyMiwljWJz1y97syzcfCaYdK4V0lRbIifiZIuh8YaDseENKnwie upgzhCRVSw/ACURUAEew5Bms3TVa+1NzhK6JBIf/K9lHSvtD/UKu34uMRtGH8DTKbwOY /1bTy+/2z9FSZrbxQuKrXn7eyhuS/mrXu04m9tg/ws2F+Y74YH3mRV0pdY0L6Df+HIgs bK+lfEyAL0aI4g+4nbGBvkFgMpNmNcjjmKuBblntGbEwmYldSCmkx49EV3Tgxdu2lymk rdfw== X-Gm-Message-State: AE9vXwMDMti9WslytFzXBUH+hsgqPJ+UCD/YlB4l9S5koZNLKocMkIiPGzpO0w6rT8xuiQ== X-Received: by 10.66.47.67 with SMTP id b3mr374055pan.43.1473348659444; Thu, 08 Sep 2016 08:30:59 -0700 (PDT) Received: from localhost.localdomain (rrcs-97-105-183-34.sw.biz.rr.com. [97.105.183.34]) by smtp.gmail.com with ESMTPSA id m82sm34199130pfk.64.2016.09.08.08.30.12 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 08 Sep 2016 08:30:18 -0700 (PDT) From: Weiliang Luo To: dev@dpdk.org Cc: Weiliang Luo Date: Thu, 8 Sep 2016 10:29:57 -0500 Message-Id: <1473348597-11904-1-git-send-email-droidluo@gmail.com> X-Mailer: git-send-email 2.7.4 (Apple Git-66) Subject: [dpdk-dev] [PATCH] mempool: fix corruption due to invalid handler X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" When using rte_mempool_create(), the mempool handler is selected depending on the flags given by the user: - multi-consumer / multi-producer - multi-consumer / single-producer - single-consumer / multi-producer - single-consumer / single-producer The flags were not properly tested, resulting in the selection of sc/sp handler if sc/mp or mc/sp was asked. This can lead to corruption or crashes because the get/put operations are not atomic. Fixes: 449c49b93a6b ("mempool: support handler operations") Signed-off-by: Weiliang Luo Acked-by: Olivier Matz --- lib/librte_mempool/rte_mempool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index 2e28e2e..350d77a 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -879,7 +879,7 @@ rte_mempool_create(const char *name, unsigned n, unsigned elt_size, * Since we have 4 combinations of the SP/SC/MP/MC examine the flags to * set the correct index into the table of ops structs. */ - if (flags & (MEMPOOL_F_SP_PUT | MEMPOOL_F_SC_GET)) + if ((flags & MEMPOOL_F_SP_PUT) && (flags & MEMPOOL_F_SC_GET)) rte_mempool_set_ops_byname(mp, "ring_sp_sc", NULL); else if (flags & MEMPOOL_F_SP_PUT) rte_mempool_set_ops_byname(mp, "ring_sp_mc", NULL);