From patchwork Thu Feb 2 22:34:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 52197 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp510558wrn; Thu, 2 Feb 2023 14:36:17 -0800 (PST) X-Google-Smtp-Source: AK7set87/qEhGlQQb4Kbr+9WXVoJ7y4RcnOtzQBqr7Rg6D+izm5Bfg1MXGz+vPd+v5asr0BmoR20 X-Received: by 2002:a17:90a:1908:b0:22b:baf3:8f0d with SMTP id 8-20020a17090a190800b0022bbaf38f0dmr8324981pjg.16.1675377376774; Thu, 02 Feb 2023 14:36:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675377376; cv=none; d=google.com; s=arc-20160816; b=J3NNQewOfqQUfxL9yPiVeTJXs89AEQAvwPHCvEYfmmBcQeE629UN0AXvcdXRdaEyzX qEN+LD46ExUm/+NKahqdSbfHMQhTdajPwUwh7o0xHirnH8Srb3PmwZRFP20SlzZdWply XwJQ0w303bnKQq7+j9lpiZgwIZyn28PE8fU/UKZE2HoxlOBOLJ+SnA/zbhG5ZG0AnkqU j7ONjjMJZE9i8O+KRg9T/X1QnQHd/RE9FoYMubdQrHNkQDr4xR7PBYqi2qWqFGgCjONP +NlZ9KE0tt+Tw/idzwj9vK5vgl2zJkDABE0B1uEkjlB4e2YIAWUbMknBUgVmGB+NFt1n Sfxw== 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:mime-version:date :dkim-signature; bh=JqXBZCshocKpxm4gEZMlbqbtIQK38/N6xcknjdoOafE=; b=scPgX2+8GuaeN7dOqILWvjVsPztOsoK8KV5lrsjN0nr7Uua9kb1lpeBGyaVFmo9Fh2 /QpvKbWM8O+dgq5Lx66c1IC6P1uGzqwb5OT08acqzv7tQekDkR6MPdbftzXnto75gJ3n 9XzzPd6BUEwyIX2h+Q1iEugp1r+QI+dFLg3MnA8BGSK/R2HX6sDgW90Gu/7QUCY8h2cR xyxhJ78pRaf691T08JfVLACJsDT0lnamEy1mypvo5kPAeJ3CIxVa4gyK86Ln1+nySmTg w4qoN2uibz2KRev0SPU1O92//fxzIR026tecJi8isWTLvotqv2r4NV7r88kxxEg35SlE 57sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rtxJ+BeT; 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 y25-20020a637d19000000b004f1a97a4c9fsi841362pgc.470.2023.02.02.14.36.04; Thu, 02 Feb 2023 14:36:16 -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=rtxJ+BeT; 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 S232389AbjBBWeS (ORCPT + 99 others); Thu, 2 Feb 2023 17:34:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229667AbjBBWeP (ORCPT ); Thu, 2 Feb 2023 17:34:15 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2D5668AD4 for ; Thu, 2 Feb 2023 14:34:12 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id z9-20020a170902d54900b00196680ec8bbso1575385plf.16 for ; Thu, 02 Feb 2023 14:34:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=JqXBZCshocKpxm4gEZMlbqbtIQK38/N6xcknjdoOafE=; b=rtxJ+BeTJ2KGfEbZbbP4kOUdXR7t10eCA7N/6Qus1DybSK7fnJzApwwV+0M4y+1A7C QNE+jnNgMUEclDsYBGvrxLCJFp1efPe1N+3AruYpf1ePfHUDbH3USc2n7YDrQO52Z3yW S+vVueWtrBlQjeLj1foHFhrVTOUyeY48oR319ratj8r031ViZk6P6heXrazbE2XQKSQb d4TeNmyocCJmTUYe1n3PsuZBmUBRwiX9+dSvL6Gg8JysuDgdFFYev52/dVinOiLgxIK1 O9ZT2V6B25uH8VmekIe1mqwmng5zEYHkW8F3ohP7EsyL+U04jVQhnye+GsGlW/0gHa4r P/nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=JqXBZCshocKpxm4gEZMlbqbtIQK38/N6xcknjdoOafE=; b=DYuTmLYWqcI0XQLdQuwZGDYpFW4DhW6gXRA1erievxgLHA3rHOISmEWGBSYWLASViU yEWa9ghmGYBED2yRTU3NxPX8OPVtL35e7Gq7H8oXwX0n7nfowePGYjRQNWKuBN8eplfA 66wI/jzxoD0CIa/Ma/85mnM4J04TX+m7W56EZxovnmHLFfQuckfKpFtQ9L4NbRkOHd+d MlZSIcybbwRXUERoAjlFDvGuzbTswKJk+mtmJGKyqaAbEpJbKGq3vubv78QwEawb5Y+S ir3wBxYWm96hn6u+ZZ9iO/ajJO9hgskOhv433A89Bh32KLWEQ7nkx1jqtH67VZs0SiK1 Hatg== X-Gm-Message-State: AO0yUKV41oR792oIWb92ybC4xHIUoAjwkVRLPxRrRajnwqItHlJFw/oA B9e6mnIEsP9i+vUAx7IlGP4rbIpCYHKZprotj/+ErdQUQCr2NYv9wC7/BEzvDPKstcXdVkAiB1V J6AUKn/mpilNHF7LzbY72HemErhRXm0obhI6iIBYhcQOG68Pvsqjw2i+0FHqSxjWEQknI7N4= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a17:90a:3d04:b0:22c:7639:a926 with SMTP id h4-20020a17090a3d0400b0022c7639a926mr974784pjc.83.1675377252249; Thu, 02 Feb 2023 14:34:12 -0800 (PST) Date: Thu, 2 Feb 2023 22:34:06 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog Message-ID: <20230202223409.2812443-1-jstultz@google.com> Subject: [RFC][PATCH 1/4] locktorture: Add nested_[un]lock() hooks and nlocks parameter 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?1756760508217429866?= X-GMAIL-MSGID: =?utf-8?q?1756760508217429866?= In order ot extend locktorture to support lock nesting, add nested_lock() and nested_unlock() hooks to the torture ops. These take a 32bit lockset mask which is generated at random, so some number of locks will be taken before the main lock is taken and released afterwards. Additionally, add nlocks module parameter to allow specifying the number of nested locks to be used. This has been helpful to uncover issues in the proxy-exec series development. 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 | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index 9c2fb613a55d..f4fbd3194654 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c @@ -48,6 +48,9 @@ torture_param(int, stat_interval, 60, torture_param(int, stutter, 5, "Number of jiffies to run/halt test, 0=disable"); torture_param(int, verbose, 1, "Enable verbose debugging printk()s"); +torture_param(int, nlocks, 0, "Number of nested locks"); +/* Going much higher trips "BUG: MAX_LOCKDEP_CHAIN_HLOCKS too low!" errors */ +#define MAX_LOCKS 8 static char *torture_type = "spin_lock"; module_param(torture_type, charp, 0444); @@ -76,10 +79,12 @@ static void lock_torture_cleanup(void); struct lock_torture_ops { void (*init)(void); void (*exit)(void); + int (*nested_lock)(int tid, u32 lockset); int (*writelock)(int tid); void (*write_delay)(struct torture_random_state *trsp); void (*task_boost)(struct torture_random_state *trsp); void (*writeunlock)(int tid); + void (*nested_unlock)(int tid, u32 lockset); int (*readlock)(int tid); void (*read_delay)(struct torture_random_state *trsp); void (*readunlock)(int tid); @@ -669,6 +674,7 @@ static int lock_torture_writer(void *arg) struct lock_stress_stats *lwsp = arg; int tid = lwsp - cxt.lwsa; DEFINE_TORTURE_RANDOM(rand); + u32 lockset_mask; VERBOSE_TOROUT_STRING("lock_torture_writer task started"); set_user_nice(current, MAX_NICE); @@ -677,7 +683,10 @@ static int lock_torture_writer(void *arg) if ((torture_random(&rand) & 0xfffff) == 0) schedule_timeout_uninterruptible(1); + lockset_mask = torture_random(&rand); cxt.cur_ops->task_boost(&rand); + if (cxt.cur_ops->nested_lock) + cxt.cur_ops->nested_lock(tid, lockset_mask); cxt.cur_ops->writelock(tid); if (WARN_ON_ONCE(lock_is_write_held)) lwsp->n_lock_fail++; @@ -690,6 +699,8 @@ static int lock_torture_writer(void *arg) lock_is_write_held = false; WRITE_ONCE(last_lock_release, jiffies); cxt.cur_ops->writeunlock(tid); + if (cxt.cur_ops->nested_unlock) + cxt.cur_ops->nested_unlock(tid, lockset_mask); stutter_wait("lock_torture_writer"); } while (!torture_must_stop()); @@ -830,11 +841,11 @@ lock_torture_print_module_parms(struct lock_torture_ops *cur_ops, const char *tag) { pr_alert("%s" TORTURE_FLAG - "--- %s%s: nwriters_stress=%d nreaders_stress=%d stat_interval=%d verbose=%d shuffle_interval=%d stutter=%d shutdown_secs=%d onoff_interval=%d onoff_holdoff=%d\n", + "--- %s%s: nwriters_stress=%d nreaders_stress=%d nlocks=%d stat_interval=%d verbose=%d shuffle_interval=%d stutter=%d shutdown_secs=%d onoff_interval=%d onoff_holdoff=%d\n", torture_type, tag, cxt.debug_lock ? " [debug]": "", - cxt.nrealwriters_stress, cxt.nrealreaders_stress, stat_interval, - verbose, shuffle_interval, stutter, shutdown_secs, - onoff_interval, onoff_holdoff); + cxt.nrealwriters_stress, cxt.nrealreaders_stress, nlocks, + stat_interval, verbose, shuffle_interval, stutter, + shutdown_secs, onoff_interval, onoff_holdoff); } static void lock_torture_cleanup(void) @@ -1053,6 +1064,10 @@ static int __init lock_torture_init(void) } } + /* cap nlocks to MAX_LOCKS */ + if (nlocks > MAX_LOCKS) + nlocks = MAX_LOCKS; + if (cxt.cur_ops->readlock) { reader_tasks = kcalloc(cxt.nrealreaders_stress, sizeof(reader_tasks[0]), From patchwork Thu Feb 2 22:34:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 52199 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp510577wrn; Thu, 2 Feb 2023 14:36:21 -0800 (PST) X-Google-Smtp-Source: AK7set+1P/iUR3ygDrg4LcLKYGPsr2M6SfoMHjaF/UGQsNVD2NRvYwuUCAB9dOMpseZUfqDJ9l9D X-Received: by 2002:a17:90a:1982:b0:22c:59f2:9006 with SMTP id 2-20020a17090a198200b0022c59f29006mr8523014pji.34.1675377380763; Thu, 02 Feb 2023 14:36:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675377380; cv=none; d=google.com; s=arc-20160816; b=YEIeiLy8LDHVr7CNWB0xpjjPavqYT3LVp+dFOCGUNUA8BVf/omILqRdJWUNu/ZAAYu wuLTIwGzm1IqElPgKRija/P2jUTeE18EBtVjc/gJXbsxkgl7vya2KRfzhHQIT/lWoTXE K+xqBAoDioJbMk3UT24TjpYxXPeJGOYwRfSxSYrbkSAvem61MrAAnVZSSRriEPIC3s3b UZmo5MEVdD8DGDyfsqHYWb06uQg1onPq1z0UOVhn+FLxNnMf1XtAoLxgiPxRefaVn8md 8esvwNGBZ2jirSxWVLpgr06NLLgLtZ70lfkBrKRO3MfnBA71K12ItiThAnZ1Lk20lgmY RJ1Q== 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=dHYTUHZ8SljeUpfYx0Af13LEtqVRaVyIcAWcaM3M5WQ=; b=aa8zU6YbU6NWASQqEfO/9BP4r9NF9sGNTbcFiTCecZHzihBhBDUSXpwo17+vgoDFcn dpzcO3kfnrP9PF3HRfWl34ivPXB1w1soNcHUggM+GP2yKHtYTQkFha3GB835Gy3Q3lYX +sYXysTj1Z3P8r0lyG+FToaSan7kr7jhHw723zu6ipoBo0adPBJ/wUFrpit6DQb2p7hR DfJuFWA8tq4PlJj/UXwIDddHyaDJsd+btZ2QA+RFfLcvj2O4DsPXRgbNiqyLUDMz2keC M+VeO2vVE2QwcXiVVsuX5saYC8AW8NdtJwhpmCBROWquHB34xG+SLoAGx2I34BcqgmmT OCeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="I/Jz7ePL"; 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 l68-20020a633e47000000b004e934a7fc3bsi715495pga.346.2023.02.02.14.36.08; Thu, 02 Feb 2023 14:36:20 -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="I/Jz7ePL"; 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 S231751AbjBBWeQ (ORCPT + 99 others); Thu, 2 Feb 2023 17:34:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjBBWeP (ORCPT ); Thu, 2 Feb 2023 17:34:15 -0500 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C5EA68AD2 for ; Thu, 2 Feb 2023 14:34:14 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id bn10-20020a056a02030a00b004da3651ff4cso1635240pgb.13 for ; Thu, 02 Feb 2023 14:34:14 -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=dHYTUHZ8SljeUpfYx0Af13LEtqVRaVyIcAWcaM3M5WQ=; b=I/Jz7ePL18BdC75UYYW8y+xqrtgsO4ZgRjhlqBdH9sYeHDOxQsgeRUHzNF6LNs/F7v 4OipkPn3QzZTtSmns1wX7NmgOzGouFkfRS4KF5WnM789ageXhDWCobNeCgwd+VhHM3ir PvJFC/Wtx9kHkGtI1dwtA1SikbHe0rXNuzI3aN4LmDn/mIZIx5I5HW0u5mployOx4lcM Ri6QruxqZ1lCjXC8dHbH7ww1jiBWxgPIfWYMtr8sfrWahfFugXtAUnP8i4nkGB+//YmQ mRNhlORIzSR9YtZIw57shpojkEO3V9zUZp2s868j0vK7Fs4TgycHIygcJRAahwTXlXX4 g4Vg== 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=dHYTUHZ8SljeUpfYx0Af13LEtqVRaVyIcAWcaM3M5WQ=; b=RGYEcAdeY+1rWSN6eoQlIMFnSOkPnM6pesWDr6qAfNaduBcPT/uUQZIHrv5dWvZgme V425jkMC7FgbRXdINY54ibScbqQUMPi06Jjb32wA12PgDGzLocYdzcKa1w0puz41CdW2 VEEYPsiNHLGo948MgGw/Et8K68Tbtwizw4/zoyg1PlIEV74WnzuphsVQfB1fk/UEKWYP ItUph9Ji8YTIISlNHxoS+PwL5REg0/BjEvdpR98wsVqbfNfpPwOEpk4cL1o2y9ib1mBL osnKYCYBcVGCXycq0TdqrMGNilNiSECrzd2eQZjWhB/isxk/D4t/Dqa1pJMr3GcJUNJi r3Lw== X-Gm-Message-State: AO0yUKVIHDhWiFMiYOJ9lyDRvC8E7n/QB2QT3yKfJPGYVOcchhirbY2x Quzn1leWVo/jVl7bzQB4yr/z3KAIWQF2AEZa5qgw9SrQV7y8FQ3ppZDPK+A9zT71oUnvHhNFGvU 5mWzvZ8VusYf9FsgxgR7G3LKlPQ8yL9bNLjNEC8YNQOudvxw3lS37857ew3CY/WFmK1m0fHU= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a17:902:d349:b0:198:debf:d114 with SMTP id l9-20020a170902d34900b00198debfd114mr6721plk.29.1675377253704; Thu, 02 Feb 2023 14:34:13 -0800 (PST) Date: Thu, 2 Feb 2023 22:34:07 +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-2-jstultz@google.com> Subject: [RFC][PATCH 2/4] locktorture: Add nested locking to mutex 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?1756760511984408465?= X-GMAIL-MSGID: =?utf-8?q?1756760511984408465?= 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 f4fbd3194654..27d92ce36836 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c @@ -332,6 +332,28 @@ static struct lock_torture_ops rw_lock_irq_ops = { }; static DEFINE_MUTEX(torture_mutex); +static struct mutex torture_nested_mutexes[MAX_LOCKS]; +static struct lock_class_key nested_mutex_keys[MAX_LOCKS]; + +static void torture_mutex_init(void) +{ + int i; + + for (i = 0; i < MAX_LOCKS; i++) + __mutex_init(&torture_nested_mutexes[i], __func__, + &nested_mutex_keys[i]); +} + +static int torture_mutex_nested_lock(int tid __maybe_unused, + u32 lockset) +{ + int i; + + for (i = 0; i < nlocks; i++) + if (lockset & (1 << i)) + mutex_lock(&torture_nested_mutexes[i]); + return 0; +} static int torture_mutex_lock(int tid __maybe_unused) __acquires(torture_mutex) @@ -360,11 +382,24 @@ __releases(torture_mutex) mutex_unlock(&torture_mutex); } +static void torture_mutex_nested_unlock(int tid __maybe_unused, + u32 lockset) +{ + int i; + + for (i = nlocks - 1; i >= 0; i--) + if (lockset & (1 << i)) + mutex_unlock(&torture_nested_mutexes[i]); +} + static struct lock_torture_ops mutex_lock_ops = { + .init = torture_mutex_init, + .nested_lock = torture_mutex_nested_lock, .writelock = torture_mutex_lock, .write_delay = torture_mutex_delay, .task_boost = torture_boost_dummy, .writeunlock = torture_mutex_unlock, + .nested_unlock = torture_mutex_nested_unlock, .readlock = NULL, .read_delay = NULL, .readunlock = NULL, 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, From patchwork Thu Feb 2 22:34:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 52200 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp510637wrn; Thu, 2 Feb 2023 14:36:28 -0800 (PST) X-Google-Smtp-Source: AK7set/zV/TiF/h4lINbBCCrlRIsAG5S6StFLnL3rjxgKt16uHGuAmfP9Qyjtz2YZWj8e5YEFyBY X-Received: by 2002:a05:6a20:8e08:b0:bc:930e:4165 with SMTP id y8-20020a056a208e0800b000bc930e4165mr10253446pzj.15.1675377388594; Thu, 02 Feb 2023 14:36:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675377388; cv=none; d=google.com; s=arc-20160816; b=RqAz/ymm+HF7KCI+U4A6mkl4CN2QrPnnA26PPcOZL+J28enwt8lcOUmPtFfPPiCBjy ovjcrnV7aIRSdUZ6wEN9Ej3bpuleS/kpPimYYJJ2ZTrkDnNyThF0ekCyCX53ScIvot17 /tp4lHlNbQyVmCMpb80sBiuLw3XaRLbP0XKrXfcPiuMvUEX/KbVtWYyErKAFhYzyo2Ya 6TF/1TlIC/mg+e/PinuP0B2uVQQhVrvxyduejsmn7CR2iNEchW+3ONl/sWt9OB28Utj/ 1FL89h2ILoRz4xsk5QE1IQscAOosOSizPGc+qc6LhrrGaTUcm3GJegh255d8a0d8Kh63 tatw== 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=Yt4n7TrebHBHw1pv+f/VYH1/nL9tMmkgabnkwlM1MoM=; b=rervy7bZXemf7arcz9qZRnEYt5+eU6Y+4e/kImNnUIIxzsNDyfNP0COQuoDC/YgTTe bk6OeWKQDPBOIgFNOr7oIeeVTxu1w87oDWXZc/Xz9IDuOSFoJJ9w45EtVoBRgWyeGoAu htzOuuduJYCGgLF5VD40JgCDo1Nz7h+29egK7Ar1zR+YfKlvTzdo2iZbkHoAWRPXOjSP MOo/Oy2HVscdD3VKirUqfJ48J78gowcwmQsBJC0F10qsartG7/R7I8IXYzE1y7AXgGWK V8G4X5biDlQksPwg7Rb+Cef8DhFNpU8a0B4apBxI4fgMkzE/jEej0r/ifkpt4iTuLA0S TqWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lkvfRnCR; 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 b19-20020a17090aa59300b0022711011581si5544628pjq.175.2023.02.02.14.36.11; Thu, 02 Feb 2023 14:36:28 -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=lkvfRnCR; 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 S232736AbjBBWeY (ORCPT + 99 others); Thu, 2 Feb 2023 17:34:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232509AbjBBWeT (ORCPT ); Thu, 2 Feb 2023 17:34:19 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E7786A32A for ; Thu, 2 Feb 2023 14:34:18 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id f15-20020a62380f000000b0058db55a8d7aso1633006pfa.21 for ; Thu, 02 Feb 2023 14:34:18 -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=Yt4n7TrebHBHw1pv+f/VYH1/nL9tMmkgabnkwlM1MoM=; b=lkvfRnCR9L4p48JCZwFZKWUKHGN61Q3m0t7AYSHtCynD8fd/3R0LutY7M8PjtUNTAF 75GpSew/2QQYyvsc6dNLfGFaHsNxWUjTbvbWHaFPATihKYBfAoSzg9TsANL2ayno0iFW DQ31W/I3W0ZEpyBr6VhnMbXBU2b44i0YGfsCzylRXeCADASPJJxwtrSsFKLhGEhwLPLP RvHmLd3iUMU5hPOfHF9wp3JwzOML0GCzI9DJkY1X4gTtAX40FiJnjMD/UeQKBD6NMPkA 99baXrHXLS6CEfsAYP7QHJs8HVLMWw7JxF3ekZQE0Rs96QAt2qP570o51O3gKemcHTj+ FPhA== 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=Yt4n7TrebHBHw1pv+f/VYH1/nL9tMmkgabnkwlM1MoM=; b=3Pt3rSGf3pggcUaUG9dJLUdXD5IMxGaTljuKdCauxBOBPX72QwlCJ5Sbr51vQC78K1 V9gU46BIU/tUF0g/H9gPWykDnDPz+FI4Qlze3MZaTvDS7E7SfBCDXQYEMZUA+QKgP/w3 2JE4rtKkmmYlxKM7uSIY2d8yosZWJ+qnH8jkAd+SzR0yHZW/AOysF8VAw+3G2rbnhtAC a3c0V0otDncHiqPRBJ8PHgYPOP5obgE5SWbZB3gfQwX7kBAVufu4Xxk0JcsXPM+B9cFY 9oKwP3L6Pz+fSK91Xxog0TdC74mUfx0Y/rmYGV8f3PIB2NydQtAQqXpXUqMWCtWff8Dt qfXw== X-Gm-Message-State: AO0yUKXe4Qf1mxaF/oH+4u0ZGuzku9/RHJfph5a7+vaHHpbAXzE+c7Bm yFgUNkzt2m6KM48q9qiqTMManmTZpeEnNozKE9C++4s28UDuuuvwQBqCqHzj0trNW7/P9kEm8vl LGsBZN5G3SfsJ+ZwL3RTIlV1ZLE1U27LMh4YLCoJ16yQZkdb97IwYZgcw7sMyY/IyjTQkSKQ= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:aa7:84c5:0:b0:593:37d6:dcb8 with SMTP id x5-20020aa784c5000000b0059337d6dcb8mr1853562pfn.30.1675377257642; Thu, 02 Feb 2023 14:34:17 -0800 (PST) Date: Thu, 2 Feb 2023 22:34:09 +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-4-jstultz@google.com> Subject: [RFC][PATCH 4/4] locktorture: With nested locks, occasionally skip main lock 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?1756760520901966532?= X-GMAIL-MSGID: =?utf-8?q?1756760520901966532?= If we're using nested locking to stress things, occasionally skip taking the main lock, so that we can get some different contention patterns between the writers (to hopefully get two disjoint blocked trees) This patch was inspired by earlier work by Connor O'Brien. 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 | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index 5fb17a5057b5..6f56dcb8a496 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c @@ -745,6 +745,7 @@ static int lock_torture_writer(void *arg) int tid = lwsp - cxt.lwsa; DEFINE_TORTURE_RANDOM(rand); u32 lockset_mask; + bool skip_main_lock; VERBOSE_TOROUT_STRING("lock_torture_writer task started"); set_user_nice(current, MAX_NICE); @@ -754,21 +755,28 @@ static int lock_torture_writer(void *arg) schedule_timeout_uninterruptible(1); lockset_mask = torture_random(&rand); + skip_main_lock = nlocks && !(torture_random(&rand) % 100); + cxt.cur_ops->task_boost(&rand); if (cxt.cur_ops->nested_lock) cxt.cur_ops->nested_lock(tid, lockset_mask); - cxt.cur_ops->writelock(tid); - if (WARN_ON_ONCE(lock_is_write_held)) - lwsp->n_lock_fail++; - lock_is_write_held = true; - if (WARN_ON_ONCE(atomic_read(&lock_is_read_held))) - lwsp->n_lock_fail++; /* rare, but... */ - lwsp->n_lock_acquired++; + if (!skip_main_lock) { + cxt.cur_ops->writelock(tid); + if (WARN_ON_ONCE(lock_is_write_held)) + lwsp->n_lock_fail++; + lock_is_write_held = true; + if (WARN_ON_ONCE(atomic_read(&lock_is_read_held))) + lwsp->n_lock_fail++; /* rare, but... */ + + lwsp->n_lock_acquired++; + } cxt.cur_ops->write_delay(&rand); - lock_is_write_held = false; - WRITE_ONCE(last_lock_release, jiffies); - cxt.cur_ops->writeunlock(tid); + if (!skip_main_lock) { + lock_is_write_held = false; + WRITE_ONCE(last_lock_release, jiffies); + cxt.cur_ops->writeunlock(tid); + } if (cxt.cur_ops->nested_unlock) cxt.cur_ops->nested_unlock(tid, lockset_mask);