From patchwork Thu Feb 13 20:24:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 11381263 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E20BA17F0 for ; Thu, 13 Feb 2020 20:24:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C125724689 for ; Thu, 13 Feb 2020 20:24:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Op4XKO8f" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728380AbgBMUYi (ORCPT ); Thu, 13 Feb 2020 15:24:38 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:26032 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727926AbgBMUYh (ORCPT ); Thu, 13 Feb 2020 15:24:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581625476; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a4MJkD5t2+MNe06mPL9vuWnH2ew7+ptqnyRGGIuyzxY=; b=Op4XKO8f4eMFRgXTDpwEQzTQjzS46N7AMrn44N2V7Hp6VbilZwCzNdItuAJiGU1zLhDIi1 OybFBWCQrwJ6IJosl5pMrht7yH4wYtmzKeCqaHcjYk3SyA8jQzDt1vSvvbze3gvxQrpnGN iSmoIfneP6Y+7LP2PjyTWoVK8jberKY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-162-jbiV0VMONpC_oj62Ox8ycw-1; Thu, 13 Feb 2020 15:24:32 -0500 X-MC-Unique: jbiV0VMONpC_oj62Ox8ycw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1438513FC; Thu, 13 Feb 2020 20:24:31 +0000 (UTC) Received: from max.home.com (ovpn-204-60.brq.redhat.com [10.40.204.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id D40891001B0B; Thu, 13 Feb 2020 20:24:28 +0000 (UTC) From: Andreas Gruenbacher To: Alexander Viro , David Sterba , Jeff Layton , "Theodore Ts'o" , Chao Yu , Richard Weinberger Cc: linux-fsdevel@vger.kernel.org, Andreas Gruenbacher , Jan Kara Subject: [PATCH 1/7] fs: Un-inline page_mkwrite_check_truncate Date: Thu, 13 Feb 2020 21:24:17 +0100 Message-Id: <20200213202423.23455-2-agruenba@redhat.com> In-Reply-To: <20200213202423.23455-1-agruenba@redhat.com> References: <20200213202423.23455-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Per review comments from Jan and Ted, un-inline page_mkwrite_check_truncate and move it to mm/filemap.c. This function doesn't seem worth inlining. Signed-off-by: Andreas Gruenbacher Cc: Jan Kara Cc: Theodore Y. Ts'o Reviewed-by: Jan Kara --- include/linux/pagemap.h | 28 +--------------------------- mm/filemap.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index ccb14b6a16b5..6c9c5b88924d 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -636,32 +636,6 @@ static inline unsigned long dir_pages(struct inode *inode) PAGE_SHIFT; } -/** - * page_mkwrite_check_truncate - check if page was truncated - * @page: the page to check - * @inode: the inode to check the page against - * - * Returns 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, - struct inode *inode) -{ - loff_t size = i_size_read(inode); - pgoff_t index = size >> PAGE_SHIFT; - int offset = offset_in_page(size); - - if (page->mapping != inode->i_mapping) - return -EFAULT; - - /* page is wholly inside EOF */ - if (page->index < index) - return PAGE_SIZE; - /* page is wholly past EOF */ - if (page->index > index || !offset) - return -EFAULT; - /* page is partially inside EOF */ - return offset; -} +int page_mkwrite_check_truncate(struct page *page, struct inode *inode); #endif /* _LINUX_PAGEMAP_H */ diff --git a/mm/filemap.c b/mm/filemap.c index 1784478270e1..edcb4a8a6121 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2678,6 +2678,34 @@ const struct vm_operations_struct generic_file_vm_ops = { .page_mkwrite = filemap_page_mkwrite, }; +/** + * page_mkwrite_check_truncate - check if page was truncated + * @page: the page to check + * @inode: the inode to check the page against + * + * Returns the number of bytes in the page up to EOF, + * or -EFAULT if the page was truncated. + */ +int 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); + + if (page->mapping != inode->i_mapping) + return -EFAULT; + + /* page is wholly inside EOF */ + if (page->index < index) + return PAGE_SIZE; + /* page is wholly past EOF */ + if (page->index > index || !offset) + return -EFAULT; + /* page is partially inside EOF */ + return offset; +} +EXPORT_SYMBOL(page_mkwrite_check_truncate); + /* This is used for a general mmap of a disk file */ int generic_file_mmap(struct file * file, struct vm_area_struct * vma) From patchwork Thu Feb 13 20:24:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 11381261 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 75A6F139A for ; Thu, 13 Feb 2020 20:24:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 54DE224680 for ; Thu, 13 Feb 2020 20:24:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RfmlOiBM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728378AbgBMUYh (ORCPT ); Thu, 13 Feb 2020 15:24:37 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:38151 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727609AbgBMUYh (ORCPT ); Thu, 13 Feb 2020 15:24:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581625476; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GnIwQ36PAuYJKj04cVkizzS1/0imgTxxjR+ggRy2CGk=; b=RfmlOiBMIMlR1ulk8APC4lt1hGWEJQmbS7xFmUCI3yHdMfD5wc0iGiTUij7BydaovbZKzF og0QG5FgnFqBIVM3K2ounWmcbyp3hnyEyN0vimbLGtXyzUk1FS1PBkoSGx7wMhda7lEuZ8 K+3U3IwxOCYiBNO77HnY/f2Ahn6BndI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-367-FIkxOjaKMXOlws7gnFuW0w-1; Thu, 13 Feb 2020 15:24:35 -0500 X-MC-Unique: FIkxOjaKMXOlws7gnFuW0w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 72345800EB8; Thu, 13 Feb 2020 20:24:33 +0000 (UTC) Received: from max.home.com (ovpn-204-60.brq.redhat.com [10.40.204.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6FC911001B0B; Thu, 13 Feb 2020 20:24:31 +0000 (UTC) From: Andreas Gruenbacher To: Alexander Viro , David Sterba , Jeff Layton , "Theodore Ts'o" , Chao Yu , Richard Weinberger Cc: linux-fsdevel@vger.kernel.org, Andreas Gruenbacher Subject: [PATCH 2/7] fs: Switch to page_mkwrite_check_truncate in block_page_mkwrite Date: Thu, 13 Feb 2020 21:24:18 +0100 Message-Id: <20200213202423.23455-3-agruenba@redhat.com> In-Reply-To: <20200213202423.23455-1-agruenba@redhat.com> References: <20200213202423.23455-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use the "page has been truncated" logic in page_mkwrite_check_truncate instead of reimplementing it here. Other than with the existing code, fail with -EFAULT / VM_FAULT_NOPAGE when page_offset(page) == size here as well, as should be expected. Signed-off-by: Andreas Gruenbacher --- fs/buffer.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index b8d28370cfd7..31a9a02878a2 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2499,23 +2499,13 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf, struct page *page = vmf->page; struct inode *inode = file_inode(vma->vm_file); unsigned long end; - loff_t size; int ret; lock_page(page); - size = i_size_read(inode); - if ((page->mapping != inode->i_mapping) || - (page_offset(page) > size)) { - /* We overload EFAULT to mean page got truncated */ - ret = -EFAULT; + ret = page_mkwrite_check_truncate(page, inode); + if (ret < 0) goto out_unlock; - } - - /* page is wholly or partially inside EOF */ - if (((page->index + 1) << PAGE_SHIFT) > size) - end = size & ~PAGE_MASK; - else - end = PAGE_SIZE; + end = ret; ret = __block_write_begin(page, 0, end, get_block); if (!ret) From patchwork Thu Feb 13 20:24:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 11381265 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 118A0109A for ; Thu, 13 Feb 2020 20:24:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D713324680 for ; Thu, 13 Feb 2020 20:24:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="J/xg7fxB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728388AbgBMUYk (ORCPT ); Thu, 13 Feb 2020 15:24:40 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:47285 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727926AbgBMUYk (ORCPT ); Thu, 13 Feb 2020 15:24:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581625479; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t3/PicjsaEbx6Lq+NpmHhZDHuMbNepYoytXnxjT+hNw=; b=J/xg7fxBKUDc90eso2vGqGJo5n0PvmEA4AxPTv5xj1+7kyx70JLii3w7GFVFsDxclB1aPT OW9/vBZam0+5+erIAeiTJP1RDukzZykbKfnVTrpkFGMSM+Wx+miTZ3AWBvVCh65viTMZQV RcO5s4stdd0Q0G6m01jwRr3e4gXmssE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-145-8JzXEXabPfuHrPxlqbM6VQ-1; Thu, 13 Feb 2020 15:24:37 -0500 X-MC-Unique: 8JzXEXabPfuHrPxlqbM6VQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C941013E4; Thu, 13 Feb 2020 20:24:35 +0000 (UTC) Received: from max.home.com (ovpn-204-60.brq.redhat.com [10.40.204.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB52B100032E; Thu, 13 Feb 2020 20:24:33 +0000 (UTC) From: Andreas Gruenbacher To: Alexander Viro , David Sterba , Jeff Layton , "Theodore Ts'o" , Chao Yu , Richard Weinberger Cc: linux-fsdevel@vger.kernel.org, Andreas Gruenbacher Subject: [PATCH 3/7] ubifs: Switch to page_mkwrite_check_truncate in ubifs_vm_page_mkwrite Date: Thu, 13 Feb 2020 21:24:19 +0100 Message-Id: <20200213202423.23455-4-agruenba@redhat.com> In-Reply-To: <20200213202423.23455-1-agruenba@redhat.com> References: <20200213202423.23455-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use the "page has been truncated" logic in page_mkwrite_check_truncate instead of reimplementing it here. Other than with the existing code, fail with -EFAULT / VM_FAULT_NOPAGE when page_offset(page) == size here as well, as should be expected. Signed-off-by: Andreas Gruenbacher Acked-by: Richard Weinberger --- fs/ubifs/file.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index 743928efffc1..395ff2081ecb 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c @@ -1559,8 +1559,7 @@ static vm_fault_t ubifs_vm_page_mkwrite(struct vm_fault *vmf) } lock_page(page); - if (unlikely(page->mapping != inode->i_mapping || - page_offset(page) > i_size_read(inode))) { + if (unlikely(page_mkwrite_check_truncate(page, inode) < 0)) { /* Page got truncated out from underneath us */ goto sigbus; } From patchwork Thu Feb 13 20:24:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 11381269 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0CDBB139A for ; Thu, 13 Feb 2020 20:24:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E15C324682 for ; Thu, 13 Feb 2020 20:24:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RI87dwrX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728072AbgBMUYm (ORCPT ); Thu, 13 Feb 2020 15:24:42 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:51509 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727926AbgBMUYm (ORCPT ); Thu, 13 Feb 2020 15:24:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581625481; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Vlxo1nx7BalMfC2VSU4oKmB2UgE3wRf52tiqPzNnaGY=; b=RI87dwrXRJIhpMHOI4UQv3g5tkvQJAryZHDfy1QKS4eS1l7XMNGlrZVJDAivvjPS3Vxpol TsW1JASLhfLDFD6zdE38uw5Sa+zPq9JEQrFV1HIfx06W21WXCzYDR+fjqpO2rsi3/w8P/9 SFH3thaB1ciSZLGxg2yQhc9NegOLIA0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-406-86J8RduONh-1EMQ_820JFA-1; Thu, 13 Feb 2020 15:24:39 -0500 X-MC-Unique: 86J8RduONh-1EMQ_820JFA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2C25F800D50; Thu, 13 Feb 2020 20:24:38 +0000 (UTC) Received: from max.home.com (ovpn-204-60.brq.redhat.com [10.40.204.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E7F11001B0B; Thu, 13 Feb 2020 20:24:35 +0000 (UTC) From: Andreas Gruenbacher To: Alexander Viro , David Sterba , Jeff Layton , "Theodore Ts'o" , Chao Yu , Richard Weinberger Cc: linux-fsdevel@vger.kernel.org, Andreas Gruenbacher Subject: [PATCH 4/7] ext4: Switch to page_mkwrite_check_truncate in ext4_page_mkwrite Date: Thu, 13 Feb 2020 21:24:20 +0100 Message-Id: <20200213202423.23455-5-agruenba@redhat.com> In-Reply-To: <20200213202423.23455-1-agruenba@redhat.com> References: <20200213202423.23455-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use the "page has been truncated" logic in page_mkwrite_check_truncate instead of reimplementing it here. Other than with the existing code, fail with -EFAULT / VM_FAULT_NOPAGE when page_offset(page) == size here as well, as should be expected. Signed-off-by: Andreas Gruenbacher Acked-by: Theodore Ts'o --- fs/ext4/inode.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 1305b810c44a..4e00a6014fb3 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5902,13 +5902,11 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; struct page *page = vmf->page; - loff_t size; unsigned long len; int err; vm_fault_t ret; struct file *file = vma->vm_file; struct inode *inode = file_inode(file); - struct address_space *mapping = inode->i_mapping; handle_t *handle; get_block_t *get_block; int retries = 0; @@ -5938,18 +5936,13 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf) } lock_page(page); - size = i_size_read(inode); - /* Page got truncated from under us? */ - if (page->mapping != mapping || page_offset(page) > size) { + err = page_mkwrite_check_truncate(page, inode); + if (err < 0) { unlock_page(page); - ret = VM_FAULT_NOPAGE; - goto out; + goto out_ret; } + len = err; - if (page->index == size >> PAGE_SHIFT) - len = size & ~PAGE_MASK; - else - len = PAGE_SIZE; /* * Return if we have all the buffers mapped. This avoids the need to do * journal_start/journal_stop which can block and take a long time From patchwork Thu Feb 13 20:24:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 11381271 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 131A4109A for ; Thu, 13 Feb 2020 20:24:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E72CF24685 for ; Thu, 13 Feb 2020 20:24:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HYCDVheK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728105AbgBMUYr (ORCPT ); Thu, 13 Feb 2020 15:24:47 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:34700 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727926AbgBMUYr (ORCPT ); Thu, 13 Feb 2020 15:24:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581625486; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IAY2w5m5A+eioJ5oHT8xTyzWNhcSLI/RhwQbztvcyaU=; b=HYCDVheKxGdL9m5BcY+2+ZRHllBhTknns8i4KMQKL58SiP6zrK6XhjIUry333zfl6yzzgZ TcvvIYsIyjGuDs8T2W7Bsq74a2xCFmeEX9Ip3Baoun6pwcB6PyG81Ai3t3N6lfmuTbYCDx QGhCys3Gjo6W23Kq5Wa9paIwwoND2Fw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-48-WCmtbwjDOI-o6W5Sps6d4g-1; Thu, 13 Feb 2020 15:24:42 -0500 X-MC-Unique: WCmtbwjDOI-o6W5Sps6d4g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D1F36801E6C; Thu, 13 Feb 2020 20:24:40 +0000 (UTC) Received: from max.home.com (ovpn-204-60.brq.redhat.com [10.40.204.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8601510027A4; Thu, 13 Feb 2020 20:24:38 +0000 (UTC) From: Andreas Gruenbacher To: Alexander Viro , David Sterba , Jeff Layton , "Theodore Ts'o" , Chao Yu , Richard Weinberger Cc: linux-fsdevel@vger.kernel.org, Andreas Gruenbacher , Chao Yu Subject: [PATCH 5/7] f2fs: Switch to page_mkwrite_check_truncate in f2fs_vm_page_mkwrite Date: Thu, 13 Feb 2020 21:24:21 +0100 Message-Id: <20200213202423.23455-6-agruenba@redhat.com> In-Reply-To: <20200213202423.23455-1-agruenba@redhat.com> References: <20200213202423.23455-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use the "page has been truncated" logic in page_mkwrite_check_truncate instead of reimplementing it here. Other than with the existing code, fail with -EFAULT / VM_FAULT_NOPAGE when page_offset(page) == size here as well, as should be expected. Signed-off-by: Andreas Gruenbacher Acked-by: Chao Yu --- fs/f2fs/file.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 0d4da644df3b..0d5ac7a92230 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -52,7 +52,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) struct f2fs_sb_info *sbi = F2FS_I_SB(inode); struct dnode_of_data dn; bool need_alloc = true; - int err = 0; + int offset, err = 0; if (unlikely(f2fs_cp_error(sbi))) { err = -EIO; @@ -91,11 +91,12 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) file_update_time(vmf->vma->vm_file); down_read(&F2FS_I(inode)->i_mmap_sem); lock_page(page); - if (unlikely(page->mapping != inode->i_mapping || - page_offset(page) > i_size_read(inode) || - !PageUptodate(page))) { + offset = -EFAULT; + if (likely(PageUptodate(page))) + offset = page_mkwrite_check_truncate(page, inode); + if (unlikely(offset < 0)) { unlock_page(page); - err = -EFAULT; + err = offset; goto out_sem; } @@ -124,14 +125,8 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) if (PageMappedToDisk(page)) goto out_sem; - /* page is wholly or partially inside EOF */ - if (((loff_t)(page->index + 1) << PAGE_SHIFT) > - i_size_read(inode)) { - loff_t offset; - - offset = i_size_read(inode) & ~PAGE_MASK; + if (offset != PAGE_SIZE) zero_user_segment(page, offset, PAGE_SIZE); - } set_page_dirty(page); if (!PageUptodate(page)) SetPageUptodate(page); From patchwork Thu Feb 13 20:24:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 11381273 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 88E6717F0 for ; Thu, 13 Feb 2020 20:24:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5B38224685 for ; Thu, 13 Feb 2020 20:24:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AP3RRSaI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728107AbgBMUYr (ORCPT ); Thu, 13 Feb 2020 15:24:47 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:41007 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727938AbgBMUYr (ORCPT ); Thu, 13 Feb 2020 15:24:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581625486; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6WdwOaFsdBeuYn31kmg4N/dXknKYxiAKpK/9IIYLyZQ=; b=AP3RRSaInbTfUSsiEznCvxbypgdUalomcmk8DiMZxpRgy1x7E+GhKcialaIZ9XP2fQlqyq tIoWjWMwfYdskd/MXgSJ56B9NMDIyfnSeHDoabjcBxHdrwZPR2wRar15jDb1OY+O5BDyFJ tDpZ6nKu9vby15aLkQE2ttTtNmIiRA0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-345-YRPQlKgDMoStszn5XUaf1w-1; Thu, 13 Feb 2020 15:24:44 -0500 X-MC-Unique: YRPQlKgDMoStszn5XUaf1w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 363BF8017CC; Thu, 13 Feb 2020 20:24:43 +0000 (UTC) Received: from max.home.com (ovpn-204-60.brq.redhat.com [10.40.204.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38C221001B0B; Thu, 13 Feb 2020 20:24:41 +0000 (UTC) From: Andreas Gruenbacher To: Alexander Viro , David Sterba , Jeff Layton , "Theodore Ts'o" , Chao Yu , Richard Weinberger Cc: linux-fsdevel@vger.kernel.org, Andreas Gruenbacher Subject: [PATCH 6/7] ceph: Switch to page_mkwrite_check_truncate in ceph_page_mkwrite Date: Thu, 13 Feb 2020 21:24:22 +0100 Message-Id: <20200213202423.23455-7-agruenba@redhat.com> In-Reply-To: <20200213202423.23455-1-agruenba@redhat.com> References: <20200213202423.23455-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use the "page has been truncated" logic in page_mkwrite_check_truncate instead of reimplementing it here. Other than with the existing code, fail with -EFAULT / VM_FAULT_NOPAGE when page_offset(page) == size here as well, as should be expected. Signed-off-by: Andreas Gruenbacher Acked-by: Jeff Layton --- fs/ceph/addr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 7ab616601141..ef958aa4adb4 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1575,7 +1575,7 @@ static vm_fault_t ceph_page_mkwrite(struct vm_fault *vmf) do { lock_page(page); - if ((off > size) || (page->mapping != inode->i_mapping)) { + if (page_mkwrite_check_truncate(page, inode) < 0) { unlock_page(page); ret = VM_FAULT_NOPAGE; break; From patchwork Thu Feb 13 20:24:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 11381275 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BCF92109A for ; Thu, 13 Feb 2020 20:24:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 967FF24688 for ; Thu, 13 Feb 2020 20:24:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EfnIfyt9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728389AbgBMUYt (ORCPT ); Thu, 13 Feb 2020 15:24:49 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:44843 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727938AbgBMUYs (ORCPT ); Thu, 13 Feb 2020 15:24:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581625488; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jwKR0CnG4/7jIZO0QFfvC7ZnXn9Hg1xkhj3v1/ri4WQ=; b=EfnIfyt9M18WMk1zK0jcr5fQe6654lv1LDq24r4KM8MKVSEkIzkjm5115feWndlcQW9GC7 h+R8RBYyiw8TNTeVdYV4YT73OUCVwJ0q2URETke8RbASnF0X60oRB+j6dKfWuF+3G1vYBu LrGVIyjFi0GuGwieZlRueOPIyNBwtMk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-78-wDwSgUGyMT25CZ-7sroD1w-1; Thu, 13 Feb 2020 15:24:46 -0500 X-MC-Unique: wDwSgUGyMT25CZ-7sroD1w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8B213107ACC7; Thu, 13 Feb 2020 20:24:45 +0000 (UTC) Received: from max.home.com (ovpn-204-60.brq.redhat.com [10.40.204.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EAFE100032E; Thu, 13 Feb 2020 20:24:43 +0000 (UTC) From: Andreas Gruenbacher To: Alexander Viro , David Sterba , Jeff Layton , "Theodore Ts'o" , Chao Yu , Richard Weinberger Cc: linux-fsdevel@vger.kernel.org, Andreas Gruenbacher Subject: [PATCH 7/7] btrfs: Switch to page_mkwrite_check_truncate in btrfs_page_mkwrite Date: Thu, 13 Feb 2020 21:24:23 +0100 Message-Id: <20200213202423.23455-8-agruenba@redhat.com> In-Reply-To: <20200213202423.23455-1-agruenba@redhat.com> References: <20200213202423.23455-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use the "page has been truncated" logic in page_mkwrite_check_truncate instead of reimplementing it here. Signed-off-by: Andreas Gruenbacher Acked-by: David Sterba --- fs/btrfs/inode.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 5b3ec93ff911..532cc4aa9222 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8441,16 +8441,15 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf) goto out_noreserve; } - ret = VM_FAULT_NOPAGE; /* make the VM retry the fault */ again: lock_page(page); - size = i_size_read(inode); - if ((page->mapping != inode->i_mapping) || - (page_start >= size)) { - /* page got truncated out from underneath us */ + ret2 = page_mkwrite_check_truncate(page, inode); + if (ret2 < 0) { + ret = block_page_mkwrite_return(ret2); goto out_unlock; } + zero_start = ret2; wait_on_page_writeback(page); lock_extent_bits(io_tree, page_start, page_end, &cached_state); @@ -8471,6 +8470,7 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf) goto again; } + size = i_size_read(inode); if (page->index == ((size - 1) >> PAGE_SHIFT)) { reserved_space = round_up(size - page_start, fs_info->sectorsize); @@ -8502,12 +8502,6 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf) goto out_unlock; } - /* page is wholly or partially inside EOF */ - if (page_start + PAGE_SIZE > size) - zero_start = offset_in_page(size); - else - zero_start = PAGE_SIZE; - if (zero_start != PAGE_SIZE) { kaddr = kmap(page); memset(kaddr + zero_start, 0, PAGE_SIZE - zero_start);