Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp241761img; Mon, 18 Mar 2019 02:01:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxac9mGUaza2zxKJU/9mH0QmRtuxaU5UPTRms1bbdtbWCJ4OUZgF1+06fRXnj1IlWnhsb1+ X-Received: by 2002:a17:902:8643:: with SMTP id y3mr18425539plt.195.1552899706925; Mon, 18 Mar 2019 02:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552899706; cv=none; d=google.com; s=arc-20160816; b=zBHoPIpccIBhxyOzQNq1WAf0NgwJe6F1eCzEs60JcaTpMxTiC9X/yhkM+AUwjGJuKb Y73ZGv5jUhZ/u+cvMG/p3vZh5A3G7aCcfOEImcfuHZaOChCbRxbOoi88IQYhgXUTrseh pWMuf1fffjHEaaf7vJDS7gMWfsacHwbCGJbAcjpV8/tx+JeXw3jrkgpXqpWQKj/CdOA4 lAypRPuvs3wXhDU75IF3WskfEDmjE6nmxvHMcwlV1BOTk02BipQLKH+DQwv4vB1elDmf paBiWhS3lOfM1/oxSb56hwzCcNZNJSyNpBVQtvAOxP+7lDTecP/7iulFnWy7jOJeaIEg VpYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=KyHrxDe/xpb07A9K3M4+mxUi1KrAuSfwcb6ndTfQUHA=; b=xvYrk3PGWgk4C1vtz8djmOqBvX2SIPGnPcrfX53ZrGb0IWiZO6nKR5RrsqBJZCl4DQ wsT4rW9RwlSPwCdD3oJyBEajt8KtGFuiTjOqQ2uVaMyijsf++zXmRuJ9aU7iSfKLbGQ8 bz1XvMUw9ygZa9TzjzBFBF8dq5PpTt+TJVdS4NzX7mxLf+lTutUU596H5LzwOnVQnGYq ovgrtOOiJf8hIlmYKRE8jO6eN/gAP8rkTvI01mxHgswCgVYpKlB4cRxuorECQIfxhZ7p TL6UcdNbcDtkRAouHfbywa8ws2Qnr1N7bf8FbBhCrm5URMI5kFdMLAuXPRy88WldgSEZ HPKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kY1RcOK8; 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 i30si8803384pgb.413.2019.03.18.02.01.29; Mon, 18 Mar 2019 02:01:46 -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=kY1RcOK8; 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 S1727368AbfCRI6J (ORCPT + 99 others); Mon, 18 Mar 2019 04:58:09 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:36003 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727336AbfCRI6G (ORCPT ); Mon, 18 Mar 2019 04:58:06 -0400 Received: by mail-pf1-f196.google.com with SMTP id p10so3996181pff.3 for ; Mon, 18 Mar 2019 01:58:06 -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; bh=KyHrxDe/xpb07A9K3M4+mxUi1KrAuSfwcb6ndTfQUHA=; b=kY1RcOK8xX2A5gB6C3uCfJtXrhg81dLPNNz2vYx7HLKKTPTDfmN4tqcBx2iJzGx0zz BTjICtSvogqHbbUieYnvfSX5gZLKS8W2tVtBEfuErTpWa6veyc7xs5OzSx7yZB5bdpXS gdhI+0uFTl3Y2Xs+JRi+eGjwnwYw/P68kK84dPIcCxQJN0+Myc1s4bs3ho6mFN0zs07U UfAa+/sVFkTU70T1adD2igOzwjkLnfs8A7sVyWP8TsCTiymbV4WDCLekP7FJpZgC0Cfr 2etBCM4f55nvscWd1poim/PhicZ+Q8MSr1vo+U6C3GWBKPTSoR3c+/OjtZ3TEdeCN5gD pMqQ== 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; bh=KyHrxDe/xpb07A9K3M4+mxUi1KrAuSfwcb6ndTfQUHA=; b=IKOK3cyCXlmN24Uh1FZ1+tzxyoSOK/7NenVL5UzhmiorB5zY3m2PDyXhQpeeu3wDrA rN9tcIgahd9ShOuk18r1+plLWDNAh4stQ6VqkpF4V/fGejXykAWzK4mVONWvrTMVQ12a bT+cYG7H+ACXKIrxpZ1fmQXYxb/yF5Wl8oED/SRb8BgztD6vJd0tvsBWr2RdBrRpmtX3 l5qWATuGDwQmbybTDrjiva/LqiL1IzmCffgq/tDL3i9jAM51os2J/tusYc9SpEbWxtk1 0cUs8c0gLTXQhss1TBSOtNlC97eQszkN5Ut2nkY1OXeQWa3yQEe8dPP+n8I93Jt359SZ ls/Q== X-Gm-Message-State: APjAAAWtKYmqBgBLa2kIK6NkEbSjZ0Dv6Maz0e5zJ95dMNdZXMFFDURz cAf6eMV3okJfE9nRMZta9F8= X-Received: by 2002:a17:902:aa87:: with SMTP id d7mr18132416plr.146.1552899485873; Mon, 18 Mar 2019 01:58:05 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id k8sm11147024pgq.37.2019.03.18.01.58.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Mar 2019 01:58:05 -0700 (PDT) From: Yuyang Du To: peterz@infradead.org, will.deacon@arm.com, mingo@kernel.org Cc: bvanassche@acm.org, ming.lei@redhat.com, linux-kernel@vger.kernel.org, Yuyang Du Subject: [PATCH v2 08/19] locking/lockdep: Use lockdep_init_task for task initiation consistently Date: Mon, 18 Mar 2019 16:57:22 +0800 Message-Id: <20190318085733.3143-9-duyuyang@gmail.com> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20190318085733.3143-1-duyuyang@gmail.com> References: <20190318085733.3143-1-duyuyang@gmail.com> 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 1258a62..49b928f 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -280,6 +280,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); @@ -404,6 +406,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) { } @@ -496,7 +502,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 46dbf54..9460878 100644 --- a/init/init_task.c +++ b/init/init_task.c @@ -165,6 +165,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 77059b2..c0d2000 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1869,9 +1869,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 3df0a5e..737fe0a 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++; @@ -4492,9 +4499,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