From patchwork Fri Mar 4 07:06:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 12768590 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 D7E0EC433F5 for ; Fri, 4 Mar 2022 07:07:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 903588D0008; Fri, 4 Mar 2022 02:07:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 468C08D0010; Fri, 4 Mar 2022 02:07:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBD8D8D0001; Fri, 4 Mar 2022 02:07:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0135.hostedemail.com [216.40.44.135]) by kanga.kvack.org (Postfix) with ESMTP id E0AD08D0008 for ; Fri, 4 Mar 2022 02:07:10 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 79DBB181C49A4 for ; Fri, 4 Mar 2022 07:07:10 +0000 (UTC) X-FDA: 79205822220.27.6C5D000 Received: from lgeamrelo11.lge.com (lgeamrelo12.lge.com [156.147.23.52]) by imf13.hostedemail.com (Postfix) with ESMTP id A009420003 for ; Fri, 4 Mar 2022 07:07:08 +0000 (UTC) Received: from unknown (HELO lgemrelse6q.lge.com) (156.147.1.121) by 156.147.23.52 with ESMTP; 4 Mar 2022 16:07:06 +0900 X-Original-SENDERIP: 156.147.1.121 X-Original-MAILFROM: byungchul.park@lge.com Received: from unknown (HELO localhost.localdomain) (10.177.244.38) by 156.147.1.121 with ESMTP; 4 Mar 2022 16:07:06 +0900 X-Original-SENDERIP: 10.177.244.38 X-Original-MAILFROM: byungchul.park@lge.com From: Byungchul Park To: torvalds@linux-foundation.org Cc: 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, bfields@fieldses.org, 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: [PATCH v4 05/24] dept: Apply Dept to spinlock Date: Fri, 4 Mar 2022 16:06:24 +0900 Message-Id: <1646377603-19730-6-git-send-email-byungchul.park@lge.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1646377603-19730-1-git-send-email-byungchul.park@lge.com> References: <1646377603-19730-1-git-send-email-byungchul.park@lge.com> X-Rspamd-Queue-Id: A009420003 X-Stat-Signature: kt59e99kz7xeghp3nyjz3usz1wfkkw9d Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of byungchul.park@lge.com designates 156.147.23.52 as permitted sender) smtp.mailfrom=byungchul.park@lge.com; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1646377628-863185 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: Makes Dept able to track dependencies by spinlock. Signed-off-by: Byungchul Park --- include/linux/lockdep.h | 18 +++++++++++++++--- include/linux/spinlock.h | 26 ++++++++++++++++++++++++++ include/linux/spinlock_types_raw.h | 13 +++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index c1a56fe..529ea18 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -584,9 +584,21 @@ static inline void print_irqtrace_events(struct task_struct *curr) #define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 1, n, i) #define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 1, n, i) -#define spin_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) -#define spin_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i) -#define spin_release(l, i) lock_release(l, i) +#define spin_acquire(l, s, t, i) \ +do { \ + lock_acquire_exclusive(l, s, t, NULL, i); \ + dept_spin_lock(&(l)->dmap, s, t, NULL, "spin_unlock", i); \ +} while (0) +#define spin_acquire_nest(l, s, t, n, i) \ +do { \ + lock_acquire_exclusive(l, s, t, n, i); \ + dept_spin_lock(&(l)->dmap, s, t, (n) ? &(n)->dmap : NULL, "spin_unlock", i); \ +} while (0) +#define spin_release(l, i) \ +do { \ + lock_release(l, i); \ + dept_spin_unlock(&(l)->dmap, i); \ +} while (0) #define rwlock_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) #define rwlock_acquire_read(l, s, t, i) \ diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h index 5c0c517..6b5c3f4 100644 --- a/include/linux/spinlock.h +++ b/include/linux/spinlock.h @@ -95,6 +95,32 @@ # include #endif +#ifdef CONFIG_DEPT +#define dept_spin_lock(m, ne, t, n, e_fn, ip) \ +do { \ + if (t) { \ + dept_ecxt_enter(m, 1UL, ip, __func__, e_fn, ne); \ + dept_ask_event(m); \ + } else if (n) { \ + dept_skip(m); \ + } else { \ + dept_wait(m, 1UL, ip, __func__, ne); \ + dept_ecxt_enter(m, 1UL, ip, __func__, e_fn, ne); \ + dept_ask_event(m); \ + } \ +} while (0) +#define dept_spin_unlock(m, ip) \ +do { \ + if (!dept_unskip_if_skipped(m)) { \ + dept_event(m, 1UL, ip, __func__); \ + dept_ecxt_exit(m, ip); \ + } \ +} while (0) +#else +#define dept_spin_lock(m, ne, t, n, e_fn, ip) do { } while (0) +#define dept_spin_unlock(m, ip) do { } while (0) +#endif + #ifdef CONFIG_DEBUG_SPINLOCK extern void __raw_spin_lock_init(raw_spinlock_t *lock, const char *name, struct lock_class_key *key, short inner); diff --git a/include/linux/spinlock_types_raw.h b/include/linux/spinlock_types_raw.h index 91cb36b..279e821 100644 --- a/include/linux/spinlock_types_raw.h +++ b/include/linux/spinlock_types_raw.h @@ -26,16 +26,28 @@ #define SPINLOCK_OWNER_INIT ((void *)-1L) +#ifdef CONFIG_DEPT +# define RAW_SPIN_DMAP_INIT(lockname) .dmap = { .name = #lockname, .skip_cnt = ATOMIC_INIT(0) }, +# define SPIN_DMAP_INIT(lockname) .dmap = { .name = #lockname, .skip_cnt = ATOMIC_INIT(0) }, +# define LOCAL_SPIN_DMAP_INIT(lockname) .dmap = { .name = #lockname, .skip_cnt = ATOMIC_INIT(0) }, +#else +# define RAW_SPIN_DMAP_INIT(lockname) +# define SPIN_DMAP_INIT(lockname) +# define LOCAL_SPIN_DMAP_INIT(lockname) +#endif + #ifdef CONFIG_DEBUG_LOCK_ALLOC # define RAW_SPIN_DEP_MAP_INIT(lockname) \ .dep_map = { \ .name = #lockname, \ .wait_type_inner = LD_WAIT_SPIN, \ + RAW_SPIN_DMAP_INIT(lockname) \ } # define SPIN_DEP_MAP_INIT(lockname) \ .dep_map = { \ .name = #lockname, \ .wait_type_inner = LD_WAIT_CONFIG, \ + SPIN_DMAP_INIT(lockname) \ } # define LOCAL_SPIN_DEP_MAP_INIT(lockname) \ @@ -43,6 +55,7 @@ .name = #lockname, \ .wait_type_inner = LD_WAIT_CONFIG, \ .lock_type = LD_LOCK_PERCPU, \ + LOCAL_SPIN_DMAP_INIT(lockname) \ } #else # define RAW_SPIN_DEP_MAP_INIT(lockname)