xfs
[Top] [All Lists]

Re: [PATCH 1/2] vfs: Fix data corruption when blocksize < pagesize for m

To: Jan Kara <jack@xxxxxxx>
Subject: Re: [PATCH 1/2] vfs: Fix data corruption when blocksize < pagesize for mmaped data
From: Theodore Ts'o <tytso@xxxxxxx>
Date: Wed, 1 Oct 2014 22:06:19 -0400
Cc: linux-fsdevel@xxxxxxxxxxxxxxx, linux-ext4@xxxxxxxxxxxxxxx, xfs@xxxxxxxxxxx, Dave Chinner <david@xxxxxxxxxxxxx>
Delivered-to: xfs@xxxxxxxxxxx
Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=thunk.org; s=ef5046eb; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=/UxifbJSGf4D9Ql8weGW9qceelWIJ0yskxe3iY/RmWg=; b=DD8zfHGhQBU30pB9hBrGEmjbQs3RYYQiiyf4jGQSrOetKkC4dC3/NKCralDfUC0dkD5BUDl31Alnf49lKGy5obFsAUQ340CYghnUH1nswMHPFRce0PhpS2ZTRBXmJPNJqDbz9LtzocHxxOU/VTwzc9I0NNf0nFAf57FVV/Z1TCM=;
In-reply-to: <1411648916-16773-2-git-send-email-jack@xxxxxxx>
References: <1411648916-16773-1-git-send-email-jack@xxxxxxx> <1411648916-16773-2-git-send-email-jack@xxxxxxx>
User-agent: Mutt/1.5.23 (2014-03-12)
On Thu, Sep 25, 2014 at 02:41:55PM +0200, Jan Kara wrote:
> ->page_mkwrite() is used by filesystems to allocate blocks under a page
> which is becoming writeably mmapped in some process' address space. This
> allows a filesystem to return a page fault if there is not enough space
> available, user exceeds quota or similar problem happens, rather than
> silently discarding data later when writepage is called.
> 
> However VFS fails to call ->page_mkwrite() in all the cases where
> filesystems need it when blocksize < pagesize. For example when
> blocksize = 1024, pagesize = 4096 the following is problematic:
>   ftruncate(fd, 0);
>   pwrite(fd, buf, 1024, 0);
>   map = mmap(NULL, 1024, PROT_WRITE, MAP_SHARED, fd, 0);
>   map[0] = 'a';       ----> page_mkwrite() for index 0 is called
>   ftruncate(fd, 10000); /* or even pwrite(fd, buf, 1, 10000) */
>   mremap(map, 1024, 10000, 0);
>   map[4095] = 'a';    ----> no page_mkwrite() called
> 
> At the moment ->page_mkwrite() is called, filesystem can allocate only
> one block for the page because i_size == 1024. Otherwise it would create
> blocks beyond i_size which is generally undesirable. But later at
> ->writepage() time, we also need to store data at offset 4095 but we
> don't have block allocated for it.
> 
> This patch introduces a helper function filesystems can use to have
> ->page_mkwrite() called at all the necessary moments.
> 
> Signed-off-by: Jan Kara <jack@xxxxxxx>

Applied to the ext4 tree, thanks.

                                        - Ted

<Prev in Thread] Current Thread [Next in Thread>
  • Re: [PATCH 1/2] vfs: Fix data corruption when blocksize < pagesize for mmaped data, Theodore Ts'o <=