From patchwork Mon Feb 6 21:05:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 53509 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2462571wrn; Mon, 6 Feb 2023 13:09:18 -0800 (PST) X-Google-Smtp-Source: AK7set9Xi5+gupEpV10oAHUt1bBLXD+T2wVWEYn+DxPbeobUv4W7h8XYUonE5QL4WeiNb6hJpDRn X-Received: by 2002:a05:6a20:b1a6:b0:bf:58d1:ce8f with SMTP id ee38-20020a056a20b1a600b000bf58d1ce8fmr10783079pzb.14.1675717758561; Mon, 06 Feb 2023 13:09:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675717758; cv=none; d=google.com; s=arc-20160816; b=x/ye3Cxtzph/XKhqqEyDYUkHdHSgRrk3fbocAHEQ1/Q0PEmE2ph6XwiasML9LaHQ46 YxNfppoSsE0RpP1coLPojBvk8CUSU0ahE645DxBiGlB43IqNTqT2LQKIsaabPV2pSiF6 zB5kUTA8jJHFwvjUd3/69lRdZ8S+p2cywqn1uLPuAUX9RLEuuWL6W7Stzki/ij3LOUIr 726uTwor0DbtCBj5ni3z1Q4z48F3ZVlGpoBYvOOmzQjCE1Ty7VOwo4wL7PvMWgGiKXbX razP6CS8GnGt+cN1ECd5FFpyVyvFzpNKV6gx1Ue1gXelvlsEX57Hpq636g79Ful2iww7 YP9A== 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=r4JnahttLljJJlPAPN3loqxjqxcv9cWRfojdRp8HWw8=; b=koolX7FDW5BSOwtxTwVqcL+rJGIzYltNsKgy4bD0I/WDAq2WQBc/89koUHH6txeHbi tZ7pabxC0SNRCZYD/mLmxlVTh8k0kNREk/0W7aho6fwf/qQnuAFEn3xklJvkYLiY0ihn WeU2bvwM0YH5uBMzrOZ50UMrK1UWwCUpilFTN6rLQRGfg8rZjU1EJy2JuP+IbsmJbLp5 EVs5MpW9NkdHUtA0aW+AIQhO2GUpqPc4rcEDAwgNMLHHxmPhgjDy/SswBPnbyBvaoNF3 5S1rUJJe/LNsW7joyDR4jM5lv/NHRUan3DXT4X9ccyAWmFESq8u28meBgOu/wBVnBO3U bxFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HzxXLThh; 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 s14-20020a17090a880e00b0022c890c2d4asi16217518pjn.179.2023.02.06.13.09.05; Mon, 06 Feb 2023 13:09: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=HzxXLThh; 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 S229571AbjBFVGK (ORCPT + 99 others); Mon, 6 Feb 2023 16:06:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbjBFVGJ (ORCPT ); Mon, 6 Feb 2023 16:06:09 -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 A0EF06E83 for ; Mon, 6 Feb 2023 13:06:07 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id z7-20020aa79587000000b00593f19705d5so7049965pfj.10 for ; Mon, 06 Feb 2023 13:06:07 -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=r4JnahttLljJJlPAPN3loqxjqxcv9cWRfojdRp8HWw8=; b=HzxXLThhUtwk2vaY+Xxj4TK/5HUQjNE6rzyLCh2JeTeGA9uAqXNQh95UvZWkhGFWv2 Lbvo51XgSqQnkIkxOaWDx0T5HEyxTfChGwa2H70A6XEsgiri9RysXUvdvis0MHCteMfd gTn7X3GdNFkbRdOpsZ/h142lZt6cdRnmSBtz8q83adXlP/DSQBqYNW4FOJQMzarSP5cI gWc124qhi3sg5GO+m4HaARbZko3ehJcNU/cKWuSiU6aN+GPOcjLQTSvifBeF9q1+4Uan ZP1W7bgtnCz9joJnjPkIv1LVODbIa/D3qs84k0a8Ev0UB3NMRyfhhWqmrz0VmiGKgYfb XWZQ== 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=r4JnahttLljJJlPAPN3loqxjqxcv9cWRfojdRp8HWw8=; b=4ZZV0qa3TCUMyHJhcoImiyIYT48bEF3+XFAPfrUap86H5cflro1G3hsmRogKeWMInJ AQemGmg7XWHhe/02/wmDcu5AApgyf67Xj+k0rHlyY7hZG3ADvydb58WFkCjqIr4D5Bsc pW45S+z0GF0zu6mpXTjIb/97TzCBO/CQ8llIF5J8HFFssm4ih3UL+6AESoRJ+XXULRfE B09an2+F9YLs4/Tj/cR+dOJCjGgiUQ/zLAcZsGjC/UL56zKiaqVFXs1wKFnUk0eY+w0f Hnyv9QCPcFifzXwEZy8edxETnr1/AP7HkSV2+znSAVHna6DYn84Hwy7y6YvHb5IBOWpX VPxg== X-Gm-Message-State: AO0yUKXMaFdzxNcdB2MokvvMnZIOWvgfc0iVVwE1aWQWHVzUEbf2VTYn MjZXJamS1XOmGAD0q2vVtJOS+87GpyV/MpYrHw24x0TYnrxsS9CfIRGkP30ixHWf/v+a17/NEJa me9/AIz2AOEfdNflXC3l8zFJtsSNTF9jp4jg8CozjTu0LXB19Je+xD6gL3osUX5zfvkW5F6M= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a17:90a:29c3:b0:228:d64f:ddbe with SMTP id h61-20020a17090a29c300b00228d64fddbemr279824pjd.40.1675717566433; Mon, 06 Feb 2023 13:06:06 -0800 (PST) Date: Mon, 6 Feb 2023 21:05:53 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog Message-ID: <20230206210556.660318-1-jstultz@google.com> Subject: [PATCH v3 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?1757117424478827079?= In order to 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 nested_locks 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/ 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 --- v3: * Minor commit message tweaks and naming changes suggested 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..6fe046594868 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, nested_locks, 0, "Number of nested locks (max = 8)"); +/* Going much higher trips "BUG: MAX_LOCKDEP_CHAIN_HLOCKS too low!" errors */ +#define MAX_NESTED_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 nested_locks=%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, + nested_locks, 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 nested_locks to MAX_NESTED_LOCKS */ + if (nested_locks > MAX_NESTED_LOCKS) + nested_locks = MAX_NESTED_LOCKS; + if (cxt.cur_ops->readlock) { reader_tasks = kcalloc(cxt.nrealreaders_stress, sizeof(reader_tasks[0]), From patchwork Mon Feb 6 21:05:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 53510 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2462609wrn; Mon, 6 Feb 2023 13:09:22 -0800 (PST) X-Google-Smtp-Source: AK7set9WKVn8Y8I1+6h8tGhfFElO9kLOeFo/oQ1bknkuN4CuzXtNWLF5o4LLD83JL215BiWarIWu X-Received: by 2002:a17:903:2288:b0:196:548f:dfc with SMTP id b8-20020a170903228800b00196548f0dfcmr327360plh.27.1675717761878; Mon, 06 Feb 2023 13:09:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675717761; cv=none; d=google.com; s=arc-20160816; b=d3x3dUVdGnnrifdxLNFRYba/JZ9i3OqocPsENEf0M2KGcP3FlrcXIvnk+roZJJ/dfJ y9ErDyOkhyJ/pTiAivKPqgXMPq5YyJMsIJXfjw7AmJGY4okDbLpxHxRuXM7427dHEItr 34aret8jYeUujYrawK6pXM1AoxkKvFz39fZovdalzX1H9ETAv1ZBiULVRU93PSlTvrn9 lS5YiaeShXN5e6oHvCh4OMDjBYOotWX0Ha7JXfsdQrgEqQQlDMSpNWaYKPLyNX9Xjbg+ +k0pCfqk6lel5JHHzNaCL4Ssj4zD91pdco9k+18y2oDK6moGuSFm8mFMPRWyDhnwnQkw ZiHg== 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=Cjg1wQcr6HPBZFA4eCrjoL4w1V6/fgx7gki8zaICVCo=; b=KPOE5Oet2sQBeUjSb9rnHxYht2l33UeNt5IdWIHE2Tce5sDRpjJ1EE25Mq/R8Qjn9V CEM3ioR64B7Lxlos5sIOe4WugxcpUmHTgumORa4yJb6c+PJmiXM272C2xOw1x8zN+FZw TyA0g5SHqtuspjxg46C3RXwzNJ2YT+R2Rof1WXdI+awO2VZMiewBQMZPUWCsi0TKqtoe 9r7gQMxLVyLXgE3w3N46cVuOS2q2jvf0jVeMwj53XpcLul6Dvitfk/ZQYMKIsrMhVwFL NjCUDFQ8QdUZ19gjL2zLhEXoRqIaMQjTD4IlSmijme1ICOGYSFz0v3J2sFIuo4vBgvwL wE9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JksLUcD+; 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 ij7-20020a170902ab4700b001932c1921c4si12092243plb.410.2023.02.06.13.09.09; Mon, 06 Feb 2023 13:09: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=JksLUcD+; 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 S229772AbjBFVGN (ORCPT + 99 others); Mon, 6 Feb 2023 16:06:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbjBFVGJ (ORCPT ); Mon, 6 Feb 2023 16:06:09 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D57846EA6 for ; Mon, 6 Feb 2023 13:06:08 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id h1-20020a17090a470100b0022646263abfso5177079pjg.6 for ; Mon, 06 Feb 2023 13:06:08 -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=Cjg1wQcr6HPBZFA4eCrjoL4w1V6/fgx7gki8zaICVCo=; b=JksLUcD+s/K5QbXrCBKe9Fq7MMs3hW/WK8+8zMYpjOJ0oezih8H66ZI0/EORvVlZGN HlqO2tKE0qGs6Y8l3l0Kg9P9tzx+iz8fupo4QWOHmQ1+xIfF8BkWJYZZRi3571XKOXLB WYv8zeAvmS+wjUpyrDN8+9btjNsl6fGOxIw7lmYnz8H6PUl9citH2pv0kteAeJULCLrb diK0TIULo6HqBusnp62jgTT7bUB/6g8jOj2NPULBCfSM0v7fFEGgLfORGsOAzQ0KbSv4 xuwhstWN6wA7KpAzwFrS20dCX4S589S9jLc5OMMJ+4LwYXVjmHCcSw9IjPk7Ink+hATM QALQ== 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=Cjg1wQcr6HPBZFA4eCrjoL4w1V6/fgx7gki8zaICVCo=; b=XgGpxLkD3c4tErw9Y2Lc62jcp9hv1GlOUTF61Xo8kPSkthBZHgCzf8f1t8NA3ErCWc Oa1fTcxstVII3ozXRLaY9fK5yWpYVnsL6YYlmKWwC1epawy9h5ofKw4/XZLKN81C7A68 qp7Cvg/N5/2vG70Pa4kiB7GMeI3AcKCbKEx+DIMAvCI/qhxjVHiTw8lZms11DnNkZnlr AGcSDfD6qKYn8sXuigX+b99jDHPrMzO4QNS/aaj+ZWTHw7tXDHsj03EXgkUG2MsXf/qO cDWTqe+EniRmEkqhTGQNTE6wNaMoThoI3QBnQ2vJk06XlLSvm6IKBrpG+lHIi8Hb4h5y x1Qg== X-Gm-Message-State: AO0yUKVmwZxUmSfJ2G5qToNNEYE+0WTW2R/7uzKCIRote5IQWBdG98jG pFSRJ8ro28tVg+ENxf0SuDwrnVpZLYbRISbpLtJPqnVmXBc5j6RPcBFqBVIsWMOwWk/BJ2lSAdt JbfNevfp6mIqJ19c8Ev2HpmQXODNhScdYaWLFRnuCHoxAhdszSz8iXofoOSJzfhi9bBPZT5k= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a17:903:124a:b0:198:debf:d122 with SMTP id u10-20020a170903124a00b00198debfd122mr66079plh.16.1675717568179; Mon, 06 Feb 2023 13:06:08 -0800 (PST) Date: Mon, 6 Feb 2023 21:05:54 +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-2-jstultz@google.com> Subject: [PATCH v3 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?1757117427723051828?= X-GMAIL-MSGID: =?utf-8?q?1757117427723051828?= This patch adds randomized nested locking to the mutex torture tests, as well as new LOCK08 config files for testing mutexes 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 LOCK08 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/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 6fe046594868..8a08c004aa80 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_NESTED_LOCKS]; +static struct lock_class_key nested_mutex_keys[MAX_NESTED_LOCKS]; + +static void torture_mutex_init(void) +{ + int i; + + for (i = 0; i < MAX_NESTED_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 < nested_locks; 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 = nested_locks - 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..b8b6caebb89e --- /dev/null +++ b/tools/testing/selftests/rcutorture/configs/lock/LOCK08.boot @@ -0,0 +1 @@ +locktorture.torture_type=mutex_lock locktorture.nested_locks=8 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 From patchwork Mon Feb 6 21:05:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 53512 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2462747wrn; Mon, 6 Feb 2023 13:09:39 -0800 (PST) X-Google-Smtp-Source: AK7set/hFG+TrPETjBE7B3vP0tAytJWO46QyMOLQUbVUnmqw66BRJmuQHBGS3gmV9TfHt1JjDpRh X-Received: by 2002:a05:6a21:3881:b0:c0:af73:be4d with SMTP id yj1-20020a056a21388100b000c0af73be4dmr366776pzb.54.1675717779341; Mon, 06 Feb 2023 13:09:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675717779; cv=none; d=google.com; s=arc-20160816; b=rcyipUun+ywhP8OQ/SlzTbikfUd79TTayG9of8hrXoSO4cOkH71cfZ4IgfbH+O4UG4 4op5IFgo67TwvT9r7bChJCsZbRIUflnvt0IzryNdWy9o1KBSwkA1+ChTf6JYIOFdM3YQ +GAK/3C5Qg7w8uMJNRbed3dxdQQRoMsn4R96ofB8ynMiwk4MWkkf1poDSkgqLSt4Q9XM NHEuMGzpOCbpL7J0Gqtg8b/FOs6jPKLACElj70p/kA2wSsfYQMklkulyYjFye5kc8Ea8 zDI4VzrwY7pGjvLlESNj/A41/WL+zjNsQD3WeD9TMxvxqnDaXtbMLD5smYlqPAwYHpEc E5hA== 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=I3e/s9avw1m4n0KoQjfHLWE3N93DXhuhhva7XCYBBqk=; b=UFEVsu5iJxj9L7WZ3ZVFrCZMKv8sPGqmsMpUZ42+Itc/3da4jnBY18ky7QHYw4P7gf JVqVo5U+C5OjpTKABKOD+6J57Y/GXiB5xZx9/KL3uIsjaY6GX7k4Fh5CD6wDPRegwFn3 luJ2SCXZOENS0BKCubNUpmHTu9Ax8RSVzQLQkCbdObxC+y0Lil46rwmIhJVuQgJiVCgL xzoKOwE+MVdsY/VcNtEDBIWHamkOHlJA9ueNVg4aoIHTPTRGVfewPymifj0ce3G9nNR3 J0OVyxkilyQgpmHkeJlE7vlfSHgnXcqj+jypLaskhb+t+UvLwkZ2DHefIyAMIYp+hN+N Rbpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HokxCYxl; 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 m8-20020a638c08000000b004915c5ca6b1si11771383pgd.866.2023.02.06.13.09.26; Mon, 06 Feb 2023 13:09:39 -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=HokxCYxl; 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 S229923AbjBFVGT (ORCPT + 99 others); Mon, 6 Feb 2023 16:06:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229686AbjBFVGN (ORCPT ); Mon, 6 Feb 2023 16:06:13 -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 D40B42C649 for ; Mon, 6 Feb 2023 13:06:12 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id j14-20020aa7928e000000b00593bca77b0dso6953694pfa.9 for ; Mon, 06 Feb 2023 13:06: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:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=I3e/s9avw1m4n0KoQjfHLWE3N93DXhuhhva7XCYBBqk=; b=HokxCYxl6SUv/u4i1B4MSvdUni65+hHCahZPbRel82LgW2njrOIL7KZFDtMGa2VnyB hjXqVcyejXgPnAaMv1Kw/Lp68BU18saa2DNpXrpbwTGKsIXGJ1m96FQCxVoSPPt7C73m QNRsKo4r3cEHT2TFXE616xDky8i59SO/oncU7xwwfpQf1Wh2BSAluLwHHEuLUBHbZoeP Or6cJNi27gxZtDmrE+saH7xQ+Qp4PHgTwkYow3D8qjAhunNPK8xDXjAnx2LuX2zwwV0N v01sCwU/VwSi8+mkz7wwO/6NK5S8XebVV5Dny08dA4B8VvyiL6TNbKitMq/p2MHkgD30 xX2Q== 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=I3e/s9avw1m4n0KoQjfHLWE3N93DXhuhhva7XCYBBqk=; b=RO6To3HoGfjHsT5//iLr01GsQeXFtfHq3KJ8hHZs1JUZQMKLWvN1WoQ/mTLkdyntLK Wiqmw6b6yt8zh1cL2OhAcMOb1i0UjECDaVgzfumnpoMjdmlks+XbV6FXJegr1K16gtXA c/lsDehbldMSY0WHtj0dZfMmHi1nScNWMlITdf6g9FrKfbnZ5RgWw2Sdr1TwvMK3QGBw migRrAmtkbxVXoe11PK7UhlSbxR+A7CDuKXN1KyP1MddTqilOyB88dIOSDhmQXnMoakC 5FUNnNHXsubjvDsu91aeHDpL2uhbDxerzgKndJw24ytTaljOBYRxNcbpqBPBLWyfUTgq JTGA== X-Gm-Message-State: AO0yUKU/8GE+ef7Ms+Y2WUrArzSoR72fS028GAl1qER32uzApLZDIXFx Ixa5sgiKgJV1GTksmw+ckqDlca5tBt5ucCoFyIdQDFnqjvpdjcCBX0JDGCQ8hRAj2d5M+vMTHeR DjAcpz6jAoHkETWVi8jSDxMDD4aUGI7kee+DF1pl2saOBMbbCQhoYBV89llNYRFOsRTOHHUw= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a17:90b:e97:b0:22c:5369:8a36 with SMTP id fv23-20020a17090b0e9700b0022c53698a36mr11794pjb.0.1675717571605; Mon, 06 Feb 2023 13:06:11 -0800 (PST) Date: Mon, 6 Feb 2023 21:05:56 +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-4-jstultz@google.com> Subject: [PATCH v3 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?1757117445870215012?= X-GMAIL-MSGID: =?utf-8?q?1757117445870215012?= 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. 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 --- v3: * Minor rework for naming changes suggested by Davidlohr Bueso * Added comment explaining why we skip the main lock, as suggested by Davidlohr Bueso --- kernel/locking/locktorture.c | 37 ++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index fd8b2b007c26..ab896cc42b87 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,37 @@ static int lock_torture_writer(void *arg) schedule_timeout_uninterruptible(1); lockset_mask = torture_random(&rand); + /* + * When using nested_locks, we want to occasionally + * skip the main lock so we can avoid always serializing + * the lock chains on that central lock. By skipping the + * main lock occasionally, we can create different + * contention patterns (allowing for multiple disjoint + * blocked trees) + */ + skip_main_lock = (nested_locks && + !(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);