Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp183021pxf; Wed, 17 Mar 2021 19:26:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDPkHEajqy/QMWkG/1Oc05SKo5QdwRLHLxlBX/HiHdGmPj/DLLeiDBY0EtIlNtifvCRV/f X-Received: by 2002:a17:906:cecc:: with SMTP id si12mr38739394ejb.461.1616034417157; Wed, 17 Mar 2021 19:26:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616034417; cv=none; d=google.com; s=arc-20160816; b=XAoiwSuyvV90I2KCUzowb35z5kc2kZABBg34LlBVW+iCBusiJ17MOFttKJ1htg2Jaf uvolDk5h1tGv7H+Mj85azcZan9YH8lEYdn+gWMn++RJqZOBr5KKd9vur11cnwCSEMdjm CqyViL3+R1Qz+4Ql6XyaJZHb62L3JLHuK/kRgnDIcAId1ICdVH4na8oDpoBe6z2E5aSV RLpsL7KG5nPkikcZKdpWqLKIR45OmJrLnkcx6NJb7ajRYH2Ff1pE2rvuQPPgguJO0i88 5B2UKoHyvEeKOdkLl9CIMle0GY9uP0ZEmMTkJs6b3i5zCkh+mQS7Emr/goXJry76FTkB GQrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=KtRoYljdLC9wtNNIQKgFt5kI0MSMpD7ofw+TcTRYVTo=; b=PP28l1YL2llJ1a6pL0HOgZGR9fPktsPSV51ni2pFyXQoB7NTX2jPrKPzL3XkvUPLE9 od57srN+uNYofp8q9y1XBfnswo05BJ/sHz9c3JZx5CvABc9aywIU/s3hJ/maYB5NMKiA 5ZQ15uTRtpBMxJICq/Uu6lrcNS5qyhXR/laWjW7OCu/RxdRvsdC6q1vdZD3lgJo0smr9 +ZUh6G7c/MccVnxi8ae80uCStnUNBn2DrP+G1riutW0BblQ13VCifKdVF6pqGrxnhqBk hD3o862u1vYDvJgUP49HjfmETcuI/nD3+XqcAaXDarh6Ag+jeS2I75ZI6D2SgiqUilo7 B0tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JfToSI4k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z23si509327ejw.362.2021.03.17.19.26.34; Wed, 17 Mar 2021 19:26:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JfToSI4k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230221AbhCRCYf (ORCPT + 99 others); Wed, 17 Mar 2021 22:24:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229702AbhCRCY3 (ORCPT ); Wed, 17 Mar 2021 22:24:29 -0400 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B6BAC06174A for ; Wed, 17 Mar 2021 19:24:29 -0700 (PDT) Received: by mail-qt1-x82f.google.com with SMTP id h7so3014364qtx.3 for ; Wed, 17 Mar 2021 19:24:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=KtRoYljdLC9wtNNIQKgFt5kI0MSMpD7ofw+TcTRYVTo=; b=JfToSI4kaBWN0qUCBE3Q9DPIPE+BeYzj516ZRCD8oSKbGgEMflIpd0jqn35vszBpcd yjLvJ6rOzzl7lbCJNBeS+dVViSca835sOdLEqwobmUNnPRU/e9eB8ySyuLcQdYD/1cZR rcR+f9zoMB6RrIC7oI9D41mj2eOo3invqQWGOFjJEC+KJDEobUPN+1rf1hN5IBr9HV7G 2HpHXcLujlcEnnLl6UQltvehTTmen5x0F20lWJ6zwYZJoZuqyEw2h3u5NY2+43IvhwSE uQImVhSaRSxIUdtNz1tQttGY7vMzKJYvADyMf5yTWL/hvqNnAHjef+eEXh6PbuVkXtiF +27g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=KtRoYljdLC9wtNNIQKgFt5kI0MSMpD7ofw+TcTRYVTo=; b=LgzthnBskBsYS05gUIUJWTK3byr0k8EGbRMeXa7mYmpQ5K/tNRKv28zQxwtbkcUU7D b1I8hphfd+evOffulC1M+BDJg5EiCzTfxfy/69s487C14QVQq9pzg7qcQtywfMS5fqLI DKCdluwlcMfVXc86/WM4Y+AWev2xleDsD3ALm1ZB8rotHd1FaasDHubd/gRnzsfURlyX w+M+y9npJGMBb12eEmXncuEKgWCJDp2vk5EQAAGkwGqg6T4rIDeWVSGYdkt1GSnlp8k0 9vmBqVK5mD62MHot3kQ8ymjR5rkInYwd4VJ3+VeXk5n37cF+XHqeHDtqOTgc/Ra1SEzq lt6A== X-Gm-Message-State: AOAM531K9H1YQa68VNcH5TUcrQNeTGgyqy+agf/3gSZ7Uo+rfRZPFKt/ 8Oh2XRt7ZNzCWKATb+dYpunl6WAtI2E= X-Received: by 2002:ac8:e81:: with SMTP id v1mr1821498qti.23.1616034268524; Wed, 17 Mar 2021 19:24:28 -0700 (PDT) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id c73sm780161qkg.6.2021.03.17.19.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 19:24:27 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailauth.nyi.internal (Postfix) with ESMTP id 207D127C0054; Wed, 17 Mar 2021 22:24:26 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Wed, 17 Mar 2021 22:24:27 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudefhedggeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeeuohhquhhn ucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrth htvghrnhepvdelieegudfggeevjefhjeevueevieetjeeikedvgfejfeduheefhffggedv geejnecukfhppedufedurddutdejrddugeejrdduvdeinecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhh phgvrhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunh drfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgv X-ME-Proxy: Received: from localhost (unknown [131.107.147.126]) by mail.messagingengine.com (Postfix) with ESMTPA id C8CA11080057; Wed, 17 Mar 2021 22:24:25 -0400 (EDT) Date: Thu, 18 Mar 2021 10:24:08 +0800 From: Boqun Feng To: Waiman Long Cc: Peter Zijlstra , Ingo Molnar , Will Deacon , "Paul E. McKenney" , Davidlohr Bueso , linux-kernel@vger.kernel.org, Juri Lelli Subject: Re: [PATCH 3/4] locking/ww_mutex: Treat ww_mutex_lock() like a trylock Message-ID: References: <20210316153119.13802-1-longman@redhat.com> <20210316153119.13802-4-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210316153119.13802-4-longman@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Waiman, Just a question out of curiosity: how does this problem hide so long? ;-) Because IIUC, both locktorture and ww_mutex_lock have been there for a while, so why didn't we spot this earlier? I ask just to make sure we don't introduce the problem because of some subtle problems in lock(dep). Regards, Boqun On Tue, Mar 16, 2021 at 11:31:18AM -0400, Waiman Long wrote: > It was found that running the ww_mutex_lock-torture test produced the > following lockdep splat almost immediately: > > [ 103.892638] ====================================================== > [ 103.892639] WARNING: possible circular locking dependency detected > [ 103.892641] 5.12.0-rc3-debug+ #2 Tainted: G S W > [ 103.892643] ------------------------------------------------------ > [ 103.892643] lock_torture_wr/3234 is trying to acquire lock: > [ 103.892646] ffffffffc0b35b10 (torture_ww_mutex_2.base){+.+.}-{3:3}, at: torture_ww_mutex_lock+0x316/0x720 [locktorture] > [ 103.892660] > [ 103.892660] but task is already holding lock: > [ 103.892661] ffffffffc0b35cd0 (torture_ww_mutex_0.base){+.+.}-{3:3}, at: torture_ww_mutex_lock+0x3e2/0x720 [locktorture] > [ 103.892669] > [ 103.892669] which lock already depends on the new lock. > [ 103.892669] > [ 103.892670] > [ 103.892670] the existing dependency chain (in reverse order) is: > [ 103.892671] > [ 103.892671] -> #2 (torture_ww_mutex_0.base){+.+.}-{3:3}: > [ 103.892675] lock_acquire+0x1c5/0x830 > [ 103.892682] __ww_mutex_lock.constprop.15+0x1d1/0x2e50 > [ 103.892687] ww_mutex_lock+0x4b/0x180 > [ 103.892690] torture_ww_mutex_lock+0x316/0x720 [locktorture] > [ 103.892694] lock_torture_writer+0x142/0x3a0 [locktorture] > [ 103.892698] kthread+0x35f/0x430 > [ 103.892701] ret_from_fork+0x1f/0x30 > [ 103.892706] > [ 103.892706] -> #1 (torture_ww_mutex_1.base){+.+.}-{3:3}: > [ 103.892709] lock_acquire+0x1c5/0x830 > [ 103.892712] __ww_mutex_lock.constprop.15+0x1d1/0x2e50 > [ 103.892715] ww_mutex_lock+0x4b/0x180 > [ 103.892717] torture_ww_mutex_lock+0x316/0x720 [locktorture] > [ 103.892721] lock_torture_writer+0x142/0x3a0 [locktorture] > [ 103.892725] kthread+0x35f/0x430 > [ 103.892727] ret_from_fork+0x1f/0x30 > [ 103.892730] > [ 103.892730] -> #0 (torture_ww_mutex_2.base){+.+.}-{3:3}: > [ 103.892733] check_prevs_add+0x3fd/0x2470 > [ 103.892736] __lock_acquire+0x2602/0x3100 > [ 103.892738] lock_acquire+0x1c5/0x830 > [ 103.892740] __ww_mutex_lock.constprop.15+0x1d1/0x2e50 > [ 103.892743] ww_mutex_lock+0x4b/0x180 > [ 103.892746] torture_ww_mutex_lock+0x316/0x720 [locktorture] > [ 103.892749] lock_torture_writer+0x142/0x3a0 [locktorture] > [ 103.892753] kthread+0x35f/0x430 > [ 103.892755] ret_from_fork+0x1f/0x30 > [ 103.892757] > [ 103.892757] other info that might help us debug this: > [ 103.892757] > [ 103.892758] Chain exists of: > [ 103.892758] torture_ww_mutex_2.base --> torture_ww_mutex_1.base --> torture_ww_mutex_0.base > [ 103.892758] > [ 103.892763] Possible unsafe locking scenario: > [ 103.892763] > [ 103.892764] CPU0 CPU1 > [ 103.892765] ---- ---- > [ 103.892765] lock(torture_ww_mutex_0.base); > [ 103.892767] lock(torture_ww_mutex_1.base); > [ 103.892770] lock(torture_ww_mutex_0.base); > [ 103.892772] lock(torture_ww_mutex_2.base); > [ 103.892774] > [ 103.892774] *** DEADLOCK *** > > Since ww_mutex is supposed to be deadlock-proof if used properly, such > deadlock scenario should not happen. To avoid this false positive splat, > treat ww_mutex_lock() like a trylock(). > > After applying this patch, the locktorture test can run for a long time > without triggering the circular locking dependency splat. > > Signed-off-by: Waiman Long > --- > kernel/locking/mutex.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c > index 622ebdfcd083..bb89393cd3a2 100644 > --- a/kernel/locking/mutex.c > +++ b/kernel/locking/mutex.c > @@ -946,7 +946,10 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, > } > > preempt_disable(); > - mutex_acquire_nest(&lock->dep_map, subclass, 0, nest_lock, ip); > + /* > + * Treat as trylock for ww_mutex. > + */ > + mutex_acquire_nest(&lock->dep_map, subclass, !!ww_ctx, nest_lock, ip); > > if (__mutex_trylock(lock) || > mutex_optimistic_spin(lock, ww_ctx, NULL)) { > -- > 2.18.1 >