Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1278967iob; Thu, 19 May 2022 03:20:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQseHuCbjXBFoS/wNRSbM+OpMnOk+v6HLXKmbPFmx0v23zrgQrHXbF8OEAe9XWvbXPFiFx X-Received: by 2002:a05:6402:741:b0:42a:8fad:8f67 with SMTP id p1-20020a056402074100b0042a8fad8f67mr4375868edy.285.1652955655835; Thu, 19 May 2022 03:20:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652955655; cv=none; d=google.com; s=arc-20160816; b=i4A0sEM3l3A4n4/UphIivSHZriZLlY/jsnbp5hiNB0TCPYHo7I/e6gyzvdpwyO6oqG OMcWABwvoUjEm2oWv8TAmyeHn/N9Y9vpi2jR8VeWYV/+BB9Chxtz2TLxT1U/DoIr5vwe 9XWzvscPo4I8+bOBuYi39UHEneGimaiHnnb51baIDBdmxPw+J+qp9TMZwAiM3gIvJJK+ B7GwJ3yKexMlRZuR1SHQ+OHOYDxZCiEiIsK1hky+GCSOdcvRQtcuVhP9CylVWHtchmlY 9yH4fMsty3MAgT+GL+6C7ZC3XgKrEa/fihkQcMs9WhJLCh+8g8nSTt2RlPnb9ixzzGYF xAfw== 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; bh=CFKeS4oNmfHe0X/6jN/He+N5VW12UarVP4nKiDCO12U=; b=SRLs/VaP/SAvbGVlVEwXV97B7HyCCjT2yIMQVKHYK6O8zhvHUWIoqkzKT6xjFoLds3 LK06buDFmkJCi0flQmUYLZblgTs/9BMD6uaAcv6x3jPwcjOROKljs3uOLYTNBV905LqO yYnNQEtG3GsWuBfKTmc8LrjtxvdV8sZg6ahi4ehu9HPHdiw/GFAq48SGLRXLo/SVQtkv h3ZUb3mIM8oOR40xHI7EkV1rpPGS67EXGOi0EINHwVtwuzqtpY/kDwBPOazmmPLLSAZ3 AxCqH7kJmdi8pKttORYtv8mkxDp8cetyDSutkWJz5i/c90W5sszjeHnXYLRxAuo0nT7u kzKw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w6-20020aa7cb46000000b0041d7dba939asi4421355edt.170.2022.05.19.03.20.29; Thu, 19 May 2022 03:20:55 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236588AbiESKL2 (ORCPT + 99 others); Thu, 19 May 2022 06:11:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236578AbiESKL1 (ORCPT ); Thu, 19 May 2022 06:11:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C05A33A22; Thu, 19 May 2022 03:11:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 72B3D619A6; Thu, 19 May 2022 10:11:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A385C385AA; Thu, 19 May 2022 10:11:14 +0000 (UTC) Date: Thu, 19 May 2022 11:11:10 +0100 From: Catalin Marinas To: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: Byungchul Park , 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: 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: X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 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. 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. -- Catalin