From patchwork Fri Feb 3 20:01:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 52629 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1035434wrn; Fri, 3 Feb 2023 12:07:26 -0800 (PST) X-Google-Smtp-Source: AK7set//Qdslo+9KRLV5xouFbZiv7/qJ3yqtJCkXcs4wdvO4zJEPVdryE7msgUP2q22MRKfgC3EE X-Received: by 2002:aa7:db4e:0:b0:47e:eaae:9a69 with SMTP id n14-20020aa7db4e000000b0047eeaae9a69mr11561175edt.41.1675454846023; Fri, 03 Feb 2023 12:07:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675454846; cv=none; d=google.com; s=arc-20160816; b=a4owG+gPs/70UwLW0QM4m6R7uB6ePddgOpxIPtGPEibiSBJJ9AN05xRueBishmnvJa K82Qt3ejYQsRg2yo3DSf2hjmRGHKPU41U1odDqaaGRvN3gEvsuMSOA/DgcSe1j2T788k +nJKYJMtYlTcLgmF+8SJVougduhgV0UbKQSTxf8WdnZBM/ki0pDy4ssvedwlAWu9ypit rtBafq8eR075kmET90cauEkKe41u54Z30yJ4yX/s0ZLTDnzFBGMPkVBVu0IXRK4CQKdG eLXXsa7DqNhuD9CPdSDq9v3rx2RNSEJPUrzillc/13F1Au9uC5gSU8kWV1KdaJxnrWGj Yz8A== 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=YN5Jpu9PRwHsBzEdMZpplQm4v2Rz3ustyK/yj1wYqwhVzxCdixZnxdv1YqwBa3epEo S8bkmPd3QmkXxuNTh1W/wtirftvUKwhD1iNkEV4W8580vCNwzHG5u28AxX344NVfJxpb tl3fiZQNSVWKQ2vYnjc3budbF6mUrP2Nav6v4yolUeoIM81ygew3HaBXpqtsPI9cWwGR XcJxanGiWjGgGbXCrsvkfD0jZNMeimWFKmt3qYDwKlQREG1T4RORTeH9t4BxCCsMAvSu Kp4Ds4jSRyTOrn4l8eMDXF15wp9XRK35YrjfP7d58FdZ97kPy5EMnFvGVhKxtOnrCdb3 XPvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="KPkJ1C/q"; 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 i4-20020a50fc04000000b004a22d78a971si3382668edr.215.2023.02.03.12.06.48; Fri, 03 Feb 2023 12:07:26 -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="KPkJ1C/q"; 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 S233425AbjBCUBp (ORCPT + 99 others); Fri, 3 Feb 2023 15:01:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbjBCUBn (ORCPT ); Fri, 3 Feb 2023 15:01:43 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35D2DA6C07 for ; Fri, 3 Feb 2023 12:01:42 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id z7-20020aa79587000000b00593f19705d5so3207440pfj.10 for ; Fri, 03 Feb 2023 12:01:42 -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=KPkJ1C/qL+FzGJYKo7gZ9K8p9Rgy19fakC/0EXy5pbZ9pd7P+QiTu0iD0dhI9UbSJE ug9LrnGhUIFtdtwIQyckSPbuQQe3jbw9Oy21pU+za+tjCpzjDq73hVOchBdcN8PCAmAl 0NnMek0tb/OU0RvhfHWeFcOJFawcLGLO6fO5Rfq87athdWEN4bAChRYsL/ETwxqRQGyd IE7CYS156co+zXWT9O+hzT1mhN2LlMFYOVuwTia/t5apG1VfKGhqHH7RPEs3uhotz9ry x1RHZAI3i6wb4BpMmyDiepFohU0aMUssXeL10kjpkWU9e2cXoF49WhvcmpysMm1/+eK+ kR1A== 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=4fl4VMtzNvkDShE82fMYsgtH7hnp/7katEPTc+cVqft8htTMEYbnrPEYda289l8fVp UvdhgO62OpWtLmOU+k9Lxiy3GU3MzQt4MVf9rAE2Tbw9nym4JJkRWeyx3pZQm1NDgyfP AnHjKHP2ITrv4NCEYXe6sFgDoPYzKHYCdUSHyiyrYUA3mUCgXdFwprSdWTZqrC/AHBbQ y4FmkoOIQBlvSeyQKevGSrGOa3D3xEcMhaWWoAM7mWlD3Ib7K/uqfSt8k9y9T83satfJ opXNOpWxBmT2G49yrWu15cbfNOrpIsi56YlDYeg7z/r/AUlCTd52ST41g8OZbNzPPg9q BIIQ== X-Gm-Message-State: AO0yUKUUWmh+ewpumVop5yAkx/tD06xzKvIdR37GMjsxeccEpVjZ3UEO hX3yCFemvAWO1sES89SRrS9r79x3oSZKohrF25nNF4sJUa3r2q3MxnBxWJhbNj9VYKi2ooHgbXh s56RWxHgHAp6+1O1QsNeC8kw1qQ8sRG6AcoH4bp6FwIOXJYIP7naweau1kcrNP64AfjQdat0= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a17:902:8649:b0:194:706a:ad18 with SMTP id y9-20020a170902864900b00194706aad18mr2662260plt.18.1675454501477; Fri, 03 Feb 2023 12:01:41 -0800 (PST) Date: Fri, 3 Feb 2023 20:01:35 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog Message-ID: <20230203200138.3872873-1-jstultz@google.com> Subject: [PATCH v2 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?1756841740703601986?= X-GMAIL-MSGID: =?utf-8?q?1756841740703601986?= 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 Reviewed-by: Davidlohr Bueso --- 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 Fri Feb 3 20:01:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 52630 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1035848wrn; Fri, 3 Feb 2023 12:08:21 -0800 (PST) X-Google-Smtp-Source: AK7set8iH5KMcdKcpaVvwkIMIoPZErAWlzqp2qeesAJTQO+2gPlAipVAJdGV+ihCJ5R5dC4YSxzw X-Received: by 2002:a50:c30f:0:b0:4aa:7c46:8f69 with SMTP id a15-20020a50c30f000000b004aa7c468f69mr399958edb.37.1675454901267; Fri, 03 Feb 2023 12:08:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675454901; cv=none; d=google.com; s=arc-20160816; b=ZGeazzrilKbIhFNOHXV3Rn11BNpZ63u/YgCCG0F9/s5wJ1XR/2SEFL6NsqHAvPlztv hzany+ghhxn/vAUSWcb2nFlhijsQUq3bvvhAhPTpbWYQHOcL8jPTMRSVHVh0gzRyKd0l tFmrjniiLMk1MT+E42Hi65ooX3nF2zvmKrmnfyetYIYaTQOauHMxDIjA+Bx5o2dzx2e8 xlJwKDsZsx4ByWEQVAjeD26P3NRlLhoZzmESiw6zVh7guVZc2zqbyR7MTINz8hSkJPEo AQapNSbHarPY0z2epqCUDppUMAl/jqPVX6m7oFEZiq5zfig6Ep2twFisgMFO8MtLsN8M H+tw== 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=SS9njUMJOmQ8htY8Ip0UFz+DAaIXbVEtUJNiEBJ9FB0=; b=mWQcQ0uu7HDGaozFoHelx9DS8Odw6jL0SnfFYcf1DGMfuCi3/AsyZvv8W156tOz3vh LaYC/kUB3D67g6azW3eYN7EASI15RQLmhZS6nXrRTteEyP8hdi8n8FL5w4VwPO81/FoW FE/oGjAh9wDwfQPNQopC5RMONosMoam/rV98nAQebCXp7l7BV+iDsX5CIdOZYMkUdq9t 0IgYwi6AfOf+jldg1coDbhWcqe982AgdzzC39izgXz1CxRioYWF4Ig4PkCjY89GhvWM/ MKcm6WPWaItfhECS5je3wV9U0VfytkI88NAZJWAVjEaWC8pASV9BuN3cQnLbVbj6m/Co /ITw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Nl/hIjpe"; 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 v7-20020aa7d807000000b004a08f96879asi3462390edq.451.2023.02.03.12.07.42; Fri, 03 Feb 2023 12:08:21 -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="Nl/hIjpe"; 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 S233501AbjBCUBs (ORCPT + 99 others); Fri, 3 Feb 2023 15:01:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233385AbjBCUBo (ORCPT ); Fri, 3 Feb 2023 15:01:44 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D08C8A6C07 for ; Fri, 3 Feb 2023 12:01:43 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id h4-20020a17090aa88400b0022c8dfc9db4so2878946pjq.2 for ; Fri, 03 Feb 2023 12:01:43 -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=SS9njUMJOmQ8htY8Ip0UFz+DAaIXbVEtUJNiEBJ9FB0=; b=Nl/hIjpeflwlcE1OUDo5VXhIMnYa6u/CpDe5qKpM2CVsBi1quwv/ehJSNvcbnG0kZ8 B0LJ6KVotUDFFkJ0iryEulNtLCCWy6vUkcLdoQvEGnpxiTKlUVg0ff+hJ532Jh3oP/nE uietnXlvtWom6jlLHduXukJP29lJVtWo0hNiyRUkiHGFPZmuT8kCCzKe92nY85BorkkO qO98V4oIUk9XE5lWAsSDFOtmC9iUCyHh9sS8PFHN0hbnkQ3CkUulSo31y1SjjxKt5RIa 5ZNnpO4WfEYvd+VtdSke2CGVycW8xjxcUNJo2ERuY9/QnColbgCCioOb3kK1yAkssmuQ d4cA== 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=SS9njUMJOmQ8htY8Ip0UFz+DAaIXbVEtUJNiEBJ9FB0=; b=RleH55MikkbBOIfLGHgooa1w+0JV+/p9Cx+5Ef4xi0G5GLO7XW/6mWCfWYa/jvwofL X4wuh36By5cyKxbWm9HA4VoH4J2gzLoFAiA2m20IGyYeqpA+RWekNf8xvCLS92ProAkZ d4xe3u0IjYpQoadOGIyus1yr1ce+yJGMyeUMdCSneBVs+cPW2ZPn2aidAbO8M96DECQE uZf4ubzDp9kyCv3VVVJC8Zq57Q4KqIIKWL47H+IkPAf/H0MxQNFoeJTlR+kCvTgG/DlP z1pT9uvouBD1LEph3SXmJiOE0lBPizPkxl+V9/+mSAWCX22QTsljQWuiWfQconwzVmE6 mLwQ== X-Gm-Message-State: AO0yUKUdsfJTbWOQaUBa5mZK/j1rOtjuJvJUK3288Tc1LdKKTLt7m1L7 8uTqYWCf241Hc0Zrrae6vv+NgfP1LVoOpivWvILoyaRttNVU7uKcuuR9WKbw0eGprpeNez2q5/b aVUv0WSxo6dpXbNw5VywHKVWfrdbxfoqgpf35VJRX6Aj8hDdGa7dUIPdRdIZmI0/GZgSA82I= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a05:6a00:4208:b0:58e:2111:9c42 with SMTP id cd8-20020a056a00420800b0058e21119c42mr2692517pfb.22.1675454503197; Fri, 03 Feb 2023 12:01:43 -0800 (PST) Date: Fri, 3 Feb 2023 20:01:36 +0000 In-Reply-To: <20230203200138.3872873-1-jstultz@google.com> Mime-Version: 1.0 References: <20230203200138.3872873-1-jstultz@google.com> X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog Message-ID: <20230203200138.3872873-2-jstultz@google.com> Subject: [PATCH v2 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?1756841799006507950?= X-GMAIL-MSGID: =?utf-8?q?1756841799006507950?= This patch adds randomized nested locking to the mutex torture tests, as well as new LOCK08 config files for testing mutexes with nested locking 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 Reviewed-by: Davidlohr Bueso --- v2: * Add LOCK08 config file suggested by Paul McKenney --- kernel/locking/locktorture.c | 35 +++++++++++++++++++ .../selftests/rcutorture/configs/lock/CFLIST | 1 + .../selftests/rcutorture/configs/lock/LOCK08 | 6 ++++ .../rcutorture/configs/lock/LOCK08.boot | 1 + 4 files changed, 43 insertions(+) create mode 100644 tools/testing/selftests/rcutorture/configs/lock/LOCK08 create mode 100644 tools/testing/selftests/rcutorture/configs/lock/LOCK08.boot 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, diff --git a/tools/testing/selftests/rcutorture/configs/lock/CFLIST b/tools/testing/selftests/rcutorture/configs/lock/CFLIST index 41bae5824339..a48bba0d35a6 100644 --- a/tools/testing/selftests/rcutorture/configs/lock/CFLIST +++ b/tools/testing/selftests/rcutorture/configs/lock/CFLIST @@ -5,3 +5,4 @@ LOCK04 LOCK05 LOCK06 LOCK07 +LOCK08 diff --git a/tools/testing/selftests/rcutorture/configs/lock/LOCK08 b/tools/testing/selftests/rcutorture/configs/lock/LOCK08 new file mode 100644 index 000000000000..1d1da1477fc3 --- /dev/null +++ b/tools/testing/selftests/rcutorture/configs/lock/LOCK08 @@ -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/LOCK08.boot b/tools/testing/selftests/rcutorture/configs/lock/LOCK08.boot new file mode 100644 index 000000000000..e59a369b470e --- /dev/null +++ b/tools/testing/selftests/rcutorture/configs/lock/LOCK08.boot @@ -0,0 +1 @@ +locktorture.torture_type=mutex_lock locktorture.nlocks=8 From patchwork Fri Feb 3 20:01:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 52631 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1036508wrn; Fri, 3 Feb 2023 12:09:49 -0800 (PST) X-Google-Smtp-Source: AK7set//wtqTj4l+3jHPucT9n45z02wbwv/teDNkYPfQC/Ml6Pn5vWbKae5gvDQt/u4I4G7jbdXE X-Received: by 2002:a17:906:4b16:b0:88d:72c0:611 with SMTP id y22-20020a1709064b1600b0088d72c00611mr12276403eju.3.1675454989002; Fri, 03 Feb 2023 12:09:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675454988; cv=none; d=google.com; s=arc-20160816; b=OWzBFejmPFbPru/Y+3ZV9FMfSYeaNOZ8i1l2fErCmKrv1+5SD9yUNQzFxZW6Jf+GFZ Fl8VQf8ZrTsmPdMFYvZy54+1rDik+fdxJHaEWVt2e/QrZPsR/OfGdlFpXNnfOvnPnbEH tIn25jGMUcVojv/Myood8BRSINNic/nE4GA3M7YcJDYp5jjO5zfxuvV5FHc8gN+vMmUX S8Z3gXn59OhFWsKFszmwiE8pIqN+Y68Kl14wpv5YrZzahtmuJLjqCL3uvLWxa2BxdwBC hPy9DjzwJOBpgNgD6LmQSCACauKdx/uZoKm0qaRcKjBGTZVxLchN7ksr7yTHK8x0eH+s 014A== 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=C8PT34t2qDr/GJI8LrC6wOUFBvKY3Hp95WNgfanV6IM=; b=VpISOQ/tbCYYCBXotTv5oIVZDCm9y60JnxiGQ4ObrRv1f02fyQNjv384EJLsBnk7co JQ5hB/WdZ1jMycDnGKrh7iYHQc2KWSzfOj4pkMrg6GomoyrJlp2IsRSEV1Xtwg/4y192 l9/znfDVKNpPvoACWLEsEhqc5NUfxm69Jt4lRlHZF2t8uX5nIsmhFUSSb4VrBhJMc9XO GqHiTW44L2y/elKnGAnSh4lIHW7ON+J0k+QqO1OjpdgQalq63Re5QyW2UuAtjPcflrCd uZo005ntOwgGwN0nmVJ1QykLa7rXza51tVAZRkIE15W6Eq3I7OygPPUfsu1V7qXJna7b bkRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="r8ITG/RT"; 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 gj36-20020a170907742400b0088ee29d660csi3475567ejc.21.2023.02.03.12.09.24; Fri, 03 Feb 2023 12:09:48 -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="r8ITG/RT"; 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 S233719AbjBCUBv (ORCPT + 99 others); Fri, 3 Feb 2023 15:01:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233185AbjBCUBq (ORCPT ); Fri, 3 Feb 2023 15:01:46 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB682A77A4 for ; Fri, 3 Feb 2023 12:01:45 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id b18-20020a253412000000b0085747dc8317so5758333yba.15 for ; Fri, 03 Feb 2023 12:01:45 -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=C8PT34t2qDr/GJI8LrC6wOUFBvKY3Hp95WNgfanV6IM=; b=r8ITG/RTClzhaLsg3hhm7dmQgWr73lKexW4jM1UsgvmEn8c2l5RzJjOfHXv6tjakn2 TyaOggZEXSK5y7OvuQlIfPtBI+Y/NnMNQApJjOrnauNZb0hFNwwALksnw09C6QQMV8l3 3TKDWrCj/La7Fx4mDg6hWF7PWv5c/AfQSA0OX8mFxYyektarfysYI7irdbHZuQHRC613 qPl3NH5KhmGgXihVgYaVgYri5OtxbH35IgCeiLAlCH5P9Y3M95C+B1AbO9yHFQd6cPZ5 m6VpdxWu0kOuyOHdnwbxIbXRi06tuASqKc+4/hpDP/Nrra5ZLHvvgK/Uq8Hgq//jjJs1 TF7A== 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=C8PT34t2qDr/GJI8LrC6wOUFBvKY3Hp95WNgfanV6IM=; b=OAbfqkGHe8h9aKuR2g7Ik/86M2k+hJV1hNUJdW8saZgOrYLULoi06MyaZSewEKQQxe //JclT01iyf9EJmr3lE3gDf4HzYHKZ0e7ADmOyqZex8pVVWSxN7V+xkNH1emfKPFC1zj HmfgC1+r7hHKt8pEa62EceTQBbowaw0UiSMvXiaUIsGhqIzszc3+49pWqSHEeID2KFoF e9nl+lICz5iusZRm9GPKF+XR49ngEkNJFtnt7wd//Jt3sEPHOCAU8Zzuvwm4GzxcJ9+5 P57nSZShscPUz3HJmvrOt5afgTnJqiOnyEgVSP+QkGP4iK2sYP64gce+IxhukJJJxx9Q oRbQ== X-Gm-Message-State: AO0yUKUevaIbwF4F7UJ5XE29CYQ+y49wkqQ/3HvQM62ydoTamsyodgzv eXgKbL9Ef/pEEjMd6RFKhvI5HuR7jTkIykMb9DGvZllxsOl/YXzDb8OyZXzxu9881NTQkYGJ9AA 0I1aU1lM1jPItkMmFE81oesUHUgjJdXnUl4uVGgixAZxuuvGIAPAj02+tiHWNI0Pny981p0Y= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a81:4955:0:b0:4fe:a39e:395b with SMTP id w82-20020a814955000000b004fea39e395bmr1365791ywa.408.1675454504895; Fri, 03 Feb 2023 12:01:44 -0800 (PST) Date: Fri, 3 Feb 2023 20:01:37 +0000 In-Reply-To: <20230203200138.3872873-1-jstultz@google.com> Mime-Version: 1.0 References: <20230203200138.3872873-1-jstultz@google.com> X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog Message-ID: <20230203200138.3872873-3-jstultz@google.com> Subject: [PATCH v2 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?1756841890850242674?= X-GMAIL-MSGID: =?utf-8?q?1756841890850242674?= This patch adds randomized nested locking to the rtmutex torture tests. Additionally it adds LOCK09 config files for testing rtmutexes with nested locking. 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 Reviewed-by: Davidlohr Bueso Reviewed-by: Davidlohr Bueso --- v2: * Add LOCK08 config file suggested by Paul McKenney --- 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 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, 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..6c413e3e1bdf --- /dev/null +++ b/tools/testing/selftests/rcutorture/configs/lock/LOCK09.boot @@ -0,0 +1 @@ +locktorture.torture_type=rtmutex_lock locktorture.nlocks=8 From patchwork Fri Feb 3 20:01:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 52632 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1037550wrn; Fri, 3 Feb 2023 12:12:10 -0800 (PST) X-Google-Smtp-Source: AK7set95tN+CLhq1ikTBLbbP5CgnhOUDfJK+veo0pQrY64X/g+RIHK44EuIij9jv9u5SJlPxbEKD X-Received: by 2002:a17:907:20fb:b0:87b:d409:f087 with SMTP id rh27-20020a17090720fb00b0087bd409f087mr10773978ejb.21.1675455130701; Fri, 03 Feb 2023 12:12:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675455130; cv=none; d=google.com; s=arc-20160816; b=Qw8f+Djyqi7uIrHuG7vhEnGNG/sb0AtXBI7Mj7R04GBIhFXJpwf+d+l2NZzP9caToF 3UI1pi8wvzcjWg+EXa7cvZZOIMEfFRdSrOxEo9KYr30TQ58SSgox+kMiFaDB5EdslJcn oyJyaGvleRyuIy4TVuuBPY4F6B4iMFuD3WotQ8+Tm65LP9mcCzErabeARfHaVtTbUIRi /bxAdn6fu+Slo+bPZbtgFEmvYiiQgPrw9k3XWoVisFsAHieeBQIh2ngONjIfuB8z0/kG ihxB57oEW9nCnpN798uHKohmXKuo1h/SNDiWrv4CfwUkSyY9XZPjwuet7Rid1N+KPU1Q +LCA== 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=ne5vhldLxHb8UPoF94yCaaVv10NMrydEnVaHrikuJDrnAagcc1Bsusi67KBnfA+opi XMHL5N+Qyl2dNt3m8P/csfhWWob4u+lX77fMoQiYDowOdj47XzgYJR/5Oskt+laIBKVl jFs2BLwSg2+FotPQQFlAJ38MZQPNmGXPP180Sxrmwnz6Er2bmj5KzDPEmz+Qo+5bLduv t5iIG41nDInDGpQNZZDWmcgjhpQKofdIrYYOnHRF5FDdGUikbDTJAXdcienyiv+K09Hl 1P6zHz1eEKXJuP2u4rhhKJXLes31F1WoSs6cX08hdaw5joSgrdoBo5o4p1e3U3fX500d afdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=fMPtyxtz; 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 fn18-20020a1709069d1200b008716321a08fsi3591538ejc.708.2023.02.03.12.11.46; Fri, 03 Feb 2023 12:12:10 -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=fMPtyxtz; 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 S233742AbjBCUBy (ORCPT + 99 others); Fri, 3 Feb 2023 15:01:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233602AbjBCUBs (ORCPT ); Fri, 3 Feb 2023 15:01:48 -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 48905A77B6 for ; Fri, 3 Feb 2023 12:01:47 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id z9-20020a25ba49000000b007d4416e3667so5825211ybj.23 for ; Fri, 03 Feb 2023 12:01:47 -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=fMPtyxtz/sSfFNjjRD5ySCffBSUU6QiDEXza5AgFvN0rIoBvkIEdIDVZ+Xg52loddj lmMO5IYa+Oj57RacBvop4iZOd1IaD75y1qPByi/w9bsZ/zdHZfGsGOZ9Qrte0R90aW+z +XDTYLDbRZkAkDV1zjwqCtzB1z9C0pXgKRSDx0ZzdChO4+QTiY/3Zk/wxQYSWkel5ETr HhybkR8UnNvraSI+P09YhdH/r5YZoE/uKJUDE20GAz/+zYnbOQxeicxIjZszOfyRTch/ P1OxVUgyQb9PbHSjm4Wk39pJeD8LeKD/bNiNep+wU+Kv1258edtOfpPLhloihRh697N7 KaoA== 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=tj9mWDNAc81vCRY6FoxQyA0KRHJNqNhYHQv8+G8ysqaFHJCTrgVZHVuuC3uz18vT5n buocjgdlhLzmLfT6uFkC/O4yDDzXOFigjKgEI/AP8o9P/kEJAlcEE58ry+LhjYJVDbc6 CLtSxC64hfxG3gstwG0w26yr81Ae2mSRG6AxQzC2skefKNkdzbPakm8bFAsD+qa7oV/+ Poysw3cAeXMdCjTkajhi+qNKZ8pXKHzvT2frj4ijLL2onHvXKmWwO9I6xDRD/krm9jU2 Dp12NjAursGtAldDuv54OYfgT8iroqGqFCCPfWFFfPVrjc3HPBe7RNMjFhFG8vDi4NwZ 79qg== X-Gm-Message-State: AO0yUKWnipBsVCNGeUkTFOsmlsVelfM79CR6Yu/NB4dAqzpIneMHb76h v2N6KLOkeUdev5w87YXpDqRabqjxq0j/edzfmLckbMCOpT/7W6Ngk/rgH4boF03jZphLNQazvdI 8bw7Kw2gGzol8iGnuOq/vHsvjz5XxZvg5yXtHSolm2nA3iB0dtvmqup+UtxbLFSnkmRRcpm8= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a05:6902:4c8:b0:87c:45a2:8656 with SMTP id v8-20020a05690204c800b0087c45a28656mr52620ybs.86.1675454506493; Fri, 03 Feb 2023 12:01:46 -0800 (PST) Date: Fri, 3 Feb 2023 20:01:38 +0000 In-Reply-To: <20230203200138.3872873-1-jstultz@google.com> Mime-Version: 1.0 References: <20230203200138.3872873-1-jstultz@google.com> X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog Message-ID: <20230203200138.3872873-4-jstultz@google.com> Subject: [PATCH v2 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?1756842039303374307?= X-GMAIL-MSGID: =?utf-8?q?1756842039303374307?= 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);