From patchwork Fri Oct 14 23:57:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 13007522 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 5193BC4332F for ; Fri, 14 Oct 2022 23:57:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D347B6B0081; Fri, 14 Oct 2022 19:57:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE5416B0082; Fri, 14 Oct 2022 19:57:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BAC526B0083; Fri, 14 Oct 2022 19:57:50 -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 A503F6B0081 for ; Fri, 14 Oct 2022 19:57:50 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7EA9AC0E13 for ; Fri, 14 Oct 2022 23:57:50 +0000 (UTC) X-FDA: 80021220300.22.0B6463E Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf23.hostedemail.com (Postfix) with ESMTP id 07C3E140029 for ; Fri, 14 Oct 2022 23:57:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665791870; x=1697327870; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dRBEo+va9LdTaMALBHzem55il8qhSDS6I2rVZ6WlqEM=; b=JsP6kXz7wDxS1G7veJDpAYeoY+yLw/Yw7fz1FeuC1EbNwZd7hJy67ZqQ EIlw0E3bHGJFE/YEd6R3i85j6erj4DN9J4OUOfiWxfQlOwc6yz1NlfrBc 8lB4DY49v/of1rK4qkDqywvFeM1rsT5eyZqECkg6dlO5bc/gko3M1pCUU 3Puf/OPOfNX/lw2S1zzHCA5PZTsCpN7y1BUEw/sJ63dqArr5XuZsi1sJF WgZhJ8CWqksB2b3M3JM+T+s+yXKRCi4XQFYU73uNMuj6pkJJwhDakZV3J 2dMxhX/JNlDpSU4sPpMl5aQPX25pH1sRIipUYK0Dk8c8PtV4iduAd9Hwj A==; X-IronPort-AV: E=McAfee;i="6500,9779,10500"; a="292861985" X-IronPort-AV: E=Sophos;i="5.95,185,1661842800"; d="scan'208";a="292861985" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2022 16:57:48 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10500"; a="630113300" X-IronPort-AV: E=Sophos;i="5.95,185,1661842800"; d="scan'208";a="630113300" Received: from uyoon-mobl.amr.corp.intel.com (HELO dwillia2-xfh.jf.intel.com) ([10.209.90.112]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2022 16:57:43 -0700 Subject: [PATCH v3 08/25] fsdax: Update dax_insert_entry() calling convention to return an error From: Dan Williams To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , "Darrick J. Wong" , Jason Gunthorpe , Christoph Hellwig , John Hubbard , david@fromorbit.com, nvdimm@lists.linux.dev, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org Date: Fri, 14 Oct 2022 16:57:43 -0700 Message-ID: <166579186334.2236710.388332274317019999.stgit@dwillia2-xfh.jf.intel.com> In-Reply-To: <166579181584.2236710.17813547487183983273.stgit@dwillia2-xfh.jf.intel.com> References: <166579181584.2236710.17813547487183983273.stgit@dwillia2-xfh.jf.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=JsP6kXz7; spf=pass (imf23.hostedemail.com: domain of dan.j.williams@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665791870; a=rsa-sha256; cv=none; b=xZe92tGyP+I9GZ21RZr8pBpG/Tv4fMpipTXWeLVckyJ73QworpfpPz/beqGzbwiZ5I3nZd nTELnmRqswfw9uN8di4AujELWnS5mzxoOye32282Xl/EErtVro1/z9H7AQpJKXcrBAJ/m2 i5Npt5GtH8/zW1/BqK1S9CK+8BhE5fI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665791870; 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=FqTkZYoXrsXbDq6UxOR5urGX8nFTPi0wgrVHtoiUmsM=; b=h78tV/btAbkYe/p+QTiNVoPWXadZBgN6PyAPZLB7UohDlEdqWFBESuQ71EBIhB9+VEBNnP H1aQvuFf8rHHRJz3DzvhWUE41lmS4qtLpscsJiUGzQDuhm4MvvOcn1aTsRSnMLQ+zGdpVY JubEbjsuCbIEaHVbFyoJikKnYgaTs5o= X-Rspam-User: Authentication-Results: imf23.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=JsP6kXz7; spf=pass (imf23.hostedemail.com: domain of dan.j.williams@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 07C3E140029 X-Stat-Signature: 8n1xdyy83u7n5r63x46qk96bka34hojy X-HE-Tag: 1665791869-194770 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: In preparation for teaching dax_insert_entry() to take live @pgmap references, enable it to return errors. Given the observation that all callers overwrite the passed in entry with the return value, just update @entry in place and convert the return code to a vm_fault_t status. Cc: Matthew Wilcox Cc: Jan Kara Cc: "Darrick J. Wong" Cc: Jason Gunthorpe Cc: Christoph Hellwig Cc: John Hubbard Signed-off-by: Dan Williams --- fs/dax.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 6990a6e7df9f..1f6c1abfe0c9 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -907,14 +907,15 @@ static bool dax_fault_is_cow(const struct iomap_iter *iter) * already in the tree, we will skip the insertion and just dirty the PMD as * appropriate. */ -static void *dax_insert_entry(struct xa_state *xas, struct vm_fault *vmf, - const struct iomap_iter *iter, void *entry, pfn_t pfn, - unsigned long flags) +static vm_fault_t dax_insert_entry(struct xa_state *xas, struct vm_fault *vmf, + const struct iomap_iter *iter, void **pentry, + pfn_t pfn, unsigned long flags) { struct address_space *mapping = vmf->vma->vm_file->f_mapping; void *new_entry = dax_make_entry(pfn, flags); bool dirty = !dax_fault_is_synchronous(iter, vmf->vma); bool cow = dax_fault_is_cow(iter); + void *entry = *pentry; if (dirty) __mark_inode_dirty(mapping->host, I_DIRTY_PAGES); @@ -960,7 +961,9 @@ static void *dax_insert_entry(struct xa_state *xas, struct vm_fault *vmf, xas_set_mark(xas, PAGECACHE_TAG_TOWRITE); xas_unlock_irq(xas); - return entry; + + *pentry = entry; + return 0; } static int dax_writeback_one(struct xa_state *xas, struct dax_device *dax_dev, @@ -1206,9 +1209,12 @@ static vm_fault_t dax_load_hole(struct xa_state *xas, struct vm_fault *vmf, pfn_t pfn = pfn_to_pfn_t(my_zero_pfn(vaddr)); vm_fault_t ret; - *entry = dax_insert_entry(xas, vmf, iter, *entry, pfn, DAX_ZERO_PAGE); + ret = dax_insert_entry(xas, vmf, iter, entry, pfn, DAX_ZERO_PAGE); + if (ret) + goto out; ret = vmf_insert_mixed(vmf->vma, vaddr, pfn); +out: trace_dax_load_hole(inode, vmf, ret); return ret; } @@ -1225,6 +1231,7 @@ static vm_fault_t dax_pmd_load_hole(struct xa_state *xas, struct vm_fault *vmf, struct page *zero_page; spinlock_t *ptl; pmd_t pmd_entry; + vm_fault_t ret; pfn_t pfn; zero_page = mm_get_huge_zero_page(vmf->vma->vm_mm); @@ -1233,8 +1240,10 @@ static vm_fault_t dax_pmd_load_hole(struct xa_state *xas, struct vm_fault *vmf, goto fallback; pfn = page_to_pfn_t(zero_page); - *entry = dax_insert_entry(xas, vmf, iter, *entry, pfn, - DAX_PMD | DAX_ZERO_PAGE); + ret = dax_insert_entry(xas, vmf, iter, entry, pfn, + DAX_PMD | DAX_ZERO_PAGE); + if (ret) + return ret; if (arch_needs_pgtable_deposit()) { pgtable = pte_alloc_one(vma->vm_mm); @@ -1587,6 +1596,7 @@ static vm_fault_t dax_fault_iter(struct vm_fault *vmf, bool write = iter->flags & IOMAP_WRITE; unsigned long entry_flags = pmd ? DAX_PMD : 0; int err = 0, id; + vm_fault_t ret; pfn_t pfn; void *kaddr; @@ -1613,8 +1623,10 @@ static vm_fault_t dax_fault_iter(struct vm_fault *vmf, return pmd ? VM_FAULT_FALLBACK : dax_fault_return(err); } - *entry = dax_insert_entry(xas, vmf, iter, *entry, pfn, entry_flags); + ret = dax_insert_entry(xas, vmf, iter, entry, pfn, entry_flags); dax_read_unlock(id); + if (ret) + return ret; if (write && srcmap->type != IOMAP_HOLE && srcmap->addr != iomap->addr) {