From patchwork Fri Oct 14 23:57:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 13007521 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 30AF7C4332F for ; Fri, 14 Oct 2022 23:57:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B86D26B0080; Fri, 14 Oct 2022 19:57:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B369A6B0081; Fri, 14 Oct 2022 19:57:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FEAC6B0082; Fri, 14 Oct 2022 19:57:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8D9FA6B0080 for ; Fri, 14 Oct 2022 19:57:40 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6495B803B9 for ; Fri, 14 Oct 2022 23:57:40 +0000 (UTC) X-FDA: 80021219880.22.A340D4A Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by imf02.hostedemail.com (Postfix) with ESMTP id C470C8002D for ; Fri, 14 Oct 2022 23:57:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665791859; x=1697327859; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yd85VDxCtKyxeZdpNqoca3KmUlvyPqntXffUSxCk3NA=; b=IiE/RKn2TvEvzZmubF4U0Xcy3p6qVCAKd7hk1/Wej+Pl8u8D11NiuFPw byNzIeGbNY1cTqsHKw3ynMp0sOHpZ1fHCJGLP6si0vgC103C20Ph1COdN nJ9l93ew9uAaQWf+uRumCDliJfvBochMwN5aadsG9Se6lwwJ5Xzw9ba0q jdLPkWEwabkFTw25bIvZboRYaqSrvp1qUFp+/5icCcteq2trJPXeDLjCB nFD7AHyLnNE5bNBu2J0403r6OCU+x6oFpsa7TX3wtVwda48WdQHo4Zejp GXE6cJMNoO+VsHM64Rrl83vEaPSwA5LfF2nJBQYoxBQjA70a0UT1uxKNe g==; X-IronPort-AV: E=McAfee;i="6500,9779,10500"; a="307154575" X-IronPort-AV: E=Sophos;i="5.95,185,1661842800"; d="scan'208";a="307154575" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2022 16:57:38 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10500"; a="630113270" X-IronPort-AV: E=Sophos;i="5.95,185,1661842800"; d="scan'208";a="630113270" 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:37 -0700 Subject: [PATCH v3 07/25] fsdax: Hold dax lock over mapping insertion 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:37 -0700 Message-ID: <166579185727.2236710.8711235794537270051.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665791860; a=rsa-sha256; cv=none; b=ikCRy7dyyHQ6UAHxJhzEk5tkI0f+btQr/8dM0mIqtKyuZ0YqTjcK8CksZGJ38xq6G00zoS vTV+lvWpOtU8pWFuqzHa2Jnn46W9FbMVa24L5JpRm8M6v0QKct60Y32YddxdwJW6wPS1j0 H67zFQINH5DzJbbZWRh/Ais3OHJRAF0= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b="IiE/RKn2"; spf=pass (imf02.hostedemail.com: domain of dan.j.williams@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=dan.j.williams@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=1665791860; 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=qzlqEJ1ug+gcINugjdFLGS/BbcQqCegyPErlCHAUL18=; b=2pYBY5rFHnyp6adnM9Kx4i0iQc4vobgd7zjYHYAVp1p5fnhpFsT7ABPcfweV8KEguoxe7c eRXf476fGk77XRNJsTiRf1ewZ5DTL7Atn4Es/aCI0rlNniSDXzdWcW1ZdkHWBIO99ZI/EU 6sklu9gTK7X2hVVL6+HPgMqsK1Oy9BA= X-Stat-Signature: t3i6hmganhew53nxgbzqb9bowk6nkmm9 X-Rspamd-Queue-Id: C470C8002D X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b="IiE/RKn2"; spf=pass (imf02.hostedemail.com: domain of dan.j.williams@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspamd-Server: rspam06 X-HE-Tag: 1665791859-544652 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 dax_insert_entry() to start taking page and pgmap references ensure that page->pgmap is valid by holding the dax_read_lock() over both dax_direct_access() and dax_insert_entry(). I.e. the code that wants to elevate the reference count of a pgmap page from 0 -> 1 must ensure that the pgmap is not exiting and will not start exiting until the proper references have been taken. 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 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 1d4f0072e58d..6990a6e7df9f 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -1107,10 +1107,9 @@ static int dax_iomap_direct_access(const struct iomap *iomap, loff_t pos, size_t size, void **kaddr, pfn_t *pfnp) { pgoff_t pgoff = dax_iomap_pgoff(iomap, pos); - int id, rc = 0; long length; + int rc = 0; - id = dax_read_lock(); length = dax_direct_access(iomap->dax_dev, pgoff, PHYS_PFN(size), DAX_ACCESS, kaddr, pfnp); if (length < 0) { @@ -1135,7 +1134,6 @@ static int dax_iomap_direct_access(const struct iomap *iomap, loff_t pos, if (!*kaddr) rc = -EFAULT; out: - dax_read_unlock(id); return rc; } @@ -1588,7 +1586,7 @@ static vm_fault_t dax_fault_iter(struct vm_fault *vmf, loff_t pos = (loff_t)xas->xa_index << PAGE_SHIFT; bool write = iter->flags & IOMAP_WRITE; unsigned long entry_flags = pmd ? DAX_PMD : 0; - int err = 0; + int err = 0, id; pfn_t pfn; void *kaddr; @@ -1608,11 +1606,15 @@ static vm_fault_t dax_fault_iter(struct vm_fault *vmf, return pmd ? VM_FAULT_FALLBACK : VM_FAULT_SIGBUS; } + id = dax_read_lock(); err = dax_iomap_direct_access(iomap, pos, size, &kaddr, &pfn); - if (err) + if (err) { + dax_read_unlock(id); return pmd ? VM_FAULT_FALLBACK : dax_fault_return(err); + } *entry = dax_insert_entry(xas, vmf, iter, *entry, pfn, entry_flags); + dax_read_unlock(id); if (write && srcmap->type != IOMAP_HOLE && srcmap->addr != iomap->addr) {