Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2201153yba; Mon, 6 May 2019 01:21:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVpWKSxW3XuwPg9oIAnyh4yJm5TAOD/Z0MiN/RsjwDwW14Bz0hAyK8Q7W2InCnlrGXAj67 X-Received: by 2002:a17:902:1d4a:: with SMTP id u10mr25667591plu.272.1557130902319; Mon, 06 May 2019 01:21:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557130902; cv=none; d=google.com; s=arc-20160816; b=QC6YRRIozjvES9hChjg9t22YJlj+w9MfdL/REfZfMR0cANlR3lIgndBvfclpcdXTgx lgzeYcX7ApkUixpb4roVAvswzT7jPcusEljtBTlar7NYEd66u2FsP/DNTl1Do5XnprIZ 5R0BKDG4jNHm04JuK4/DzpkGxcQYXA50c/p2FXJOIv+pWC19HcypM/MQirMN7TkT8Jna CsdiLuO+K0pJlAxfQ3mSCF98uHww4me4DOZ3z6j0Z38hqFTDz+dngIKpHbEisBC96Bn6 LAO5P8Ddg4jk8XSOli2k89Qs6sq1Dj23ycuHi+fu+Ax+VlQV+coKEVvcsffjLgv0Axnq XiUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Q1/noZSQvGvwMNkiB3NXfKHnpLYzNs326g0n8wQumEE=; b=eM6vZmd/FzKfnKQOSxM9pmZ6w9NImlZzUrxpaD6Ss2Orr0mH3rPTx1pdVuDfdaJgir Up171rYT1rvkZmitb562FjvOCm2IVKxa/j1rgkCOK3tY02FO7LPSkS2qEmcRNbDJJcNE ZhxGcAHbajog8ZXKFtMS45rXRHZ0mNmGUlBVH+BEkAsf8dKxk1H6cD1EfLE+uRyT+DaI 0FOFgOpIsvwqGyp1j1n4p1WJbqfiKSDxZ+VkhuV39U5mqEXwKSoLPXZn0NFLFroU7nqP kV3GWCIsGL9zMT9uo5Bd+kV0KA4rjtwU6Co8LXi4HLGwiVk6L6WNnBarZKqyBOZsVnl2 H/cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cuRhF2mE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k13si14333651pgj.15.2019.05.06.01.21.27; Mon, 06 May 2019 01:21:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cuRhF2mE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726483AbfEFIUO (ORCPT + 99 others); Mon, 6 May 2019 04:20:14 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:44615 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726197AbfEFIUM (ORCPT ); Mon, 6 May 2019 04:20:12 -0400 Received: by mail-pg1-f196.google.com with SMTP id z16so6080720pgv.11 for ; Mon, 06 May 2019 01:20:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q1/noZSQvGvwMNkiB3NXfKHnpLYzNs326g0n8wQumEE=; b=cuRhF2mEerWphgQZh7DB8+/c6Q1rN3zmkeJEKc+4rT2CMXegUdkH4/zZfQZOuUlHnO 9aufGOBfqoGXnI8654pYFBlS2kBgEbstw9WXajwTtvLluZ0jWUIHpE6eiq4quKBHe3/T IJhypqPi4LkgvGvPsLyfCH2vMTreIN5hTaDxVYywH7QZ3Sm1sptIOcbideEB1z6j1X94 7Zv1LfFPPH/HrzVYDS4BMBH9M7hlaT3se3o3dQ/0Het3S5K7IeBB0pqqWoGAvhmYkWb1 5RprGeZ9x+RvlXykqFN2rmfrc76eWiyFYcnDpBW9ijyrWUUwFVfmef3NeVwWwWEOv2eZ 85lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q1/noZSQvGvwMNkiB3NXfKHnpLYzNs326g0n8wQumEE=; b=AvF3VjseOWKYa00dgq4Ctzx/NsthsCwGwqdIcFCpCy/rEiApm0xEJE3GqYYQsfFh5P FFuluvk9EXPL/7zzkcQBgL09Bhjh5dWyz2+5TpDDz+N8CYn70sQLItMQi78HuhfULaQo JaFR7tWed3qkefns1O25kku42grA7008gdJt44OAvbQBdIeepnYRdkc5l3FWZbqmuNOq yDYRSWHxw72af+LL9Kv6SStG4bYrvtsN0xEjuPJ6rKHseLIZizu1eAwWYMHICT1MFHBH mPEhbZQXoar3WLB5ccjOmMV9YyTSAK9HoE9T79ZNGblD7/TywQpJd/1u8IA4xUaO18VH 9QOw== X-Gm-Message-State: APjAAAWpRQu94jlpMTMmMnIxKu3wPzlGPNNr+X4sh+awcLZKI+zYbQ7p xaCEVLrA7npu78wJV+kmuZ0= X-Received: by 2002:a65:518d:: with SMTP id h13mr30658254pgq.259.1557130811927; Mon, 06 May 2019 01:20:11 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id v19sm20958013pfa.138.2019.05.06.01.20.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 01:20:10 -0700 (PDT) From: Yuyang Du To: peterz@infradead.org, will.deacon@arm.com, mingo@kernel.org Cc: bvanassche@acm.org, ming.lei@redhat.com, frederic@kernel.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, Yuyang Du Subject: [PATCH v2 07/23] locking/lockdep: Use lockdep_init_task for task initiation consistently Date: Mon, 6 May 2019 16:19:23 +0800 Message-Id: <20190506081939.74287-8-duyuyang@gmail.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190506081939.74287-1-duyuyang@gmail.com> References: <20190506081939.74287-1-duyuyang@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Despite that there is a lockdep_init_task() which does nothing, lockdep initiates tasks by assigning lockdep fields and does so inconsistently. Fix this by using lockdep_init_task(). Signed-off-by: Yuyang Du --- include/linux/lockdep.h | 7 ++++++- init/init_task.c | 2 ++ kernel/fork.c | 3 --- kernel/locking/lockdep.c | 11 ++++++++--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index 851d44f..751a2cc 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -287,6 +287,8 @@ struct held_lock { extern asmlinkage void lockdep_sys_exit(void); extern void lockdep_set_selftest_task(struct task_struct *task); +extern inline void lockdep_init_task(struct task_struct *task); + extern void lockdep_off(void); extern void lockdep_on(void); @@ -411,6 +413,10 @@ static inline void lock_set_subclass(struct lockdep_map *lock, #else /* !CONFIG_LOCKDEP */ +static inline void lockdep_init_task(struct task_struct *task) +{ +} + static inline void lockdep_off(void) { } @@ -503,7 +509,6 @@ enum xhlock_context_t { { .name = (_name), .key = (void *)(_key), } static inline void lockdep_invariant_state(bool force) {} -static inline void lockdep_init_task(struct task_struct *task) {} static inline void lockdep_free_task(struct task_struct *task) {} #ifdef CONFIG_LOCK_STAT diff --git a/init/init_task.c b/init/init_task.c index c70ef65..1b15cb9 100644 --- a/init/init_task.c +++ b/init/init_task.c @@ -166,6 +166,8 @@ struct task_struct init_task .softirqs_enabled = 1, #endif #ifdef CONFIG_LOCKDEP + .lockdep_depth = 0, /* no locks held yet */ + .curr_chain_key = 0, .lockdep_recursion = 0, #endif #ifdef CONFIG_FUNCTION_GRAPH_TRACER diff --git a/kernel/fork.c b/kernel/fork.c index 9dcd18a..8ec9e78 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1868,9 +1868,6 @@ static __latent_entropy struct task_struct *copy_process( p->pagefault_disabled = 0; #ifdef CONFIG_LOCKDEP - p->lockdep_depth = 0; /* no locks held yet */ - p->curr_chain_key = 0; - p->lockdep_recursion = 0; lockdep_init_task(p); #endif diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 222ee91..f02f7dc 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -358,6 +358,13 @@ static inline u64 iterate_chain_key(u64 key, u32 idx) return k0 | (u64)k1 << 32; } +inline void lockdep_init_task(struct task_struct *task) +{ + task->lockdep_depth = 0; /* no locks held yet */ + task->curr_chain_key = 0; + task->lockdep_recursion = 0; +} + void lockdep_off(void) { current->lockdep_recursion++; @@ -4588,9 +4595,7 @@ void lockdep_reset(void) int i; raw_local_irq_save(flags); - current->curr_chain_key = 0; - current->lockdep_depth = 0; - current->lockdep_recursion = 0; + lockdep_init_task(current); memset(current->held_locks, 0, MAX_LOCK_DEPTH*sizeof(struct held_lock)); nr_hardirq_chains = 0; nr_softirq_chains = 0; -- 1.8.3.1