Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp489380pxb; Wed, 13 Apr 2022 06:31:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4/t3FNy4M7zQjPN9cVlRJX7QREcERjeRSXYW9/Q9eN05J35TiCAgeIkRZw0TV7bo6IEQQ X-Received: by 2002:a17:903:2446:b0:154:3bb0:7ba0 with SMTP id l6-20020a170903244600b001543bb07ba0mr41815218pls.38.1649856672411; Wed, 13 Apr 2022 06:31:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649856672; cv=none; d=google.com; s=arc-20160816; b=mAX8q/g+HBWgcb+V79WVybyC2vy21FW3p5xRza8j4XmhKCb6MYNzDyW5SqSoI9IQmy Aatjc/dneBO4/wlKVpzELH9LnKXlwGdjH6TfWg0ylLaUBxadio+Mhejeo3PC+X+Zq/qV ZJ7dH6RE/vvgchxCYtfGX1rzrACwuN8mn2kNQfJvXcvSyUp9jkOqoq8KPplOVLAzeqn6 +21cp+mkF2SStK2M77NWPorfe3/l75ACMsgPfDGVv1dACJvy3pLzdk7lC3c4XS8FX/DB Fl50W5p7i+OP4LMoVZFV668bhXZQz91BbwXRq/JfS9EIDiT8XvzKeFKBmEuuBlCSdURo nJjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:message-id:date:cc:to:from:subject:dkim-signature; bh=krlOYNIPWVqzv8KTzYmJOnh6IDJk9Q0erJL/yjrcB7o=; b=NVOYQfZYNrkQfoZ3uqfYguHEbjvwj055dWYxq9nwk5K3xH84l9Lp6CfKCGvD/pznpZ RsO2u2weA9kCSTjGIUTeRaTAmJ0Tzm96g2bMjK+SN0KAD/UKNdaS0Jx7Hm8WpNMRiA1N IzSI92XefOAONjJt/6GHtcLcBnxrNyYfUXBYEioqWqQkMYuPjqukUnhgChUe9bRQoZK9 MqZ7f/13sv8tCoQgAZZpQdUAM9dD+bKVz2BOzP+dpYl2TY1XHGOmyBwg8jcZrwKk4g96 6khT4mCiY1/WVKzOGwK0yMNWAjHFjF0BoWRNuLtPruRhWiGhJZFVbGBTvl8SY5oi81UX Qlww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bV7PMUEm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t186-20020a6381c3000000b003816043ee48si4214787pgd.61.2022.04.13.06.30.26; Wed, 13 Apr 2022 06:31:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bV7PMUEm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232773AbiDMGD4 (ORCPT + 99 others); Wed, 13 Apr 2022 02:03:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230025AbiDMGDy (ORCPT ); Wed, 13 Apr 2022 02:03:54 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C3F8252BC; Tue, 12 Apr 2022 23:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649829694; x=1681365694; h=subject:from:to:cc:date:message-id:mime-version: content-transfer-encoding; bh=PfDWaktmCESkI/Q8ppnRmVQE2iUjMwl7xXHFrkBc6ik=; b=bV7PMUEmf/NIqB0dNMvfGUlUrrHvTbk18//QMsqvW+9FFmxzBq2nn/Sp mkoi2Ep5/y/Nb/LvGwuzFzD0up19lZaMu3Ztleraz360fnEMv0EUA6AjG B07uZrW+YiTtkJgpWj/ZIK6+osASkO4Q5uSgMdptbuYa1pN6AgWxxQuXJ AGeDcwH+DmN6GPGh2jCNyZwfV8tp4aiDgeKvg8E987PvGCGxs5aO5Ljtv GDTC9AU2gDuvJ32nkz/2g+K+RNC2DhNX9fEKcOmytgA2IGX2OLloEyax/ cds4hJ9ncpnk/xUbtt6v7PhFf3xh9U5SgnNxeXEVBKZccqFo78mJInVd3 w==; X-IronPort-AV: E=McAfee;i="6400,9594,10315"; a="323027652" X-IronPort-AV: E=Sophos;i="5.90,255,1643702400"; d="scan'208";a="323027652" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2022 23:01:34 -0700 X-IronPort-AV: E=Sophos;i="5.90,256,1643702400"; d="scan'208";a="660799727" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.25]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2022 23:01:28 -0700 Subject: [PATCH v2 00/12] device-core: Enable device_lock() lockdep validation From: Dan Williams To: linux-cxl@vger.kernel.org Cc: Ira Weiny , Dave Jiang , Peter Zijlstra , Jonathan Cameron , Vishal Verma , Ben Widawsky , Kevin Tian , Pierre-Louis Bossart , Alison Schofield , Boqun Feng , Ingo Molnar , Greg Kroah-Hartman , Will Deacon , Waiman Long , "Rafael J. Wysocki" , gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev Date: Tue, 12 Apr 2022 23:01:28 -0700 Message-ID: <164982968798.684294.15817853329823976469.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Changes since v1 [1]: - Improve the clarity of the cover letter and changelogs of the major patches (Patch2 and Patch12) (Pierre, Kevin, and Dave) - Fix device_lock_interruptible() false negative deadlock detection (Kevin) - Fix off-by-one error in the device_set_lock_class() enable case (Kevin) - Spelling fixes in Patch2 changelog (Pierre) - Compilation fixes when both CONFIG_CXL_BUS=n and CONFIG_LIBNVDIMM=n. (0day robot) [1]: https://lore.kernel.org/all/164610292916.2682974.12924748003366352335.stgit@dwillia2-desk3.amr.corp.intel.com/ --- The device_lock() is why the lockdep_set_novalidate_class() API exists. The lock is taken in too many disparate contexts, and lockdep by design assumes that all device_lock() acquisitions are identical. The lack of lockdep coverage leads to deadlock scenarios landing upstream. To mitigate that problem the lockdep_mutex was added [2]. The lockdep_mutex lets a subsystem mirror device_lock() acquisitions without lockdep_set_novalidate_class() to gain some limited lockdep coverage. The mirroring approach is limited to taking the device_lock() after-the-fact in a subsystem's 'struct bus_type' operations and fails to cover device_lock() acquisition in the driver-core. It also can only track the needs of one subsystem at a time so, for example the kernel needs to be recompiled between CONFIG_PROVE_NVDIMM_LOCKING and CONFIG_PROVE_CXL_LOCKING depending on which subsystem is being regression tested. Obviously that also means that intra-subsystem locking dependencies can not be validated. Two enhancements are proposed to improve the current state of device_lock() lockdep validation: 1/ Communicate a lock class to the device-core and let it acquire dev->lockdep_mutex per the subsystem's nested locking expectations. 2/ Go further and provide a lockdep_mutex per-subsystem so each has the full span of MAX_LOCKDEP_SUBCLASSES available for its use. This enabling has already prevented at least one device_lock() deadlock from making its way upstream. [2]: commit 87a30e1f05d7 ("driver-core, libnvdimm: Let device subsystems add local lockdep coverage") --- Dan Williams (12): device-core: Move device_lock() lockdep init to a helper device-core: Add dev->lock_class to enable device_lock() lockdep validation cxl/core: Refactor a cxl_lock_class() out of cxl_nested_lock() cxl/core: Remove cxl_device_lock() cxl/core: Clamp max lock_class cxl/core: Use dev->lock_class for device_lock() lockdep validation cxl/acpi: Add a device_lock() lock class for the root platform device libnvdimm: Refactor an nvdimm_lock_class() helper ACPI: NFIT: Drop nfit_device_lock() libnvdimm: Drop nd_device_lock() libnvdimm: Enable lockdep validation device-core: Enable multi-subsystem device_lock() lockdep validation drivers/acpi/nfit/core.c | 30 ++++--- drivers/acpi/nfit/nfit.h | 24 ------ drivers/base/core.c | 5 - drivers/cxl/acpi.c | 1 drivers/cxl/core/memdev.c | 1 drivers/cxl/core/pmem.c | 6 + drivers/cxl/core/port.c | 56 ++++++------- drivers/cxl/cxl.h | 76 +++++++----------- drivers/cxl/mem.c | 4 - drivers/cxl/pmem.c | 12 +-- drivers/cxl/port.c | 2 drivers/nvdimm/btt_devs.c | 16 ++-- drivers/nvdimm/bus.c | 26 +++--- drivers/nvdimm/core.c | 10 +- drivers/nvdimm/dimm_devs.c | 8 +- drivers/nvdimm/namespace_devs.c | 36 ++++----- drivers/nvdimm/nd-core.h | 51 +++--------- drivers/nvdimm/pfn_devs.c | 24 +++--- drivers/nvdimm/pmem.c | 2 drivers/nvdimm/region.c | 2 drivers/nvdimm/region_devs.c | 16 ++-- include/linux/device.h | 162 ++++++++++++++++++++++++++++++++++++++- lib/Kconfig.debug | 23 ------ 23 files changed, 325 insertions(+), 268 deletions(-) -- base-commit: ce522ba9ef7e2d9fb22a39eb3371c0c64e2a433e