Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1635749pxb; Wed, 9 Feb 2022 00:45:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJziNt5KtN+6VdQLyxpw5iC3/BnugS4wq4Nbfm8N18YzdGN2/027uowrVD6FssxbMELj9+VH X-Received: by 2002:a63:6942:: with SMTP id e63mr1079850pgc.226.1644396306969; Wed, 09 Feb 2022 00:45:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644396306; cv=none; d=google.com; s=arc-20160816; b=yiwguHVGU7I7DcbN/xHVlim5rPcbkmHwHKUamJq9L5LED1+MpDxa1tVtmYu1BZTZIR RlowIKgVNu1QAzAfdtV7eL/DHLJ7j80E9gTsYnLztxd1qFKJpHsAzR1CG6JqGMjTdDfw JVOGfpIn7aVCyhwl6JTvRmGRAYCwN0jLp4sUsIHltexI6iuV884xCM9Qpc6gJnYMr8g7 F6eQeEDDJZP+B7c3pUtQH4U5X9BoQNLRElAmbpqw9uC2TZMydCBtHIH3jbSOOIzX44vA L6dXLbHlAOxDxxHza6GD+zXvETENNGxr0EqyhpYlOGOIhnthheQcp3lY8TocCgrYvtJ+ WHQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=Yy80CGDeGmOdUiLaU44tdYuu65avXredLZvHqvqZxvA=; b=SjFeUK/yJYL/CDaUySgp8FMOwPNLe1pnxQUolUEcGhporYzYII1LB/jM2axtJqz4G7 qipxM51YOqdYK1PaT9hOSdvIoP0DXh2AfvIrRKzBYCMoY4Hy7KSyybA/zi6peEnX4GdS ErNJujYek7rC35s71FiSLgTFQseTNggCjvLe48aZmLpsJRM7ygzCEBuRokwbWE9e73gV vABj5xht9Uj6/vEyIHgqFoCtiR3Pp6rKmFSM9erK260zWYe8j0BlJ0aVqr87bbL1n33A Vf4r9oE+HZpg/OC6ASBlTvnxOwxgq/HajXC+0yfuZMHehOO4z4g1Wp/OI8Jy41OeNYAN ITJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HY74ArTf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x125si1080779pfb.169.2022.02.09.00.45.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 00:45:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HY74ArTf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B5CCDC0302CD; Wed, 9 Feb 2022 00:41:44 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240097AbiBHSnF (ORCPT + 99 others); Tue, 8 Feb 2022 13:43:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385192AbiBHSmf (ORCPT ); Tue, 8 Feb 2022 13:42:35 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A22AAC0613C9 for ; Tue, 8 Feb 2022 10:42:34 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id v13-20020a17090ac90d00b001b87bc106bdso2780112pjt.4 for ; Tue, 08 Feb 2022 10:42:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Yy80CGDeGmOdUiLaU44tdYuu65avXredLZvHqvqZxvA=; b=HY74ArTf2vfe81gaRsrqYSZLWy3/H/uLYAxkGNA5eJ1YodBldaI1Fleh4a0U0VLuEQ waa+glfVUrpkQfwXaA93xK2aiCn0HqUcLXTQ/oKcqc3eDtEtuDN3KLFz14ElozqV/pAO NUYTaN0/AzeEwY83KBHL6R2K10TJWsX7exn0l0YrDObSW6Ujo61OWuYT7wHlJWmcLomb 8VWB+4T3hTSeZK8F/gg/yXj1JM6K8ulRwATWXEuSsW4LP1R1IqHzJro5RV5+z52+67QR vtBlkRXMCLZrYZXVXO/qnBpqAVqrIRUl/q7dlrSwZybH+SVSLmxbIgE8uV670YHX/aW2 voIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Yy80CGDeGmOdUiLaU44tdYuu65avXredLZvHqvqZxvA=; b=d0CB81DL4L9DZ4O0cXK7Y3PF4i4zNw+XL8YcZ7jO4y8ehpw5Na3dZ1dp+3KZfG9IHn cBdGZH4JaC+CbROXrbDyhUsJ/GMQdKQxKCSXBJnH3IKwsLiBLDYMtU8M+3bv4aGz0oM0 cB8uOnvIkNnkpKQ6Yn46alQxER89rNINtK8U1WDe7OmDWhexND+c4ONvF7LCiSy1KniP nZ/SD5wZ0wjhHZ34iOmlp6IlIrbrGem9LjkS07KziD3PYHPub3jndPkNGvfyZZagTNfF 305yJaj8rwhHBUNF7RlW6/3pJxGRPutLVW9EmUsbNY65QXhEegD2m9c9vyF1Rf3koN4E OE2g== X-Gm-Message-State: AOAM532l0b7rka07FEeSjnHAQzFcFoU0CfBHMddPtVmgjgEhiKA3IzVE tEF+MoRlCc5MHcctmC340Ec= X-Received: by 2002:a17:902:da85:: with SMTP id j5mr5683614plx.81.1644345754103; Tue, 08 Feb 2022 10:42:34 -0800 (PST) Received: from balhae.hsd1.ca.comcast.net ([2601:647:4800:c6f0:347f:e607:176:4358]) by smtp.gmail.com with ESMTPSA id l14sm3517027pjf.1.2022.02.08.10.42.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 10:42:33 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng Cc: LKML , Thomas Gleixner , Steven Rostedt , Byungchul Park , "Paul E. McKenney" , Mathieu Desnoyers , Radoslaw Burny Subject: [PATCH 09/12] locking: Add more static lockdep init macros Date: Tue, 8 Feb 2022 10:42:05 -0800 Message-Id: <20220208184208.79303-10-namhyung@kernel.org> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220208184208.79303-1-namhyung@kernel.org> References: <20220208184208.79303-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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-kernel@vger.kernel.org Add STATIC_LOCKDEP_MAP_INIT_{WAIT,TYPE} macros and use it for various lock init codes. This helps having different implementations of CONFIG_LOCK_INFO like lockdep and tracepoints. Signed-off-by: Namhyung Kim --- drivers/gpu/drm/drm_connector.c | 5 ++--- include/linux/local_lock_internal.h | 10 ++++------ include/linux/lockdep.h | 23 +++++++++++++++++------ include/linux/mutex.h | 6 ++---- include/linux/rtmutex.h | 8 +++----- include/linux/rwlock_types.h | 5 +---- include/linux/rwsem.h | 8 +++----- include/linux/spinlock_types_raw.h | 24 ++++++++---------------- kernel/printk/printk.c | 10 ++++------ kernel/rcu/update.c | 27 +++++++++------------------ mm/memcontrol.c | 5 ++--- 11 files changed, 55 insertions(+), 76 deletions(-) diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index 94931b32a491..7f470de2ef2b 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -677,9 +677,8 @@ const char *drm_get_connector_force_name(enum drm_connector_force force) } #ifdef CONFIG_LOCK_INFO -static struct lockdep_map connector_list_iter_dep_map = { - .name = "drm_connector_list_iter" -}; +static struct lockdep_map connector_list_iter_dep_map = + STATIC_LOCKDEP_MAP_INIT("drm_connector_list_iter", NULL); #endif /** diff --git a/include/linux/local_lock_internal.h b/include/linux/local_lock_internal.h index 56f03f588aa7..dd280fcfadec 100644 --- a/include/linux/local_lock_internal.h +++ b/include/linux/local_lock_internal.h @@ -16,12 +16,10 @@ typedef struct { } local_lock_t; #ifdef CONFIG_LOCK_INFO -# define LOCAL_LOCK_DEBUG_INIT(lockname) \ - .dep_map = { \ - .name = #lockname, \ - .wait_type_inner = LD_WAIT_CONFIG, \ - .lock_type = LD_LOCK_PERCPU, \ - }, \ +# define LOCAL_LOCK_DEBUG_INIT(lockname) \ + .dep_map = STATIC_LOCKDEP_MAP_INIT_TYPE(#lockname, NULL, \ + LD_WAIT_CONFIG, LD_WAIT_INV, \ + LD_LOCK_PERCPU), \ .owner = NULL, static inline void local_lock_acquire(local_lock_t *l) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index 0cc2b338a006..38cbef7601c7 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -237,6 +237,19 @@ static inline void lockdep_init_map(struct lockdep_map *lock, const char *name, #define lockdep_set_novalidate_class(lock) \ lockdep_set_class_and_name(lock, &__lockdep_no_validate__, #lock) +/* + * To initialize a lockdep_map statically use this macro. + * Note that _name must not be NULL. + */ +#define STATIC_LOCKDEP_MAP_INIT(_name, _key) \ + { .name = (_name), .key = (void *)(_key), } + +#define STATIC_LOCKDEP_MAP_INIT_WAIT(_name, _key, _inner) \ + { .name = (_name), .key = (void *)(_key), .wait_type_inner = (_inner), } + +#define STATIC_LOCKDEP_MAP_INIT_TYPE(_name, _key, _inner, _outer, _type) \ + { .name = (_name), .key = (void *)(_key), .wait_type_inner = (_inner), \ + .wait_type_outer = (_outer), .lock_type = (_type), } /* * Compare locking classes */ @@ -377,6 +390,10 @@ static inline void lockdep_set_selftest_task(struct task_struct *task) #define lockdep_set_novalidate_class(lock) do { } while (0) +#define STATIC_LOCKDEP_MAP_INIT(_name, _key) { } +#define STATIC_LOCKDEP_MAP_INIT_WAIT(_name, _key, _inner) { } +#define STATIC_LOCKDEP_MAP_INIT_TYPE(_name, _key, _inner, _outer, _type) { } + /* * We don't define lockdep_match_class() and lockdep_match_key() for !LOCKDEP * case since the result is not well defined and the caller should rather @@ -432,12 +449,6 @@ enum xhlock_context_t { }; #define lockdep_init_map_crosslock(m, n, k, s) do {} while (0) -/* - * To initialize a lockdep_map statically use this macro. - * Note that _name must not be NULL. - */ -#define STATIC_LOCKDEP_MAP_INIT(_name, _key) \ - { .name = (_name), .key = (void *)(_key), } static inline void lockdep_invariant_state(bool force) {} static inline void lockdep_free_task(struct task_struct *task) {} diff --git a/include/linux/mutex.h b/include/linux/mutex.h index 369c1abbf3d0..b2d018250a41 100644 --- a/include/linux/mutex.h +++ b/include/linux/mutex.h @@ -22,10 +22,8 @@ #ifdef CONFIG_LOCK_INFO # define __DEP_MAP_MUTEX_INITIALIZER(lockname) \ - , .dep_map = { \ - .name = #lockname, \ - .wait_type_inner = LD_WAIT_SLEEP, \ - } + , .dep_map = STATIC_LOCKDEP_MAP_INIT_WAIT(#lockname, \ + NULL, LD_WAIT_SLEEP) #else # define __DEP_MAP_MUTEX_INITIALIZER(lockname) #endif diff --git a/include/linux/rtmutex.h b/include/linux/rtmutex.h index 8eafdd6dcf35..887ffcd5fc09 100644 --- a/include/linux/rtmutex.h +++ b/include/linux/rtmutex.h @@ -77,11 +77,9 @@ do { \ } while (0) #ifdef CONFIG_LOCK_INFO -#define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \ - .dep_map = { \ - .name = #mutexname, \ - .wait_type_inner = LD_WAIT_SLEEP, \ - } +#define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) \ + .dep_map = STATIC_LOCKDEP_MAP_INIT_WAIT(#mutexname, \ + NULL, LD_WAIT_SLEEP) #else #define __DEP_MAP_RT_MUTEX_INITIALIZER(mutexname) #endif diff --git a/include/linux/rwlock_types.h b/include/linux/rwlock_types.h index 3e621bfd7cd0..438d8639a229 100644 --- a/include/linux/rwlock_types.h +++ b/include/linux/rwlock_types.h @@ -7,10 +7,7 @@ #ifdef CONFIG_LOCK_INFO # define RW_DEP_MAP_INIT(lockname) \ - .dep_map = { \ - .name = #lockname, \ - .wait_type_inner = LD_WAIT_CONFIG, \ - } + .dep_map = STATIC_LOCKDEP_MAP_INIT_WAIT(#lockname, NULL, LD_WAIT_CONFIG) #else # define RW_DEP_MAP_INIT(lockname) #endif diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h index c488485861f5..39126e6d97a1 100644 --- a/include/linux/rwsem.h +++ b/include/linux/rwsem.h @@ -17,11 +17,9 @@ #include #ifdef CONFIG_LOCK_INFO -# define __RWSEM_DEP_MAP_INIT(lockname) \ - .dep_map = { \ - .name = #lockname, \ - .wait_type_inner = LD_WAIT_SLEEP, \ - }, +# define __RWSEM_DEP_MAP_INIT(lockname) \ + .dep_map = STATIC_LOCKDEP_MAP_INIT_WAIT(#lockname, \ + NULL, LD_WAIT_SLEEP), #else # define __RWSEM_DEP_MAP_INIT(lockname) #endif diff --git a/include/linux/spinlock_types_raw.h b/include/linux/spinlock_types_raw.h index 564092a30cc4..006250640e76 100644 --- a/include/linux/spinlock_types_raw.h +++ b/include/linux/spinlock_types_raw.h @@ -27,23 +27,15 @@ typedef struct raw_spinlock { #define SPINLOCK_OWNER_INIT ((void *)-1L) #ifdef CONFIG_LOCK_INFO -# define RAW_SPIN_DEP_MAP_INIT(lockname) \ - .dep_map = { \ - .name = #lockname, \ - .wait_type_inner = LD_WAIT_SPIN, \ - } -# define SPIN_DEP_MAP_INIT(lockname) \ - .dep_map = { \ - .name = #lockname, \ - .wait_type_inner = LD_WAIT_CONFIG, \ - } +# define RAW_SPIN_DEP_MAP_INIT(lockname) \ + .dep_map = STATIC_LOCKDEP_MAP_INIT_WAIT(#lockname, NULL, LD_WAIT_SPIN) -# define LOCAL_SPIN_DEP_MAP_INIT(lockname) \ - .dep_map = { \ - .name = #lockname, \ - .wait_type_inner = LD_WAIT_CONFIG, \ - .lock_type = LD_LOCK_PERCPU, \ - } +# define SPIN_DEP_MAP_INIT(lockname) \ + .dep_map = STATIC_LOCKDEP_MAP_INIT_WAIT(#lockname, NULL, LD_WAIT_CONFIG) + +# define LOCAL_SPIN_DEP_MAP_INIT(lockname) \ + .dep_map = STATIC_LOCKDEP_MAP_INIT_TYPE(#lockname, NULL, LD_WAIT_CONFIG,\ + LD_WAIT_INV, LD_LOCK_PERCPU) #else # define RAW_SPIN_DEP_MAP_INIT(lockname) # define SPIN_DEP_MAP_INIT(lockname) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index e45664e0ca30..7889df01a378 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -94,9 +94,8 @@ EXPORT_SYMBOL_GPL(console_drivers); int __read_mostly suppress_printk; #ifdef CONFIG_LOCK_INFO -static struct lockdep_map console_lock_dep_map = { - .name = "console_lock" -}; +static struct lockdep_map console_lock_dep_map = + STATIC_LOCKDEP_MAP_INIT("console_lock", NULL); #endif enum devkmsg_log_bits { @@ -1753,9 +1752,8 @@ SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len) */ #ifdef CONFIG_LOCK_INFO -static struct lockdep_map console_owner_dep_map = { - .name = "console_owner" -}; +static struct lockdep_map console_owner_dep_map = + STATIC_LOCKDEP_MAP_INIT("console_owner", NULL); #endif static DEFINE_RAW_SPINLOCK(console_owner_lock); diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c index 156892c22bb5..8202ab6ddb4c 100644 --- a/kernel/rcu/update.c +++ b/kernel/rcu/update.c @@ -243,30 +243,21 @@ core_initcall(rcu_set_runtime_mode); #ifdef CONFIG_DEBUG_LOCK_ALLOC static struct lock_class_key rcu_lock_key; -struct lockdep_map rcu_lock_map = { - .name = "rcu_read_lock", - .key = &rcu_lock_key, - .wait_type_outer = LD_WAIT_FREE, - .wait_type_inner = LD_WAIT_CONFIG, /* PREEMPT_RT implies PREEMPT_RCU */ -}; +struct lockdep_map rcu_lock_map = /* PREEMPT_RT implies PREEMPT_RCU */ + STATIC_LOCKDEP_MAP_INIT_TYPE("rcu_read_lock", &rcu_lock_key, + LD_WAIT_CONFIG, LD_WAIT_FREE, 0); EXPORT_SYMBOL_GPL(rcu_lock_map); static struct lock_class_key rcu_bh_lock_key; -struct lockdep_map rcu_bh_lock_map = { - .name = "rcu_read_lock_bh", - .key = &rcu_bh_lock_key, - .wait_type_outer = LD_WAIT_FREE, - .wait_type_inner = LD_WAIT_CONFIG, /* PREEMPT_RT makes BH preemptible. */ -}; +struct lockdep_map rcu_bh_lock_map = /* PREEMPT_RT makes BH preemptable. */ + STATIC_LOCKDEP_MAP_INIT_TYPE("rcu_read_lock_bh", &rcu_bh_lock_key, + LD_WAIT_CONFIG, LD_WAIT_FREE, 0); EXPORT_SYMBOL_GPL(rcu_bh_lock_map); static struct lock_class_key rcu_sched_lock_key; -struct lockdep_map rcu_sched_lock_map = { - .name = "rcu_read_lock_sched", - .key = &rcu_sched_lock_key, - .wait_type_outer = LD_WAIT_FREE, - .wait_type_inner = LD_WAIT_SPIN, -}; +struct lockdep_map rcu_sched_lock_map = + STATIC_LOCKDEP_MAP_INIT_TYPE("rcu_read_lock_sched", &rcu_sched_lock_key, + LD_WAIT_SPIN, LD_WAIT_FREE, 0); EXPORT_SYMBOL_GPL(rcu_sched_lock_map); // Tell lockdep when RCU callbacks are being invoked. diff --git a/mm/memcontrol.c b/mm/memcontrol.c index d4ecfdd5eb8f..a561a6c66b2f 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1672,9 +1672,8 @@ static int mem_cgroup_soft_reclaim(struct mem_cgroup *root_memcg, } #ifdef CONFIG_LOCK_INFO -static struct lockdep_map memcg_oom_lock_dep_map = { - .name = "memcg_oom_lock", -}; +static struct lockdep_map memcg_oom_lock_dep_map = + STATIC_LOCKDEP_MAP_INIT("memcg_oom_lock", NULL); #endif static DEFINE_SPINLOCK(memcg_oom_lock); -- 2.35.0.263.gb82422642f-goog