From patchwork Tue Apr 30 17:44:24 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: 13649810 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 79B32C4345F for ; Tue, 30 Apr 2024 17:44:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E580A6B00C0; Tue, 30 Apr 2024 13:44:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E075E6B00BF; Tue, 30 Apr 2024 13:44:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE2D86B00C2; Tue, 30 Apr 2024 13:44:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9C3B66B00BF for ; Tue, 30 Apr 2024 13:44:48 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 196C7A15B8 for ; Tue, 30 Apr 2024 17:44:48 +0000 (UTC) X-FDA: 82066923456.07.5D8EB84 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by imf04.hostedemail.com (Postfix) with ESMTP id CD8BC4000C for ; Tue, 30 Apr 2024 17:44:45 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=cBjZiq7X; spf=pass (imf04.hostedemail.com: domain of vishal.l.verma@intel.com designates 198.175.65.10 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714499086; 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:in-reply-to:references:references:dkim-signature; bh=Pih/+yY2ciakpRXfNfV/CIIuPIeOCltpAElFzV4y3Bg=; b=C/JoUuYL27kWjV9Nga/4GG3WK21FdMz+klCGLq5uwvBFHzQPV3s/G6rA4gb+P0gA0jTcKU CT12g9pUXmk5WfTXAK1M9lMg7XIJjmAkP9tss00wzPPK6C0JzRKo55cUh6vU9oQvOqFEx1 30FQ9qAS3qYPlq1DV7vMWaYmBafUGSo= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=cBjZiq7X; spf=pass (imf04.hostedemail.com: domain of vishal.l.verma@intel.com designates 198.175.65.10 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714499086; a=rsa-sha256; cv=none; b=4C61juTVE+Ab+GJYPGYy9Zma6fcVVOTz/TEY5DvrBHSrk5Khgyxz9pd0u9UET1mnhSH8J2 2KrlVipj1XKuYrDBM2/6D1YCzfD8kPkj/SFp2YGOo00pc/H5kUNQ0wS7c7YZT3uzQBiGkL aZy48a6OlvZOwdMayv6Ce089wdqrdAo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1714499086; x=1746035086; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=T52oU7nq5CORc4zUmW3MiR7iyOzbCEAUapTKwbnnDtE=; b=cBjZiq7X78iCAlTCtP3+5zzwyuIsRExgrsYHV7YU/W8WE/FH0o6qDUMv CUjx0E4hWYwlTIXTgIEcbhkG/NNyovFZbZCCOgOZ6Z6CyVnBizQ5NHDAh z02G78XexL5oZE6/kq8b5pYuQszY5oVP7dl8VaNQdokcOd0pn1I6YXw7+ MYda8YRdcXknRzpjOtoFhg2sG3vA8ygWQO+C/A5eehhHH5v0llEZf7r27 Bl6ZFQdOyBoicRiylzRDU/9ucL0V6pmMg2GVYA0CWSyGxM9Ycv7MeYt4i W2KRQH+3m8/Rq5FbaLyVb2Hl+QL0+pOxzgAp6sYs4rmsOj70EpGg0zJ0r g==; X-CSE-ConnectionGUID: rGFS+za4TI2UDM0p9i8XKQ== X-CSE-MsgGUID: 9For+gHRTb656uSVVGYlog== X-IronPort-AV: E=McAfee;i="6600,9927,11060"; a="27669836" X-IronPort-AV: E=Sophos;i="6.07,242,1708416000"; d="scan'208";a="27669836" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Apr 2024 10:44:41 -0700 X-CSE-ConnectionGUID: mAtDHbLVRkeXR30fmCFHxg== X-CSE-MsgGUID: liAd+UmlS8+j6gqf+bh/lw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,242,1708416000"; d="scan'208";a="26534777" Received: from vverma7-desk1.amr.corp.intel.com (HELO [192.168.1.200]) ([10.212.82.45]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Apr 2024 10:44:41 -0700 From: Vishal Verma Date: Tue, 30 Apr 2024 11:44:24 -0600 Subject: [PATCH v3 2/4] dax/bus.c: fix locking for unregister_dax_dev / unregister_dax_mapping paths MIME-Version: 1.0 Message-Id: <20240430-vv-dax_abi_fixes-v3-2-e3dcd755774c@intel.com> References: <20240430-vv-dax_abi_fixes-v3-0-e3dcd755774c@intel.com> In-Reply-To: <20240430-vv-dax_abi_fixes-v3-0-e3dcd755774c@intel.com> 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=3760; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=T52oU7nq5CORc4zUmW3MiR7iyOzbCEAUapTKwbnnDtE=; b=owGbwMvMwCXGf25diOft7jLG02pJDGmGehxf90/d0nXems10qoBf6nS+bxeNLjG1dP1Rc0w4I ZLQVyrYUcrCIMbFICumyPJ3z0fGY3Lb83kCExxh5rAygQxh4OIUgIlozmFkOLHqhbMVN3/OfKaM yUJ3l3GLbshgnx3VKqeklKO6MZqFi+GfUd+7g/M8FsVor3m469bJ2YYu7+06zvy3FJl/6Ln69rP X+QE= X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Rspamd-Queue-Id: CD8BC4000C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: bzfw6rmfbzj519haeeb1pwzrqq8hkdbo X-HE-Tag: 1714499085-422930 X-HE-Meta: U2FsdGVkX18IexJZYKWmTP5mYCYTIy2ViS2J/dpEkcIiuFRAmAUAdoMumZHQ+wSfmwEGfCueuo5QcWHRmRN0Zapp0pw8odhn8SwxxHcFMWiVHFFY3iScuGfdW2E/b1FelwkLMRmfEDTWQAVEZi95TfQuFaCfv/QIFyWTepbFQDLptKy3gKX4bgcjXTSfSV8XE4GXGxxQFWC0ZkiubZSaGc2RpH1LCkqtM+arph0qWRbSlZMXRzbJyNoCKmqvFiOKFuIsltekQ8jyO7vUHhtz1DMJsD6KZQRrQBqnE1Fa7aMUn2wPwWtHrUYdPYwa8F8tN+EQ3XQkvd8nn+nfa2rD8U9wyWFO/lGvHwydO1Ms7r6w+BdcxXxwygD/5DiKAyUbTJ4u9EtCMwzOYuV4/6QSaIXdiDYGYfnxYTlx58SzABn6RstCZN6lUwZ9u1CGGVKqsjcWI3icoelePSKBnTAignQXtQdPH/2Acd7ThoctS7ej9DrS7YbFijs7L8heFiIv/WJ/9h1KRvZh9oeu+pcCvXavjWjrtNNFXNqd4WOv/siFaxtsULwcqGXYGznlPrSzkSVmyfm+4QldcMV9zkNisSkhqr5B4d92B/3mwerBY5KdWwYoM9ofp9uQ98TDhZmMustkHVt+fVm+p1Prhe9ypQqdR3EIiXKTsLHrn+zOwgQSPiavsK6L8dl9XZzOCLPpZn55tJZWJ2+us7+Wgd7M8l4BuPAKFgQ6EvBaGz0DSsHalfHv1go4ixmVY3EXubj7ep6SnjmuVIxUZTtZH3X5/c5SgaD/rwIPd7mA/L6QWTYJaZgvEVhnsgKmIWGFeV6F1LCDfmb2S1brxU65gzGctGpyj3nJw3pQKR4Aj+fNtYrGe7BwZn/Ghp0F4YwwXEM7Bvb3/SQXug6Sjp6T4RyoFLewpD2THZWoeZYHt2RKYM8ZyccCdS8Yu+1M1GgjsoW6MFymqudao1tAy0Rahzw ngcfV4sz //5ylF4piXU0eYeHpf6xElievyJh316JtcdsxVAXcqgLRA5Q+kvcyjxvvze5c8ifJUMbBe3aCD7aLBe+hzc7khgEnczZzXBGsyLn3u5gV7cnIPs4BxPyx6BQtm+Rul9AcVk3lTOKadtZmz/6AOrsgPc5dRef2M3ORVJfn5JkiSFAmQb7mXPF2bToQ/URVethiXXQktr98iTzmHp6dlxWZ8ihRWWQR7ZpYYpULG/yp4iO8QSfbvfk9tk724Q== 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: Commit c05ae9d85b47 ("dax/bus.c: replace driver-core lock usage by a local rwsem") aimed to undo device_lock() abuses for protecting changes to dax-driver internal data-structures like the dax_region resource tree to device-dax-instance range structures. However, the device_lock() was legitamately enforcing that devices to be deleted were not current actively attached to any driver nor assigned any capacity from the region. As a result of the device_lock restoration in delete_store(), the conditional locking in unregister_dev_dax() and unregister_dax_mapping() can be removed. Fixes: c05ae9d85b47 ("dax/bus.c: replace driver-core lock usage by a local rwsem") Reported-by: Dan Williams Reviewed-by: Dan Williams Signed-off-by: Vishal Verma --- drivers/dax/bus.c | 42 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 7924dd542a13..e2c7354ce328 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -465,26 +465,17 @@ static void free_dev_dax_ranges(struct dev_dax *dev_dax) trim_dev_dax_range(dev_dax); } -static void __unregister_dev_dax(void *dev) +static void unregister_dev_dax(void *dev) { struct dev_dax *dev_dax = to_dev_dax(dev); dev_dbg(dev, "%s\n", __func__); + down_write(&dax_region_rwsem); kill_dev_dax(dev_dax); device_del(dev); free_dev_dax_ranges(dev_dax); put_device(dev); -} - -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)) - return; - __unregister_dev_dax(dev); up_write(&dax_region_rwsem); } @@ -560,15 +551,10 @@ static ssize_t delete_store(struct device *dev, struct device_attribute *attr, if (!victim) return -ENXIO; - rc = down_write_killable(&dax_region_rwsem); - if (rc) - return rc; - rc = down_write_killable(&dax_dev_rwsem); - if (rc) { - up_write(&dax_region_rwsem); - return rc; - } + device_lock(dev); + device_lock(victim); dev_dax = to_dev_dax(victim); + down_write(&dax_dev_rwsem); if (victim->driver || dev_dax_size(dev_dax)) rc = -EBUSY; else { @@ -589,11 +575,12 @@ static ssize_t delete_store(struct device *dev, struct device_attribute *attr, rc = -EBUSY; } up_write(&dax_dev_rwsem); + device_unlock(victim); /* won the race to invalidate the device, clean it up */ if (do_del) devm_release_action(dev, unregister_dev_dax, victim); - up_write(&dax_region_rwsem); + device_unlock(dev); put_device(victim); return rc; @@ -705,7 +692,7 @@ static void dax_mapping_release(struct device *dev) put_device(parent); } -static void __unregister_dax_mapping(void *data) +static void unregister_dax_mapping(void *data) { struct device *dev = data; struct dax_mapping *mapping = to_dax_mapping(dev); @@ -713,25 +700,12 @@ static void __unregister_dax_mapping(void *data) dev_dbg(dev, "%s\n", __func__); - lockdep_assert_held_write(&dax_region_rwsem); - dev_dax->ranges[mapping->range_id].mapping = NULL; mapping->range_id = -1; device_unregister(dev); } -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)) - return; - __unregister_dax_mapping(data); - up_write(&dax_region_rwsem); -} - static struct dev_dax_range *get_dax_range(struct device *dev) { struct dax_mapping *mapping = to_dax_mapping(dev);