From patchwork Wed Jan 24 11:59:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungchul Park X-Patchwork-Id: 13529071 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 71927C46CD2 for ; Wed, 24 Jan 2024 12:00:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0E086B0087; Wed, 24 Jan 2024 06:59:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DBE0E6B0088; Wed, 24 Jan 2024 06:59:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE7CE6B0089; Wed, 24 Jan 2024 06:59:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A5D226B0087 for ; Wed, 24 Jan 2024 06:59:56 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7A5811A02C2 for ; Wed, 24 Jan 2024 11:59:56 +0000 (UTC) X-FDA: 81714060792.04.AEB1EA0 Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf24.hostedemail.com (Postfix) with ESMTP id 940B118001E for ; Wed, 24 Jan 2024 11:59:54 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706097595; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=wYwglYqfeifxk6lW+gBTi4yrQI/O7ARWxzTDfqjUyi8=; b=12E0UUH32Kgnku/yV2N2eh1vX+S+qDJ7a5JVT8ua94T5WYKNr+6oIHEw+63WelQSDxJIRH 9NVZ3IIYo8bK6yLGk1SpE/GAp/f5e5I4P5CkRTHu7vsBdV6ciUF/vWU91bfiR0A5n1EMba a2Jzk5US/I+U8bRIi+CP0Y+Nhbkw870= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706097595; a=rsa-sha256; cv=none; b=ImktBUL8xuKI68KsKQDlms0NMvDCzmXLiudkCUJxB7eH4+LmOikznrTDB6tl3IFPrvaATW YK0ElhMF66gEdJjr5ZfKGw3IdrdyvT7kQy7GoMsjU33UxsTseCvYMd8qvywzCQmLKJWKVt 1hBoWxj0EcqyXpasuMd0WmmLSAv/0jg= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com; dmarc=none X-AuditID: a67dfc5b-d85ff70000001748-82-65b0fbb4b9cc From: Byungchul Park To: linux-kernel@vger.kernel.org Cc: kernel_team@skhynix.com, torvalds@linux-foundation.org, damien.lemoal@opensource.wdc.com, linux-ide@vger.kernel.org, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, will@kernel.org, tglx@linutronix.de, rostedt@goodmis.org, joel@joelfernandes.org, sashal@kernel.org, daniel.vetter@ffwll.ch, duyuyang@gmail.com, johannes.berg@intel.com, tj@kernel.org, tytso@mit.edu, willy@infradead.org, david@fromorbit.com, amir73il@gmail.com, 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, josef@toxicpanda.com, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, jlayton@kernel.org, dan.j.williams@intel.com, hch@infradead.org, djwong@kernel.org, dri-devel@lists.freedesktop.org, rodrigosiqueiramelo@gmail.com, melissa.srw@gmail.com, hamohammed.sa@gmail.com, 42.hyeyoo@gmail.com, chris.p.wilson@intel.com, gwan-gyeong.mun@intel.com, max.byungchul.park@gmail.com, boqun.feng@gmail.com, longman@redhat.com, hdanton@sina.com, her0gyugyu@gmail.com Subject: [PATCH v11 04/26] dept: Add lock dependency tracker APIs Date: Wed, 24 Jan 2024 20:59:15 +0900 Message-Id: <20240124115938.80132-5-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240124115938.80132-1-byungchul@sk.com> References: <20240124115938.80132-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAAzWSa0hTcRjG+5/rtloc1sWjBcVKutEVq5eIMLodCKEoghKqoYccXptpGUQr tzIvpXmZN0Kt1piaaxp4WyxFzUS3ctWyaWZRmVuWtqFOrWn15eUHz8OP58MrwCUNZIBAHnOO V8TIoqSUiBC55pWuf+w18JuKMiSQlb4J3L9SCCiuqqDA+rAcQUXNFQwGWw7AG48TgbfTgoMm 14qg9EMvDjWtfQhMuqsUdH+aDzb3MAXtuWkUJN+touDF0CQGjrzbGJQbQ6AjswwD8/gXAjSD FBRpkjHf+YrBuFZPg1YZCAO6QhomP2yG9r7XJJh61kHBHQcFjaZ2AlprBzDori+moK/iNwkd rc8IsGZlkFD5vYyCIY8WB617mIaX5hIMDCqf6NroNAltGWYMrt17hIHtbQOCJyn9GBgrXlPQ 7HZiUG3MxWHiQQuCgZsuGtTp4zQUXbmJIE2dR4Blqo0ElWMreMeKqeAdXLNzGOdU1ec5k6eE 4J6XsVxdYS/NqZ700F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LRmC8kk7C61/NFBg6FeD+kU3vCBIahscIwWCL EuomcknhWT4vVGd+ZATDkw5GyLVGCLaiVUJB7SAW8sZdlGC1XKcF63gqIySOOLEw+uoVIzy9 4yaFfmcGPrDkiGTraVGtihS1a7edkIQYPOvODSyMLrTrkR4VyxKRF8tzG/kEt5GYZprz59vb J2fYm1vG25I+U4lIwhJcwmy+6OtLejqYz+3kf5mG0TSTnC/f2NpNTrOUU/C3mj+hf9KlfHGF fUbkxW3iS+92zHRknk6P5SaTgiS5aJYFeas0kWFKlVoRoAsNidGoogNOhYdZkedpzJemTI/Q 99bgesSxSD5HusNSLsooZaQuJqwe8Swh95a2LyoTZdLTyphYURt+XBuhFnX1aDFLyhdKdx8S T8i4M8rzYqgonhO1/1PMevno0UnjhmOBqpDy5Tma0abIhoB36akG27fseVOVK2oc1Q+To6pc g2xn7Elb5vqgFt+BlWce+k8sGM3Uz4/oTjk8vr1acXDkaPOCdzU3w26rw5dnbSk0bdyTJYsa 69r7Is7v64WLBfA+QhF6K6EWGzXBvs6E6AeNu9hY/yNnL/ttSfZLPysndSHKwFWEVqf8CxVQ taswAwAA X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 940B118001E X-Rspam-User: X-Stat-Signature: dw5wkmfdt4dipkt56h75wphm5sw8ukjo X-Rspamd-Server: rspam03 X-HE-Tag: 1706097594-103084 X-HE-Meta: U2FsdGVkX1/4ov1DY0X1Ludz/hKnS3Yn7/fLgxJ7vV90Zpd7EpeYu7yqlPSntsC9HPLRSHppKSxY++RlBtAnFYrdvnBF7Q50ROUwM8XYSEEU32NKoBNFcrHMqf7KPZ+/x7I51s3Q5iy2PAPgoW27i879EX3glg7quf8MVgkxVw+ADj1jIpMu2LQJE1PejW+ubTraTN+jAemgZ5Q0tbwmInpPxZ2Z49NDKPR1ICZL1WocJioYYolqLUMm5i1/MnrHWgMNkV2gTep42OdcWDsgph9s3pFFN5lTzOu8qqVWSdVQBF+GoJi0G5D92dB6BPbRVR5nENemrC2th0SZ5e2y+myX68mMOfAUXBhwltnjtsqen6+ZCubDl55i/vwbre2TghInnK0JoAQ5X3Gzsf25PakX471N//kzmnaXBJtG6KiKVU8ebOnTR6oJ8CoI7Hy3pPyb9MCE2r6Sj448Mn2bINFJHA5hsCNkIuejDeroQ1BTuG/ZUTufrRkcsAbHxQ+EnPBfjvyP9shyi/WRiyKkzYxkN/uQP8zjI0ssbAmCROBtsqI4GVGzUBYT4yEYGVMsynbNvNDeJowmLRDfajF8npntc7mWavhCmOatWXT4Ovv7/hHdfaSSLuvkcyv8ZagWK+Fd5oLzeqWbWNVVLg0mABdfPQXPYGftIHFv0/HGAGVXXfiSr1dPYOO+Pfcd6enLXBYg6tLr27EQLBeN9o1zhloJ6ZfLJgg4ibJ6b1saMUS0QNIQrZUH6DK4X4CSsXRlswXU9D9WoS6VAQVQ5gosoFfkaXLmmsHOH037zmmhIeGpeFGg6nZA9q+LU+L0KLo/X43JAHwwlzzfeS/Pr6wjZ/kn54bO3kjubj2XWXL/iNu0fr6MBG2SYsu4yhf48IB2lZutmZVPB+znF9TcCgIxbgDzpISqG7y9s9Q2ujkDKc5//+97MB00SMv07tiKGoFALF6TuamCMqWnRp8r7CN hYMLeJSV l6TbeL/fzT6FKJoDV4Tfj2oiYywDeJCO0CIKV5XLEwn8QvQH5TM+5j5QDjIshO4m5Ysi6hKAdTevtvBwilU3VqWMqug== 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: List-Subscribe: List-Unsubscribe: Wrapped the base APIs for easier annotation on typical lock. Signed-off-by: Byungchul Park --- include/linux/dept_ldt.h | 77 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 include/linux/dept_ldt.h diff --git a/include/linux/dept_ldt.h b/include/linux/dept_ldt.h new file mode 100644 index 000000000000..062613e89fc3 --- /dev/null +++ b/include/linux/dept_ldt.h @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Lock Dependency Tracker + * + * Started by Byungchul Park : + * + * Copyright (c) 2020 LG Electronics, Inc., Byungchul Park + */ + +#ifndef __LINUX_DEPT_LDT_H +#define __LINUX_DEPT_LDT_H + +#include + +#ifdef CONFIG_DEPT +#define LDT_EVT_L 1UL +#define LDT_EVT_R 2UL +#define LDT_EVT_W 1UL +#define LDT_EVT_RW (LDT_EVT_R | LDT_EVT_W) +#define LDT_EVT_ALL (LDT_EVT_L | LDT_EVT_RW) + +#define ldt_init(m, k, su, n) dept_map_init(m, k, su, n) +#define ldt_lock(m, sl, t, n, i) \ + do { \ + if (n) \ + dept_ecxt_enter_nokeep(m); \ + else if (t) \ + dept_ecxt_enter(m, LDT_EVT_L, i, "trylock", "unlock", sl);\ + else { \ + dept_wait(m, LDT_EVT_L, i, "lock", sl); \ + dept_ecxt_enter(m, LDT_EVT_L, i, "lock", "unlock", sl);\ + } \ + } while (0) + +#define ldt_rlock(m, sl, t, n, i, q) \ + do { \ + if (n) \ + dept_ecxt_enter_nokeep(m); \ + else if (t) \ + dept_ecxt_enter(m, LDT_EVT_R, i, "read_trylock", "read_unlock", sl);\ + else { \ + dept_wait(m, q ? LDT_EVT_RW : LDT_EVT_W, i, "read_lock", sl);\ + dept_ecxt_enter(m, LDT_EVT_R, i, "read_lock", "read_unlock", sl);\ + } \ + } while (0) + +#define ldt_wlock(m, sl, t, n, i) \ + do { \ + if (n) \ + dept_ecxt_enter_nokeep(m); \ + else if (t) \ + dept_ecxt_enter(m, LDT_EVT_W, i, "write_trylock", "write_unlock", sl);\ + else { \ + dept_wait(m, LDT_EVT_RW, i, "write_lock", sl); \ + dept_ecxt_enter(m, LDT_EVT_W, i, "write_lock", "write_unlock", sl);\ + } \ + } while (0) + +#define ldt_unlock(m, i) dept_ecxt_exit(m, LDT_EVT_ALL, i) + +#define ldt_downgrade(m, i) \ + do { \ + if (dept_ecxt_holding(m, LDT_EVT_W)) \ + dept_map_ecxt_modify(m, LDT_EVT_W, NULL, LDT_EVT_R, i, "downgrade", "read_unlock", -1);\ + } while (0) + +#define ldt_set_class(m, n, k, sl, i) dept_map_ecxt_modify(m, LDT_EVT_ALL, k, 0UL, i, "lock_set_class", "(any)unlock", sl) +#else /* !CONFIG_DEPT */ +#define ldt_init(m, k, su, n) do { (void)(k); } while (0) +#define ldt_lock(m, sl, t, n, i) do { } while (0) +#define ldt_rlock(m, sl, t, n, i, q) do { } while (0) +#define ldt_wlock(m, sl, t, n, i) do { } while (0) +#define ldt_unlock(m, i) do { } while (0) +#define ldt_downgrade(m, i) do { } while (0) +#define ldt_set_class(m, n, k, sl, i) do { } while (0) +#endif +#endif /* __LINUX_DEPT_LDT_H */