From patchwork Tue Apr 2 06:24:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 13613413 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E063CD1284 for ; Tue, 2 Apr 2024 06:24:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFD446B008C; Tue, 2 Apr 2024 02:24:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BACDB6B0092; Tue, 2 Apr 2024 02:24:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A26406B0093; Tue, 2 Apr 2024 02:24:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 82E746B008C for ; Tue, 2 Apr 2024 02:24:42 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4E578A06F3 for ; Tue, 2 Apr 2024 06:24:42 +0000 (UTC) X-FDA: 81963603204.14.FE615C1 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) by imf05.hostedemail.com (Postfix) with ESMTP id 1621C100008 for ; Tue, 2 Apr 2024 06:24:38 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=YPAWNNMN; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf05.hostedemail.com: domain of vishal.l.verma@intel.com designates 198.175.65.19 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712039080; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=gtWTA//c5QKczt+OQRoeP+HLLvruPe0hDOCE+aelPTc=; b=CLqv5rhuvhyzhiUm0m8P16tXxQO4aH8j10Kop/vcR+zX2dF/OI19cTaSmCfRV08c5BkiI/ 32Lv/1E2rT1QirvH6d/S3GSjILEL/C5lQwFTJa+Gv6Jz+HniwpIsDw3rhL+J6YzE14gs4R LKVcpqJZhV8dkJACLxAY5HpJxojSsLg= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=YPAWNNMN; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf05.hostedemail.com: domain of vishal.l.verma@intel.com designates 198.175.65.19 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712039080; a=rsa-sha256; cv=none; b=zgPuKH8+1mRFSYNlWjHhNLwcoNjYA5lxb/J0eXAvEkjXYNqBFSTsS/5qzPAl1W1nJofR2C X5FIjRyQMhfQXoP75aPWDdqxlJ6l44wz9mw0tocc6vSM2ypbhGofISxinBA+f+LNpFAViV ImJqmPfPfy81Cr6VrOlAh9SbJTrNA24= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712039079; x=1743575079; h=from:date:subject:mime-version:content-transfer-encoding: message-id:to:cc; bh=Avcgwic9to73qYuJOM9j0RdxPlc4XVJ76Q8h7Wk8SVw=; b=YPAWNNMNZfOXYAQz8Bdz0FTISVwG22+HnfOjcmdChAicsy9QuYjYBd4d B/eCEJJsS6egnYAGYnwKi8b0UxlPZpY5Wr638vucKZXLR/H2BVryFwauH 2hB2xKc6ysZFUuLiOu6JJ7onUJQCVviGRW/DWkM3ar2D0uM1kkcvcHlZL /9OThVLVdhR27o2tBwRAuMUPKzRON/s93CuaYTKSKQ5NMb8PWOl0eY4hJ uFFzuDcmdDHoacNWxxXsttygmxXIa/xkUQFomL4z14C6OHfH+5luLt2o0 Ck881pVo2JC3slPlq52AF3T/CLutAYDUiD0VCPzlVIGHTT/kXnqWUZs+l w==; X-CSE-ConnectionGUID: /wSRCuUoStinmcx2xnGPeQ== X-CSE-MsgGUID: yEyd0ApZQWC0UaF8Gba7dw== X-IronPort-AV: E=McAfee;i="6600,9927,11031"; a="7044662" X-IronPort-AV: E=Sophos;i="6.07,174,1708416000"; d="scan'208";a="7044662" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2024 23:24:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,174,1708416000"; d="scan'208";a="18040555" Received: from vverma7-desk1.amr.corp.intel.com (HELO [192.168.1.200]) ([10.212.66.53]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2024 23:24:37 -0700 From: Vishal Verma Date: Tue, 02 Apr 2024 00:24:28 -0600 Subject: [PATCH] dax/bus.c: replace WARN_ON_ONCE() with lockdep asserts MIME-Version: 1.0 Message-Id: <20240402-vv-dax_abi_fixes-v1-1-c3e0fdbafba5@intel.com> X-B4-Tracking: v=1; b=H4sIAJukC2YC/x3LTQqAIBBA4avIrBNs+iG6SoRMOdZsKhRECO+et Px4vBciB+EIs3ohcJIo91XRNgr2k66DtbhqQIO96Q3qlLSjbGkT6yVz1BP5bhu9Rx4I6vYE/kO 9lrWUD3zE2/hiAAAA To: Dan Williams , Dave Jiang , Alison Schofield , Andrew Morton Cc: linux-mm@kvack.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Vishal Verma X-Mailer: b4 0.14-dev-5ce50 X-Developer-Signature: v=1; a=openpgp-sha256; l=5236; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=Avcgwic9to73qYuJOM9j0RdxPlc4XVJ76Q8h7Wk8SVw=; b=owGbwMvMwCXGf25diOft7jLG02pJDGncSxb4pTYHHd8tzN3jmrJ/kapw7kyTslmLJiQqZjJY7 0t7ztLWUcrCIMbFICumyPJ3z0fGY3Lb83kCExxh5rAygQxh4OIUgIlk3Gf4H8U1qX8DWxHjF+ut uqpvupjfJrvse8Wd3n+sUZnz9r+e9wx/5a8v4ZjPGzlToPeKjPel6sxFvMIa529F1DqbCFcka9/ kAwA= X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Rspamd-Queue-Id: 1621C100008 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: t3txcoz3y6kud4zersnhrbczm4ucg3c4 X-HE-Tag: 1712039078-12862 X-HE-Meta: U2FsdGVkX1/TfesqT7T0DQebHbcBhH3TV69dVP46L/Cev7SWYQAN3WFBJHWpz//WLqJ5MjWeJuKCtIHzhx4g5503krRYoeeHUxZPQHhWeH2UcdfNH9MhQCp3wBHeLudIVPAJthbqYl8GqFKm06invrhF1DtXZqzV2CSkqvy9Kvo1EoJnsAOzFIHlG6lvU+WzCF0CaGS5Y3ni6v+AbgbUtUqoC+twZE60AkIVKD3tVdCQ/TIi/Eb4cehmZDxlRVbKftzZcN+ybnwz97q5bQvcwjYOSgZDiBpFwmNo+a77t2wGfjyRMwBpikGTzLTX7f6wbv0jJsiDgzMdI489hOETMFPZnwLW/Rttj3yc02Otdvtv5o/jgd73hurVVEJAN7W+1YCze67Fr1lWXzKxyKjj+ORbH1Z6E95lxiVQ6WhtZPOZmpGfbX2O912HVYJWyw6O/Xyc9IM8L1xdr6VWJTkljFF5f/PelHXx3zZtyQP9nglfouLuCZr/TRsfz8Bob4vKdE3tiagSozteXRPXgESHzMaSgy8EQlLxvqHLmdQA4fWKE6j/BctD6nD0TyCNkX7VYy38GnUy9bCRNyBFMWKaQSH6JbOU86EYNOsZ8AWqYFpdSO1AvW0WN+Vs0ZWRENQpca900TqDLoCn+9kBxlWz+iQZ1CXzlnWNHmA9oL572qYROm7+f1VnnSD7uytSkMn2FhEe7BoFnTQ/oicZEuAUG2P5a4V5ppceqJiZvkhScwED+rzwT+84rB3FuvfhJnKN8kxt6YtlKoMeJpiYgDP/B6QrwNKz8NQhQco04IrXL/qThi5lc80df4B6es88Rso8KhB7GpZe6jS6/jZ5pXYnyf5DRb6+Dq+Dmdd51kRFpwa3SUV+E+hkKIXSYKko5VRL3vRphApBiFjhqngHQetkNvrbaCI/hWNmpuEjjSj3L6fitJ/5eM4AGaCw9d8+5D65LF+3W84MRpdT0CLjEME 1VPxWnVP 9dYUnXq0u0MwJFOGktgrskEMy9YIwzFZnj2TQTpagfEIoet9xDlFBMFBTSSQiNpE4KHUa2DwwEBrPamnv22tsQVRgrMaLtewhxFrits3z9YzA80SASu4APX7SS1K2GEwpYgfalFvbtgtluhN1SJ7SQnBjQuRqdczBGVBAFYc7MIvJWxIqm0/1Q5AxlKbo5PfQTfGV5HsEY63aWOnOW8uuZn+unbMJYt7kgTlU+uPA199peToyPsU6krhlG4zVM/Qqr6gQYDsk2ni6dlxT7X2x47GtrLJXm67YgdUdCLXqjqe0BneF+mv0cSbyxgDjJudEOuzq6pujaJEgJtQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In [1], Dan points out that all of the WARN_ON_ONCE() usage in the referenced patch should be replaced with lockdep_assert_held(_write)(). Replace those, and additionally, replace a couple of other WARN_ON_ONCE() introduced in the same patch for actual failure cases (i.e. when acquiring a semaphore fails in a remove / unregister path) with dev_WARN_ONCE() as is the precedent here. Recall that previously, unregistration paths was implicitly protected by overloading the device lock, which the patch in [1] sought to remove. This meant adding a semaphore acquisition in these unregistration paths. Since that can fail, and it doesn't make sense to return errors from these paths, retain the two instances of (now) dev_WARN_ONCE(). Link: https://lore.kernel.org/r/65f0b5ef41817_aa222941a@dwillia2-mobl3.amr.corp.intel.com.notmuch [1] Fixes: c05ae9d85b47 ("dax/bus.c: replace driver-core lock usage by a local rwsem") Cc: Andrew Morton Reported-by: Dan Williams Signed-off-by: Vishal Verma --- drivers/dax/bus.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) --- base-commit: 39cd87c4eb2b893354f3b850f916353f2658ae6f change-id: 20240402-vv-dax_abi_fixes-8af3b6ff2e5a Best regards, diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 797e1ebff299..d89c8c3b62f7 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -192,7 +192,7 @@ static u64 dev_dax_size(struct dev_dax *dev_dax) u64 size = 0; int i; - WARN_ON_ONCE(!rwsem_is_locked(&dax_dev_rwsem)); + lockdep_assert_held(&dax_dev_rwsem); for (i = 0; i < dev_dax->nr_range; i++) size += range_len(&dev_dax->ranges[i].range); @@ -302,7 +302,7 @@ static unsigned long long dax_region_avail_size(struct dax_region *dax_region) resource_size_t size = resource_size(&dax_region->res); struct resource *res; - WARN_ON_ONCE(!rwsem_is_locked(&dax_region_rwsem)); + lockdep_assert_held(&dax_region_rwsem); for_each_dax_region_resource(dax_region, res) size -= resource_size(res); @@ -447,7 +447,7 @@ static void trim_dev_dax_range(struct dev_dax *dev_dax) struct range *range = &dev_dax->ranges[i].range; struct dax_region *dax_region = dev_dax->region; - WARN_ON_ONCE(!rwsem_is_locked(&dax_region_rwsem)); + lockdep_assert_held_write(&dax_region_rwsem); dev_dbg(&dev_dax->dev, "delete range[%d]: %#llx:%#llx\n", i, (unsigned long long)range->start, (unsigned long long)range->end); @@ -471,6 +471,7 @@ static void __unregister_dev_dax(void *dev) dev_dbg(dev, "%s\n", __func__); + lockdep_assert_held_write(&dax_region_rwsem); kill_dev_dax(dev_dax); device_del(dev); free_dev_dax_ranges(dev_dax); @@ -482,7 +483,8 @@ static void unregister_dev_dax(void *dev) if (rwsem_is_locked(&dax_region_rwsem)) return __unregister_dev_dax(dev); - if (WARN_ON_ONCE(down_write_killable(&dax_region_rwsem) != 0)) + if (dev_WARN_ONCE(dev, down_write_killable(&dax_region_rwsem) != 0, + "unable to acquire region rwsem\n")) return; __unregister_dev_dax(dev); up_write(&dax_region_rwsem); @@ -507,7 +509,7 @@ static int __free_dev_dax_id(struct dev_dax *dev_dax) struct dax_region *dax_region; int rc = dev_dax->id; - WARN_ON_ONCE(!rwsem_is_locked(&dax_dev_rwsem)); + lockdep_assert_held_write(&dax_dev_rwsem); if (!dev_dax->dyn_id || dev_dax->id < 0) return -1; @@ -713,7 +715,7 @@ static void __unregister_dax_mapping(void *data) dev_dbg(dev, "%s\n", __func__); - WARN_ON_ONCE(!rwsem_is_locked(&dax_region_rwsem)); + lockdep_assert_held_write(&dax_region_rwsem); dev_dax->ranges[mapping->range_id].mapping = NULL; mapping->range_id = -1; @@ -726,7 +728,8 @@ static void unregister_dax_mapping(void *data) if (rwsem_is_locked(&dax_region_rwsem)) return __unregister_dax_mapping(data); - if (WARN_ON_ONCE(down_write_killable(&dax_region_rwsem) != 0)) + if (dev_WARN_ONCE(data, down_write_killable(&dax_region_rwsem) != 0, + "unable to acquire region rwsem\n")) return; __unregister_dax_mapping(data); up_write(&dax_region_rwsem); @@ -830,7 +833,7 @@ static int devm_register_dax_mapping(struct dev_dax *dev_dax, int range_id) struct device *dev; int rc; - WARN_ON_ONCE(!rwsem_is_locked(&dax_region_rwsem)); + lockdep_assert_held_write(&dax_region_rwsem); if (dev_WARN_ONCE(&dev_dax->dev, !dax_region->dev->driver, "region disabled\n")) @@ -876,7 +879,7 @@ static int alloc_dev_dax_range(struct dev_dax *dev_dax, u64 start, struct resource *alloc; int i, rc; - WARN_ON_ONCE(!rwsem_is_locked(&dax_region_rwsem)); + lockdep_assert_held_write(&dax_region_rwsem); /* handle the seed alloc special case */ if (!size) { @@ -935,7 +938,7 @@ static int adjust_dev_dax_range(struct dev_dax *dev_dax, struct resource *res, r struct device *dev = &dev_dax->dev; int rc; - WARN_ON_ONCE(!rwsem_is_locked(&dax_region_rwsem)); + lockdep_assert_held_write(&dax_region_rwsem); if (dev_WARN_ONCE(dev, !size, "deletion is handled by dev_dax_shrink\n")) return -EINVAL;