Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp777166ybg; Wed, 10 Jun 2020 13:28:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBJI9DOtwb9jvORgKrJx7z+oOtWRAeatJTNgSdu1pu5Y63KPHY1gbHeancUbj/1IZ/rSh3 X-Received: by 2002:a50:ee01:: with SMTP id g1mr3940243eds.44.1591820889659; Wed, 10 Jun 2020 13:28:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591820889; cv=none; d=google.com; s=arc-20160816; b=dKzEi+BKTtVpv1Ss6i65ITaNntaNrY057/M7G76ooGFt7dxUbLks0acPFyTs4OEraH zyUs54coOCI/ePjFNlfiGYXfQ2Pe88o/IR5QAvGCSKKZlL/0ibxpRIFR7J2fIc1y+MKG B4Yw00TXhdo8mGh6cioNyQWuplZf+xvvbKT+MoomtAvds6CcbPSOjfqkpiYM2a3oP1TV w4SkBbpO/5aIaZ1bRKzel7TQwa1xarPOVMLT9nDr1R/EOOo2p40cCa0tXc2eqrnPcbfF g6vJ8m/NB73Ft/+kHJOiJpAQiuF+cBXjBL9sQCWI43fukzcRTahAolcAHL9PHCf/j9Zb mKIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4figGncYPDs23Of7IYih6m6FXzxa/L1ppRPiwe0GXZ0=; b=IoOPRrgyQPLf/qO0sKq+yDygdnZ+bZuKlItGBh02jdZwFbNIqJfoKvZMSxoX7F2u3p II/MHRUnvUTQ3TF1CtsExWo3Qsty2v3mFci5+8AWwdjcHBJmP7QqFT1gldKENhc/Ghon Oj9z8HgDhElKg993HHsS8vZp/79+nXP/Zyi7bJN8EClVZTnUj2rFNWw/qiQmpALFer41 /7ybY9zsJxYNbbuy3P9rbtcCl14GcTcPcba8c8uYypPxRNCFztR/Gv9dRRrB/Lp4WGGi RH+Yw/CnD5RFJ6h9rUn76LCIp1/SapvHeYudePBJNqR9nCa3H8zMejP0kvY3RB1De99U abyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=PJFR2z3i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lh18si643025ejb.487.2020.06.10.13.27.46; Wed, 10 Jun 2020 13:28:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=PJFR2z3i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730940AbgFJURQ (ORCPT + 99 others); Wed, 10 Jun 2020 16:17:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730534AbgFJUNt (ORCPT ); Wed, 10 Jun 2020 16:13:49 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AB75C08C5CA; Wed, 10 Jun 2020 13:13:48 -0700 (PDT) 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=4figGncYPDs23Of7IYih6m6FXzxa/L1ppRPiwe0GXZ0=; b=PJFR2z3iqH2Nw5qEV5yTriVnR4 HHwB6hGy6N6yjAOR3migbMhFuAjDYBO6zIYCw/fNrcXicSxzoCBkGdnPHKmUgvpT3T7TDaLRyvaav JGyWQdEtV3qbBb8Akw6Oicgk1HRqEMSDKJxUuBiCo2XzUryuxUSF9ai14FYO7HMb5E4/Zviwb/xGA S7OwUAUqIjL/lz0EN8hcdX7VP/Url6U4TE9XF7AVlkVigU2+dimH6OoHYtq/2FFpNUe1FupIPkIOg 2atAbD5fBVz0PhB1Bm/qWf0zS8QyDPlrlJg1vM2oxmuuHtC7d1wQRZUWYh/wEa8J9je9BFvpqk0R4 ceJa2iyQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jj76Z-0003Ue-TO; Wed, 10 Jun 2020 20:13:47 +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 v6 17/51] fs: Make page_mkwrite_check_truncate thp-aware Date: Wed, 10 Jun 2020 13:13:11 -0700 Message-Id: <20200610201345.13273-18-willy@infradead.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200610201345.13273-1-willy@infradead.org> References: <20200610201345.13273-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 3ad0c92be649..f47ba9f18f3e 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -868,22 +868,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 = i_size_read(inode); pgoff_t index = size >> PAGE_SHIFT; - int offset = offset_in_page(size); + unsigned long offset = offset_in_thp(page, size); if (page->mapping != inode->i_mapping) return -EFAULT; /* page is wholly inside EOF */ - if (page->index < index) - return PAGE_SIZE; + if (page->index + thp_nr_pages(page) - 1 < index) + return thp_size(page); /* page is wholly past EOF */ if (page->index > index || !offset) return -EFAULT; -- 2.26.2