From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757304AbcBSGtT (ORCPT ); Fri, 19 Feb 2016 01:49:19 -0500 Received: from mail-wm0-f52.google.com ([74.125.82.52]:35713 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757119AbcBSGtQ (ORCPT ); Fri, 19 Feb 2016 01:49:16 -0500 From: Alfredo Alvarez Fernandez X-Google-Original-From: Alfredo Alvarez Fernandez To: sasha.levin@oracle.com, peterz@infradead.org, mingo@redhat.com Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 0/3] lockdep: liblockdep: Prevent chain_key collisions Date: Fri, 19 Feb 2016 07:48:50 +0100 Message-Id: <1455864533-7536-1-git-send-email-alfredoalvarezernandez@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <20160217083852.GC1197@gmail.com> References: <20160217083852.GC1197@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch series prevents possible collisions in the chain_key hashing macro iterate_chain_key(key1, key2) that can lead to lockdep not detecting very simple deadlocks such as AA or ABBA. The problem only affects the first allocated lock classes. That could explain why it was not seen while running lockdep's test suite, since by the time the test suite runs there are already registered lock classes and the indexes allocated for the lock classes under test are high enough to avoid collisions. The patch series also extends the tools/liblockdep test suite with tests covering the offending cases. I came across the problem while testing a simple AA deadlock scenario in userspace using a pthread_mutex and tools/liblockdep. In that context it is fairly easy to have a clean and deterministic initial state where the problem can be reproduced. The proposed solution was tested with the newly introduced tests and also with lockdep's test suite: [ 0.000000] Good, all 253 testcases passed! | v2: - Add detection for chain_key collisions under CONFIG_DEBUG_LOCKDEP. When a collision is detected the problem is reported and all lock debugging is turned off. Tested using liblockdep and the added tests before and after applying the fix, confirming both that the code added for the detection correctly reports the problem and that the fix actually fixes it. Tested tweaking lockdep to generate false collisions and verified that the problem is reported and that lock debugging is turned off. Also tested with lockdep's test suite after applying the patch: [ 0.000000] Good, all 253 testcases passed! | - Fix code style problems in added liblockdep tests Alfredo Alvarez Fernandez (3): tools/liblockdep: add userspace version of READ_ONCE tools/liblockdep: add tests lockdep: prevent and detect chain_key collisions kernel/locking/lockdep.c | 73 ++++++++++++++++++++++------- tools/lib/lockdep/tests/AA.c | 8 ++-- tools/lib/lockdep/tests/ABA.c | 13 +++++ tools/lib/lockdep/tests/ABBA_2threads.c | 46 ++++++++++++++++++ tools/lib/lockdep/uinclude/linux/compiler.h | 1 + 5 files changed, 121 insertions(+), 20 deletions(-) create mode 100644 tools/lib/lockdep/tests/ABA.c create mode 100644 tools/lib/lockdep/tests/ABBA_2threads.c -- 2.5.0