Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1362565imu; Tue, 11 Dec 2018 18:27:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/VKLDeixbVYrvynF377EXlxJ7QkL329J1MeUYkDx1xIzyNL756B/BG3uCzrmxafzeL3KEdv X-Received: by 2002:a63:2784:: with SMTP id n126mr17163256pgn.48.1544581657076; Tue, 11 Dec 2018 18:27:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544581657; cv=none; d=google.com; s=arc-20160816; b=jygdGVnh83C0hA6GMkSHUA3JvLORG2jpnag4PvCcvY5wpCK78iz0nF+OHmPbYBWnPE 9gsZ5b0EWZOwZCo20j0QkxozrnrzjDAMe+ltGmZ1ip3U2sGl0W2lmpEl5f199dJ9S25p /wz8W3QvTRVOfryFkCMdT8JBUAtoZW5SuJzcog/7iQNZw1GzSI9anuX7VXdvITaEJIZP JHEKX/5UrCBne5r0CWUCvl8H7N2Ibrneit/jkjZgE2eHDGOtchkcer1W0wt6yDOCtuWQ X5LmrImMWk3xY/L72qeFctIhb8upG4kuz2kQ42T7E/z8U2B8HUjoOiXNOWDbghB3OPkk qWWA== 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=RmKCG2vjvx5pkCe9XrXlTLfU5SXj6SQnQr7mWTh5qIk=; b=LksjafNGP0fDK7P9fuZ5uShcNssiIsmW5SkS2DvZ7K3vR2mPT2Vv839CkJZ/CKd9sd PQHDPFDnxZS2mNAMRvMVVJ+AmEwfOXmAcT5G77mNTD3xuF/sZMm1FBn7Hy79og56XhdW zQjMlijv2kvBPxsvF5zqJjQwIz4/+d3bf+21mVGWjabJr7hVmYdR7a7JuC7kxdpHIncu XwG1wz4LIwbbYbnKOSh/EwqOxj0wHxN9xZLo62o/YPxc6KQlNnEmVdCaHuS2bfqgw3Nx OIaKZOsQUjeHKK3kEdV9/uJWHlfxSjYVSBEIccu3hsxOCoqq0Ty98ZKQ+KHVWlGWgU4Q ckJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=UDDoqQC0; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j135si13234661pgc.517.2018.12.11.18.27.22; Tue, 11 Dec 2018 18:27:37 -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=@chromium.org header.s=google header.b=UDDoqQC0; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726394AbeLLCZT (ORCPT + 99 others); Tue, 11 Dec 2018 21:25:19 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:42432 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726368AbeLLCZP (ORCPT ); Tue, 11 Dec 2018 21:25:15 -0500 Received: by mail-pg1-f193.google.com with SMTP id d72so7567060pga.9 for ; Tue, 11 Dec 2018 18:25:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RmKCG2vjvx5pkCe9XrXlTLfU5SXj6SQnQr7mWTh5qIk=; b=UDDoqQC0tKdh07XAH/wc/oczJV9lXxNYH0JUAZZy7imigLmFgOvN1YM0O6n6fidX1Y qPbuz+wDscLLdXuY70JDUAUFVzEkDpx3pir/97FDEN3SDHcNZiJBLhWZjlPH2XwTFHWQ 5j+mVYOlLMSE5WV/5PubqOyRT4FDwv2vEe2T8= 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=RmKCG2vjvx5pkCe9XrXlTLfU5SXj6SQnQr7mWTh5qIk=; b=EgIo+zL5xCyHEzsW8VxMhDcNEqej/Te0G4kmkvMKR6GRBxd7062X+SgWmsZAdecNEi 3+eVefvSuEsQs0FzGVKz147Do05iPKB1KEh2zQ2ngE6ln9kROzH2EDbQfjkejgBUpCVI TX5qKLc5X9Tw2jxHR27gn/bavktAT4T/tuay0QdczP4nYUdJ/Ji2iQPrNqouESO+ad4B ACyaWtdHE9o5PyHJnDN+p27z6IqdktieNeIDKi9ITUHrEmarNZty9tnb97AeoejFV30x RBfGksJw7ilEZsA6Y43n8RtNmMuyUYbFIqh9B361XvFQk/FTxKhPrnb7gPG/6LUbiJN4 /VYA== X-Gm-Message-State: AA+aEWZbyaNzQhEb5n+6KcsJMX4mYCITHrni9EM689FYWwjvT4nlfL6j s46FSqwCb+r+R6ugHpiJMLSSrQ== X-Received: by 2002:a63:85c6:: with SMTP id u189mr16105154pgd.156.1544581515165; Tue, 11 Dec 2018 18:25:15 -0800 (PST) Received: from exogeni.mtv.corp.google.com ([2620:15c:202:1:db8d:8e3f:2514:5db8]) by smtp.gmail.com with ESMTPSA id f6sm27334649pfg.188.2018.12.11.18.25.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 18:25:14 -0800 (PST) From: Derek Basehore To: peterz@infradead.org Cc: mingo@redhat.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, Derek Basehore Subject: RFC [PATCH 1/1] locking/lockdep: Fix nest lock warning on unlock Date: Tue, 11 Dec 2018 18:25:06 -0800 Message-Id: <20181212022506.171936-2-dbasehore@chromium.org> X-Mailer: git-send-email 2.20.0.rc2.403.gdbc3b29805-goog In-Reply-To: <20181212022506.171936-1-dbasehore@chromium.org> References: <20181212022506.171936-1-dbasehore@chromium.org> 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 The function __lock_acquire checks that the nest lock is held passed in as an argument. The issue with this is that __lock_acquire is used for internal bookkeeping on lock_release. This produces a false positive lockdep warning on unlock. Since you explicitly don't need to hold the nest lock on unlock, this is an issue. This fixes the problem by only checking the nest lock on the actual lock acquire step. Signed-off-by: Derek Basehore --- kernel/locking/lockdep.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 1efada2dd9dd..2e7297ee6596 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3155,15 +3155,15 @@ EXPORT_SYMBOL_GPL(lockdep_init_map); struct lock_class_key __lockdep_no_validate__; EXPORT_SYMBOL_GPL(__lockdep_no_validate__); -static int -print_lock_nested_lock_not_held(struct task_struct *curr, - struct held_lock *hlock, +static void +print_lock_nested_lock_not_held(struct lockdep_map *lock, + struct lockdep_map *nest_lock, unsigned long ip) { if (!debug_locks_off()) - return 0; + return; if (debug_locks_silent) - return 0; + return; pr_warn("\n"); pr_warn("==================================\n"); @@ -3171,22 +3171,21 @@ print_lock_nested_lock_not_held(struct task_struct *curr, print_kernel_ident(); pr_warn("----------------------------------\n"); - pr_warn("%s/%d is trying to lock:\n", curr->comm, task_pid_nr(curr)); - print_lock(hlock); + pr_warn("%s/%d is trying to lock:\n", current->comm, + task_pid_nr(current)); + pr_warn("%s\n", lock->name); pr_warn("\nbut this task is not holding:\n"); - pr_warn("%s\n", hlock->nest_lock->name); + pr_warn("%s\n", nest_lock->name); pr_warn("\nstack backtrace:\n"); dump_stack(); pr_warn("\nother info that might help us debug this:\n"); - lockdep_print_held_locks(curr); + lockdep_print_held_locks(current); pr_warn("\nstack backtrace:\n"); dump_stack(); - - return 0; } static int __lock_is_held(const struct lockdep_map *lock, int read); @@ -3335,9 +3334,6 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, } chain_key = iterate_chain_key(chain_key, class_idx); - if (nest_lock && !__lock_is_held(nest_lock, -1)) - return print_lock_nested_lock_not_held(curr, hlock, ip); - if (!validate_chain(curr, lock, hlock, chain_head, chain_key)) return 0; @@ -3843,6 +3839,9 @@ void lock_acquire(struct lockdep_map *lock, unsigned int subclass, trace_lock_acquire(lock, subclass, trylock, read, check, nest_lock, ip); __lock_acquire(lock, subclass, trylock, read, check, irqs_disabled_flags(flags), nest_lock, ip, 0, 0); + if (nest_lock && !__lock_is_held(nest_lock, -1)) + print_lock_nested_lock_not_held(lock, nest_lock, ip); + current->lockdep_recursion = 0; raw_local_irq_restore(flags); } -- 2.20.0.rc2.403.gdbc3b29805-goog