Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3270511lfo; Mon, 23 May 2022 00:22:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwd7LCAZaYLt0EHS99Cr/YeUR+v24oPMyopGA0UHtFEeOPJX/rBTR8TyVK2JJy8qed8jP8M X-Received: by 2002:a05:6a00:2908:b0:4fa:9297:f631 with SMTP id cg8-20020a056a00290800b004fa9297f631mr22510819pfb.3.1653290576563; Mon, 23 May 2022 00:22:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653290576; cv=none; d=google.com; s=arc-20160816; b=wNDAltraAQxLOzZOoZ9qVPPCVR4rA5cGbfFdqBxisGtNo0e1Y/FfS34QkdKINZ5hrf R19/2xbPuf7LWPnqGMNKRc24WzbXBcDxNrtr1UcnlnMSi7kdK3rmbXu8DYU44Nv24EMS g4/TH/mZX1gC5vSVwSGW3diSf7A+UKiacNaPYw/RXyFYi1bGlhqrAerJrxomCoi4w7Eo g6kwH9qs0rjFrz3E7Sw92AJJVvHCds7N2+z/Mys5TeF6CZW2PxWc7Hwu9czQ/YtQZnco FjeUFNzl8YbPbV1Hwv7iV59dMOg6TJ+bJBQS9mXRvS3dmUmg1eE9+Hya6fb4lDl0ha3e UUrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=J4f4zaR6BNzGqNI5U8ohHMedSyF99NIbs2EIf4+Xnic=; b=0L2DA53TB/ecAWZ8YQTot8zCvqVJyKbZ0Crj3c6gdRPAxsTV4S1w46MRVszjkMBG8J xaaTwFiGSfJ03fnKwtaecusqQPQ3nHNvjLH0zSE7PpPiQhxMsCK3DsgTPmTOe8NjLWi3 pS7niOrlgwBMOPLPVfH+PL2G6Jm2KoQDyWv2bMCqPUlFlZsG0CqMEWINULkJ2SwuyYBG TuSJDDSDvW61aULY6sOlr686L1QKRqk/vysmIVh40GnVmJq4uUGLrWT5C0hoDDZpLy1e d0kg0CUKFmCkcmU/4N8M5bAPi9iIPvatqM9ccb9WVsdaxbi+7wmWJq/0VrWSxlRaVwVr SePQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g16-20020a056a0023d000b005183283a2dcsi13092077pfc.59.2022.05.23.00.22.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 00:22:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5A1D2A30AB; Sun, 22 May 2022 23:37:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353078AbiEWCpS (ORCPT + 99 others); Sun, 22 May 2022 22:45:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240903AbiEWCpR (ORCPT ); Sun, 22 May 2022 22:45:17 -0400 Received: from lgeamrelo11.lge.com (lgeamrelo12.lge.com [156.147.23.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0AE442E0BA for ; Sun, 22 May 2022 19:45:13 -0700 (PDT) Received: from unknown (HELO lgemrelse6q.lge.com) (156.147.1.121) by 156.147.23.52 with ESMTP; 23 May 2022 11:45:12 +0900 X-Original-SENDERIP: 156.147.1.121 X-Original-MAILFROM: byungchul.park@lge.com Received: from unknown (HELO X58A-UD3R) (10.177.244.38) by 156.147.1.121 with ESMTP; 23 May 2022 11:45:12 +0900 X-Original-SENDERIP: 10.177.244.38 X-Original-MAILFROM: byungchul.park@lge.com Date: Mon, 23 May 2022 11:43:21 +0900 From: Byungchul Park To: Catalin Marinas Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, torvalds@linux-foundation.org, damien.lemoal@opensource.wdc.com, linux-ide@vger.kernel.org, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, mingo@redhat.com, linux-kernel@vger.kernel.org, peterz@infradead.org, will@kernel.org, tglx@linutronix.de, rostedt@goodmis.org, joel@joelfernandes.org, sashal@kernel.org, daniel.vetter@ffwll.ch, chris@chris-wilson.co.uk, duyuyang@gmail.com, johannes.berg@intel.com, tj@kernel.org, tytso@mit.edu, willy@infradead.org, david@fromorbit.com, amir73il@gmail.com, gregkh@linuxfoundation.org, kernel-team@lge.com, linux-mm@kvack.org, akpm@linux-foundation.org, mhocko@kernel.org, minchan@kernel.org, hannes@cmpxchg.org, vdavydov.dev@gmail.com, sj@kernel.org, jglisse@redhat.com, dennis@kernel.org, cl@linux.com, penberg@kernel.org, rientjes@google.com, vbabka@suse.cz, ngupta@vflare.org, linux-block@vger.kernel.org, paolo.valente@linaro.org, josef@toxicpanda.com, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, jack@suse.com, jlayton@kernel.org, dan.j.williams@intel.com, hch@infradead.org, djwong@kernel.org, dri-devel@lists.freedesktop.org, airlied@linux.ie, rodrigosiqueiramelo@gmail.com, melissa.srw@gmail.com, hamohammed.sa@gmail.com Subject: Re: [PATCH RFC v6 00/21] DEPT(Dependency Tracker) Message-ID: <20220523024321.GB16721@X58A-UD3R> References: <1651795895-8641-1-git-send-email-byungchul.park@lge.com> <20220509001637.GA6047@X58A-UD3R> <20220510233929.GB18445@X58A-UD3R> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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-ext4@vger.kernel.org On Thu, May 19, 2022 at 11:11:10AM +0100, Catalin Marinas wrote: > On Wed, May 11, 2022 at 07:04:51PM +0900, Hyeonggon Yoo wrote: > > On Wed, May 11, 2022 at 08:39:29AM +0900, Byungchul Park wrote: > > > On Tue, May 10, 2022 at 08:18:12PM +0900, Hyeonggon Yoo wrote: > > > > On Mon, May 09, 2022 at 09:16:37AM +0900, Byungchul Park wrote: > > > > > CASE 1. > > > > > > > > > > lock L with depth n > > > > > lock_nested L' with depth n + 1 > > > > > ... > > > > > unlock L' > > > > > unlock L > > > > > > > > > > This case is allowed by Lockdep. > > > > > This case is allowed by DEPT cuz it's not a deadlock. > > > > > > > > > > CASE 2. > > > > > > > > > > lock L with depth n > > > > > lock A > > > > > lock_nested L' with depth n + 1 > > > > > ... > > > > > unlock L' > > > > > unlock A > > > > > unlock L > > > > > > > > > > This case is allowed by Lockdep. > > > > > This case is *NOT* allowed by DEPT cuz it's a *DEADLOCK*. > > > > > > > > Yeah, in previous threads we discussed this [1] > > > > > > > > And the case was: > > > > scan_mutex -> object_lock -> kmemleak_lock -> object_lock > > > > And dept reported: > > > > object_lock -> kmemleak_lock, kmemleak_lock -> object_lock as > > > > deadlock. > > > > > > > > But IIUC - What DEPT reported happens only under scan_mutex and it > > > > is not simple just not to take them because the object can be > > > > removed from the list and freed while scanning via kmemleak_free() > > > > without kmemleak_lock and object_lock. > > The above kmemleak sequence shouldn't deadlock since those locks, even > if taken in a different order, are serialised by scan_mutex. For various > reasons, trying to reduce the latency, I ended up with some > fine-grained, per-object locking. I understand why you introduced the fine-grained lock. However, the different order should be avoided anyway. As Steven said, Lockdep also should've detected this case, say, this would have been detected if Lockdep worked correctly. It's not a technical issue to make a tool skip the reversed order when it's already protected by another lock. Because each lock has its own purpose as you explained, no body knows if the cases might arise that use kmemleak_lock and object_lock only w/o holding scan_mutex someday. I'm wondering how other folks think this case should be handled tho. > For object allocation (rbtree modification) and tree search, we use > kmemleak_lock. During scanning (which can take minutes under > scan_mutex), we want to prevent (a) long latencies and (b) freeing the > object being scanned. We release the locks regularly for (a) and hold > the object->lock for (b). > > In another thread Byungchul mentioned: > > | context X context Y > | > | lock mutex A lock mutex A > | lock B lock C > | lock C lock B > | unlock C unlock B > | unlock B unlock C > | unlock mutex A unlock mutex A > | > | In my opinion, lock B and lock C are unnecessary if they are always > | along with lock mutex A. Or we should keep correct lock order across all > | the code. > > If these are the only two places, yes, locks B and C would be > unnecessary. But we have those locks acquired (not nested) on the > allocation path (kmemleak_lock) and freeing path (object->lock). We > don't want to block those paths while scan_mutex is held. > > That said, we may be able to use a single kmemleak_lock for everything. > The object freeing path may be affected slightly during scanning but the > code does release it every MAX_SCAN_SIZE bytes. It may even get slightly > faster as we'd hammer a single lock (I'll do some benchmarks). > > But from a correctness perspective, I think the DEPT tool should be > improved a bit to detect when such out of order locking is serialised by > an enclosing lock/mutex. Again, I don't think this is a technical issue. Byungchul > > -- > Catalin