From patchwork Tue Feb 21 19:02: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: 60228 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp178159wrd; Tue, 21 Feb 2023 11:11:43 -0800 (PST) X-Google-Smtp-Source: AK7set8baomevls6/sE4Tr73nbS3/tVm3xwN6IyWrxRNHPDVxNnwzTomdG+1AZshRloIYBhutgLk X-Received: by 2002:a05:6a20:6987:b0:c7:13bf:3fd0 with SMTP id t7-20020a056a20698700b000c713bf3fd0mr6437941pzk.25.1677006703161; Tue, 21 Feb 2023 11:11:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677006703; cv=none; d=google.com; s=arc-20160816; b=nmBRw64YGFfdT1kMBTWsi+icTw6YJmfFE9w7CPmvthM4Q4fSjJHZIYCjusbD3NtBNE 6OftkZIq43dv6hpnpiY1evbaDDsBX1Sh9aXMP1023NuMfnToIqYZsb2QbIW8WQNoNhmo qVnfmuTF2ZHurCakn/KGBkAmiCEOnExXrSuvuvafIkSP6kemCQWraAB/LuDdBf81PuUv UzxYiUt63cJ36sIVFE2o8OyM6ptRpIU0MqGEiDU9yBF1th1ryDAV4Yw+aszPXVbqmegs yU40Dq6JYN7GXF07hgbqMoguifPHiGsdPDtPbboIMZT6sMvr2XgaiRM+E0S83X4Fb9QX AF3A== 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=WwK53qS/jcR6/xM0LNfdTpR4NejvvarONLmagoE1yHA=; b=LhzaM3SnR63Vqa7DyojSP9NFOxyqn4iTdgBJk3EGUVXbXYVKHlyj6yTJpubZN8I4UD Qw+bA4EoNt+eO2g+NeI1BHPcAemnRqRYyGbV3ccj+kjALP0kHIvXCTuKkNqZtE9G8cuX gRO23Sf5HLuP/pQQik5v9VwEaaNNwLBDEk/CGK3iDOzwCEcV2cSQIg9K8e+O2WAxRig3 CP/CeXn0oqwZYu6fSwjsSkjkRvav9qhTqGI8Stcu0EvDKVIbAD94rumzQpEjNjWlO/gU qazhli+p2YZTJZWwo9eboB/EPh0zAejzyof/DBK4az82yuTZdRP43yL6lAONaiEKnn9f DTBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Rn8Q8/DR"; 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 w189-20020a6362c6000000b004fbd563f23fsi18956776pgb.166.2023.02.21.11.11.30; Tue, 21 Feb 2023 11:11:43 -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="Rn8Q8/DR"; 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 S229686AbjBUTCs (ORCPT + 99 others); Tue, 21 Feb 2023 14:02:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbjBUTCr (ORCPT ); Tue, 21 Feb 2023 14:02:47 -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 627BF2D15D for ; Tue, 21 Feb 2023 11:02:43 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id d7-20020a25adc7000000b00953ffdfbe1aso6092074ybe.23 for ; Tue, 21 Feb 2023 11:02: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:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=WwK53qS/jcR6/xM0LNfdTpR4NejvvarONLmagoE1yHA=; b=Rn8Q8/DRcejIDDnzupSaVh/xi9Z0bSnXaAVXNzvfTilsOMgsUxUKgTLlH+4MCiHikc 4S56Z5kgYkZDJw3NFnr9mzRFquuoWagHJ4tTH7/1Pra5LDmBOrlqvKw1eRlFIUb4FYQE P5aBK2d7yQV34rVOcqvASAQ+DAOJR+0NzyfKBBfsn1a4YejHCbV/9br3x3nx5TUt0Hyb v7FOQm4XMFkiZXUMPXIbaTR0BlTNCP0d8TibphFWng8+7kP3qzwU2P+Gj2HuILJ/R/Vu njlyMz/Dks0m0SPQ+wjSbkG330jP5WjDXgWZ9gzEVM0urjNGYbMdQ0TdjMMXwmAxYZd/ Ghsg== 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=WwK53qS/jcR6/xM0LNfdTpR4NejvvarONLmagoE1yHA=; b=wS452BdEapbRKhBvq3C6X+vTnYRiF2GH2yhhZ+5pFcuwVJ7uNzbRbnqPiheLUkdM/I EHXgSetn5cLtDNOU1jJamavVMwK4FtgGdvDyFgj1pgEkN9ChMD5lKqkpumgi5baXhb15 9saSXlI19xfqxOTn8sWf4bWcleACj59y3svMwXSnvi0uU82cw7gDXXewmqpBbjhqyvX1 aImmcB/RVEGaicrQAI537Bzu99uM5dVqKW/4u4mir6yfN7pxptOqEKGGo7m+wTu2CPUz Bf4q3Hgglm4KditJ08nhhH+9PcnKA73FpJwfIG9XQsGxxMauh84GsDjbU4ga/8BH49gq GPpQ== X-Gm-Message-State: AO0yUKV0zzcg2yQ8TU7ZNvOoyQ8MsPnRVZeyOG8b4qgrE0D+GK3eiWxh XNsN6urfC5wYOwhwtPV0B+zHN8K/76Jr/h0R1vlzQo1+RtXuEn9lOQy9fwpjLFqom4ni2zbb1Ok 2WKRMQrwzQLz4zxWCqzXg6ptZR3LLfaYOnBiHM+CjK0xOAb7IFOOJdrrxEKYGrLJc09TrLZ4= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a05:6902:10ca:b0:9ed:13e9:fe68 with SMTP id w10-20020a05690210ca00b009ed13e9fe68mr551231ybu.3.1677006162586; Tue, 21 Feb 2023 11:02:42 -0800 (PST) Date: Tue, 21 Feb 2023 19:02:35 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221190238.21285-1-jstultz@google.com> Subject: [PATCH v4 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 , kernel-team@android.com, "Connor O'Brien" 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?1758468980732376167?= X-GMAIL-MSGID: =?utf-8?q?1758468980732376167?= 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 Cc: kernel-team@android.com Reviewed-by: Davidlohr Bueso Co-developed-by: Connor O'Brien Signed-off-by: Connor O'Brien Signed-off-by: John Stultz --- v3: * Minor commit message tweaks and naming changes suggested by Davidlohr Bueso v4: * Add co-developed tag --- 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 Tue Feb 21 19:02: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: 60229 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp178178wrd; Tue, 21 Feb 2023 11:11:45 -0800 (PST) X-Google-Smtp-Source: AK7set+xCjT8VzCOr4BT0f57YbuX1vJw7uu1/w/k7kRiD0fflwV0HV9kFoTCGHCQ4UUxaON5Tj/J X-Received: by 2002:a17:903:11cf:b0:19a:b32e:cbb with SMTP id q15-20020a17090311cf00b0019ab32e0cbbmr5845527plh.11.1677006705175; Tue, 21 Feb 2023 11:11:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677006705; cv=none; d=google.com; s=arc-20160816; b=O2PNIXtduPjZLlAKzfTzA5gHmQWhmL9tUyseTyAr4e5AVLc15G9KRxFdBLH6ZDCtre gzI7JwZ0fgYLY4OyyrMIuG/93kujL2XO+B4VVTsXF3UB6nXqonNfR2bj5W7XjYp91JWM nhaQHNLGiAkRzUwGDnoLUbnjitAojUVIbBpcuLO9Co13657mw843hmo4RUdf/bn+ZGZQ qkCYWqBixmxcoH9iGQvu6B84hEGhuBpenPUP1Rr+xPCr1R5sa9fLnTeEpmR3TWna7ZrW IKqjwQFh9uZ0KTvmh8Qju1Hnsvb+ezDtf5HpFKcmW5gUJA0ASG25nQWH3vYB7LpV5bLg o1DA== 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=5cepCIHpaKzs52FKbEjggulKdfWjoWwYnrJ7V/VC8n0=; b=qyL7DSZ9yPVnwFwN5KdtW77fvLemN87B7JgkmnecR4/pcydreGsLAfKO8cQlovgvft CI+Zv7aYD+5UqFy/SdM8zbAzJ92gaSl/X8jAn40NTqjgfbkvzZz7+14fY9bu9kgF2VSI DcR4Zimu7GeZfbj++g3XQP+McWC/PMvIVuYInaG4ODHIivrj3vGzjMaSLE8eD7akZQVi Y3pjceounvRubJAs3ih1bdzT3eByqmQcCkF0JaQQtv45uljrMzLHfJah8jKRaqd41g6p EW+oYsmVDMpsa2b4T+bKDXAcj/Zz08gibx+zmY7Xnf0EGSJcbsKOs8igVtIEeOGDGeCS 2MTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=CDDNatyy; 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 o11-20020a170902d4cb00b0019953ab9cf2si5145322plg.138.2023.02.21.11.11.33; Tue, 21 Feb 2023 11:11:45 -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=CDDNatyy; 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 S229886AbjBUTCu (ORCPT + 99 others); Tue, 21 Feb 2023 14:02:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbjBUTCr (ORCPT ); Tue, 21 Feb 2023 14:02:47 -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 03D762ED4C for ; Tue, 21 Feb 2023 11:02:45 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id p14-20020a170902e74e00b0019ad833d8a4so2492596plf.15 for ; Tue, 21 Feb 2023 11:02:44 -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=5cepCIHpaKzs52FKbEjggulKdfWjoWwYnrJ7V/VC8n0=; b=CDDNatyyioKxlkIW9KqEU0dbH7/bxu8/DiWfXuP7z+579D7+hKsC6II4rsZ1KFTnSm sXByQojJWGePA5fDSVReZQ8N0xe0qS9ijzqb7TOeRvv2/Q4lA6xojL5XY6EAsvWMzgRB qJ/aa5Nvaz48s6fgEYHkFd/VbFOYB8xw4wrfnn19xjoVq6VelozaZ9yX7jOe/KL8n11+ leWmALz8cNgbtE9XQ/H87WhiHIKmRudv2O2x8bZC2n73XSPqMC8dVrQtNdCJw7OxSbQX HbLvlvBiT/uc+H4VKVOkIwCbdXRSAuXAnzrnADlo+dwvI3MvrXMxn+ZR3XXJCXZXR5cp 5mvg== 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=5cepCIHpaKzs52FKbEjggulKdfWjoWwYnrJ7V/VC8n0=; b=IgcKCO3iLjeLVEP1sQiNc3NIuf4d/fzxxZ0cGVp1u/oCeMh8CoMDwyKgC5NacmG6xT 63UJlmmJ9ezoR0h1hObkp+e88tAfGVdIQC+g40xsr4IOfpVNt1dxF4t4I/465++fwK+D w/egqzGH3c4feSWhrWqdaQcOMojl7fEA5nEujcl5NyIcHKcJ4a/KCkdVainWy4mbnHHb y2KOhlPbfH/rXsCTcRU0EfxwIzHdmxNlT3K2zeu8srJS3O0jk+S1lOkkCTEoHVx2WKqq tH+Idye8NPZf9yfaEHw0Uy4yUheZu3jD6F+T+KyB0gQt1fkbvAEe9cAL5PdJnzT6iOhO mNFg== X-Gm-Message-State: AO0yUKVkwVrFVF16uiPQCfM/NHv7gQm6556KhvCoMqpNctUbQbu3BKId +nKZCU5hd7DTtUHF7OLRKMu2O0NhOXZ10Uxg+WTb+1fwt7RJwxPNHBpUJwFCaxg4SAj/Ha9ymx5 LvvUokg61pLHe3zvmD/eEcfaLcu9j3mL2Q2Rgp3pDl6IyJc8TG3AJx+IJWHOSw2NT0UqJCpI= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a17:903:48e:b0:19a:f63a:47de with SMTP id jj14-20020a170903048e00b0019af63a47demr789500plb.7.1677006164331; Tue, 21 Feb 2023 11:02:44 -0800 (PST) Date: Tue, 21 Feb 2023 19:02:36 +0000 In-Reply-To: <20230221190238.21285-1-jstultz@google.com> Mime-Version: 1.0 References: <20230221190238.21285-1-jstultz@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221190238.21285-2-jstultz@google.com> Subject: [PATCH v4 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 , kernel-team@android.com, "Connor O'Brien" 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?1758468983098265299?= X-GMAIL-MSGID: =?utf-8?q?1758468983098265299?= 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 Cc: kernel-team@android.com Reviewed-by: Davidlohr Bueso Co-developed-by: Connor O'Brien Signed-off-by: Connor O'Brien 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 v4: * Add co-developed tag --- 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 Tue Feb 21 19:02: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: 60230 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp178180wrd; Tue, 21 Feb 2023 11:11:45 -0800 (PST) X-Google-Smtp-Source: AK7set+ZAPHgOQJESl4+rLwcCL307ATUWDbPqVrXKqeJSwp9idiGs+/h518yepkAwqE1foLlL5Ds X-Received: by 2002:aa7:9eca:0:b0:5a8:ac19:8f42 with SMTP id r10-20020aa79eca000000b005a8ac198f42mr5039859pfq.14.1677006705236; Tue, 21 Feb 2023 11:11:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677006705; cv=none; d=google.com; s=arc-20160816; b=JpaPcRGY20FF7VkC3O/xwGcVrnTg2wv/HKy49SIdhDzsZrWNKEGD6ueslDBXNVpGby 57Rhz4/KS+hmvrZcHrn9cDWRmP75V3OA01UzPMU3yrrw9bGizlJu5RgXHq8EMG6Uu54s Yu78Hvd61hbDXEFPKv/zZlF2Y387yUPohmeLqXEe3NjQqLH++R3Xh3iVcCuySo90nGXt 0mHxdf5O1lu7u+BJFmmc1L5qAyIlKunogq2R50vHJTwe5Qhd/goMlEVAnvQVDzIVPNFb g3NyR8vE2vI00qMAoIdOxDCXsZflIaPI/fIJwAMRN1dl3Eqq5oPzPNGPT/PIIDjr+FpB AMAg== 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=+PDdG/xsbruylMts3CB20c9cAMQAh0JCYl5tHB8A4B0=; b=IQHGr9w2pLHzCdsRYT515hde/4qE2kzx7coQCBq3PlQ56VC8wng0vlJIcJmka+SgSx dfpFZwvqirpSdJnW/O9iuD7+AbjNsHnnb5AXOIzL7oyGKlwtK3GBH4tvs0tbtaYsEh1N IXzu4s+eYkZEcBGcCPYVlce/k2hBrloPAPyG6TIkJHrrqCtn6yse/gc8D7tg3ZliQ2i/ Ss1Iis1vZrBKhxYVgp6iYNnvVDlbU1DppWNkfDEQ9XY+H4COaBFui59SaHecjYmugmEP dg5J+VcZPfxnnN+/HBK9doq8sHQFx/3e6+pCHyvmGZrOI/S5oIhT4qWWUapbv/zTGG2b dy0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=n1VEkquQ; 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 n22-20020a056a0007d600b005a867303079si17761208pfu.164.2023.02.21.11.11.33; Tue, 21 Feb 2023 11:11:45 -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=n1VEkquQ; 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 S229960AbjBUTCw (ORCPT + 99 others); Tue, 21 Feb 2023 14:02:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229549AbjBUTCr (ORCPT ); Tue, 21 Feb 2023 14:02:47 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1C422D16F for ; Tue, 21 Feb 2023 11:02:46 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id w7-20020a170902e88700b0019ca50c7fa3so343613plg.23 for ; Tue, 21 Feb 2023 11:02:46 -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=+PDdG/xsbruylMts3CB20c9cAMQAh0JCYl5tHB8A4B0=; b=n1VEkquQlwo0RUie1ys+LnHyXx+2/hsc+JHa+ftOmW1u9L5D+p6agkVv9tqb/4EHjz /uktewL/nYsEHn5BGvMvLf9Ef4q119Pxo1acUv37JmEEzQi27pyGT9m0fk9dD+vQShUP Y/sXl1bF1sQ+9GXEKk/n1p6szq1ZEd+RfnDTUSLHLq5r/RsWAVPdapsoWhDQy1dPrvbb ZY4xehHFfgYOdutOILSx5z9zJ4PK2IgLJdgzp6GnmEK302uwJJcA7XqnJsNQdztqUcPj G7elixIbzuw5DEWS5JGNsHPkwSHXvTPkqVpT/eVIQ20TANqDcpQ1OqLDyixny+qnwgiX 1z6g== 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=+PDdG/xsbruylMts3CB20c9cAMQAh0JCYl5tHB8A4B0=; b=7nM2zDtOa090jpyBNoETJLUy2QtSe4mtMaLgNwxWwVbnmWTmfl1cKMDJ58LzIAPxow p6wH3qG8YDABvhva9JgJf8p8T6SPVvR+pAHBdIK9tgJzFBpsNZueeCNdaocaxjnmUD7C SzXpS6nYLPT7VfBcw6pGhqJEgy3hiAG39yRhs09bQIDe/dlJX26O48iQKODKep+SEbS3 Q/ji7vZjFc+54lCJII6GXzxUQVEpqcnbpXRHzNbNufuni56ko/X0NIOpboWKUP2q7+ze K18LDmM5XME6bXiwgP5pmtw5cRZTRM8tu1kaD0Dj5eXAnYdUJSIRU75JBc8JM2ZPpEDO cRrg== X-Gm-Message-State: AO0yUKXLACxxoD84jycQ3sHq2tR60LK1TSi0dD8XhXTRl7M3OMfUa5st aMJmuVlbeU6RTu/gJvPGCBaFtTGjrn+gYURsxQCqVGz8JcOl0kfTGAQbW+QX2jj6MuUUWt8YU8f nLrhFK5kYykKl09jQeabZyn4gvyU/7fBcUFl/IcUrky4JyTChKorZQGgI+BgNskXQ6mRuieI= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:aa7:9396:0:b0:592:5896:89cf with SMTP id t22-20020aa79396000000b00592589689cfmr724292pfe.0.1677006166032; Tue, 21 Feb 2023 11:02:46 -0800 (PST) Date: Tue, 21 Feb 2023 19:02:37 +0000 In-Reply-To: <20230221190238.21285-1-jstultz@google.com> Mime-Version: 1.0 References: <20230221190238.21285-1-jstultz@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221190238.21285-3-jstultz@google.com> Subject: [PATCH v4 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 , kernel-team@android.com, "Connor O'Brien" 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?1758468982972439717?= X-GMAIL-MSGID: =?utf-8?q?1758468982972439717?= 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 Cc: kernel-team@android.com Reviewed-by: Davidlohr Bueso Co-developed-by: Connor O'Brien Signed-off-by: Connor O'Brien 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 v4: * Add co-developed tag --- 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 Tue Feb 21 19:02: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: 60223 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp177829wrd; Tue, 21 Feb 2023 11:10:56 -0800 (PST) X-Google-Smtp-Source: AK7set8zsHLvEznU+iSPsY22UtoCDuS5ocfQGLatPTWgjr7mbC989C0+1tVEXnd0/0QnYcXT7DhI X-Received: by 2002:a17:90a:8988:b0:234:b964:5709 with SMTP id v8-20020a17090a898800b00234b9645709mr8461376pjn.6.1677006656483; Tue, 21 Feb 2023 11:10:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677006656; cv=none; d=google.com; s=arc-20160816; b=GbR6bCcycMOAEJFK8huP6cDIrzKm5Z4+gJgLZJrRXafXkwibTCBo+wdOV92l4+alIw 5cv+1P4j35Nb9onmZjuOx3Pszyrz/0Kz3ZYBDzw7Sb+NJlk3Awa82WkPyAAsyAj8+hSC OSnPnbiMVm3n/63IBColMNCwYBFMiEhLhVhnRGkRmwdWotk8ptdwF4d+IwnyI4cXYB7T a8piJCN51QMz5SYnpfXXP/wg3v3SVWqPJ5vEuT7MZ4oIP5n4zlG9CFKETBNQu1RVeF0R 5Y013v0X6gkKou9aMRPiB7mMickOYrhUdVx61C5J67c5XPkgT0rLQ1FrqUsjbcwMpv3R aQtQ== 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=DqmNrLVmJBftM1yoPM/PSlPmkh/mDl2swNT+iqdeHDo=; b=YSwg5XYfLHxRaVYW/H0iJyNDu015hGfUJsBln5sRLtoh7wMLek0qt/qggHwc9Svj5F ngJlyY+pFMXLgONiPsxFlkYorDnCFAHFtkMad+rpJ9ao1y/yQGJy1ri6WRjEW4Jljx1/ gGErw9CtlfMuFZv1/EeEtoFyIWVSmWs5j2Apd+VY5UkoqZ96D0LMfgvMOYkkfNw9veNW GEztU8xD3jrFvkZEdBD2C+P/XYQDfn2ljhJsWdI0mzw3kUtPBfUC844WPgFu+5mNQa7i 355NGGHxDq1t0NnxbUEV8adS6zgZWKRcudeV6BZDsApsj5HVO+icPyaY948GNRjTkb6Z Ddpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Q4j2nMBX; 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 cm6-20020a17090afa0600b00234a84d3ed4si5718901pjb.190.2023.02.21.11.10.44; Tue, 21 Feb 2023 11:10:56 -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=Q4j2nMBX; 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 S230086AbjBUTDB (ORCPT + 99 others); Tue, 21 Feb 2023 14:03:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229946AbjBUTCw (ORCPT ); Tue, 21 Feb 2023 14:02:52 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA4C4DC for ; Tue, 21 Feb 2023 11:02:48 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-536bf635080so43999207b3.23 for ; Tue, 21 Feb 2023 11:02:48 -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=DqmNrLVmJBftM1yoPM/PSlPmkh/mDl2swNT+iqdeHDo=; b=Q4j2nMBXUKKLmBRvTfp0HrFhmn7yV4Ga7xgMIUOjN4sPurLnmgrZAET75ngq+zcDqU nTdkChOjaWLBQu4/IvY9A4afYsRcyrq77u8X2d58PaoCsfJ/jwvM5EuT+btFvc6EP95e zHZPlpdfTjjs3V2sXm5OjFqhxCENOM9jIm01smePUIAejPypPof7i96+nzM+h3GzErgy wXdJFS5CsZDhDKkSqf4ZrnOMhcFNppwF2Li7jc5SBOVsrV54Co5wyyMMtb5FMC6apPTR QCc+ka1E30I6MZmpGDXgIi8Tao5UxyAkIPgLiztFL4LnBvpd/WNAPdK/WXWMyarghhU4 m1Bw== 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=DqmNrLVmJBftM1yoPM/PSlPmkh/mDl2swNT+iqdeHDo=; b=G+6Mkc5zt6d9KYUbmFHp9yIAQKm4No/moN3dMGjHUoF+NryqLXtUcPaWaWUuM8Srd5 KQOnYyTjGHWplAe+MsIdkbOni/aHlj3PSV3VUHWl5rlNA4LVDaW6nsnrWiQbIi89AFus AZBvSyfdWp8+dJTubDrOvbaIJ7I1dRBFZINDuyfU1n9+K0znEjRfgg5krAfqv76oYuzW K6+OchNanUDNDxfbFvzBCf5LdSOj2vy5AKBCw/oWcHLY83RQn5Pu9zglBDs0rK/2Isyt aSFtPp85yrvYyltoSPYojiQ0D5CW26X+NYHWOcixtRvB60FxOiLAAYcUg3kc89V7/6X8 s+XA== X-Gm-Message-State: AO0yUKVmjX9zffSEZDyxBLXneUci2ae3pkIgoEi4IERgMXT17ushMrBU GVHpqrKPXeIsKjYSw6pPlCvG0iS80do3zn/2HHEDT2oZID2V/Ihg0iAQYb3EBmEw0Qs0JwT+kvi /iwtmTDz3uzgyb0mvzxuMlaoyzF/M3qeAMZPuL7PTSw4AZLRyGRI4OJIiS+z0krVouIdyMVU= X-Received: from jstultz-noogler2.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:600]) (user=jstultz job=sendgmr) by 2002:a81:a24d:0:b0:536:ff56:531a with SMTP id z13-20020a81a24d000000b00536ff56531amr46299ywg.544.1677006167995; Tue, 21 Feb 2023 11:02:47 -0800 (PST) Date: Tue, 21 Feb 2023 19:02:38 +0000 In-Reply-To: <20230221190238.21285-1-jstultz@google.com> Mime-Version: 1.0 References: <20230221190238.21285-1-jstultz@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221190238.21285-4-jstultz@google.com> Subject: [PATCH v4 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 , kernel-team@android.com, "Connor O'Brien" 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?1758468931365595474?= X-GMAIL-MSGID: =?utf-8?q?1758468931365595474?= 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) Cc: Davidlohr Bueso Cc: "Paul E. McKenney" Cc: Josh Triplett Cc: Joel Fernandes Cc: Juri Lelli Cc: Valentin Schneider Cc: Dietmar Eggemann Cc: kernel-team@android.com Co-developed-by: Connor O'Brien Signed-off-by: Connor O'Brien 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 v4: * Add co-developed tag --- 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);