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);