From patchwork Fri Oct 14 23:57:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 13007520 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 6C2ADC433FE for ; Fri, 14 Oct 2022 23:57:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3A796B007E; Fri, 14 Oct 2022 19:57:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE8276B0080; Fri, 14 Oct 2022 19:57:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B0D76B0081; Fri, 14 Oct 2022 19:57:34 -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 89BA36B007E for ; Fri, 14 Oct 2022 19:57:34 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 63E5980A02 for ; Fri, 14 Oct 2022 23:57:34 +0000 (UTC) X-FDA: 80021219628.19.64A0EBA Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by imf22.hostedemail.com (Postfix) with ESMTP id B2ECAC0028 for ; Fri, 14 Oct 2022 23:57:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1665791853; x=1697327853; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WDhrLpyapWWVzBNALsAavqF2Cp5tBjhlbxEJIcuaLkE=; b=Cm9t/cMo73W42SS1YSVvWK5gw81hGqwWlQnObD8atZzRneo5ZIjY/5A/ HhkJJnUFCISK+qqzeMsXc6e8teiXsgWw+hTztnPIA5wBUqnH6jjFzyE6D DnEOuvXlRTC1x1XIdaAk69cmo8N4pgqj2puJcRTmsqXvccxLTdRTWm1aL 0RFMETqJ359t3nST+2oOBtSIYxNxeaBRLgBO1xMaa7e0c1iJzYlet6mdg 5BWxYERn6JEUqf95Wpdsl2SyAcvgePV997tKOZac3jBOYy3yY1o1ug9y4 LwmLVUK2nITe/X67n3Xn0D7x0/igrsoDLvBfSINLq9cpmBQp0xTrWbt7E g==; X-IronPort-AV: E=McAfee;i="6500,9779,10500"; a="367523084" X-IronPort-AV: E=Sophos;i="5.95,185,1661842800"; d="scan'208";a="367523084" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2022 16:57:32 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10500"; a="630113254" X-IronPort-AV: E=Sophos;i="5.95,185,1661842800"; d="scan'208";a="630113254" 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:31 -0700 Subject: [PATCH v3 06/25] fsdax: Validate DAX layouts broken before truncate From: Dan Williams To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , "Darrick J. Wong" , Jason Gunthorpe , Christoph Hellwig , John Hubbard , Dave Chinner , nvdimm@lists.linux.dev, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org Date: Fri, 14 Oct 2022 16:57:31 -0700 Message-ID: <166579185112.2236710.17571345510304035858.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; imf22.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b="Cm9t/cMo"; spf=pass (imf22.hostedemail.com: domain of dan.j.williams@intel.com designates 134.134.136.31 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=1665791853; a=rsa-sha256; cv=none; b=yCFHFpSkRBRK4RUr9/cFzrFI2MVI5CoXVAHaBfeJm3nM29G8ZLko21PUHSeAPXJy8JVpRo pD2/Xme2j6DiTgDJ8IyXjeoCtwvqPBOIZ1Gi2mfgnU+1mRNifCVVrJ+MvzCxMsD3hDmzf4 eMKcfEnIivo2L0Nn4gCZps1ExzYeHOY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665791853; 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=OI4yd8tcXdPjF9n/Dll0IIgldncIeYstMvGae4rxZBE=; b=NeB1Jd6q/rvo4HFYZSpThiHpRZaTFU7azQwsqbFm+fyYE+eOE9NbK5LPAxsS+RhlEIUYZH PO2+vkmsBu+UmSQ3RJ27vwPT7QR/MSFouA2rffjIVB1hZP9vdCjkQQmWYG9NCorUVbF77/ qY9yP/eoUARx4Mu9aRjPuwfaO3HLmnQ= X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b="Cm9t/cMo"; spf=pass (imf22.hostedemail.com: domain of dan.j.williams@intel.com designates 134.134.136.31 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: B2ECAC0028 X-Stat-Signature: 8se8e7s4xuowmq5a9itq37j5z46fmxat X-HE-Tag: 1665791853-739643 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: Now that iput_final() arranges for dax_break_layouts(), all truncate_inode_pages() paths in the kernel ensure that no DAX pages hosted by that inode are in use. Add warnings to assert the new entry state transitions. Cc: Matthew Wilcox Cc: Jan Kara Cc: "Darrick J. Wong" Cc: Jason Gunthorpe Cc: Christoph Hellwig Cc: John Hubbard Cc: Dave Chinner Signed-off-by: Dan Williams --- fs/dax.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index e3deb60a792f..1d4f0072e58d 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -401,13 +401,15 @@ 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 && !dax_page_idle(page)); if (dax_mapping_is_cow(page->mapping)) { /* keep the CoW flag if this page is still shared */ if (page->index-- > 0) continue; - } else + } else { + WARN_ON_ONCE(trunc && !dax_is_zapped(entry)); + WARN_ON_ONCE(trunc && !dax_page_idle(page)); WARN_ON_ONCE(page->mapping && page->mapping != mapping); + } page->mapping = NULL; page->index = 0; }