From patchwork Mon Feb 6 21:05:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 53511 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2462619wrn; Mon, 6 Feb 2023 13:09:23 -0800 (PST) X-Google-Smtp-Source: AK7set87JmEGiX3mm6V+7hZXFZ8AqtjxJOf1D3aRSIBf9Jaj3x0dkx6a/WlaRSLXm1w3GzxG24kB X-Received: by 2002:a17:90b:4a52:b0:230:76b1:8db2 with SMTP id lb18-20020a17090b4a5200b0023076b18db2mr721790pjb.31.1675717762808; Mon, 06 Feb 2023 13:09:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675717762; cv=none; d=google.com; s=arc-20160816; b=Mylz0tMnESEB+wMS+eqqcPaF+DRrBDOy7K4W+7FXE/AfgQ27FAswwDRZms1yuu/ypC 1fVa07ZKXS3GA55YLlveF6qqrp8Y68tfItNGyOkuQ5Evcx9EcryOY/GWv0qZZ6gEHa5i uKOdU9ovuZ4/l7jie5g16rRcR3I9EEUsCLhp9QqTLzWPFmn8jVMo9YGu3ugM9HvwQJ/w rzR/AAWh3w4jpah99gKS+YSIJsefSxXFQjRzUfwJ9v4gZvOPF+NOwDB/FUQDSYPBU6fz EuCtS0z0/cWyH6lrdgOGB7duN0UNuJvaxp+AWtGm3J2T21cnFvxhqh/gIz8QJfkh89/R OGUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=xCwxWvSr3s2unKl3mPkOoa10/6N4Osd9n10mDC6raKw=; b=kZajZzwfSkPkajm5sAiqvvtHjB/awU3e/Hf+O2rnSP5v+hQray9oMGGIWV9nLe2NQR y1cHM7hPX+cabIoEXzjQdA/qwPawp/IAeXuvNDU0hPY4Xoc+4EWZpBhGW19Y6Uv3xac/ scrK7QghxEp0ckl+lzd6ckve6YooOZm0icm9aVWwETVAQveU6BuknUYIF1VQpgRKUIIR R22bKrrmbnooStHM6z5v7Jf9nfjLqiYeJwL5yWQPsWSmwvBht+lFyrOKVtqAHfSuvVj2 ABNCcufBTsKTWRV+dZEqFIy421WOjORX0vEHX23uobd58fryZrGEzQwcu2C2/WWf263H klog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qdIm713d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id me18-20020a17090b17d200b00230cd48760fsi2984241pjb.39.2023.02.06.13.09.09; Mon, 06 Feb 2023 13:09:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qdIm713d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229873AbjBFVGQ (ORCPT + 99 others); Mon, 6 Feb 2023 16:06:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229728AbjBFVGM (ORCPT ); Mon, 6 Feb 2023 16:06:12 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEBB46E83 for ; Mon, 6 Feb 2023 13:06:10 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id a9-20020a25af09000000b0083fa6f15c2fso12717550ybh.16 for ; Mon, 06 Feb 2023 13:06:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xCwxWvSr3s2unKl3mPkOoa10/6N4Osd9n10mDC6raKw=; b=qdIm713de6oE+5cCGu2bZQAIQcuVSxv1n1cc1tNVznp2fnmL+UPKHj836nDy9xAPNv sZAmnDutiEO9qq9QttDEevr2jQqeHBbPQCAIZ759ZiU+tbEVl6z8r6Wmu7vJoAJ2Pj+y M5NbNMqMmkU/6u8O3QkyhkN5QoS+oT4cc431rtkZ8Gf5wBwT3urB/OoFVipgCX8Lqq+c aCF1trWYV90q2qd+MULryufESqkCldjoEjkFFW5AppZIA64NfeeK7yJVOe7Rr+vuCAT1 kWidct0eOnKnzVWu8k9hQ9gQNarHrfqoGBlOUktTiYFAxIjmXTfrABlGehmp+BQTyXeI ndyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xCwxWvSr3s2unKl3mPkOoa10/6N4Osd9n10mDC6raKw=; b=olxFngcpYafshjAWHkFYRrJAtJwqrFQOPo91I9WlLpb8CqGCx33xBzXO3gI111M9Hu aBdHTUX29PxHWWRxHFeBhzHKmQRKmoNjE6wUTgJ0ZAtgqEabvUDxVbmmqF1xW7/AS6ei a2WwqhHmoyv2DaYmDN5BHx3CeiKtC3AvYrN+Hegem+e72q5/gMHBKIj6h8AVZtb7S+4I 59DNEXsWFNd3/mfKx/w/vC181MVEwfhb80mPsZO02IMRBDTiHWy3V/xEH/O4NR6S0RnD Cj5MRXP3XXA9f3kBn+LR0GKbYOHtodX89aNGUnot2qub4UxmZrjS30MLmHLFg4LVKkUw 2lUw== X-Gm-Message-State: AO0yUKXefkyVrUuQM/NzaiR0fG/I3GImKYGhEJYRqSYE6e5IJy+85XSr npyDznPorgcgbFUmCFJ0tG28rWOChrtMBDM2GbQZnXj5ovKqvETCvLVBDaKr5aceIUNeWxPIujU BfBUJYyl1pw23gnr+FxzRwfqahYQWOBAzIzzINNq3ZuYsSVQ9dlSBFuL6t1iu55cUYozo0t0= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a81:5203:0:b0:527:acad:5564 with SMTP id g3-20020a815203000000b00527acad5564mr72638ywb.35.1675717570016; Mon, 06 Feb 2023 13:06:10 -0800 (PST) Date: Mon, 6 Feb 2023 21:05:55 +0000 In-Reply-To: <20230206210556.660318-1-jstultz@google.com> Mime-Version: 1.0 References: <20230206210556.660318-1-jstultz@google.com> X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog Message-ID: <20230206210556.660318-3-jstultz@google.com> Subject: [PATCH v3 3/4] locktorture: Add nested locking to rtmutex torture tests From: John Stultz To: LKML Cc: John Stultz , Davidlohr Bueso , "Paul E. McKenney" , Josh Triplett , Joel Fernandes , Juri Lelli , Valentin Schneider , Dietmar Eggemann X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757117428734986029?= X-GMAIL-MSGID: =?utf-8?q?1757117428734986029?= This patch adds randomized nested locking to the rtmutex torture tests. Additionally it adds LOCK09 config files for testing rtmutexes with nested locking. Cc: Davidlohr Bueso Cc: "Paul E. McKenney" Cc: Josh Triplett Cc: Joel Fernandes Cc: Juri Lelli Cc: Valentin Schneider Cc: Dietmar Eggemann Reviewed-by: Davidlohr Bueso Signed-off-by: John Stultz --- v2: * Add LOCK09 config file suggested by Paul McKenney v3: * Minor commit message tweaks and naming changes suggested by Davidlohr Bueso --- kernel/locking/locktorture.c | 35 +++++++++++++++++++ .../selftests/rcutorture/configs/lock/CFLIST | 1 + .../selftests/rcutorture/configs/lock/LOCK09 | 6 ++++ .../rcutorture/configs/lock/LOCK09.boot | 1 + 4 files changed, 43 insertions(+) create mode 100644 tools/testing/selftests/rcutorture/configs/lock/LOCK09 create mode 100644 tools/testing/selftests/rcutorture/configs/lock/LOCK09.boot diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index 8a08c004aa80..fd8b2b007c26 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c @@ -506,6 +506,28 @@ static struct lock_torture_ops ww_mutex_lock_ops = { #ifdef CONFIG_RT_MUTEXES static DEFINE_RT_MUTEX(torture_rtmutex); +static struct rt_mutex torture_nested_rtmutexes[MAX_NESTED_LOCKS]; +static struct lock_class_key nested_rtmutex_keys[MAX_NESTED_LOCKS]; + +static void torture_rtmutex_init(void) +{ + int i; + + for (i = 0; i < MAX_NESTED_LOCKS; i++) + __rt_mutex_init(&torture_nested_rtmutexes[i], __func__, + &nested_rtmutex_keys[i]); +} + +static int torture_rtmutex_nested_lock(int tid __maybe_unused, + u32 lockset) +{ + int i; + + for (i = 0; i < nested_locks; i++) + if (lockset & (1 << i)) + rt_mutex_lock(&torture_nested_rtmutexes[i]); + return 0; +} static int torture_rtmutex_lock(int tid __maybe_unused) __acquires(torture_rtmutex) @@ -570,11 +592,24 @@ __releases(torture_rtmutex) rt_mutex_unlock(&torture_rtmutex); } +static void torture_rtmutex_nested_unlock(int tid __maybe_unused, + u32 lockset) +{ + int i; + + for (i = nested_locks - 1; i >= 0; i--) + if (lockset & (1 << i)) + rt_mutex_unlock(&torture_nested_rtmutexes[i]); +} + static struct lock_torture_ops rtmutex_lock_ops = { + .init = torture_rtmutex_init, + .nested_lock = torture_rtmutex_nested_lock, .writelock = torture_rtmutex_lock, .write_delay = torture_rtmutex_delay, .task_boost = torture_rtmutex_boost, .writeunlock = torture_rtmutex_unlock, + .nested_unlock = torture_rtmutex_nested_unlock, .readlock = NULL, .read_delay = NULL, .readunlock = NULL, diff --git a/tools/testing/selftests/rcutorture/configs/lock/CFLIST b/tools/testing/selftests/rcutorture/configs/lock/CFLIST index a48bba0d35a6..28e23d05d5a5 100644 --- a/tools/testing/selftests/rcutorture/configs/lock/CFLIST +++ b/tools/testing/selftests/rcutorture/configs/lock/CFLIST @@ -6,3 +6,4 @@ LOCK05 LOCK06 LOCK07 LOCK08 +LOCK09 diff --git a/tools/testing/selftests/rcutorture/configs/lock/LOCK09 b/tools/testing/selftests/rcutorture/configs/lock/LOCK09 new file mode 100644 index 000000000000..1d1da1477fc3 --- /dev/null +++ b/tools/testing/selftests/rcutorture/configs/lock/LOCK09 @@ -0,0 +1,6 @@ +CONFIG_SMP=y +CONFIG_NR_CPUS=4 +CONFIG_HOTPLUG_CPU=y +CONFIG_PREEMPT_NONE=n +CONFIG_PREEMPT_VOLUNTARY=n +CONFIG_PREEMPT=y diff --git a/tools/testing/selftests/rcutorture/configs/lock/LOCK09.boot b/tools/testing/selftests/rcutorture/configs/lock/LOCK09.boot new file mode 100644 index 000000000000..fd5eff148a93 --- /dev/null +++ b/tools/testing/selftests/rcutorture/configs/lock/LOCK09.boot @@ -0,0 +1 @@ +locktorture.torture_type=rtmutex_lock locktorture.nested_locks=8