From patchwork Mon Feb 28 09:56:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 12762651 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 BE357C433FE for ; Mon, 28 Feb 2022 09:57:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D82478D0005; Mon, 28 Feb 2022 04:57:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B6B348D0003; Mon, 28 Feb 2022 04:57:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FFA68D0003; Mon, 28 Feb 2022 04:57:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0167.hostedemail.com [216.40.44.167]) by kanga.kvack.org (Postfix) with ESMTP id 2F9F48D0003 for ; Mon, 28 Feb 2022 04:57:23 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id DD0D79C164 for ; Mon, 28 Feb 2022 09:57:22 +0000 (UTC) X-FDA: 79191735924.31.29144E4 Received: from lgeamrelo11.lge.com (lgeamrelo12.lge.com [156.147.23.52]) by imf03.hostedemail.com (Postfix) with ESMTP id 0855220002 for ; Mon, 28 Feb 2022 09:57:20 +0000 (UTC) Received: from unknown (HELO lgemrelse6q.lge.com) (156.147.1.121) by 156.147.23.52 with ESMTP; 28 Feb 2022 18:57:19 +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; 28 Feb 2022 18:57:19 +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 v3 05/21] dept: Apply Dept to spinlock Date: Mon, 28 Feb 2022 18:56:44 +0900 Message-Id: <1646042220-28952-6-git-send-email-byungchul.park@lge.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1646042220-28952-1-git-send-email-byungchul.park@lge.com> References: <1646042220-28952-1-git-send-email-byungchul.park@lge.com> X-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: 8qjomk6o6yaespuk7cw3a71hd1fuy6qb Authentication-Results: imf03.hostedemail.com; dkim=none; spf=pass (imf03.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-Rspamd-Queue-Id: 0855220002 X-HE-Tag: 1646042240-464119 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)