Received: by 10.223.185.116 with SMTP id b49csp1594175wrg; Wed, 21 Feb 2018 23:08:18 -0800 (PST) X-Google-Smtp-Source: AH8x226pWBfr1GYc0pz9aYvHI8f8cePxB97CHSHZoAQjIEmjJdcEqY0l+NWvYio4TAn0MASeDPzU X-Received: by 2002:a17:902:4601:: with SMTP id o1-v6mr5643338pld.210.1519283298019; Wed, 21 Feb 2018 23:08:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519283297; cv=none; d=google.com; s=arc-20160816; b=dB93zoo4jmaR0DSuwGUuecmqhLHazdH0cRcpM10XyiFrgQYIS2UlsGgLX8p6td1P9F Uv3IGTFEeTiDLg5ktBwRIInsK7G40QpBm+5vT3eM7QRB9lm4wyfBpKbQXJc41oNS8/be f2JM7XmrqKX7MYt9s5FeW4noqr1KKrCnK4rKOCFLpT6aa9ZpBJKvXa37lBc9+gBcFe+h WJEabfh0YYxrb6zZM8xP+pl1z82RNQjJ0GdKW6O9voMLQF5MVp4+pRXDi7VQStsMaApf LFuaatApqIlawz4lvnbGWho1nuGjoVqI20hcYADQlPbC+xow+/tzZ4IBxg9gaF5mWAcE ak5Q== 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:arc-authentication-results; bh=n+xO07bPNQnpjRF9GIa03Mee5w/m8EqHaFHo6Lt0Osc=; b=RY40zwPcQQP4Ya+jZJ8mEto7N1cdwXtG5CjeqLTbxWRhitdcpWckn+6iWn9H2+rhqg 5XQrGLuTJ+HDavzVQ2r3FSA0idVZw6tsTngSFWhRlTGJTtaKdOJDhrTagVYCWWHmytvm 25FMt6+vKugfYH2G4t6/M7do02QEDCJwC2qMN8ajfhLXfmiXb96YirkNFPcLU/8HZ+Gn jFTqBr04da5pPcWbladKHC17Ed5PfzfVRW1yli8inbQNQmm1UanCTRw3fEdWdGiVjkYi v5wma7BNlhUf/mQjVOfeNW/0GtKdyNITxrdfbelT5N6Ej5mK3CsaX88qSmIjoQTVIq6L FMqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vTwIb2EO; 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 m187si2879230pfb.291.2018.02.21.23.08.03; Wed, 21 Feb 2018 23:08:17 -0800 (PST) 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=vTwIb2EO; 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 S1752611AbeBVHGH (ORCPT + 99 others); Thu, 22 Feb 2018 02:06:07 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:52580 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752581AbeBVHGD (ORCPT ); Thu, 22 Feb 2018 02:06:03 -0500 Received: by mail-wm0-f67.google.com with SMTP id t3so1824913wmc.2; Wed, 21 Feb 2018 23:06:02 -0800 (PST) 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=n+xO07bPNQnpjRF9GIa03Mee5w/m8EqHaFHo6Lt0Osc=; b=vTwIb2EOyhLZtnxNC4NaitgNLuwZEhDHJ8f8B/lm8c6ChXSu1uCRlZN2rnahgGcDjr SfowWp3gBHKqVgTGZK02ZPgFwdZ87z75gmMnE68aUvupU5Xq7bp2tnFvHA84wJ4WsQyc lyZe11IuJI71y4tPFXaA0TyWm1IyQfZ/AzMuOAADl69FeeLhjN+yPPTr7O6k5xzjycyw a6YFMqzm7cEQ6m5Ue91siYzxPywmWY/KmrCHZbbcAgff6Kky/Wwh4V/jlkl8ajf88qdj buNZn35JxqmJxfsX/pmFEu+x1O8efhn0LVxqDZj2J2tL05eJZqtxB9z23APnww9E1pxg lbfA== 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=n+xO07bPNQnpjRF9GIa03Mee5w/m8EqHaFHo6Lt0Osc=; b=Jr7uBeDrcKYCE7RwrFjfOQ5JOA0Z3iVtL4fEVNL6D1whwUU1WIacVZWag1cj62Pk0R YkGEIqNS6ttrmsv6Yea+ZzVHCwf3AZTnLyaUhjFBeU1JEYy0h1k5RB7jsgnhNWgqxPJo ICMBj7pY4qQ96KN71yXjf069Kw7r2pVKEKolov812zsHW6IKCH2+vgpU611INsNNZChs upg/Iwwjq8BP8YWBu3XMSDn2myw84SnqKfh+Ryqr+uL9+w10BdJa03+Ib64jcU0OL5mD Myu3tqkys9P+cM7VawRdxsOCSbBk18Obhu9bMw+y+U/X6YpA/Smy1uDn0JtjZNADqZCB 0zjA== X-Gm-Message-State: APf1xPBh8/n/sFQZNyJT3g7/1ulEyFfSJooztItwQFs8WJ6tP6oJ7LQY CMz/N+lVkQvF2f+LH5tmLu8= X-Received: by 10.80.159.196 with SMTP id c62mr7782629edf.277.1519283161696; Wed, 21 Feb 2018 23:06:01 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id 26sm9711389eds.26.2018.02.21.23.05.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 23:06:00 -0800 (PST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailauth.nyi.internal (Postfix) with ESMTP id 4A24020784; Thu, 22 Feb 2018 02:05:59 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Thu, 22 Feb 2018 02:05:59 -0500 X-ME-Sender: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id C83EF246A3; Thu, 22 Feb 2018 02:05:57 -0500 (EST) From: Boqun Feng To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Ingo Molnar , Andrea Parri , Boqun Feng , Jonathan Corbet , linux-doc@vger.kernel.org (open list:DOCUMENTATION) Subject: [RFC tip/locking/lockdep v5 03/17] lockdep: Redefine LOCK_*_STATE* bits Date: Thu, 22 Feb 2018 15:08:50 +0800 Message-Id: <20180222070904.548-4-boqun.feng@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180222070904.548-1-boqun.feng@gmail.com> References: <20180222070904.548-1-boqun.feng@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are three types of lock acquisitions: write, non-recursive read and recursive read, among which write locks and non-recursive read locks have no difference from a viewpoint for deadlock detections, because a write acquisition of the corresponding lock on an independent CPU or task makes a non-recursive read lock act as a write lock in the sense of deadlock. So we could treat them as the same type(named as "non-recursive lock") in lockdep. As in the irq lock inversion detection(safe->unsafe deadlock detection), we used to differ write lock with read lock(non-recursive and recursive ones), such a classification could be improved as non-recursive read lock behaves the same as write lock, so this patch redefines the meanings of LOCK_{USED_IN, ENABLED}_STATE*. old: LOCK_* : stands for write lock LOCK_*_READ: stands for read lock(non-recursive and recursive) new: LOCK_* : stands for non-recursive(write lock and non-recursive read lock) LOCK_*_RR: stands for recursive read lock Such a change is needed for a future improvement on recursive read related irq inversion deadlock detection. Signed-off-by: Boqun Feng --- Documentation/locking/lockdep-design.txt | 6 +++--- kernel/locking/lockdep.c | 28 ++++++++++++++-------------- kernel/locking/lockdep_internals.h | 16 ++++++++-------- kernel/locking/lockdep_proc.c | 12 ++++++------ 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Documentation/locking/lockdep-design.txt b/Documentation/locking/lockdep-design.txt index 9de1c158d44c..382bc25589c2 100644 --- a/Documentation/locking/lockdep-design.txt +++ b/Documentation/locking/lockdep-design.txt @@ -30,9 +30,9 @@ State The validator tracks lock-class usage history into 4n + 1 separate state bits: - 'ever held in STATE context' -- 'ever held as readlock in STATE context' +- 'ever held as recursive readlock in STATE context' - 'ever held with STATE enabled' -- 'ever held as readlock with STATE enabled' +- 'ever held as recurisve readlock with STATE enabled' Where STATE can be either one of (kernel/locking/lockdep_states.h) - hardirq @@ -51,7 +51,7 @@ locking error messages, inside curlies. A contrived example: (&sio_locks[i].lock){-.-...}, at: [] mutex_lock+0x21/0x24 -The bit position indicates STATE, STATE-read, for each of the states listed +The bit position indicates STATE, STATE-RR, for each of the states listed above, and the character displayed in each indicates: '.' acquired while irqs disabled and not in irq context diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index c80f8276ceaa..5e6bf8d6954d 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -448,10 +448,10 @@ DEFINE_PER_CPU(struct lockdep_stats, lockdep_stats); */ #define __USAGE(__STATE) \ - [LOCK_USED_IN_##__STATE] = "IN-"__stringify(__STATE)"-W", \ - [LOCK_ENABLED_##__STATE] = __stringify(__STATE)"-ON-W", \ - [LOCK_USED_IN_##__STATE##_READ] = "IN-"__stringify(__STATE)"-R",\ - [LOCK_ENABLED_##__STATE##_READ] = __stringify(__STATE)"-ON-R", + [LOCK_USED_IN_##__STATE] = "IN-"__stringify(__STATE), \ + [LOCK_ENABLED_##__STATE] = __stringify(__STATE)"-ON", \ + [LOCK_USED_IN_##__STATE##_RR] = "IN-"__stringify(__STATE)"-RR", \ + [LOCK_ENABLED_##__STATE##_RR] = __stringify(__STATE)"-ON-RR", static const char *usage_str[] = { @@ -492,7 +492,7 @@ void get_usage_chars(struct lock_class *class, char usage[LOCK_USAGE_CHARS]) #define LOCKDEP_STATE(__STATE) \ usage[i++] = get_usage_char(class, LOCK_USED_IN_##__STATE); \ - usage[i++] = get_usage_char(class, LOCK_USED_IN_##__STATE##_READ); + usage[i++] = get_usage_char(class, LOCK_USED_IN_##__STATE##_RR); #include "lockdep_states.h" #undef LOCKDEP_STATE @@ -1645,7 +1645,7 @@ static const char *state_names[] = { static const char *state_rnames[] = { #define LOCKDEP_STATE(__STATE) \ - __stringify(__STATE)"-READ", + __stringify(__STATE)"-RR", #include "lockdep_states.h" #undef LOCKDEP_STATE }; @@ -3039,14 +3039,14 @@ static int mark_irqflags(struct task_struct *curr, struct held_lock *hlock) * mark the lock as used in these contexts: */ if (!hlock->trylock) { - if (hlock->read) { + if (hlock->read == 2) { if (curr->hardirq_context) if (!mark_lock(curr, hlock, - LOCK_USED_IN_HARDIRQ_READ)) + LOCK_USED_IN_HARDIRQ_RR)) return 0; if (curr->softirq_context) if (!mark_lock(curr, hlock, - LOCK_USED_IN_SOFTIRQ_READ)) + LOCK_USED_IN_SOFTIRQ_RR)) return 0; } else { if (curr->hardirq_context) @@ -3058,13 +3058,13 @@ static int mark_irqflags(struct task_struct *curr, struct held_lock *hlock) } } if (!hlock->hardirqs_off) { - if (hlock->read) { + if (hlock->read == 2) { if (!mark_lock(curr, hlock, - LOCK_ENABLED_HARDIRQ_READ)) + LOCK_ENABLED_HARDIRQ_RR)) return 0; if (curr->softirqs_enabled) if (!mark_lock(curr, hlock, - LOCK_ENABLED_SOFTIRQ_READ)) + LOCK_ENABLED_SOFTIRQ_RR)) return 0; } else { if (!mark_lock(curr, hlock, @@ -3170,9 +3170,9 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this, switch (new_bit) { #define LOCKDEP_STATE(__STATE) \ case LOCK_USED_IN_##__STATE: \ - case LOCK_USED_IN_##__STATE##_READ: \ + case LOCK_USED_IN_##__STATE##_RR: \ case LOCK_ENABLED_##__STATE: \ - case LOCK_ENABLED_##__STATE##_READ: + case LOCK_ENABLED_##__STATE##_RR: #include "lockdep_states.h" #undef LOCKDEP_STATE ret = mark_lock_irq(curr, this, new_bit); diff --git a/kernel/locking/lockdep_internals.h b/kernel/locking/lockdep_internals.h index d459d624ba2a..93002d337936 100644 --- a/kernel/locking/lockdep_internals.h +++ b/kernel/locking/lockdep_internals.h @@ -13,9 +13,9 @@ enum lock_usage_bit { #define LOCKDEP_STATE(__STATE) \ LOCK_USED_IN_##__STATE, \ - LOCK_USED_IN_##__STATE##_READ, \ + LOCK_USED_IN_##__STATE##_RR, \ LOCK_ENABLED_##__STATE, \ - LOCK_ENABLED_##__STATE##_READ, + LOCK_ENABLED_##__STATE##_RR, #include "lockdep_states.h" #undef LOCKDEP_STATE LOCK_USED, @@ -30,9 +30,9 @@ enum lock_usage_bit { enum { #define LOCKDEP_STATE(__STATE) \ __LOCKF(USED_IN_##__STATE) \ - __LOCKF(USED_IN_##__STATE##_READ) \ + __LOCKF(USED_IN_##__STATE##_RR) \ __LOCKF(ENABLED_##__STATE) \ - __LOCKF(ENABLED_##__STATE##_READ) + __LOCKF(ENABLED_##__STATE##_RR) #include "lockdep_states.h" #undef LOCKDEP_STATE __LOCKF(USED) @@ -41,10 +41,10 @@ enum { #define LOCKF_ENABLED_IRQ (LOCKF_ENABLED_HARDIRQ | LOCKF_ENABLED_SOFTIRQ) #define LOCKF_USED_IN_IRQ (LOCKF_USED_IN_HARDIRQ | LOCKF_USED_IN_SOFTIRQ) -#define LOCKF_ENABLED_IRQ_READ \ - (LOCKF_ENABLED_HARDIRQ_READ | LOCKF_ENABLED_SOFTIRQ_READ) -#define LOCKF_USED_IN_IRQ_READ \ - (LOCKF_USED_IN_HARDIRQ_READ | LOCKF_USED_IN_SOFTIRQ_READ) +#define LOCKF_ENABLED_IRQ_RR \ + (LOCKF_ENABLED_HARDIRQ_RR | LOCKF_ENABLED_SOFTIRQ_RR) +#define LOCKF_USED_IN_IRQ_RR \ + (LOCKF_USED_IN_HARDIRQ_RR | LOCKF_USED_IN_SOFTIRQ_RR) /* * CONFIG_LOCKDEP_SMALL is defined for sparc. Sparc requires .text, diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c index ad69bbc9bd28..630a6bc6e24c 100644 --- a/kernel/locking/lockdep_proc.c +++ b/kernel/locking/lockdep_proc.c @@ -252,17 +252,17 @@ static int lockdep_stats_show(struct seq_file *m, void *v) nr_hardirq_safe++; if (class->usage_mask & LOCKF_ENABLED_HARDIRQ) nr_hardirq_unsafe++; - if (class->usage_mask & LOCKF_USED_IN_IRQ_READ) + if (class->usage_mask & LOCKF_USED_IN_IRQ_RR) nr_irq_read_safe++; - if (class->usage_mask & LOCKF_ENABLED_IRQ_READ) + if (class->usage_mask & LOCKF_ENABLED_IRQ_RR) nr_irq_read_unsafe++; - if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ_READ) + if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ_RR) nr_softirq_read_safe++; - if (class->usage_mask & LOCKF_ENABLED_SOFTIRQ_READ) + if (class->usage_mask & LOCKF_ENABLED_SOFTIRQ_RR) nr_softirq_read_unsafe++; - if (class->usage_mask & LOCKF_USED_IN_HARDIRQ_READ) + if (class->usage_mask & LOCKF_USED_IN_HARDIRQ_RR) nr_hardirq_read_safe++; - if (class->usage_mask & LOCKF_ENABLED_HARDIRQ_READ) + if (class->usage_mask & LOCKF_ENABLED_HARDIRQ_RR) nr_hardirq_read_unsafe++; #ifdef CONFIG_PROVE_LOCKING -- 2.16.1