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.5 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,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 ECFF8C433E1 for ; Fri, 29 May 2020 02:58:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AEA612075F for ; Fri, 29 May 2020 02:58:39 +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="azO5bv91" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AEA612075F 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 9921B800C0; Thu, 28 May 2020 22:58:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4AF9B800C2; Thu, 28 May 2020 22:58:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9686800BF; Thu, 28 May 2020 22:58:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0233.hostedemail.com [216.40.44.233]) by kanga.kvack.org (Postfix) with ESMTP id BAFFA800BC for ; Thu, 28 May 2020 22:58:28 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6DFA5824556B for ; Fri, 29 May 2020 02:58:28 +0000 (UTC) X-FDA: 76868248296.26.mom25_fba99fe98b63 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 4C1141804B660 for ; Fri, 29 May 2020 02:58:28 +0000 (UTC) X-HE-Tag: mom25_fba99fe98b63 X-Filterd-Recvd-Size: 3166 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Fri, 29 May 2020 02:58:27 +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=+Gdlnc0udokkhmpgTuYwy/cxPMcGzAo5nlIsHs4S828=; b=azO5bv91BlL2PSAaefYCm2mmLr X/mOTyr1rHNC+2UV0xAy2gLqAN2y63TkhOjjSEijow/WP+r8CHKYZABY3rv1CtXJ7xFQDqpXI0rGk YzMx/U357PPIEgCk8q5pNJU6dH5RSYjfPKVIGk2sRQvLx61LMHjxDvCcuIYb+WLBXzNGAN/esgkIC 57latdAMVIrO8pgSYfthHiq1TcUI7i0exv3KcjbkmH3hcAS2aCg2W3MpTC41t0mIaQIkNUEpU7Ulv yeWWeiBb5kf3RyALUA62kgdJPMSGfRxucinKMI6eT4uLylIzFSECEdbClkdNrR4PLcgKDWz+RcQva LR74BoAg==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jeVE2-0008Qc-Ux; Fri, 29 May 2020 02:58:26 +0000 From: Matthew Wilcox To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 10/39] fs: Make page_mkwrite_check_truncate thp-aware Date: Thu, 28 May 2020 19:57:55 -0700 Message-Id: <20200529025824.32296-11-willy@infradead.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200529025824.32296-1-willy@infradead.org> References: <20200529025824.32296-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4C1141804B660 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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 last index in the page and return the appropriate size. Change the return type to ssize_t in case we ever support pages larger than 2GB. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/pagemap.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 53a914105591..612f6f090d0f 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -828,22 +828,22 @@ static inline unsigned long dir_pages(struct inode = *inode) * @page: the page to check * @inode: the inode to check the page against * - * Returns the number of bytes in the page up to EOF, + * Return: The number of bytes in the page up to EOF, * or -EFAULT if the page was truncated. */ -static inline int page_mkwrite_check_truncate(struct page *page, +static inline ssize_t page_mkwrite_check_truncate(struct 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); + unsigned long offset =3D offset_in_thp(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 + hpage_nr_pages(page) - 1 < index) + return thp_size(page); /* page is wholly past EOF */ if (page->index > index || !offset) return -EFAULT; --=20 2.26.2