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 808D3A00C4; Thu, 4 Jun 2020 19:17:48 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CA39D1D5D8; Thu, 4 Jun 2020 19:17:47 +0200 (CEST) Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by dpdk.org (Postfix) with ESMTP id AFF591D5D7 for ; Thu, 4 Jun 2020 19:17:46 +0200 (CEST) Received: by mail-pl1-f193.google.com with SMTP id q16so2457218plr.2 for ; Thu, 04 Jun 2020 10:17:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SMIGnVCdJCvQ6kvEhEqQ/nFer3cSDrriyDrgkWRJ+sE=; b=fpZUW9t+5nF17mko5Xne4/Uo04sKuM52Q9tdfdzfqKkaZTFEIUtghiD0sdkeYBYfcG X7nEANgey4shm8h0g5DN4V+e1/zj+lAATid7eEh4UIzWMa/DSJF342Is/8PnJ+D2g2Xm 3I+OBl3t1XlW9tUngNuLUm6Kft27f31zJD6FgMLK2OwTFAV2Zxw5i2KPEHwAx8JAP1O2 3BdG81wIfaGXJjnNWHXXdxk2R+pRmlkbB4oDN81cQ7no4HtOCdLLaeEv2V34KQC1NynU h4HfR+HIEZ6S1saezSWI6LT2zd/KG5aCcleqn4SIB/bLzqjlPD+C79eFjg3FeA7Tbk5L Eihw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SMIGnVCdJCvQ6kvEhEqQ/nFer3cSDrriyDrgkWRJ+sE=; b=JotixKtrDvULzFPtSOz4mygcQRkZt1kZIE9hO42hDGSLJ4o0cl3SJsBzObC98IeMUG beKsHKY5uxYcTeclVQCfhK5rBZsxt2IAWE3LHaFjxVsXVUsCCCnoDcJzFAdpWzU7pGgZ h2PcN2O8ZjLmOKoC7DqTILb+Xi7+h7Zu/zyRq6uTo9iWmMUVXf92ZWqX8BIADeH65HZJ 4xSLokrt24SP66oXk43yN6+iDoBn0ADpyuQlkX14bEzlhpcLCAGl+wY+hfJ4rxWsXXK7 vsgImlG52v3LWBEgo0cYoTZJOOM/kDdRihIUKN6ycPrNWpY6jVTbhcqPStJtoMY906yH GrXg== X-Gm-Message-State: AOAM532A7G0ygP6kT7RLUfzhX4+C68vqblQET0a4tFuTmOdYxIuaJF76 6MG/Q5aUVUlkmwJ4xByJJTKgtA== X-Google-Smtp-Source: ABdhPJwVbwuwF78N1d0lPjEb58k3Km8e+BtwDLrKtkq7hpKNEptb7evIfzyAjtoBzwV0Yn3/msjlGw== X-Received: by 2002:a17:902:694b:: with SMTP id k11mr6060212plt.59.1591291065514; Thu, 04 Jun 2020 10:17:45 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id k126sm5170011pfd.129.2020.06.04.10.17.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 10:17:44 -0700 (PDT) From: Stephen Hemminger To: Yipeng Wang , Sameh Gobriel , Bruce Richardson Cc: dev@dpdk.org, Stephen Hemminger , honnappa.nagarahalli@arm.com, pablo.de.lara.guarch@intel.com Date: Thu, 4 Jun 2020 10:17:31 -0700 Message-Id: <20200604171731.6738-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] hash: document breakage with multi-writer thread 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 code in rte_cuckoo_hash multi-writer support is broken if write operations are called from a non-EAL thread. rte_lcore_id() wil return LCORE_ID_ANY (UINT32_MAX) for non EAL thread and that leads to using wrong local cache. Add error checks and document the restriction. Fixes: 9d033dac7d7c ("hash: support no free on delete") Fixes: 5915699153d7 ("hash: fix scaling by reducing contention") Signed-off-by: Stephen Hemminger Cc: honnappa.nagarahalli@arm.com Cc: pablo.de.lara.guarch@intel.com --- doc/guides/prog_guide/hash_lib.rst | 1 + lib/librte_hash/rte_cuckoo_hash.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/doc/guides/prog_guide/hash_lib.rst b/doc/guides/prog_guide/hash_lib.rst index d06c7de2ead1..29b41a425a43 100644 --- a/doc/guides/prog_guide/hash_lib.rst +++ b/doc/guides/prog_guide/hash_lib.rst @@ -85,6 +85,7 @@ For concurrent writes, and concurrent reads and writes the following flag values * If the multi-writer flag (RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD) is set, multiple threads writing to the table is allowed. Key add, delete, and table reset are protected from other writer threads. With only this flag set, readers are not protected from ongoing writes. + The writer threads must be EAL threads, it is not safe to write to a multi-writer hash table from an interrupt, control or other threads. * If the read/write concurrency (RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY) is set, multithread read/write operation is safe (i.e., application does not need to stop the readers from accessing the hash table until writers finish their updates. Readers and writers can operate on the table concurrently). diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c index 90cb99b0eef8..79c94107a582 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -979,6 +979,9 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, /* Did not find a match, so get a new slot for storing the new key */ if (h->use_local_cache) { lcore_id = rte_lcore_id(); + if (lcore_id == LCORE_ID_ANY) + return -EINVAL; + cached_free_slots = &h->local_free_slots[lcore_id]; /* Try to get a free slot from the local cache */ if (cached_free_slots->len == 0) { @@ -1382,6 +1385,10 @@ remove_entry(const struct rte_hash *h, struct rte_hash_bucket *bkt, unsigned i) if (h->use_local_cache) { lcore_id = rte_lcore_id(); + ERR_IF_TRUE((lcore_id == LCORE_ID_ANY), + "%s: attempt to remove entry from non EAL thread\n", + __func__); + cached_free_slots = &h->local_free_slots[lcore_id]; /* Cache full, need to free it. */ if (cached_free_slots->len == LCORE_CACHE_SIZE) { @@ -1637,6 +1644,8 @@ rte_hash_free_key_with_position(const struct rte_hash *h, if (h->use_local_cache) { lcore_id = rte_lcore_id(); + RETURN_IF_TRUE((lcore_id == LCORE_ID_ANY), -EINVAL); + cached_free_slots = &h->local_free_slots[lcore_id]; /* Cache full, need to free it. */ if (cached_free_slots->len == LCORE_CACHE_SIZE) { -- 2.26.2