Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp628120ybz; Wed, 29 Apr 2020 06:39:03 -0700 (PDT) X-Google-Smtp-Source: APiQypK3ypjW3R4c3srroIbhC2XMr7AAva9ErxDzSnSLaWnM8itda39cU0eVGICIWBBlc6NpZkKH X-Received: by 2002:a17:907:9c4:: with SMTP id bx4mr2538922ejc.199.1588167542611; Wed, 29 Apr 2020 06:39:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588167542; cv=none; d=google.com; s=arc-20160816; b=RgcpBZ8dAmpbtua28queqyW2XNWllBiPzJ0uYQ24ze/ntddoXs7isy56m3PuFj9TDV wXGj4lt6e70TFcHOcGsKufuixyYVXktvYJqt9t8U93YFKn+tt8yXQXhCjRwmzAuELc1h xbzVrXRiaPgBUFPfQJZuCtSCcPL+eXz4T9yQq5mfXg6t1JsWorKQ2tJulRUk/CiLJMTy bx0VnItlZATfeyPBgArQdZCePHIddqU56mebhhGs5uDQNiVQctPEYlAfJQohJTcTY4x3 X2FvvgeY0bIk1e+IeCK8WdXhrSnahTRFavEfTMTavIEUD991VoBc8LFpBvtUdg8ACWJV l3DA== 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=ge1BoUMX82GI5q3SrfLgWmdAjO6g3bBg6ygIR4JPjIs=; b=iS/jT0scjrC3GffbwHoZta1gZaJUHKaeFt6XqsVtHzUvoCj6AjhKkmZsiY0OA6bJku qyWYukjXW4bU2s34yayxOKqP2qtolXWb13DbrYjPUJyuUf+cXYuYxqcCzqKXLs+gcHyV i2IQKvuHkOMpz2C+TT3qnkgGqt+udaY/vCS6giAuigZUcXXiz1knPTrb4tUn6a1t1+qm Gw0y2j3+7Y/JmNamdkeX7UrO5n0IuM2yQZq7gwUtGnuw5112AGcJcK4fdH5NJmW2oOMb bTpVKgyEko8S5b5r0Y/6zYvjEf7NmywigY1ANxcGHRW9mhFAa1+BDvgfrVTLZtrZ6+TX N6rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=tFly8VTh; 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 c17si3580075edt.167.2020.04.29.06.38.39; Wed, 29 Apr 2020 06:39:02 -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=tFly8VTh; 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 S1726776AbgD2NhI (ORCPT + 99 others); Wed, 29 Apr 2020 09:37:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726884AbgD2NhA (ORCPT ); Wed, 29 Apr 2020 09:37:00 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74206C08ED7D; Wed, 29 Apr 2020 06:36:59 -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=ge1BoUMX82GI5q3SrfLgWmdAjO6g3bBg6ygIR4JPjIs=; b=tFly8VThEPFCjuFXAD1Ux1ym7B KHUPeFptHgJ/BcrDM1bhUVEAhZ5fN14j0UoowdHZEbzX+PtKtZAIQaZFH42BZVZUtldo9CRd1owhw JGHbg8x/kElPHCmvdVvk0VY9HolDw7dANtB6lJZzSHdWt5hrcKkCgpVbPmW8kV/Vtg+WEI8I5d7Pn mGdTrAyFIY1RkFAb5APwMLrac8sFpWg33J8fnC9EGBrYHIW9LFT8SNcmvVQS6S8AYW5ReM+m4+s7l ayBH9G4CJtwfbW+DDu9OcU+p7MecvsK+i6ktJhH/M5owq1bspgebK3DFIOPXPcD94KIN0E0JT3r4F +gFJR3BQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jTmtX-0005us-AU; Wed, 29 Apr 2020 13:36:59 +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 v3 07/25] fs: Make page_mkwrite_check_truncate thp-aware Date: Wed, 29 Apr 2020 06:36:39 -0700 Message-Id: <20200429133657.22632-8-willy@infradead.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200429133657.22632-1-willy@infradead.org> References: <20200429133657.22632-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 ba16f7bf676b..55199cb5bd66 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -793,22 +793,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 + hpage_nr_pages(page) - 1 < index) + return thp_size(page); /* page is wholly past EOF */ if (page->index > index || !offset) return -EFAULT; -- 2.26.2