Received: by 10.223.185.116 with SMTP id b49csp1593019wrg; Wed, 21 Feb 2018 23:06:48 -0800 (PST) X-Google-Smtp-Source: AH8x226WFO0ey0go/1+3zkxzZOOvL2F30S1MmM/wTWyNgo6ASYSWr8yvU/4ELZwWnUO1AJIPqFIE X-Received: by 2002:a17:902:4d:: with SMTP id 71-v6mr5633609pla.341.1519283207907; Wed, 21 Feb 2018 23:06:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519283207; cv=none; d=google.com; s=arc-20160816; b=ixIZGEcu1LeJhpooaSk4wtEsVtTowns3v3ukKow3MSLp9Hu2SnaPfQygFnjhy/dq8x 5GrkSKzNpS2sIxsmlPUYPThLtT9kRnJf0HfDk4lPGZ2ZVskTmOaCYB1iYw1KBXARPH3d 1Mr+ZNGavt6BzZlgvSfpvjZ4OlsY45NuAgVXfPlrkcF5txdeBh9nJOnpNkzVchNmUlTK Xr0LfMy0zml4HYD3KFEUBoTFhSVmRCVk0Vh0K4/emIuUeiDgLiR0Ccl+wjYtZKUloVhr pJYZ3UlZqiYLOgEAChk6XUsXFTRSsWnu/D515UZk4vSJhK2/KcmWNGaiFsmOOjqXZG1l pY9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=oboUmE7XPpXUSSssrKkrgkeOzwYAv9AawXo+byFYF/4=; b=0w57ZRQq5CLors0tEUYcxuORV94LOxhWFApSWepNoJL98wyAPEYYorH98qvO7Asjnz y8TjQlxm8vX9XXhhJlTC/gcK8tojYqZ0y67hyglJF5JK4p/aWWZAF/xK5wn0wb34DUaD oUhClzqqXmicsFSxhxoTiqNeE/vxvvjWoqQAm7hszqq0VFyMJdIPmphpRt1lTYQ5Piq8 6wEZg3rRpft2AHaeY8VJ4woRLwgUghMd2GuRIxSVeeHG49Lxq3kMonvn2x2KhvJi+Cgz f4fNpbizAZwNTWxPF8VrNdqZnci1n9/ioQSC2qdOr78/2ubSpOGOvG5eKJNS39gtW8+F rA6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EiQIieOx; 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 f69si780908pfd.211.2018.02.21.23.06.32; Wed, 21 Feb 2018 23:06:47 -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=EiQIieOx; 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 S1752442AbeBVHFv (ORCPT + 99 others); Thu, 22 Feb 2018 02:05:51 -0500 Received: from mail-wm0-f52.google.com ([74.125.82.52]:33998 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751657AbeBVHFu (ORCPT ); Thu, 22 Feb 2018 02:05:50 -0500 Received: by mail-wm0-f52.google.com with SMTP id a20so1042851wmd.1 for ; Wed, 21 Feb 2018 23:05:49 -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; bh=oboUmE7XPpXUSSssrKkrgkeOzwYAv9AawXo+byFYF/4=; b=EiQIieOxwATY2hPe2bxQL637WgbHdeowf8OYSrI2jN0Dckb/sOaHRtk/5ipALVGS14 PRzZP45nDNefcdXd6QwXt1I+91TZkxzhUPCqox1YzTiBQzGL2/YlDhC4fMS/skGfP3gg WoD29jRWNdW+9itUJt/zKgHx9Q5o+rlM2jZ4+tIG7HXjyHaA76F4KUGDUDlziuOuLNne EBtAgybIMM5b/jn4ft4fWid03aqalk/OZMgnbKG0iyHIzWaqim68f7JvGroIB2+kCWpO xC5Q1pdFP1GuxIhGM74UTBpDLRiRPYWEAoI0oGDYzC7BVeYQg+x+4gm8Q5CxEgXqAs4z KKXg== 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; bh=oboUmE7XPpXUSSssrKkrgkeOzwYAv9AawXo+byFYF/4=; b=SFvrBTPlmpprCOeJzy60hTzWos0M+5nlZ45ajJkTwBij3mDZoRWgXRvY1N3nveemfT dUzWOHKojFjZ0vsKuXJjKW8f7Khj9faZ1vk8en62/IAPZQCDiqEJASYoiH4tCUjNR/vY Yf01fRYSg9MCmioEFWp9GQM6AAaEKvDnN3Gq4jddHo1LcT2333cX0gEyeg+ieTbWPTjJ fF+dQmUr1+NofV3ZT03ZWX9+kkumKsS61+3wqlyeUVBSKEpEyxBBsx1/omddkG0roY5q sjSJ1Nl9fFq8UNA33RIOVl4YrJhedH94v41AcRyXieWlStNn3a1Z7xW36Pyr5f/bslYg 7STw== X-Gm-Message-State: APf1xPAMDOSLrxWW3YL6ij74o29JdulHMuL8w6IZVBskBu1ubE1LAv5D 96CfeLjTFbKslYu1Hef+xKE= X-Received: by 10.80.226.68 with SMTP id o4mr8129405edl.151.1519283148714; Wed, 21 Feb 2018 23:05:48 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id 26sm9710530eds.26.2018.02.21.23.05.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 23:05:47 -0800 (PST) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailauth.nyi.internal (Postfix) with ESMTP id 1CC2220B1C; Thu, 22 Feb 2018 02:05:46 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute7.internal (MEProxy); Thu, 22 Feb 2018 02:05:46 -0500 X-ME-Sender: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id 7F8547E371; Thu, 22 Feb 2018 02:05:45 -0500 (EST) From: Boqun Feng To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Ingo Molnar , Andrea Parri , Boqun Feng Subject: [RFC tip/locking/lockdep v5 00/17] lockdep: Support deadlock detection for recursive read locks Date: Thu, 22 Feb 2018 15:08:47 +0800 Message-Id: <20180222070904.548-1-boqun.feng@gmail.com> X-Mailer: git-send-email 2.16.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ingo and Peter, This is V5 for recursive read lock support in lockdep. The changes since V4 are quite trivial: * Fix some wording issues in patch #16 as pointed out by Randy Dunlap I added the explanation about reasoning in patch #16 in V4, which will help understand this whole series. This patchset is based on v4.16-rc2. Changes since V3: * Reduce the unnecessary cost in structure lock_list as suggested by Peter Zijlstra * Add documentation for explanation of the reasoning in recursive read lock deadlock detection. * Add comments before bfs() describing the greedy search we use in BFS for strong dependency paths. * Add myself as a reviewer for LOCKING PRIMITIVES so that if there is any performance regression, log misunderstanding or false positives, people know who to blame^Wask help from. V1: https://marc.info/?l=linux-kernel&m=150393341825453 V2: https://marc.info/?l=linux-kernel&m=150468649417950 V3: https://marc.info/?l=linux-kernel&m=150637795424969 V4: https://marc.info/?l=linux-kernel&m=151550860121565 As Peter pointed out: https://marc.info/?l=linux-kernel&m=150349072023540 The lockdep current has a limit support for recursive read locks, the deadlock case as follow could not be detected: read_lock(A); lock(B); lock(B); write_lock(A); I got some inspiration from Gautham R Shenoy: https://lwn.net/Articles/332801/ , and came up with this series. The basic idea is: * Add recursive read locks into the graph * Classify dependencies into -(RR)->, -(NR)->, -(RN)->, -(NN)->, where R stands for recursive read lock, N stands for other locks(i.e. non-recursive read locks and write locks). * Define strong dependency paths as the paths of dependencies don't have two adjacent dependencies as -(*R)-> and -(R*)->. * Extend __bfs() to only traverse on strong dependency paths. * If __bfs() finds a strong dependency circle, then a deadlock is reported. The whole series consists of 17 patches: 1. Do a clean up on the return value of __bfs() and its friends. 2. Make __bfs() able to visit every dependency until a match is found. The old version of __bfs() could only visit each lock class once, and this is insufficient if we are going to add recursive read locks into the dependency graph. 3. Redefine LOCK*_STATE*, now LOCK*_STATE_RR stand for recursive read lock only and LOCK*_STATE stand for write lock and non-recursive read lock. 4-5 Extend __bfs() to be able to traverse the stong dependency patchs after recursive read locks added into the graph. 6-8 Adjust check_redundant(), check_noncircular() and check_irq_usage() with recursive read locks into consideration. 9. Finally add recursive read locks into the dependency graph. 10-11 Adjust lock cache chain key generation with recursive read locks into consideration, and provide a test case. 12-13 Add more test cases. 14. Revert commit d82fed752942 ("locking/lockdep/selftests: Fix mixed read-write ABBA tests"), 15. Reduce the extra size cost of lock_list to zero 16. Add documentation for recursive read lock deadlock detection reasoning 17. Add myself as a LOCKING PRIMITIVES reviewer. This series passed all the lockdep selftest cases(including those I introduce). Test and comments are welcome! Regards, Boqun