Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2111129pxu; Fri, 18 Dec 2020 05:55:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9QGbn4UWqgz/tjIYnCuGZb1qkc8SIfP9UYoMQ9TwMeybxvHZPQplTTZzMVTzDctT2zBe3 X-Received: by 2002:aa7:df91:: with SMTP id b17mr4548031edy.272.1608299754900; Fri, 18 Dec 2020 05:55:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1608299754; cv=pass; d=google.com; s=arc-20160816; b=nsbs2wGxLEyf7MDEduZgCIIF2YdXhF4NZCh6jfr5xQUrIGaRD05ZbdHAs2Y9nOZGwZ yubQlgl2sOgBrfNu37eZ1Cssd55+D5lB9PBeJ69LQs2SR/kVZQVbaFB0QJ4pzDmSOzHb +dLlJbG4H9VKFCZd7kgphSNpLD6BRfbZAE67UNelegq84kM3ErJIhsHd/BXC0k+H5EOQ IaCmg67/fPu7L20/TQAVQaQ0im2YG2ZCwqlS613QWhcqHCzAruic5ZevgSEp7IHuJYzo ptIk9nd/Gl+4/T1bZnDoT7FxIBDWBLJFYY4X+9zBJAKWvJaUfCOzfA98EMRIJxlMqxjC gDUA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=awXflIhmEnSwwuTtk1iHfgGZL5MVwlaN1kgEGSNkTpc=; b=GZLa8yjXFIhnfvkAVIvQGdSrgcTMayA4FZ2Bee/6hWJPGwt9qUM6PF67FjbOInxhE/ iOgxppX6tPsXyrlFJ32CWjDXtltL5pViQaGfqqjMjS2bs5HIB/LUOiRwBlVQQW0bmXfH d71GzsJfV+OmezVh9pdZRPnhU6rmxqOeLJNl+dSB4w8AruTbvipbAGXu3CGTss7kcOMA 1nzD6U9BJEY6lS4Nxh4SVWqsVt4aYsBZZZ9aU3Dwfclei+r/L2BQFZT86FsGpHvG2e+t srEzZkV5kJPGCWXzGmxS26/NUrO6Vcrdbz7CXFwJklSt0w3hUnk+l3NMxh3kNCAhtPJI TlHw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mykernel.net header.s=zohomail header.b=JerxTB0+; arc=pass (i=1 spf=pass spfdomain=mykernel.net dkim=pass dkdomain=mykernel.net dmarc=pass fromdomain=mykernel.net>); spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-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 m1si4656166eja.95.2020.12.18.05.55.30; Fri, 18 Dec 2020 05:55:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@mykernel.net header.s=zohomail header.b=JerxTB0+; arc=pass (i=1 spf=pass spfdomain=mykernel.net dkim=pass dkdomain=mykernel.net dmarc=pass fromdomain=mykernel.net>); spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726476AbgLRNqJ (ORCPT + 99 others); Fri, 18 Dec 2020 08:46:09 -0500 Received: from sender2-op-o12.zoho.com.cn ([163.53.93.243]:17133 "EHLO sender2-op-o12.zoho.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726540AbgLRNqJ (ORCPT ); Fri, 18 Dec 2020 08:46:09 -0500 X-Greylist: delayed 1004 seconds by postgrey-1.27 at vger.kernel.org; Fri, 18 Dec 2020 08:46:03 EST ARC-Seal: i=1; a=rsa-sha256; t=1608298110; cv=none; d=zoho.com.cn; s=zohoarc; b=PJI7BSydzTDGXQv6doml7CFfNUR21WMLzEVJPFm+l28KUGHdaiabDlEfo5gpMwgDyY4+bArGrCbwkpp3OvyUergcnH+YIsBn8nPjih8jQbKbWYzezcRPzl9+/g+6e3Y7xo2VGqxIZ1ikY4xXVdVFnlVUO1qovt/4M0Q4yFqPPb0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com.cn; s=zohoarc; t=1608298110; h=Cc:Date:From:Message-ID:Subject:To; bh=awXflIhmEnSwwuTtk1iHfgGZL5MVwlaN1kgEGSNkTpc=; b=qz077Y75qUZOfx5oVKsANHnZ422weEAdjJnb7PjpkcBkwfc5xdeDTbAHzH+sHJ+xubbNmDE3lgNGpgh5TRDo5ij7v4+R1jTj5E1UNamrNmGBoboDCmncpEH5Qqe8MVFCjviJHGGIRCAOhICNYl9sho8FL/5s0hrV6wZqiJ2nHAQ= ARC-Authentication-Results: i=1; mx.zoho.com.cn; dkim=pass header.i=mykernel.net; spf=pass smtp.mailfrom=cgxu519@mykernel.net; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1608298110; s=zohomail; d=mykernel.net; i=cgxu519@mykernel.net; h=From:To:Cc:Subject:Date:Message-Id; bh=awXflIhmEnSwwuTtk1iHfgGZL5MVwlaN1kgEGSNkTpc=; b=JerxTB0+0t4gqLPZMPA8LHkSj3wlzDo7aCiQlapj3h5+Cyogs3wvNMh9oURQT0XX aa4m7UU/CdFVuQvQw6yKhpjWJYKbb8bJr/Nte+ayS1t4JPXWw/dJjRgH7S2HmP2gUsJ aIxJLmWtpaZxXsqgDIuAr2p4jkKdX69vnUCAHGuE= Received: from localhost.localdomain (81.71.33.115 [81.71.33.115]) by mx.zoho.com.cn with SMTPS id 1608298107117568.1965624674809; Fri, 18 Dec 2020 21:28:27 +0800 (CST) From: Chengguang Xu To: jack@suse.com Cc: linux-ext4@vger.kernel.org, Chengguang Xu Subject: [PATCH] ext2: implement ->page_mkwrite Date: Fri, 18 Dec 2020 21:27:57 +0800 Message-Id: <20201218132757.279685-1-cgxu519@mykernel.net> X-Mailer: git-send-email 2.18.4 X-ZohoCNMailClient: External Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Currently ext2 uses generic mmap operations for non DAX file and filemap_page_mkwrite() does not check the block allocation for shared writable mmapped area on pagefault. In some cases like disk space exhaustion or disk quota limitation, it will cause silent data loss. This patch tries to check and do block preallocation on pagefault if necessary and explicitly return error to user when allocation failure. Signed-off-by: Chengguang Xu --- fs/ext2/file.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/fs/ext2/file.c b/fs/ext2/file.c index 96044f5dbc0e..a34119415ef1 100644 --- a/fs/ext2/file.c +++ b/fs/ext2/file.c @@ -25,10 +25,34 @@ #include #include #include +#include #include "ext2.h" #include "xattr.h" #include "acl.h" +vm_fault_t ext2_page_mkwrite(struct vm_fault *vmf) +{ + struct vm_area_struct *vma = vmf->vma; + struct inode *inode = file_inode(vma->vm_file); + int err; + + if (unlikely(IS_IMMUTABLE(inode))) + return VM_FAULT_SIGBUS; + + sb_start_pagefault(inode->i_sb); + file_update_time(vma->vm_file); + err = block_page_mkwrite(vma, vmf, ext2_get_block); + sb_end_pagefault(inode->i_sb); + + return block_page_mkwrite_return(err); +} + +const struct vm_operations_struct ext2_vm_ops = { + .fault = filemap_fault, + .map_pages = filemap_map_pages, + .page_mkwrite = ext2_page_mkwrite, +}; + #ifdef CONFIG_FS_DAX static ssize_t ext2_dax_read_iter(struct kiocb *iocb, struct iov_iter *to) { @@ -123,15 +147,23 @@ static const struct vm_operations_struct ext2_dax_vm_ops = { static int ext2_file_mmap(struct file *file, struct vm_area_struct *vma) { + file_accessed(file); if (!IS_DAX(file_inode(file))) - return generic_file_mmap(file, vma); + vma->vm_ops = &ext2_vm_ops; + else + vma->vm_ops = &ext2_dax_vm_ops; - file_accessed(file); - vma->vm_ops = &ext2_dax_vm_ops; return 0; } + #else -#define ext2_file_mmap generic_file_mmap +static int ext2_file_mmap(struct file *file, struct vm_area_struct *vma) +{ + file_accessed(file); + vma->vm_ops = &ext2_vm_ops; + return 0; +} + #endif /* -- 2.18.4