Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp994386pxb; Fri, 28 Jan 2022 15:13:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxunPSWuurzLZoSjI7YqQEL6TSeCcok0d5behaYMn/gldA2dlta6Z94dQdfM0AHiWmSQq/9 X-Received: by 2002:a17:906:9491:: with SMTP id t17mr8430361ejx.339.1643411624559; Fri, 28 Jan 2022 15:13:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643411624; cv=none; d=google.com; s=arc-20160816; b=HtLfFE7xMcDv1xGP6Lr00rMajPskG/6yyRqiw6TbiZHU+0jphk/z+sprI/sYl9LnHD ManFPb99jsIVNkJ/ED31dPZhJ4wx8T143w9uB8MqvrH0T/Hof/UZvVDdhz4g1ajdgrBE bQ63FIGOyebiROkqu30U6ELZag32/6W1dXlhv4UTgoEvf9kSdBXZ/4Ow1A2Bo61Agy6B R239INJZ4W6nlklnpIi4NtiObFydBRDmA53OviIs4Z4EGjeLJ76U7qqu8sNgZIxIsrFB aCrinZNGuGza0eBClaZFfpIKQLxx0px2Fytle25s4AGlxx/DjUcDDy3uN/Md5Xg7XZzA Mjtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=V/05GzOrgOl/UyUBKWfOm8imWYPgACNjFeMcbOGPBpc=; b=aSgrY7T13srVFhehN1c+aUiSH4KZOJz8xSwevE4orxmxFGYsiDIRYbCM1NWzZGXo76 jIeTnfcjobBHkha4V7/VJ4u7qs2Mo9tHLjXt13LP0uZXz/dy0FNr+Rg9WN26ZCX9MbzE Cs8S2lB18LZ0rUF7ySSRKJ0VqtrQSDurTUJrhQeVsjtqIlfTgiOMjzTE6DtxiRZ4LsV8 RjgzAlPBZqbg5+YCr9xIplUfJW5Hq0g27R1HNG09wSOFi9IK0VBy23LXbuSDw7/UTmBx JueEUbudg9sCelTG3n6wtG3MaR4UmOMDtzSd2xwK6P8V3JzBGgOAeIz5Kso12r5cOYsk z7zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=tLr1nf2C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n8si4316396edx.400.2022.01.28.15.13.20; Fri, 28 Jan 2022 15:13:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=tLr1nf2C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344618AbiA1A0e (ORCPT + 99 others); Thu, 27 Jan 2022 19:26:34 -0500 Received: from ale.deltatee.com ([204.191.154.188]:46948 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236199AbiA1A00 (ORCPT ); Thu, 27 Jan 2022 19:26:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=V/05GzOrgOl/UyUBKWfOm8imWYPgACNjFeMcbOGPBpc=; b=tLr1nf2CgmrXo3UylgDfejDLSA e7xAEnjM8MryfrJln0g42DeGCO4Tau2qcnIyG0UAgpBgHzPO155HM9LjSV55iVUuzjEEw/Aw0kTPf VoJL03pfwmN1Z9/T5DG4l3j86mVC9N/D0lVn2KL/Fre6jUPLw23Ngw4A2wNNmC+Cj7XRA3I29ze9G +/3EKIHzq2e29X3Gi5t4Ar5qNunlgnF/Jn2SL3QEX2T8gRsF9UlXfYMUHtDay/KcBT+wL1lQ/ToF1 Zkql/xSSCKKCXzk8vdecuhOKVjmehApGrLxNwOwyAj8sVjRx6Ycgw1RCx9yNmydD9HwLubB9aHPm/ h739BC5Q==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nDF5p-005OcX-U8; Thu, 27 Jan 2022 17:26:23 -0700 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1nDF5m-0001cD-7l; Thu, 27 Jan 2022 17:26:18 -0700 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org Cc: Stephen Bates , Christoph Hellwig , Dan Williams , Jason Gunthorpe , =?UTF-8?q?Christian=20K=C3=B6nig?= , John Hubbard , Don Dutile , Matthew Wilcox , Daniel Vetter , Jakowski Andrzej , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin , Bjorn Helgaas , Ira Weiny , Robin Murphy , Martin Oliveira , Chaitanya Kulkarni , Ralph Campbell , Alex Sierra , Theodore Ts'o , "Darrick J . Wong" Date: Thu, 27 Jan 2022 17:25:51 -0700 Message-Id: <20220128002614.6136-2-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220128002614.6136-1-logang@deltatee.com> References: <20220128002614.6136-1-logang@deltatee.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org, sbates@raithlin.com, hch@lst.de, jgg@ziepe.ca, ddutile@redhat.com, willy@infradead.org, daniel.vetter@ffwll.ch, jason@jlekstrand.net, dave.hansen@linux.intel.com, dan.j.williams@intel.com, andrzej.jakowski@intel.com, dave.b.minturn@intel.com, jianxin.xiong@intel.com, ira.weiny@intel.com, robin.murphy@arm.com, martin.oliveira@eideticom.com, ckulkarnilinux@gmail.com, jhubbard@nvidia.com, rcampbell@nvidia.com, christian.koenig@amd.com, alex.sierra@amd.com, tytso@mit.edu, helgaas@kernel.org, djwong@kernel.org X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-6.5 required=5.0 tests=ALL_TRUSTED,BAYES_00, MYRULES_FREE,MYRULES_NO_TEXT autolearn=no autolearn_force=no version=3.4.6 Subject: [PATCH v5 01/24] ext4/xfs: add page refcount helper X-SA-Exim-Version: 4.2.1 (built Sat, 13 Feb 2021 17:57:42 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ralph Campbell There are several places where ZONE_DEVICE struct pages assume a reference count == 1 means the page is idle and free. Instead of open coding this, add a helper function to hide this detail. Signed-off-by: Ralph Campbell Signed-off-by: Alex Sierra Reviewed-by: Christoph Hellwig Acked-by: Theodore Ts'o Acked-by: Darrick J. Wong --- fs/dax.c | 4 ++-- fs/ext4/inode.c | 5 +---- fs/fuse/dax.c | 4 +--- fs/xfs/xfs_file.c | 4 +--- include/linux/dax.h | 10 ++++++++++ 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index cd03485867a7..d9b856cf6436 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -369,7 +369,7 @@ static void dax_disassociate_entry(void *entry, struct address_space *mapping, for_each_mapped_pfn(entry, pfn) { struct page *page = pfn_to_page(pfn); - WARN_ON_ONCE(trunc && page_ref_count(page) > 1); + WARN_ON_ONCE(trunc && !dax_page_unused(page)); WARN_ON_ONCE(page->mapping && page->mapping != mapping); page->mapping = NULL; page->index = 0; @@ -383,7 +383,7 @@ static struct page *dax_busy_page(void *entry) for_each_mapped_pfn(entry, pfn) { struct page *page = pfn_to_page(pfn); - if (page_ref_count(page) > 1) + if (!dax_page_unused(page)) return page; } return NULL; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 5f79d265d06a..99e3ed7bcd06 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3899,10 +3899,7 @@ int ext4_break_layouts(struct inode *inode) if (!page) return 0; - error = ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) == 1, - TASK_INTERRUPTIBLE, 0, 0, - ext4_wait_dax_page(inode)); + error = dax_wait_page(inode, page, ext4_wait_dax_page); } while (error == 0); return error; diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c index 182b24a14804..f8b3f30d2303 100644 --- a/fs/fuse/dax.c +++ b/fs/fuse/dax.c @@ -676,9 +676,7 @@ static int __fuse_dax_break_layouts(struct inode *inode, bool *retry, return 0; *retry = true; - return ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) == 1, TASK_INTERRUPTIBLE, - 0, 0, fuse_wait_dax_page(inode)); + return dax_wait_page(inode, page, fuse_wait_dax_page); } /* dmap_end == 0 leads to unmapping of whole file */ diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 22ad207bedf4..57a440666935 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -859,9 +859,7 @@ xfs_break_dax_layouts( return 0; *retry = true; - return ___wait_var_event(&page->_refcount, - atomic_read(&page->_refcount) == 1, TASK_INTERRUPTIBLE, - 0, 0, xfs_wait_dax_page(inode)); + return dax_wait_page(inode, page, xfs_wait_dax_page); } int diff --git a/include/linux/dax.h b/include/linux/dax.h index 9fc5f99a0ae2..479939b3be40 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -201,6 +201,16 @@ static inline bool dax_mapping(struct address_space *mapping) return mapping->host && IS_DAX(mapping->host); } +static inline bool dax_page_unused(struct page *page) +{ + return page_ref_count(page) == 1; +} + +#define dax_wait_page(_inode, _page, _wait_cb) \ + ___wait_var_event(&(_page)->_refcount, \ + dax_page_unused(_page), \ + TASK_INTERRUPTIBLE, 0, 0, _wait_cb(_inode)) + #ifdef CONFIG_DEV_DAX_HMEM_DEVICES void hmem_register_device(int target_nid, struct resource *r); #else -- 2.30.2