From patchwork Tue Aug 2 11:48:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hillf Danton X-Patchwork-Id: 12934562 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 AAD0EC00140 for ; Tue, 2 Aug 2022 11:48:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 005276B0071; Tue, 2 Aug 2022 07:48:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF7016B0072; Tue, 2 Aug 2022 07:48:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE5828E0001; Tue, 2 Aug 2022 07:48:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CF1846B0071 for ; Tue, 2 Aug 2022 07:48:41 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id AB1454128F for ; Tue, 2 Aug 2022 11:48:41 +0000 (UTC) X-FDA: 79754480442.11.07D5FB1 Received: from r3-25.sinamail.sina.com.cn (r3-25.sinamail.sina.com.cn [202.108.3.25]) by imf30.hostedemail.com (Postfix) with SMTP id E378580113 for ; Tue, 2 Aug 2022 11:48:37 +0000 (UTC) Received: from unknown (HELO localhost.localdomain)([114.249.59.48]) by sina.com (172.16.97.23) with ESMTP id 62E90EF400023F95; Tue, 2 Aug 2022 19:48:06 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com X-SMAIL-MID: 7145054920041 From: Hillf Danton To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Thomas Gleixner Subject: [RFC] hrtimer: add lockdep annotation Date: Tue, 2 Aug 2022 19:48:24 +0800 Message-Id: <20220802114824.1543-1-hdanton@sina.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of hdanton@sina.com designates 202.108.3.25 as permitted sender) smtp.mailfrom=hdanton@sina.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659440920; a=rsa-sha256; cv=none; b=xcL+oz8zGxdrcXnlIoKOLyqBqVD31ZUbyjjOgfjgxHQawGWsO3uVJAbzWXcixrBls2Qq4P ivkxyy8Gy6pcBwxJP1jWWu552XmG4yzya2UfPwILRnwdnszEQuYw8ik22/Z7NaQKG8RnIb QrAWZWasTdMvztiL5cwXPqKJKrWNXmo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659440920; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=Egp7E++qTZaT3mq2zVa35L+EMtOERnQ5Ahbl6ziUw+I=; b=qnparcl+zVXbtP9g/60m/kP3uSvetS9Dw1li4dvQORdQgpfueZtzmjhMaHiT16EXWztpIU GB1KKEA5merEuK3RuSXYgxeA/G7i5Gx/KcPK4ylxAPJUPnD7I9hpjwi3hxVObmTbUVx1wR 8kq6r9TY71rVxSeK26bP90zx3YW5jeE= Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of hdanton@sina.com designates 202.108.3.25 as permitted sender) smtp.mailfrom=hdanton@sina.com; dmarc=none X-Stat-Signature: qkusjxgjfm3txnrxpcjx4doyazmxbkbk X-Rspamd-Queue-Id: E378580113 X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1659440917-811449 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: This is a lame copy of lockdep map in timer. Only for thoughts now. Hillf --- a/include/linux/hrtimer.h +++ b/include/linux/hrtimer.h @@ -124,6 +124,9 @@ struct hrtimer { u8 is_rel; u8 is_soft; u8 is_hard; +#ifdef CONFIG_LOCKDEP + struct lockdep_map lockdep_map; +#endif }; /** @@ -369,10 +372,34 @@ static inline void hrtimer_cancel_wait_r /* Exported timer functions: */ /* Initialize timers: */ -extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock, - enum hrtimer_mode mode); -extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, clockid_t clock_id, - enum hrtimer_mode mode); +extern void hrtimer_init_key(struct hrtimer *timer, clockid_t which_clock, + enum hrtimer_mode mode, + const char *name, struct lock_class_key *key); +extern void hrtimer_init_sleeper_key(struct hrtimer_sleeper *sl, clockid_t clock_id, + enum hrtimer_mode mode, + const char *name, struct lock_class_key *key); + +#ifdef CONFIG_LOCKDEP +#define hrtimer_init(t, c, m) \ + do { static struct lock_class_key __k; \ + hrtimer_init_key(t, c, m, #t, &__k); \ + } while (0) + +#define hrtimer_init_sleeper(s, c, m) \ + do { static struct lock_class_key __k; \ + hrtimer_init_sleeper_key(s, c, m, #s, &__k); \ + } while (0) +#else +#define hrtimer_init(t, c, m) \ + do { \ + hrtimer_init_key(t, c, m, NULL, NULL); \ + } while (0) + +#define hrtimer_init_sleeper(s, c, m) \ + do { \ + hrtimer_init_sleeper_key(s, c, m, NULL, NULL); \ + } while (0) +#endif #ifdef CONFIG_DEBUG_OBJECTS_TIMERS extern void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t which_clock, --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1439,6 +1439,8 @@ int hrtimer_cancel(struct hrtimer *timer { int ret; + lock_map_acquire(&timer->lockdep_map); + lock_map_release(&timer->lockdep_map); do { ret = hrtimer_try_to_cancel(timer); @@ -1575,7 +1577,7 @@ static void __hrtimer_init(struct hrtime } /** - * hrtimer_init - initialize a timer to the given clock + * hrtimer_init_key - initialize a timer to the given clock * @timer: the timer to be initialized * @clock_id: the clock to be used * @mode: The modes which are relevant for initialization: @@ -1586,13 +1588,14 @@ static void __hrtimer_init(struct hrtime * but the PINNED bit is ignored as pinning happens * when the hrtimer is started */ -void hrtimer_init(struct hrtimer *timer, clockid_t clock_id, - enum hrtimer_mode mode) +void hrtimer_init_key(struct hrtimer *timer, clockid_t clock_id, + enum hrtimer_mode mode, + const char *name, struct lock_class_key *key) { debug_init(timer, clock_id, mode); __hrtimer_init(timer, clock_id, mode); + lockdep_init_map(&timer->lockdep_map, name, key, 0); } -EXPORT_SYMBOL_GPL(hrtimer_init); /* * A timer is active, when it is enqueued into the rbtree or the @@ -1647,6 +1650,11 @@ static void __run_hrtimer(struct hrtimer enum hrtimer_restart (*fn)(struct hrtimer *); bool expires_in_hardirq; int restart; +#ifdef CONFIG_LOCKDEP + struct lockdep_map lockdep_map; + + lockdep_copy_map(&lockdep_map, &timer->lockdep_map); +#endif lockdep_assert_held(&cpu_base->lock); @@ -1681,9 +1689,11 @@ static void __run_hrtimer(struct hrtimer raw_spin_unlock_irqrestore(&cpu_base->lock, flags); trace_hrtimer_expire_entry(timer, now); expires_in_hardirq = lockdep_hrtimer_enter(timer); + lock_map_acquire(&lockdep_map); restart = fn(timer); + lock_map_release(&lockdep_map); lockdep_hrtimer_exit(expires_in_hardirq); trace_hrtimer_expire_exit(timer); raw_spin_lock_irq(&cpu_base->lock); @@ -1999,19 +2009,19 @@ static void __hrtimer_init_sleeper(struc } /** - * hrtimer_init_sleeper - initialize sleeper to the given clock + * hrtimer_init_sleeper_key - initialize sleeper to the given clock * @sl: sleeper to be initialized * @clock_id: the clock to be used * @mode: timer mode abs/rel */ -void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, clockid_t clock_id, - enum hrtimer_mode mode) +void hrtimer_init_sleeper_key(struct hrtimer_sleeper *sl, clockid_t clock_id, + enum hrtimer_mode mode, + const char *name, struct lock_class_key *key) { debug_init(&sl->timer, clock_id, mode); __hrtimer_init_sleeper(sl, clock_id, mode); - + lockdep_init_map(&sl->timer.lockdep_map, name, key, 0); } -EXPORT_SYMBOL_GPL(hrtimer_init_sleeper); int nanosleep_copyout(struct restart_block *restart, struct timespec64 *ts) {