From patchwork Thu Feb 2 22:34:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 52198 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp510572wrn; Thu, 2 Feb 2023 14:36:18 -0800 (PST) X-Google-Smtp-Source: AK7set/q4JSFxUGKSgqmXHuyzCmJfCHlsM/DabE0G4D/9NffLdauF6SIZNECmQKIxUDJkjT7PjnK X-Received: by 2002:a05:6a20:692a:b0:b8:8027:13bc with SMTP id q42-20020a056a20692a00b000b8802713bcmr10317686pzj.8.1675377378442; Thu, 02 Feb 2023 14:36:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675377378; cv=none; d=google.com; s=arc-20160816; b=UcCt0BD+YivShHKGcmcbPuSiC9sAwXmj7alV0Wv16zKjwzIw1EKsIF2MGFnKnLStOB q3zRpOu0ZbtUQEP3opVmZk63kdA3B1pZqE2OFTPE3twmt84KhHixRagYRNsxkBbVZNEW CVYeYo3dSSSeEh4WdMlT2yMMx5ojXUKusRFTe0wDRUwuS+Ge/GSfxS20RaVmYE/F4i3j Z2q+6wV2ZJRumV1vrkTBe12wWNtXl88/5u51qrjsHYuoewTmk4cFkKceg+KmKCQvG2rJ KZiOuVK9FGSVmKLGLz5mvAiYJADtFPWIlCvuRunKZ3+3oqYBVs/n2jWDkWs4uHgMiimN 2B5A== 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=mqEbaoXKZhduzvtpNpkhhcX7LiSnTOQP98iiJKeE854=; b=SDgLtMQmvEIKGKPdOuPQyrcHBabxqShZL8F5it0RYHagK/RGY66OrZM73ytsbxmRMH t0YVaJ6dftptjIJoeEHYMxgQFOUZddbNP9nTdbt4VIjMdG4R5lCrNwMDV/N1O2A/1y8V h2l/GJ1cz12zOG0W1iYtJPgj9+gT6lmBZ/eNfHyrap8V7niDll7Wyb5htu6U8t+O1ujH LgBaRD/o4LdQ/hzuvObBIpF/lV5mmbuWIWSzmhPvHYgSU9ciyU3HpSYgr2EDY8HzDM7F QI19QQrln/guaulzlcjcX4SwNdQVn2r9vIs13dEzysjK0smlMjaf7Ni9dSKVFWyxK9vL 19sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FwHExR9n; 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 r204-20020a632bd5000000b004e3ba113359si833632pgr.565.2023.02.02.14.36.06; Thu, 02 Feb 2023 14:36:18 -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=FwHExR9n; 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 S229974AbjBBWeW (ORCPT + 99 others); Thu, 2 Feb 2023 17:34:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232424AbjBBWeS (ORCPT ); Thu, 2 Feb 2023 17:34:18 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C7706952E for ; Thu, 2 Feb 2023 14:34:17 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-51e4bb90e78so33996807b3.1 for ; Thu, 02 Feb 2023 14:34:17 -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=mqEbaoXKZhduzvtpNpkhhcX7LiSnTOQP98iiJKeE854=; b=FwHExR9nBYi6inpOGnmsjd7ibbGtNobjrt2tyzYYMtoKUTFuTxaY9aTWYxwDthzwdc Hj6zHwKuIomOMJN9GRyzs3YnN8G4CyZbrbd4PXn4CrTHr1ncOrUFedjXXVc/Mi2PBW+8 A63NL9q7koYpwx8Au2YscoIZMxpUszainMvI6J91No3l7AsWWxMq3JqS6XkIEuYD+KGc R8A5JUbHv5FDxHd6Dzo5oI5ewynbmyYS+qN1faBZPTJS4E0DCt1hBwyED1MW13LcCuBd BR7whP2z8utCcejOBa4n2l5QlSOxeoMOSfnluehxFUjHfedZpbuImBCZ6InVlYgwT2Wz cXig== 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=mqEbaoXKZhduzvtpNpkhhcX7LiSnTOQP98iiJKeE854=; b=JdqM2i0KCh18qM9nLrwn3wHc+ypCh8XOq35NGonNkDQzJUWFHSEwixtj/6TFAHCEFi Je0kVh4NO0F9W7QaoBzIKzLmoSe7X8Vrlzrcr8kFOIpnokHCHrtzOyiD6ft3LbaIM2XS geC1CupmcdDgR9ehUVZHFftuhONrGydqQJbU++ZMYdvcV09IrD5zOuRCmsjkm0VDMCdN 9b7QJ0S0tuqv3XNLnX/mKYKHCpw4pr3cBgrX1GAfv5Y2a7IT88EMf5ZGE6GHVvb6mbN2 /ALWkLFzCpRMEvztTIHH6OYFN9XsplLg2ue9MBVmKTP+j2vIrAvZHHQFTfA3sZdRsmTe KkGg== X-Gm-Message-State: AO0yUKXZj8tnlttufZJVYvLIKDfjIPbgs8Blyngm666JlxVI2lYnWp4J jwAZX7JrH92TOE3UG+SrxGiYN/I8UjLg92abLAoF4WLP7EH66ufssE3MrNwITxdIsaGEFape/c9 Z1UQIZ+C8XOAwYVXOOpoZqzYsuyDU/S7e8GQBE9eWKKBSdkF7OmrwvW74Ccgfgm3ASd33+sk= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a81:7355:0:b0:521:db02:1015 with SMTP id o82-20020a817355000000b00521db021015mr7ywc.5.1675377255510; Thu, 02 Feb 2023 14:34:15 -0800 (PST) Date: Thu, 2 Feb 2023 22:34:08 +0000 In-Reply-To: <20230202223409.2812443-1-jstultz@google.com> Mime-Version: 1.0 References: <20230202223409.2812443-1-jstultz@google.com> X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog Message-ID: <20230202223409.2812443-3-jstultz@google.com> Subject: [RFC][PATCH 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?1756760510315079781?= X-GMAIL-MSGID: =?utf-8?q?1756760510315079781?= This patch adds randomized nested locking to the mutex torture tests. This was inspired by locktorture extensions originally implemented by Connor O'Brien, for stress testing the proxy-execution series: https://lore.kernel.org/lkml/20221003214501.2050087-12-connoro@google.com/ Comments or feedback would be greatly appreciated! Cc: Davidlohr Bueso Cc: "Paul E. McKenney" Cc: Josh Triplett Cc: Joel Fernandes Cc: Juri Lelli Cc: Valentin Schneider Cc: Dietmar Eggemann Signed-off-by: John Stultz --- kernel/locking/locktorture.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index 27d92ce36836..5fb17a5057b5 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_LOCKS]; +static struct lock_class_key nested_rtmutex_keys[MAX_LOCKS]; + +static void torture_rtmutex_init(void) +{ + int i; + + for (i = 0; i < MAX_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 < nlocks; 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 = nlocks - 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,