From patchwork Fri Jan 13 06:59:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boqun Feng X-Patchwork-Id: 13100194 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13841C677F1 for ; Fri, 13 Jan 2023 07:14:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241146AbjAMHOJ (ORCPT ); Fri, 13 Jan 2023 02:14:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241346AbjAMHNn (ORCPT ); Fri, 13 Jan 2023 02:13:43 -0500 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C3DF84629; Thu, 12 Jan 2023 23:00:13 -0800 (PST) Received: by mail-qt1-x82a.google.com with SMTP id jr10so11152939qtb.7; Thu, 12 Jan 2023 23:00:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=bL7FAKnljET09Lz5o8O5NOQXfeYUZOAStn+hSKBeOpU=; b=mLKdcXQfYIaVPGU/nFUcKanZjagSZZU1Zzk/zDGg8fyKkBdBUeD+aiZqGf4B15lcFD XvLY6GMcL3ok/8LM6egXBh+JwQ3GpOSVTaGKk5iulFhBD8m9rlrXHCuI1vnALThnvgqJ v4ItVyJtHmiBqkNzcFz3UFZyJPPEdfNxbk4cpw9aYJTT2WB9Gv9cW2Z/f+olVaRzztab 5+Syy19z6Gh5wnN48AzLIChROYG60r2xu3kc+YOAAvCFMnLRhaRirwxjqPRKExksHLlC VF80TrC3GM+c5deULwcIDqZrB7ySmhHAE8S+VVd6OUf/K1SGAzJ6/ika3jnosRIFQI1y KVLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=bL7FAKnljET09Lz5o8O5NOQXfeYUZOAStn+hSKBeOpU=; b=Dpg5lvBqrdPF9STDISpT/AP7Bui9zYJMmO98zeh0unOZgBVArzClwgHWg5M6MUUlT4 uLYOrtl/UNLrzYnua5S5frrkdj7frukBJ7jMtMXP2IfakLbT5TtD4zMD45xfXl/o5WXu MejvtyZ6ak5+TCWlSVoSUFBu/5VrBBo2+qBLQfYUvG/ej13Fs8W1Ho2UBb4gRU7DGGgl bm2J+15rpQUPLNWJGt3HPdkSPBMdJ9zjJDn55HQbVxeK8JIkaAt3qOYV/4uN0ArESBUb 7Dc5QzS7x6Zw0ahkuOvurrkN3gsInuoTFHFcq+gJi7v9X17zBC4+/WNl9dlVbBRNN/Vn i+SA== X-Gm-Message-State: AFqh2krakvt82rw+q2UC+lrt+cQaTtyqbs1Xvf2UnCXQxxGxtlo/5xNE wiVr26f4JV2Njc3eeCXdl/c= X-Google-Smtp-Source: AMrXdXuIMNulWdH7ixWS7z9Lx70JG51NniRsnsm25d0tH8PwKh7R7JqGS38UxepwK9Kan+JJ+wcEuA== X-Received: by 2002:a05:622a:206:b0:3a7:eb36:5cb3 with SMTP id b6-20020a05622a020600b003a7eb365cb3mr141815642qtx.41.1673593209390; Thu, 12 Jan 2023 23:00:09 -0800 (PST) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id z26-20020ac8101a000000b003a70a675066sm10121892qti.79.2023.01.12.23.00.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 23:00:08 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailauth.nyi.internal (Postfix) with ESMTP id 6892327C005B; Fri, 13 Jan 2023 02:00:08 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Fri, 13 Jan 2023 02:00:08 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrleejgddutdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeegleejiedthedvheeggfejveefjeejkefgveffieeujefhueeigfegueeh geeggfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdei gedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfih igmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 13 Jan 2023 02:00:07 -0500 (EST) From: Boqun Feng To: linux-kernel@vger.kernel.org, rcu@vger.kernel.org, kvm@vger.kernel.org Cc: Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , Lai Jiangshan , "Paul E. McKenney" , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , David Woodhouse , Paolo Bonzini , seanjc@google.com, Joel Fernandes , Matthew Wilcox , Michal Luczaj Subject: [PATCH 3/3] WIP: locking/lockdep: selftests: Add selftests for SRCU Date: Thu, 12 Jan 2023 22:59:55 -0800 Message-Id: <20230113065955.815667-4-boqun.feng@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230113065955.815667-1-boqun.feng@gmail.com> References: <20230113065955.815667-1-boqun.feng@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: rcu@vger.kernel.org Signed-off-by: Boqun Feng --- lib/locking-selftest.c | 71 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c index 8d24279fad05..5fc206a2f9f1 100644 --- a/lib/locking-selftest.c +++ b/lib/locking-selftest.c @@ -60,6 +60,7 @@ __setup("debug_locks_verbose=", setup_debug_locks_verbose); #define LOCKTYPE_RTMUTEX 0x20 #define LOCKTYPE_LL 0x40 #define LOCKTYPE_SPECIAL 0x80 +#define LOCKTYPE_SRCU 0x100 static struct ww_acquire_ctx t, t2; static struct ww_mutex o, o2, o3; @@ -100,6 +101,13 @@ static DEFINE_RT_MUTEX(rtmutex_D); #endif +#ifdef CONFIG_SRCU +static struct lock_class_key srcu_A_key; +static struct lock_class_key srcu_B_key; +static struct srcu_struct srcu_A; +static struct srcu_struct srcu_B; +#endif + /* * Locks that we initialize dynamically as well so that * e.g. X1 and X2 becomes two instances of the same class, @@ -1418,6 +1426,12 @@ static void reset_locks(void) memset(&ww_lockdep.acquire_key, 0, sizeof(ww_lockdep.acquire_key)); memset(&ww_lockdep.mutex_key, 0, sizeof(ww_lockdep.mutex_key)); local_irq_enable(); + +#ifdef CONFIG_SRCU + __init_srcu_struct(&srcu_A, "srcuA", &srcu_A_key); + __init_srcu_struct(&srcu_B, "srcuB", &srcu_B_key); +#endif + } #undef I @@ -2360,6 +2374,58 @@ static void ww_tests(void) pr_cont("\n"); } +static void srcu_ABBA(void) +{ + int ia, ib; + + ia = srcu_read_lock(&srcu_A); + synchronize_srcu(&srcu_B); + srcu_read_unlock(&srcu_A, ia); + + ib = srcu_read_lock(&srcu_B); + synchronize_srcu(&srcu_A); + srcu_read_unlock(&srcu_B, ib); // should fail +} + +static void srcu_mutex_ABBA(void) +{ + int ia; + + mutex_lock(&mutex_A); + synchronize_srcu(&srcu_A); + mutex_unlock(&mutex_A); + + ia = srcu_read_lock(&srcu_A); + mutex_lock(&mutex_A); + mutex_unlock(&mutex_A); + srcu_read_unlock(&srcu_A, ia); // should fail +} + +static void srcu_irqsafe(void) +{ + int ia; + + HARDIRQ_ENTER(); + ia = srcu_read_lock(&srcu_A); + srcu_read_unlock(&srcu_A, ia); + HARDIRQ_EXIT(); + + synchronize_srcu(&srcu_A); // should NOT fail +} + +static void srcu_tests(void) +{ + printk(" --------------------------------------------------------------------------\n"); + printk(" | SRCU tests |\n"); + printk(" ---------------\n"); + print_testname("ABBA read-sync/read-sync"); + dotest(srcu_ABBA, FAILURE, LOCKTYPE_SRCU); + print_testname("ABBA mutex-sync/read-mutex"); + dotest(srcu_mutex_ABBA, FAILURE, LOCKTYPE_SRCU); + print_testname("Irqsafe synchronize_srcu"); + dotest(srcu_irqsafe, SUCCESS, LOCKTYPE_SRCU); + pr_cont("\n"); +} /* * @@ -2881,6 +2947,10 @@ void locking_selftest(void) printk(" --------------------------------------------------------------------------\n"); init_shared_classes(); +#ifdef CONFIG_SRCU + __init_srcu_struct(&srcu_A, "srcuA", &srcu_A_key); + __init_srcu_struct(&srcu_B, "srcuB", &srcu_B_key); +#endif lockdep_set_selftest_task(current); DO_TESTCASE_6R("A-A deadlock", AA); @@ -2965,6 +3035,7 @@ void locking_selftest(void) DO_TESTCASE_6x2x2RW("irq read-recursion #3", irq_read_recursion3); ww_tests(); + srcu_tests(); force_read_lock_recursive = 0; /*