From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FDACC433E7 for ; Wed, 14 Oct 2020 03:04:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9FCA721D81 for ; Wed, 14 Oct 2020 03:04:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="h2D+PCR8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9FCA721D81 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A707B940007; Tue, 13 Oct 2020 23:04:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7692B6B006E; Tue, 13 Oct 2020 23:04:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28B6F940007; Tue, 13 Oct 2020 23:04:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0034.hostedemail.com [216.40.44.34]) by kanga.kvack.org (Postfix) with ESMTP id C1FE06B0071 for ; Tue, 13 Oct 2020 23:04:03 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 57872180AD807 for ; Wed, 14 Oct 2020 03:04:03 +0000 (UTC) X-FDA: 77369036766.21.club87_42108de27208 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 34D1F180442C2 for ; Wed, 14 Oct 2020 03:04:03 +0000 (UTC) X-HE-Tag: club87_42108de27208 X-Filterd-Recvd-Size: 3352 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Wed, 14 Oct 2020 03:04:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=j56S9O9WrvJwFfp3jWhAG41igcUKnP5ChYtNlOLmqVw=; b=h2D+PCR8Gha6OcbuOB2GBMzhS0 gRUjdmkK723DckDKVFPqjMcduPz3oe6xBGPe5GSehH75/txbO92mgjSmEse+8HPoa2Yq379BRn+hZ pTGxv+R0ZsvJe6iqLMcrvzPfj30EaZi7NAk9yJqHDDHsJW2C1HFyOFN5z4lXPAdxU+et8/LLMvC6b /Mcy8Ya+xrko0fZggbRRzFLko98VDFJ5rvW3WBoyCPnCBSLvGbxKNWi6UOaopBgHMIYUCwZPjFE/E OTp/mwMIFyH6YptVXd+l1UgFZZeH/fgsHWihD/tk74FyBPkxdDeHXUbstUHmpZ28aisEklqjgGMLy 4oG3MciA==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kSX55-0005i3-Ff; Wed, 14 Oct 2020 03:03:59 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH 01/14] fs: Support THPs in vfs_dedupe_file_range Date: Wed, 14 Oct 2020 04:03:44 +0100 Message-Id: <20201014030357.21898-2-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201014030357.21898-1-willy@infradead.org> References: <20201014030357.21898-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: We may get tail pages returned from vfs_dedupe_get_page(). If we do, we have to call page_mapping() instead of dereferencing page->mapping directly. We may also deadlock trying to lock the page twice if they're subpages of the same THP, so compare the head pages instead. Signed-off-by: Matthew Wilcox (Oracle) --- fs/read_write.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 19f5c4bf75aa..ead675fef582 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1604,6 +1604,8 @@ static struct page *vfs_dedupe_get_page(struct inod= e *inode, loff_t offset) */ static void vfs_lock_two_pages(struct page *page1, struct page *page2) { + page1 =3D thp_head(page1); + page2 =3D thp_head(page2); /* Always lock in order of increasing index. */ if (page1->index > page2->index) swap(page1, page2); @@ -1616,6 +1618,8 @@ static void vfs_lock_two_pages(struct page *page1, = struct page *page2) /* Unlock two pages, being careful not to unlock the same page twice. */ static void vfs_unlock_two_pages(struct page *page1, struct page *page2) { + page1 =3D thp_head(page1); + page2 =3D thp_head(page2); unlock_page(page1); if (page1 !=3D page2) unlock_page(page2); @@ -1670,8 +1674,8 @@ static int vfs_dedupe_file_range_compare(struct ino= de *src, loff_t srcoff, * someone is invalidating pages on us and we lose. */ if (!PageUptodate(src_page) || !PageUptodate(dest_page) || - src_page->mapping !=3D src->i_mapping || - dest_page->mapping !=3D dest->i_mapping) { + page_mapping(src_page) !=3D src->i_mapping || + page_mapping(dest_page) !=3D dest->i_mapping) { same =3D false; goto unlock; } --=20 2.28.0