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 AD980C6FD18 for ; Tue, 25 Apr 2023 15:51:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 371276B007E; Tue, 25 Apr 2023 11:51:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 320F06B0080; Tue, 25 Apr 2023 11:51:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2104F6B0081; Tue, 25 Apr 2023 11:51:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 128746B007E for ; Tue, 25 Apr 2023 11:51:18 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BA20EA02DE for ; Tue, 25 Apr 2023 15:51:17 +0000 (UTC) X-FDA: 80720352594.22.1D192B3 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf14.hostedemail.com (Postfix) with ESMTP id C7E16100008 for ; Tue, 25 Apr 2023 15:51:14 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=cJ5gxBPG; spf=pass (imf14.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682437875; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SZl+g5Ej3CkAUwqlFRxFOmCl6XeGbuQoLBx1Ft1/RCU=; b=cBiAPscAm8bAxgUBvhkE/BDAHsiEbz1O2kPR3sH1Ips71ZIX1p4/3lyxYA2N1sfzNBBm1p t2SA3fjNg3yzN0z6ZMsSXV/dZdxqSGEfwjFNV1/0F5zsnzbm578afw0YE7TF1i3HHuJP7u 9UbSFviljprH0/vhlT1TF8j+htHgfLY= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=cJ5gxBPG; spf=pass (imf14.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682437875; a=rsa-sha256; cv=none; b=LmOZofcpAvuGsJ8ZNAZIOha7yTkOGWBYPLoOS8JcocqK7kVVY6D9CnI4GpN9hT+Xq8Olx8 HseqKSnhBVb2bBXrI0iIcyzlKAZ9ImIXQ9oRVMQzdbaxEvVsE8RDsYyYm3d4zRKljvBeiS rC8CXWpqtXOIID9/MCcJsBWVhW6Z4RE= Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-63b8b927f62so1346141b3a.0 for ; Tue, 25 Apr 2023 08:51:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1682437873; x=1685029873; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=SZl+g5Ej3CkAUwqlFRxFOmCl6XeGbuQoLBx1Ft1/RCU=; b=cJ5gxBPGIKAw3sdvDbTj+bK3aJIfweq4uAB6lOccOHM9LdZcHNzoR8dPgbBspjunjs pjHLL0dr5HfBzQdl654qH5q9X0tVUONRsAhBmrPfFMlgc95p5MClyxPJQbBQnvIVlhEB ZMkd6VPr3RvDsHwjyg103tk1p+ftXKelGp2YMRhztSX9ecV4LP06cWMpWtUkSNbQMfPk TNtTlC0LbK6xcLfVaaoXYwckSlCcm9ZWfU4jU7xs6Nv2Arg5iCY34BxsRW4PBdgGkrpb O7e9emnVnhyM9AYZNtwXthZQrOhzL+AmHQQVZKny9ZxZJmYDgrIHCds+CF/n3/g+o1tz mtVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682437873; x=1685029873; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SZl+g5Ej3CkAUwqlFRxFOmCl6XeGbuQoLBx1Ft1/RCU=; b=AmfUV7xeNwtAtfG0ihrZauC6Hf5K3i7BPWOAl5OMRJ8lre0n60LghgAKhLCcZUCPHx jNb6WxsPpkq4eWXu8lqTU+ZVIMltbTICLsHgPtabn+NPdIdLMsXMOw5JEGVil4+O9Suu DAtO713EvZz0bvPoq/BVnMborTMyeFZfHqPPWtQF/oHIfQlor8IbLwriN0Z3hIvyxx2h DosaXW4pMdgpHN91+tYJvWMwBo+6rUZZVjkEQqWFfHuMEpH9hyo+ywmUWlyN0KnTstu8 l/O1lgkbmpNC7UnlQ6eEauVg7iqyKSoO55jwpN+f50y03XVXSCIr/l+9iq72UkCicUGw Uxpg== X-Gm-Message-State: AAQBX9fpHqGcqCEMHNafa2m9B7aMKkMl52MUtzDGr5gB4/EKIFD1ohEb tfqNraPET1aaBo5QmrihxgdZbQ== X-Google-Smtp-Source: AKy350bQt2OWtuD2cw1VJuvsFt7QmKRbQ5gmHLaeqXNNtDF04owZbFxlEXRnL10oml1zPoRvhvWCyQ== X-Received: by 2002:a05:6a20:728a:b0:f1:c0a1:8035 with SMTP id o10-20020a056a20728a00b000f1c0a18035mr23888317pzk.0.1682437873258; Tue, 25 Apr 2023 08:51:13 -0700 (PDT) Received: from [10.200.11.243] ([139.177.225.234]) by smtp.gmail.com with ESMTPSA id w68-20020a636247000000b00520f4ecd71esm8193260pgb.93.2023.04.25.08.51.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 Apr 2023 08:51:12 -0700 (PDT) Message-ID: <6582d31f-e4d5-a982-4797-c22b2dd8b150@bytedance.com> Date: Tue, 25 Apr 2023 23:51:05 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH] mm: slub: annotate kmem_cache_node->list_lock as raw_spinlock To: Peter Zijlstra 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" 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> <20230425150313.GA1340063@hirez.programming.kicks-ass.net> Content-Language: en-US From: Qi Zheng In-Reply-To: <20230425150313.GA1340063@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C7E16100008 X-Stat-Signature: 6kiq45pr8n9g54b1a4sw4sxmih5gm4na X-Rspam-User: X-HE-Tag: 1682437874-186918 X-HE-Meta: U2FsdGVkX18tSogyB0V8+M/oRqbzJq9dYXBV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LD8KePynICa9aGHv+8c0fHOUpYyTjTzqVJYvBBXHVqdVL/1GEazv+WsfifoHqStST52htCew+ausrphDq7Du0sX5oUP6rgav4nf/Mwh3c4hgQOFDT5ETwNavKyRvPPjQEtlRESv+XVoSAxGdzchaZ8+2V1sSZisiymVrguYyAexvLrhD4ojFgRZdtxPair1VTHcsN7kXBM2ZA3txDNYyZqcVouw8cSwsEfapqWLewU69bEo0sCSIwKovJSzdly251E1woDwxL/gYxuS5wALNFIsxprzNsVBcU20zEoHiXIzEZDCbyEzq7lFaV6J8CQFumhQ1t7FStN9P7tviEm8K8h1vgmB834XDL1/3BEfUL0vftymYcrG9+e5gFo3oUkKBo6VHe4XAsZ7LvN9eqLr7uG+BvIu/w== 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 2023/4/25 23:03, Peter Zijlstra wrote: > 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). Oh, 'trylock' is a good idea. I just tested the following code and it can resolve the warning I encountered. :) Thanks, Qi > > --- > 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); > -- Thanks, Qi