From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C6CCC6FD18 for ; Tue, 25 Apr 2023 15:03:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46C3D6B007E; Tue, 25 Apr 2023 11:03:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 41D176B0083; Tue, 25 Apr 2023 11:03:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2BCFE6B0085; Tue, 25 Apr 2023 11:03:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 1E5DD6B007E for ; Tue, 25 Apr 2023 11:03:50 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E09E9AC104 for ; Tue, 25 Apr 2023 15:03:49 +0000 (UTC) X-FDA: 80720232978.28.DE445B1 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf11.hostedemail.com (Postfix) with ESMTP id 60B2C4001E for ; Tue, 25 Apr 2023 15:03:46 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=j+PumkSX; spf=none (imf11.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682435027; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1+6DaEPXYHMcMl7eR6WzgMsRqfkoo2bM0HNxeyk154Y=; b=NofNTwcM3UNTy4df4Nzj5QuG3Ld3H0dxIlmOgO6xcf6V+GezRMeIPqTCiZ7TSnZMx4ULWj XumpDEAFAAGc6Qv+u0Lux7WEdrFb5ateSSKvahDIDRP28TGZyx7md4h0V1wO4yQIrXomTo TtYJLsFameTng+dvfeuNa9L/M+iq2N8= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=j+PumkSX; spf=none (imf11.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682435027; a=rsa-sha256; cv=none; b=Vt/Ys8kTD3TklpXK+lhG+/AZqUju6xom/kPPSWR+k/5wOJ32q0Dfn1vmaSO6DGFddZfRVx MSIoRgJahIWB7+bS+cDbe1gXTC29WQmTWn02KHLCC05chzzgEPPEqwaOlIIQABwMLrJH8C uWAiP/daYAh1x4We+GcPhqHfDc63w3A= 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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 60B2C4001E X-Stat-Signature: 4t4qrf9b84jshb9pp1mtnanegt9pyco4 X-HE-Tag: 1682435026-79459 X-HE-Meta: U2FsdGVkX1+A9Im8Yzrl172U89GgeIXfxomwwsm9UrlbITHrn3nFsEiushVgDfdWTTkuHcv3fnAWVMGnsDv314MwYqfLyYQIr0CCF5lTB+VPYZaTm8MnDklomr6Za2/3GFwZ3CFeSADUYVd+dpISdtWfokAFp/wgpM9/dpx9iDw4GRQKUvg98gMFM2M+mis8+FOk+lU30mNTpt2KfoULN+V4peOXmINPDtE5Vp79zGd3wDIKkJlNXnHLHoJfMckZO0bT6L+5m8WCWwoKrd9wFwP4PuaKojC94tFc8iy1ip/ONtMOPjHsACRZ2UVVkAG2yZQtwhc9ww02gfnue626AUoDbVBpfANeGh+UYtjvpVYLqDiuSs0YoGlRgBDcjss9zIcyRFLZGJ3iu7onjO1Qs0NNh+NWXXZ/vLjAZD9MWy+0iqimHD4hbrR1RcTMVMogd6ktHlI3YixmNGDUxltBPAoEZ1Tm3plABzPtV3lLwmbGHYi+l0Wry2E/TK1Tf4R3GsfxlAC+C6E23RnnI/ggtmFOZEsY3uH0rfJi1E6jII/+INUWtltfy/oI/sEymMpCdnR5N0fBD4Y7e9zEVhLnRfok4CnHAdbLUfs+cRP704HB0X0p48X1G+WQ8JBwKv8PBwwlyTIyArjUNXrmW9DwNL4l/okRD6j0uP2AWvdWsvlVDf8beBKpCMImCHkJ73hb0Os/M5iTfJDZrdg9rMNEINEB2BtZ+mhMq44OIcZqm+ferw5T4XpcsxDt4GvOd7Vz6Lo8Il5bW+oh4ypsOD3LgieYlFawj4t6oN/N0N40KiOob4Cl6NXFk8mhW1plFrewFMCKlk0/KodKpfCPkkkz/EbZ1Rn/T0iAh7mj+Qj6kuSBLXtfIg6OLv2fTtyG6Pf44UxDSYxk2XQGysdU6mvV+v71tyNX6nWIn/qIjKs6rgAf5iy5TfXAxGhmb2fEsX41cMbLPuRRXQemZerqQyJ 9H+yEH/t FOdaOkZh6lbIN47LnB1lrL/TqPa0e7YjjU9JGQZegXwHciUwxc5q+GhcXIYm32H4RzOUTLKHvmCDpuKhQS/a0MryKVtwwCmavIzAL3ZCWaOmjRsCxUKPXP25smNnf6LOmLScSw5wh6lwqRO3mR+11/SREcg0oDp4qNNvSPEfoOo+gkLl7wNfA2Ckx+MlZBmahklHS72NO5NH8sB2hSRM3yKCXookVoET7ZeAbAswfDqumNyaRH9yQ3ii/7O1v69vmK0Okm9EdWWDW91//jCkMY46cjnAz3m+OzSii2WHSGtHFiIA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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);