Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7102141rwr; Tue, 25 Apr 2023 08:07:49 -0700 (PDT) X-Google-Smtp-Source: AKy350aZEnn378sa348TNemDJ8qHWmHSetQe4Y8+j0QLYUNhomXEwr7WMLPTGHwdm5U/6dSAPron X-Received: by 2002:a05:6a21:3286:b0:f2:6fc6:9ca3 with SMTP id yt6-20020a056a21328600b000f26fc69ca3mr18748494pzb.43.1682435268434; Tue, 25 Apr 2023 08:07:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682435268; cv=none; d=google.com; s=arc-20160816; b=ua0sGLnx2wlT6SQ0jo4v9hOqRLFwyi9KARjJB5+KEskTtAPldcHYm9lUy5haNnTaJu 2VYGFYPUFKd6Tipi90Wy/siK6Vr8PsgCg/4lqBh5Qy+zeMgmGuXMEVSs2d2lJduevfuH 5wlY/5jY6+6Z+N1830qK2eou+dTDhNfE8LLPTkZP1BzK8DbLuXpgNwilub8ElOI6JUps w7V8kbqK4kePYbAl8HCX4VqpTk6VNwYIfbJZMTga7+pH4V7rZudxfEuefc90pCcfwPUq E/SeqJedJlGaNqF3U5iG04tMcWo3Ul4PB3Y8d/M0QbTwdiK1GpYCNT0ZancZtgrxbeHc yo/g== 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=1+6DaEPXYHMcMl7eR6WzgMsRqfkoo2bM0HNxeyk154Y=; b=Wv9IlKM4fVtm5j8xDCJBD0CIuW0MjqRLTKT/GSRM3gYhalw4GQiH70I77k03ima4Uq oJAZaqqq+sGo+7+MQZXYt5z0aS/NMtKyf+1/Y+UyBdn52s0UM13aCHEIqAIiXEVY5OO8 Vq9HXN/3zM5BW5VSsCgqP9L7JBxrmmCa0nupE81qmfCr+Fc3r+cNM2v7P3N07dWbRFSD DSlEZaXtXmKO8FDBHHrWqnlOeY6wTsMnAiYz49mEx6ZOwwsuDaK9D+yjF7owg8TInJaF H1JCrnkRpH1zysoNcoWggGVq7KnwWq/uXbFfAsLQpKDBz2nc3mL0yXlYvJ8ODsOoaZ73 Xx7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=j+PumkSX; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e5-20020a656885000000b0051f045555b6si13360322pgt.601.2023.04.25.08.07.29; Tue, 25 Apr 2023 08:07:48 -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; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=j+PumkSX; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234217AbjDYPEE (ORCPT + 99 others); Tue, 25 Apr 2023 11:04:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233991AbjDYPED (ORCPT ); Tue, 25 Apr 2023 11:04:03 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 196B549CD; Tue, 25 Apr 2023 08:04:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=1+6DaEPXYHMcMl7eR6WzgMsRqfkoo2bM0HNxeyk154Y=; b=j+PumkSXIuBZmMCfBPGIHq3ydO /LANrH3KDvsJUHdx4Jbb8y9XwEoqXfUDXZU2RYIoBpyk0yf+mX3+n5HP2hEvL0rD40kLaNuWj4hxc qx2M1oozCWl+/tO3losXPI4v8Hvejv99QQyj2a8iL2ZfVKSwQT+a3DNO9Ont025pyiM61mozHqiKA /XoDZarlce1egdpyBUipmX4hpnLVUZRduZ9WhBaj74ADClKgCflA7efScPb6ewXuClq//fexMzNj7 h9Pns1HDIQsO4d52wk9q7orGSj8CusfSLjfy/BW2dzW4XuSjGpb1hxEkqYDHdz2nk4WZmZ78KR51n kGszkf/g==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1prKCK-009fx4-2P; Tue, 25 Apr 2023 15:03:17 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id B368F3000D5; Tue, 25 Apr 2023 17:03:13 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 7A3BC31C76403; Tue, 25 Apr 2023 17:03:13 +0200 (CEST) Date: Tue, 25 Apr 2023 17:03:13 +0200 From: Peter Zijlstra To: Qi Zheng Cc: Vlastimil Babka , "Zhang, Qiang1" , Boqun Feng , "42.hyeyoo@gmail.com" <42.hyeyoo@gmail.com>, "akpm@linux-foundation.org" , "roman.gushchin@linux.dev" , "iamjoonsoo.kim@lge.com" , "rientjes@google.com" , "penberg@kernel.org" , "cl@linux.com" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Zhao Gongyi , Sebastian Andrzej Siewior , Thomas Gleixner , RCU , "Paul E . McKenney" Subject: Re: [PATCH] mm: slub: annotate kmem_cache_node->list_lock as raw_spinlock Message-ID: <20230425150313.GA1340063@hirez.programming.kicks-ass.net> References: <932bf921-a076-e166-4f95-1adb24d544cf@bytedance.com> <20230412124735.GE628377@hirez.programming.kicks-ass.net> <76e15f10-d3f1-2cab-63cb-25aa3b4f2cd4@bytedance.com> <20230413074013.GD4253@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230413074013.GD4253@hirez.programming.kicks-ass.net> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Thu, Apr 13, 2023 at 09:40:13AM +0200, Peter Zijlstra wrote: > On Thu, Apr 13, 2023 at 12:44:42AM +0800, Qi Zheng wrote: > > > Something like the completely untested below might be of help.. > > > I just tested the above code, and then got the following > > warning: > > > > > It seems that the LD_WAIT_SLEEP we set is already greater than the > > LD_WAIT_SPIN of the current context. > > Yeah, I'm an idiot and got it wrong.. I'll try again later if I manage > to wake up today :-) And then I forgot ofcourse :/ Can you give the below (still mostly untested) a spin? The crucial difference is the new lock_map_acquire_try(). By making the annotation a 'trylock' it will skip the acquire of the annotation itself (since trylocks don't block). --- diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index 1023f349af71..435a3b0f8ea6 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -551,6 +551,7 @@ do { \ #define rwsem_release(l, i) lock_release(l, i) #define lock_map_acquire(l) lock_acquire_exclusive(l, 0, 0, NULL, _THIS_IP_) +#define lock_map_acquire_try(l) lock_acquire_exclusive(l, 0, 1, NULL, _THIS_IP_) #define lock_map_acquire_read(l) lock_acquire_shared_recursive(l, 0, 0, NULL, _THIS_IP_) #define lock_map_acquire_tryread(l) lock_acquire_shared_recursive(l, 0, 1, NULL, _THIS_IP_) #define lock_map_release(l) lock_release(l, _THIS_IP_) diff --git a/include/linux/lockdep_types.h b/include/linux/lockdep_types.h index d22430840b53..f3120d6a7d9e 100644 --- a/include/linux/lockdep_types.h +++ b/include/linux/lockdep_types.h @@ -33,6 +33,7 @@ enum lockdep_wait_type { enum lockdep_lock_type { LD_LOCK_NORMAL = 0, /* normal, catch all */ LD_LOCK_PERCPU, /* percpu */ + LD_LOCK_WAIT, /* annotation */ LD_LOCK_MAX, }; diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 50d4863974e7..d254f9e53c0e 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -2253,6 +2253,9 @@ static inline bool usage_match(struct lock_list *entry, void *mask) static inline bool usage_skip(struct lock_list *entry, void *mask) { + if (entry->class->lock_type == LD_LOCK_NORMAL) + return false; + /* * Skip local_lock() for irq inversion detection. * @@ -2279,14 +2282,11 @@ static inline bool usage_skip(struct lock_list *entry, void *mask) * As a result, we will skip local_lock(), when we search for irq * inversion bugs. */ - if (entry->class->lock_type == LD_LOCK_PERCPU) { - if (DEBUG_LOCKS_WARN_ON(entry->class->wait_type_inner < LD_WAIT_CONFIG)) - return false; - - return true; - } + if (entry->class->lock_type == LD_LOCK_PERCPU && + DEBUG_LOCKS_WARN_ON(entry->class->wait_type_inner < LD_WAIT_CONFIG)) + return false; - return false; + return true; } /* @@ -4752,7 +4752,8 @@ static int check_wait_context(struct task_struct *curr, struct held_lock *next) for (; depth < curr->lockdep_depth; depth++) { struct held_lock *prev = curr->held_locks + depth; - u8 prev_inner = hlock_class(prev)->wait_type_inner; + struct lock_class *class = hlock_class(prev); + u8 prev_inner = class->wait_type_inner; if (prev_inner) { /* @@ -4762,6 +4763,12 @@ static int check_wait_context(struct task_struct *curr, struct held_lock *next) * Also due to trylocks. */ curr_inner = min(curr_inner, prev_inner); + + /* + * Allow override for annotations. + */ + if (unlikely(class->lock_type == LD_LOCK_WAIT)) + curr_inner = prev_inner; } } diff --git a/lib/debugobjects.c b/lib/debugobjects.c index df86e649d8be..0e089882146b 100644 --- a/lib/debugobjects.c +++ b/lib/debugobjects.c @@ -565,8 +565,16 @@ __debug_object_init(void *addr, const struct debug_obj_descr *descr, int onstack * On RT enabled kernels the pool refill must happen in preemptible * context: */ - if (!IS_ENABLED(CONFIG_PREEMPT_RT) || preemptible()) + if (!IS_ENABLED(CONFIG_PREEMPT_RT) || preemptible()) { + static struct lockdep_map dep_map = { + .name = "wait-type-override", + .wait_type_inner = LD_WAIT_SLEEP, + .lock_type = LD_LOCK_WAIT, + }; + lock_map_acquire_try(&dep_map); fill_pool(); + lock_map_release(&dep_map); + } db = get_bucket((unsigned long) addr);