From patchwork Thu Apr 22 15:54:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaetan Rivet X-Patchwork-Id: 1469280 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=u256.net header.i=@u256.net header.a=rsa-sha256 header.s=fm1 header.b=iyHlTcDf; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=UxJJlK3i; dkim-atps=neutral Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FR2770ThGz9sW5 for ; Fri, 23 Apr 2021 01:54:58 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id DBF06405EA; Thu, 22 Apr 2021 15:54:53 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gbdoTOr1OYgv; Thu, 22 Apr 2021 15:54:51 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTP id 4C2D7403B9; Thu, 22 Apr 2021 15:54:50 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C248FC001B; Thu, 22 Apr 2021 15:54:48 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6E97DC001F for ; Thu, 22 Apr 2021 15:54:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 30152608E5 for ; Thu, 22 Apr 2021 15:54:44 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=u256.net header.b="iyHlTcDf"; dkim=pass (2048-bit key) header.d=messagingengine.com header.b="UxJJlK3i" Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id d8CX3cdmXJRf for ; Thu, 22 Apr 2021 15:54:40 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by smtp3.osuosl.org (Postfix) with ESMTPS id 213B36068C for ; Thu, 22 Apr 2021 15:54:40 +0000 (UTC) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 721AE160C; Thu, 22 Apr 2021 11:54:39 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 22 Apr 2021 11:54:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u256.net; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=yQH7JP6AybdTn RonVs39ILJOOXSxqsuufmeRIjlKvc4=; b=iyHlTcDfux9qiFPKVOS4n+gdTmb54 HSxUolmzkSUPx+wbbJx6whxPApKNEXq+BDk7vyzGeSdZr0tSAYWHQW1QIRACTuvF 4DfZJvPK6w5QuG1+ZFCRFUa/dapGXbxYfDdffPXvZv3gFhBarnOqyP3PgOEiCjmq ri6hx+ubZ0G83aAsJrqnFmAkfeWjJg8GGiSjJWhdPVEWj5bwXxfAeIumbytQ2V76 92c5ibCBP6jXPWawgI8BuYZAkVOa4gvhULMMABEN/7AVctBNWCvHtD8ysj+dUjmd Esbmhwfwy4hUqj+yQ2d6wf7tAeVt0VXzjvI0ZCRKLmGdIM3GSzPyHXMSQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=yQH7JP6AybdTnRonVs39ILJOOXSxqsuufmeRIjlKvc4=; b=UxJJlK3i tmjUVq8aIm4HcbvvFIqakrOQRI1lQUACUa9qBx8iFyRrA1xr2rpIGlVrFlS5TPE2 tZom6FdJcMOk0ab7XaWWJVkHbXihYQwxb0/CU/o5LUvFTYv//cpbh1ZrjgNz9ptG Fj3GbB8JiKqk5tZyjXCNrEbxBTu9LGSojG9Df3gbakaJpkLMloOOyUWadqxJkNhA SpiHQmKLUQi0CEWp67UrxiaJJ6zuqHnGAaIu1Ziy8o4F1UlYfiaVQ4SLnadj34nO agDsddC/KFJeU5SqqZEfxg3MuY74LrTjVJv13PhMpwWmMpUtcrByeHTTjELAKxKy hsmwawwLUEb/Ig== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvddutddgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepifgrvghtrghnucftihhvvghtuceoghhrihhvvgesuhdvheei rdhnvghtqeenucggtffrrghtthgvrhhnpeduheekveehfedtueejjeeigeehvdfggefhte dugedutdefhfekhedugeetveeuhfenucffohhmrghinhepshhhsgdrtghinecukfhppeek iedrvdehgedrvdegfedrudegieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehgrhhivhgvsehuvdehiedrnhgvth X-ME-Proxy: Received: from inocybe.home (lfbn-poi-1-930-146.w86-254.abo.wanadoo.fr [86.254.243.146]) by mail.messagingengine.com (Postfix) with ESMTPA id 04DED240066; Thu, 22 Apr 2021 11:54:37 -0400 (EDT) From: Gaetan Rivet To: ovs-dev@openvswitch.org Date: Thu, 22 Apr 2021 17:54:26 +0200 Message-Id: <146a494ac326cb9175bf608398c9f18e35b9db3c.1619106089.git.grive@u256.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Cc: i.maximets@ovn.org Subject: [ovs-dev] [RFC PATCH 1/8] configure: add --enable-asan option X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Add a configure option to enable ASAN in a simple way. Adding an AC variable to allow checking for support in the testsuite. Signed-off-by: Gaetan Rivet --- .ci/linux-build.sh | 4 ++-- NEWS | 1 + acinclude.m4 | 16 ++++++++++++++++ configure.ac | 1 + tests/atlocal.in | 1 + 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.ci/linux-build.sh b/.ci/linux-build.sh index 977449350..3c58637b4 100755 --- a/.ci/linux-build.sh +++ b/.ci/linux-build.sh @@ -229,10 +229,10 @@ fi if [ "$ASAN" ]; then # This will override default option configured in tests/atlocal.in. export ASAN_OPTIONS='detect_leaks=1' + EXTRA_OPTS="$EXTRA_OPTS --enable-asan" # -O2 generates few false-positive memory leak reports in test-ovsdb # application, so lowering optimizations to -O1 here. - CLFAGS_ASAN="-O1 -fno-omit-frame-pointer -fno-common -fsanitize=address" - CFLAGS_FOR_OVS="${CFLAGS_FOR_OVS} ${CLFAGS_ASAN}" + CFLAGS_FOR_OVS="${CFLAGS_FOR_OVS} -O1" fi save_OPTS="${OPTS} $*" diff --git a/NEWS b/NEWS index 95cf922aa..57e1f041b 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,7 @@ Post-v2.15.0 * New option '--no-record-hostname' to disable hostname configuration in ovsdb on startup. * New command 'record-hostname-if-not-set' to update hostname in ovsdb. + - New --enable-asan configure option enables AddressSanitizer. v2.15.0 - 15 Feb 2021 diff --git a/acinclude.m4 b/acinclude.m4 index 15a54d636..615e7f962 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -58,6 +58,22 @@ AC_DEFUN([OVS_ENABLE_WERROR], fi AC_SUBST([SPARSE_WERROR])]) +dnl OVS_ENABLE_ASAN +AC_DEFUN([OVS_ENABLE_ASAN], + [AC_ARG_ENABLE( + [asan], + [AC_HELP_STRING([--enable-asan], + [Enable the Address Sanitizer])], + [ASAN_ENABLED=yes], [ASAN_ENABLED=no]) + AC_SUBST([ASAN_ENABLED]) + AC_CONFIG_COMMANDS_PRE([ + if test "$ASAN_ENABLED" = "yes"; then + OVS_CFLAGS="$OVS_CFLAGS -fno-omit-frame-pointer" + OVS_CFLAGS="$OVS_CFLAGS -fno-common -fsanitize=address" + fi + ]) + ]) + dnl OVS_CHECK_LINUX dnl dnl Configure linux kernel source tree diff --git a/configure.ac b/configure.ac index c077034d4..eec5a9d1b 100644 --- a/configure.ac +++ b/configure.ac @@ -182,6 +182,7 @@ OVS_CONDITIONAL_CC_OPTION([-Wno-unused-parameter], [HAVE_WNO_UNUSED_PARAMETER]) OVS_CONDITIONAL_CC_OPTION([-mavx512f], [HAVE_AVX512F]) OVS_CHECK_CC_OPTION([-mavx512f], [CFLAGS="$CFLAGS -DHAVE_AVX512F"]) OVS_ENABLE_WERROR +OVS_ENABLE_ASAN OVS_ENABLE_SPARSE OVS_CTAGS_IDENTIFIERS OVS_CHECK_DPCLS_AUTOVALIDATOR diff --git a/tests/atlocal.in b/tests/atlocal.in index cfca7e192..f61e752bf 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -220,6 +220,7 @@ export OVS_SYSLOG_METHOD OVS_CTL_TIMEOUT=30 export OVS_CTL_TIMEOUT +ASAN_ENABLED='@ASAN_ENABLED@' # Add some default flags to make the tests run better under Address # Sanitizer, if it was used for the build. # From patchwork Thu Apr 22 15:54:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaetan Rivet X-Patchwork-Id: 1469276 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=u256.net header.i=@u256.net header.a=rsa-sha256 header.s=fm1 header.b=ooC2CKT7; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=QRy0VuYN; dkim-atps=neutral Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FR2700Zybz9sWH for ; Fri, 23 Apr 2021 01:54:51 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 762DB403D1; Thu, 22 Apr 2021 15:54:48 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GC2OOkpoTcHz; Thu, 22 Apr 2021 15:54:47 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTP id 33FEB403BA; Thu, 22 Apr 2021 15:54:46 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A0CB5C0023; Thu, 22 Apr 2021 15:54:44 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3DD75C000B for ; Thu, 22 Apr 2021 15:54:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 2C1DC83C06 for ; Thu, 22 Apr 2021 15:54:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=u256.net header.b="ooC2CKT7"; dkim=pass (2048-bit key) header.d=messagingengine.com header.b="QRy0VuYN" Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GOUmZXQuOnNt for ; Thu, 22 Apr 2021 15:54:42 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by smtp1.osuosl.org (Postfix) with ESMTPS id 35EFA83C27 for ; Thu, 22 Apr 2021 15:54:42 +0000 (UTC) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id C71261430; Thu, 22 Apr 2021 11:54:39 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 22 Apr 2021 11:54:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u256.net; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=3J0EyAW/iM2oC D7koXFRGaBLayB8VAFSemX2uEV2u2k=; b=ooC2CKT7TjfDU7h2Jda7O7UGLs97m 8BNATT6fUD1KE88QQWESAKqOONsKv5GqrXYhlPmdYGBh31EQoLZudnzOrdqil6g1 gQY/X3ccuS8KDQ4vUAW3rU80ZXbPNTFGMFypxrdMwAGnCFuWB9R80YsqcSVW+t/c zirTWUt8/S0Vk3UGkx1YTLw/cKi4nsl4leL4FLLyrd0bS913HBEKe3RWKM4S20C/ 7wu4M+YAi2mWzvwqULwRhjzNboCRELN/oLPghEgDFeOppJe0GjJb6eLUBVrF8/+U yBmO7zL84hmHFPTW7OKryw3eS6nS0xmwqAxQbKW5M2eKWexB8jzKV0D1A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=3J0EyAW/iM2oCD7koXFRGaBLayB8VAFSemX2uEV2u2k=; b=QRy0VuYN sefSDZoSNQV9927iIMQj9wiabKo3xkA52U2C2Xdn+ap5mYi9CZsmNfqeun/DhE5h qdJjeUa2h4P0ga6pr6evAc3NEuk96r/ZRXsUqXsl3+1qksTBv5TpwtmR4Y2469wG RGDmUIPE9BuhBJXmbh95kLPGOHePlbWKoF899niOvcXslOgYuKN+b7J1ZVsmhYjn bJuRmlnQB8/iDpANUo2odysW6sWOXVUysHs434maoXFUavRlB0cqcQpqmqWCiO8x 7np0JFiPS9t7FkpmYBpv5hXl+fqjO9ie7Gr3ZJOfTkdrjG6GNm4bW1ESbjvgCYaD B9+6WdtVkfZwNA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvddutddgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepifgrvghtrghnucftihhvvghtuceoghhrihhvvgesuhdvheei rdhnvghtqeenucggtffrrghtthgvrhhnpeduhfefieekieeiudetgfehkeeludektdekje ehudehffetieduheeigfekvdelfeenucffohhmrghinheprghprggthhgvrdhorhhgnecu kfhppeekiedrvdehgedrvdegfedrudegieenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehgrhhivhgvsehuvdehiedrnhgvth X-ME-Proxy: Received: from inocybe.home (lfbn-poi-1-930-146.w86-254.abo.wanadoo.fr [86.254.243.146]) by mail.messagingengine.com (Postfix) with ESMTPA id C2D2C24006B; Thu, 22 Apr 2021 11:54:38 -0400 (EDT) From: Gaetan Rivet To: ovs-dev@openvswitch.org Date: Thu, 22 Apr 2021 17:54:27 +0200 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Cc: i.maximets@ovn.org Subject: [ovs-dev] [RFC PATCH 2/8] tests: Add ovs-barrier unit test X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" No unit test exist currently for the ovs-barrier type. It is however crucial as a building block and should be verified to work as expected. Create a simple test verifying the basic function of ovs-barrier. Integrate the test as part of the test suite. Signed-off-by: Gaetan Rivet --- tests/automake.mk | 1 + tests/library.at | 5 + tests/test-barrier.c | 264 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 270 insertions(+) create mode 100644 tests/test-barrier.c diff --git a/tests/automake.mk b/tests/automake.mk index 1a528aa39..a32abd41c 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -448,6 +448,7 @@ tests_ovstest_SOURCES = \ tests/ovstest.h \ tests/test-aes128.c \ tests/test-atomic.c \ + tests/test-barrier.c \ tests/test-bundle.c \ tests/test-byte-order.c \ tests/test-classifier.c \ diff --git a/tests/library.at b/tests/library.at index 1702b7556..e572c22e3 100644 --- a/tests/library.at +++ b/tests/library.at @@ -246,6 +246,11 @@ AT_SETUP([ofpbuf module]) AT_CHECK([ovstest test-ofpbuf], [0], []) AT_CLEANUP +AT_SETUP([barrier module]) +AT_KEYWORDS([barrier]) +AT_CHECK([ovstest test-barrier], [0], []) +AT_CLEANUP + AT_SETUP([rcu]) AT_CHECK([ovstest test-rcu-quiesce], [0], []) AT_CLEANUP diff --git a/tests/test-barrier.c b/tests/test-barrier.c new file mode 100644 index 000000000..3bc5291cc --- /dev/null +++ b/tests/test-barrier.c @@ -0,0 +1,264 @@ +/* + * Copyright (c) 2021 NVIDIA Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include "ovs-thread.h" +#include "ovs-rcu.h" +#include "ovstest.h" +#include "random.h" +#include "util.h" + +#define DEFAULT_N_THREADS 4 +#define NB_STEPS 4 + +static bool verbose; +static struct ovs_barrier barrier; + +struct blocker_aux { + unsigned int tid; + bool leader; + int step; +}; + +static void * +basic_blocker_main(void *aux_) +{ + struct blocker_aux *aux = aux_; + size_t i; + + aux->step = 0; + for (i = 0; i < NB_STEPS; i++) { + ovs_barrier_block(&barrier); + aux->step++; + ovs_barrier_block(&barrier); + } + + return NULL; +} + +static void +basic_block_check(struct blocker_aux *aux, size_t n, int expected) +{ + size_t i; + + for (i = 0; i < n; i++) { + if (verbose) { + printf("aux[%" PRIuSIZE "]=%d == %d", i, aux[i].step, expected); + if (aux[i].step != expected) { + printf(" <--- X"); + } + printf("\n"); + } else { + ovs_assert(aux[i].step == expected); + } + } + ovs_barrier_block(&barrier); + ovs_barrier_block(&barrier); +} + +/* + * Basic barrier test. + * + * N writers and 1 reader participate in the test. + * Each thread goes through M steps (=NB_STEPS). + * The main thread participates as the reader. + * + * A Step is divided in three parts: + * 1. before + * (barrier) + * 2. during + * (barrier) + * 3. after + * + * Each writer updates a thread-local variable with the + * current step number within part 2 and waits. + * + * The reader checks all variables during part 3, expecting + * all variables to be equal. If any variable differs, it means + * its thread was not properly blocked by the barrier. + */ +static void +test_barrier_basic(size_t n_threads) +{ + struct blocker_aux *aux; + pthread_t *threads; + size_t i; + + ovs_barrier_init(&barrier, n_threads + 1); + + aux = xcalloc(n_threads, sizeof *aux); + threads = xmalloc(n_threads * sizeof *threads); + for (i = 0; i < n_threads; i++) { + threads[i] = ovs_thread_create("ovs-barrier", + basic_blocker_main, &aux[i]); + } + + for (i = 0; i < NB_STEPS; i++) { + basic_block_check(aux, n_threads, i); + } + ovs_barrier_destroy(&barrier); + + for (i = 0; i < n_threads; i++) { + xpthread_join(threads[i], NULL); + } + + free(threads); + free(aux); +} + +static unsigned int *shared_mem; + +static void * +lead_blocker_main(void *aux_) +{ + struct blocker_aux *aux = aux_; + size_t i; + + aux->step = 0; + for (i = 0; i < NB_STEPS; i++) { + if (aux->leader) { + shared_mem = xmalloc(sizeof *shared_mem); + if (verbose) { + printf("*T1: allocated shmem\n"); + } + } + xnanosleep(random_range(100) * 1000); + + ovs_barrier_block(&barrier); + + if (verbose) { + printf("%cT%u: ENTER, writing\n", + (aux->leader ? '*' : ' '), aux->tid); + } + + shared_mem[0] = 42; + + ovs_barrier_block(&barrier); + + if (verbose) { + printf("%cT%u: EXIT\n", + (aux->leader ? '*' : ' '), aux->tid); + } + + if (aux->leader) { + free(shared_mem); + if (verbose) { + printf("*T1: freed shmem\n"); + } + } + xnanosleep(random_range(100) * 1000); + } + + return NULL; +} + +/* + * Leader barrier test. + * + * N threads participates, one of which is marked as + * the leader (thread 0). The main thread does not + * participate. + * + * The test is divided in M steps (=NB_STEPS). + * A Step is divided in three parts: + * 1. before + * (barrier) + * 2. during + * (barrier) + * 3. after + * + * Part 1, the leader allocates a block of shared memory. + * Part 2, all threads write to the shared memory. + * Part 3: the leader frees the shared memory. + * + * If any thread is improperly blocked by the barrier, + * the shared memory accesses will trigger a segfault + * or a use-after-free if ASAN is enabled. + */ +static void +test_barrier_lead(size_t n_threads) +{ + struct blocker_aux *aux; + pthread_t *threads; + size_t i; + + ovs_barrier_init(&barrier, n_threads); + + aux = xcalloc(n_threads, sizeof *aux); + threads = xmalloc(n_threads * sizeof *threads); + + aux[0].leader = true; + + for (i = 0; i < n_threads; i++) { + aux[i].tid = i + 1; + threads[i] = ovs_thread_create("ovs-barrier", + lead_blocker_main, &aux[i]); + } + + for (i = 0; i < n_threads; i++) { + xpthread_join(threads[i], NULL); + } + + /* If the main thread does not participate in the barrier, + * it must wait for all threads to join before destroying it. + */ + ovs_barrier_destroy(&barrier); + + free(threads); + free(aux); +} + +static void +usage(char *test_name) +{ + fprintf(stderr, "Usage: %s [n_threads=%d] [-v]\n", + test_name, DEFAULT_N_THREADS); +} + +static void +test_barrier(int argc, char *argv[]) +{ + size_t n_threads = DEFAULT_N_THREADS; + char **args = argv + optind - 1; + + set_program_name(argv[0]); + + argc -= optind; + if (argc > 2) { + usage(args[0]); + return; + } + + while (argc-- > 0) { + args++; + if (!strcmp(args[0], "-v")) { + verbose = true; + } else { + n_threads = strtol(args[0], NULL, 10); + if (n_threads > 20) { + n_threads = 20; + } + } + } + + test_barrier_basic(n_threads); + test_barrier_lead(n_threads); +} + +OVSTEST_REGISTER("test-barrier", test_barrier); From patchwork Thu Apr 22 15:54:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaetan Rivet X-Patchwork-Id: 1469278 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=u256.net header.i=@u256.net header.a=rsa-sha256 header.s=fm1 header.b=NdpfOcA7; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=ZI/jzDGG; dkim-atps=neutral Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FR2736wr3z9sW5 for ; Fri, 23 Apr 2021 01:54:55 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 94A0C4059D; Thu, 22 Apr 2021 15:54:51 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jjpIlU-C6HWr; Thu, 22 Apr 2021 15:54:50 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTP id C76DB4057B; Thu, 22 Apr 2021 15:54:48 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C885BC0019; Thu, 22 Apr 2021 15:54:47 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 32BB8C000E for ; Thu, 22 Apr 2021 15:54:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id A0EFB40112 for ; Thu, 22 Apr 2021 15:54:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ck2yeE2js8XG for ; Thu, 22 Apr 2021 15:54:42 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by smtp2.osuosl.org (Postfix) with ESMTPS id 35F6E40206 for ; Thu, 22 Apr 2021 15:54:42 +0000 (UTC) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id AE14E1607; Thu, 22 Apr 2021 11:54:40 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 22 Apr 2021 11:54:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u256.net; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=hogO2iwtKCCcz 1FTta3UdI+swRfqjbkPfz6FozEpBUU=; b=NdpfOcA7rnO9+HlgAdFOTNUra8t3n Q5yG7KGj1z4hwRcsxVxuAjqtY5SEmc09xpV7XKJDADnmQWMQH5lpvYes48eCfRi1 yQByil7NhW8F2bOvOoExI3l+WlQhYNtisHu0XaNcqz6UzmBJr3OFc0pMBratIE1D jlACwKjmGhO/KPN0cYBJLs3nir5Tv25lSO78ZKMA95wNnTfF2/ibAy1l3PR42p3R 6OaMpZ69eODAxGloTQ3MfIWE72Us3BjdyTefJoOTAbE08xowtE9CXfJNs3n5NOW1 o8ueTxTboEgHdHQiwK/mvksN6jHQ6MUXnbHo45Xg4UGmpv645QCfme3YA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=hogO2iwtKCCcz1FTta3UdI+swRfqjbkPfz6FozEpBUU=; b=ZI/jzDGG pkoNkk3NvbQTfwzQnGz+FAst1pdQ8V+qlDMXB0qKLK7OCCoTNy6rPMfeYb/DSw6p Y893QKmOZBo74s7UdxKjiQvMp6jtez88E32lSgM5MAFwx/fyXHUU9aLXuGL62Ily 7p8IoF/kZx2WXu0On9wvOIkTZPujiN6b0NzAPVB/o9BVxMDltpnmRE4aqhTdYWac 4NhE8/p2tKGYNrSkZZKSvI59Gu7Z18fA0eDClGDIpgtpXJwYQmPNVePVUeF4+hUZ Yfj3v8j3ubOxc4b/nJOBwLu7w+GL6En26eSZU/FUWG2v9fpmwhXBdvCcHISbAJHI Cf+Ocrr6IEZceQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvddutddgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepifgrvghtrghnucftihhvvghtuceoghhrihhvvgesuhdvheei rdhnvghtqeenucggtffrrghtthgvrhhnpeehgfevffekteehteefieefvdehleefjeefhe evudetjefhkeeutdekieeuvdetheenucfkphepkeeirddvheegrddvgeefrddugeeinecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhrihhvvg esuhdvheeirdhnvght X-ME-Proxy: Received: from inocybe.home (lfbn-poi-1-930-146.w86-254.abo.wanadoo.fr [86.254.243.146]) by mail.messagingengine.com (Postfix) with ESMTPA id 8188D24005B; Thu, 22 Apr 2021 11:54:39 -0400 (EDT) From: Gaetan Rivet To: ovs-dev@openvswitch.org Date: Thu, 22 Apr 2021 17:54:28 +0200 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Cc: i.maximets@ovn.org Subject: [ovs-dev] [RFC PATCH 3/8] tests: Add RCU postpone test X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Add a simple postponing test verifying RCU callbacks have executed and RCU exits in order. Add as part of library unit-tests. Change-Id: I2ae4da750a1e4c2609a3064ea4d87bc3c5e96c8f Signed-off-by: Gaetan Rivet --- tests/library.at | 8 ++++++- tests/test-rcu.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/tests/library.at b/tests/library.at index e572c22e3..6e8a154e5 100644 --- a/tests/library.at +++ b/tests/library.at @@ -251,10 +251,16 @@ AT_KEYWORDS([barrier]) AT_CHECK([ovstest test-barrier], [0], []) AT_CLEANUP -AT_SETUP([rcu]) +AT_SETUP([rcu quiescing]) +AT_KEYWORDS([rcu]) AT_CHECK([ovstest test-rcu-quiesce], [0], []) AT_CLEANUP +AT_SETUP([rcu postponing]) +AT_KEYWORDS([rcu]) +AT_CHECK([ovstest test-rcu], [0], []) +AT_CLEANUP + AT_SETUP([stopwatch module]) AT_CHECK([ovstest test-stopwatch], [0], [...... ], [ignore]) diff --git a/tests/test-rcu.c b/tests/test-rcu.c index 965f3c49f..88db04a45 100644 --- a/tests/test-rcu.c +++ b/tests/test-rcu.c @@ -49,3 +49,62 @@ test_rcu_quiesce(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) } OVSTEST_REGISTER("test-rcu-quiesce", test_rcu_quiesce); + +struct rcu_user_aux { + bool done; +}; + +static void +rcu_user_deferred(struct rcu_user_aux *aux) +{ + aux->done = true; +} + +static void * +rcu_user_main(void *aux_) +{ + struct rcu_user_aux *aux = aux_; + + ovsrcu_quiesce(); + + aux->done = false; + ovsrcu_postpone(rcu_user_deferred, aux); + + ovsrcu_quiesce(); + + return NULL; +} + +#define N_THREAD 4 + +static void +test_rcu(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) +{ + struct rcu_user_aux aux[N_THREAD] = {0}; + struct rcu_user_aux main_aux = {0}; + pthread_t users[N_THREAD]; + size_t i; + + for (i = 0; i < ARRAY_SIZE(users); i++) { + users[i] = ovs_thread_create("user", rcu_user_main, &aux[i]); + } + + for (i = 0; i < ARRAY_SIZE(users); i++) { + xpthread_join(users[i], NULL); + } + + /* Register a last callback and verify that it will be properly executed + * even if the RCU lib is exited without this thread quiescing. + */ + ovsrcu_postpone(rcu_user_deferred, &main_aux); + + ovsrcu_exit(); + + ovs_assert(main_aux.done); + + for (i = 0; i < ARRAY_SIZE(users); i++) { + ovs_assert(aux[i].done); + } +} + +OVSTEST_REGISTER("test-rcu", test_rcu); From patchwork Thu Apr 22 15:54:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaetan Rivet X-Patchwork-Id: 1469275 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=u256.net header.i=@u256.net header.a=rsa-sha256 header.s=fm1 header.b=WIK4MSTA; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=HmqoTi+/; dkim-atps=neutral Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FR26v6KbSz9sW5 for ; Fri, 23 Apr 2021 01:54:47 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id BC56160B8D; Thu, 22 Apr 2021 15:54:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xuEWW3LgbAmD; Thu, 22 Apr 2021 15:54:44 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTP id C8CCB6068D; Thu, 22 Apr 2021 15:54:43 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A5EF6C0019; Thu, 22 Apr 2021 15:54:43 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 04744C000B for ; Thu, 22 Apr 2021 15:54:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id E6D434020C for ; Thu, 22 Apr 2021 15:54:42 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=u256.net header.b="WIK4MSTA"; dkim=pass (2048-bit key) header.d=messagingengine.com header.b="HmqoTi+/" Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id R0SKiDJ_ijke for ; Thu, 22 Apr 2021 15:54:41 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by smtp2.osuosl.org (Postfix) with ESMTPS id E0E4340112 for ; Thu, 22 Apr 2021 15:54:41 +0000 (UTC) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 392811558; Thu, 22 Apr 2021 11:54:41 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 22 Apr 2021 11:54:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u256.net; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=4ya0fOHV8i/13 olTgTVfox7loI75eJhqhxCM+suIZyk=; b=WIK4MSTATuHEq2ACh2FcT5svx6vKo D8BPItCbeoKKKUKqBLI8//oEmmnGVovQfix86St4kjj04qsYFh1wAAtIHfOCvJLc 2UAtWH1cULvhxOIXFoMKIilBJprbxtVuxJ2YiYEsL+yfdq/TZgjQxSHWzL86M1p1 /4YwVQSNLnC1AoT0zsNtQOZ86mBYMjEgJxtshV4l66r+oj39amRST5IIrPEGcGOl Y4vhx/ZZsy//lqhAzu8hriHlZ1uTWXSQUbwFlyLBhbidNlgdeU2CLPNMoXfzyI1x halunl2hco43ZLdRHGosv0ru9vW2xOKh7S65upV6J7g13lOcccSOiPoYg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=4ya0fOHV8i/13olTgTVfox7loI75eJhqhxCM+suIZyk=; b=HmqoTi+/ uMdzuJU70SZa6u7QS1GMfWaknHdtqpYZS+efKJ3qAcg3+HeGuWrKF44nmagErIvJ WIQYS25XAIFj8YoxjlExRaBrkIOD5TDM4tSZCwav5BapV1NN32/Z3LYl7T1qMOWp RTY/WnHqX5Dupi7CY+mOiLbPTRCXdRdf1A9S4u8CcLgLuclOyG+38bbuDsGasnSS ONXLgjU4dFDIEpV0kTexJo45DYr8X82kWg1Qzlxm4tvEM66V4DJDp0ykj2uZKtb9 E2FfcxPdmrBhr6mOhv5zkHioVPFi0XGKm7jVO21Jo06D8HpZnnfsJHbPtCOzPd7l a7OkZwd2CXcadQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvddutddgleefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepifgrvghtrghnucftihhvvghtuceoghhrihhvvgesuhdvheei rdhnvghtqeenucggtffrrghtthgvrhhnpeduhfefieekieeiudetgfehkeeludektdekje ehudehffetieduheeigfekvdelfeenucffohhmrghinheprghprggthhgvrdhorhhgnecu kfhppeekiedrvdehgedrvdegfedrudegieenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehgrhhivhgvsehuvdehiedrnhgvth X-ME-Proxy: Received: from inocybe.home (lfbn-poi-1-930-146.w86-254.abo.wanadoo.fr [86.254.243.146]) by mail.messagingengine.com (Postfix) with ESMTPA id 3FCA9240066; Thu, 22 Apr 2021 11:54:40 -0400 (EDT) From: Gaetan Rivet To: ovs-dev@openvswitch.org Date: Thu, 22 Apr 2021 17:54:29 +0200 Message-Id: <1cb601c1bfb227cf38917020023c28d2d941a762.1619106089.git.grive@u256.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Cc: i.maximets@ovn.org Subject: [ovs-dev] [RFC PATCH 4/8] tests: Add ASAN use-after-free validation with RCU X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" When using the RCU mechanism and deferring memory reclamation, potential use-after-free due to incorrect use of RCU can be hidden. Add a test triggering a UAF event. When the test suite is built with AddressSanitizer support, verify that the event triggers and the tool is usable with RCU. Signed-off-by: Gaetan Rivet --- tests/automake.mk | 1 + tests/library.at | 33 +++++++++++++++ tests/test-rcu-uaf.c | 98 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 tests/test-rcu-uaf.c diff --git a/tests/automake.mk b/tests/automake.mk index a32abd41c..4420a3f7f 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -472,6 +472,7 @@ tests_ovstest_SOURCES = \ tests/test-packets.c \ tests/test-random.c \ tests/test-rcu.c \ + tests/test-rcu-uaf.c \ tests/test-reconnect.c \ tests/test-rstp.c \ tests/test-sflow.c \ diff --git a/tests/library.at b/tests/library.at index 6e8a154e5..4a549f77e 100644 --- a/tests/library.at +++ b/tests/library.at @@ -261,6 +261,39 @@ AT_KEYWORDS([rcu]) AT_CHECK([ovstest test-rcu], [0], []) AT_CLEANUP +AT_SETUP([rcu quiesce use-after-free detection]) +AT_SKIP_IF([test "$IS_WIN32" = "yes"]) +AT_SKIP_IF([test "$ASAN_ENABLED" = "no"]) +# SIGABRT + 128 +exit_status=134 +AT_KEYWORDS([rcu asan]) +AT_CHECK([ovstest test-rcu-uaf quiesce], [$exit_status], [ignore], [ignore]) +# ASAN report is expected on success. +rm asan.* +AT_CLEANUP + +AT_SETUP([rcu try-quiesce use-after-free detection]) +AT_SKIP_IF([test "$IS_WIN32" = "yes"]) +AT_SKIP_IF([test "$ASAN_ENABLED" = "no"]) +# SIGABRT + 128 +exit_status=134 +AT_KEYWORDS([rcu asan]) +AT_CHECK([ovstest test-rcu-uaf try-quiesce], [$exit_status], [ignore], [ignore]) +# ASAN report is expected on success. +rm asan.* +AT_CLEANUP + +AT_SETUP([rcu quiesce-start-end use-after-free detection]) +AT_SKIP_IF([test "$IS_WIN32" = "yes"]) +AT_SKIP_IF([test "$ASAN_ENABLED" = "no"]) +AT_KEYWORDS([rcu asan]) +# SIGABRT + 128 +exit_status=134 +AT_CHECK([ovstest test-rcu-uaf quiesce-start-end], [$exit_status], [ignore], [ignore]) +# ASAN report is expected on success. +rm asan.* +AT_CLEANUP + AT_SETUP([stopwatch module]) AT_CHECK([ovstest test-stopwatch], [0], [...... ], [ignore]) diff --git a/tests/test-rcu-uaf.c b/tests/test-rcu-uaf.c new file mode 100644 index 000000000..f97738795 --- /dev/null +++ b/tests/test-rcu-uaf.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2021 NVIDIA Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include "ovs-thread.h" +#include "ovs-rcu.h" +#include "ovstest.h" +#include "util.h" + +enum ovsrcu_uaf_type { + OVSRCU_UAF_QUIESCE, + OVSRCU_UAF_TRY_QUIESCE, + OVSRCU_UAF_QUIESCE_START_END, +}; + +static void * +rcu_uaf_main(void *aux) +{ + enum ovsrcu_uaf_type *type = aux; + char *xx = xmalloc(2); + + xx[0] = 'a'; + ovsrcu_postpone(free, xx); + switch (*type) { + case OVSRCU_UAF_QUIESCE: + ovsrcu_quiesce(); + break; + case OVSRCU_UAF_TRY_QUIESCE: + while (ovsrcu_try_quiesce()) { + ; + } + break; + case OVSRCU_UAF_QUIESCE_START_END: + ovsrcu_quiesce_start(); + ovsrcu_quiesce_end(); + break; + default: + OVS_NOT_REACHED(); + } + xx[1] = 'b'; + + return NULL; +} + +static void +usage(char *test_name) +{ + fprintf(stderr, "Usage: %s \n", + test_name); +} + +static void +test_rcu_uaf(int argc, char *argv[]) +{ + char **args = argv + optind - 1; + enum ovsrcu_uaf_type type; + pthread_t quiescer; + + if (argc - optind != 1) { + usage(args[0]); + return; + } + + set_program_name(argv[0]); + + if (!strcmp(args[1], "quiesce")) { + type = OVSRCU_UAF_QUIESCE; + } else if (!strcmp(args[1], "try-quiesce")) { + type = OVSRCU_UAF_TRY_QUIESCE; + } else if (!strcmp(args[1], "quiesce-start-end")) { + type = OVSRCU_UAF_QUIESCE_START_END; + } else { + usage(args[0]); + return; + } + + /* Need to create a separate thread, to support try-quiesce. */ + quiescer = ovs_thread_create("rcu-uaf", rcu_uaf_main, &type); + xpthread_join(quiescer, NULL); +} + +OVSTEST_REGISTER("test-rcu-uaf", test_rcu_uaf); From patchwork Thu Apr 22 15:54:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaetan Rivet X-Patchwork-Id: 1469277 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=u256.net header.i=@u256.net header.a=rsa-sha256 header.s=fm1 header.b=ECcnpuU8; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=t1RjslJo; dkim-atps=neutral Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FR2705cxPz9sWK for ; Fri, 23 Apr 2021 01:54:52 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id B4F7160D67; Thu, 22 Apr 2021 15:54:49 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MtgyX7VUdVuX; Thu, 22 Apr 2021 15:54:48 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTP id 58F8560865; Thu, 22 Apr 2021 15:54:47 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C8ABCC001B; Thu, 22 Apr 2021 15:54:46 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 99EE7C000B for ; Thu, 22 Apr 2021 15:54:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 7C27160865 for ; Thu, 22 Apr 2021 15:54:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rF3m4XUGlVMi for ; Thu, 22 Apr 2021 15:54:42 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by smtp3.osuosl.org (Postfix) with ESMTPS id A7D816068D for ; Thu, 22 Apr 2021 15:54:42 +0000 (UTC) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id E5CFD1620; Thu, 22 Apr 2021 11:54:41 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 22 Apr 2021 11:54:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u256.net; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=lJ6+Jhax9UCDn izTO8oOunFeh88ZoBz10j40A7uY5iM=; b=ECcnpuU8a4Gjot6aCLCcVUNvA02x2 eA8rKJ/7J/JGF2lRJBMK91kv5lhoSO65VsG5Kj+7JGQ63OiGNa+jgqpdavqZINy8 bphp/EiwGQ8vSo5M7JVzn//NMjEgYbuysJTrNOwgjE6ra7bVTHlb/RtLqYLr1bm+ JyJ4orJKVPImOtS8NSHDHr6tOKLABqw6MNnPrILOsa5qkIJceOlTmPBlghIoxigh pBtbZdU91QL6pqdrV2olaCqlMrvjdsiZ2TkVq7N6sYmBJhkSZhGMbdlWewOXemsR gKYG/voAaIgZy8RP6PYQGYg83HGRbODObrJbU/8LXpx1Pz0ISfZHNv53Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=lJ6+Jhax9UCDnizTO8oOunFeh88ZoBz10j40A7uY5iM=; b=t1RjslJo vk6G48yL6v1t42IV30R+6dpbPORvfFPutMgyEAZA8MYQ0KltK70S4av8+fXOu+d5 DOIfG3QOqZJ/FnOV0t9ejMX4wKBALAvoTRSPt/jkesiyH71n4UfimwS2cqABO2z5 kKBds47BlASPWaC4h38jh6Lbr29W8o/03wC7nX9ji55nT5/xz39El9U3wun3sHid MsCY9que4GXBxrA7Q2ep/ERIN5NZoz+ufq/Otj82DovypWiPALmpIWTT3bLneMeP tVH9wbwI0XTBF5oEcBmr+etFb9pjaVialM/wauZGmLoNGevwX+ljg4mi5kYoiJgL wCr/N0uQ8gbkJg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvddutddgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepifgrvghtrghnucftihhvvghtuceoghhrihhvvgesuhdvheei rdhnvghtqeenucggtffrrghtthgvrhhnpeehgfevffekteehteefieefvdehleefjeefhe evudetjefhkeeutdekieeuvdetheenucfkphepkeeirddvheegrddvgeefrddugeeinecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhrihhvvg esuhdvheeirdhnvght X-ME-Proxy: Received: from inocybe.home (lfbn-poi-1-930-146.w86-254.abo.wanadoo.fr [86.254.243.146]) by mail.messagingengine.com (Postfix) with ESMTPA id F219A24005C; Thu, 22 Apr 2021 11:54:40 -0400 (EDT) From: Gaetan Rivet To: ovs-dev@openvswitch.org Date: Thu, 22 Apr 2021 17:54:30 +0200 Message-Id: <936abce083f5805ed1fad2b58622a03166129a63.1619106089.git.grive@u256.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Cc: i.maximets@ovn.org Subject: [ovs-dev] [RFC PATCH 5/8] ovs-thread: Fix barrier use-after-free X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" When a thread is blocked on a barrier, there is no guarantee regarding the moment it will resume, only that it will at some point in the future. One thread can resume first then proceed to destroy the barrier while another thread has not yet awoken. When it finally happens, the second thread will attempt a seq_read() on the barrier seq, while the first thread have already destroyed it, triggering a use-after-free. Introduce an additional indirection layer within the barrier. A internal barrier implementation holds all the necessary elements for a thread to safely block and destroy. Whenever a barrier is destroyed, the internal implementation is left available to still blocking threads if necessary. A reference counter is used to track threads still using the implementation. Note that current uses of ovs-barrier are not affected: RCU and revalidators will not destroy their barrier immediately after blocking on it. Fixes: d8043da7182a ("ovs-thread: Implement OVS specific barrier.") Signed-off-by: Gaetan Rivet --- lib/ovs-thread.c | 61 +++++++++++++++++++++++++++++++++++++++--------- lib/ovs-thread.h | 6 ++--- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c index b686e4548..805cba622 100644 --- a/lib/ovs-thread.c +++ b/lib/ovs-thread.c @@ -299,21 +299,53 @@ ovs_spin_init(const struct ovs_spin *spin) } #endif +struct ovs_barrier_impl { + uint32_t size; /* Number of threads to wait. */ + atomic_count count; /* Number of threads already hit the barrier. */ + struct seq *seq; + struct ovs_refcount refcnt; +}; + +static void +ovs_barrier_impl_ref(struct ovs_barrier_impl *impl) +{ + ovs_refcount_ref(&impl->refcnt); +} + +static void +ovs_barrier_impl_unref(struct ovs_barrier_impl *impl) +{ + if (ovs_refcount_unref(&impl->refcnt) == 1) { + seq_destroy(impl->seq); + free(impl); + } +} + /* Initializes the 'barrier'. 'size' is the number of threads * expected to hit the barrier. */ void ovs_barrier_init(struct ovs_barrier *barrier, uint32_t size) { - barrier->size = size; - atomic_count_init(&barrier->count, 0); - barrier->seq = seq_create(); + struct ovs_barrier_impl *impl; + + impl = xmalloc(sizeof *impl); + impl->size = size; + atomic_count_init(&impl->count, 0); + impl->seq = seq_create(); + ovs_refcount_init(&impl->refcnt); + + ovsrcu_set(&barrier->impl, impl); } /* Destroys the 'barrier'. */ void ovs_barrier_destroy(struct ovs_barrier *barrier) { - seq_destroy(barrier->seq); + struct ovs_barrier_impl *impl; + + impl = ovsrcu_get(struct ovs_barrier_impl *, &barrier->impl); + ovsrcu_set(&barrier->impl, NULL); + ovs_barrier_impl_unref(impl); } /* Makes the calling thread block on the 'barrier' until all @@ -325,23 +357,30 @@ ovs_barrier_destroy(struct ovs_barrier *barrier) void ovs_barrier_block(struct ovs_barrier *barrier) { - uint64_t seq = seq_read(barrier->seq); + struct ovs_barrier_impl *impl; uint32_t orig; + uint64_t seq; - orig = atomic_count_inc(&barrier->count); - if (orig + 1 == barrier->size) { - atomic_count_set(&barrier->count, 0); + impl = ovsrcu_get(struct ovs_barrier_impl *, &barrier->impl); + ovs_barrier_impl_ref(impl); + + seq = seq_read(impl->seq); + orig = atomic_count_inc(&impl->count); + if (orig + 1 == impl->size) { + atomic_count_set(&impl->count, 0); /* seq_change() serves as a release barrier against the other threads, * so the zeroed count is visible to them as they continue. */ - seq_change(barrier->seq); + seq_change(impl->seq); } else { /* To prevent thread from waking up by other event, * keeps waiting for the change of 'barrier->seq'. */ - while (seq == seq_read(barrier->seq)) { - seq_wait(barrier->seq, seq); + while (seq == seq_read(impl->seq)) { + seq_wait(impl->seq, seq); poll_block(); } } + + ovs_barrier_impl_unref(impl); } DEFINE_EXTERN_PER_THREAD_DATA(ovsthread_id, OVSTHREAD_ID_UNSET); diff --git a/lib/ovs-thread.h b/lib/ovs-thread.h index 7ee98bd4e..3b444ccdc 100644 --- a/lib/ovs-thread.h +++ b/lib/ovs-thread.h @@ -21,16 +21,16 @@ #include #include #include "ovs-atomic.h" +#include "ovs-rcu.h" #include "openvswitch/thread.h" #include "util.h" struct seq; /* Poll-block()-able barrier similar to pthread_barrier_t. */ +struct ovs_barrier_impl; struct ovs_barrier { - uint32_t size; /* Number of threads to wait. */ - atomic_count count; /* Number of threads already hit the barrier. */ - struct seq *seq; + OVSRCU_TYPE(struct ovs_barrier_impl *) impl; }; /* Wrappers for pthread_mutexattr_*() that abort the process on any error. */ From patchwork Thu Apr 22 15:54:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaetan Rivet X-Patchwork-Id: 1469279 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=u256.net header.i=@u256.net header.a=rsa-sha256 header.s=fm1 header.b=g7WGheqk; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=pDz8h3j0; dkim-atps=neutral Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FR2745pkcz9sWH for ; Fri, 23 Apr 2021 01:54:56 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 4EF8A83EF7; Thu, 22 Apr 2021 15:54:54 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6g3KfCvPe6KR; Thu, 22 Apr 2021 15:54:53 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTP id D3E8483C75; Thu, 22 Apr 2021 15:54:51 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id DB348C000E; Thu, 22 Apr 2021 15:54:49 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id A1A46C0024 for ; Thu, 22 Apr 2021 15:54:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 7FDB44054E for ; Thu, 22 Apr 2021 15:54:44 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp4.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=u256.net header.b="g7WGheqk"; dkim=pass (2048-bit key) header.d=messagingengine.com header.b="pDz8h3j0" Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JxVw3UBOsJWM for ; Thu, 22 Apr 2021 15:54:43 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by smtp4.osuosl.org (Postfix) with ESMTPS id C95E640411 for ; Thu, 22 Apr 2021 15:54:43 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 203A11607; Thu, 22 Apr 2021 11:54:43 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 22 Apr 2021 11:54:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u256.net; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=ENEjZXBBD2TeN NamaGEHXFnPpKcjacPUN4bgCWy6Ytg=; b=g7WGheqkwOv/a1G19G/6o9yhFEkv0 oFu+O1w4RYIHmeu3Bfud/XQC/94YXsOLFXJH1DCbQQ+/F0e3859Yd0azppiLYEBb znNdwZ+zca+9sxiEx99m60LnUwoEpXAIgjjtOiscpuPqnft6wKUkfeg0+gerN9qR 4eq3hxtTeNYFWGxk4ACfAqCbb2arNaok3aaIxqrOtXBeYg159KfJL6ui9ibgyDpW yhsSqyyHae05MIu4TAw6+UmAfyuIICHuzk/4TMYEujkEkuS9NCXkGGyTMBPZCOZz 2Jj6kU9X/kVyh++XWtuMUYYLLPqS9HDe7bvU7ZRlFotELj2e+NaBPCzNw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=ENEjZXBBD2TeNNamaGEHXFnPpKcjacPUN4bgCWy6Ytg=; b=pDz8h3j0 JUrwZSU/U1PS3gZ0lqZgOw11P71WUIiFQ10xtwzMAA2qPei9vtZs+Fp/8Eg+84M/ oTG6Liv4GgPV9hDMfpDoL4NG84uYsoxZ1haAaFwwPT4xnSTYQ6Onz+jiMVe5cOG2 9dSWsjAmfH1q+igJjj6aSqAtx24PdvxpiJLZmj4I6ny2fCYbvFUoQE81eegQk81O fcwN3W98xUsHUvolkGwxXX1hsG0SAgpTFbniT/blwMf2XqmOanwWk1ldyrE1A2nB lx9OlVN0wMid0buPUp+Z59Bm2+Fg2c4Nvw4oXtzbnGMyz2pdvhjNyUC6xzKxFsBn UqtHPzP4cOmBWg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvddutddgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepifgrvghtrghnucftihhvvghtuceoghhrihhvvgesuhdvheei rdhnvghtqeenucggtffrrghtthgvrhhnpeehgfevffekteehteefieefvdehleefjeefhe evudetjefhkeeutdekieeuvdetheenucfkphepkeeirddvheegrddvgeefrddugeeinecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhrihhvvg esuhdvheeirdhnvght X-ME-Proxy: Received: from inocybe.home (lfbn-poi-1-930-146.w86-254.abo.wanadoo.fr [86.254.243.146]) by mail.messagingengine.com (Postfix) with ESMTPA id B0B03240066; Thu, 22 Apr 2021 11:54:41 -0400 (EDT) From: Gaetan Rivet To: ovs-dev@openvswitch.org Date: Thu, 22 Apr 2021 17:54:31 +0200 Message-Id: <59e5c2ae58ab4e2814b65d4778b1da2dd688a694.1619106089.git.grive@u256.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Cc: i.maximets@ovn.org Subject: [ovs-dev] [RFC PATCH 6/8] ovs-thread: Quiesce when joining pthreads X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Joining pthreads makes the caller quiescent. It should register as such, as joined threads may wait on an RCU callback executing before quitting, deadlocking the caller. Signed-off-by: Gaetan Rivet --- lib/ovs-thread.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c index 805cba622..bf58923f8 100644 --- a/lib/ovs-thread.c +++ b/lib/ovs-thread.c @@ -180,8 +180,6 @@ XPTHREAD_FUNC1(pthread_cond_destroy, pthread_cond_t *); XPTHREAD_FUNC1(pthread_cond_signal, pthread_cond_t *); XPTHREAD_FUNC1(pthread_cond_broadcast, pthread_cond_t *); -XPTHREAD_FUNC2(pthread_join, pthread_t, void **); - typedef void destructor_func(void *); XPTHREAD_FUNC2(pthread_key_create, pthread_key_t *, destructor_func *); XPTHREAD_FUNC1(pthread_key_delete, pthread_key_t); @@ -191,6 +189,20 @@ XPTHREAD_FUNC2(pthread_setspecific, pthread_key_t, const void *); XPTHREAD_FUNC3(pthread_sigmask, int, const sigset_t *, sigset_t *); #endif +void +xpthread_join(pthread_t thread, void **retval) +{ + int error; + + ovsrcu_quiesce_start(); + error = pthread_join(thread, retval); + ovsrcu_quiesce_end(); + + if (OVS_UNLIKELY(error)) { + ovs_abort(error, "%s failed", __func__); + } +} + static void ovs_mutex_init__(const struct ovs_mutex *l_, int type) { From patchwork Thu Apr 22 15:54:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaetan Rivet X-Patchwork-Id: 1469281 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=u256.net header.i=@u256.net header.a=rsa-sha256 header.s=fm1 header.b=altOBLI1; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=Jmr4edbk; dkim-atps=neutral Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FR2793ryJz9sW5 for ; Fri, 23 Apr 2021 01:55:01 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id D739C60DBE; Thu, 22 Apr 2021 15:54:59 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AaXIjWW3nVvx; Thu, 22 Apr 2021 15:54:58 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTP id C2F086068C; Thu, 22 Apr 2021 15:54:54 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 90056C0024; Thu, 22 Apr 2021 15:54:52 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2E4BBC0024 for ; Thu, 22 Apr 2021 15:54:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 9F78940112 for ; Thu, 22 Apr 2021 15:54:44 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=u256.net header.b="altOBLI1"; dkim=pass (2048-bit key) header.d=messagingengine.com header.b="Jmr4edbk" Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7hJrFw5uHOmJ for ; Thu, 22 Apr 2021 15:54:44 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by smtp2.osuosl.org (Postfix) with ESMTPS id 2938A403AC for ; Thu, 22 Apr 2021 15:54:44 +0000 (UTC) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 5F5601617; Thu, 22 Apr 2021 11:54:43 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 22 Apr 2021 11:54:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u256.net; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=fPf3qvElfOarN lye+EYY+qXW9kFSK71qaIqX3c+pQIk=; b=altOBLI1nFDbXHQBei/WbO4itV83S 7um7ozy7k15Ih6VrZF6MA4XskP8D2nj83utend0ugZGZPMt0p+5mppSvJSTnWUf8 GegZXMitnE7vq654IEmfQetCTPz6QaTmP5Xx0BxJBopK28iEQNU3pMvaPLZ06Gh6 dLyB9oHFrvdTNQqw+LifmvRga/bDVjuV82eFMk8A2b3m3z/3nKTvt5XJ0pLjRy69 kIVlLC/RIotZD+SiK5ZnMzwU9k2tJHkPJa/f4qrwHq5BTTI3bg0wPkgNlnFqI3pz FYchTt/L7lS7yNOfLVqp9ebboaLu3ktB1xdG7AUrUva/qBF75ap1Y16gQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=fPf3qvElfOarNlye+EYY+qXW9kFSK71qaIqX3c+pQIk=; b=Jmr4edbk IWRFXQGQ80rum/SUvavCTxvpNbyQXzw0Mou+9uITgXaGvvK9co2tAmVFRxpdTLpK QucVt8pLT/+/lLFoilgGd+ZCWK1YTwiWFTAsj07Cb1qd11RmGXxQBPwIy2FmJXZ0 7/PrOK8qa7QtZxiLVMjLKU5F/pqWQmFtCg9Fc0hCgsz5p6j3rz77XlxqZXTwiitt bpVLwKXPZZXINJ2FetnfOFDb+z0vhclyxaXUOU5B5ORV8PvPJFA37s5hJTlFpTiG 7gkH6muWUqKVRTn7yxeZ4Gj51T3wD6vInMMRiSih6o/1dLZaRs7m2JAwq8H0YDGT reDwvg6i0lYEcw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvddutddgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepifgrvghtrghnucftihhvvghtuceoghhrihhvvgesuhdvheei rdhnvghtqeenucggtffrrghtthgvrhhnpeehgfevffekteehteefieefvdehleefjeefhe evudetjefhkeeutdekieeuvdetheenucfkphepkeeirddvheegrddvgeefrddugeeinecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhrihhvvg esuhdvheeirdhnvght X-ME-Proxy: Received: from inocybe.home (lfbn-poi-1-930-146.w86-254.abo.wanadoo.fr [86.254.243.146]) by mail.messagingengine.com (Postfix) with ESMTPA id 6E20924005B; Thu, 22 Apr 2021 11:54:42 -0400 (EDT) From: Gaetan Rivet To: ovs-dev@openvswitch.org Date: Thu, 22 Apr 2021 17:54:32 +0200 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Cc: i.maximets@ovn.org Subject: [ovs-dev] [RFC PATCH 7/8] rcu: Remove unused perthread mutex X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" A mutex is allocated, initialized and destroyed, without being used in the perthread structure. Signed-off-by: Gaetan Rivet --- lib/ovs-rcu.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/ovs-rcu.c b/lib/ovs-rcu.c index cde1e925b..1866bd308 100644 --- a/lib/ovs-rcu.c +++ b/lib/ovs-rcu.c @@ -47,7 +47,6 @@ struct ovsrcu_cbset { struct ovsrcu_perthread { struct ovs_list list_node; /* In global list. */ - struct ovs_mutex mutex; uint64_t seqno; struct ovsrcu_cbset *cbset; char name[16]; /* This thread's name. */ @@ -84,7 +83,6 @@ ovsrcu_perthread_get(void) const char *name = get_subprogram_name(); perthread = xmalloc(sizeof *perthread); - ovs_mutex_init(&perthread->mutex); perthread->seqno = seq_read(global_seqno); perthread->cbset = NULL; ovs_strlcpy(perthread->name, name[0] ? name : "main", @@ -406,7 +404,6 @@ ovsrcu_unregister__(struct ovsrcu_perthread *perthread) ovs_list_remove(&perthread->list_node); ovs_mutex_unlock(&ovsrcu_threads_mutex); - ovs_mutex_destroy(&perthread->mutex); free(perthread); seq_change(global_seqno); From patchwork Thu Apr 22 15:54:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaetan Rivet X-Patchwork-Id: 1469283 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=u256.net header.i=@u256.net header.a=rsa-sha256 header.s=fm1 header.b=lRHkxNes; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=GPi7LF4H; dkim-atps=neutral Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FR27C2cY4z9sW5 for ; Fri, 23 Apr 2021 01:55:03 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 9BDB784309; Thu, 22 Apr 2021 15:55:01 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zam-7Sv0MU0N; Thu, 22 Apr 2021 15:54:58 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTP id 491A9842BE; Thu, 22 Apr 2021 15:54:56 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id DDDC5C001C; Thu, 22 Apr 2021 15:54:53 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id AB41DC0026 for ; Thu, 22 Apr 2021 15:54:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 9EE5483C2E for ; Thu, 22 Apr 2021 15:54:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4Hj3ZQ8LsYPH for ; Thu, 22 Apr 2021 15:54:44 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by smtp1.osuosl.org (Postfix) with ESMTPS id BEE8083C27 for ; Thu, 22 Apr 2021 15:54:44 +0000 (UTC) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 22B621612; Thu, 22 Apr 2021 11:54:44 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 22 Apr 2021 11:54:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u256.net; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=0lghokyx94VxQ Zi2/Ic4kUht7WsDYASR8upAnsPScOk=; b=lRHkxNesJqbAbM16DJHQaNbDhXTxo q4jZfcy4DCLpxMokHm8z+5NUQeWXfQ28kQBzwEUQY2CYmlV5jGzYXbPqUg4JN7V7 ksNWqulSiflu4wTrqRlnrwRczqs5RIkm2+IqAk3KnDU4DtbOWDqj5C1CdfwidGUq KDX0LNpwiTEUQNJWdWx4ynmeNrKoSgAKRZr8z0MkSZnkkx/cORfbg/gP7QdN6KOa fnuzD3Nufqv9C3ZvG8fFg/miRisK5XWadTfkVeKWWSBQfYIoCZRq5JMA6JolMHyW tiRMcNse9ong3ZrmB6T/5MU3lcAkhzrvXA6cdnFiGGzyFiWtgDTFox+Gw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=0lghokyx94VxQZi2/Ic4kUht7WsDYASR8upAnsPScOk=; b=GPi7LF4H 7R9nLV0sfH4l4CejlxWiltHVaBgDtaXHK6niuW0aDVQO109taImcw/dR8tgthg7C tfrwgGLZGev3RlkTHA2Eeimvpu61GZzYexYnRdyxNP8jxN1/WbDj3OFsiCdbUDpj V6sSkkClKX2Lgnatd2kKZk18e5OZwbA6HkOIG47R+2vqVqSOrwkDfSbhiELjV8DX J00LDb4tfEUzDj2l4hK34cjM/jspe0T9bGFzps7lxLbTU2/JkSpwRAqW0SIX/X1s jFd3PJ9DZMZ2YbR01bS14KaWOoHGvwzW42jaIy1HdpceNZdDl8wjDEjcfeV/dZqh GFL/ytYeq+xCOg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvddutddgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepifgrvghtrghnucftihhvvghtuceoghhrihhvvgesuhdvheei rdhnvghtqeenucggtffrrghtthgvrhhnpeduheekveehfedtueejjeeigeehvdfggefhte dugedutdefhfekhedugeetveeuhfenucffohhmrghinhepshhhsgdrtghinecukfhppeek iedrvdehgedrvdegfedrudegieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehgrhhivhgvsehuvdehiedrnhgvth X-ME-Proxy: Received: from inocybe.home (lfbn-poi-1-930-146.w86-254.abo.wanadoo.fr [86.254.243.146]) by mail.messagingengine.com (Postfix) with ESMTPA id 2CA30240069; Thu, 22 Apr 2021 11:54:43 -0400 (EDT) From: Gaetan Rivet To: ovs-dev@openvswitch.org Date: Thu, 22 Apr 2021 17:54:33 +0200 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Cc: i.maximets@ovn.org Subject: [ovs-dev] [RFC PATCH 8/8] rcu: Add blocking RCU mode X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Add the configure option --enable-rcu-blocking, that modifies the RCU library. When enabled, quiescing from other threads will block, waiting on the RCU thread to execute the postponed jobs. This mode forces the deferred memory reclamation to happen deterministically, reducing the latency of the deferral and forcing memory to be freed any time a thread goes through a quiescent state. Some use-after-free that were hidden by deferred memory reclamation may become observable as a result. Previously the RCU mechanism would make them harder to detect. UAF detection tools should then be used in conjunction with this compilation flag, e.g. (assuming llvm installed): ./configure --enable-rcu-blocking --enable-asan export ASAN_SYMBOLIZER_PATH=$(which llvm-symbolizer) export ASAN_OPTIONS=symbolize=1 make # Verify the tool works: should trigger a UAF ./tests/ovstest test-rcu-uaf quiesce ./tests/ovstest test-rcu-uaf try-quiesce ./tests/ovstest test-rcu-uaf quiesce-start-end # The testsuite can be used as well make check TESTSUITEFLAGS='-k rcu' Signed-off-by: Gaetan Rivet --- .ci/linux-build.sh | 4 ++ .github/workflows/build-and-test.yml | 7 +++ NEWS | 1 + acinclude.m4 | 15 +++++ configure.ac | 1 + lib/ovs-rcu.c | 86 +++++++++++++++++++++++++++- tests/atlocal.in | 1 + tests/library.at | 3 + 8 files changed, 117 insertions(+), 1 deletion(-) diff --git a/.ci/linux-build.sh b/.ci/linux-build.sh index 3c58637b4..e4cbe2024 100755 --- a/.ci/linux-build.sh +++ b/.ci/linux-build.sh @@ -235,6 +235,10 @@ if [ "$ASAN" ]; then CFLAGS_FOR_OVS="${CFLAGS_FOR_OVS} -O1" fi +if [ "$RCU_BLOCK" ]; then + EXTRA_OPTS="$EXTRA_OPTS --enable-rcu-blocking" +fi + save_OPTS="${OPTS} $*" OPTS="${EXTRA_OPTS} ${save_OPTS}" diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index ce98a9f98..655923325 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -23,6 +23,7 @@ jobs: M32: ${{ matrix.m32 }} OPTS: ${{ matrix.opts }} TESTSUITE: ${{ matrix.testsuite }} + RCU_BLOCK: ${{ matrix.rcu_blocking }} name: linux ${{ join(matrix.*, ' ') }} runs-on: ubuntu-18.04 @@ -109,6 +110,12 @@ jobs: - compiler: gcc deb_package: deb + - compiler: clang + testsuite: test + kernel: 3.16 + asan: asan + rcu_blocking: rcu-blocking + steps: - name: checkout uses: actions/checkout@v2 diff --git a/NEWS b/NEWS index 57e1f041b..83fcfe1d0 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,7 @@ Post-v2.15.0 in ovsdb on startup. * New command 'record-hostname-if-not-set' to update hostname in ovsdb. - New --enable-asan configure option enables AddressSanitizer. + - New --enable-rcu-blocking configure option to debug RCU usage. v2.15.0 - 15 Feb 2021 diff --git a/acinclude.m4 b/acinclude.m4 index 615e7f962..b01264373 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1386,6 +1386,21 @@ AC_DEFUN([OVS_ENABLE_SPARSE], [], [enable_sparse=no]) AM_CONDITIONAL([ENABLE_SPARSE_BY_DEFAULT], [test $enable_sparse = yes])]) +dnl OVS_ENABLE_RCU_BLOCKING +AC_DEFUN([OVS_ENABLE_RCU_BLOCKING], + [AC_ARG_ENABLE( + [rcu-blocking], + [AC_HELP_STRING([--enable-rcu-blocking], + [Enable the blocking RCU mode])], + [RCU_BLOCKING=yes], [RCU_BLOCKING=no]) + AC_SUBST([RCU_BLOCKING]) + AC_CONFIG_COMMANDS_PRE([ + if test "$RCU_BLOCKING" = "yes"; then + OVS_CFLAGS="$OVS_CFLAGS -DOVS_RCU_BLOCKING=1" + fi + ]) + ]) + dnl OVS_CTAGS_IDENTIFIERS dnl dnl ctags ignores symbols with extras identifiers. This is a list of diff --git a/configure.ac b/configure.ac index eec5a9d1b..de11ff777 100644 --- a/configure.ac +++ b/configure.ac @@ -184,6 +184,7 @@ OVS_CHECK_CC_OPTION([-mavx512f], [CFLAGS="$CFLAGS -DHAVE_AVX512F"]) OVS_ENABLE_WERROR OVS_ENABLE_ASAN OVS_ENABLE_SPARSE +OVS_ENABLE_RCU_BLOCKING OVS_CTAGS_IDENTIFIERS OVS_CHECK_DPCLS_AUTOVALIDATOR OVS_CHECK_BINUTILS_AVX512 diff --git a/lib/ovs-rcu.c b/lib/ovs-rcu.c index 1866bd308..fd929abf1 100644 --- a/lib/ovs-rcu.c +++ b/lib/ovs-rcu.c @@ -71,6 +71,81 @@ static void ovsrcu_unregister__(struct ovsrcu_perthread *); static bool ovsrcu_call_postponed(void); static void *ovsrcu_postpone_thread(void *arg OVS_UNUSED); +#ifdef OVS_RCU_BLOCKING + +static struct seq *postpone_wait; +DEFINE_STATIC_PER_THREAD_DATA(bool, need_wait, false); +DEFINE_STATIC_PER_THREAD_DATA(uint64_t, quiescent_seqno, 0); + +static bool +ovsrcu_exited(void) +{ + /* Do not wait on the postpone thread if it has been cleared for exit. */ + return single_threaded() || latch_is_set(&postpone_exit); +} + +static void +ovsrcu_postpone_end(void) +{ + seq_change(postpone_wait); +} + +static void +ovsrcu_postpone_wait_enable(bool seq_locked) +{ + if (strncmp(get_subprogram_name(), "urcu", strlen("urcu")) && + !ovsrcu_exited()) { + + if (seq_locked) { + *quiescent_seqno_get() = seq_read_protected(postpone_wait); + } else { + *quiescent_seqno_get() = seq_read(postpone_wait); + } + + *need_wait_get() = true; + } +} + +static void +ovsrcu_postpone_wait(void) +{ + struct ovsrcu_perthread *perthread; + uint64_t last_seqno_seen; + + ovsrcu_init_module(); + + if (strncmp(get_subprogram_name(), "urcu", strlen("urcu")) && + !ovsrcu_exited() && *need_wait_get()) { + *need_wait_get() = false; + + last_seqno_seen = *quiescent_seqno_get(); + if (last_seqno_seen != seq_read(postpone_wait)) { + return; + } + + seq_wait(postpone_wait, *quiescent_seqno_get()); + + /* Unregistering the potential current perthread + * marks this thread as quiescent. + */ + perthread = pthread_getspecific(perthread_key); + if (perthread) { + pthread_setspecific(perthread_key, NULL); + ovsrcu_unregister__(perthread); + } + + poll_block(); + } +} + +#else + +#define ovsrcu_postpone_end() do { } while (0) +#define ovsrcu_postpone_wait_enable(b) do { } while (0) +#define ovsrcu_postpone_wait() do { } while (0) + +#endif /* OVS_RCU_BLOCKING */ + static struct ovsrcu_perthread * ovsrcu_perthread_get(void) { @@ -122,6 +197,7 @@ ovsrcu_quiesced(void) ovsthread_once_done(&once); } } + ovsrcu_postpone_wait(); } /* Indicates the beginning of a quiescent state. See "Details" near the top of @@ -154,6 +230,7 @@ ovsrcu_quiesce(void) perthread = ovsrcu_perthread_get(); perthread->seqno = seq_read(global_seqno); if (perthread->cbset) { + ovsrcu_postpone_wait_enable(false); ovsrcu_flush_cbset(perthread); } seq_change(global_seqno); @@ -172,6 +249,7 @@ ovsrcu_try_quiesce(void) if (!seq_try_lock()) { perthread->seqno = seq_read_protected(global_seqno); if (perthread->cbset) { + ovsrcu_postpone_wait_enable(true); ovsrcu_flush_cbset__(perthread, true); } seq_change_protected(global_seqno); @@ -359,7 +437,9 @@ ovsrcu_postpone_thread(void *arg OVS_UNUSED) while (!latch_is_set(&postpone_exit)) { uint64_t seqno = seq_read(flushed_cbsets_seq); - if (!ovsrcu_call_postponed()) { + bool postpone_executed = ovsrcu_call_postponed(); + ovsrcu_postpone_end(); + if (!postpone_executed) { seq_wait(flushed_cbsets_seq, seqno); latch_wait(&postpone_exit); poll_block(); @@ -397,6 +477,7 @@ static void ovsrcu_unregister__(struct ovsrcu_perthread *perthread) { if (perthread->cbset) { + ovsrcu_postpone_wait_enable(false); ovsrcu_flush_cbset(perthread); } @@ -432,6 +513,9 @@ ovsrcu_init_module(void) { static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; if (ovsthread_once_start(&once)) { +#ifdef OVS_RCU_BLOCKING + postpone_wait = seq_create(); +#endif global_seqno = seq_create(); xpthread_key_create(&perthread_key, ovsrcu_thread_exit_cb); fatal_signal_add_hook(ovsrcu_cancel_thread_exit_cb, NULL, NULL, true); diff --git a/tests/atlocal.in b/tests/atlocal.in index f61e752bf..c677049c9 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -4,6 +4,7 @@ OPENSSL_SUPPORTS_SNI='@OPENSSL_SUPPORTS_SNI@' HAVE_UNBOUND='@HAVE_UNBOUND@' EGREP='@EGREP@' PYTHON3='@PYTHON3@' +RCU_BLOCKING='@RCU_BLOCKING@' # PYTHONCOERCECLOCALE=0 disables the Unicode compatibility warning on # stderr that breaks almost any Python3 test (PEP 0538) diff --git a/tests/library.at b/tests/library.at index 4a549f77e..cae612eea 100644 --- a/tests/library.at +++ b/tests/library.at @@ -264,6 +264,7 @@ AT_CLEANUP AT_SETUP([rcu quiesce use-after-free detection]) AT_SKIP_IF([test "$IS_WIN32" = "yes"]) AT_SKIP_IF([test "$ASAN_ENABLED" = "no"]) +AT_SKIP_IF([test "$RCU_BLOCKING" = "no"]) # SIGABRT + 128 exit_status=134 AT_KEYWORDS([rcu asan]) @@ -275,6 +276,7 @@ AT_CLEANUP AT_SETUP([rcu try-quiesce use-after-free detection]) AT_SKIP_IF([test "$IS_WIN32" = "yes"]) AT_SKIP_IF([test "$ASAN_ENABLED" = "no"]) +AT_SKIP_IF([test "$RCU_BLOCKING" = "no"]) # SIGABRT + 128 exit_status=134 AT_KEYWORDS([rcu asan]) @@ -286,6 +288,7 @@ AT_CLEANUP AT_SETUP([rcu quiesce-start-end use-after-free detection]) AT_SKIP_IF([test "$IS_WIN32" = "yes"]) AT_SKIP_IF([test "$ASAN_ENABLED" = "no"]) +AT_SKIP_IF([test "$RCU_BLOCKING" = "no"]) AT_KEYWORDS([rcu asan]) # SIGABRT + 128 exit_status=134