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=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,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 A931EC2BA83 for ; Wed, 12 Feb 2020 04:19:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6E2022082F for ; Wed, 12 Feb 2020 04:19:42 +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="r8IAdQpE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E2022082F 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 9EDD26B03AF; Tue, 11 Feb 2020 23:18:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 92DB46B03B4; Tue, 11 Feb 2020 23:18:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5ACED6B03B0; Tue, 11 Feb 2020 23:18:53 -0500 (EST) 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 3A7D66B03B0 for ; Tue, 11 Feb 2020 23:18:53 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id DD690180AD804 for ; Wed, 12 Feb 2020 04:18:52 +0000 (UTC) X-FDA: 76480169304.24.smash60_134a81fe7c058 X-HE-Tag: smash60_134a81fe7c058 X-Filterd-Recvd-Size: 2899 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Wed, 12 Feb 2020 04:18:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=5Ar0Jeyv020FR8vajw8QCoSu+6yNwintSCRCindI1ZQ=; b=r8IAdQpEyytTz+UkRifmhnp5oX tug+Zi6+43HDkgNWNMhAa6OxOVd1gvh5gww7IiRtJBPzgMbvLgd4eyZtWFBYBKhBWDBKmzf9sKi6t 2I9goiE3TQteNTlAxrA50cRHD4Dyj1NxT6zZxIc3j4q1cn4+JYscrIoBIFKc5iRshjfoKQLa441Ox xYxbbKWzdqFhZXpx8MbdbSRVRBHohpv2+cBC5IcdVnOeJJGWWpjF4qTtq/+1LJpHlyuqYxHdoA4JL 4a+qp70EIhma0kqSu9bFWN7Vt/okHXBWf9mim6hn+OffxYV+Gb8S/Zv2Vh5S1N+x+hgBjCDvvh+RP nnc2wqAg==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j1jU6-0006na-Ty; Wed, 12 Feb 2020 04:18:46 +0000 From: Matthew Wilcox To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org Subject: [PATCH v2 11/25] fs: Make page_mkwrite_check_truncate thp-aware Date: Tue, 11 Feb 2020 20:18:31 -0800 Message-Id: <20200212041845.25879-12-willy@infradead.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200212041845.25879-1-willy@infradead.org> References: <20200212041845.25879-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: From: "Matthew Wilcox (Oracle)" If the page is compound, check the appropriate indices and return the appropriate sizes. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/pagemap.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index aa925295347c..2ec33aabdbf6 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -732,17 +732,18 @@ static inline int page_mkwrite_check_truncate(struc= t page *page, struct inode *inode) { loff_t size =3D i_size_read(inode); - pgoff_t index =3D size >> PAGE_SHIFT; - int offset =3D offset_in_page(size); + pgoff_t first_index =3D size >> PAGE_SHIFT; + pgoff_t last_index =3D first_index + hpage_nr_pages(page) - 1; + unsigned long offset =3D offset_in_this_page(page, size); =20 if (page->mapping !=3D inode->i_mapping) return -EFAULT; =20 /* page is wholly inside EOF */ - if (page->index < index) - return PAGE_SIZE; + if (page->index < first_index) + return thp_size(page); /* page is wholly past EOF */ - if (page->index > index || !offset) + if (page->index > last_index || !offset) return -EFAULT; /* page is partially inside EOF */ return offset; --=20 2.25.0